| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311 |
- #include "core/config.h"
- #if CONFIG_NFMBASECLASS
- #include <stdio.h>
- #include <string.h>
- #include "core/main.h" // _snprintf
- #include "core/config_pins.h"
- #include "crc32.h"
- #include "drivers/keycontrol/keycontrol_ll.h"
- #include "drivers/power_management/power_management.h"
- #include "app/nfm/nfm_base_excls.h"
- #include "app/thermo/tsensor.h"
- #include "app/led/led.h"
- #include "app/thermo/NTCtsensor.h"
- #include "app/version/version.h"
- #include <stdlib.h> // atoi[NFMCLASS_ENABLE__SERIAL_NUMBER_LEGACY]
- #include <ctype.h> // tolower
- #define NFMCLASS_ENABLE__SERIAL_NUMBER_LEGACY 0
- #include "my_assert.h"
- #include "app/control_table/control_table.h"
- STATIC_ASSERT( sizeof(xNFMGetFreqPoints_t) == sizeof(sNFMGetFreqPoints_t), "Invalid xNFMGetPoints_t/sNFMGetPoints_t size" );
- STATIC_ASSERT( sizeof(xNFMGetPointsSimplified_t) == sizeof(sNFMGetPointsSimplified_t), "Invalid xNFMGetPointsSimplified_t/sNFMGetPointsSimplified_t size" );
- #if defined(PLANAR)
- // Device Manufacturer ID
- const static char manufacturerId[] = "Planar";
- //#elif defined(CMT)
- //const static char manufacturerId[] = "Copper Mountain Technologies";
- #elif defined(CMT)
- const static char manufacturerId[] = "CMT";
- #else
- #error Please, specify VENDOR macro
- #endif
- // Firmware ID
- static char g_firmwareId[16] = "0.1/01";
- // NFM model name
- static char g_modelName[16] = "ME208-18A";
- // Serial Number String
- static char g_serialNumber[9] = "00000001";
- // NFM Connectors descriptions
- const static char * const aConnectorsNames[] =
- {
- "Type-N50 -M-",
- "Type-N50 -F-",
- "3.5mm -M-",
- "3.5mm -F-",
- "2.4mm -M-",
- "2.4mm -F-",
- "Type-N75 -M-",
- "Type-N75 -F-",
- "Type-F -M-",
- "Type-F -F-",
- "7/16 -M-",
- "7/16 -F-",
- "APC-7",
- };
- const static char pcConnectorUndefined[] = "Unknown";
- //------------------------------------------------------------------------------
- static void private_ClassInit();
- static size_t static_StrCpyLimit( const char * source, size_t srcMaxLen,
- char * dest, size_t destMaxLen );
- static const sNFMModel_t *
- static_GetModelProfileByDeviceId( uint16_t deviceId );
- static bool private_getModelId( uint16_t * pDeviceId );
- static bool private_CheckTableParams( ePortComb_t portComb, ePortStateId_t portState );
- static size_t NFMGetDeviceManufacturer( char * buffer, size_t size );
- static size_t NFMGetDeviceSerial( char * buffer, size_t size );
- static size_t NFMGetModelName( char * buffer, size_t size );
- static bool NFMCheckPortStateAvailable( ePortStateId_t portState );
- static bool NFMCheckPortCombinationAvailable( ePortComb_t portComb );
- // static bool NFMCheckPortParamsAvailable( ePortComb_t portComb, ePortStateId_t portState );
- // static size_t NFMGetPoints( eChrz_t tableId, ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl );
- // static size_t NFMGetPointsMagnThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl );
- // static size_t NFMGetPointsPhaseThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl );
- static size_t NFMGetPointsCount( eChrz_t tableId );
- static bool NFMGetPointsCount_Safe( eChrz_t tableId, int16_t * count );
- static bool NFMGetDate( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
- static bool NFMGetTime( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
- static bool NFMGetScaleType( eChrz_t tableId, eChrzScaleType_t * pType );
- static size_t NFMGetScaleSegment( eChrz_t tableId, sEcalSegment_t * pSegment, size_t nSegmentId );
- //------------------------------------------------------------------------------
- static int32_t NFMGetScaleFreqs_Begin( eChrz_t tableId, double * pFreqArray, size_t BufferCapacity, xNFMGetFreqPoints_t * xCtl );
- static int32_t NFMGetScaleFreqs_Continue( xNFMGetFreqPoints_t * xCtl, size_t * pnPointsRetrieve );
- //------------------------------------------------------------------------------
- static int32_t SWGetTablePoints_Begin( eChrz_t tableId, sSWTablePoint_t * pPointsArray, size_t BufferCapacity, xSWGetTablePoints_t * xCtl );
- static int32_t SWGetTablePoints_Continue( xSWGetTablePoints_t * xCtl, size_t * pnPointsRetrieve );
- //------------------------------------------------------------------------------
- static size_t NFMGetPoints_Begin( eChrz_t sectorId, ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- xNFMGetPointsSimplified_t * xCtl );
- static int32_t NFMGetPoints_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve );
- //------------------------------------------------------------------------------
- static size_t NFMGetPointsThermo_Begin( ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- sNFMGetPointsSimplified_t * pCtl );
- static size_t NFMGetPointsThermoMagn_Begin( ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- xNFMGetPointsSimplified_t * xCtl );
- static size_t NFMGetPointsThermoPhase_Begin( ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- xNFMGetPointsSimplified_t * xCtl );
- //------------------------------------------------------------------------------
- static int32_t NFMGetPointsThermo_Continue( sNFMGetPointsSimplified_t * pCtl, size_t * pnPointsRetrieve );
- static int32_t NFMGetPointsThermoMagn_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve );
- static int32_t NFMGetPointsThermoPhase_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve );
- //------------------------------------------------------------------------------
- static bool NFMGetStartFreq( eChrz_t tableId, double * pStartFreq );
- static bool NFMGetStopFreq( eChrz_t tableId, double * pStopFreq );
- static bool NFMGetChrzTemp( eChrz_t tableId, double * pTemperature );
- static bool NFMGetConnectorType( ePortId_t portId, char * buffer, size_t size, size_t * bytes );
- static bool NFMGetAdapterDesc( eChrz_t tableId, ePortId_t portId, char * buffer, size_t size, size_t * bytes );
- static bool NFMGetAnalyzer( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
- static bool NFMGetPlace( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
- static bool NFMGetOperator( eChrz_t tableId, char * buffer, size_t size, size_t * bytes ); //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- static bool NFMGetInterface( eNFMUSBInterface_t * pCurrentIface );
- static bool NFMSetInterface( eNFMUSBInterface_t activateInterface );
- //------------------------------------------------------------------------------
- static uint16_t NFMGetPortState (uint16_t portNumber);
- static bool NFMSetPortState (uint16_t portNumber, uint16_t portState);
- //------------------------------------------------------------------------------
- static bool NFMSetMemoryProtect();
- static bool NFMSetMemoryUnProtect();
- static bool NFMGetMemoryProtect();
- //------------------------------------------------------------------------------
- static bool NFMGetStartFreqThermo( double * pStartFreq );
- static bool NFMGetStopFreqThermo( double * pStopFreq );
- static size_t NFMGetPointsThermo();
- static bool NFMGetPointsThermo_Safe( int16_t * count );
- //------------------------------------------------------------------------------
- static NFMClassEx_t __NFMClass =
- {
- .public =
- {
- .properties =
- {
- .manufacturerId = manufacturerId,
- .firmwareId = g_firmwareId,
- .modelName = g_modelName,
- .serialNumber = g_serialNumber,
- .allowedInputPorts = 2,
- .allowedOutputPorts = 12,
- .defaultInputState = eTerminatePortState,
- //.inputPortStates = {0, 0},
- .deviceId = eModel_undefined,
- .isServiceMode = false
- },
- .methods =
- {
- .usbInterface =
- {
- .getInterface = NFMGetInterface,
- .setInterface = NFMSetInterface
- },
-
- .portMethods =
- {
- .getPortState = NFMGetPortState,
- .setPortState = NFMSetPortState,
- },
- .getDeviceManufacturer = NFMGetDeviceManufacturer,
- .getDeviceSerial = NFMGetDeviceSerial,
- .getModelName = NFMGetModelName,
- .checkPortStateAvailable = NFMCheckPortStateAvailable,
- .checkPortCombinationAvailable = NFMCheckPortCombinationAvailable,
- .checkTableParams = private_CheckTableParams,
- .xCharacterization =
- {
- //.getPoints = NFMGetPoints,
- .getPoints_Init = NFMGetPoints_Begin,
- .getPoints_Next = NFMGetPoints_Continue,
- .getPointsCount = NFMGetPointsCount,
- .getPointsCountSafe = NFMGetPointsCount_Safe,
- .getDate = NFMGetDate,
- .getTime = NFMGetTime,
- .getScaleType = NFMGetScaleType,
- .getScaleSegment = NFMGetScaleSegment,
- .getScaleFreqs_Init = NFMGetScaleFreqs_Begin,
- .getScaleFreqs_Next = NFMGetScaleFreqs_Continue,
- .getStartFreq = NFMGetStartFreq,
- .getStopFreq = NFMGetStopFreq,
- .getChrzTemp = NFMGetChrzTemp,
- .getConnectorType = NFMGetConnectorType,
- .getAdapterDesc = NFMGetAdapterDesc,
- .getAnalyzer = NFMGetAnalyzer,
- .getPlace = NFMGetPlace,
- .getOperator = NFMGetOperator,
- },
-
- .xTable =
- {
- .getTablePoints_Init = SWGetTablePoints_Begin,
- .getTablePoints_Next = SWGetTablePoints_Continue,
- },
- .xThermo =
- {
- .getStartFreq = NFMGetStartFreqThermo,
- .getStopFreq = NFMGetStopFreqThermo,
- .getPointsCount = NFMGetPointsThermo,
- .getPointsCountSafe = NFMGetPointsThermo_Safe,
- //.getPointsMagn = NFMGetPointsMagnThermo,
- //.getPointsPhase = NFMGetPointsPhaseThermo,
- .getPointsThermoMagn_Init = NFMGetPointsThermoMagn_Begin,
- .getPointsThermoMagn_Next = NFMGetPointsThermoMagn_Continue,
- .getPointsThermoPhase_Init = NFMGetPointsThermoPhase_Begin,
- .getPointsThermoPhase_Next = NFMGetPointsThermoPhase_Continue,
- },
- .xMemoryProtection =
- {
- .enable = NFMSetMemoryProtect,
- .disable = NFMSetMemoryUnProtect,
- .check = NFMGetMemoryProtect,
- },
- },
- },
- .private =
- {
- .methods =
- {
- .classInit = private_ClassInit,
- .getModelId = private_getModelId,
- .memory =
- {
- .setProtect = NFM_ROM_SetMemoryProtectStatus_Bank0,
- .getProtect = NFM_ROM_GetMemoryProtectStatus_Bank0,
- .getCommonHeader = NFM_ROM_GetCommonHeader,
- .getDataHeader = NFM_ROM_GetDataHeader,
- .getTCompHeader = NFM_ROM_GetTCompHeader,
- .getChrzTableIndex = NFM_ROM_GetChrzTableIndex,
- .getTCompTableIndex = NFM_ROM_GetTCompTableIndex,
- .getChrzTableHeader = NFM_ROM_ReadChrzTableHeader,
- .getChrzPoints = NFM_ROM_ReadChrzTablePoints,
- .getTCompMagnTableHeader = NFM_ROM_GetTCompMagnTableHeader,
- .getTCompPhaseTableHeader = NFM_ROM_GetTCompPhaseTableHeader,
- .getTCompMagnPoints = NFM_ROM_GetTCompMagnPoints,
- .getTCompPhasePoints = NFM_ROM_GetTCompPhasePoints,
- .getSettingsBlock = NFM_ROM_ReadDeviceSettings,
- .setSettingsBlock = NFM_ROM_WriteDeviceSettings,
- .getSettingsBlockSize = NFM_ROM_GetDeviceSettingsSize,
- .validateSettings = NFM_ROM_ValidateUserSettings,
- }
- },
- .properties =
- {
- .deviceId = eModel_undefined,
- .modelProfile = NULL,
- }
- }
- };
- __root NFMClass_t * NFMClass = (NFMClass_t*)&__NFMClass;
- __root NFMClassEx_t * NFMClassExtended = &__NFMClass;
- //------------------------------------------------------------------------------------------------------------
- //-- Global methods ------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------------
- void nfmbase_init()
- {
- // initialize NFM object
- NFMClassExtended->private.methods.classInit();
- // set key-switch state by default
- //NFMClass->methods.keyStatesMethods.setKeyStateDefault();
- // sTableTablePoint_t TablePoint;
- // TablePoint.port1 = 12;
- // TablePoint.port2 = 2;
- // SW_ROM_SetDataPoint(0, &TablePoint);
- // TablePoint.port1 = 4;
- // TablePoint.port2 = 6;
- // SW_ROM_SetDataPoint(0, &TablePoint);
- // TablePoint.port1 = 1;
- // TablePoint.port2 = 3;
- // SW_ROM_SetDataPoint(0, &TablePoint);
- // uint8_t buffer[100];
- // memset(&buffer, 0x00, sizeof(buffer));
- // SW_ROM_GetDataPoint(0, 5, &buffer, sizeof(sTableTablePoint_t));
- // SW_ROM_GetDataPoint(0, 6, &buffer, sizeof(sTableTablePoint_t));
- // SW_ROM_GetDataPoint(0, 7, &buffer, sizeof(sTableTablePoint_t));
- // SW_ROM_GetDataPoint(0, 8, &buffer, sizeof(sTableTablePoint_t));
- // uint32_t crc = SW_ROM_Get_Table_crc( eChValues );
- // SW_ROM_Set_Table_crc ( crc );
- // SW_ROM_Check_Table_crc();
- // SW_ROM_Table_Clear();
- #if CONFIG_NFMCLASS_AUTOPROTECT_MEMORY
- // protect factory data: set memory protection
- NFMClass->methods.xMemoryProtection.enable();
- #endif
- }
- #define NFMCLASS_TEST CONFIG_NFMBASECLASS_TEST
- #define NFMCLASS_TEST_TEMPERATURE 0
- #define NFMCLASS_TEST_TEMPERATURESTR 0
- #define NFMCLASS_TEST_MANUFACTURERSTR 0
- #define NFMCLASS_TEST_SERIALSTR 0
- #define NFMCLASS_TEST_SERIALLEGACY 0
- #define NFMCLASS_TEST_STATENAMES 0
- #define NFMCLASS_TEST_STATELIST 0
- #define NFMCLASS_TEST_KEYSWSTATENAME 0
- #define NFMCLASS_TEST_MODELNAME 0
- #define NFMCLASS_TEST_CURRENTSTATE 0
- #define NFMCLASS_TEST_LEGACYSTATE 0
- #define NFMCLASS_TEST_RAWKEYCODE 0
- #define NFMCLASS_TEST_KEYSTATESHORTCUTS 0
- #define NFMCLASS_TEST_CHRZ_ADAPTERSTR 0
- #define NFMCLASS_TEST_CHRZ_ANALYZERSTR 0
- #define NFMCLASS_TEST_CHRZ_TEMP 0
- #define NFMCLASS_TEST_CHRZ_CONNECTORSTR 0
- #define NFMCLASS_TEST_CHRZ_DATESTR 0
- #define NFMCLASS_TEST_CHRZ_TIMESTR 0
- #define NFMCLASS_TEST_CHRZ_OPERATORSTR 0
- #define NFMCLASS_TEST_CHRZ_PLACESTR 0
- #define NFMCLASS_TEST_CHRZ_POINTSCOUNT 0
- #define NFMCLASS_TEST_CHRZ_SEGMENTS 0
- #define NFMCLASS_TEST_CHRZ_STARTFREQ 0
- #define NFMCLASS_TEST_CHRZ_STOPFREQ 0
- #define NFMCLASS_TEST_THERMO_POINTSCOUNT 0
- #define NFMCLASS_TEST_THERMO_STOPFREQ 0
- #define NFMCLASS_TEST_THERMO_STARTFREQ 0
- #define NFMCLASS_TEST_MEM_PROTECTION 0
- void nfmbase_test()
- {
- #if NFMCLASS_TEST
- asm( "bkpt #0" );
- #if 1 && NFMCLASS_TEST_TEMPERATURE
- {
- float avgTemp = NFMClass->methods.getAverageTemperature();
- asm( "bkpt #0" );
- (void)avgTemp;
- }
- #endif
- #if 0 && NFMCLASS_TEST_TEMPERATURESTR
- {
- char avgTempStrBuffer[ 20 ] = {0};
- NFMClass->methods.getAverageTemperatureString( avgTempStrBuffer, sizeof(avgTempStrBuffer) )
- asm( "bkpt #0" );
- (void)avgTempStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_MANUFACTURERSTR
- {
- char manufacturerStrBuffer[ 20 ] = {0};
- NFMClass->methods.getDeviceManufacturer( manufacturerStrBuffer, sizeof(manufacturerStrBuffer) );
- asm( "bkpt #0" );
- (void)manufacturerStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_SERIALSTR
- {
- char serialStrBuffer[ 20 ] = {0};
- NFMClass->methods.getDeviceSerial( serialStrBuffer, sizeof(serialStrBuffer) );
- asm( "bkpt #0" );
- (void)serialStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_SERIALLEGACY
- {
- uint32_t serialNumber = NFMClass->methods.getDeviceSerialLegacy();
- asm( "bkpt #0" );
- (void)serialNumber;
- }
- #endif
- #if 1 && NFMCLASS_TEST_STATENAMES
- {
- char stateNameStrBuffer[ 20 ] = {0};
- eNFMKeyState_t state = NFMClass->methods.getKeyStateByName( "SALL", 4 );
- asm( "bkpt #0" );
- NFMClass->methods.getKeyStateName( state, stateNameStrBuffer, sizeof(stateNameStrBuffer) );
- asm( "bkpt #0" );
- (void)state, (void)stateNameStrBuffer;
- }
- {
- char stateNameStrBuffer[ 20 ] = {0};
- eNFMKeyState_t state = NFMClass->methods.getKeyStateByName( "OALL", 4 );
- asm( "bkpt #0" );
- NFMClass->methods.getKeyStateName( state, stateNameStrBuffer, sizeof(stateNameStrBuffer) );
- asm( "bkpt #0" );
- (void)state, (void)stateNameStrBuffer;
- }
- {
- char stateNameStrBuffer[ 20 ] = {0};
- eNFMKeyState_t state = NFMClass->methods.getKeyStateByName( "LALL", 4 );
- asm( "bkpt #0" );
- NFMClass->methods.getKeyStateName( state, stateNameStrBuffer, sizeof(stateNameStrBuffer) );
- asm( "bkpt #0" );
- (void)state, (void)stateNameStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_STATELIST
- {
- char statesListStrBuffer[ 64 ] = {0};
- NFMClass->methods.getKeyStateList( statesListStrBuffer, sizeof(statesListStrBuffer) );
- asm( "bkpt #0" );
- (void)statesListStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_KEYSWSTATENAME
- {
- char keySwitchNameStrBuffer[ 20 ] = {0};
- NFMClass->methods.getKeySwitchName( keySwitchNameStrBuffer, sizeof(keySwitchNameStrBuffer) );
- asm( "bkpt #0" );
- (void)keySwitchNameStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_MODELNAME
- {
- char modelNameStrBuffer[ 20 ] = {0};
- NFMClass->methods.getModelName( modelNameStrBuffer, sizeof(modelNameStrBuffer) );
- asm( "bkpt #0" );
- (void)modelNameStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CURRENTSTATE
- {
- eNFMKeyState_t currentState = NFMClass->methods.keyStatesMethods.getKeyStateCommon();
- asm( "bkpt #0" );
- (void)currentState;
- }
- #endif
- #if 1 && NFMCLASS_TEST_LEGACYSTATE
- {
- uint32_t legacyState = 0;
- eNFMKeyState_t testState = eKeyState_CHECK;
- if( NFMClass->methods.keyStatesMethods.getKeyStateLegacy( &legacyState ) )
- {
- asm( "bkpt #0" ); // OK
- NFMClass->methods.keyStatesMethods.setKeyStateCommon( testState );
- if( testState == NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- if( NFMClass->methods.keyStatesMethods.setKeyStateLegacy( legacyState ) )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- uint32_t legacyState_2 = 0;
- if( NFMClass->methods.keyStatesMethods.getKeyStateLegacy( &legacyState_2 ) )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- if( legacyState_2 == legacyState )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- }
- else
- asm( "bkpt #0" ); // ERROR
- }
- #endif
- #if 1 && NFMCLASS_TEST_RAWKEYCODE
- {
- uint32_t rawCode = NFMClass->methods.keyStatesMethods.getRawKeyControlCode();
- asm( "bkpt #0" );
- (void)rawCode;
- }
- #endif
- #if 1 && NFMCLASS_TEST_KEYSTATESHORTCUTS
- {
- eNFMKeyState_t prevState = NFMClass->methods.keyStatesMethods.getKeyStateCommon();
- int32_t eKeyState_SALL_shortcut=-1, eKeyState_OALL_shortcut=-1, eKeyState_LALL_shortcut=-1;
- if( !NFMClass->methods.keyStatesMethods.shortcuts.findShortCutForState( eKeyState_SALL, &eKeyState_SALL_shortcut ) )
- asm( "bkpt #0" ); // ERROR
- if( !NFMClass->methods.keyStatesMethods.shortcuts.findShortCutForState( eKeyState_OALL, &eKeyState_OALL_shortcut ) )
- asm( "bkpt #0" ); // ERROR
- if( !NFMClass->methods.keyStatesMethods.shortcuts.findShortCutForState( eKeyState_LALL, &eKeyState_LALL_shortcut ) )
- asm( "bkpt #0" ); // ERROR
- if( !NFMClass->methods.keyStatesMethods.shortcuts.setKeyStateByShortcut( eKeyState_SALL_shortcut ) )
- asm( "bkpt #0" ); // ERROR
- else
- if( eKeyState_SALL != NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
- asm( "bkpt #0" ); // ERROR
- if( !NFMClass->methods.keyStatesMethods.shortcuts.setKeyStateByShortcut( eKeyState_OALL_shortcut ) )
- asm( "bkpt #0" ); // ERROR
- else
- if( eKeyState_OALL != NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
- asm( "bkpt #0" ); // ERROR
- if( !NFMClass->methods.keyStatesMethods.shortcuts.setKeyStateByShortcut( eKeyState_LALL_shortcut ) )
- asm( "bkpt #0" ); // ERROR
- else
- if( eKeyState_LALL != NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
- asm( "bkpt #0" ); // ERROR
- if( !NFMClass->methods.keyStatesMethods.setKeyStateCommon( prevState ) )
- asm( "bkpt #0" ); // ERROR
- }
- #endif
- asm( "bkpt #0" );
- #if 1 && NFMCLASS_TEST_CHRZ_ADAPTERSTR
- {
- size_t n;
- char adapterStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getAdapterDesc( eChFactory, ePortId_A, adapterStrBuffer, sizeof(adapterStrBuffer), &n );
- asm( "bkpt #0" );
- (void)adapterStrBuffer;
- }
- {
- size_t n;
- char adapterStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getAdapterDesc( eChFactory, ePortId_B, adapterStrBuffer, sizeof(adapterStrBuffer), &n );
- asm( "bkpt #0" );
- (void)adapterStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_ANALYZERSTR
- {
- size_t n;
- char analyzerStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getAnalyzer( eChFactory, analyzerStrBuffer, sizeof(analyzerStrBuffer), &n );
- asm( "bkpt #0" );
- (void)analyzerStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_TEMP
- {
- double chrzTemp = 0.0;
- NFMClass->methods.xCharacterization.getChrzTemp( eChFactory, &chrzTemp );
- asm( "bkpt #0" );
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_CONNECTORSTR
- {
- size_t n;
- char connectorStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getConnectorType( ePortId_A, connectorStrBuffer, sizeof(connectorStrBuffer), &n );
- asm( "bkpt #0" );
- (void)connectorStrBuffer;
- }
- {
- size_t n;
- char connectorStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getConnectorType( ePortId_B, connectorStrBuffer, sizeof(connectorStrBuffer), &n );
- asm( "bkpt #0" );
- (void)connectorStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_DATESTR
- {
- size_t n;
- char dateStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getDate( eChFactory, dateStrBuffer, sizeof(dateStrBuffer), &n );
- asm( "bkpt #0" );
- (void)dateStrBuffer;
- }
- #endif
-
- #if 1 && SWCLASS_TEST_TABLE_HEADER
- {
- //SW_ROM_ChangeTableHeader(5);
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_TIMESTR
- {
- size_t n;
- char timeStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getTime( eChFactory, timeStrBuffer, sizeof(timeStrBuffer), &n );
- asm( "bkpt #0" );
- (void)timeStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_OPERATORSTR
- {
- size_t n;
- char operatorStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getOperator( eChFactory, operatorStrBuffer, sizeof(operatorStrBuffer), &n );
- asm( "bkpt #0" );
- (void)operatorStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_PLACESTR
- {
- size_t n;
- char placeStrBuffer[ 20 ] = {0};
- NFMClass->methods.xCharacterization.getPlace( eChFactory, placeStrBuffer, sizeof(placeStrBuffer), &n );
- asm( "bkpt #0" );
- (void)placeStrBuffer;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_POINTSCOUNT
- {
- size_t nPoints = NFMClass->methods.xCharacterization.getPointsCount( eChFactory );
- asm( "bkpt #0" );
- (void)nPoints;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_SEGMENTS
- {
- size_t nSegments = NFMClass->methods.xCharacterization.getScaleSegment( eChFactory, NULL, 0 );
- asm( "bkpt #0" );
- (void)nSegments;
- asm( "bkpt #0" );
- for( size_t i = 0; i < nSegments; ++i )
- {
- sEcalSegment_t segm;
- if( 0 == NFMClass->methods.xCharacterization.getScaleSegment( eChFactory, &segm, i ) )
- asm( "bkpt #0" ); // ERROR
- else
- asm( "bkpt #0" ); // OK
- (void)segm;
- }
- asm( "bkpt #0" );
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_STARTFREQ
- {
- double startFreq = 0.0;
- if( NFMClass->methods.xCharacterization.getStartFreq( eChFactory, &startFreq ) )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- (void)startFreq;
- }
- #endif
- #if 1 && NFMCLASS_TEST_CHRZ_STOPFREQ
- {
- double stopFreq = 0.0;
- if( NFMClass->methods.xCharacterization.getStopFreq( eChFactory, &stopFreq ) )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- (void)stopFreq;
- }
- #endif
- asm( "bkpt #0" );
- #if 1 && NFMCLASS_TEST_MEM_PROTECTION
- {
- bool oldstate = NFMClass->methods.xMemoryProtection.check();
- asm( "bkpt #0" );
- NFMClass->methods.xMemoryProtection.disable();
- asm( "bkpt #0" );
- bool state = NFMClass->methods.xMemoryProtection.check();
- asm( "bkpt #0" );
- NFMClass->methods.xMemoryProtection.enable();
- asm( "bkpt #0" );
- state = NFMClass->methods.xMemoryProtection.check();
- asm( "bkpt #0" );
- if( oldstate ) NFMClass->methods.xMemoryProtection.enable();
- else NFMClass->methods.xMemoryProtection.disable();
- }
- #endif
- #if 1 && NFMCLASS_TEST_THERMO_STARTFREQ
- {
- double startFreq = 0.0;
- if( NFMClass->methods.xThermo.getStartFreq( &startFreq ) )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- (void)startFreq;
- }
- #endif
- #if 1 && NFMCLASS_TEST_THERMO_STOPFREQ
- {
- double stopFreq = 0.0;
- if( NFMClass->methods.xThermo.getStopFreq( &stopFreq ) )
- asm( "bkpt #0" ); // OK
- else
- asm( "bkpt #0" ); // ERROR
- (void)stopFreq;
- }
- #endif
- #if 1 && NFMCLASS_TEST_THERMO_POINTSCOUNT
- {
- size_t nPoints = NFMClass->methods.xThermo.getPointsCount( eChFactory );
- asm( "bkpt #0" );
- (void)nPoints;
- }
- #endif
- #endif
- }
- //------------------------------------------------------------------------------------------------------------
- //-- Public methods ------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------------
- // Enable Memory Protection for BANK0
- static bool NFMSetMemoryProtect()
- {
- return NFMClassExtended->private.methods.memory.setProtect( true );
- }
- // Disable Memory Protection for BANK0
- static bool NFMSetMemoryUnProtect()
- {
- return NFMClassExtended->private.methods.memory.setProtect( false );
- }
- // Check the Memory Protection Status for BANK0
- static bool NFMGetMemoryProtect()
- {
- return NFMClassExtended->private.methods.memory.getProtect();
- }
- #if 0
- // Set common key-switch state
- static bool NFMSetKeyStateCommon( eNFMKeyState_t state )
- {
- if( NFMClassExtended->public.methods.checkStateAvailable( state ) )
- {
- if( NULL != NFMClassExtended->private.properties.statesEncoding )
- {
- for( size_t i = 0; i < NFMClassExtended->public.properties.allowedStatesCount; ++i )
- {
- if( state == NFMClassExtended->private.properties.statesEncoding[i].commonKeyState )
- {
- NFMClassExtended->private.methods.switchControl(
- &NFMClassExtended->private.properties.statesEncoding[i]
- );
- NFMClassExtended->private.properties.keyState = state;
- return true;
- }
- }
- }
- }
- return false;
- }
- #endif
- // Get device serial number in string format
- static size_t NFMGetDeviceSerial( char * buffer, size_t size )
- {
- const sEcalHeader_t * Header = NFMClassExtended->private.methods.memory.getCommonHeader( NULL, 0 );
- if( NULL != Header )
- {
- size_t n = static_StrCpyLimit( (const char*)Header->SN, sizeof(Header->SN), buffer, size );
- if( n + 1 <= size )
- {
- buffer[n] = '\0';
- return (n + 1);
- }
- }
- return 0;
- }
- // Set device serial number in string format
- static size_t NFMSetDeviceSerial( char * buffer, size_t size )
- {
- const sEcalHeader_t * Header = NFMClassExtended->private.methods.memory.getCommonHeader( NULL, 0 );
- if( NULL != Header )
- {
- size_t n = static_StrCpyLimit( (const char*)Header->SN, sizeof(Header->SN), buffer, size );
- if( n + 1 <= size )
- {
- buffer[n] = '\0';
- return (n + 1);
- }
- }
- return 0;
- }
- // Get device manufacturer ID in string format
- // See more: NFMClass->properties.manufacturerId
- static size_t NFMGetDeviceManufacturer( char * buffer, size_t size )
- {
- size_t retval = 0;
- if( NULL != buffer && size > 1 )
- {
- const char * manufacturer_id = NFMClassExtended->public.properties.manufacturerId;
- while( (size > 1) && (*manufacturer_id != '\0') )
- {
- *buffer = *manufacturer_id;
- manufacturer_id++;
- buffer++;
- retval++; size--;
- }
- *buffer = '\0';
- }
- return retval;
- }
- // Get device model name in string format
- static size_t NFMGetModelName( char * buffer, size_t size )
- {
- if( NULL == buffer || 0 == size )
- return 0;
- size_t l = strlen( NFMClassExtended->public.properties.modelName );
- if( l <= size )
- {
- memcpy( buffer, NFMClassExtended->public.properties.modelName, l );
- }
- else
- {
- l = 0;
- }
- return l;
- }
- static bool NFMCheckPortStateAvailable( ePortStateId_t portState )
- {
- extern NFMClassEx_t * NFMClassExtended;
-
- // if( ePortStateId_MAX <= portState
- // || ePortStateId_UNDEFINED == portState
- // )
- // {
- // return (false);
- // }
- //
- // if(
- // NULL == NFMClassExtended->private.properties.memProfile
- // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw )
- // {
- // return (false);
- // }
- //
- // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile_XPort = NFMClassExtended->private.properties.memProfile->tbls_raw;
- //
- // switch(tableProfile_XPort->Header.ChrzTableType.eType)
- // {
- // case eNfmChrzTable2Port:
- // {
- // if( ePortStateId_MIN_SINGLE_2Port <= portState
- // && ePortStateId_MAX_SINGLE_2Port >= portState )
- // {
- // return true;
- // }
- // if( ePortStateId_MIN_THRU_2Port <= portState
- // && ePortStateId_MAX_THRU_2Port >= portState )
- // {
- // return true;
- // }
- // if( ePortStateId_MIN_CHECK_2Port <= portState
- // && ePortStateId_MAX_CHECK_2Port >= portState )
- // {
- // return true;
- // }
- // }
- // break;
- // case eNfmChrzTable4Port:
- // {
- // if( ePortStateId_MIN_SINGLE_4Port <= portState
- // && ePortStateId_MAX_SINGLE_4Port >= portState )
- // {
- // return true;
- // }
- // if( ePortStateId_MIN_THRU_4Port <= portState
- // && ePortStateId_MAX_THRU_4Port >= portState )
- // {
- // return true;
- // }
- // if( ePortStateId_MIN_CHECK_4Port <= portState
- // && ePortStateId_MAX_CHECK_4Port >= portState )
- // {
- // return true;
- // }
- // }
- // break;
- // }
-
- return (false); // unsupported characterization table type
- }
- static bool NFMCheckPortCombinationAvailable( ePortComb_t portCombination )
- {
- extern NFMClassEx_t * NFMClassExtended;
-
- if( ePortComb_MAX <= portCombination
- || ePortComb_UNDEFINED == portCombination
- )
- {
- return (false);
- }
-
- // if(
- // NULL == NFMClassExtended->private.properties.memProfile
- // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw )
- // {
- // return (false);
- // }
- //
- // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile_XPort = NFMClassExtended->private.properties.memProfile->tbls_raw;
- //
- // if( ePortComb_MIN_SINGLE_XPort <= portCombination
- // && ePortComb_MAX_SINGLE_XPort >= portCombination )
- // {
- // switch(tableProfile_XPort->Header.ChrzTableType.eType)
- // {
- // case eNfmChrzTable2Port:
- // {
- // if( ePortComb_MIN_SINGLE_2Port <= portCombination
- // && ePortComb_MAX_SINGLE_2Port >= portCombination )
- // {
- // return true;
- // }
- // }
- // break;
- // case eNfmChrzTable4Port:
- // {
- // if( ePortComb_MIN_SINGLE_4Port <= portCombination
- // && ePortComb_MAX_SINGLE_4Port >= portCombination )
- // {
- // return true;
- // }
- // }
- // break;
- // }
- //
- // return 0; // unsupported characterization table type
- // }
- // else
- // if( ePortComb_MIN_THRU_XPort <= portCombination
- // && ePortComb_MAX_THRU_XPort >= portCombination )
- // {
- // switch(tableProfile_XPort->Header.ChrzTableType.eType)
- // {
- // case eNfmChrzTable2Port:
- // {
- // if( ePortComb_MIN_THRU_2Port <= portCombination
- // && ePortComb_MAX_THRU_2Port >= portCombination )
- // {
- // return true;
- // }
- // }
- // break;
- // case eNfmChrzTable4Port:
- // {
- // if( ePortComb_MIN_THRU_4Port <= portCombination
- // && ePortComb_MAX_THRU_4Port >= portCombination )
- // {
- // return true;
- // }
- // }
- // break;
- // }
- //
- // return 0; // unsupported characterization table type
- // }
- // else
- // if( ePortComb_CHECK == portCombination )
- // {
- // return true; // always available
- // }
-
- return (false);
- }
- #if 0
- static bool NFMCheckPortParamsAvailable( ePortComb_t portComb, ePortStateId_t portState )
- {
- return ( NFM_CHRZ_TABLEIDX_INVALID
- !=
- NFMClassExtended->private.methods.memory
- .getChrzTableIndex( portComb, portState )
- );
- }
- #endif
- //------------------------------------------------------------------------------------------------------------
- //-- Private methods -----------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------------
- // private_ClassInit:
- // NFMClass object constructor
- static void private_ClassInit()
- {
- // -------------------------------------------------------------------------
- // Load device model profile by DeviceID from Common Header
- uint16_t deviceId;
- NFMClassExtended->private.properties.deviceId = eModel_undefined;
- NFMClassExtended->private.properties.modelProfile = NULL;
- NFMClassExtended->private.properties.memProfile = NULL;
- NFMClassExtended->public.properties.modelName = NULL;
- NFMClassExtended->public.properties.firmwareId = g_firmwareId;
-
- // prepare firmware ID string
- memset( (char*)g_firmwareId, 0, sizeof(g_firmwareId) );
- uint16_t firmware_version = pProgramVersion->firmware_version;
- _snprintf(g_firmwareId, sizeof(g_firmwareId) - 1,
- "%d%c%d%c%02d",
- ((firmware_version & 0xF000)>>12),
- '.',
- ((firmware_version & 0x0F00)>>8),
- '/',
- ((firmware_version & 0xFF)) );
- // // check model version
- // if(!NFMClassExtended->private.methods.getModelId(&deviceId)) // FOR DEBUGGING (ïèøåì äåâàéñ ID âî ôëåø)
- // {
- // bool xPro = NFMClassExtended->public.methods.xMemoryProtection.check();
- //
- // if( xPro )
- // {
- // NFMClassExtended->public.methods.xMemoryProtection.disable();
- // }
- //
- // NFM_ROM_ChangeModel( eModel_NFM );
- //
- //
- // if( xPro )
- // {
- // NFMClassExtended->public.methods.xMemoryProtection.enable();
- // }
- // }
-
- //const char serial[10] = {'0', '0', '0', '1', '5', '9', '1', '6', '5', '7'};
- //NFM_ROM_ChangeSerialNumber(serial);
-
- //NFM_ROM_ChangeModel(eModel_SWB);
-
- if( NFMClassExtended->private.methods.getModelId( &deviceId ) )
- {
- const sNFMModel_t * modelProfile = static_GetModelProfileByDeviceId( deviceId );
- if( NULL != modelProfile )
- {
- NFMClassExtended->public.properties.deviceId = (uint16_t)deviceId;
- NFMClassExtended->public.properties.modelName = modelProfile->modelName;
- NFMClassExtended->private.properties.deviceId = deviceId;
- NFMClassExtended->private.properties.modelProfile = modelProfile;
- NFMClassExtended->private.properties.memProfile = modelProfile->memProfile;
- if( NULL != modelProfile->nfProfile )
- {
- // NOTE: do not initialize if wrong number has been set
- // ---------------------------------------------------
- NFMClassExtended->public.properties.allowedInputPorts
- = modelProfile->nfProfile->controlProfile.allowedInputPorts;
- NFMClassExtended->public.properties.allowedOutputPorts
- = modelProfile->nfProfile->controlProfile.allowedOutputPorts;
- NFMClassExtended->public.properties.defaultInputState
- = modelProfile->nfProfile->controlProfile.defaultInputState;
- NFMClassExtended->public.properties.inputPortStates
- = modelProfile->nfProfile->controlProfile.inputPortStates;
- }
- }
-
- NFMClassExtended->public.methods.getDeviceSerial(
- g_serialNumber,
- sizeof(g_serialNumber)
- );
- NFMClassExtended->public.properties.serialNumber = g_serialNumber;
-
- if( ! NFMClassExtended->private.methods.memory.validateSettings())
- {
- // set default parameters
-
- unsigned char interface[8] = {'U', 'S', 'B', 'T', 'M', 'C', '!', 0};
- sNFMSettingsBlockCrc_t sSettingsBlock;
- for(int i = 0; i < sizeof(interface); i++)
- {
- sSettingsBlock.settings.rawBytes[i] = interface[i];
- }
- sSettingsBlock.settings.settingsVersion = 1;
- sSettingsBlock.settings.tempCoeff = 3988; // Not used
-
- TCRC crc = ICRC32;
- crc = CRC32( crc, (uint8_t *)&sSettingsBlock.settings, sizeof(sSettingsBlock.settings));
-
- sSettingsBlock.CRCValue = crc;
-
- NFMClassExtended->private.methods.memory.setSettingsBlock( (uint8_t*)&sSettingsBlock,
- 0,
- sizeof(sSettingsBlock) );
- }
- }
- /*
- else
- {
- asm("bkpt #0");
- bool xPro = NFMClassExtended->public.methods.xMemoryProtection.check();
- if( xPro )
- {
- NFMClassExtended->public.methods.xMemoryProtection.disable();
- }
- NFM_ROM_ChangeModel( eModel_SC4520_v1 );
- if( xPro )
- {
- NFMClassExtended->public.methods.xMemoryProtection.enable();
- }
- asm("bkpt #0");
- }
- */
- }
- // Checks the characterization table parameters for compatibility
- bool private_CheckTableParams( ePortComb_t portComb, ePortStateId_t portState )
- {
- // Validate the combination of @portComb, @portState and
- // validate the @portComb and @portState itself.
- // Retrieve the table index (ordered index)
- size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
- if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
- {
- // Invalid combination or value
- return false;
- }
- return true;
- }
- /*
- // private_getModelName
- // Get device model name by DeviceID
- static const char * private_getModelName()
- {
- uint16_t deviceId = eModel_undefined;
- if( ! NFMClassExtended->private.methods.getModelId( &deviceId ) )
- {
- deviceId = eModel_undefined;
- }
- return NFMClassExtended->private.methods.getModelNameById( deviceId );
- }
- */
- /*
- // private_getModelNameById
- // Get device model name by DeviceID
- static const char * private_getModelNameById( uint16_t deviceId )
- {
- const sNFMModel_t * modelProfile = static_GetModelProfileByDeviceId( deviceId );
- if( NULL == modelProfile )
- return NULL;
- return modelProfile->modelName;
- }
- */
- // private_getModelId
- // Get device model ID (DeviceID)
- static bool private_getModelId( uint16_t * pDeviceId )
- {
- const sEcalHeader_t * Header = NFMClassExtended->private.methods.memory.getCommonHeader( NULL, 0 );
- if( NULL != Header )
- {
- if( NULL != pDeviceId )
- {
- *pDeviceId = Header->DeviceID;
- return true;
- }
- }
- return false;
- }
- //------------------------------------------------------------------------------------------------------------
- //-- Static methods -----------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------------
- static bool static_KeyStateNameCompare( const char * name1,
- const char * name2,
- size_t size )
- {
- if( NULL == name1 || NULL == name2 || 0 == size )
- return false;
- for( size_t i = 0; i < size; ++i )
- {
- if( tolower(name1[i]) != tolower(name2[i]) )
- {
- return false;
- }
- }
- return true;
- }
- static size_t static_StrCpyLimit( const char * source, size_t srcMaxLen,
- char * dest, size_t destMaxLen )
- {
- size_t srcLen = srcMaxLen;
- for( size_t i = 0; (0 == srcMaxLen) || (i < srcMaxLen); ++i )
- {
- if( source[i] == '\0' )
- {
- srcLen = i;
- break;
- }
- }
- size_t rc = 0;
- for( size_t i = 0; true; ++i )
- {
- if( (i >= destMaxLen) || (i >= srcLen) )
- {
- rc = (i);
- break;
- }
- dest[i] = source[i];
- }
- return (rc);
- }
- // Searches the model profile by device ID
- static const sNFMModel_t * static_GetModelProfileByDeviceId( uint16_t deviceId )
- {
- for( size_t i = 0; i < aNFMModels_count; ++i )
- {
- if( aNFMModels[i].deviceId == deviceId )
- {
- return &aNFMModels[i];
- }
- }
- for( size_t i = 0; i < aNFMModels_count; ++i )
- {
- if( eModel_undefined == aNFMModels[i].deviceId )
- {
- return &aNFMModels[i];
- }
- }
- return NULL;
- }
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- #if 0
- // MEM:TABL:DATA?
- // Reads the data points of the characterization table
- size_t NFMGetPoints( eChrz_t sectorId, ePortComb_t portComb, ePortStateId_t portState,
- sNFMGetPoints_t * pCtl )
- {
- if( portComb >= ePortComb_MAX
- || portComb == ePortComb_UNDEFINED
- || portState >= ePortStateId_MAX
- || portState == ePortStateId_UNDEFINED
- || NULL == pCtl
- || NULL == pCtl->in.pDataArray
- )
- {
- if( NULL != pCtl )
- pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- /* --- do it later: inside @getChrzTableHeader() call
- // Validate the combination of @portComb, @portState and
- // validate the @portComb and @portState itself.
- // Retrieve the table index (ordered index)
- size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
- if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
- {
- // Invalid combination or value
- return 0;
- }
- */
- // Check the input parameter: @pCtl->in.nCount
- // For zero value: required to load the table header
- // During the loading the table header it is required:
- // - load the main characterization header, check CRC
- // - retrieve number of points (@nPoints) from the header for specified @sectorId
- // - load the table header and check it's CRC
- // - retrieve the table address @TableAddress (for next operations)
- // - retrieve the @min and @max fields from the table header
- // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- // - return (1) in case of success, or (0) on error
- if( 0 == pCtl->in.nCount )
- {
- // load characterization main header
- // and check the CRC
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory
- .getDataHeader( sectorId, NULL, 0 );
- // check the main header: number of points
- if( NULL == pChrzHeader
- || 0 == pChrzHeader->Points )
- {
- pCtl->svc.errCode = ERR_NFMGETPOINTS_INVHDR;
- return (0);
- }
- // move @.Points into @nPoints
- // due to @pChrzHeader will be corrupted
- size_t nPoints = pChrzHeader->Points;
- sEcalChrzTableHeader_t tableMicroHeader;
- // load the table base address
- // Note: the data by @pChrzHeader is not valid after this call,
- // due to the function uses the same internal buffer!
- size_t tableAddress = NFMClassExtended->private.methods.memory
- .getChrzTableHeader( // load the table base address
- sectorId, // for specified memory sector
- portComb, // for specified port combination
- portState, // for specified port state
- nPoints, // for retrieved number of points
- &tableMicroHeader, // and store the header into @tableMicroHeader
- &pCtl->svc.errCode // And fill the error code
- );
- // check the result: @tableAddress
- // 0 - table corrupted or invalid port combination or port state.
- // but since the @portComb and @portState are validated above...
- // this result means only that the table is corrupted
- // non zero - this is the absolute address of the requested table.
- if( 0 == tableAddress )
- {
- (void)pCtl->svc.errCode;
- return 0; // error, sorry
- }
- // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- pCtl->out.max = tableMicroHeader.MaxMagn;
- pCtl->out.min = tableMicroHeader.MinMagn;
- pCtl->out.TableAddress = tableAddress;
- pCtl->out.nPoints = nPoints;
- pCtl->svc.errCode = ERR_NFMGETPOINTS_NOERR;
- // success
- return 1;
- }
- // -----------------
- // User must call this function with (pCtl->in.nCount=0) first time
- // to initialize the @pCtl->out contents.
- // Here: 0 != pCtl->in.nCount
- // -----------------
- // Check the header data, loaded at previous step ( see pCtl->in.nCount == 0 )
- if( 0 == pCtl->out.nPoints // check the number of points in the table
- || 0 == pCtl->out.TableAddress ) // check the table base address
- {
- // error, invalid parameters
- // Call the function with (pCtl->in.nCount = 0) to load the header
- pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- // Check the input parameters
- if( pCtl->in.nCount > pCtl->out.nPoints // check the amount of requested points
- || pCtl->in.nStartPoint >= pCtl->out.nPoints // check the starting point
- || NULL == pCtl->in.pDataArray ) // check receiving data buffer
- {
- // error: invalid input parameters
- pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- return NFMClassExtended->private.methods.memory.getChrzPoints( pCtl );
- }
- #endif
- // MEM:TABL:DATA?
- // Prepares the context before reading the data points of the characterization table
- // This method is designed to replace the obsolete @NFMGetPoints.
- // Parameters:
- // @sectorId - bank id, characterization bank;
- // @portComb - port combination to request (NFM path);
- // @portState - port state to request (S-parameter);
- // @pDataBuffer - output data buffer;
- // @szDataBuffer - output data buffer capacity;
- // @xCtl - the control context to initialize;
- // Returns: 0 in case error, or number of points in case success.
- size_t NFMGetPoints_Begin( eChrz_t sectorId, ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- xNFMGetPointsSimplified_t * xCtl )
- {
- sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
- // Check if arguments are valid in general
- if( ( sectorId >= eCh_MAX )
- || ( portComb >= ePortComb_MAX )
- || ( portState >= ePortStateId_MAX )
- || ( portComb == ePortComb_UNDEFINED )
- || ( NULL == xCtl )
- || ( 0 == szDataBuffer ) )
- {
- if( NULL != pCtl )
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- // Check if arguments are valid particularly for this device
- if( ! NFMClassExtended->public.methods.checkTableParams( portComb, portState ) )
- {
- // Invalid combination or value
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- // Try to validate configuration (table ID)
- size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
- if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
- {
- // Invalid combination or value
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- // Fill input parameters:
- pCtl->BufferCapacity = szDataBuffer; // - output buffer capacity
- pCtl->sectorId = sectorId; // - requested bank
- pCtl->portComb = portComb; // - requested port combination (nfm path)
- pCtl->portState = portState; // - requested state (S-parameter)
- pCtl->intCtx.in.nCount = szDataBuffer; // - number of points to get
- pCtl->intCtx.in.nStartPoint = 0; // - start point
- pCtl->intCtx.in.pDataArray = pDataBuffer; // - output buffer
- // During the loading the table header it is required:
- // - load the main characterization header, check CRC
- // - retrieve number of points (@nPoints) from the header for specified @sectorId
- // - load the table header and check it's CRC
- // - retrieve the table address @TableAddress (for next operations)
- // - retrieve the @min and @max fields from the table header
- // - store @min, @max, @TableAddress, @nPoints into @pCtl.intCtx.out
- // load characterization main header
- // and check the CRC
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory
- .getDataHeader( sectorId, NULL, 0 );
- // check the main header: number of points
- if( NULL == pChrzHeader
- || 0 == pChrzHeader->Points )
- {
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVHDR;
- return (0);
- }
- // move @.Points into @nPoints
- // due to @pChrzHeader will be corrupted
- size_t nPoints = pChrzHeader->Points;
- sEcalChrzTableHeader_t tableMicroHeader;
- // load the table base address
- // Note: the data by @pChrzHeader is not valid after this call,
- // due to the function uses the same internal buffer!
- size_t tableAddress = NFMClassExtended->private.methods.memory
- .getChrzTableHeader( // load the table base address
- sectorId, // for specified memory sector
- portComb, // for specified port combination
- portState, // for specified port state
- nPoints, // for retrieved number of points
- &tableMicroHeader, // and store the header into @tableMicroHeader
- &pCtl->intCtx.svc.errCode // And fill the error code
- );
- // check the result: @tableAddress
- // 0 - table corrupted or invalid port combination or port state.
- // but since the @portComb and @portState are validated above...
- // this result means only that the table is corrupted
- // non zero - this is the absolute address of the requested table.
- if( 0 == tableAddress )
- {
- (void)pCtl->intCtx.svc.errCode;
- return 0; // error, sorry
- }
- // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- pCtl->intCtx.out.max = tableMicroHeader.MaxMagn;
- pCtl->intCtx.out.min = tableMicroHeader.MinMagn;
- pCtl->intCtx.out.TableAddress = tableAddress;
- pCtl->intCtx.out.nPoints = nPoints;
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
- // success
- return nPoints;
- }
- // MEM:TABL:DATA?
- // @NFMGetPoints_Continue
- // Uses already prepared context and reads the data points of the characterization
- // table to the top of specified buffer (see @NFMGetPoints_Begin).
- // This method is designed to replace the obsolete @NFMGetPoints.
- // Parameters:
- // @xCtl - control context prepared by previous NFMGetPoints_Begin call
- // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
- //
- // Returns:
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from the table have been read;
- // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
- // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
- int32_t NFMGetPoints_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve )
- {
- sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
- if( NULL == pCtl || NULL == pnPointsRetrieve )
- {
- return eNFMGetPointError_InvalidValue;
- }
- // Check if arguments are valid in general
- if( ( pCtl->sectorId >= eCh_MAX )
- || ( pCtl->portComb >= ePortComb_MAX )
- || ( pCtl->portState >= ePortStateId_MAX )
- || ( pCtl->portComb == ePortComb_UNDEFINED )
- || ( 0 == pCtl->BufferCapacity )
- || ( 0 == pCtl->intCtx.out.nPoints )
- || ( 0 == pCtl->intCtx.out.TableAddress )
- || ( NULL == pCtl->intCtx.in.pDataArray ) )
- {
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return eNFMGetPointError_InvalidValue;
- }
- // check ranges
- if( pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints;
- if( pCtl->intCtx.in.nStartPoint >= pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nStartPoint = pCtl->intCtx.out.nPoints; // end-of-points
- if( pCtl->intCtx.in.nStartPoint +
- pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
- {
- pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
- }
- // check for end condition
- if( 0 == pCtl->intCtx.in.nCount
- || pCtl->intCtx.in.nStartPoint == pCtl->intCtx.out.nPoints )
- {
- *pnPointsRetrieve = 0; // number of points read is zero
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
- return eNFMGetPointError_Success;
- }
- int32_t success_rc = eNFMGetPointError_Success;
-
- // check buffer capacity range
- if( pCtl->intCtx.in.nCount > pCtl->BufferCapacity )
- {
- pCtl->intCtx.in.nCount = pCtl->BufferCapacity;
- success_rc = eNFMGetPointError_OutOfBuffer; // out of buffer, the number of points is limited
- }
- else
- if( pCtl->intCtx.in.nStartPoint + pCtl->intCtx.in.nCount < pCtl->intCtx.out.nPoints )
- {
- success_rc = eNFMGetPointError_Limit; // number of points is limited by user
- }
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_IO;
- size_t nRead = NFMClassExtended->private.methods.memory.getChrzPoints( &pCtl->intCtx );
- // check for error condition
- if( nRead == 0 )
- {
- *pnPointsRetrieve = 0; // number of points read is zero
- (void)pCtl->intCtx.svc.errCode;
- return eNFMGetPointError_DataError;
- }
- pCtl->intCtx.in.nStartPoint += nRead; // increment start point for next call
- // check range
- if( pCtl->intCtx.in.nStartPoint +
- pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
- {
- pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
- }
- *pnPointsRetrieve = nRead; // number of points read
-
- return success_rc;
- }
- // Reads amount of points in the characterization table
- size_t NFMGetPointsCount( eChrz_t tableId )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader )
- return (0);
- return (size_t)pChrzHeader->Points;
- }
- // MEM:TABL:POIN?
- // Reads amount of points in the characterization table
- bool NFMGetPointsCount_Safe( eChrz_t tableId, int16_t * count )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == count )
- return false;
- *count = pChrzHeader->Points;
- return true;
- }
- // MEM:TABL:DATE?
- // Reads the date of characterization table
- bool NFMGetDate( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == buffer || 0 == size || NULL == bytes )
- return (false);
- size_t nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->CalDate,
- sizeof(pChrzHeader->CalDate),
- buffer,
- size );
- *bytes = nCpy;
- return true;
- }
- // MEM:TABL:TIME?
- // Reads the time of characterization table
- bool NFMGetTime( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == buffer || 0 == size || NULL == bytes )
- return (false);
- size_t nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->CalTime,
- sizeof(pChrzHeader->CalTime),
- buffer,
- size );
- *bytes = nCpy;
- return true;
- }
- // MEM:TABL:FREQ:TYPE?
- // Reads the type of the frequency scale of data characterization table
- bool NFMGetScaleType( eChrz_t tableId, eChrzScaleType_t * pType )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader )
- return (false);
- if( NULL != pType )
- {
- if( SWEEP_VERSION_LINEAR == pChrzHeader->Version )
- {
- *pType = eChScaleLinear;
- return true;
- }
- else if( SWEEP_VERSION_SEGMENT == pChrzHeader->Version )
- {
- *pType = eChScaleSegment;
- return true;
- }
- }
- return false;
- }
- // MEM:TABL:FREQ:SEGM:DATA?
- // Reads the scale segment of data characterization table
- // Pass NULL in @pSegment to retrieve amount of segments in return value
- size_t NFMGetScaleSegment( eChrz_t tableId, sEcalSegment_t * pSegment, size_t nSegmentId )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader )
- return (0);
- // in case @pSegment is NULL, return amount of segments
- if( NULL == pSegment )
- {
- if( 1 == pChrzHeader->Version ) // Linear Sweep
- {
- return 1; // One segment
- }
- return pChrzHeader->NSegm;
- }
- if( ( (nSegmentId >= pChrzHeader->NSegm) && (pChrzHeader->Version == 2) )
- || ( (nSegmentId != 0) && (pChrzHeader->Version == 1) )
- || ( pChrzHeader->Version != 1 && pChrzHeader->Version != 2) )
- {
- // error: check the @nSegmentId, it must be less than amount of segments
- return 0;
- }
- else
- {
- if( 1 == pChrzHeader->Version ) // Linear Sweep
- pSegment->Points = pChrzHeader->Points;
- else
- pSegment->Points = pChrzHeader->Segm[ nSegmentId ].Points;
- double Fstart = 0.0;
- double Fstop = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fstart,
- // & pChrzHeader->Segm[ nSegmentId ].Fstart_unaligned,
- // sizeof(Fstart)
- // );
- if( 1 == pChrzHeader->Version ) // Linear Sweep
- Fstart = pChrzHeader->Fmin_unaligned;
- else
- Fstart = pChrzHeader->Segm[ nSegmentId ].Fstart_unaligned;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fstop,
- // & pChrzHeader->Segm[ nSegmentId ].Fstop_unaligned,
- // sizeof(Fstop)
- // );
- if( 1 == pChrzHeader->Version ) // Linear Sweep
- Fstop = pChrzHeader->Fmax_unaligned;
- else
- Fstop = pChrzHeader->Segm[ nSegmentId ].Fstop_unaligned;
- pSegment->Fstart = Fstart;
- pSegment->Fstop = Fstop;
- }
- return 1;
- }
- // @NFMGetScaleFreqs_Begin
- // Prepares a retrieving context for calling the @NFMGetScaleFreqs_Continue routine.
- // Initializes such values as:
- // - a number of starting point to retrive
- // - a buffer to retrieve the values to
- // - characterization table (unit) identifier (@tableId)
- // Parameters:
- // @tableId - characterization table to operate with;
- // @nStartPoint - starting point to begin retrieving from (default = 0);
- // @nStartSegment - starting segment to begin retrieving from (default = 0);
- // @pFreqArray - a floating point values buffer to store data to;
- // @BufferCapacity - receiving buffer capacity [@pFreqArray]
- // @xCtl - a control structure to intialize; use this structure to call @NFMGetScaleFreqs_Continue.
- //
- // Returns: integer result (see @eNFMGetPointError_t):
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
- int32_t NFMGetScaleFreqs_Begin( eChrz_t tableId, double * pFreqArray, size_t BufferCapacity, xNFMGetFreqPoints_t * xCtl )
- {
- sNFMGetFreqPoints_t * pCtl = (sNFMGetFreqPoints_t*)(xCtl);
- // Checking arguments:
- if( tableId >= eCh_MAX
- || NULL == pFreqArray
- || NULL == xCtl
- || 0 == BufferCapacity )
- {
- return (eNFMGetPointError_InvalidValue); // error condition
- }
- // initialize the fields
- pCtl->pDataArray = pFreqArray; // specify receiving buffer
- pCtl->tableId = tableId; // specify table ID;
- // Get the scale type (LIN | SEGM):
- if( ! NFMClass->methods.xCharacterization.getScaleType( tableId, &pCtl->scaleType ) )
- {
- return (eNFMGetPointError_DataError); // error condition
- }
- // Get segments count for linear or segment scale
- switch( pCtl->scaleType )
- {
- case eChScaleSegment:
- {
- // Get segments count
- pCtl->nSegments = NFMClass->methods.xCharacterization.getScaleSegment( tableId, NULL, 0 );
- // Check segments count
- if( 0 == pCtl->nSegments )
- {
- return (eNFMGetPointError_DataError); // error condition: invalid segments count (=0)
- }
- }
- break;
- case eChScaleLinear:
- {
- // For linear scale: number of segments is 1
- pCtl->nSegments = 1;
- }
- break;
- default:
- return (eNFMGetPointError_DataError); // error condition: invalid scale type
- }
- // Initialize the rest fields
- pCtl->BufferCapacity = BufferCapacity; // set user buffer capacity
- pCtl->nStartSegment = 0; // specify starting segment
- pCtl->nStartPoint = 0; // specify starting point
- pCtl->Segment.Points = 0; // forward set, will be updated in @NFMGetScaleFreqs_Continue
- pCtl->Segment.Fstart = 0.0;
- pCtl->Segment.Fstop = 0.0;
- return eNFMGetPointError_Success;
- }
- // @NFMGetScaleFreqs_Continue
- // Related SCPI command: 'MEM:TABL:FREQ:DATA?'
- // Reads the frequencies of data characterization table's points (either for Linear and Segment scale)
- // and stores it into the buffer specified by calling @NFMGetScaleFreqs_Begin
- // Note: the points are stored to the top of the specified buffer each call.
- //
- // Parameters:
- // @xCtl - retrieve context, must be initialized by @NFMGetScaleFreqs_Begin
- // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
- //
- // !!! Attention: user shall control the @pFreqArray buffer range itself when calling @NFMGetScaleFreqs_Begin
- // !!! and guarantee, that it has enough room to recevie specified number of points [@nPointsRetrieve].
- //
- // Returns:
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
- // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
- // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
- int32_t NFMGetScaleFreqs_Continue( xNFMGetFreqPoints_t * xCtl, size_t * pnPointsRetrieve )
- {
- sNFMGetFreqPoints_t * pCtl = (sNFMGetFreqPoints_t*)(xCtl);
- // Checking arguments:
- if( NULL == xCtl || NULL == pnPointsRetrieve || 0 == *pnPointsRetrieve )
- {
- return (eNFMGetPointError_InvalidValue); // error condition
- }
- // Check input parameters from context:
- if( 0 == pCtl->nSegments || eChScale_undefined == pCtl->scaleType || eCh_MAX <= pCtl->tableId || NULL == pCtl->pDataArray || 0 == pCtl->BufferCapacity )
- {
- return (eNFMGetPointError_InvalidValue); // error condition
- }
- size_t iPointRequested = 0;
- bool bBreak = false;
- int32_t rc = eNFMGetPointError_Success; // forward set to success code
- // For each segment and each point:
- for( (void)pCtl->nStartSegment;
- (pCtl->nStartSegment < pCtl->nSegments) && (!bBreak);
- ++ pCtl->nStartSegment )
- {
- for( (void)pCtl->nStartPoint;
- ((void)pCtl->Segment.Points, (!bBreak));
- ++ pCtl->nStartPoint )
- {
- // Check if the segment is loaded
- if( 0 == pCtl->Segment.Points )
- {
- // load segment data:
- switch( pCtl->scaleType )
- {
- case eChScaleSegment:
- {
- // Retrieve the segment data
- if( 1 != NFMClass->methods.xCharacterization.getScaleSegment( pCtl->tableId, &pCtl->Segment, pCtl->nStartSegment ) )
- {
- return (eNFMGetPointError_DataError); // error condition: can not load segment data
- }
- }
- break;
-
- case eChScaleLinear:
- {
- // For linear scale: retrieve from the common characterization header
- if( ! NFMClass->methods.xCharacterization.getPointsCountSafe( pCtl->tableId, &pCtl->Segment.Points )
- || ! NFMClass->methods.xCharacterization.getStartFreq( pCtl->tableId, &pCtl->Segment.Fstart )
- || ! NFMClass->methods.xCharacterization.getStopFreq( pCtl->tableId, &pCtl->Segment.Fstop ) )
- {
- return (eNFMGetPointError_DataError); // error condition: can not load segment data
- }
- }
- break;
-
- default:
- return (eNFMGetPointError_DataError); // error condition: invalid scale type
- }
- // Calculate the discrette
- pCtl->Fdesc = (pCtl->Segment.Fstop - pCtl->Segment.Fstart) / (pCtl->Segment.Points - 1);
- pCtl->nStartPoint = 0; // Reset start point for current segment
- }
- // Segment loaded?
- if( 0 != pCtl->Segment.Points )
- {
- // yes, check condition: all the points of segment have been processed?
- if( pCtl->nStartPoint >= pCtl->Segment.Points ) break;
- }
- else
- {
- // Invalid segment
- return (eNFMGetPointError_DataError); // error condition: can not load segment data
- }
- // Fill the output array from the begining
- // Note @pDataArray have at least one cell due to input checking
- pCtl->pDataArray[ iPointRequested++ ] = (pCtl->Segment.Fstart + pCtl->Fdesc * pCtl->nStartPoint);
- // Check for overflow: user buffer overflow
- if( iPointRequested >= pCtl->BufferCapacity )
- {
- bBreak = true;
- rc = eNFMGetPointError_OutOfBuffer; // warning
- /* break; DO NOT BREAK, need to increment @nStartPoint */
- }
- // Check for end condition: user limit
- if( iPointRequested >= *pnPointsRetrieve )
- {
- bBreak = true;
- rc = eNFMGetPointError_Limit; // warning
- /* break; DO NOT BREAK, need to increment @nStartPoint */;
- }
- }
- // Check for end condition: out of points in segment or out of segments
- if( pCtl->nStartPoint >= pCtl->Segment.Points )
- {
- if( pCtl->nStartSegment >= pCtl->nSegments - 1 ) /* -1: because @nStartSegment has not been incremented yet */
- {
- pCtl->nStartSegment++; // instead of reaching the top of operator 'for'
- bBreak = true;
- (void)rc; // eNFMGetPointError_Success, end-of-data
- }
-
- pCtl->Segment.Points = 0; // Reset points count: make to load the segment data at next iteration
- pCtl->nStartPoint = 0; // Reset start point for next segment
- }
- if( bBreak ) break; // do not increment @nStartSegment
- }
- (void)rc; // If no points are available, the @eNFMGetPointError_Success code is returned with *pnPointsRetrieve set to zero
- *pnPointsRetrieve = iPointRequested; // write number of points read
- return rc;
- }
- // @SWGetTablePoints_Begin
- // Prepares a retrieving context for calling the @SWGetTablePoints_Continue routine.
- // Initializes such values as:
- // - a number of starting point to retrive
- // - a buffer to retrieve the values to
- // - points table (unit) identifier (@tableId)
- // Parameters:
- // @tableId - characterization table to operate with;
- // @nStartPoint - starting point to begin retrieving from (default = 0);
- // @nStartSegment - starting segment to begin retrieving from (default = 0);
- // @pPointsArray - a floating point values buffer to store data to;
- // @BufferCapacity - receiving buffer capacity [@pFreqArray]
- // @xCtl - a control structure to intialize; use this structure to call @SWGetTablePoints_Continue.
- //
- // Returns: integer result (see @eNFMGetPointError_t):
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
- int32_t SWGetTablePoints_Begin( eChrz_t tableId, sSWTablePoint_t * pPointsArray, size_t BufferCapacity, xSWGetTablePoints_t * xCtl )
- {
- sSWGetTablePoints_t * pCtl = (sSWGetTablePoints_t*)(xCtl);
- // Checking arguments:
- if( tableId >= eCh_MAX
- || NULL == pPointsArray
- || NULL == xCtl
- || 0 == BufferCapacity )
- {
- return (eNFMGetPointError_InvalidValue); // error condition
- }
- // initialize the fields
- pCtl->pDataArray = pPointsArray; // specify receiving buffer
- pCtl->tableId = tableId; // specify table ID;
- // Initialize the rest fields
- pCtl->BufferCapacity = BufferCapacity; // set user buffer capacity
- pCtl->nStartPoint = 0; // specify starting point
- //pCtl->nNumberOfPoints = TableHandle.GetNumberOfPoints();
- pCtl->nNumberOfPoints = TableHandle.GetNumberOfPoints();
- pCtl->TablePoint.port1 = 0;
- pCtl->TablePoint.port2 = 0;
- return eNFMGetPointError_Success;
- }
- // @NFMGetScaleFreqs_Continue
- // Related SCPI command: 'MEM:TABL:FREQ:DATA?'
- // Reads the frequencies of data characterization table's points (either for Linear and Segment scale)
- // and stores it into the buffer specified by calling @NFMGetScaleFreqs_Begin
- // Note: the points are stored to the top of the specified buffer each call.
- //
- // Parameters:
- // @xCtl - retrieve context, must be initialized by @NFMGetScaleFreqs_Begin
- // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
- //
- // !!! Attention: user shall control the @pFreqArray buffer range itself when calling @NFMGetScaleFreqs_Begin
- // !!! and guarantee, that it has enough room to recevie specified number of points [@nPointsRetrieve].
- //
- // Returns:
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
- // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
- // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
- int32_t SWGetTablePoints_Continue( xSWGetTablePoints_t * xCtl, size_t * pnPointsRetrieve )
- {
- sSWGetTablePoints_t * pCtl = (sSWGetTablePoints_t*)(xCtl);
- // Checking arguments:
- if( NULL == xCtl || NULL == pnPointsRetrieve || 0 == *pnPointsRetrieve )
- {
- return (eNFMGetPointError_InvalidValue); // error condition
- }
- // Check input parameters from context:
- if( eCh_MAX <= pCtl->tableId || NULL == pCtl->pDataArray || 0 == pCtl->BufferCapacity )
- {
- return (eNFMGetPointError_InvalidValue); // error condition
- }
- size_t iPointRequested = 0;
- bool bBreak = false;
- int32_t rc = eNFMGetPointError_Success; // forward set to success code
- // For each point:
- for( (void)pCtl->nStartPoint;
- ((void)pCtl->nNumberOfPoints, (!bBreak));
- ++ pCtl->nStartPoint )
- {
-
- // Check if the point is loaded
- if( 0 != pCtl->nNumberOfPoints )
- {
- // yes, check condition: all the points of segment have been processed?
- if( pCtl->nStartPoint >= pCtl->nNumberOfPoints )
- { // Check for end condition: out of points in segment or out of segments
- bBreak = true;
- (void)rc; // eNFMGetPointError_Success, end-of-data
- pCtl->nNumberOfPoints = 0; // Reset points count: make to load the segment data at next iteration
- pCtl->nStartPoint = 0; // Reset start point for next segment
- break;
- }
- if( ! TableHandle.Get_Point(pCtl->nStartPoint, &pCtl->TablePoint))
- {
- return (eNFMGetPointError_DataError); // error condition: can not load segment data
- }
- }
- else
- {
- // Invalid segment
- return (eNFMGetPointError_DataError); // error condition: can not load segment data
- }
-
- // Fill the output array from the begining
- // Note @pDataArray have at least one cell due to input checking
- pCtl->pDataArray[ iPointRequested ].port1 = pCtl->TablePoint.port1;
- pCtl->pDataArray[ iPointRequested ].port2 = pCtl->TablePoint.port2;
- // To next point
- iPointRequested++;
- // Check for overflow: user buffer overflow
- if( iPointRequested >= pCtl->BufferCapacity )
- {
- bBreak = true;
- rc = eNFMGetPointError_OutOfBuffer; // warning
- /* break; DO NOT BREAK, need to increment @nStartPoint */
- }
-
- // Check for end condition: user limit
- if( iPointRequested >= *pnPointsRetrieve )
- {
- bBreak = true;
- rc = eNFMGetPointError_Limit; // warning
- /* break; DO NOT BREAK, need to increment @nStartPoint */;
- }
- }
- (void)rc; // If no points are available, the @eNFMGetPointError_Success code is returned with *pnPointsRetrieve set to zero
- *pnPointsRetrieve = iPointRequested; // write number of points read
- return rc;
- }
- /*
- /// --------------------------------------------------------------------------
- ///
- /// \brief createAbscissa
- /// \details ������� ��� �������� ������������ �������� ��� ��������� ���������
- /// \param[in] segment - QVector �� ��������� ��������� (Fmin, Fmax, NPoints)
- /// \return ��������� �� ������ ������������ �������� � ���������� ������� � ��������� �����
- /// �� ���� ��������� ��������� (RndAbscissa)
- /// \note �������� � lambda ����� �� ���������� Hardware � ������������ ����� NfmKit.h,
- /// �.�. ��� ��������� ����� ������ ������ ���������� ������.
- /// \note ������� �����������, �� �������������� �� ������.
- static auto createAbscissa( const QVector<Planar::VNA::Hardware::SegmentInfo>& segments )
- {
- // ���������� ����� �� ���� ���������:
- size_t nPointsTotal = 0;
- // ��������� ��� ������� ���������� �������� ���������� ������� ��������������:
- // (��������� ������ ���������� ����� �� ���� ��������� ���������):
- for ( auto& segment : segments )
- {
- // ���������� ����� � ��������:
- size_t nPoints = static_cast<size_t>(segment.Points);
- // ������������ ������ ���������� ����� � ���������
- nPointsTotal += nPoints;
- }
- // �������� ������� ������������ ������� ��� ���� ��������� (����� ���������� �����):
- Dsp::RndAbscissa* customAbscissa = new Dsp::RndAbscissa( nPointsTotal );
- // �������� �������, ��������� ������� ������ �������������
- // ����� � ��������: @abscissaPointIndex
- size_t abscissaPointIndex = 0;
- // ��������� ��� ������� ���������� �������� ���������� ������� ��������������:
- // (���������� ������ � ���������� ��������� �����):
- for ( auto& segment : segments )
- {
- // ���������� ����� � ��������:
- size_t nPoints = static_cast<size_t>(segment.Points);
- // �������� ��������� � ������� ��:
- // - ��������� ������� ��������: @Fmin
- auto Fmin = Unit(segment.Fmin).toSI().value();
- // - �������� ������� ��������: @Fmax
- auto Fmax = Unit(segment.Fmax).toSI().value();
- // - ��� ����� ������ � ������� ��������: @Fstep
- auto Fstep = (Fmax - Fmin) / nPoints;
- // ���������� ��������� ����� �������:
- for ( size_t p = 0; p < nPoints; ++p )
- {
- customAbscissa->setValue( abscissaPointIndex + p, Fmin + Fstep * p );
- }
- // �������� �������� ������� �� ���������� ����� � ������� ��������,
- // ������������� � ���������� ��������:
- abscissaPointIndex += nPoints;
- }
- return QSharedPointer<Dsp::RndAbscissa>(customAbscissa);
- */
- // MEM:TABL:FREQ:STAR?
- // Reads the start frequency of the characterization table
- bool NFMGetStartFreq( eChrz_t tableId, double * pStartFreq )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == pStartFreq )
- return (false);
- if( SWEEP_VERSION_LINEAR == pChrzHeader->Version )
- {
- double Fmin = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fmin,
- // & pChrzHeader->Fmin_unaligned,
- // sizeof(Fmin)
- // ); // *pStartFreq = pChrzHeader->Fmin, fixed 28/08/18
- Fmin = pChrzHeader->Fmin_unaligned;
- *pStartFreq = Fmin;
- return true;
- }
- else if( SWEEP_VERSION_SEGMENT == pChrzHeader->Version )
- {
- if( 0 < pChrzHeader->NSegm )
- {
- // double min = pChrzHeader->Segm[0].Fstart; // fixed 28/08/18
- double Fstart_min = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fstart_min,
- // & pChrzHeader->Segm[0].Fstart_unaligned,
- // sizeof(Fstart_min)
- // ); // min = pChrzHeader->Segm[0].Fstart
- Fstart_min = pChrzHeader->Segm[0].Fstart_unaligned;
- for( size_t n = 0; n < pChrzHeader->NSegm; ++n )
- {
- double Fstart_n = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fstart_n,
- // & pChrzHeader->Segm[n].Fstart_unaligned,
- // sizeof(Fstart_n)
- // ); // min = pChrzHeader->Segm[n].Fstart, fixed 28/08/18
- Fstart_n = pChrzHeader->Segm[n].Fstart_unaligned;
- if( Fstart_n < Fstart_min )
- {
- Fstart_min = Fstart_n;
- }
- }
- *pStartFreq = Fstart_min;
- return true;
- }
- }
- return false;
- }
- // MEM:TABL:FREQ:STOP?
- // Reads the stop frequency of the characterization table
- bool NFMGetStopFreq( eChrz_t tableId, double * pStopFreq )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == pStopFreq )
- return (false);
- if( SWEEP_VERSION_LINEAR == pChrzHeader->Version )
- {
- double Fmax = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fmax,
- // & pChrzHeader->Fmax_unaligned,
- // sizeof(Fmax)
- // ); // *pStopFreq = pChrzHeader->Fmax;, fixed 28/08/18
- Fmax = pChrzHeader->Fmax_unaligned;
- *pStopFreq = Fmax;
- return true;
- }
- else if( SWEEP_VERSION_SEGMENT == pChrzHeader->Version )
- {
- if( 0 < pChrzHeader->NSegm )
- {
- double Fstop_max = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fstop_max,
- // & pChrzHeader->Segm[ pChrzHeader->NSegm - 1 ].Fstop_unaligned,
- // sizeof(Fstop_max)
- // ); // double max = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 ].Fstop;, fixed 28/08/18
- Fstop_max = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 ].Fstop_unaligned;
- for( size_t n = 0; n < pChrzHeader->NSegm; ++n )
- {
- double Fstop_n = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fstop_n,
- // & pChrzHeader->Segm[ pChrzHeader->NSegm - 1 - n ].Fstop_unaligned,
- // sizeof(Fstop_n)
- // ); // max = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 - n ].Fstop;, fixed 28/08/18
- Fstop_n = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 - n ].Fstop_unaligned;
- if( Fstop_n > Fstop_max )
- {
- Fstop_max = Fstop_n;
- }
- }
- *pStopFreq = Fstop_max;
- return true;
- }
- }
- return false;
- }
- // MEM:TABL:TEMP?
- // Reads the characterization temperature of characterization table
- bool NFMGetChrzTemp( eChrz_t tableId, double * pTemperature )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == pTemperature )
- return (false);
- double temperature = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & temperature,
- // & pChrzHeader->Temperature_unaligned,
- // sizeof(temperature)
- // ); // *pTemperature = pChrzHeader->Temperature;, fixed 28/08/18
- temperature = pChrzHeader->Temperature_unaligned;
- *pTemperature = temperature;
- return true;
- }
- // MEM:TABL:CONN?
- // Reads the connector type of the NFM
- bool NFMGetConnectorType( ePortId_t portId, char * buffer, size_t size, size_t * bytes )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( eChFactory, NULL, 0 );
- if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
- return (false);
- uint16_t connector;
- const char * pDescConnector = NULL;
- size_t nCpy = 0;
- switch( portId )
- {
- case ePortId_A:
- connector = pChrzHeader->ConnectorA;
- break;
- case ePortId_B:
- connector = pChrzHeader->ConnectorB;
- break;
- case ePortId_C:
- connector = pChrzHeader->ConnectorC;
- break;
- case ePortId_D:
- connector = pChrzHeader->ConnectorD;
- break;
- default: return (false);
- }
- if( connector >= sizeof(aConnectorsNames)/sizeof(aConnectorsNames[0]) )
- {
- pDescConnector = pcConnectorUndefined;
- }
- else
- {
- pDescConnector = aConnectorsNames[ connector ];
- }
- nCpy = static_StrCpyLimit(
- (const char*)pDescConnector,
- 0,
- buffer,
- size );
- *bytes = nCpy;
- return true;
- }
- // MEM:TABL:ADAP?
- // Reads the adapter description of the NFM connector
- bool NFMGetAdapterDesc( eChrz_t tableId, ePortId_t portId, char * buffer, size_t size, size_t * bytes )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
- return (false);
- size_t nCpy = 0;
- switch( portId )
- {
- case ePortId_A:
- nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->AdapterDescriptionA,
- sizeof(pChrzHeader->AdapterDescriptionA),
- buffer,
- size );
- break;
- case ePortId_B:
- nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->AdapterDescriptionB,
- sizeof(pChrzHeader->AdapterDescriptionB),
- buffer,
- size );
- break;
- case ePortId_C:
- nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->AdapterDescriptionC,
- sizeof(pChrzHeader->AdapterDescriptionC),
- buffer,
- size );
- break;
- case ePortId_D:
- nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->AdapterDescriptionD,
- sizeof(pChrzHeader->AdapterDescriptionD),
- buffer,
- size );
- break;
- default: return (false);
- }
- *bytes = nCpy;
- return true;
- }
- // MEM:TABL:ANAL? ( =ANALyzer)
- // Reads the analyzer type
- bool NFMGetAnalyzer( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
- return (false);
- size_t nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->Analyzer,
- sizeof(pChrzHeader->Analyzer),
- buffer,
- size );
- *bytes = nCpy;
- return true;
- }
- // MEM:TABL:PLAC?
- // Reads the place where the characterization had been created
- bool NFMGetPlace( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
- return (false);
- size_t nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->Location,
- sizeof(pChrzHeader->Location),
- buffer,
- size );
- *bytes = nCpy;
- return true;
- }
- // MEM:TABL:OPER?
- // Reads the the characterization operator's name
- bool NFMGetOperator( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
- {
- const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
- if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
- return (false);
- size_t nCpy = static_StrCpyLimit(
- (const char*)pChrzHeader->Operator,
- sizeof(pChrzHeader->Operator),
- buffer,
- size );
- *bytes = nCpy;
- return true;
- }
- // MEM:TABL:THER:CORR:FREQ:START
- // Reads the the start frequency of thermocompensation data
- static bool NFMGetStartFreqThermo( double * pStartFreq )
- {
- const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
- if( NULL == pTCompHeader || NULL == pStartFreq )
- return (false);
- double Fmin = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fmin,
- // & pTCompHeader->Fmin_unaligned,
- // sizeof(Fmin)
- // ); // *pStartFreq = pTCompHeader->Fmin;, fixed 28/08/18
- Fmin = pTCompHeader->Fmin_unaligned;
- *pStartFreq = Fmin;
- return true;
- }
- // MEM:TABL:THER:CORR:FREQ:STOP
- // Reads the the stop frequency of thermocompensation data
- static bool NFMGetStopFreqThermo( double * pStopFreq )
- {
- const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
- if( NULL == pTCompHeader || NULL == pStopFreq )
- return (false);
- double Fmax = 0.0;
- // aligned access to the unaligned 'double' field
- // memcpy( & Fmax,
- // & pTCompHeader->Fmax_unaligned,
- // sizeof(Fmax)
- // ); // *pStopFreq = pTCompHeader->Fmax;, fixed 28/08/18
- Fmax = pTCompHeader->Fmax_unaligned;
- *pStopFreq = Fmax;
- return true;
- }
- // Reads the amount of points of thermocompensation data
- static size_t NFMGetPointsThermo()
- {
- const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
- if( NULL == pTCompHeader )
- return (0);
- return pTCompHeader->Points;
- }
- // MEM:TABL:THER:CORR:POIN?
- // Reads the amount of points of thermocompensation data
- static bool NFMGetPointsThermo_Safe( int16_t * count )
- {
- const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
- if( NULL == pTCompHeader || NULL == count )
- return false;
- *count = pTCompHeader->Points;
- return true;
- }
- // // MEM:TABL:THER:CORR:MAGN?
- // // Reads the magnitude data points of the thermocompensation table
- // static size_t NFMGetPointsMagnThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl )
- // {
- // if( portComb >= ePortComb_MAX
- // || portComb == ePortComb_UNDEFINED
- // || portState >= ePortStateId_MAX
- // || portState == ePortStateId_UNDEFINED
- // || NULL == pCtl
- // || NULL == pCtl->in.pDataArray
- // )
- // {
- // if( NULL != pCtl )
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- //
- // return 0;
- // }
- //
- // /* --- do it later: inside @getChrzTableHeader() call
- // // Validate the combination of @portComb, @portState and
- // // validate the @portComb and @portState itself.
- // // Retrieve the table index (ordered index)
- // size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
- //
- // if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
- // {
- // // Invalid combination or value
- // return 0;
- // }
- // */
- //
- // // Check the input parameter: @pCtl->in.nCount
- // // For zero value: required to load the table header
- // // During the loading the table header it is required:
- // // - load the main thermocompensation header, check CRC
- // // - retrieve number of points (@nPoints) from the header
- // // - load the table header and check it's CRC
- // // - retrieve the table address @TableAddress (for next operations)
- // // - retrieve the @min and @max fields from the table header
- // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- // // - return (1) in case of success, or (0) on error
- // if( 0 == pCtl->in.nCount )
- // {
- // // load thermocompensation main header
- // // and check the CRC
- // const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory
- // .getTCompHeader( NULL, 0 );
- //
- // // check the TComp header: number of points
- // if( NULL == pTCompHeader
- // || 0 == pTCompHeader->Points )
- // {
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVHDR;
- // return (0);
- // }
- //
- // // move @.Points into @nPoints
- // // due to @pTCompHeader will be corrupted
- // size_t nPoints = pTCompHeader->Points;
- //
- // sEcalTCompTableMagnHeader_t tableMicroHeader;
- //
- // // load the table base address
- // // Note: the data by @pChrzHeader is not valid after this call,
- // // due to the function uses the same internal buffer!
- // size_t tableAddress = NFMClassExtended->private.methods.memory
- // .getTCompMagnTableHeader( // load the table base address
- // portComb, // for specified port combination
- // portState, // for specified port state
- // nPoints, // for retrieved number of points
- // &tableMicroHeader, // and store the header into @tableMicroHeader
- // &pCtl->svc.errCode // And fill up the error code
- // );
- //
- // // check the result: @tableAddress
- // // 0 - table corrupted or invalid port combination or port state.
- // // but since the @portComb and @portState are validated above...
- // // this result means only that the table is corrupted
- // // non zero - this is the absolute address of the requested table.
- // if( 0 == tableAddress )
- // {
- // (void)pCtl->svc.errCode;
- // return 0; // error, sorry
- // }
- //
- // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- // pCtl->out.max = tableMicroHeader.MaxMagn;
- // pCtl->out.min = tableMicroHeader.MinMagn;
- // pCtl->out.TableAddress = tableAddress;
- // pCtl->out.nPoints = nPoints;
- //
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_NOERR;
- // // success
- // return 1;
- // }
- //
- // // -----------------
- // // User must call this function with (pCtl->in.nCount=0) first time
- // // to initialize the @pCtl->out contents.
- // // Here: 0 != pCtl->in.nCount
- // // -----------------
- //
- // // Check the header data, loaded at previous step ( see pCtl->in.nCount == 0 )
- // if( 0 == pCtl->out.nPoints // check the number of points in the table
- // || 0 == pCtl->out.TableAddress ) // check the table base address
- // {
- // // error, invalid parameters
- // // Call the function with (pCtl->in.nCount = 0) to load the header
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- //
- // return 0;
- // }
- //
- // // Check the input parameters
- // if( pCtl->in.nCount > pCtl->out.nPoints // check the amount of requested points
- // || pCtl->in.nStartPoint >= pCtl->out.nPoints // check the starting point
- // || NULL == pCtl->in.pDataArray ) // check receiving data buffer
- // {
- // // error: invalid input parameters
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- //
- // return 0;
- // }
- //
- // return NFMClassExtended->private.methods.memory.getTCompMagnPoints( pCtl );
- // }
- // // MEM:TABL:THER:CORR:PHASE?
- // // Reads the phase data points of the thermocompensation table
- // static size_t NFMGetPointsPhaseThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl )
- // {
- // if( portComb >= ePortComb_MAX
- // || portComb == ePortComb_UNDEFINED
- // || portState >= ePortStateId_MAX
- // || portState == ePortStateId_UNDEFINED
- // || NULL == pCtl
- // || NULL == pCtl->in.pDataArray
- // )
- // {
- // if( NULL != pCtl )
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- //
- // return 0;
- // }
- //
- // /* --- do it later: inside @getChrzTableHeader() call
- // // Validate the combination of @portComb, @portState and
- // // validate the @portComb and @portState itself.
- // // Retrieve the table index (ordered index)
- // size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
- //
- // if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
- // {
- // // Invalid combination or value
- // return 0;
- // }
- // */
- //
- // // Check the input parameter: @pCtl->in.nCount
- // // For zero value: required to load the table header
- // // During the loading the table header it is required:
- // // - load the main thermocompensation header, check CRC
- // // - retrieve number of points (@nPoints) from the header
- // // - load the table header and check it's CRC
- // // - retrieve the table address @TableAddress (for next operations)
- // // - retrieve the @min and @max fields from the table header
- // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- // // - return (1) in case of success, or (0) on error
- // if( 0 == pCtl->in.nCount )
- // {
- // // load thermocompensation main header
- // // and check the CRC
- // const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory
- // .getTCompHeader( NULL, 0 );
- //
- // // check the TComp header: number of points
- // if( NULL == pTCompHeader
- // || 0 == pTCompHeader->Points )
- // {
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVHDR;
- //
- // return (0);
- // }
- //
- // // move @.Points into @nPoints
- // // due to @pTCompHeader will be corrupted
- // size_t nPoints = pTCompHeader->Points;
- //
- // sEcalTCompTablePhaseHeader_t tableMicroHeader;
- //
- // // load the table base address
- // // Note: the data by @pChrzHeader is not valid after this call,
- // // due to the function uses the same internal buffer!
- // size_t tableAddress = NFMClassExtended->private.methods.memory
- // .getTCompPhaseTableHeader( // load the table base address
- // portComb, // for specified port combination
- // portState, // for specified port state
- // nPoints, // for retrieved number of points
- // &tableMicroHeader, // and store the header into @tableMicroHeader
- // &pCtl->svc.errCode // And fill up the error code
- // );
- //
- // // check the result: @tableAddress
- // // 0 - table corrupted or invalid port combination or port state.
- // // but since the @portComb and @portState are validated above...
- // // this result means only that the table is corrupted
- // // non zero - this is the absolute address of the requested table.
- // if( 0 == tableAddress )
- // {
- // (void)pCtl->svc.errCode;
- // return 0; // error, sorry
- // }
- //
- // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- // pCtl->out.max = tableMicroHeader.MaxPhase;
- // pCtl->out.min = tableMicroHeader.MinPhase;
- // pCtl->out.TableAddress = tableAddress;
- // pCtl->out.nPoints = nPoints;
- //
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_NOERR;
- //
- // // success
- // return 1;
- // }
- //
- // // -----------------
- // // User must call this function with (pCtl->in.nCount=0) first time
- // // to initialize the @pCtl->out contents.
- // // Here: 0 != pCtl->in.nCount
- // // -----------------
- //
- // // Check the header data, loaded at previous step ( see pCtl->in.nCount == 0 )
- // if( 0 == pCtl->out.nPoints // check the number of points in the table
- // || 0 == pCtl->out.TableAddress ) // check the table base address
- // {
- // // error, invalid parameters
- // // Call the function with (pCtl->in.nCount = 0) to load the header
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- //
- // return 0;
- // }
- //
- // // Check the input parameters
- // if( pCtl->in.nCount > pCtl->out.nPoints // check the amount of requested points
- // || pCtl->in.nStartPoint >= pCtl->out.nPoints // check the starting point
- // || NULL == pCtl->in.pDataArray ) // check receiving data buffer
- // {
- // // error: invalid input parameters
- // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
- //
- // return 0;
- // }
- //
- // return NFMClassExtended->private.methods.memory.getTCompPhasePoints( pCtl );
- // }
- // MEM:TABL:THERmo:CORRection:MAGNitude?
- // NFMGetPointsThermoMagn_Begin
- // Prepares the context before reading the data points of the thermocompensation table of magnitudes
- // This method is designed to replace the obsolete @NFMGetPointsMagnThermo
- // Parameters:
- // @portComb - port combination to request (NFM path);
- // @portState - port state to request (S-parameter);
- // @pDataBuffer - output data buffer;
- // @szDataBuffer - output data buffer capacity;
- // @xCtl - the control context to initialize;
- // Returns: 0 in case error, or number of points in case success.
- size_t NFMGetPointsThermoMagn_Begin( ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- xNFMGetPointsSimplified_t * xCtl )
- {
- sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
- if( NULL == pCtl )
- {
- return eNFMGetPointError_InvalidValue;
- }
- pCtl->isThermoPhase = 0;
- return NFMGetPointsThermo_Begin( portComb, portState, pDataBuffer, szDataBuffer, pCtl );
- }
- // MEM:TABL:THERmo:CORRection:PHASe?
- // NFMGetPointsThermoPhase_Begin
- // Prepares the context before reading the data points of the thermocompensation table of magnitudes/phases
- // This method is designed to replace the obsolete NFMGetPointsPhaseThermo.
- // Parameters:
- // @portComb - port combination to request (NFM path);
- // @portState - port state to request (S-parameter);
- // @pDataBuffer - output data buffer;
- // @szDataBuffer - output data buffer capacity;
- // @xCtl - the control context to initialize;
- // Returns: 0 in case error, or number of points in case success.
- size_t NFMGetPointsThermoPhase_Begin( ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- xNFMGetPointsSimplified_t * xCtl )
- {
- sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
- if( NULL == pCtl )
- {
- return eNFMGetPointError_InvalidValue;
- }
- pCtl->isThermoPhase = 1;
- return NFMGetPointsThermo_Begin( portComb, portState, pDataBuffer, szDataBuffer, pCtl );
- }
- // MEM:TABL:THERmo:CORRection:MAGNitude?
- // MEM:TABL:THERmo:CORRection:PHASe?
- // NFMGetPointsThermo_Begin
- // Prepares the context before reading the data points of the thermocompensation table of magnitudes/phases
- // This method is designed to replace the obsolete @NFMGetPointsMagnThermo/NFMGetPointsPhaseThermo.
- // Parameters:
- // @portComb - port combination to request (NFM path);
- // @portState - port state to request (S-parameter);
- // @pDataBuffer - output data buffer;
- // @szDataBuffer - output data buffer capacity;
- // @xCtl - the control context to initialize;
- // Returns: 0 in case error, or number of points in case success.
- static size_t NFMGetPointsThermo_Begin( ePortComb_t portComb, ePortStateId_t portState,
- sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
- sNFMGetPointsSimplified_t * pCtl )
- {
- my_assert( pCtl ); // see @NFMGetPointsThermoMagn_Begin/NFMGetPointsThermoPhase_Begin
- // Check if arguments are valid in general
- if( ( portComb >= ePortComb_MAX )
- || ( portState >= ePortStateId_MAX )
- || ( portComb == ePortComb_UNDEFINED )
- || ( 0 == szDataBuffer ) )
- {
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- // Check if arguments are valid particularly for this device
- if( ! NFMClassExtended->public.methods.checkTableParams( portComb, portState ) )
- {
- // Invalid combination or value
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return 0;
- }
- // Fill input parameters:
- pCtl->BufferCapacity = szDataBuffer; // - output buffer capacity
- pCtl->sectorId = eChFactory; // - don't care for Thermocompensation
- pCtl->portComb = portComb; // - requested port combination (nfm path)
- pCtl->portState = portState; // - requested state (S-parameter)
- pCtl->intCtx.in.nCount = szDataBuffer; // - number of points to get
- pCtl->intCtx.in.nStartPoint = 0; // - start point
- pCtl->intCtx.in.pDataArray = pDataBuffer; // - output buffer
- // During the loading the table header it is required:
- // - load the main characterization header, check CRC
- // - retrieve number of points (@nPoints) from the header for specified @sectorId
- // - load the table header and check it's CRC
- // - retrieve the table address @TableAddress (for next operations)
- // - retrieve the @min and @max fields from the table header
- // - store @min, @max, @TableAddress, @nPoints into @pCtl.intCtx.out
- // load thermocompensation main header
- // and check the CRC
- const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
- // check the TComp header: number of points
- if( NULL == pTCompHeader
- || 0 == pTCompHeader->Points )
- {
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVHDR;
- return (0);
- }
- // move @.Points into @nPoints
- // due to @pTCompHeader will be corrupted
- size_t nPoints = pTCompHeader->Points;
- union
- {
- sEcalTCompTableMagnHeader_t tableMicroHeaderMagn;
- sEcalTCompTablePhaseHeader_t tableMicroHeaderPhase;
- };
- // load the table base address
- // Note: the data by @pChrzHeader is not valid after this call,
- // due to the function uses the same internal buffer!
- size_t tableAddress = 0;
- if( 0 == pCtl->isThermoPhase )
- tableAddress = NFMClassExtended->private.methods.memory
- .getTCompMagnTableHeader( // load the table base address: magnitude
- portComb, // for specified port combination
- portState, // for specified port state
- nPoints, // for retrieved number of points
- &tableMicroHeaderMagn, // and store the header into @tableMicroHeaderMagn
- &pCtl->intCtx.svc.errCode // And fill up the error code
- );
- else
- tableAddress = NFMClassExtended->private.methods.memory
- .getTCompPhaseTableHeader( // load the table base address: phase
- portComb, // for specified port combination
- portState, // for specified port state
- nPoints, // for retrieved number of points
- &tableMicroHeaderPhase, // and store the header into @tableMicroHeaderPhase
- &pCtl->intCtx.svc.errCode // And fill up the error code
- );
- // check the result: @tableAddress
- // 0 - table corrupted or invalid port combination or port state.
- // but since the @portComb and @portState are validated above...
- // this result means only that the table is corrupted
- // non zero - this is the absolute address of the requested table.
- if( 0 == tableAddress )
- {
- (void)pCtl->intCtx.svc.errCode;
- return 0; // error, sorry
- }
- // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
- if( 0 == pCtl->isThermoPhase )
- {
- pCtl->intCtx.out.max = tableMicroHeaderMagn.MaxMagn;
- pCtl->intCtx.out.min = tableMicroHeaderMagn.MinMagn;
- }
- else
- {
- pCtl->intCtx.out.max = tableMicroHeaderPhase.MaxPhase;
- pCtl->intCtx.out.min = tableMicroHeaderPhase.MinPhase;
- }
- pCtl->intCtx.out.TableAddress = tableAddress;
- pCtl->intCtx.out.nPoints = nPoints;
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
- // success
- return nPoints;
- }
- // MEM:TABL:THER:CORR:MAGN?
- // @NFMGetPointsThermoMagn_Continue
- // Uses already prepared context and reads magnutude data points of the thermocompensation
- // table to the top of specified buffer (see @NFMGetPointsThermo_Begin).
- // This method is designed to replace the obsolete @NFMGetPointsMagnThermo.
- // Parameters:
- // @xCtl - control context prepared by previous NFMGetPointsThermo_Begin call
- // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
- //
- // Returns:
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from the table have been read;
- // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
- // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
- int32_t NFMGetPointsThermoMagn_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve )
- {
- sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
- if( NULL == pCtl || NULL == pnPointsRetrieve || 0 != pCtl->isThermoPhase )
- {
- return eNFMGetPointError_InvalidValue;
- }
- return NFMGetPointsThermo_Continue( pCtl, pnPointsRetrieve );
- }
- // MEM:TABL:THER:CORR:PHAS?
- // @NFMGetPointsThermoPhase_Continue
- // Uses already prepared context and reads phase data points of the thermocompensation
- // table to the top of specified buffer (see @NFMGetPointsThermo_Begin).
- // This method is designed to replace the obsolete @NFMGetPointsPhaseThermo.
- // Parameters:
- // @xCtl - control context prepared by previous NFMGetPointsThermo_Begin call
- // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
- //
- // Returns:
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from the table have been read;
- // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
- // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
- int32_t NFMGetPointsThermoPhase_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve )
- {
- sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
- if( NULL == pCtl || NULL == pnPointsRetrieve || 0 == pCtl->isThermoPhase )
- {
- return eNFMGetPointError_InvalidValue;
- }
- return NFMGetPointsThermo_Continue( pCtl, pnPointsRetrieve );
- }
- // MEM:TABL:THER:CORR:MAGN?
- // MEM:TABL:THER:CORR:PHAS?
- // @NFMGetPointsThermo_Continue
- // Uses already prepared context and reads magnutude/phase data points of the thermocompensation
- // table to the top of specified buffer (see @NFMGetPointsThermo_Begin).
- // This method is designed to replace the obsolete @NFMGetPointsMagnThermo/NFMGetPointsPhaseThermo.
- // Parameters:
- // @xCtl - control context prepared by previous NFMGetPointsThermo_Begin call
- // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
- //
- // Returns:
- // - eNFMGetPointError_DataError: error, can not load data;
- // - eNFMGetPointError_InvalidValue: error, invalid parameters;
- // - eNFMGetPointError_Success: success, all the points from the table have been read;
- // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
- // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
- static int32_t NFMGetPointsThermo_Continue( sNFMGetPointsSimplified_t * pCtl, size_t * pnPointsRetrieve )
- {
- my_assert( pCtl ); // see @NFMGetPointsThermoMagn_Continue, @NFMGetPointsThermoPhase_Continue
- my_assert( pnPointsRetrieve ); // see @NFMGetPointsThermoMagn_Continue, @NFMGetPointsThermoPhase_Continue
-
- // Check if arguments are valid in general
- if( ( pCtl->sectorId != eChFactory ) // Formal checking: actually it is does not matter what value is specified here
- || ( pCtl->portComb >= ePortComb_MAX )
- || ( pCtl->portState >= ePortStateId_MAX )
- || ( pCtl->portComb == ePortComb_UNDEFINED )
- || ( 0 == pCtl->BufferCapacity )
- || ( 0 == pCtl->intCtx.out.nPoints )
- || ( 0 == pCtl->intCtx.out.TableAddress )
- || ( NULL == pCtl->intCtx.in.pDataArray ) )
- {
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
- return eNFMGetPointError_InvalidValue;
- }
- // check ranges
- if( pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints;
- if( pCtl->intCtx.in.nStartPoint >= pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nStartPoint = pCtl->intCtx.out.nPoints; // end-of-points
- if( pCtl->intCtx.in.nStartPoint +
- pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
- {
- pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
- }
- // check for end condition
- if( 0 == pCtl->intCtx.in.nCount
- || pCtl->intCtx.in.nStartPoint == pCtl->intCtx.out.nPoints )
- {
- *pnPointsRetrieve = 0; // number of points read is zero
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
- return eNFMGetPointError_Success;
- }
- int32_t success_rc = eNFMGetPointError_Success;
-
- // check buffer capacity range
- if( pCtl->intCtx.in.nCount > pCtl->BufferCapacity )
- {
- pCtl->intCtx.in.nCount = pCtl->BufferCapacity;
- success_rc = eNFMGetPointError_OutOfBuffer; // out of buffer, the number of points is limited
- }
- else
- if( pCtl->intCtx.in.nStartPoint + pCtl->intCtx.in.nCount < pCtl->intCtx.out.nPoints )
- {
- success_rc = eNFMGetPointError_Limit; // number of points is limited by user
- }
- pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_IO;
- size_t nRead = 0;
-
- if( 0 == pCtl->isThermoPhase )
- nRead = NFMClassExtended->private.methods.memory.getTCompMagnPoints( &pCtl->intCtx );
- else
- nRead = NFMClassExtended->private.methods.memory.getTCompPhasePoints( &pCtl->intCtx );
- // check for error condition
- if( nRead == 0 )
- {
- *pnPointsRetrieve = 0; // number of points read is zero
- (void)pCtl->intCtx.svc.errCode;
- return eNFMGetPointError_DataError;
- }
- pCtl->intCtx.in.nStartPoint += nRead; // increment start point for next call
- // check range
- if( pCtl->intCtx.in.nStartPoint +
- pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
- {
- pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
- }
- *pnPointsRetrieve = nRead; // number of points read
-
- return success_rc;
- }
- static bool NFMGetInterface( eNFMUSBInterface_t * pCurrentIface )
- {
- if( NULL != pCurrentIface )
- {
- if( sizeof(sNFMSettingsBlockCrc_t) == NFMClassExtended->private.methods.memory.getSettingsBlockSize() )
- {
- sNFMSettingsBlockCrc_t sSettingsBlock;
- if( NFMClassExtended->private.methods.memory.getSettingsBlock( (uint8_t*)&sSettingsBlock,
- 0,
- sizeof(sSettingsBlock) ) )
- {
- *pCurrentIface = eNFM_IfaceUSBVendor;
- if( sSettingsBlock.settings.rawBytes[0] == 'U' )
- if( sSettingsBlock.settings.rawBytes[1] == 'S' )
- if( sSettingsBlock.settings.rawBytes[2] == 'B' )
- if( sSettingsBlock.settings.rawBytes[3] == 'T' )
- if( sSettingsBlock.settings.rawBytes[4] == 'M' )
- if( sSettingsBlock.settings.rawBytes[5] == 'C' )
- if( sSettingsBlock.settings.rawBytes[6] == '!' )
- if( sSettingsBlock.settings.rawBytes[7] == 0 )
- *pCurrentIface = eNFM_IfaceUSBTMC;
- return true;
- }
- }
- }
- return false;
- }
- static bool NFMSetInterface( eNFMUSBInterface_t activateInterface )
- {
- if( (activateInterface == eNFM_IfaceUSBVendor)
- ||(activateInterface == eNFM_IfaceUSBTMC) )
- {
- if( sizeof(sNFMSettingsBlockCrc_t) == NFMClassExtended->private.methods.memory.getSettingsBlockSize() )
- {
- sNFMSettingsBlockCrc_t sSettingsBlock;
- if( NFMClassExtended->private.methods.memory.getSettingsBlock( (uint8_t*)&sSettingsBlock,
- 0,
- sizeof(sSettingsBlock) ) )
- {
- if( eNFM_IfaceUSBTMC == activateInterface )
- {
- sSettingsBlock.settings.rawBytes[0] = 'U';
- sSettingsBlock.settings.rawBytes[1] = 'S';
- sSettingsBlock.settings.rawBytes[2] = 'B';
- sSettingsBlock.settings.rawBytes[3] = 'T';
- sSettingsBlock.settings.rawBytes[4] = 'M';
- sSettingsBlock.settings.rawBytes[5] = 'C';
- sSettingsBlock.settings.rawBytes[6] = '!';
- sSettingsBlock.settings.rawBytes[7] = 0 ;
- }
- else
- {
- sSettingsBlock.settings.rawBytes[0] = 'V';
- sSettingsBlock.settings.rawBytes[1] = 'E';
- sSettingsBlock.settings.rawBytes[2] = 'N';
- sSettingsBlock.settings.rawBytes[3] = 'D';
- sSettingsBlock.settings.rawBytes[4] = 'O';
- sSettingsBlock.settings.rawBytes[5] = 'R';
- sSettingsBlock.settings.rawBytes[6] = '!';
- sSettingsBlock.settings.rawBytes[7] = 0 ;
- }
-
- TCRC crc = ICRC32;
- crc = CRC32( crc, (uint8_t *)&sSettingsBlock.settings, sizeof(sSettingsBlock.settings));
- sSettingsBlock.CRCValue = crc;
-
- return NFMClassExtended->private.methods.memory.setSettingsBlock( (uint8_t*)&sSettingsBlock,
- 0,
- sizeof(sSettingsBlock) );
- }
- }
- }
- return false;
- }
- static uint16_t* GetPort(uint16_t portNumber)
- {
- switch(portNumber)
- {
- case eNFMPort_1:
- return &NFMClassExtended->public.properties.inputPortStates[ePort_1];
- case eNFMPort_2:
- return &NFMClassExtended->public.properties.inputPortStates[ePort_2];
- default:
- return 0;
- }
- }
- static uint16_t NFMGetPortState (uint16_t portNumber)
- {
- return *GetPort(portNumber);
- }
- static bool NFMSetPortState (uint16_t portNumber, uint16_t portState)
- {
- uint16_t* port = GetPort(portNumber);
- if(port == NULL)
- return false;
-
- *port = portState;
- return true;
- }
- #endif
|