| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525 |
- #include "lpc176x.h"
- #include "usb_hardware.h"
- #ifdef USBTMC // #endif â êîíöå ôàéëà
- #include "utils.h"
- #include "../usbtmc/gpib_parser.h"
- #include "../usbtmc/gpib_parser_validators.h"
- #include "../usbtmc/gpib_parser_strutils.h"
- #include "../usbtmc/gpib_parser_numutils.h"
- #include "usb_enumeration.h"
- #include "../usbtmc/usbtmc.h"
- #include "../usbtmc/utilits.h"
- #include "usb_options.h"
- #include "options.h"
- #include "usb_application.h"
- #include "usb_proto.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <stddef.h> // ptrdiff_t
- static char SCPIBParam[ MEMORY_SIZE_PARAMQUEUE ];
- // Ïàðñèíã GPIB êîììàíä. Êîììàíäû òèïà :COMMAND1:COMMAND2:COMMAND3 <DATA> ðàçáèâàþòñÿ íà îòäåëüíûå
- // êîììàíäû COMMAND1, COMMAND2, COMMAND3. Èçíà÷àëüíî, òðåáóåòñÿ îïðåäåëèòü, êàêèå êîììàíëû áóäóò ïîääåðæèâàòüñÿ.
- // Êàæäàÿ êîììàíäà ïðåäñòàâëÿåò ñîáîé íåêóþ ñòðóêòóðó äàííûõ, îïèñàííóþ íèæå (sScpiCommand_t). Îíà èìååò çàãîëîâîê,
- // òîåñòü ñîáñòâåííî èìÿ êîììàíäû, ñîêðàùåííîå èìÿ êîììàíäû, óêàçàòåëü íà ôóíêöèþ, êîòîðàÿ áóäåò âûïîëíåíà,
- // åñëè êîììàíäà ïðèíÿòà, è óêàçàòåëü íà ñïèñîê äî÷åðíèõ êîììàíä. Òàê, íàïðèìåð, êîììàíäà :SYSTem ìîæåò èìåòü
- // äâå äî÷åðíèå êîììàíäû INFO è VERsion. Äëÿ ïàðñèíãà ñòðîèòñÿ äåðåâî êîììàíä. Ñíà÷àëà íóæíî îáúÿâèòü êîðíåâóþ êîììàíäó,
- // êîòîðàÿ íå èìååò èìåíè, íî èìååò äî÷åðíèå êîììàíäû, òàê íàçûâàåìàÿ root êîììàíäà. ÏÐè íà÷àëå ðàçáîðà, êîììàíäû
- // áóäóò èçíà÷àëüíî èñêàòüñÿ èìåííî â äî÷åðíèõ êîììàíäàõ root. Äëÿ òîãî, ÷òîáû îáúÿâèòü root, âûçîâåì ôóíêöèþ
- // GPIB_InitializeCommand(sScpiCommand_t * Pointer, char * header, char *shortheader, TCmdParser_f function, unsigned int childcount )
- // ãäå Pointer - óêàçàòåëü íà âûäåëåííóþ ïîä ñòðóòóðó ïàìÿòü, header è shortheader óêàçàòåëè íà ñòðîêè, ñîäåðæàùèå
- // ïîëíîå è ñîêðàùåííûå èìåíà êîììàíäû ñîîòâåòñâåííî (îíè ìîãóò áûòü ðàçìåùåíû â ñåêöèè êîäà), function - óêàçàòåëü íà
- // ôóíêöèþ - îáðàáîò÷èê òèïà TCmdParser_f, êîòîðàÿ ïðèíèìàåò äâà ïàðàìåòðà - óêàçàòåëü íà ñòðîêó, è íà USB_DEVICE_INFO
- // childcount - êîëè÷åñòâî äî÷åðíèõ êîììàíä, íåîáõîäèìî óêàçàòü òî÷íîå êîëè÷åñòâî êîììàíä â ñåêöèè root äëÿ âûäåëåíèÿ ïîä íèõ
- // ïàìÿòè. Ïîñëå òîãî, êàê GPIB_InitializeCommand âåðíåò óêàçàòåëü íà ñòðóêòóðó sScpiCommand_t, åãî ìîæíî çàïîìíèòü â ïåðåìåííóþ è èñïîëüçîâàòü
- // êàê ñïèñîê êîììàíä ïðè ïåðåäà÷å â ôóíêöèþ parse(). Ïîñëå ñîçäàíèÿ root, äîáàâëÿåì âñå êîììàíäû, âûçûâàÿ
- // GPIB_AddChildCommand( sScpiCommand_t * OwnerCommand, char * header, char *shortheader, TCmdParser_f function, unsigned int childcount )
- // ãäå OwnerCommand - óêàçàòåëü íà êîììàíäó, äëÿ êîòîðîé äîáàâëÿåìàÿ êîììàíäà áóäåò äî÷åðíåé. Åñëè äîáàâëÿåìàÿ êîììàíäà íå äîëæíà áûòü
- // äî÷åðíåé, à äîëæíà áûòü îñíîâíîé (:SYSTem), íóæíî ïåðåäàòü óêàçàòåëü root. Îñòàëüíûå ïàðàìåòðû àíàëîãè÷íû GPIB_InitializeCommand
- // Êàæäûé âûçîâ GPIB_AddChildCommand âîçâðàùàåò óêàçàòåëü íà âíîâü ñîçäàííóþ êîììàíäó, êîòîðûé íóæíî ñîõðàíèòü â ïåðåìåííîé,
- // åñëè ñîçäàâàåìàÿ êîììàíäà áóäåò èìåòü äî÷åðíèå êîììàíäû.
- /*
- char * fGPIB_Parser_CMD1(char*); // -- ïðîòîòèïû
- char * fGPIB_Parser_CMD2(char*); //
- char * fGPIB_Parser_CMD3(char*); //
- char * fGPIB_Parser_CMD4(char*); //
- char * fGPIB_Parser_CMD5_1(char*); //
- //------------------------------------------------------------------------------------------------------------
- sScpiCommand_t Root; // -- ïåðåìåííàÿ õðàíèò êîììàíäó root
- sScpiCommand_t * root = GPIB_InitializeCommand( &Root, NULL, NULL, NULL, 5 ); // -- ïðåäïîëàãàåòñÿ ñîçäàòü 5 êîììàíä â root
- sScpiCommand_t * Command1 = GPIB_AddChildCommand( root, "CoMmanD1","CMD1", fGPIB_Parser_CMD1, 0 ); // -- êîììàíäà CMD1 íå áóäåò èìåòü äî÷åðíèõ. Îáðàáàòûâàòüñÿ êîììàíäà áóäåò ôóíêöèåé char * fGPIB_Parser_CMD1(char*)
- sScpiCommand_t * Command2 = GPIB_AddChildCommand( root, "CoMmanD2","CMD2", fGPIB_Parser_CMD2, 0 );
- sScpiCommand_t * Command3 = GPIB_AddChildCommand( root, "CoMmanD3","CMD3", fGPIB_Parser_CMD3, 0 );
- sScpiCommand_t * Command4 = GPIB_AddChildCommand( root, "CoMmanD4","CMD4", fGPIB_Parser_CMD4, 0 );
- sScpiCommand_t * Command5 = GPIB_AddChildCommand( root, "CoMmanD5","CMD5", fGPIB_Parser_CMD5, 1 ); // -- êîììàíäà áóäåò èìåòü äî÷åðíþþ
- sScpiCommand_t * Command5_1 = GPIB_AddChildCommand( Command5, "CoMmanD5_1","CM51", fGPIB_Parser_CMD5_1, 0 ); // -- êîììàíäà äîáàâëåíà ê êîììàíäå Command5 êàê äî÷åðíÿÿ
- */
- // Òàêèì îáðàçîì, äîáàâëÿòü è èçìåíÿòü êîëè÷åñòâî è ïîääåðæêó êîììàíä çíà÷èòåëüíî ïðîùå, ÷åì îáðàáàòûâàòü
- // âñþ ñòðîêó â ëîá ñ êó÷åé if-îâ
- // ==================== ïðîòîòèïû =========================================================
- // ============================= ÑÅÐÂÈÑÍÛÅ ÔÓÍÊÖÈÈ ===================================================
- // GPIB_InitializeCommand:
- // Initializes the GPIB command
- // @pointer - the pointer to the command entry to initialize
- // @header - the command header (name)
- // @shortheader - the short command name
- // @function - command handler
- // @childMax - the maximum amount of child commands
- // @enablerequest - boolean flag, allows the request mode for the command
- sScpiCommand_t * GPIB_InitializeCommand ( sScpiCommand_t * pCmd,
- const char * header,
- const char *shortheader,
- TCmdParser_f function,
- size_t childMax,
- BOOL enablerequest )
- {
- if( !IsCorrectPointer(pCmd) )
- return NULL;
- pCmd->enablerequest = enablerequest; // request mode enable
- pCmd->header = header; // full header
- pCmd->shortheader = shortheader; // short header
- pCmd->function = function; // handler
- pCmd->childcount = 0; // amount of child commands
- pCmd->childcountmax = childMax; // maximum available of child commands
- pCmd->pcommands = (sScpiCommand_t*)malloc( sizeof(sScpiCommand_t) * childMax ); // allocate memory for child commands
- pCmd->bTagArgUsed = FALSE;
- if( (NULL == pCmd->pcommands)
- && (childMax > 0) )
- {
- return NULL;
- }
-
- return pCmd;
- }
- //-----------------------------------------------------------------------------------------------------
- // GPIB_MakeSpecialCommand() transform the command to special command
- // Special command has an extra tag parameter to specialize the handler call.
- BOOL GPIB_MakeSpecialCommand ( sScpiCommand_t * pCmd, int xTag, BOOL bUsed )
- {
- if( !IsCorrectPointer(pCmd) )
- return FALSE;
-
- pCmd->bTagArgUsed = bUsed;
- pCmd->xTagArg = xTag;
-
- return TRUE;
- }
- // ------------------------------------------------------------------------------------------------------
- // GPIB_AddChildCommand:
- // Appends the child command to the specified owner @pOwnerCommand
- sScpiCommand_t * GPIB_AddChildCommand( sScpiCommand_t * pOwnerCommand, char * header, char * shortheader, TCmdParser_f function, size_t childMax, BOOL enablerequest )
- {
- if( !IsCorrectPointer(pOwnerCommand) )
- return NULL;
- sScpiCommand_t * ChildCommand;
- // check the limit of children
- if( pOwnerCommand->childcountmax > pOwnerCommand->childcount )
- {
- // Use already allocated memory for child command in @pOwnerCommand->pcommands block.
- ChildCommand = GPIB_InitializeCommand( &pOwnerCommand->pcommands[ pOwnerCommand->childcount ], header, shortheader, function, childMax, enablerequest );
-
- if( ChildCommand != NULL )
- pOwnerCommand->childcount++; // increment count of children
- }
- else
- ChildCommand = NULL; //error
-
- return ChildCommand;
- }
- //-------------------------------------------------------------------------------
- // GPIB_Parse:
- // Parse one command with parameters.
- // Note: the command must be without subsystem-character in the begining (semicolon)
- // E.g. SYSTem:TRIGger
- //
- sScpiCommand_t * GPIB_Parse( USB_DEVICE_INFO * udi, char * str, BOOL request, char * end )
- {
- sScpiCommand_t * searchRoot = udi->usbtmcGpib.gpib_search; // retrieve the root of the search
- // -----------------------------------------------------------------------------------------------------------
- // Validate the pointer @searchRoot
- if( ! IsCorrectPointer(searchRoot) )
- return NULL; // error
-
- // Validate the pointers @str and @end
- // It must be non NULL.
- if( NULL == str || NULL == end )
- return NULL;
-
- // Check if the @end greater than @str
- if( ChooseLowestPtrConst(str, end) == end )
- // error: the @str greater than @end
- // @end it's end of the string and must be greater.
- return NULL;
- // -----------------------------------------------------------------------------------------------------------
-
- // -----------------------------------------------------------------------------------------------------------
- // @sysNodeBegin: search for the subsystem delimiter (semicolon)
- char * sysNodeBegin = GPIB_StrChr_rw( str, GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN, end);
- // @sysNodeEnd: search for the end of all subsystems (whole command header, e.g. space btw cmd and data)
-
- //char * sysNodeEnd = strwhite( str ); // So, search for first white-charater
- char * sysNodeEnd = searchHeaderEnd( str, end ); // Search for the end of the header
-
- char charWhite = *sysNodeEnd; // Save the white character by offset @sysNodeEnd.
-
- // Calculate the string length
- size_t strLength = (int)((ptrdiff_t)(end) - (ptrdiff_t)(str));
- size_t strLength2 = strlen(str);
- // Choose the shortest one between strlen() and substraction btw @end and @str
- strLength = (strLength<strLength2 ? strLength : strLength2);
-
- BOOL bCommandFound = FALSE; // flag, is TRUE if a command found
- BOOL bRequest = FALSE; // is TRUE for the REQUEST command, e.g. *CMD? for "*CMD" command
-
- // Note: it is normal that @sysNodeBegin is NULL.
- // Note: it is normal that @sysNodeEnd is NULL.
-
- if( NULL != sysNodeBegin ) *sysNodeBegin = '\0'; // make the long command shorter - only one subsystem will be used til the semicolon
- if( NULL != sysNodeEnd ) *sysNodeEnd = '\0'; // make the long command shorter - replace white character with the null terminator
- // -----------------------------------------------------------------------------------------------------------
- // Validate the header
- if( TRUE != GPIB_CheckHeader(str, end) )
- //if( TRUE != GPIB_CheckHeader(str) )
- {
- // restore the subsystem delimiter
- if( sysNodeBegin != NULL ) *sysNodeBegin = GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN;
-
- // restore the white character
- if( sysNodeEnd != NULL ) *sysNodeEnd = charWhite;
-
- /* ëèøíèé êîä - òà æå ñàìàÿ îøèáêà ãåíåðèðóåòñÿ â GPIB_CommandExecure, è îíà ïîëó÷àåòñÿ äóáëèðîâàíà
- // error: raise an error
- // 27/08/18 if( usbtmc_RaiseError( udi, GPIB_ERROR_ID_EXE, ERROR_USBTMC_EXECUTION, "'", 1 ) )
- // 30/08/18 if( usbtmc_RaiseError( udi, errClass_Command, ERROR_USBTMC_EXECUTION, "'", 1 ) )
- if( usbtmc_RaiseError( udi, errClass_Command, ERROR_USBTMC_INVALID_HEADER, "'", 1 ) )
- {
- //if( usbtmc_RaiseError_CatDescription( udi, str, strlen(str) ) ) // strlen(str): takes the command til the first '\0'
- if( usbtmc_RaiseError_CatDescription( udi, str, strLength ) )
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1) )
- {
- usbtmc_ErrorQueue_RestoreCheckpoint( udi );
- }
- }
- else
- usbtmc_ErrorQueue_RestoreCheckpoint( udi );
- }
- else
- usbtmc_ErrorQueue_RestoreCheckpoint( udi );
- */
-
- // return NULL
- return NULL;
- }
-
- if( GPIB_CHAR_MANDATORY_IEEE488_SIGN == str[0] && strLength < 3 )
- {
- }
- else
- {
- // search for the header in the command list from specified root (@searchRoot)
- for( size_t i = 0; i < searchRoot->childcount; ++i )
- {
- bCommandFound = FALSE;
-
- do
- {
- // -------------------------------------------------------------
- // Attempt 1.
- // -------------------------------------------------------------
- // Compare the command header
- if( GPIB_HeaderCompare( searchRoot->pcommands[i].header, str ) // the command header matchs
- || GPIB_HeaderCompare( searchRoot->pcommands[i].shortheader, str ) ) // the command short header matchs
- {
- bCommandFound = TRUE;
-
- // In case searchRoot->pcommands[i].enablerequest is FALSE, but
- // the command actually is a request, the header contain a request
- // character in the end. It is required to set @bRequst to appropriate value.
- if( GPIB_CHAR_REQUEST_SIGN == *(sysNodeEnd - 1) )
- bRequest = TRUE;
- break; // do-while
- }
-
- // -------------------------------------------------------------
- // Attempt 2.
- // -------------------------------------------------------------
- // Note: if @enablerequest it means the command in the list is registered
- // without question mark, e.g. ESE, but not ESE?. So it means the command
- // can be used as either "command" and "request". In this case GPIB_HeaderCompare
- // does not find full match
- // Check if the command is registered without the request mark (?).
- if( searchRoot->pcommands[i].enablerequest )
- {
- // get the header length
- // Note: @str string had been cut with null-terminator above.
- strLength = strlen( str );
- // Check if @str contain a request character
- if( (GPIB_CHAR_REQUEST_SIGN == str[ strLength-1 ])
- && (strLength > 1)
- )
- {
- // replace the request character with a null-terminator.
- str[ strLength-1 ] = '\0';
-
- // Perform another comparaion of the command header
- if( GPIB_HeaderCompare( searchRoot->pcommands[i].header, str ) // the command header matchs
- || GPIB_HeaderCompare( searchRoot->pcommands[i].shortheader, str ) ) // the command short header matchs
- {
- bCommandFound = TRUE;
- bRequest = TRUE;
- str[ strLength-1 ] = GPIB_CHAR_REQUEST_SIGN; // restore the request character
- break; // do-while
- }
-
- str[ strLength-1 ] = GPIB_CHAR_REQUEST_SIGN; // restore the request character
- }
- }
- }
- while(0);
-
- if( bCommandFound )
- {
- // Check is there next subsystem separator in the string.
- // If there no such separator, the the whole input command string is processed.
- if( sysNodeBegin != NULL )
- {
- // There are more subsystem separators
-
- *sysNodeBegin = GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN; // restore subsystem separator
-
- if( sysNodeEnd != NULL ) *sysNodeEnd = charWhite; // restore white character
-
- udi->usbtmcGpib.gpib_owner = udi->usbtmcGpib.gpib_search; // save the command owner: searchRoot->pcommands[i]
- udi->usbtmcGpib.gpib_search = &searchRoot->pcommands[i]; // set the root for the searching in the next recursive call
-
- sysNodeBegin++; // skip subsystem separator
-
- return GPIB_Parse( udi, sysNodeBegin, bRequest, end ); // parse the command recursive in the found command
- }
- else // if the input string is processed til the end
- {
- if( sysNodeEnd != NULL ) // if there is a white character in the tail of header
- { // Note: a white character always presents.
- *sysNodeEnd = charWhite; // restore white character
-
-
-
- size_t nRespondBytes = 0; // @nRespondBytes - amount of sent bytes
- size_t nOffset = 0;
-
- // It is required to insert the delimiter between replies
- // relating to the different input requests in case more than one
- // command is in the string.
- if( bRequest )
- {
- /*
- // pointer to the buffer for respond
- BULKIN_HEADER * pBulkInHeader= (BULKIN_HEADER*) udi->EPBulkStatus.InPipe.pData;
-
- // if there are any bytes in the respond buffer - it must be a reply of another command
- if( 0 < pBulkInHeader->stRespondMessage.TransferSize )
- {
- // insert a delimiter
- udi->usbtmcGpib.pData[0] = GPIB_CHAR_RPLSEPARATOR_SIGN;
- udi->usbtmcGpib.pData++;
- nOffset++;
- }
- */
- if( udi->BulkRespondStatus.dwDeviceOut > 0 )
- {
- // insert a delimiter
- udi->usbtmcGpib.pData[0] = GPIB_CHAR_RPLSEPARATOR_SIGN;
- udi->usbtmcGpib.pData++;
- nOffset++;
- }
- }
-
-
- size_t paramLength = 0;
- // -------------
- // If the end of header reached - set @sysNodeEnd to NULL, and set @paramLength to 0
- sysNodeEnd++;
- if( sysNodeEnd >= end )
-
- sysNodeEnd = NULL;
- else
- paramLength = SubPointers( end, sysNodeEnd );
- // -------------
-
- // Enumerate parameters and pack it into the queue
- QUEUE QParameters;
- queue_create( SCPIBParam, MEMORY_SIZE_PARAMQUEUE, &QParameters ); // @SCPIBParam - global and static buffer
- // Check command tag:
- if(searchRoot->pcommands[i].bTagArgUsed == TRUE)
- {
- // push the tag-parameter into the queue
- queue_add( &QParameters,
- (char*)&searchRoot->pcommands[i].xTagArg,
- sizeof(searchRoot->pcommands[i].xTagArg) );
- }
- // Allow unlimited amount of non-request commands, and limited amount of requests
- if( !bRequest || udi->usbtmcGpib.cRequestCountSupport > 0 )
- {
- // request: decrease amount of allowed requests (@cRequestCountSupport)
- if( bRequest ) udi->usbtmcGpib.cRequestCountSupport--;
-
- int rcEnum = 1;
-
- if( NULL != sysNodeEnd && 0 != paramLength )
- {
- // Enumerate all the parameters and pack it into the queue @QParameters
- rcEnum = GPIB_EnumParameters( sysNodeEnd, paramLength, &QParameters, NULL );
- }
-
- if( rcEnum > 0 )
- {
- QParameters.nStringLen = paramLength;
- QParameters.pString = sysNodeEnd;
- // ----------------------------------------------------------------------------
-
- // It is required to keep command context to give
- // enough time the current command to send it's reply.
- // --- usbtmc_delete_function_context( udi ) ---
-
- // see USBTMC spec, rev 1.0, 2003, page 16, table 12, index 1
- // Stall and abort the endpoint in case the IRQ-transfer is in progress
- if(udi->BulkRespondStatus.INTransferInProgress == TRUE && bRequest)
- usbtmc_bulkin_stall_and_abort( udi );
-
- // call the command processor
- nRespondBytes += (searchRoot->pcommands[i].function( udi, &QParameters, bRequest ));
-
- udi->usbtmcGpib.pData += nRespondBytes; // shift the pointer of the reply buffer
- udi->BulkRespondStatus.RespondBufferSize -= (nRespondBytes + nOffset); // and decrease amount of free space.
- udi->BulkRespondStatus.dwDeviceOut += (nRespondBytes + nOffset); // Increase of output transfer.
- }
- else
- {
- // 27/08/18
- // GPIB_RaiseStandartError( udi, ERROR_GPIB_INVALID_ENUM_PARAMETERS, NULL, GPIB_ERROR_ID_EXE );
- GPIB_RaiseStandartError( udi, ERROR_GPIB_INVALID_ENUM_PARAMETERS, NULL, errClass_Autodetect );
- }
- }
- else
- {
- // 27/08/18
- // GPIB_RaiseStandartError( udi, ERROR_GPIB_TOO_MANY_REQUESTS, NULL, GPIB_ERROR_ID_EXE );
- GPIB_RaiseStandartError( udi, ERROR_GPIB_TOO_MANY_REQUESTS, NULL, errClass_Command );
- }
-
- return searchRoot;
- }
-
- break;
- }
- }
- }
- }
-
- // Reach this point in case the command header not found.
- if( bCommandFound == FALSE )
- {
- sScpiCommand_t * pseudo_result;
- sScpiCommand_t * SearchSave;
- sScpiCommand_t * OwnerSave;
-
- searchRoot = udi->usbtmcGpib.gpib_owner; // get the owner for the search
- // it is possible that optional header is omitted
-
- if( sysNodeBegin != NULL ) *sysNodeBegin = GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN; // restore subsystem separator
- if( sysNodeEnd != NULL ) *sysNodeEnd = charWhite; // restore white character
-
- for( size_t i = 0; i < searchRoot->childcount; ++i )
- {
- if( IsOptionalHeader( searchRoot->pcommands[i].shortheader )
- || IsOptionalHeader( searchRoot->pcommands[i].header ) ) // optional header found
- {
- /*!*/SearchSave = udi->usbtmcGpib.gpib_search; // save the search pointer
- /*!*/OwnerSave = udi->usbtmcGpib.gpib_owner; // save the owner command
-
- udi->usbtmcGpib.gpib_owner = udi->usbtmcGpib.gpib_search;
- udi->usbtmcGpib.gpib_search = &searchRoot->pcommands[i]; // change the search point for a while
-
- pseudo_result = GPIB_Parse( udi, str, request, end); // call the parser recursively
-
- /*!*/udi->usbtmcGpib.gpib_search = SearchSave; // restore the search pointer
- /*!*/udi->usbtmcGpib.gpib_owner = OwnerSave; // restore the owner command
-
- if( pseudo_result != NULL )
- return pseudo_result; // command found among optional commands
- }
- }
- }
-
- return NULL;
- }
- /*
- //-------------------------------------------------------------------------------
- //
- // Parameters: str - óêàçàòåëü íà îäíó êîììàíäó. Ïðèìåð, "SYSTem:TRIGger"
- // Êîììàíäà ":SYSTem:TRIGger" íåêîððåêòíà, òàê êàê èìååòñÿ íåçíà÷àùåå äâîåòî÷èå â íà÷àëå.
- // Íóæíî óáèðàòü äâîåòî÷èå â íà÷àëå
- sScpiCommand_t * parse( USB_DEVICE_INFO * udi, char * str, BOOL request, char * end)
- {
- sScpiCommand_t * Search = udi->usbtmcGpib.gpib_search; // -- íîä äåðåâà, ñ êîòîðîãî íà÷èíàåòñÿ ïîèñê
- BULKIN_HEADER * pBulkInHeader= (BULKIN_HEADER*) udi->EPBulkStatus.InPipe.pData; // óêàçàòåëü íà íà÷àëî áóôåðà-îòâåòà, óêàçàòåëü íà çàãîëîâîê Bulk-IN
- // -----------------------------------------------------------------------------------------------------------
- if( !IsCorrectPointer(Search) ) return NULL; // -- ïðîâåðÿåì êîððåêòíîñòü óêàçàòåëÿ
- // -----------------------------------------------------------------------------------------------------------
- char * p = GPIB_StrChr_rw( str, GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN, end); // -- èùåì ñëåäóþùèé íîä â ñòðîêå
- char * s = strwhite( str ); // -- èùåì çàâåðøàþùèé ñèìâîë êîìàíäû
- char _s = *s; // -- ñîõðàíÿåì çàâåðøàþùèé ñèìâîë êîììàíäû
- int l; // -- õðàíèò äëèííó ñòðîêè
- BOOL bCommandFound = FALSE; // -- êîììàíäà íåíàéäåíà
- BOOL q = FALSE; // -- ðàâåí TRUE åñëè ïðèøåë çàïðîñ "*REQUEST?", Õîòÿ èìååòñÿ êîììàíäà "*REQUEST"
- if( p != NULL ) *p = 0; // -- åñëè íàøëè ñëåä. íîä, óêîðà÷èâàåì êîììàíäó, äåëàÿ èç ïîñëåäîâàòåëüíîñòè êîììàíä îäíó êîììàíäó
- if( s != NULL ) *s = 0; // -- åñëè íàøëè çàâåðøàþùèé ñèìâîë, çàìåíÿåì åãî íà íóëü òåðìèíàòîð
- // -----------------------------------------------------------------------------------------------------------
- if( GPIB_CheckHeader(str) != TRUE )
- {
- // ñíà÷àëà ãåíåðèì îøèáêó, strlen äîéäåò äî '\0'
- // à ïîòîì óæå âåðíåì ïðîáåë íà ìåñòî
- if( usbtmc_RaiseError( udi, GPIB_ERROR_ID_EXE, ERROR_USBTMC_EXECUTION, "'", 1 ))
- if(usbtmc_RaiseError_CatDescription( udi, str, strlen(str)))
- usbtmc_RaiseError_CatDescription( udi, "'", 1);
- if( p != NULL ) *p = GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN; // -- âîññòàíàâëèâàåì äâîåòî÷èå
- if( s != NULL ) *s = _s; // -- âîññòàíàâëèâàåì white ñèìâîë, (åñëè ýòî íàïðèìåð ïðîáåë, îòäåëÿþùèé äàííûå)
- }
- else
- {
- if(!( *str == GPIB_CHAR_MANDATORY_IEEE488_SIGN && strlen(str)<=2 ))
- for(int i=0; i< Search->childcount; i++) // -- èùåì ïî òåêóùåìó íîäó ïîèñêà íóæíóþ êîììàíäó
- // ------ ïðîâåðÿåì ñîâïàäåíèÿ êîììàíä...
- // --------------------------------------
- if( TRUE==GPIB_HeaderCompare( Search->pcommands[i].header, str ) || // -- èëè åñëè ñîâïàëî èìÿ êîììàíäû
- TRUE==GPIB_HeaderCompare( Search->pcommands[i].shortheader, str ) || // -- èëè åñëè ñîâïàëà àááðåâèàòóðà êîììàíäû
- // ---------- ïðîâåðÿåì ñîâïàäåíèå çàïðîñà...............
- // -- ïðîâåðêà äàëüøå, åñëè èìÿ è àááðåâèàòóðà íå ñîâïàëè
- (Search->pcommands[i].enablerequest == TRUE && // -- èëè åñëè ðàçðåøåíî ñðàâíåíèå áåç '?'
- ( // ---------- ïðîâåðÿåì, åñòü ëè â êîíöå çàïðîñíûé ñèìâîë '?'
- ((l = strlen( str )) && (str[l-1] == '?')) && // ---- è '?' åñòü â êîíöå ñòðîêè
- ( // --------- ñèìâîë åñòü, ñðàâíèâàåì áåç ñèìâîëà
- 0==strncmp( Search->pcommands[i].header, str, l-1 ) || // -- ñâåðÿåì èìÿ áåç '?'
- 0==strncmp( Search->pcommands[i].shortheader, str, l-1 ) // -- ñâåðÿåì àááð áåç '?'
- ) && (l>1) && ((q = TRUE),q) // -- åñëè âñå óñëîâèÿ âûïîëíåíû, q=TRUE
-
- )
- )
- )
- {
- bCommandFound = TRUE;
- if (p != NULL ) // -- åñëè ñòðîêà ðàçîáðàíà íå ïîëíîñòüþ
- { if( p != NULL ) *p = GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN; // -- âîññòàíàâëèâàåì äâîåòî÷èå
- if( s != NULL ) *s = _s; // -- âîññòàíàâëèâàåì white ñèìâîë, (åñëè ýòî íàïðèìåð ïðîáåë, îòäåëÿþùèé äàííûå)
- udi->usbtmcGpib.gpib_owner = udi->usbtmcGpib.gpib_search; // ñîõðàíÿåì âëàäåëüöà êîììàíäû Search->pcommands[i]
- udi->usbtmcGpib.gpib_search = &Search->pcommands[i];
- return parse( udi, p+1, q, end); // -- ðåêóðñèâíî ïàðñèì ñëåäóþùóþ êîììàíäó. ïîèñê â óæå íàéäåíîì íîäå
- }
- else // -- åñëè ñòðîêà ðàçîáðàíà ïîëíîñòüþ
- if( s != NULL ) // -- åñëè èìååòñÿ white ñèìâîë, à îí âñåãäà èìååòñÿ
- { *s = _s; // -- âîññòàíàâëèâàåì åãî
-
-
- int dwRespondBytes=0; // -- dwRespondBytes - êîëè÷åñòâî áàéò, îòïðàâëÿåìûõ â îòâåò íà êîììàíäó
- int dwOffset=0;
-
-
- if( q == FALSE && *(s-1) == '?' ) q = TRUE; // åñëè êîììàíäà äîáàâëåíà êàê RequestOnly, åå header ñîäåðæèò '?'. q=FALSE åñëè êîììàíäà RequestOnly. Ýòà ñòðîêà èñïðàâëÿåò ñèòóàöèþ
- // --------------------- âñòàâêà ðàçäåëèòåëÿ ; â îòâåòíîå ñîîáùåíèå ìåæäó îòâåòàìè ------------------------
- // --------------------------------------------------------------------------------------------------------
- if(q==TRUE // -- åñëè ïðèøåë ÇÀÏÐÎÑ
- &&
- pBulkInHeader->stRespondMessage.TransferSize // -- åñëè óæå áûëè äàííûå â áóôåðå îò ïðåäûäóùåé êîììàíäå
- &&
- (++dwOffset)) // -- óâåëè÷èâàåì Offset
- (udi->usbtmcGpib.pData++)[0] = ';'; // -- âñòàâëÿåì ðàçäåëèòåëü
- // --------------------------------------------------------------------------------------------------------
-
-
-
- if( end <= ++s ) s = NULL; // åñëè êîíåö ñòðîêè èëè êîíåö êîììàíäû (ðàçäåëèòåëü ñëåäîì) òî s=NULL
-
- unsigned int strl = SubPointers(end,s);
-
- // -------------------------- ýíóìåðóåì ïàðàìåòðû è ëîæèì èõ â î÷åðåäü --------
- QUEUE QParameters;
- queue_create( SCPIBParam, MEMORY_SIZE_PARAMQUEUE, &QParameters ); // áóôåð î÷åðåäè ãëîáàëüíûé è ñòàòè÷åñêèé.
- if(Search->pcommands[i].bTagArgUsed == TRUE)
- queue_add( &QParameters, (char*)&Search->pcommands[i].xTagArg, sizeof(Search->pcommands[i].xTagArg) );
- if( !q || (q && udi->usbtmcGpib.cRequestCountSupport-- > 0) )
- if( GPIB_EnumParameters( s, strl, &QParameters, NULL ) != -1 )
- {
- QParameters.strl = strl;
- QParameters.str = s;
- // ----------------------------------------------------------------------------
-
- //-- ïåðåä âûïîëíåíèåì GPIB ôóíêöèè íåëüçÿ óäàëÿòü êîíòåêñò,
- //-- âåäü ñëåä êîììàíäà ìîæåò åãî è íå èñïîëüçóåò,
- //-- à òåêóùàÿ íå óñïååò ïåðåäàòü äàííûå
- //usbtmc_delete_function_context( udi );
-
- // see USBTMC spec, rev 1.0, 2003, page 16, table 12, index 1
- if(udi->BulkRespondStatus.INTransferInProgress == TRUE && q)
- usbtmc_bulkin_stall_and_abort( udi );
-
-
- dwRespondBytes+= (Search->pcommands[i].function( udi, &QParameters, q )); // -- âûçûâàåì îáðàáîò÷èê êîììàíäû, ïåðåäàâàÿ åìó îñòàâøóþñÿ ÷àñòü ñòðîêè ïîñëå white ñèìâîëà
-
- udi->usbtmcGpib.pData+=dwRespondBytes; // -- ñäâèãàåì óêàçàòåëü áóôåðà, â êîòîðûé ñêëàäûâàþòñÿ îòâåòû
- udi->BulkRespondStatus.RespondBufferSize -= (dwRespondBytes+dwOffset); // -- óìåíüøàåì îáúåì äîñòóïíîãî ìåñòà â áóôåðå
- udi->BulkRespondStatus.dwDeviceOut+=(dwRespondBytes+dwOffset); // -- óâåëè÷èâàåì ðàçìåð îòâåòíîé ïåðåäà÷è
- } else GPIB_RaiseStandartError( udi, ERROR_GPIB_INVALID_ENUM_PARAMETERS, NULL, GPIB_ERROR_ID_EXE );
- else GPIB_RaiseStandartError( udi, ERROR_GPIB_TOO_MANY_REQUESTS, NULL, GPIB_ERROR_ID_EXE );
- return Search;
- }
- break;
- }
-
- // -- ñþäà ìû ïîïàäåì åñëè êîììàíäà íå íàéäåíà!
- if( bCommandFound == FALSE )
- {
- sScpiCommand_t * pseudo_result;
- sScpiCommand_t * SearchSave;
- sScpiCommand_t * OwnerSave;
- Search = udi->usbtmcGpib.gpib_owner; // ïîëó÷àåì õîçÿèíà
- // -- âîçìîæíî îïóùåí íåîáÿçàòåëüíûé çàãîëîâîê!
- if( p != NULL ) *p = GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN; // -- âîññòàíàâëèâàåì äâîåòî÷èå
- if( s != NULL ) *s = _s;
-
- for(int i=0; i< Search->childcount; i++)
- if( IsOptionalHeader(Search->pcommands[i].shortheader) || IsOptionalHeader(Search->pcommands[i].header)) // åñëè íàéäåíà îïöèîíàëüíàÿ êîììàíäà
- {
- // !!!!!!!!!!!!!
- SearchSave = udi->usbtmcGpib.gpib_search; // ñîõðàíÿåì òåêóùèé óêàçàòåëü íà òî÷êó ïîèñêà
- OwnerSave = udi->usbtmcGpib.gpib_owner; // ñîõðàíÿåì òåêóùèé óêàçàòåëü íà âëàäåëüöà êîììàíäû
- // !!!!!!!!!!!!!
- udi->usbtmcGpib.gpib_owner = udi->usbtmcGpib.gpib_search;
- udi->usbtmcGpib.gpib_search = &Search->pcommands[i]; // èçìåíÿåì íà âðåìÿ òåêóùèé óêàçàòåëü íà òî÷êó ïîèñêà
-
- pseudo_result = parse( udi, str, request, end);
-
- // !!!!!!!!!!!!!
- udi->usbtmcGpib.gpib_search = SearchSave; // âîññòàíàâëèâàåì ïðåæíèé óêàçàòåëü íà òî÷êó ïîèñêà
- udi->usbtmcGpib.gpib_owner = OwnerSave; // âîññòàíàâëèâàåì ïðåæíèé óêàçàòåëü íà âëàäåëüöà êîììàíäû
- // !!!!!!!!!!!!!
- if( pseudo_result != NULL ) return pseudo_result; // óðà, íàøëè êîììàíäó â äåðåâà â îäíîì èç îïöèîíàëüíûõ íîäîâ
- }
- }
- } // CheckHeader
- return NULL;
- }
- */
- //----------------------------------------------------------------------
- // GPIB_InitializeAllCommands:
- // Create a list of supported commands of the device.
- sScpiCommand_t * GPIB_InitializeAllCommands()
- {
- // Allocate memory for the root command
- sScpiCommand_t * root = (sScpiCommand_t *)malloc( sizeof(sScpiCommand_t) );
- if( !IsCorrectPointer(root) )
- return NULL;
- // -------------------------------------------------------------------------------------------------
- // Create a root command:
- root = GPIB_InitializeCommand( root, "root" , NULL, GPIB_DUMMY_FUNCTION, 16, FALSE );
- // -------------------------------------------------------------------------------------------------
- // Mandatory commands, add as a child of root command:
- GPIB_AddChildCommand( root, "*IDN?", "*IDN?", GPIB_Identification , 0, FALSE);
- GPIB_AddChildCommand( root, "*CLS" , "*CLS" , GPIB_Clear , 0, FALSE);
- GPIB_AddChildCommand( root, "*RST" , "*RST" , GPIB_Reset , 0, FALSE);
- GPIB_AddChildCommand( root, "*ESE" , "*ESE" , GPIB_EventStatusEnable , 0, TRUE );
- GPIB_AddChildCommand( root, "*ESR" , "*ESR" , GPIB_EventStatusRegister , 0, TRUE );
- GPIB_AddChildCommand( root, "*STB" , "*STB" , GPIB_StatusRegister , 0, TRUE );
- GPIB_AddChildCommand( root, "*SRE" , "*SRE" , GPIB_StatusEnableRegister, 0, TRUE );
- GPIB_AddChildCommand( root, "*TRG" , "*TRG" , GPIB_Trigger , 0, FALSE); // ?
- GPIB_AddChildCommand( root, "*WAI" , "*WAI" , GPIB_Wait , 0, FALSE); // ?
- GPIB_AddChildCommand( root, "*OPC" , "*OPC" , GPIB_OperationComplete , 0, TRUE );
- // -------------------------------------------------------------------------------------------------
- // Child commands of root:
- sScpiCommand_t * gpib_Mem =
- GPIB_AddChildCommand( root, "MEMORY", "MEM", GPIB_DEF_FUNCTION , 1, FALSE );
- // -------------------------------------------------------------------------------------------------
- // Child commands of "MEMORY":
- sScpiCommand_t * gpib_MemTable =
- GPIB_AddChildCommand( gpib_Mem, "TABLE", "TABL", GPIB_DEF_FUNCTION , 12, FALSE );
- // -------------------------------------------------------------------------------------------------
- // Create child commands for "MEMORY:TABLE":
- GPIB_AddChildCommand( gpib_MemTable, "POINTS", "POIN", GPIB_MemoryTablePoints , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "DATE", "DATE", GPIB_MemoryTableDate , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "TIME", "TIME", GPIB_MemoryTableTime , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "TEMPERATURE", "TEMP", GPIB_MemoryTableTemp , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "CONNECTOR", "CONN", GPIB_MemoryTableConnector, 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "ADAPTER", "ADAP", GPIB_MemoryTableAdapter , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "ANALYZER", "ANAL", GPIB_MemoryTableAnalyzer , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "OPERATOR", "OPER", GPIB_MemoryTableOperator , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "PLACE", "PLAC", GPIB_MemoryTablePlace , 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTable, "DATA", "DATA", GPIB_MemoryTableData , 0, TRUE );
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "MEMORY:TABLE":
-
- sScpiCommand_t * gpib_MemTableTher =
- GPIB_AddChildCommand( gpib_MemTable, "THERMO", "THER", GPIB_DEF_FUNCTION , 1, FALSE );
-
- sScpiCommand_t * gpib_MemTableTherCorr =
- GPIB_AddChildCommand( gpib_MemTableTher, "CORRECTION", "CORR", GPIB_DEF_FUNCTION , 4, FALSE );
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "MEMORY:TABLE:THERMO:CORRECTION":
-
- //GPIB_MakeSpecialCommand(
- GPIB_AddChildCommand( gpib_MemTableTherCorr,"MAGNITUDE", "MAGN", GPIB_MemTableTherCorrMagniture, 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTableTherCorr,"PHASE" , "PHAS", GPIB_MemTableTherCorrPhase, 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTableTherCorr,"POINTS" , "POIN", GPIB_MemTableTherCorrPoints, 0, TRUE );
-
- sScpiCommand_t * gpib_MemTableTherCorrFreq =
- GPIB_AddChildCommand( gpib_MemTableTherCorr,"FREQUENCY", "FREQ", GPIB_DEF_FUNCTION, 2, FALSE );
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "MEMORY:TABLE:THERMOCOMPENSATION:FREQUENCY":
- GPIB_AddChildCommand( gpib_MemTableTherCorrFreq, "START", "STAR", GPIB_MemTableTherCorrFreqStart, 0, TRUE );
- GPIB_AddChildCommand( gpib_MemTableTherCorrFreq, "STOP" , "STOP", GPIB_MemTableTherCorrFreqStop, 0, TRUE );
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "MEMORY:TABLE":
- sScpiCommand_t * gpib_MemTableFreq =
- GPIB_AddChildCommand( gpib_MemTable, "FREQUENCY", "FREQ", GPIB_DEF_FUNCTION, 5, FALSE );
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "MEMORY:TABLE:FREQUENCY":
-
- // MEMORY:TABLE:FREQUENCY:START?
- GPIB_AddChildCommand( gpib_MemTableFreq, "START", "STAR", GPIB_MemoryTableFreqStart, 0, TRUE ),
- // MEMORY:TABLE:FREQUENCY:STOP?
- GPIB_AddChildCommand( gpib_MemTableFreq, "STOP", "STOP" , GPIB_MemoryTableFreqStop, 0, TRUE ),
-
- // MEMORY:TABLE:FREQUENCY:TYPE?
- GPIB_AddChildCommand( gpib_MemTableFreq, "TYPE", "TYPE", GPIB_MemoryTableFreqType, 0, TRUE );
-
- sScpiCommand_t * gpib_MemTableFreqSegm =
- // MEMORY:TABLE:FREQUENCY:SEGM
- GPIB_AddChildCommand( gpib_MemTableFreq, "SEGM", "SEGM", GPIB_DEF_FUNCTION, 1, FALSE );
-
- // MEMORY:TABLE:FREQUENCY:SEGM:DATA?
- GPIB_AddChildCommand( gpib_MemTableFreqSegm,"DATA", "DATA", GPIB_MemoryTableFreqSegmData,0,TRUE );
-
- // MEMORY:TABLE:FREQUENCY:DATA?
- GPIB_AddChildCommand( gpib_MemTableFreq, "DATA", "DATA", GPIB_MemoryTableFreqData, 0, TRUE );
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of root:
- sScpiCommand_t * gpib_DeviceDependent =
- GPIB_AddChildCommand( root, "MEASURE", "MEAS", GPIB_DEF_FUNCTION, 1, FALSE); //root function 8
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "MEASURE":
- GPIB_AddChildCommand( gpib_DeviceDependent, "TEMPERATURE", "TEMP", GPIB_GetTemperature, 0, TRUE); //C÷èòûâàåò òåìïåðàòóðó âíóòðè êàëèáðîâî÷íîãî ìîäóëÿ (òîëüêî çàïðîñ).
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of root:
- sScpiCommand_t * gpib_Interface =
- GPIB_AddChildCommand( root, "INTERFACE", "INT", GPIB_DEF_FUNCTION, 1, FALSE ); //root function 7
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "INTERFACE":
- GPIB_AddChildCommand( gpib_Interface, "SWITCH", "SW", GPIB_InterfaceSwitch, 0, TRUE );
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of root:
- sScpiCommand_t * gpib_System =
- GPIB_AddChildCommand( root, "[SYSTEM]", "[SYST]", GPIB_DEF_FUNCTION, 3, FALSE ); //root function 4
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "SYSTEM":
- GPIB_AddChildCommand( gpib_System, "VERSION?", "VERS?", GPIB_SystemVersion, 0, FALSE );
- sScpiCommand_t * gpib_SystemErr =
- GPIB_AddChildCommand( gpib_System, "ERROR", "ERR", GPIB_SystemError, 2, TRUE );
- sScpiCommand_t * gpib_Source =
- GPIB_AddChildCommand( gpib_System, "[SWITCH]", "[SWIT]", GPIB_DEF_FUNCTION, 3, FALSE ); //root function 9
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "SYSTEM:ERR":
- GPIB_AddChildCommand( gpib_SystemErr, "NEXT?", "NEXT?", GPIB_SystemError, 0, FALSE);
- GPIB_AddChildCommand( gpib_SystemErr, "ALL?", "ALL?", GPIB_SystemErrorAll, 0, FALSE);
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "SYSTEM:SWITCH"
- GPIB_AddChildCommand( gpib_Source, "COUNT", "COUN", GPIB_SwitchCount, 0, TRUE );
- GPIB_AddChildCommand( gpib_Source, "STATE", "STAT", GPIB_SwitchState, 0, TRUE );
- GPIB_AddChildCommand( gpib_Source, "LIST", "LIST", GPIB_SwitchList, 0, TRUE );
- // ---------------------------------------------------------------------------------------------------------------
-
- // Child commands of root:
- // sScpiCommand_t * gpib_Status =
- // GPIB_AddChildCommand( root, "STATUS", "STAT", GPIB_DEF_FUNCTION, 3, FALSE ); //root function 5
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "STATUS":
- // GPIB_AddChildCommand( gpib_Status, "PRESET", "PRES", GPIB_StatusPreset, 0, FALSE ); // No Subcomands
- // sScpiCommand_t * gpib_StatusOperation =
- // GPIB_AddChildCommand( gpib_Status, "OPERATION", "OPER", GPIB_StatusOperationEvent, 3, TRUE ); // 3 Subcommands, Request Enable -> EVENt?
- // sScpiCommand_t * gpib_StatusQuestionable =
- // GPIB_AddChildCommand( gpib_Status, "QUESTIONABLE","QUES", GPIB_StatusQuestionableEvent, 3, TRUE ); // 3 Subcommands, Request Enable -> EVENt?
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "STATUS:OPERATION":
- // GPIB_AddChildCommand( gpib_StatusOperation, "EVENT?", "ENENt?", GPIB_StatusOperationEvent, 0, FALSE ); // No Subcomands, Request Only
- // GPIB_AddChildCommand( gpib_StatusOperation, "CONDition?", "COND?", GPIB_StatusOperationCondition, 0, FALSE ); // No Subcomands, Request Only
- // GPIB_AddChildCommand( gpib_StatusOperation, "ENABLE", "ENAB", GPIB_StatusOperationEnable, 0, TRUE ); // No Subcomands, Request enable
- // ---------------------------------------------------------------------------------------------------------------
- // Child commands of "STATUS:QUESTIONABLE":
- // GPIB_AddChildCommand( gpib_StatusQuestionable, "EVENT?", "ENENt?", GPIB_StatusQuestionableEvent, 0, FALSE ); // No Subcomands, Request Only
- // GPIB_AddChildCommand( gpib_StatusQuestionable, "CONDition?","COND?", GPIB_StatusQuestionableCondition, 0, FALSE ); // No Subcomands, Request Only
- // GPIB_AddChildCommand( gpib_StatusQuestionable, "ENABLE", "ENAB", GPIB_StatusQuestionableEnable, 0, TRUE ); // No Subcomands, request enable
- // ---------------------------------------------------------------------------------------------------------------
-
- return root;
- }
- // GPIB_TrimCommand:
- // Removes either the leading and trailing white characters from the command string
- // Returns the length of command
- int GPIB_TrimCommand( char * begin, char * end, char * * pCmdStart, char * * pCmdEnd )
- {
-
- // check the input pointers
- if( NULL == end || NULL == begin || NULL == pCmdStart || NULL == pCmdEnd )
- return -1;
-
- if( SubPointers(end, begin) <= 0 )
- return -1;
- // Skip leading white characters
- while( IsWhiteOrEndChar( *begin ) )
- {
- begin++;
- }
-
- // Skip trailing white characters
- do
- {
- end--;
- }
- while( IsWhiteOrEndChar( *end ) );
-
- end++;
-
- *pCmdEnd = end;
- *pCmdStart = begin;
-
- return SubPointers( end, begin );
- }
- // GPIB_SearchCommand:
- // Searches for the end of command in the string @begin til the @end.
- // @ppCmdEnd - the pointer to the receiving cell of pointer to the end of command
- // Note: the function processes GPIB strings and GPIB datablocks.
- int GPIB_SearchCommand( const char * begin, const char * end, const char * * ppCmdEnd )
- {
- // check the input pointers
- if( NULL == end || NULL == begin )
- return -1;
-
- // check the input pointers
- if( SubPointers(end, begin) <= 0 )
- return -1;
-
- const char * iter = begin;
- const char * near;
-
- do
- {
- // Search for special characters in the string since @iter til the @end
- const char * separator = GPIB_StrChr( iter, GPIB_CHAR_CMDSEPARATOR_SIGN, end ); // search for the command separator
- const char * datablock = GPIB_StrChr( iter, GPIB_CHAR_DATATABLE_SIGN, end ); // search for the datablock
- const char * squote = GPIB_StrChr( iter, GPIB_CHAR_SINGLEQUOTE_SIGN, end ); // search for the quoted string
- const char * dquote = GPIB_StrChr( iter, GPIB_CHAR_DOUBLEQUOTE_SIGN, end ); // search for the quoted string
-
- // Select the first faced special character in the string since @iter til the @end
- near = ChooseLowestPtrConst( squote, dquote );
- near = ChooseLowestPtrConst( near, separator );
- near = ChooseLowestPtrConst( near, datablock );
-
- // check the simplest case: no separator characters found (and any other special characters)
- if( NULL == near )
- {
- // the whole string [@begin ... @end] is a command
- if( NULL != ppCmdEnd ) *ppCmdEnd = end;
-
- // return the length of command
- return SubPointers( end, begin );
- }
-
- // check if the first command does contain neither datablock or quotes
- // In this case a separator is faced first
- if( separator == near )
- {
- // the string [@iter ... @separator] is a command
- if( NULL != ppCmdEnd ) // fixed: 23/08/18
- {
- *ppCmdEnd = separator;
- }
-
- // return the length of command
- return SubPointers( separator, iter );
- }
-
- // check if the double quote is faced first
- if( dquote == near )
- {
- // the string contains GPIB string. It is required to skip it.
-
- // search a closing quote
- dquote = GPIB_StrChr( iter, GPIB_CHAR_DOUBLEQUOTE_SIGN, end );
-
- if( NULL == dquote )
- {
- // error: unpaired quote found
- return -1;
- }
- // skip the quoted string
- iter = (dquote + 1);
-
- continue;
- }
-
- // check if the single quote is faced first
- if( squote == near )
- {
- // the string contains GPIB string. It is required to skip it.
-
- // search a closing quote
- squote = GPIB_StrChr( iter, GPIB_CHAR_SINGLEQUOTE_SIGN, end );
-
- if( NULL == squote )
- {
- // error: unpaired quote found
- return -1;
- }
- // skip the quoted string
- iter = (squote + 1);
-
- continue;
- }
-
- // check if the datablock is faced first
- if( datablock == near )
- {
- size_t nDataBlock;
-
- // check if it is valid datablock
- if( IsDataBlock( datablock, SubPointers(end, datablock), &nDataBlock, NULL ) )
- {
- // datablock is valid
-
- // skip datablock
- iter = (datablock + nDataBlock);
- }
- else
- {
- // datablock is invalid
-
- // skip the datablock signature
- // maybe, it is not datablock.
- iter = (datablock + 1);
- }
-
- continue;
- }
- }
- // continue until the end of string (@end is reached)
- // and interrupt in case @near is null.
- while( (NULL != near) && SubPointers(end, iter) > 0 );
-
- // no separator found
-
- if( NULL != ppCmdEnd ) *ppCmdEnd = end;
-
- // the whole string is a command
- // return the length of command
- return SubPointers( end, begin );
- }
- // -----------------------------------
- // GPIB_CommandExecute() âûïîëíåíèå ñòðîêè êîììàíä GPIB.
- // root - óêàçàòåëü íà root êîììàíäó äåðåâà êîììàíä
- // GPIB_Commands_String - óêàçàòåëü íà ñòîêó êîììàíä GPIB, ðàçäåëåííûõ òî÷êîé ñ çàïÿòîé
- int GPIB_CommandExecute( USB_DEVICE_INFO * udi, const char * input_str )
- {
- size_t length = udi->BulkMessageStatus.OutTransferSize; // get the input string length
-
- char * iter = GPIB_StrCopyToCache( input_str, length ); // bufferize the string into internal cache
- // now @iter points to the cached string
- if( NULL == iter ) // Check if the string is cached successfully
- return -1; // error: cache overflow
-
- char * end = iter + length; // end of input string
-
- // Check the end of string: check the last character
- if( GPIB_CHAR_ENDLINE_SIGN == *(end-1) )
- {
- // Shift @end back for one character
- // Now: @end points to end-of-line character
- end --;
- }
- else
- {
- // error: end-of-line character not found.
- // Maybe, input string is too long.
- return -1;
- }
- //--------------------------------------------------------------------------
- sScpiCommand_t * xResult; // pointer to the processed command
- sScpiCommand_t * pCmdRoot = udi->usbtmcGpib.gpib_root; // root-command
- sScpiCommand_t * pCmdSearch = pCmdRoot; // search pointer in the tree
- //--------------------------------------------------------------------------
- udi->usbtmcGpib.cRequestCountSupport = 1;
- //--------------------------------------------------------------------------
- udi->usbtmcGpib.gpib_owner = pCmdRoot; // search in ROOT by default
- //--------------------------------------------------------------------------
- size_t nCmdProcessed = 0; // count of processed commands
- int nCmdLength = 0;
-
-
- do
- {
- // Skip the only first command separator
- if( GPIB_CHAR_CMDSEPARATOR_SIGN == *iter )
- {
- iter++;
- }
-
- // Search for the end of the command
- nCmdLength = GPIB_SearchCommand( iter, end, NULL );
-
- if( nCmdLength > 0 )
- {
- char * cmdStart;
- char * cmdEnd;
-
- // Trim the command
- if( GPIB_TrimCommand( iter, (iter + nCmdLength), &cmdStart, &cmdEnd ) > 0 )
- {
- if( GPIB_CHAR_MANDATORY_IEEE488_SIGN == *cmdStart )
- {
- pCmdSearch = pCmdRoot; // change the search pointer to the root
- }
- else
- if( GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN == *cmdStart )
- {
- pCmdSearch = pCmdRoot; // change the search pointer to the root
- cmdStart++; // skip subsystem separator
- }
-
- udi->usbtmcGpib.gpib_search = pCmdSearch;
- udi->usbtmcGpib.sgpib_current = cmdStart;
- xResult = GPIB_Parse( udi, cmdStart, FALSE, cmdEnd );
-
- if( NULL != xResult )
- {
- // Success
- nCmdProcessed++; // increment the processed command counter
- }
- else
- {
- // Error
-
- // Form a error message
- /* 27/08/18 if(usbtmc_RaiseError( udi, GPIB_ERROR_ID_EXE, ERROR_USBTMC_INVALID_HEADER, "'", 1)) */
- if(usbtmc_RaiseError( udi, errClass_Command, ERROR_USBTMC_INVALID_HEADER, "'", 1))
- {
- if(usbtmc_RaiseError_CatDescription( udi, cmdStart, SubPointers(cmdEnd, cmdStart) ) )
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1 ) )
- {
- usbtmc_ErrorQueue_RestoreCheckpoint( udi );
- }
- }
- else
- usbtmc_ErrorQueue_RestoreCheckpoint( udi );
- }
- else
- usbtmc_ErrorQueue_RestoreCheckpoint( udi );
-
- xResult = pCmdSearch;
- }
-
- pCmdSearch = xResult; // set the search point for the next command
-
- iter += nCmdLength;
- }
- else break;
- }
- }
- while( nCmdLength > 0 );
-
- return nCmdProcessed;
- }
- //
- //// -----------------------------------
- //// GPIB_CommandExecute() âûïîëíåíèå ñòðîêè êîììàíä GPIB.
- //// root - óêàçàòåëü íà root êîììàíäó äåðåâà êîììàíä
- //// GPIB_Commands_String - óêàçàòåëü íà ñòîêó êîììàíä GPIB, ðàçäåëåííûõ òî÷êîé ñ çàïÿòîé
- //int GPIB_CommandExecute( USB_DEVICE_INFO * udi, char * str ) {
- // // ----------------------------------------------------------------------------------------------------------
- //
- // sScpiCommand_t * rc; // -- óêàçàòåëü íà âûïîëíåííóþ êîììàíäó
- // sScpiCommand_t * root = udi->usbtmcGpib.gpib_root; // -- êîðíåâàÿ êîììàíäà äðåâà êîììàíä
- // sScpiCommand_t * Search=root; // -- óêàçàòåëü íà òåêóùèé "ïóòü" ïîèñêà êîììàíäû
- ////-----------------------------------------------------
- // unsigned int datatablesize = 0; // -- ðàçìåð òàáëèöû äàííûõ
- // unsigned int strl; // -- ðàçìåð âõ ñòðîêè
- // unsigned int ret_val = 0; // -- âîçâðàùàåìîå çíà÷åíèå êîëè÷åñòâà ðàñïîçíàííûõ êîììàíä
- ////-----------------------------------------------------
- // BOOL datatable_found; // -- òàáëèöà äàííûõ íàéäåíà â ñòðîêå
- ////-----------------------------------------------------
- // char * semicolon=NULL; // -- óêàçàòåëü íà ðàçäåëèòåëü êîììàíä, åñëè òàêîé åñòü â ñòðîêå
- // char * datatable; // -- óêàçàòåëü íà òàáëèöó äàííûõ
- // char * stre; // -- êîíåö ñòðîêè
- // char * cmde; // êîíåö êîììàíäû,
- // char * gstre; // -- êîíåö ñòðîêè GPIB ("")
- // char * squote; // -- êàâû÷êè ñòðîêè GPIB
- // char * dquote; // -- êàâû÷êè ñòðîêè GPIB
- // char * quote; // -- êàâû÷êè ñòðîêè GPIB
- ////-----------------------------------------------------
- //
- // // -------------------------------
- // udi->usbtmcGpib.gpib_owner = root; // -- ïîèñê â root
- // // -------------------------------
- // udi->usbtmcGpib.cRequestCountSupport = 1; // -- òîëüêî îäèí çàïðîñ â ñòðîêå
- // // -------------------------------------------
- // strl = udi->BulkMessageStatus.OutTransferSize; // -- äëèííà ïåðåäàííîé ñòðîêè êîììàíä
- // str = GPIB_StrCopyToCache( str, strl ); // -- äîáàâëÿåò íóëü ñèìâîë ê êîíöó ñòðîêè
- // stre = str + strl - 1; // -- êîíåö ñòðîêè. äî 0x0A
- // if(str == NULL) return -1; // -- ÎØÈÁÊÀ ! ÍÅÒ ÏÀÌßÒÈ!
- // // -------------------------------------------
- //
- //
- // // ------- ÈÍÈÖÈÀËÈÇÀÖÈß ÏÅÐÅÄÀ×È ------
- // // ïðîèçâåäåíà â DEV_DEP_MSG_OUT()
- // // -------------------------------------
- //
- // strucase( str, strl); // -- ïåðåâîäèì ñòðîêó â ÂÅÐÕÍÈÉ ÐÅÃÈÑÒÐ
- //
- // while( *str || semicolon != NULL) // -- ïîêà íå äîøëè äî êîíöà ñòðîêè
- // {
- // gstre = str;
- //
- // // ----------------------------------------------------------------------------------------
- // // -- ïðîïóñê ñòðîêè GPIB
- // do
- // {
- //
- // datatable = GPIB_StrChr_rw( gstre, GPIB_CHAR_DATATABLE_SIGN, stre ); // +ïîèñê ñèãíàòóðû òàáëèöû äàííûõ
- // semicolon = GPIB_StrChr_rw( gstre, GPIB_CHAR_CMDSEPARATOR_SIGN, stre ); // +ïîèñê ðàçäåëèòåëÿ êîììàä
- // squote = GPIB_StrChr_rw( gstre, GPIB_CHAR_SINGLEQUOTE_SIGN, stre ); // +ïîèñê ñòðîêè GPIB
- // dquote = GPIB_StrChr_rw( gstre, GPIB_CHAR_DOUBLEQUOTE_SIGN, stre ); // +ïîèñê ñòðîêè GPIB
- //
- // if(quote = ChooseLowestPtr(squote,dquote)) // -- âîçâðàùàåò íàèáëèæàéøèé óêàçàòåëü (íàèìåíüøèé, åñëè îáà íå NULL. Åñëè îäèí NULL, âîçâðàùàåò âòîðîé)
- // if( quote == ChooseLowestPtr( quote, semicolon ) ) // -- åñëè íà ïóòè ñòðîêà GPIB (êîòîðàÿ ìîæåò ñîäåðæàòü ';')
- // gstre = GPIB_GetStringEnd_rw( quote, strl - SubPointers(quote, str) ); // -- èùåì åå êîíåö
- // else
- // gstre = NULL;
- // else
- // gstre = NULL;
- //
- // }
- // while( gstre != NULL );
- // // ----------------------------------------------------------------------------------------
- //
- // // íóæíî ðàçäåëèòü ñòðîêó íà êîììàíäû, (ðàçäåëèòåëü ;) ïðè÷åì, ó÷åñòü, ÷òî
- // // ïîñëå êàæäîé êîììàíäû ìîãóò áûòü äàííûå è ÒÀÁËÈÖÛ äàííûõ òèïà #NZZZ..ZBBBBBB...B (ñì GPIB)
- // // èëè GPIB ñòðîêè, çàêëþ÷åííûå â êàâû÷êè ("") èëè (' ').
- // // Äëÿ ýòîãî íóæíî ïðîïàðñèòü òàáëèöû, òàê êàê îíè ìîãóò ñîäåðæàòü ðàçäåëèòåëü (;)
- // // à òàêæå ñòðîêè GPIB, îíè òîæå ìîãóò ñîäåðæàòü âñå ÷òî óãîäíî
- //
- // // =================================================================================================================
- //
- //
- // // ---------- ïðîïóñê òàáëèö äàííûõ -----------------------------
- //
- // datatable_found = FALSE;
- // if(datatable!=NULL && (semicolon==NULL || ((unsigned int)semicolon> (unsigned int)datatable))) // åñëè ñèãíàòóðà îáíàðóæåíà è îíà ðàíüøå ðàçäåëèòåëÿ
- // {
- // if(IsNUMBER(*(datatable+1))) // -- åñëè çà # ñëåäóåò öèôðà N ( öèôðà îïðåäåëÿåò äëèííó ÷èñëà ñëåäîì çà íåé )
- // {
- // datatable_found = TRUE; // -- òàáëèöà äàííûõ îáíàðóæåíà
- // // -- åñëè çà # è öèôðîéN ñëåäóåò N öèôð, òî ýòî çàãîëîâîê òàáëèöû äàííûõ
- // for( int m=1 ; datatable_found && (m<=(HexCharToNumber(*(datatable+1)))) ; m++)
- // if( !IsNUMBER( *(datatable+1+m) ) ) // -- ïðîâåðÿåì ÷òî âñå ýòî öèôðû
- // datatable_found = FALSE; // -- âûõîä èç öèêëà (ñì çàãîëîâîê for)
- // }
- // }
- // else
- // datatable_found = FALSE; // -- òàáëèà äàííûõ íå îáíàðóæåíà
- // // -------------------------------------------------------------
- //
- //
- // if(datatable_found==FALSE) // -- åñëè íå îáíàðóæåíà òàáëèöà èëè ðàçäåëèòåëü ðàíüøå òàáëèöû
- // {
- // if(semicolon!=NULL)
- // {
- // *semicolon = 0x00; // -- äåëèì êîììàíäó
- // cmde = semicolon;
- // }
- // else
- // cmde = stre; // -- êîíåö ñîîáùåíèÿ
- // }
- // else
- // {
- // semicolon = NULL;
- // char * data;
- // datatablesize = 0;
- // datatable++; // -- ïðîïóñêàåì # //str++; //!#! #!#
- //
- //
- // int n = HexCharToNumber(*(datatable)); // +öèôðà N îïðåäåëÿåò êîëè÷åñòâî öèôð ïîñëå #NZZZZZBBBBBBBBBBB
- // // +N - êîëè÷åñòâî Z
- // // +Z - öèôðû ñîñòàâëÿþò ÷èñëî, êîòîðîå îïðåäåëÿåò äëèííó òàáëèöû ( êîëè÷åòñâî B )
- // data = datatable + n + 1; // +óñòàíàâëèâàåì óêàçàòåëü íà íà÷àëî òàáëèöû
- // datatable++; // +óñò óêàçàòåëü íà íà÷àëî ÷èñëà ZZZZ
- // StrToInt( datatable, n, &n ); // +êîíâåðòèóåì ÷èñëî çàïèñàííîå â ZZZZ â str â ÷èñëî â int â n
- //
- // // --- òàáëèöà äàííûõ íà÷èíàåòñÿ ñ datatable è äëèííà åå n
- //
- // datatable += n+1; // +ïðûãàåì ê êîíöó òàáëèöû äàííûõ !#!
- // cmde = datatable;
- // semicolon = GPIB_StrChr_rw( datatable, GPIB_CHAR_CMDSEPARATOR_SIGN, stre); // +èùåì ðàçäåëèòåëü ñíîâà, íî óæå ïîñëå òàáëèöû äàííûõ
- // if(semicolon == datatable) datatable++; // +åñëè îí ñðàçó ïîñëå òàáëèöû, ïðîñïóñêàåì åãî, ÷òîáû íå âûïîëíÿòü ïóñòóþ êîììàíäó
- //
- // datatable = data;
- // datatablesize = n;
- // }
- // // =================================================================================================================
- //
- // if(datatable_found==TRUE)
- // if(datatablesize>0)
- // ;
- //
- //
- // while( IsWhiteChar( *str ) ) str++; // -- ïðîïóñê WHITE
- //
- // if( *str == GPIB_CHAR_MANDATORY_IEEE488_SIGN || (*str == GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN && (str++)) ) Search = root;
- // /* ïðîâåðÿì, àáñîëþòíûé ëè ïóòü çàäàí
- // FAQ: åñëè ïóòü àáñ., îí èìååò äâîåòî÷èå â íà÷àëå. Åñëè åñòü äâîåòî÷èå,
- // òî ïåðâîå óñëîâèå â if() âûïîëíèòñÿ è âûïîëíèòñÿ âòîðîå,
- // êîòîðîå ïî ñóòè ïðîñòî ñäâèíåò óêàçàòåëü str òàê, ÷òîáû èñêëþ÷èòü äâîåòî÷èå
- // ïîèñê áóäåò ïðîèçâåäåí â root, òàê êàê ïóñòü àáñîëþòíûé */
- //
- // udi->usbtmcGpib.gpib_search = Search;
- // udi->usbtmcGpib.sgpib_current = str;
- //
- //
- //
- // if(NULL != (rc=parse( udi,str, FALSE, cmde)))
- // { // -- îáðàáîòêà îäíîé ñîñòàâíîé êîììàíäû â ñòðîêå
- //
- // ret_val++; // -- èíêðåìåíòèðóåì ñ÷åò÷èê âûïîëíåííûõ êîììàíä
- //
- // }
- // else
- // {
- //
- // if( SubPointers( cmde, str ) > 0 ) // if( INT(cmde) - INT(str) > 0 )
- // { char * tmpe = cmde;
- // if( IsEndOfLine(*tmpe) ) tmpe--;
- // while( IsWhiteChar(*tmpe) ) tmpe--;
- // if(usbtmc_RaiseError( udi, GPIB_ERROR_ID_EXE ,ERROR_USBTMC_INVALID_HEADER, "'", 1))
- // if(usbtmc_RaiseError_CatDescription( udi, str , SubPointers( tmpe+1, str ) )) // strl ïîäñ÷èòûâàåòñÿ â íà÷àëå ô-èè. -1 -ýòî ïðîïóñê 0x0A; àëñî: (INT(tmpe+1) - INT(str)) ===> SubPointers( tmpe+1, str )
- // usbtmc_RaiseError_CatDescription( udi, "'", 1 );
- //
- // }
- //
- // rc= Search;
- // }
- //
- //
- //
- // if( semicolon != NULL ) { // -- åñëè íå NULL, çíà÷èò åñòü åùå íå âûïîëíåííûå êîìàíäû â ñòðîêå
- // str = (++semicolon); // -- ïåðåõîä ê ñëåäóþùåé êîììàíäå â ñòðîêå, èñêëþ÷àÿÿ òî÷êó ñ çàïÿòîé
- // if( *str != GPIB_CHAR_SCPI_SUBSYS_SEPARATOR_SIGN ) // -- åñëè êîììàíäà íå àáñîëþòíàÿ è ïóòü åå îïóùåí
- // Search = rc; // -- óêàçûâàåì ïóòü ïîèñêà íà ïîñëåäíèé ïóòü, ãäå áûëà âûïîëíåíà êîììàíäà
- // } else break; // -- åñëè NULL âûõîäèì, íåò áîëüøå êîììàíä â ñòðîêå
- //
- // }
- //
- // return ret_val; // -- âîçâðàùàåì êîëè÷åñòâî ðàñïîçíàííûõ êîììàíä
- //}
- // =========================================== ÎÁÐÀÁÎÒ×ÈÊÈ ======================================================
- unsigned int GPIB_Default_Handler( USB_DEVICE_INFO * udi, QUEUE * pQParameters, BOOL request )
- {
- // 27/08/18
- GPIB_RaiseStandartError( udi,
- ERROR_GPIB_UNCOMPLETE_COMMAND,
- NULL,
- errClass_Command // == invalid header detected
- );
- /*
- GPIB_RaiseStandartError( udi,
- ERROR_GPIB_UNCOMPLETE_COMMAND,
- NULL,
- GPIB_ERROR_ID_COR | request
- );
- */
- return 0;
- }
- // ====================================================================================================
- // GPIB_EnumParameters:
- // Processes the @pParamString with @length length and parses the command parameters.
- // The following SCPI types are supported:
- // - NR1, NR2, NR3
- // - Mnemonic (character)
- // - Strings
- // - binary DataBlock
- // All the parameters are packed into the @pQueue
- // In case an error occurred, the function interrupts processing and return an error code.
- // Note: in case of error the @pQueue is already modified.
- // @pParamString - the source string
- // @length - the length of @pParamString
- // @pQueue - the queue to pack parameters in
- // @pEnd - (NOT IMPLEMENTED!) optional pointer to store the end of parsed string after parsing. Can be NULL.
- // If @pEnd isn't NULL, it will contain the pointer to the character after the lastest parsed character in @pParamString.
- // Return: error code (negative) or number of parsed parameters (positive)
- int GPIB_EnumParameters( const char * pParamString, size_t length, QUEUE * pQueue, const char ** pEnd )
- {
- if( NULL == pParamString || 0 == length || NULL == pQueue )
- return -1;
-
- if( NULL != pEnd )
- {
- *pEnd = NULL; // not implemented
- }
-
- int rval = 0;
-
- int nsys = 0; // numeric system
- size_t count = 0; // amount of parameters enumerated
- eQuoteMode_t qMode; // quoting mode (single/double)
- eParameterType_t eParamType = eParTypeNone; // parameter type
- const char * pParamStart = NULL; // the parameter start pointer in @pParamString
- const char * end = NULL;
- BOOL bSeparator = FALSE; // flag: separator found
-
- while( length > 0 ) // parameter search cycle
- {
- bSeparator = FALSE; // clear flag: allow a separator character in this search cycle
-
-
- // ---------------------------------------------------------------------
- while( length > 0 ) // white characters skipping cycle
- {
- // check current character: is it a white character?
- if( IsWhiteChar( *pParamString ) )
- {
- // yes. skip this character
- pParamString++;
- length--;
-
- // check the next character
- continue;
- }
-
- // check current character: is this a end-of-line character?
- if( IsEndOfLine( *pParamString ) )
- {
- // yes. skip this character
- pParamString++;
- length--;
-
- // if the line ends and the length is still greater than zero:
- // it is an error condition
- if( length > 0 )
- {
- // interrupt all procedures and exit
- rval = (-1);
- goto L_EnumParameters_EXIT;
- }
-
- // Okay, @length is 0.
- // The next "continue" will interrupt the main cycle.
-
- // But let's check the @bSeparator.
- // If @bSeparator is TRUE, it means a trailing separator found.
- if( bSeparator )
- {
- // error: trailing separator found
- rval = (-2);
- goto L_EnumParameters_EXIT;
- }
-
- // exit the main cycle, because @length == 0
- goto L_EnumParameters_EXIT;
- }
-
-
- // check if this character is an argument separator character (by default is ',')
- if( GPIB_CHAR_ARGSEPARATOR_SIGN == *pParamString )
- {
- // Yes: it is an argument separator
-
- // check if the separator is allowed now
-
- // If @bSeparator is already TRUE then it means the separator is disallowed
- // Otherwise, the separator is allowed.
- if( ! bSeparator )
- {
- bSeparator = TRUE; // set the flag: the separator is found in current cycle
-
- pParamString++; // skip the character
- length--;
-
- // check the next character
- continue;
- }
- else
- {
- // No: the separator is already found before.
- // Extra separator found: error
-
- // interrupt all procedures and exit
- rval = (-3);
- goto L_EnumParameters_EXIT;
- }
- }
- else
- {
- // No: it's neither a white character or separator character
-
- // interrupt the skipping cycle.
- break;
- }
-
- } // :while( length > 0 )
- // ---------------------------------------------------------------------
-
- // White character are skipped.
- // An argument separator processed.
- // It is assumed that the next character is an argument.
-
- // check if the argument separator presents between arguments
- if( (count > 0) && (!bSeparator) )
- {
- // In this point @bSeparator must be TRUE in order all the arguments
- // must be separated.
- // The only one exception: @count == 0, it means neither argument or
- // or separator found yet in the string.
-
- // interrupt all procedures and exit
- rval = (-4);
- goto L_EnumParameters_EXIT;
- }
-
- // ---------------------------------------------------------------------
- // Analyze the current character and check for the string type
- switch( *pParamString )
- {
- // the quoted string in single quotes
- case GPIB_CHAR_SINGLEQUOTE_SIGN: qMode = eqmSingle; break;
-
- // the quoted string in double quotes
- case GPIB_CHAR_DOUBLEQUOTE_SIGN: qMode = eqmDouble; break;
-
- // not quoted argument
- default: qMode = eqmNone;
- }
- //
- // ---------------------------------------------------------------------
- //
- // Let's determine the parameter type
- //
-
- size_t nParamSize; // parameter size in [characters]
-
- // if the quoted string is found:
- if( IsQuote( *pParamString , qMode ) )
- {
- // search for the end of quoted string
- end = GPIB_GetStringEnd( pParamString, length );
-
- // check if the string is closed
- if( NULL == end )
- {
- // error: unclosed quoted string
-
- // interrupt all procedures and exit
- rval = (-5);
- goto L_EnumParameters_EXIT;
- }
-
- // calculate the parameter size in characters
- nParamSize = (size_t)SubPointers( end, pParamString );
-
- // set the parameter start pointer
- pParamStart = pParamString;
-
- // skip the parameter's body in the parent string.
- length -= nParamSize;
- pParamString += nParamSize;
-
- // And at last, set the parameter type to @eParamType. It is string.
- eParamType = eParTypeString;
-
- // modify the parameter value: "STR" -> STR
- // delete quotes:
- pParamStart++; nParamSize-=2;
-
- // stop analyzing and process the parameter
- goto L_EnumParameters_END;
- }
-
- // ---------------------------------------------------------------------
-
- // Here: parameter is not a string parameter for sure
- // Maybe it is a mnemonic, numeric or datablock parameter
- {
- // Firstly check for DataBlock format:
-
- // @dataBlockError will store the error code of @IsDataBlock() function
- int dataBlockCode = err_IsDataBlock_Success;
-
- // Check the datablock
- if( IsDataBlock( pParamString, length, &nParamSize, &dataBlockCode ) )
- {
- // datablock detected.
- // Now @nParamSize is the size of whole datablock segment
-
- // set the parameter start pointer
- pParamStart = pParamString;
-
- // --------------------------------------------------------
- // Note: @nParamSize is whole size of data block parameter,
- // including the signature and service fields.
- // --------------------------------------------------------
-
- // skip the parameter's body in the parent string.
- pParamString += nParamSize;
- length -= nParamSize;
-
- // And at last, set the parameter type to @eParamType. It is datablock.
- eParamType = eParTypeDatablock;
-
- // modify the parameter value:
- // Set @pParamStart to the start of binary payload
- // Set @nParamSize to the binary payload size (@dataBlockCode)
- nParamSize = dataBlockCode;
- pParamStart = pParamString - nParamSize;
-
- // stop analyzing and process the parameter
- goto L_EnumParameters_END;
- }
- else
- {
- switch( dataBlockCode )
- {
- // datablock not detected
- case err_IsDataBlock_NotFound:
- break;
-
- // datablock signature detected.
- // Maybe it is not datablock,
- // Maybe it is corrupted parameter
- case err_IsDataBlock_Invalid:
- case err_IsDataBlock_Trimmed:
- case err_IsDataBlock_Huge:
-
- #if 0
- // hmmm. is it error?
- rval = (-6);
- goto L_EnumParameters_EXIT;
- #endif
-
- break;
- }
- }
- }
- // ---------------------------------------------------------------------
-
- // Here: parameter is neither a string parameter or datablock parameter
- // Maybe it is a mnemonic or numeric
- // Ok, search for the end of the parameter
- // search for the end of parameter
- // @GPIB_GetParameterEnd searches til the first white character or the end-of-line.
- end = GPIB_GetParameterEnd( pParamString, length );
-
- // check if the end of the parameter is found
- if( NULL == end )
- {
- // error: endless parameter
-
- // interrupt all procedures and exit
- rval = (-7);
- goto L_EnumParameters_EXIT;
- }
-
- {
- // calculate the parameter size in characters
- nParamSize = (size_t)SubPointers( end, pParamString );
-
- // set the parameter start pointer
- pParamStart = pParamString;
-
- // skip the parameter's body in the parent string.
- length -= nParamSize;
- pParamString += nParamSize;
- }
-
- // Check for "MNEMONIC" parameter type
- if( IsCharacter( *pParamStart ) )
- {
- // First character is an "alhpa-character":
- // So, the parameter will be considered as "MNEMONIC"
-
- // Validate the parameter format:
- if( ! GPIB_StrChkFormat( pParamStart, nParamSize, eSCM_MNEMONIC ) )
- {
- // invalid parameter format: some invalid characters found
-
- // interrupt all procedures and exit
- rval = (-8);
- goto L_EnumParameters_EXIT;
- }
-
- // And at last, set the parameter type to @eParamType. It is MNEMONIC (character-parameter).
- eParamType = eParTypeChar;
-
- // stop analyzing and process the parameter
- goto L_EnumParameters_END;
- }
-
- // ---------------------------------------------------------------------
-
- // Here: parameter is numeric: NR1, NR2 or NR3 (SCPI types)
-
- // Check for NR1:
-
- nsys = 0; // numeric system
-
- // Try to determine the numeric system
- if( IsNumericSystem(pParamStart) )
- {
- // NR1, numeric system specified
-
- // Numeric system detected: get the numeric system base
- nsys = GetNumericSystemBase( pParamStart );
- switch( nsys )
- {
- // unknown system
- case 0:
- rval = (-9);
- goto L_EnumParameters_EXIT;
- break;
-
- // Binary system
- case 2: if( GPIB_StrChkFormat( pParamStart,nParamSize,eSCM_BIN ) )
- {
- // Invalid character for binary system
- rval = (-10);
- goto L_EnumParameters_EXIT;
- }
- break;
-
- // Octal system
- case 8: if( GPIB_StrChkFormat( pParamStart,nParamSize,eSCM_OCT ) )
- {
- // Invalid character for octal system
- rval = (-10);
- goto L_EnumParameters_EXIT;
- }
- break;
-
- // Hexademical system
- case 16:if( GPIB_StrChkFormat( pParamStart,nParamSize,eSCM_HEX ) )
- {
- // Invalid character for hexademical system
- rval = (-10);
- goto L_EnumParameters_EXIT;
- }
- break;
- }
-
- // And at last, set the parameter type to @eParamType. It is NR1 (numeric, integer)
- eParamType = eParTypeNR1;
-
- // stop analyzing and process the parameter
- goto L_EnumParameters_END;
- }
- // ---------------------------------------------------------------------
-
- // Here: parameter is numeric: NR1, NR2 or NR3 (SCPI types)
-
- // Check for NR1
- if( GPIB_StrChkFormat( pParamStart,nParamSize,eSCM_DEC ) )
- {
- eParamType = eParTypeNR1;
-
- // stop analyzing and process the parameter
- goto L_EnumParameters_END;
- }
-
- // Check for NR2
- if( GPIB_StrChkFormat( pParamStart,nParamSize,eSCM_FLOAT ) )
- {
- eParamType = eParTypeNR2;
-
- // stop analyzing and process the parameter
- goto L_EnumParameters_END;
- }
-
- // Check for NR3
- if( GPIB_StrChkFormat( pParamStart,nParamSize,eSCM_EXP ) )
- {
- eParamType = eParTypeNR2;
-
- // stop analyzing and process the parameter
- goto L_EnumParameters_END;
- }
-
- // ---------------------------------------------------------------------
-
- // No valid format detected
- // Here: invalid parameter format
- // Invalid character for binary system
- rval = (-11);
- goto L_EnumParameters_EXIT;
-
- // ---------------------------------------------------------------------
-
- L_EnumParameters_END:
- // Valid format detected:
- // @pParamStart - the beginning of parameter
- // @nParamSize - the size of parameter
- // @eParamType - the type of parameter
- // -------------------------------------------------------------------------
- // Push the parameter into the parameters queue
- {
- BYTE pkdParamType = eParamType; // 1-byte packed parameter type
-
- // push the type
- if( !queue_add( pQueue, &pkdParamType, sizeof(pkdParamType) ) )
- {
- // parameters queue overflow
- rval = (-12);
- goto L_EnumParameters_EXIT;
- }
-
- // push the string value
- if( !queue_cat( pQueue, pParamStart, nParamSize ) )
- {
- // parameters queue overflow
- rval = (-13);
- goto L_EnumParameters_EXIT;
- }
- }
- // increment amount of parsed parameters
- count++;
- }
-
- rval = count;
-
- L_EnumParameters_EXIT:
- return rval;
- }
- // ====================================================================================
- eChrz_t GPIB_GetChrzTableId( const char * pParamText, size_t nTextLen )
- {
- eChrz_t ID = eCh_MAX;
- if( 0 == strncmp( pParamText, "FACT", nTextLen ) && 4 == nTextLen ) ID = eChFactory;
- else
- if( 0 == strncmp( pParamText, "FACTORY",nTextLen ) && 7 == nTextLen ) ID = eChFactory;
- else
- if( 0 == strncmp( pParamText, "USER1", nTextLen ) && 5 == nTextLen ) ID = eChUser1;
- else
- if( 0 == strncmp( pParamText, "USER2", nTextLen ) && 5 == nTextLen ) ID = eChUser2;
- else
- if( 0 == strncmp( pParamText, "USER3", nTextLen ) && 5 == nTextLen ) ID = eChUser3;
- return ID;
- }
- // ====================================================================================
- ePortId_t GPIB_GetPortId( const char * pParamText, size_t nTextLen )
- {
- ePortId_t ID = ePortId_MAX;
- if( 0 == strncmp( pParamText, "A", nTextLen ) && 1 == nTextLen ) ID = ePortId_A;
- else
- if( 0 == strncmp( pParamText, "B", nTextLen ) && 1 == nTextLen ) ID = ePortId_B;
- else
- if( 0 == strncmp( pParamText, "C", nTextLen ) && 1 == nTextLen ) ID = ePortId_C;
- else
- if( 0 == strncmp( pParamText, "D", nTextLen ) && 1 == nTextLen ) ID = ePortId_D;
- return ID;
- }
- // ====================================================================================
- ePortComb_t GPIB_GetPortComb( const char * pParamText, size_t nTextLen )
- {
- ePortComb_t ID = ePortComb_UNDEFINED;
- if( 0 == strncmp( pParamText, "A", nTextLen ) && 1 == nTextLen ) ID = ePortComb_A;
- else
- if( 0 == strncmp( pParamText, "B", nTextLen ) && 1 == nTextLen ) ID = ePortComb_B;
- else
- if( 0 == strncmp( pParamText, "C", nTextLen ) && 1 == nTextLen ) ID = ePortComb_C;
- else
- if( 0 == strncmp( pParamText, "D", nTextLen ) && 1 == nTextLen ) ID = ePortComb_D;
- else
- if( 0 == strncmp( pParamText, "AB", nTextLen ) && 2 == nTextLen ) ID = ePortComb_AB;
- else
- if( 0 == strncmp( pParamText, "AC", nTextLen ) && 2 == nTextLen ) ID = ePortComb_AC;
- else
- if( 0 == strncmp( pParamText, "AD", nTextLen ) && 2 == nTextLen ) ID = ePortComb_AD;
- else
- if( 0 == strncmp( pParamText, "BC", nTextLen ) && 2 == nTextLen ) ID = ePortComb_BC;
- else
- if( 0 == strncmp( pParamText, "BD", nTextLen ) && 2 == nTextLen ) ID = ePortComb_BD;
- else
- if( 0 == strncmp( pParamText, "CD", nTextLen ) && 2 == nTextLen ) ID = ePortComb_CD;
- else
- if( 0 == strncmp( pParamText, "CHEC",nTextLen) && 4 == nTextLen ) ID = ePortComb_CHECK;
- else
- if( 0 == strncmp( pParamText, "CHECK",nTextLen)&& 5 == nTextLen ) ID = ePortComb_CHECK;
- return ID;
- }
- // ====================================================================================
- ePortStateId_t GPIB_GetPortStateId( const char * pParamText, size_t nTextLen )
- {
- ePortStateId_t ID = ePortStateId_UNDEFINED;
- if( 4 == nTextLen && 0 == strncmp( pParamText, "SHOR", nTextLen ) ) ID = ePortStateId_Short;
- else
- if( 5 == nTextLen && 0 == strncmp( pParamText, "SHORT", nTextLen ) ) ID = ePortStateId_Short;
- else
- if( 4 == nTextLen && 0 == strncmp( pParamText, "OPEN", nTextLen ) ) ID = ePortStateId_Open;
- else
- if( 4 == nTextLen && 0 == strncmp( pParamText, "LOAD", nTextLen ) ) ID = ePortStateId_Load;
- else
- if( 5 == nTextLen && 0 == strncmp( pParamText, "OPEN2", nTextLen ) ) ID = ePortStateId_Open2;
- else
- if( 5 == nTextLen && 0 == strncmp( pParamText, "LOAD2", nTextLen ) ) ID = ePortStateId_Load2;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S11", nTextLen ) ) ID = ePortStateId_S11;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S12", nTextLen ) ) ID = ePortStateId_S12;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S13", nTextLen ) ) ID = ePortStateId_S13;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S14", nTextLen ) ) ID = ePortStateId_S14;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S21", nTextLen ) ) ID = ePortStateId_S21;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S22", nTextLen ) ) ID = ePortStateId_S22;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S23", nTextLen ) ) ID = ePortStateId_S23;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S24", nTextLen ) ) ID = ePortStateId_S24;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S31", nTextLen ) ) ID = ePortStateId_S31;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S32", nTextLen ) ) ID = ePortStateId_S32;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S33", nTextLen ) ) ID = ePortStateId_S33;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S34", nTextLen ) ) ID = ePortStateId_S34;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S41", nTextLen ) ) ID = ePortStateId_S41;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S42", nTextLen ) ) ID = ePortStateId_S42;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S43", nTextLen ) ) ID = ePortStateId_S43;
- else
- if( 3 == nTextLen && 0 == strncmp( pParamText, "S44", nTextLen ) ) ID = ePortStateId_S44;
-
- return ID;
- }
- // ====================================================================================
- /*
- EPORT GPIB_GetPortID( char * sQueueParameter, unsigned int dwQueueParameterSize )
- {
- EPORT port = ePORT_NONE;
- if(0==strncmp(sQueueParameter+1,"A",dwQueueParameterSize-1) && dwQueueParameterSize>1) port = ePORT_A;
- else
- if(0==strncmp(sQueueParameter+1,"B",dwQueueParameterSize-1) && dwQueueParameterSize>1) port = ePORT_B;
- else
- if(0==strncmp(sQueueParameter+1,"AB",dwQueueParameterSize-1) && dwQueueParameterSize>2)port = ePORT_AB;
- return port;
- }
- */
- // ====================================================================================
- /*
- ESTATE GPIB_GetKeystateID( char * sQueueParameter, unsigned int dwQueueParameterSize, BOOL ExpandFormat )
- {
- ESTATE state = eSTATE_NONE;
- if(0==strncmp(sQueueParameter+1,"OPEN",dwQueueParameterSize-1) && dwQueueParameterSize>4) state = eSTATE_OPEN;
- else
- if(0==strncmp(sQueueParameter+1,"LOAD",dwQueueParameterSize-1) && dwQueueParameterSize>4) state = eSTATE_LOAD;
- else
- if(0==strncmp(sQueueParameter+1,"SHORT",dwQueueParameterSize-1) && dwQueueParameterSize>4) state = eSTATE_SHORT; //SHOR==SHORt
- else
- if(0==strncmp(sQueueParameter+1,"OPEN2",dwQueueParameterSize-1) && dwQueueParameterSize>5) state = eSTATE_OPEN2;
- else
- if(0==strncmp(sQueueParameter+1,"LOAD2",dwQueueParameterSize-1) && dwQueueParameterSize>5) state = eSTATE_LOAD2;
- else
- if(ExpandFormat == FALSE && 0==strncmp(sQueueParameter+1,"THRU",dwQueueParameterSize-1) && dwQueueParameterSize>4) state = eSTATE_THRU;
- else
- if(ExpandFormat == FALSE && 0==strncmp(sQueueParameter+1,"ATT",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_ATTEN;
- else
- if(ExpandFormat)
- if(0==strncmp(sQueueParameter+1,"T11",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_T11;
- else
- if(0==strncmp(sQueueParameter+1,"T12",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_T12;
- else
- if(0==strncmp(sQueueParameter+1,"T21",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_T21;
- else
- if(0==strncmp(sQueueParameter+1,"T22",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_T22;
- else
- if(0==strncmp(sQueueParameter+1,"A11",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_A11;
- else
- if(0==strncmp(sQueueParameter+1,"A12",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_A12;
- else
- if(0==strncmp(sQueueParameter+1,"A21",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_A21;
- else
- if(0==strncmp(sQueueParameter+1,"A22",dwQueueParameterSize-1) && dwQueueParameterSize>3) state = eSTATE_A22;
- else
- state = eSTATE_NONE;
- return state;
- }
- */
- // ====================================================================================
- unsigned int GPIB_RaiseStandartError( USB_DEVICE_INFO * udi,
- unsigned int errCode, // error code
- const char * pDescription, // error description
- GPIB_ErrorClass_t errClass // error class
- )
- {
- const char * pStrCurrentCmd = udi->usbtmcGpib.sgpib_current;
-
- // search for the command header's end
- while( !(IsWhiteChar( *pStrCurrentCmd ) || IsEndOfLine( *pStrCurrentCmd )) )
- {
- pStrCurrentCmd++;
- }
-
- size_t nCmdLength = SubPointers( pStrCurrentCmd, udi->usbtmcGpib.sgpib_current);
- pStrCurrentCmd = udi->usbtmcGpib.sgpib_current;
-
- switch( errCode )
- {
- case ERROR_GPIB_BUFFER_OVERFLOW:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Execution;
-
- //ERROR_USBTMC_BUFFER_OVERFLOW_IN
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_INTERNAL, " in '", 5 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, "': ", 3 ) )
- {
- errCode = 0; break;
- }
- if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- {
- errCode = 0; break;
- }
- }
- break;
- case ERROR_GPIB_DATA_NOT_FOUND:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Execution;
-
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_DATANOTFOUND, " in '", 5 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, "': ", 3 ) )
- {
- errCode = 0; break;
- }
- if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- {
- errCode = 0; break;
- }
- /*
- if(usbtmc_RaiseError( udi, ErrorIdetnificator, ERROR_USBTMC_DATANOTFOUND, "", 0 ) )
- {
- if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;*/
- }
- break;
- case ERROR_GPIB_THERMDATA_NOT_FOUND:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Execution;
-
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_NOTHERMCOMPDATA, " in '", 5 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, "': ", 3 ) )
- {
- errCode = 0; break;
- }
- if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- {
- errCode = 0; break;
- }
- /*if( !usbtmc_RaiseError( udi, ErrorIdetnificator, ERROR_USBTMC_NOTHERMCOMPDATA, pDescription, strlen(pDescription) ) )
- {
- errCode = 0;
- }*/
- }
- break;
- case ERROR_GPIB_UNCOMPLETE_COMMAND:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Command;
-
- if(usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_INVALID_HEADER, "'", 1 ))
- {
- if( usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1 ) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0;
- }
- break;
-
- /*
- case ERROR_GPIB_PARAMETER_NOT_SUPPORTED:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Execution;
-
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_PARAMETER, " in '", 5 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1 ) )
- {
- errCode = 0; break;
- }
- // if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- // {
- // errCode = 0; break;
- // }
-
- // if(usbtmc_RaiseError( udi,ErrorIdetnificator, ERROR_USBTMC_PARAMETER, "'", 1 ))
- // {
- // if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- // {
- // errCode = 0;
- // }
- // }
- // else
- // errCode = 0;
- }
- break;
- */
- case ERROR_GPIB_TRIGGER_IGNORED:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Command;
-
- if(usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_TRIGGERIGNORED, "'", 1 ))
- {
- if(usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0;
- }
- break;
- case ERROR_GPIB_REQUEST_ONLY_SUPPORT:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Command;
-
- if(usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_REQUESTONLY, "'", 1 ))
- {
- if(usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "': request only supported", 25 ) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0;
- }
- break;
- case ERROR_GPIB_ARRAY_CORRUPTED:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Execution;
-
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_ARRAY_CORRUPTED, "in '", 4 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, "': ", 3 ) )
- {
- errCode = 0; break;
- }
- if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- {
- errCode = 0; break;
- }
- /*
- if(usbtmc_RaiseError( udi,ErrorIdetnificator, ERROR_USBTMC_ARRAY_CORRUPTED, "'", 1 ))
- {
- if(usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ))
- //if(usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "': invalid checksumm", 20 ) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0; */
- }
- break;
- /*
- case ERROR_GPIB_HEADER_CORRUPTED:
- {
- if(usbtmc_RaiseError( udi,ErrorIdetnificator, ERROR_USBTMC_HEADER_CORRUPTED, "'", 1 ))
- {
- if(usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "': header corrupted", 18 ) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0;
- }
- break; */
- case ERROR_GPIB_TOO_MANY_REQUESTS:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Device;
-
- if(usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_TOOMANY_REQUESTS, "'", 1 ))
- {
- if(usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "')", 2) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0;
- }
- break;
- case ERROR_GPIB_COMMAND_ONLY_SUPPORT:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Command;
-
- if(usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_COMMANDONLY, "'", 1 ))
- {
- if(usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "': request is unexpected", 24) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0;
-
- }
- break;
- case ERROR_GPIB_INTERNAL:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Device;
-
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_INTERNAL, " at command '", 13 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1 ) )
- {
- errCode = 0; break;
- }
-
- //usbtmc_RaiseError( udi,ErrorIdetnificator, ERROR_USBTMC_INTERNAL, ".", 1 );
- }
- break;
- case ERROR_GPIB_INVALID_ENUM_PARAMETERS:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Command;
-
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_PARAMETER, "in '", 4 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, "': parsing failed", 17 ) )
- {
- errCode = 0; break;
- }
- /*
- if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- {
- errCode = 0; break;
- }
- */
- /*
- if(usbtmc_RaiseError( udi,ErrorIdetnificator, ERROR_USBTMC_EXECUTION, " at '", 5 ))
- {
- if(usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1) )
- {
- errCode = 0;
- }
- }
- else
- errCode = 0;
- }
- else
- errCode = 0;*/
- }
- break;
- default:
- {
- if( errClass_Autodetect == errClass )
- errClass = errClass_Command;
-
- if( !usbtmc_RaiseError( udi, errClass, ERROR_USBTMC_PARAMETER, "in '", 4 ) )
- {
- errCode = 0; break;
- }
-
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; break;
- }
-
- /*
- if( !usbtmc_RaiseError_CatDescription( udi, "'", 1 ) )
- {
- errCode = 0; break;
- }
- */
- /*
- if( !usbtmc_RaiseError_CatDescription( udi, pDescription, strlen(pDescription) ) )
- {
- errCode = 0; break;
- }
- */
-
- /*
- if(usbtmc_RaiseError( udi,ErrorIdetnificator, ERROR_USBTMC_PARAMETER, "in '", 4 ))
- {
- if( !usbtmc_RaiseError_CatDescription( udi, pStrCurrentCmd, nCmdLength ) )
- {
- errCode = 0; // íå óäàëîñü çàïèñàòü îøèáêó, çíà÷èò è ïðîäîëæàòü (èäòè âî âòîðîé switch) íå ñòîèò
- }
- }
- else
- errCode = 0;*/
- }
- }
- // ------------ 220 error ---------------------------------------------------------
- switch( errCode )
- {
- case ERROR_GPIB_INVALID_PARAMETER_TYPE: // òàê êàê îøèáêà òèïà âîçíèêíåò ëèøü òîãäà, êîãäà get ñìîæåò äîñòàòü ïàðàìåòð è åãî òèï èç î÷åðåäè. À îí íåãî íå äîñòàòíåò, ïîòîìó ÷òî çà÷àñòóþ åìó íå õâàòèò ìåñòà â áóôåðå
- case ERROR_GPIB_INVALID_PARAMETER:
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "': invalid parameter", 20 ) )
- {
- errCode = 0;
- }
- }
- break;
-
- case ERROR_GPIB_WRONG_PARAMETERS_COUNT:
- {
- if( !usbtmc_RaiseError_CatDescription( udi, "': wrong parameters count", 25 ) )
- {
- errCode = 0;
- }
- }
- break;
-
- /*
- case ERROR_GPIB_PARAMETER_NOT_SUPPORTED:
- {
- usbtmc_RaiseError_CatDescription( udi, "': parameter not supported", 26 );
- }
- break;
- */
-
-
- default:;
- }
-
- //----------------------
- // error occurred while pushing the raised error into the queue
- if( errCode == 0 )
- {
- usbtmc_ErrorQueue_RestoreCheckpoint( udi );
- }
- //----------------------
- return 0;
- }
- /*
- unsigned int CheckCompatibilePorts( ESTATE state, EPORT port )
- {
- // ïðîâåðêà ïðàâèëüíîñòè óêàçàíèÿ ïîðòîâ è ñîñòîÿíèé âîîáùå
- if( !( ( state == eSTATE_SHORT ||
- state == eSTATE_LOAD ||
- state == eSTATE_OPEN ||
- state == eSTATE_LOAD2 ||
- state == eSTATE_OPEN2 ||
- state == eSTATE_T11 ||
- state == eSTATE_T12 ||
- state == eSTATE_T21 ||
- state == eSTATE_T22 ||
- state == eSTATE_A11 ||
- state == eSTATE_A12 ||
- state == eSTATE_A21 ||
- state == eSTATE_A22
- )
- &&
- ( port == ePORT_A ||
- port == ePORT_B ||
- port == ePORT_AB
- )
- )
- ) return FALSE;
- //---------------------------------------------------------------------------------------------------------------------------------------
- // ïðîâåðêà ïðàâèëüíîñòè óêàçàíèÿ ïîðòà (A/B) äëÿ ñîñîòîÿíèÿ SH/LD/OP/OP2/LD2
- if( ( ( state == eSTATE_SHORT ||
- state == eSTATE_LOAD ||
- state == eSTATE_OPEN ||
- state == eSTATE_LOAD2 ||
- state == eSTATE_OPEN2
- )
- &&
- ( port != ePORT_A &&
- port != ePORT_B
- )
- )
- ) return FALSE;
- //---------------------------------------------------------------------------------------------------------------------------------------
- // ïðîâåðêà ïðàâèëüíîñòè óêàçàíèÿ ïîðòà (AB) äëÿ ñîñîòîÿíèÿ T11/T12/T21/T22/A11/A12/A21/A22
- if( ( ( state == eSTATE_T11 ||
- state == eSTATE_T12 ||
- state == eSTATE_T21 ||
- state == eSTATE_T22 ||
- state == eSTATE_A11 ||
- state == eSTATE_A12 ||
- state == eSTATE_A21 ||
- state == eSTATE_A22
- )
- &&
- ( port != ePORT_AB
- )
- )
- ) return FALSE;
- return TRUE;
- }
-
- unsigned int CheckCompatibilePorts2( ESTATE state, EPORT port ) // using in Path:STATE
- {
- // ïðîâåðêà ïðàâèëüíîñòè óêàçàíèÿ ïîðòîâ è ñîñòîÿíèé âîîáùå
- if( !( ( state == eSTATE_SHORT ||
- state == eSTATE_LOAD ||
- state == eSTATE_OPEN ||
- state == eSTATE_LOAD2 ||
- state == eSTATE_OPEN2 ||
- state == eSTATE_THRU ||
- state == eSTATE_ATTEN
- )
- &&
- ( port == ePORT_A ||
- port == ePORT_B ||
- port == ePORT_AB
- )
- )
- ) return FALSE;
- //---------------------------------------------------------------------------------------------------------------------------------------
- // ïðîâåðêà ïðàâèëüíîñòè óêàçàíèÿ ïîðòà (A/B) äëÿ ñîñîòîÿíèÿ SH/LD/OP/OP2/LD2
- if( ( ( state == eSTATE_SHORT ||
- state == eSTATE_LOAD ||
- state == eSTATE_OPEN ||
- state == eSTATE_LOAD2 ||
- state == eSTATE_OPEN2
- )
- &&
- ( port != ePORT_A &&
- port != ePORT_B
- )
- )
- ) return FALSE;
- //---------------------------------------------------------------------------------------------------------------------------------------
- // ïðîâåðêà ïðàâèëüíîñòè óêàçàíèÿ ïîðòà (AB) äëÿ ñîñîòîÿíèÿ T11/T12/T21/T22/A11/A12/A21/A22
- if( ( state == eSTATE_THRU ||
- state == eSTATE_ATTEN
- )
- &&
- ( port != ePORT_AB
- )
- )
- return FALSE;
- return TRUE;
- }
- */
- unsigned int GPIBInit( USB_DEVICE_INFO * udi )
- {
- _ESE = 0x00;
- _SRE = 0x00;
- // Standard Event Status Register (ESR): bit Power On
- // 27/08/18
- // Note: in this implementation this bit is disabled
- // GPIB_SET_PWN();
-
- // GPIB_SET_OPC();
- return 0;
- }
- #endif
|