nfm_base.c 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310
  1. #include "core/config.h"
  2. #if CONFIG_NFMBASECLASS
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "core/main.h" // _snprintf
  6. #include "core/config_pins.h"
  7. #include "crc32.h"
  8. #include "drivers/keycontrol/keycontrol_ll.h"
  9. #include "drivers/power_management/power_management.h"
  10. #include "app/nfm/nfm_base_excls.h"
  11. #include "app/thermo/tsensor.h"
  12. #include "app/led/led.h"
  13. #include "app/thermo/NTCtsensor.h"
  14. #include "app/version/version.h"
  15. #include <stdlib.h> // atoi[NFMCLASS_ENABLE__SERIAL_NUMBER_LEGACY]
  16. #include <ctype.h> // tolower
  17. #define NFMCLASS_ENABLE__SERIAL_NUMBER_LEGACY 0
  18. #include "my_assert.h"
  19. #include "app/control_table/control_table.h"
  20. STATIC_ASSERT( sizeof(xNFMGetFreqPoints_t) == sizeof(sNFMGetFreqPoints_t), "Invalid xNFMGetPoints_t/sNFMGetPoints_t size" );
  21. STATIC_ASSERT( sizeof(xNFMGetPointsSimplified_t) == sizeof(sNFMGetPointsSimplified_t), "Invalid xNFMGetPointsSimplified_t/sNFMGetPointsSimplified_t size" );
  22. #if defined(PLANAR)
  23. // Device Manufacturer ID
  24. const static char manufacturerId[] = "Planar";
  25. //#elif defined(CMT)
  26. //const static char manufacturerId[] = "Copper Mountain Technologies";
  27. #elif defined(CMT)
  28. const static char manufacturerId[] = "CMT";
  29. #else
  30. #error Please, specify VENDOR macro
  31. #endif
  32. // Firmware ID
  33. static char g_firmwareId[16] = "0.1/01";
  34. // NFM model name
  35. static char g_modelName[16] = "R0467";
  36. // Serial Number String
  37. static char g_serialNumber[9] = "25230066";
  38. // NFM Connectors descriptions
  39. const static char * const aConnectorsNames[] =
  40. {
  41. "Type-N50 -M-",
  42. "Type-N50 -F-",
  43. "3.5mm -M-",
  44. "3.5mm -F-",
  45. "2.4mm -M-",
  46. "2.4mm -F-",
  47. "Type-N75 -M-",
  48. "Type-N75 -F-",
  49. "Type-F -M-",
  50. "Type-F -F-",
  51. "7/16 -M-",
  52. "7/16 -F-",
  53. "APC-7",
  54. };
  55. const static char pcConnectorUndefined[] = "Unknown";
  56. //------------------------------------------------------------------------------
  57. static void private_ClassInit();
  58. static size_t static_StrCpyLimit( const char * source, size_t srcMaxLen,
  59. char * dest, size_t destMaxLen );
  60. static const sNFMModel_t *
  61. static_GetModelProfileByDeviceId( uint16_t deviceId );
  62. static bool private_getModelId( uint16_t * pDeviceId );
  63. static bool private_CheckTableParams( ePortComb_t portComb, ePortStateId_t portState );
  64. static size_t NFMGetDeviceManufacturer( char * buffer, size_t size );
  65. static size_t NFMGetDeviceSerial( char * buffer, size_t size );
  66. static size_t NFMGetModelName( char * buffer, size_t size );
  67. static bool NFMCheckPortStateAvailable( ePortStateId_t portState );
  68. static bool NFMCheckPortCombinationAvailable( ePortComb_t portComb );
  69. // static bool NFMCheckPortParamsAvailable( ePortComb_t portComb, ePortStateId_t portState );
  70. // static size_t NFMGetPoints( eChrz_t tableId, ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl );
  71. // static size_t NFMGetPointsMagnThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl );
  72. // static size_t NFMGetPointsPhaseThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl );
  73. static size_t NFMGetPointsCount( eChrz_t tableId );
  74. static bool NFMGetPointsCount_Safe( eChrz_t tableId, int16_t * count );
  75. static bool NFMGetDate( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
  76. static bool NFMGetTime( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
  77. static bool NFMGetScaleType( eChrz_t tableId, eChrzScaleType_t * pType );
  78. static size_t NFMGetScaleSegment( eChrz_t tableId, sEcalSegment_t * pSegment, size_t nSegmentId );
  79. //------------------------------------------------------------------------------
  80. static int32_t NFMGetScaleFreqs_Begin( eChrz_t tableId, double * pFreqArray, size_t BufferCapacity, xNFMGetFreqPoints_t * xCtl );
  81. static int32_t NFMGetScaleFreqs_Continue( xNFMGetFreqPoints_t * xCtl, size_t * pnPointsRetrieve );
  82. //------------------------------------------------------------------------------
  83. static int32_t SWGetTablePoints_Begin( eChrz_t tableId, sSWTablePoint_t * pPointsArray, size_t BufferCapacity, xSWGetTablePoints_t * xCtl );
  84. static int32_t SWGetTablePoints_Continue( xSWGetTablePoints_t * xCtl, size_t * pnPointsRetrieve );
  85. //------------------------------------------------------------------------------
  86. static size_t NFMGetPoints_Begin( eChrz_t sectorId, ePortComb_t portComb, ePortStateId_t portState,
  87. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  88. xNFMGetPointsSimplified_t * xCtl );
  89. static int32_t NFMGetPoints_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve );
  90. //------------------------------------------------------------------------------
  91. static size_t NFMGetPointsThermo_Begin( ePortComb_t portComb, ePortStateId_t portState,
  92. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  93. sNFMGetPointsSimplified_t * pCtl );
  94. static size_t NFMGetPointsThermoMagn_Begin( ePortComb_t portComb, ePortStateId_t portState,
  95. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  96. xNFMGetPointsSimplified_t * xCtl );
  97. static size_t NFMGetPointsThermoPhase_Begin( ePortComb_t portComb, ePortStateId_t portState,
  98. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  99. xNFMGetPointsSimplified_t * xCtl );
  100. //------------------------------------------------------------------------------
  101. static int32_t NFMGetPointsThermo_Continue( sNFMGetPointsSimplified_t * pCtl, size_t * pnPointsRetrieve );
  102. static int32_t NFMGetPointsThermoMagn_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve );
  103. static int32_t NFMGetPointsThermoPhase_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve );
  104. //------------------------------------------------------------------------------
  105. static bool NFMGetStartFreq( eChrz_t tableId, double * pStartFreq );
  106. static bool NFMGetStopFreq( eChrz_t tableId, double * pStopFreq );
  107. static bool NFMGetChrzTemp( eChrz_t tableId, double * pTemperature );
  108. static bool NFMGetConnectorType( ePortId_t portId, char * buffer, size_t size, size_t * bytes );
  109. static bool NFMGetAdapterDesc( eChrz_t tableId, ePortId_t portId, char * buffer, size_t size, size_t * bytes );
  110. static bool NFMGetAnalyzer( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
  111. static bool NFMGetPlace( eChrz_t tableId, char * buffer, size_t size, size_t * bytes );
  112. static bool NFMGetOperator( eChrz_t tableId, char * buffer, size_t size, size_t * bytes ); //------------------------------------------------------------------------------
  113. //------------------------------------------------------------------------------
  114. static bool NFMGetInterface( eNFMUSBInterface_t * pCurrentIface );
  115. static bool NFMSetInterface( eNFMUSBInterface_t activateInterface );
  116. //------------------------------------------------------------------------------
  117. static uint16_t NFMGetPortState (uint16_t portNumber);
  118. static bool NFMSetPortState (uint16_t portNumber, uint16_t portState);
  119. //------------------------------------------------------------------------------
  120. static bool NFMSetMemoryProtect();
  121. static bool NFMSetMemoryUnProtect();
  122. static bool NFMGetMemoryProtect();
  123. //------------------------------------------------------------------------------
  124. static bool NFMGetStartFreqThermo( double * pStartFreq );
  125. static bool NFMGetStopFreqThermo( double * pStopFreq );
  126. static size_t NFMGetPointsThermo();
  127. static bool NFMGetPointsThermo_Safe( int16_t * count );
  128. //------------------------------------------------------------------------------
  129. static NFMClassEx_t __NFMClass =
  130. {
  131. .public =
  132. {
  133. .properties =
  134. {
  135. .manufacturerId = manufacturerId,
  136. .firmwareId = g_firmwareId,
  137. .modelName = g_modelName,
  138. .serialNumber = g_serialNumber,
  139. .allowedInputPorts = 2,
  140. .allowedOutputPorts = 12,
  141. .defaultInputState = eTerminatePortState,
  142. //.inputPortStates = {0, 0},
  143. .deviceId = eModel_undefined,
  144. .isServiceMode = false
  145. },
  146. .methods =
  147. {
  148. .usbInterface =
  149. {
  150. .getInterface = NFMGetInterface,
  151. .setInterface = NFMSetInterface
  152. },
  153. .portMethods =
  154. {
  155. .getPortState = NFMGetPortState,
  156. .setPortState = NFMSetPortState,
  157. },
  158. .getDeviceManufacturer = NFMGetDeviceManufacturer,
  159. .getDeviceSerial = NFMGetDeviceSerial,
  160. .getModelName = NFMGetModelName,
  161. .checkPortStateAvailable = NFMCheckPortStateAvailable,
  162. .checkPortCombinationAvailable = NFMCheckPortCombinationAvailable,
  163. .checkTableParams = private_CheckTableParams,
  164. .xCharacterization =
  165. {
  166. //.getPoints = NFMGetPoints,
  167. .getPoints_Init = NFMGetPoints_Begin,
  168. .getPoints_Next = NFMGetPoints_Continue,
  169. .getPointsCount = NFMGetPointsCount,
  170. .getPointsCountSafe = NFMGetPointsCount_Safe,
  171. .getDate = NFMGetDate,
  172. .getTime = NFMGetTime,
  173. .getScaleType = NFMGetScaleType,
  174. .getScaleSegment = NFMGetScaleSegment,
  175. .getScaleFreqs_Init = NFMGetScaleFreqs_Begin,
  176. .getScaleFreqs_Next = NFMGetScaleFreqs_Continue,
  177. .getStartFreq = NFMGetStartFreq,
  178. .getStopFreq = NFMGetStopFreq,
  179. .getChrzTemp = NFMGetChrzTemp,
  180. .getConnectorType = NFMGetConnectorType,
  181. .getAdapterDesc = NFMGetAdapterDesc,
  182. .getAnalyzer = NFMGetAnalyzer,
  183. .getPlace = NFMGetPlace,
  184. .getOperator = NFMGetOperator,
  185. },
  186. .xTable =
  187. {
  188. .getTablePoints_Init = SWGetTablePoints_Begin,
  189. .getTablePoints_Next = SWGetTablePoints_Continue,
  190. },
  191. .xThermo =
  192. {
  193. .getStartFreq = NFMGetStartFreqThermo,
  194. .getStopFreq = NFMGetStopFreqThermo,
  195. .getPointsCount = NFMGetPointsThermo,
  196. .getPointsCountSafe = NFMGetPointsThermo_Safe,
  197. //.getPointsMagn = NFMGetPointsMagnThermo,
  198. //.getPointsPhase = NFMGetPointsPhaseThermo,
  199. .getPointsThermoMagn_Init = NFMGetPointsThermoMagn_Begin,
  200. .getPointsThermoMagn_Next = NFMGetPointsThermoMagn_Continue,
  201. .getPointsThermoPhase_Init = NFMGetPointsThermoPhase_Begin,
  202. .getPointsThermoPhase_Next = NFMGetPointsThermoPhase_Continue,
  203. },
  204. .xMemoryProtection =
  205. {
  206. .enable = NFMSetMemoryProtect,
  207. .disable = NFMSetMemoryUnProtect,
  208. .check = NFMGetMemoryProtect,
  209. },
  210. },
  211. },
  212. .private =
  213. {
  214. .methods =
  215. {
  216. .classInit = private_ClassInit,
  217. .getModelId = private_getModelId,
  218. .memory =
  219. {
  220. .setProtect = NFM_ROM_SetMemoryProtectStatus_Bank0,
  221. .getProtect = NFM_ROM_GetMemoryProtectStatus_Bank0,
  222. .getCommonHeader = NFM_ROM_GetCommonHeader,
  223. .getDataHeader = NFM_ROM_GetDataHeader,
  224. .getTCompHeader = NFM_ROM_GetTCompHeader,
  225. .getChrzTableIndex = NFM_ROM_GetChrzTableIndex,
  226. .getTCompTableIndex = NFM_ROM_GetTCompTableIndex,
  227. .getChrzTableHeader = NFM_ROM_ReadChrzTableHeader,
  228. .getChrzPoints = NFM_ROM_ReadChrzTablePoints,
  229. .getTCompMagnTableHeader = NFM_ROM_GetTCompMagnTableHeader,
  230. .getTCompPhaseTableHeader = NFM_ROM_GetTCompPhaseTableHeader,
  231. .getTCompMagnPoints = NFM_ROM_GetTCompMagnPoints,
  232. .getTCompPhasePoints = NFM_ROM_GetTCompPhasePoints,
  233. .getSettingsBlock = NFM_ROM_ReadDeviceSettings,
  234. .setSettingsBlock = NFM_ROM_WriteDeviceSettings,
  235. .getSettingsBlockSize = NFM_ROM_GetDeviceSettingsSize,
  236. .validateSettings = NFM_ROM_ValidateUserSettings,
  237. }
  238. },
  239. .properties =
  240. {
  241. .deviceId = eModel_undefined,
  242. .modelProfile = NULL,
  243. }
  244. }
  245. };
  246. __root NFMClass_t * NFMClass = (NFMClass_t*)&__NFMClass;
  247. __root NFMClassEx_t * NFMClassExtended = &__NFMClass;
  248. //------------------------------------------------------------------------------------------------------------
  249. //-- Global methods ------------------------------------------------------------------------------------------
  250. //------------------------------------------------------------------------------------------------------------
  251. void nfmbase_init()
  252. {
  253. // initialize NFM object
  254. NFMClassExtended->private.methods.classInit();
  255. // set key-switch state by default
  256. //NFMClass->methods.keyStatesMethods.setKeyStateDefault();
  257. // sTableTablePoint_t TablePoint;
  258. // TablePoint.port1 = 12;
  259. // TablePoint.port2 = 2;
  260. // SW_ROM_SetDataPoint(0, &TablePoint);
  261. // TablePoint.port1 = 4;
  262. // TablePoint.port2 = 6;
  263. // SW_ROM_SetDataPoint(0, &TablePoint);
  264. // TablePoint.port1 = 1;
  265. // TablePoint.port2 = 3;
  266. // SW_ROM_SetDataPoint(0, &TablePoint);
  267. // uint8_t buffer[100];
  268. // memset(&buffer, 0x00, sizeof(buffer));
  269. // SW_ROM_GetDataPoint(0, 5, &buffer, sizeof(sTableTablePoint_t));
  270. // SW_ROM_GetDataPoint(0, 6, &buffer, sizeof(sTableTablePoint_t));
  271. // SW_ROM_GetDataPoint(0, 7, &buffer, sizeof(sTableTablePoint_t));
  272. // SW_ROM_GetDataPoint(0, 8, &buffer, sizeof(sTableTablePoint_t));
  273. // uint32_t crc = SW_ROM_Get_Table_crc( eChValues );
  274. // SW_ROM_Set_Table_crc ( crc );
  275. // SW_ROM_Check_Table_crc();
  276. // SW_ROM_Table_Clear();
  277. #if CONFIG_NFMCLASS_AUTOPROTECT_MEMORY
  278. // protect factory data: set memory protection
  279. NFMClass->methods.xMemoryProtection.enable();
  280. #endif
  281. }
  282. #define NFMCLASS_TEST CONFIG_NFMBASECLASS_TEST
  283. #define NFMCLASS_TEST_TEMPERATURE 0
  284. #define NFMCLASS_TEST_TEMPERATURESTR 0
  285. #define NFMCLASS_TEST_MANUFACTURERSTR 0
  286. #define NFMCLASS_TEST_SERIALSTR 0
  287. #define NFMCLASS_TEST_SERIALLEGACY 0
  288. #define NFMCLASS_TEST_STATENAMES 0
  289. #define NFMCLASS_TEST_STATELIST 0
  290. #define NFMCLASS_TEST_KEYSWSTATENAME 0
  291. #define NFMCLASS_TEST_MODELNAME 0
  292. #define NFMCLASS_TEST_CURRENTSTATE 0
  293. #define NFMCLASS_TEST_LEGACYSTATE 0
  294. #define NFMCLASS_TEST_RAWKEYCODE 0
  295. #define NFMCLASS_TEST_KEYSTATESHORTCUTS 0
  296. #define NFMCLASS_TEST_CHRZ_ADAPTERSTR 0
  297. #define NFMCLASS_TEST_CHRZ_ANALYZERSTR 0
  298. #define NFMCLASS_TEST_CHRZ_TEMP 0
  299. #define NFMCLASS_TEST_CHRZ_CONNECTORSTR 0
  300. #define NFMCLASS_TEST_CHRZ_DATESTR 0
  301. #define NFMCLASS_TEST_CHRZ_TIMESTR 0
  302. #define NFMCLASS_TEST_CHRZ_OPERATORSTR 0
  303. #define NFMCLASS_TEST_CHRZ_PLACESTR 0
  304. #define NFMCLASS_TEST_CHRZ_POINTSCOUNT 0
  305. #define NFMCLASS_TEST_CHRZ_SEGMENTS 0
  306. #define NFMCLASS_TEST_CHRZ_STARTFREQ 0
  307. #define NFMCLASS_TEST_CHRZ_STOPFREQ 0
  308. #define NFMCLASS_TEST_THERMO_POINTSCOUNT 0
  309. #define NFMCLASS_TEST_THERMO_STOPFREQ 0
  310. #define NFMCLASS_TEST_THERMO_STARTFREQ 0
  311. #define NFMCLASS_TEST_MEM_PROTECTION 0
  312. void nfmbase_test()
  313. {
  314. #if NFMCLASS_TEST
  315. asm( "bkpt #0" );
  316. #if 1 && NFMCLASS_TEST_TEMPERATURE
  317. {
  318. float avgTemp = NFMClass->methods.getAverageTemperature();
  319. asm( "bkpt #0" );
  320. (void)avgTemp;
  321. }
  322. #endif
  323. #if 0 && NFMCLASS_TEST_TEMPERATURESTR
  324. {
  325. char avgTempStrBuffer[ 20 ] = {0};
  326. NFMClass->methods.getAverageTemperatureString( avgTempStrBuffer, sizeof(avgTempStrBuffer) )
  327. asm( "bkpt #0" );
  328. (void)avgTempStrBuffer;
  329. }
  330. #endif
  331. #if 1 && NFMCLASS_TEST_MANUFACTURERSTR
  332. {
  333. char manufacturerStrBuffer[ 20 ] = {0};
  334. NFMClass->methods.getDeviceManufacturer( manufacturerStrBuffer, sizeof(manufacturerStrBuffer) );
  335. asm( "bkpt #0" );
  336. (void)manufacturerStrBuffer;
  337. }
  338. #endif
  339. #if 1 && NFMCLASS_TEST_SERIALSTR
  340. {
  341. char serialStrBuffer[ 20 ] = {0};
  342. NFMClass->methods.getDeviceSerial( serialStrBuffer, sizeof(serialStrBuffer) );
  343. asm( "bkpt #0" );
  344. (void)serialStrBuffer;
  345. }
  346. #endif
  347. #if 1 && NFMCLASS_TEST_SERIALLEGACY
  348. {
  349. uint32_t serialNumber = NFMClass->methods.getDeviceSerialLegacy();
  350. asm( "bkpt #0" );
  351. (void)serialNumber;
  352. }
  353. #endif
  354. #if 1 && NFMCLASS_TEST_STATENAMES
  355. {
  356. char stateNameStrBuffer[ 20 ] = {0};
  357. eNFMKeyState_t state = NFMClass->methods.getKeyStateByName( "SALL", 4 );
  358. asm( "bkpt #0" );
  359. NFMClass->methods.getKeyStateName( state, stateNameStrBuffer, sizeof(stateNameStrBuffer) );
  360. asm( "bkpt #0" );
  361. (void)state, (void)stateNameStrBuffer;
  362. }
  363. {
  364. char stateNameStrBuffer[ 20 ] = {0};
  365. eNFMKeyState_t state = NFMClass->methods.getKeyStateByName( "OALL", 4 );
  366. asm( "bkpt #0" );
  367. NFMClass->methods.getKeyStateName( state, stateNameStrBuffer, sizeof(stateNameStrBuffer) );
  368. asm( "bkpt #0" );
  369. (void)state, (void)stateNameStrBuffer;
  370. }
  371. {
  372. char stateNameStrBuffer[ 20 ] = {0};
  373. eNFMKeyState_t state = NFMClass->methods.getKeyStateByName( "LALL", 4 );
  374. asm( "bkpt #0" );
  375. NFMClass->methods.getKeyStateName( state, stateNameStrBuffer, sizeof(stateNameStrBuffer) );
  376. asm( "bkpt #0" );
  377. (void)state, (void)stateNameStrBuffer;
  378. }
  379. #endif
  380. #if 1 && NFMCLASS_TEST_STATELIST
  381. {
  382. char statesListStrBuffer[ 64 ] = {0};
  383. NFMClass->methods.getKeyStateList( statesListStrBuffer, sizeof(statesListStrBuffer) );
  384. asm( "bkpt #0" );
  385. (void)statesListStrBuffer;
  386. }
  387. #endif
  388. #if 1 && NFMCLASS_TEST_KEYSWSTATENAME
  389. {
  390. char keySwitchNameStrBuffer[ 20 ] = {0};
  391. NFMClass->methods.getKeySwitchName( keySwitchNameStrBuffer, sizeof(keySwitchNameStrBuffer) );
  392. asm( "bkpt #0" );
  393. (void)keySwitchNameStrBuffer;
  394. }
  395. #endif
  396. #if 1 && NFMCLASS_TEST_MODELNAME
  397. {
  398. char modelNameStrBuffer[ 20 ] = {0};
  399. NFMClass->methods.getModelName( modelNameStrBuffer, sizeof(modelNameStrBuffer) );
  400. asm( "bkpt #0" );
  401. (void)modelNameStrBuffer;
  402. }
  403. #endif
  404. #if 1 && NFMCLASS_TEST_CURRENTSTATE
  405. {
  406. eNFMKeyState_t currentState = NFMClass->methods.keyStatesMethods.getKeyStateCommon();
  407. asm( "bkpt #0" );
  408. (void)currentState;
  409. }
  410. #endif
  411. #if 1 && NFMCLASS_TEST_LEGACYSTATE
  412. {
  413. uint32_t legacyState = 0;
  414. eNFMKeyState_t testState = eKeyState_CHECK;
  415. if( NFMClass->methods.keyStatesMethods.getKeyStateLegacy( &legacyState ) )
  416. {
  417. asm( "bkpt #0" ); // OK
  418. NFMClass->methods.keyStatesMethods.setKeyStateCommon( testState );
  419. if( testState == NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
  420. asm( "bkpt #0" ); // OK
  421. else
  422. asm( "bkpt #0" ); // ERROR
  423. if( NFMClass->methods.keyStatesMethods.setKeyStateLegacy( legacyState ) )
  424. asm( "bkpt #0" ); // OK
  425. else
  426. asm( "bkpt #0" ); // ERROR
  427. uint32_t legacyState_2 = 0;
  428. if( NFMClass->methods.keyStatesMethods.getKeyStateLegacy( &legacyState_2 ) )
  429. asm( "bkpt #0" ); // OK
  430. else
  431. asm( "bkpt #0" ); // ERROR
  432. if( legacyState_2 == legacyState )
  433. asm( "bkpt #0" ); // OK
  434. else
  435. asm( "bkpt #0" ); // ERROR
  436. }
  437. else
  438. asm( "bkpt #0" ); // ERROR
  439. }
  440. #endif
  441. #if 1 && NFMCLASS_TEST_RAWKEYCODE
  442. {
  443. uint32_t rawCode = NFMClass->methods.keyStatesMethods.getRawKeyControlCode();
  444. asm( "bkpt #0" );
  445. (void)rawCode;
  446. }
  447. #endif
  448. #if 1 && NFMCLASS_TEST_KEYSTATESHORTCUTS
  449. {
  450. eNFMKeyState_t prevState = NFMClass->methods.keyStatesMethods.getKeyStateCommon();
  451. int32_t eKeyState_SALL_shortcut=-1, eKeyState_OALL_shortcut=-1, eKeyState_LALL_shortcut=-1;
  452. if( !NFMClass->methods.keyStatesMethods.shortcuts.findShortCutForState( eKeyState_SALL, &eKeyState_SALL_shortcut ) )
  453. asm( "bkpt #0" ); // ERROR
  454. if( !NFMClass->methods.keyStatesMethods.shortcuts.findShortCutForState( eKeyState_OALL, &eKeyState_OALL_shortcut ) )
  455. asm( "bkpt #0" ); // ERROR
  456. if( !NFMClass->methods.keyStatesMethods.shortcuts.findShortCutForState( eKeyState_LALL, &eKeyState_LALL_shortcut ) )
  457. asm( "bkpt #0" ); // ERROR
  458. if( !NFMClass->methods.keyStatesMethods.shortcuts.setKeyStateByShortcut( eKeyState_SALL_shortcut ) )
  459. asm( "bkpt #0" ); // ERROR
  460. else
  461. if( eKeyState_SALL != NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
  462. asm( "bkpt #0" ); // ERROR
  463. if( !NFMClass->methods.keyStatesMethods.shortcuts.setKeyStateByShortcut( eKeyState_OALL_shortcut ) )
  464. asm( "bkpt #0" ); // ERROR
  465. else
  466. if( eKeyState_OALL != NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
  467. asm( "bkpt #0" ); // ERROR
  468. if( !NFMClass->methods.keyStatesMethods.shortcuts.setKeyStateByShortcut( eKeyState_LALL_shortcut ) )
  469. asm( "bkpt #0" ); // ERROR
  470. else
  471. if( eKeyState_LALL != NFMClass->methods.keyStatesMethods.getKeyStateCommon() )
  472. asm( "bkpt #0" ); // ERROR
  473. if( !NFMClass->methods.keyStatesMethods.setKeyStateCommon( prevState ) )
  474. asm( "bkpt #0" ); // ERROR
  475. }
  476. #endif
  477. asm( "bkpt #0" );
  478. #if 1 && NFMCLASS_TEST_CHRZ_ADAPTERSTR
  479. {
  480. size_t n;
  481. char adapterStrBuffer[ 20 ] = {0};
  482. NFMClass->methods.xCharacterization.getAdapterDesc( eChFactory, ePortId_A, adapterStrBuffer, sizeof(adapterStrBuffer), &n );
  483. asm( "bkpt #0" );
  484. (void)adapterStrBuffer;
  485. }
  486. {
  487. size_t n;
  488. char adapterStrBuffer[ 20 ] = {0};
  489. NFMClass->methods.xCharacterization.getAdapterDesc( eChFactory, ePortId_B, adapterStrBuffer, sizeof(adapterStrBuffer), &n );
  490. asm( "bkpt #0" );
  491. (void)adapterStrBuffer;
  492. }
  493. #endif
  494. #if 1 && NFMCLASS_TEST_CHRZ_ANALYZERSTR
  495. {
  496. size_t n;
  497. char analyzerStrBuffer[ 20 ] = {0};
  498. NFMClass->methods.xCharacterization.getAnalyzer( eChFactory, analyzerStrBuffer, sizeof(analyzerStrBuffer), &n );
  499. asm( "bkpt #0" );
  500. (void)analyzerStrBuffer;
  501. }
  502. #endif
  503. #if 1 && NFMCLASS_TEST_CHRZ_TEMP
  504. {
  505. double chrzTemp = 0.0;
  506. NFMClass->methods.xCharacterization.getChrzTemp( eChFactory, &chrzTemp );
  507. asm( "bkpt #0" );
  508. }
  509. #endif
  510. #if 1 && NFMCLASS_TEST_CHRZ_CONNECTORSTR
  511. {
  512. size_t n;
  513. char connectorStrBuffer[ 20 ] = {0};
  514. NFMClass->methods.xCharacterization.getConnectorType( ePortId_A, connectorStrBuffer, sizeof(connectorStrBuffer), &n );
  515. asm( "bkpt #0" );
  516. (void)connectorStrBuffer;
  517. }
  518. {
  519. size_t n;
  520. char connectorStrBuffer[ 20 ] = {0};
  521. NFMClass->methods.xCharacterization.getConnectorType( ePortId_B, connectorStrBuffer, sizeof(connectorStrBuffer), &n );
  522. asm( "bkpt #0" );
  523. (void)connectorStrBuffer;
  524. }
  525. #endif
  526. #if 1 && NFMCLASS_TEST_CHRZ_DATESTR
  527. {
  528. size_t n;
  529. char dateStrBuffer[ 20 ] = {0};
  530. NFMClass->methods.xCharacterization.getDate( eChFactory, dateStrBuffer, sizeof(dateStrBuffer), &n );
  531. asm( "bkpt #0" );
  532. (void)dateStrBuffer;
  533. }
  534. #endif
  535. #if 1 && SWCLASS_TEST_TABLE_HEADER
  536. {
  537. //SW_ROM_ChangeTableHeader(5);
  538. }
  539. #endif
  540. #if 1 && NFMCLASS_TEST_CHRZ_TIMESTR
  541. {
  542. size_t n;
  543. char timeStrBuffer[ 20 ] = {0};
  544. NFMClass->methods.xCharacterization.getTime( eChFactory, timeStrBuffer, sizeof(timeStrBuffer), &n );
  545. asm( "bkpt #0" );
  546. (void)timeStrBuffer;
  547. }
  548. #endif
  549. #if 1 && NFMCLASS_TEST_CHRZ_OPERATORSTR
  550. {
  551. size_t n;
  552. char operatorStrBuffer[ 20 ] = {0};
  553. NFMClass->methods.xCharacterization.getOperator( eChFactory, operatorStrBuffer, sizeof(operatorStrBuffer), &n );
  554. asm( "bkpt #0" );
  555. (void)operatorStrBuffer;
  556. }
  557. #endif
  558. #if 1 && NFMCLASS_TEST_CHRZ_PLACESTR
  559. {
  560. size_t n;
  561. char placeStrBuffer[ 20 ] = {0};
  562. NFMClass->methods.xCharacterization.getPlace( eChFactory, placeStrBuffer, sizeof(placeStrBuffer), &n );
  563. asm( "bkpt #0" );
  564. (void)placeStrBuffer;
  565. }
  566. #endif
  567. #if 1 && NFMCLASS_TEST_CHRZ_POINTSCOUNT
  568. {
  569. size_t nPoints = NFMClass->methods.xCharacterization.getPointsCount( eChFactory );
  570. asm( "bkpt #0" );
  571. (void)nPoints;
  572. }
  573. #endif
  574. #if 1 && NFMCLASS_TEST_CHRZ_SEGMENTS
  575. {
  576. size_t nSegments = NFMClass->methods.xCharacterization.getScaleSegment( eChFactory, NULL, 0 );
  577. asm( "bkpt #0" );
  578. (void)nSegments;
  579. asm( "bkpt #0" );
  580. for( size_t i = 0; i < nSegments; ++i )
  581. {
  582. sEcalSegment_t segm;
  583. if( 0 == NFMClass->methods.xCharacterization.getScaleSegment( eChFactory, &segm, i ) )
  584. asm( "bkpt #0" ); // ERROR
  585. else
  586. asm( "bkpt #0" ); // OK
  587. (void)segm;
  588. }
  589. asm( "bkpt #0" );
  590. }
  591. #endif
  592. #if 1 && NFMCLASS_TEST_CHRZ_STARTFREQ
  593. {
  594. double startFreq = 0.0;
  595. if( NFMClass->methods.xCharacterization.getStartFreq( eChFactory, &startFreq ) )
  596. asm( "bkpt #0" ); // OK
  597. else
  598. asm( "bkpt #0" ); // ERROR
  599. (void)startFreq;
  600. }
  601. #endif
  602. #if 1 && NFMCLASS_TEST_CHRZ_STOPFREQ
  603. {
  604. double stopFreq = 0.0;
  605. if( NFMClass->methods.xCharacterization.getStopFreq( eChFactory, &stopFreq ) )
  606. asm( "bkpt #0" ); // OK
  607. else
  608. asm( "bkpt #0" ); // ERROR
  609. (void)stopFreq;
  610. }
  611. #endif
  612. asm( "bkpt #0" );
  613. #if 1 && NFMCLASS_TEST_MEM_PROTECTION
  614. {
  615. bool oldstate = NFMClass->methods.xMemoryProtection.check();
  616. asm( "bkpt #0" );
  617. NFMClass->methods.xMemoryProtection.disable();
  618. asm( "bkpt #0" );
  619. bool state = NFMClass->methods.xMemoryProtection.check();
  620. asm( "bkpt #0" );
  621. NFMClass->methods.xMemoryProtection.enable();
  622. asm( "bkpt #0" );
  623. state = NFMClass->methods.xMemoryProtection.check();
  624. asm( "bkpt #0" );
  625. if( oldstate ) NFMClass->methods.xMemoryProtection.enable();
  626. else NFMClass->methods.xMemoryProtection.disable();
  627. }
  628. #endif
  629. #if 1 && NFMCLASS_TEST_THERMO_STARTFREQ
  630. {
  631. double startFreq = 0.0;
  632. if( NFMClass->methods.xThermo.getStartFreq( &startFreq ) )
  633. asm( "bkpt #0" ); // OK
  634. else
  635. asm( "bkpt #0" ); // ERROR
  636. (void)startFreq;
  637. }
  638. #endif
  639. #if 1 && NFMCLASS_TEST_THERMO_STOPFREQ
  640. {
  641. double stopFreq = 0.0;
  642. if( NFMClass->methods.xThermo.getStopFreq( &stopFreq ) )
  643. asm( "bkpt #0" ); // OK
  644. else
  645. asm( "bkpt #0" ); // ERROR
  646. (void)stopFreq;
  647. }
  648. #endif
  649. #if 1 && NFMCLASS_TEST_THERMO_POINTSCOUNT
  650. {
  651. size_t nPoints = NFMClass->methods.xThermo.getPointsCount( eChFactory );
  652. asm( "bkpt #0" );
  653. (void)nPoints;
  654. }
  655. #endif
  656. #endif
  657. }
  658. //------------------------------------------------------------------------------------------------------------
  659. //-- Public methods ------------------------------------------------------------------------------------------
  660. //------------------------------------------------------------------------------------------------------------
  661. // Enable Memory Protection for BANK0
  662. static bool NFMSetMemoryProtect()
  663. {
  664. return NFMClassExtended->private.methods.memory.setProtect( true );
  665. }
  666. // Disable Memory Protection for BANK0
  667. static bool NFMSetMemoryUnProtect()
  668. {
  669. return NFMClassExtended->private.methods.memory.setProtect( false );
  670. }
  671. // Check the Memory Protection Status for BANK0
  672. static bool NFMGetMemoryProtect()
  673. {
  674. return NFMClassExtended->private.methods.memory.getProtect();
  675. }
  676. #if 0
  677. // Set common key-switch state
  678. static bool NFMSetKeyStateCommon( eNFMKeyState_t state )
  679. {
  680. if( NFMClassExtended->public.methods.checkStateAvailable( state ) )
  681. {
  682. if( NULL != NFMClassExtended->private.properties.statesEncoding )
  683. {
  684. for( size_t i = 0; i < NFMClassExtended->public.properties.allowedStatesCount; ++i )
  685. {
  686. if( state == NFMClassExtended->private.properties.statesEncoding[i].commonKeyState )
  687. {
  688. NFMClassExtended->private.methods.switchControl(
  689. &NFMClassExtended->private.properties.statesEncoding[i]
  690. );
  691. NFMClassExtended->private.properties.keyState = state;
  692. return true;
  693. }
  694. }
  695. }
  696. }
  697. return false;
  698. }
  699. #endif
  700. // Get device serial number in string format
  701. static size_t NFMGetDeviceSerial( char * buffer, size_t size )
  702. {
  703. const sEcalHeader_t * Header = NFMClassExtended->private.methods.memory.getCommonHeader( NULL, 0 );
  704. if( NULL != Header )
  705. {
  706. size_t n = static_StrCpyLimit( (const char*)Header->SN, sizeof(Header->SN), buffer, size );
  707. if( n + 1 <= size )
  708. {
  709. buffer[n] = '\0';
  710. return (n + 1);
  711. }
  712. }
  713. return 0;
  714. }
  715. // Set device serial number in string format
  716. static size_t NFMSetDeviceSerial( char * buffer, size_t size )
  717. {
  718. const sEcalHeader_t * Header = NFMClassExtended->private.methods.memory.getCommonHeader( NULL, 0 );
  719. if( NULL != Header )
  720. {
  721. size_t n = static_StrCpyLimit( (const char*)Header->SN, sizeof(Header->SN), buffer, size );
  722. if( n + 1 <= size )
  723. {
  724. buffer[n] = '\0';
  725. return (n + 1);
  726. }
  727. }
  728. return 0;
  729. }
  730. // Get device manufacturer ID in string format
  731. // See more: NFMClass->properties.manufacturerId
  732. static size_t NFMGetDeviceManufacturer( char * buffer, size_t size )
  733. {
  734. size_t retval = 0;
  735. if( NULL != buffer && size > 1 )
  736. {
  737. const char * manufacturer_id = NFMClassExtended->public.properties.manufacturerId;
  738. while( (size > 1) && (*manufacturer_id != '\0') )
  739. {
  740. *buffer = *manufacturer_id;
  741. manufacturer_id++;
  742. buffer++;
  743. retval++; size--;
  744. }
  745. *buffer = '\0';
  746. }
  747. return retval;
  748. }
  749. // Get device model name in string format
  750. static size_t NFMGetModelName( char * buffer, size_t size )
  751. {
  752. if( NULL == buffer || 0 == size )
  753. return 0;
  754. size_t l = strlen( NFMClassExtended->public.properties.modelName );
  755. if( l <= size )
  756. {
  757. memcpy( buffer, NFMClassExtended->public.properties.modelName, l );
  758. }
  759. else
  760. {
  761. l = 0;
  762. }
  763. return l;
  764. }
  765. static bool NFMCheckPortStateAvailable( ePortStateId_t portState )
  766. {
  767. extern NFMClassEx_t * NFMClassExtended;
  768. // if( ePortStateId_MAX <= portState
  769. // || ePortStateId_UNDEFINED == portState
  770. // )
  771. // {
  772. // return (false);
  773. // }
  774. //
  775. // if(
  776. // NULL == NFMClassExtended->private.properties.memProfile
  777. // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw )
  778. // {
  779. // return (false);
  780. // }
  781. //
  782. // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile_XPort = NFMClassExtended->private.properties.memProfile->tbls_raw;
  783. //
  784. // switch(tableProfile_XPort->Header.ChrzTableType.eType)
  785. // {
  786. // case eNfmChrzTable2Port:
  787. // {
  788. // if( ePortStateId_MIN_SINGLE_2Port <= portState
  789. // && ePortStateId_MAX_SINGLE_2Port >= portState )
  790. // {
  791. // return true;
  792. // }
  793. // if( ePortStateId_MIN_THRU_2Port <= portState
  794. // && ePortStateId_MAX_THRU_2Port >= portState )
  795. // {
  796. // return true;
  797. // }
  798. // if( ePortStateId_MIN_CHECK_2Port <= portState
  799. // && ePortStateId_MAX_CHECK_2Port >= portState )
  800. // {
  801. // return true;
  802. // }
  803. // }
  804. // break;
  805. // case eNfmChrzTable4Port:
  806. // {
  807. // if( ePortStateId_MIN_SINGLE_4Port <= portState
  808. // && ePortStateId_MAX_SINGLE_4Port >= portState )
  809. // {
  810. // return true;
  811. // }
  812. // if( ePortStateId_MIN_THRU_4Port <= portState
  813. // && ePortStateId_MAX_THRU_4Port >= portState )
  814. // {
  815. // return true;
  816. // }
  817. // if( ePortStateId_MIN_CHECK_4Port <= portState
  818. // && ePortStateId_MAX_CHECK_4Port >= portState )
  819. // {
  820. // return true;
  821. // }
  822. // }
  823. // break;
  824. // }
  825. return (false); // unsupported characterization table type
  826. }
  827. static bool NFMCheckPortCombinationAvailable( ePortComb_t portCombination )
  828. {
  829. extern NFMClassEx_t * NFMClassExtended;
  830. if( ePortComb_MAX <= portCombination
  831. || ePortComb_UNDEFINED == portCombination
  832. )
  833. {
  834. return (false);
  835. }
  836. // if(
  837. // NULL == NFMClassExtended->private.properties.memProfile
  838. // || NULL == NFMClassExtended->private.properties.memProfile->tbls_raw )
  839. // {
  840. // return (false);
  841. // }
  842. //
  843. // const sNFMMemory_ChrzTableMatrix_XPort_t * tableProfile_XPort = NFMClassExtended->private.properties.memProfile->tbls_raw;
  844. //
  845. // if( ePortComb_MIN_SINGLE_XPort <= portCombination
  846. // && ePortComb_MAX_SINGLE_XPort >= portCombination )
  847. // {
  848. // switch(tableProfile_XPort->Header.ChrzTableType.eType)
  849. // {
  850. // case eNfmChrzTable2Port:
  851. // {
  852. // if( ePortComb_MIN_SINGLE_2Port <= portCombination
  853. // && ePortComb_MAX_SINGLE_2Port >= portCombination )
  854. // {
  855. // return true;
  856. // }
  857. // }
  858. // break;
  859. // case eNfmChrzTable4Port:
  860. // {
  861. // if( ePortComb_MIN_SINGLE_4Port <= portCombination
  862. // && ePortComb_MAX_SINGLE_4Port >= portCombination )
  863. // {
  864. // return true;
  865. // }
  866. // }
  867. // break;
  868. // }
  869. //
  870. // return 0; // unsupported characterization table type
  871. // }
  872. // else
  873. // if( ePortComb_MIN_THRU_XPort <= portCombination
  874. // && ePortComb_MAX_THRU_XPort >= portCombination )
  875. // {
  876. // switch(tableProfile_XPort->Header.ChrzTableType.eType)
  877. // {
  878. // case eNfmChrzTable2Port:
  879. // {
  880. // if( ePortComb_MIN_THRU_2Port <= portCombination
  881. // && ePortComb_MAX_THRU_2Port >= portCombination )
  882. // {
  883. // return true;
  884. // }
  885. // }
  886. // break;
  887. // case eNfmChrzTable4Port:
  888. // {
  889. // if( ePortComb_MIN_THRU_4Port <= portCombination
  890. // && ePortComb_MAX_THRU_4Port >= portCombination )
  891. // {
  892. // return true;
  893. // }
  894. // }
  895. // break;
  896. // }
  897. //
  898. // return 0; // unsupported characterization table type
  899. // }
  900. // else
  901. // if( ePortComb_CHECK == portCombination )
  902. // {
  903. // return true; // always available
  904. // }
  905. return (false);
  906. }
  907. #if 0
  908. static bool NFMCheckPortParamsAvailable( ePortComb_t portComb, ePortStateId_t portState )
  909. {
  910. return ( NFM_CHRZ_TABLEIDX_INVALID
  911. !=
  912. NFMClassExtended->private.methods.memory
  913. .getChrzTableIndex( portComb, portState )
  914. );
  915. }
  916. #endif
  917. //------------------------------------------------------------------------------------------------------------
  918. //-- Private methods -----------------------------------------------------------------------------------------
  919. //------------------------------------------------------------------------------------------------------------
  920. // private_ClassInit:
  921. // NFMClass object constructor
  922. static void private_ClassInit()
  923. {
  924. // -------------------------------------------------------------------------
  925. // Load device model profile by DeviceID from Common Header
  926. uint16_t deviceId;
  927. NFMClassExtended->private.properties.deviceId = eModel_undefined;
  928. NFMClassExtended->private.properties.modelProfile = NULL;
  929. NFMClassExtended->private.properties.memProfile = NULL;
  930. NFMClassExtended->public.properties.modelName = g_modelName;
  931. NFMClassExtended->public.properties.firmwareId = g_firmwareId;
  932. // prepare firmware ID string
  933. memset( (char*)g_firmwareId, 0, sizeof(g_firmwareId) );
  934. uint16_t firmware_version = pProgramVersion->firmware_version;
  935. _snprintf(g_firmwareId, sizeof(g_firmwareId) - 1,
  936. "%d%c%d%c%02d",
  937. ((firmware_version & 0xF000)>>12),
  938. '.',
  939. ((firmware_version & 0x0F00)>>8),
  940. '/',
  941. ((firmware_version & 0xFF)) );
  942. // // check model version
  943. // if(!NFMClassExtended->private.methods.getModelId(&deviceId)) // FOR DEBUGGING (ïèøåì äåâàéñ ID âî ôëåø)
  944. // {
  945. // bool xPro = NFMClassExtended->public.methods.xMemoryProtection.check();
  946. //
  947. // if( xPro )
  948. // {
  949. // NFMClassExtended->public.methods.xMemoryProtection.disable();
  950. // }
  951. //
  952. // NFM_ROM_ChangeModel( eModel_NFM );
  953. //
  954. //
  955. // if( xPro )
  956. // {
  957. // NFMClassExtended->public.methods.xMemoryProtection.enable();
  958. // }
  959. // }
  960. //const char serial[10] = {'0', '0', '0', '1', '5', '9', '1', '6', '5', '7'};
  961. //NFM_ROM_ChangeSerialNumber(serial);
  962. //NFM_ROM_ChangeModel(eModel_SWB);
  963. if( NFMClassExtended->private.methods.getModelId( &deviceId ) )
  964. {
  965. const sNFMModel_t * modelProfile = static_GetModelProfileByDeviceId( deviceId );
  966. if( NULL != modelProfile )
  967. {
  968. NFMClassExtended->public.properties.deviceId = (uint16_t)deviceId;
  969. NFMClassExtended->public.properties.modelName = modelProfile->modelName;
  970. NFMClassExtended->private.properties.deviceId = deviceId;
  971. NFMClassExtended->private.properties.modelProfile = modelProfile;
  972. NFMClassExtended->private.properties.memProfile = modelProfile->memProfile;
  973. if( NULL != modelProfile->nfProfile )
  974. {
  975. // NOTE: do not initialize if wrong number has been set
  976. // ---------------------------------------------------
  977. NFMClassExtended->public.properties.allowedInputPorts
  978. = modelProfile->nfProfile->controlProfile.allowedInputPorts;
  979. NFMClassExtended->public.properties.allowedOutputPorts
  980. = modelProfile->nfProfile->controlProfile.allowedOutputPorts;
  981. NFMClassExtended->public.properties.defaultInputState
  982. = modelProfile->nfProfile->controlProfile.defaultInputState;
  983. NFMClassExtended->public.properties.inputPortStates
  984. = modelProfile->nfProfile->controlProfile.inputPortStates;
  985. }
  986. }
  987. NFMClassExtended->public.methods.getDeviceSerial(
  988. g_serialNumber,
  989. sizeof(g_serialNumber)
  990. );
  991. NFMClassExtended->public.properties.serialNumber = g_serialNumber;
  992. if( ! NFMClassExtended->private.methods.memory.validateSettings())
  993. {
  994. // set default parameters
  995. unsigned char interface[8] = {'U', 'S', 'B', 'T', 'M', 'C', '!', 0};
  996. sNFMSettingsBlockCrc_t sSettingsBlock;
  997. for(int i = 0; i < sizeof(interface); i++)
  998. {
  999. sSettingsBlock.settings.rawBytes[i] = interface[i];
  1000. }
  1001. sSettingsBlock.settings.settingsVersion = 1;
  1002. sSettingsBlock.settings.tempCoeff = 3988; // Not used
  1003. TCRC crc = ICRC32;
  1004. crc = CRC32( crc, (uint8_t *)&sSettingsBlock.settings, sizeof(sSettingsBlock.settings));
  1005. sSettingsBlock.CRCValue = crc;
  1006. NFMClassExtended->private.methods.memory.setSettingsBlock( (uint8_t*)&sSettingsBlock,
  1007. 0,
  1008. sizeof(sSettingsBlock) );
  1009. }
  1010. }
  1011. /*
  1012. else
  1013. {
  1014. asm("bkpt #0");
  1015. bool xPro = NFMClassExtended->public.methods.xMemoryProtection.check();
  1016. if( xPro )
  1017. {
  1018. NFMClassExtended->public.methods.xMemoryProtection.disable();
  1019. }
  1020. NFM_ROM_ChangeModel( eModel_SC4520_v1 );
  1021. if( xPro )
  1022. {
  1023. NFMClassExtended->public.methods.xMemoryProtection.enable();
  1024. }
  1025. asm("bkpt #0");
  1026. }
  1027. */
  1028. }
  1029. // Checks the characterization table parameters for compatibility
  1030. bool private_CheckTableParams( ePortComb_t portComb, ePortStateId_t portState )
  1031. {
  1032. // Validate the combination of @portComb, @portState and
  1033. // validate the @portComb and @portState itself.
  1034. // Retrieve the table index (ordered index)
  1035. size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
  1036. if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  1037. {
  1038. // Invalid combination or value
  1039. return false;
  1040. }
  1041. return true;
  1042. }
  1043. /*
  1044. // private_getModelName
  1045. // Get device model name by DeviceID
  1046. static const char * private_getModelName()
  1047. {
  1048. uint16_t deviceId = eModel_undefined;
  1049. if( ! NFMClassExtended->private.methods.getModelId( &deviceId ) )
  1050. {
  1051. deviceId = eModel_undefined;
  1052. }
  1053. return NFMClassExtended->private.methods.getModelNameById( deviceId );
  1054. }
  1055. */
  1056. /*
  1057. // private_getModelNameById
  1058. // Get device model name by DeviceID
  1059. static const char * private_getModelNameById( uint16_t deviceId )
  1060. {
  1061. const sNFMModel_t * modelProfile = static_GetModelProfileByDeviceId( deviceId );
  1062. if( NULL == modelProfile )
  1063. return NULL;
  1064. return modelProfile->modelName;
  1065. }
  1066. */
  1067. // private_getModelId
  1068. // Get device model ID (DeviceID)
  1069. static bool private_getModelId( uint16_t * pDeviceId )
  1070. {
  1071. const sEcalHeader_t * Header = NFMClassExtended->private.methods.memory.getCommonHeader( NULL, 0 );
  1072. if( NULL != Header )
  1073. {
  1074. if( NULL != pDeviceId )
  1075. {
  1076. *pDeviceId = Header->DeviceID;
  1077. return true;
  1078. }
  1079. }
  1080. return false;
  1081. }
  1082. //------------------------------------------------------------------------------------------------------------
  1083. //-- Static methods -----------------------------------------------------------------------------------------
  1084. //------------------------------------------------------------------------------------------------------------
  1085. static bool static_KeyStateNameCompare( const char * name1,
  1086. const char * name2,
  1087. size_t size )
  1088. {
  1089. if( NULL == name1 || NULL == name2 || 0 == size )
  1090. return false;
  1091. for( size_t i = 0; i < size; ++i )
  1092. {
  1093. if( tolower(name1[i]) != tolower(name2[i]) )
  1094. {
  1095. return false;
  1096. }
  1097. }
  1098. return true;
  1099. }
  1100. static size_t static_StrCpyLimit( const char * source, size_t srcMaxLen,
  1101. char * dest, size_t destMaxLen )
  1102. {
  1103. size_t srcLen = srcMaxLen;
  1104. for( size_t i = 0; (0 == srcMaxLen) || (i < srcMaxLen); ++i )
  1105. {
  1106. if( source[i] == '\0' )
  1107. {
  1108. srcLen = i;
  1109. break;
  1110. }
  1111. }
  1112. size_t rc = 0;
  1113. for( size_t i = 0; true; ++i )
  1114. {
  1115. if( (i >= destMaxLen) || (i >= srcLen) )
  1116. {
  1117. rc = (i);
  1118. break;
  1119. }
  1120. dest[i] = source[i];
  1121. }
  1122. return (rc);
  1123. }
  1124. // Searches the model profile by device ID
  1125. static const sNFMModel_t * static_GetModelProfileByDeviceId( uint16_t deviceId )
  1126. {
  1127. for( size_t i = 0; i < aNFMModels_count; ++i )
  1128. {
  1129. if( aNFMModels[i].deviceId == deviceId )
  1130. {
  1131. return &aNFMModels[i];
  1132. }
  1133. }
  1134. for( size_t i = 0; i < aNFMModels_count; ++i )
  1135. {
  1136. if( eModel_undefined == aNFMModels[i].deviceId )
  1137. {
  1138. return &aNFMModels[i];
  1139. }
  1140. }
  1141. return NULL;
  1142. }
  1143. //------------------------------------------------------------------------------
  1144. //------------------------------------------------------------------------------
  1145. //------------------------------------------------------------------------------
  1146. //------------------------------------------------------------------------------
  1147. #if 0
  1148. // MEM:TABL:DATA?
  1149. // Reads the data points of the characterization table
  1150. size_t NFMGetPoints( eChrz_t sectorId, ePortComb_t portComb, ePortStateId_t portState,
  1151. sNFMGetPoints_t * pCtl )
  1152. {
  1153. if( portComb >= ePortComb_MAX
  1154. || portComb == ePortComb_UNDEFINED
  1155. || portState >= ePortStateId_MAX
  1156. || portState == ePortStateId_UNDEFINED
  1157. || NULL == pCtl
  1158. || NULL == pCtl->in.pDataArray
  1159. )
  1160. {
  1161. if( NULL != pCtl )
  1162. pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1163. return 0;
  1164. }
  1165. /* --- do it later: inside @getChrzTableHeader() call
  1166. // Validate the combination of @portComb, @portState and
  1167. // validate the @portComb and @portState itself.
  1168. // Retrieve the table index (ordered index)
  1169. size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
  1170. if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  1171. {
  1172. // Invalid combination or value
  1173. return 0;
  1174. }
  1175. */
  1176. // Check the input parameter: @pCtl->in.nCount
  1177. // For zero value: required to load the table header
  1178. // During the loading the table header it is required:
  1179. // - load the main characterization header, check CRC
  1180. // - retrieve number of points (@nPoints) from the header for specified @sectorId
  1181. // - load the table header and check it's CRC
  1182. // - retrieve the table address @TableAddress (for next operations)
  1183. // - retrieve the @min and @max fields from the table header
  1184. // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  1185. // - return (1) in case of success, or (0) on error
  1186. if( 0 == pCtl->in.nCount )
  1187. {
  1188. // load characterization main header
  1189. // and check the CRC
  1190. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory
  1191. .getDataHeader( sectorId, NULL, 0 );
  1192. // check the main header: number of points
  1193. if( NULL == pChrzHeader
  1194. || 0 == pChrzHeader->Points )
  1195. {
  1196. pCtl->svc.errCode = ERR_NFMGETPOINTS_INVHDR;
  1197. return (0);
  1198. }
  1199. // move @.Points into @nPoints
  1200. // due to @pChrzHeader will be corrupted
  1201. size_t nPoints = pChrzHeader->Points;
  1202. sEcalChrzTableHeader_t tableMicroHeader;
  1203. // load the table base address
  1204. // Note: the data by @pChrzHeader is not valid after this call,
  1205. // due to the function uses the same internal buffer!
  1206. size_t tableAddress = NFMClassExtended->private.methods.memory
  1207. .getChrzTableHeader( // load the table base address
  1208. sectorId, // for specified memory sector
  1209. portComb, // for specified port combination
  1210. portState, // for specified port state
  1211. nPoints, // for retrieved number of points
  1212. &tableMicroHeader, // and store the header into @tableMicroHeader
  1213. &pCtl->svc.errCode // And fill the error code
  1214. );
  1215. // check the result: @tableAddress
  1216. // 0 - table corrupted or invalid port combination or port state.
  1217. // but since the @portComb and @portState are validated above...
  1218. // this result means only that the table is corrupted
  1219. // non zero - this is the absolute address of the requested table.
  1220. if( 0 == tableAddress )
  1221. {
  1222. (void)pCtl->svc.errCode;
  1223. return 0; // error, sorry
  1224. }
  1225. // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  1226. pCtl->out.max = tableMicroHeader.MaxMagn;
  1227. pCtl->out.min = tableMicroHeader.MinMagn;
  1228. pCtl->out.TableAddress = tableAddress;
  1229. pCtl->out.nPoints = nPoints;
  1230. pCtl->svc.errCode = ERR_NFMGETPOINTS_NOERR;
  1231. // success
  1232. return 1;
  1233. }
  1234. // -----------------
  1235. // User must call this function with (pCtl->in.nCount=0) first time
  1236. // to initialize the @pCtl->out contents.
  1237. // Here: 0 != pCtl->in.nCount
  1238. // -----------------
  1239. // Check the header data, loaded at previous step ( see pCtl->in.nCount == 0 )
  1240. if( 0 == pCtl->out.nPoints // check the number of points in the table
  1241. || 0 == pCtl->out.TableAddress ) // check the table base address
  1242. {
  1243. // error, invalid parameters
  1244. // Call the function with (pCtl->in.nCount = 0) to load the header
  1245. pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1246. return 0;
  1247. }
  1248. // Check the input parameters
  1249. if( pCtl->in.nCount > pCtl->out.nPoints // check the amount of requested points
  1250. || pCtl->in.nStartPoint >= pCtl->out.nPoints // check the starting point
  1251. || NULL == pCtl->in.pDataArray ) // check receiving data buffer
  1252. {
  1253. // error: invalid input parameters
  1254. pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1255. return 0;
  1256. }
  1257. return NFMClassExtended->private.methods.memory.getChrzPoints( pCtl );
  1258. }
  1259. #endif
  1260. // MEM:TABL:DATA?
  1261. // Prepares the context before reading the data points of the characterization table
  1262. // This method is designed to replace the obsolete @NFMGetPoints.
  1263. // Parameters:
  1264. // @sectorId - bank id, characterization bank;
  1265. // @portComb - port combination to request (NFM path);
  1266. // @portState - port state to request (S-parameter);
  1267. // @pDataBuffer - output data buffer;
  1268. // @szDataBuffer - output data buffer capacity;
  1269. // @xCtl - the control context to initialize;
  1270. // Returns: 0 in case error, or number of points in case success.
  1271. size_t NFMGetPoints_Begin( eChrz_t sectorId, ePortComb_t portComb, ePortStateId_t portState,
  1272. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  1273. xNFMGetPointsSimplified_t * xCtl )
  1274. {
  1275. sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
  1276. // Check if arguments are valid in general
  1277. if( ( sectorId >= eCh_MAX )
  1278. || ( portComb >= ePortComb_MAX )
  1279. || ( portState >= ePortStateId_MAX )
  1280. || ( portComb == ePortComb_UNDEFINED )
  1281. || ( NULL == xCtl )
  1282. || ( 0 == szDataBuffer ) )
  1283. {
  1284. if( NULL != pCtl )
  1285. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1286. return 0;
  1287. }
  1288. // Check if arguments are valid particularly for this device
  1289. if( ! NFMClassExtended->public.methods.checkTableParams( portComb, portState ) )
  1290. {
  1291. // Invalid combination or value
  1292. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1293. return 0;
  1294. }
  1295. // Try to validate configuration (table ID)
  1296. size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
  1297. if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  1298. {
  1299. // Invalid combination or value
  1300. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1301. return 0;
  1302. }
  1303. // Fill input parameters:
  1304. pCtl->BufferCapacity = szDataBuffer; // - output buffer capacity
  1305. pCtl->sectorId = sectorId; // - requested bank
  1306. pCtl->portComb = portComb; // - requested port combination (nfm path)
  1307. pCtl->portState = portState; // - requested state (S-parameter)
  1308. pCtl->intCtx.in.nCount = szDataBuffer; // - number of points to get
  1309. pCtl->intCtx.in.nStartPoint = 0; // - start point
  1310. pCtl->intCtx.in.pDataArray = pDataBuffer; // - output buffer
  1311. // During the loading the table header it is required:
  1312. // - load the main characterization header, check CRC
  1313. // - retrieve number of points (@nPoints) from the header for specified @sectorId
  1314. // - load the table header and check it's CRC
  1315. // - retrieve the table address @TableAddress (for next operations)
  1316. // - retrieve the @min and @max fields from the table header
  1317. // - store @min, @max, @TableAddress, @nPoints into @pCtl.intCtx.out
  1318. // load characterization main header
  1319. // and check the CRC
  1320. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory
  1321. .getDataHeader( sectorId, NULL, 0 );
  1322. // check the main header: number of points
  1323. if( NULL == pChrzHeader
  1324. || 0 == pChrzHeader->Points )
  1325. {
  1326. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVHDR;
  1327. return (0);
  1328. }
  1329. // move @.Points into @nPoints
  1330. // due to @pChrzHeader will be corrupted
  1331. size_t nPoints = pChrzHeader->Points;
  1332. sEcalChrzTableHeader_t tableMicroHeader;
  1333. // load the table base address
  1334. // Note: the data by @pChrzHeader is not valid after this call,
  1335. // due to the function uses the same internal buffer!
  1336. size_t tableAddress = NFMClassExtended->private.methods.memory
  1337. .getChrzTableHeader( // load the table base address
  1338. sectorId, // for specified memory sector
  1339. portComb, // for specified port combination
  1340. portState, // for specified port state
  1341. nPoints, // for retrieved number of points
  1342. &tableMicroHeader, // and store the header into @tableMicroHeader
  1343. &pCtl->intCtx.svc.errCode // And fill the error code
  1344. );
  1345. // check the result: @tableAddress
  1346. // 0 - table corrupted or invalid port combination or port state.
  1347. // but since the @portComb and @portState are validated above...
  1348. // this result means only that the table is corrupted
  1349. // non zero - this is the absolute address of the requested table.
  1350. if( 0 == tableAddress )
  1351. {
  1352. (void)pCtl->intCtx.svc.errCode;
  1353. return 0; // error, sorry
  1354. }
  1355. // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  1356. pCtl->intCtx.out.max = tableMicroHeader.MaxMagn;
  1357. pCtl->intCtx.out.min = tableMicroHeader.MinMagn;
  1358. pCtl->intCtx.out.TableAddress = tableAddress;
  1359. pCtl->intCtx.out.nPoints = nPoints;
  1360. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
  1361. // success
  1362. return nPoints;
  1363. }
  1364. // MEM:TABL:DATA?
  1365. // @NFMGetPoints_Continue
  1366. // Uses already prepared context and reads the data points of the characterization
  1367. // table to the top of specified buffer (see @NFMGetPoints_Begin).
  1368. // This method is designed to replace the obsolete @NFMGetPoints.
  1369. // Parameters:
  1370. // @xCtl - control context prepared by previous NFMGetPoints_Begin call
  1371. // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
  1372. //
  1373. // Returns:
  1374. // - eNFMGetPointError_DataError: error, can not load data;
  1375. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  1376. // - eNFMGetPointError_Success: success, all the points from the table have been read;
  1377. // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
  1378. // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
  1379. int32_t NFMGetPoints_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve )
  1380. {
  1381. sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
  1382. if( NULL == pCtl || NULL == pnPointsRetrieve )
  1383. {
  1384. return eNFMGetPointError_InvalidValue;
  1385. }
  1386. // Check if arguments are valid in general
  1387. if( ( pCtl->sectorId >= eCh_MAX )
  1388. || ( pCtl->portComb >= ePortComb_MAX )
  1389. || ( pCtl->portState >= ePortStateId_MAX )
  1390. || ( pCtl->portComb == ePortComb_UNDEFINED )
  1391. || ( 0 == pCtl->BufferCapacity )
  1392. || ( 0 == pCtl->intCtx.out.nPoints )
  1393. || ( 0 == pCtl->intCtx.out.TableAddress )
  1394. || ( NULL == pCtl->intCtx.in.pDataArray ) )
  1395. {
  1396. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
  1397. return eNFMGetPointError_InvalidValue;
  1398. }
  1399. // check ranges
  1400. if( pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints;
  1401. if( pCtl->intCtx.in.nStartPoint >= pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nStartPoint = pCtl->intCtx.out.nPoints; // end-of-points
  1402. if( pCtl->intCtx.in.nStartPoint +
  1403. pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
  1404. {
  1405. pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
  1406. }
  1407. // check for end condition
  1408. if( 0 == pCtl->intCtx.in.nCount
  1409. || pCtl->intCtx.in.nStartPoint == pCtl->intCtx.out.nPoints )
  1410. {
  1411. *pnPointsRetrieve = 0; // number of points read is zero
  1412. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
  1413. return eNFMGetPointError_Success;
  1414. }
  1415. int32_t success_rc = eNFMGetPointError_Success;
  1416. // check buffer capacity range
  1417. if( pCtl->intCtx.in.nCount > pCtl->BufferCapacity )
  1418. {
  1419. pCtl->intCtx.in.nCount = pCtl->BufferCapacity;
  1420. success_rc = eNFMGetPointError_OutOfBuffer; // out of buffer, the number of points is limited
  1421. }
  1422. else
  1423. if( pCtl->intCtx.in.nStartPoint + pCtl->intCtx.in.nCount < pCtl->intCtx.out.nPoints )
  1424. {
  1425. success_rc = eNFMGetPointError_Limit; // number of points is limited by user
  1426. }
  1427. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_IO;
  1428. size_t nRead = NFMClassExtended->private.methods.memory.getChrzPoints( &pCtl->intCtx );
  1429. // check for error condition
  1430. if( nRead == 0 )
  1431. {
  1432. *pnPointsRetrieve = 0; // number of points read is zero
  1433. (void)pCtl->intCtx.svc.errCode;
  1434. return eNFMGetPointError_DataError;
  1435. }
  1436. pCtl->intCtx.in.nStartPoint += nRead; // increment start point for next call
  1437. // check range
  1438. if( pCtl->intCtx.in.nStartPoint +
  1439. pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
  1440. {
  1441. pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
  1442. }
  1443. *pnPointsRetrieve = nRead; // number of points read
  1444. return success_rc;
  1445. }
  1446. // Reads amount of points in the characterization table
  1447. size_t NFMGetPointsCount( eChrz_t tableId )
  1448. {
  1449. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  1450. if( NULL == pChrzHeader )
  1451. return (0);
  1452. return (size_t)pChrzHeader->Points;
  1453. }
  1454. // MEM:TABL:POIN?
  1455. // Reads amount of points in the characterization table
  1456. bool NFMGetPointsCount_Safe( eChrz_t tableId, int16_t * count )
  1457. {
  1458. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  1459. if( NULL == pChrzHeader || NULL == count )
  1460. return false;
  1461. *count = pChrzHeader->Points;
  1462. return true;
  1463. }
  1464. // MEM:TABL:DATE?
  1465. // Reads the date of characterization table
  1466. bool NFMGetDate( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
  1467. {
  1468. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  1469. if( NULL == pChrzHeader || NULL == buffer || 0 == size || NULL == bytes )
  1470. return (false);
  1471. size_t nCpy = static_StrCpyLimit(
  1472. (const char*)pChrzHeader->CalDate,
  1473. sizeof(pChrzHeader->CalDate),
  1474. buffer,
  1475. size );
  1476. *bytes = nCpy;
  1477. return true;
  1478. }
  1479. // MEM:TABL:TIME?
  1480. // Reads the time of characterization table
  1481. bool NFMGetTime( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
  1482. {
  1483. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  1484. if( NULL == pChrzHeader || NULL == buffer || 0 == size || NULL == bytes )
  1485. return (false);
  1486. size_t nCpy = static_StrCpyLimit(
  1487. (const char*)pChrzHeader->CalTime,
  1488. sizeof(pChrzHeader->CalTime),
  1489. buffer,
  1490. size );
  1491. *bytes = nCpy;
  1492. return true;
  1493. }
  1494. // MEM:TABL:FREQ:TYPE?
  1495. // Reads the type of the frequency scale of data characterization table
  1496. bool NFMGetScaleType( eChrz_t tableId, eChrzScaleType_t * pType )
  1497. {
  1498. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  1499. if( NULL == pChrzHeader )
  1500. return (false);
  1501. if( NULL != pType )
  1502. {
  1503. if( SWEEP_VERSION_LINEAR == pChrzHeader->Version )
  1504. {
  1505. *pType = eChScaleLinear;
  1506. return true;
  1507. }
  1508. else if( SWEEP_VERSION_SEGMENT == pChrzHeader->Version )
  1509. {
  1510. *pType = eChScaleSegment;
  1511. return true;
  1512. }
  1513. }
  1514. return false;
  1515. }
  1516. // MEM:TABL:FREQ:SEGM:DATA?
  1517. // Reads the scale segment of data characterization table
  1518. // Pass NULL in @pSegment to retrieve amount of segments in return value
  1519. size_t NFMGetScaleSegment( eChrz_t tableId, sEcalSegment_t * pSegment, size_t nSegmentId )
  1520. {
  1521. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  1522. if( NULL == pChrzHeader )
  1523. return (0);
  1524. // in case @pSegment is NULL, return amount of segments
  1525. if( NULL == pSegment )
  1526. {
  1527. if( 1 == pChrzHeader->Version ) // Linear Sweep
  1528. {
  1529. return 1; // One segment
  1530. }
  1531. return pChrzHeader->NSegm;
  1532. }
  1533. if( ( (nSegmentId >= pChrzHeader->NSegm) && (pChrzHeader->Version == 2) )
  1534. || ( (nSegmentId != 0) && (pChrzHeader->Version == 1) )
  1535. || ( pChrzHeader->Version != 1 && pChrzHeader->Version != 2) )
  1536. {
  1537. // error: check the @nSegmentId, it must be less than amount of segments
  1538. return 0;
  1539. }
  1540. else
  1541. {
  1542. if( 1 == pChrzHeader->Version ) // Linear Sweep
  1543. pSegment->Points = pChrzHeader->Points;
  1544. else
  1545. pSegment->Points = pChrzHeader->Segm[ nSegmentId ].Points;
  1546. double Fstart = 0.0;
  1547. double Fstop = 0.0;
  1548. // aligned access to the unaligned 'double' field
  1549. // memcpy( & Fstart,
  1550. // & pChrzHeader->Segm[ nSegmentId ].Fstart_unaligned,
  1551. // sizeof(Fstart)
  1552. // );
  1553. if( 1 == pChrzHeader->Version ) // Linear Sweep
  1554. Fstart = pChrzHeader->Fmin_unaligned;
  1555. else
  1556. Fstart = pChrzHeader->Segm[ nSegmentId ].Fstart_unaligned;
  1557. // aligned access to the unaligned 'double' field
  1558. // memcpy( & Fstop,
  1559. // & pChrzHeader->Segm[ nSegmentId ].Fstop_unaligned,
  1560. // sizeof(Fstop)
  1561. // );
  1562. if( 1 == pChrzHeader->Version ) // Linear Sweep
  1563. Fstop = pChrzHeader->Fmax_unaligned;
  1564. else
  1565. Fstop = pChrzHeader->Segm[ nSegmentId ].Fstop_unaligned;
  1566. pSegment->Fstart = Fstart;
  1567. pSegment->Fstop = Fstop;
  1568. }
  1569. return 1;
  1570. }
  1571. // @NFMGetScaleFreqs_Begin
  1572. // Prepares a retrieving context for calling the @NFMGetScaleFreqs_Continue routine.
  1573. // Initializes such values as:
  1574. // - a number of starting point to retrive
  1575. // - a buffer to retrieve the values to
  1576. // - characterization table (unit) identifier (@tableId)
  1577. // Parameters:
  1578. // @tableId - characterization table to operate with;
  1579. // @nStartPoint - starting point to begin retrieving from (default = 0);
  1580. // @nStartSegment - starting segment to begin retrieving from (default = 0);
  1581. // @pFreqArray - a floating point values buffer to store data to;
  1582. // @BufferCapacity - receiving buffer capacity [@pFreqArray]
  1583. // @xCtl - a control structure to intialize; use this structure to call @NFMGetScaleFreqs_Continue.
  1584. //
  1585. // Returns: integer result (see @eNFMGetPointError_t):
  1586. // - eNFMGetPointError_DataError: error, can not load data;
  1587. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  1588. // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
  1589. int32_t NFMGetScaleFreqs_Begin( eChrz_t tableId, double * pFreqArray, size_t BufferCapacity, xNFMGetFreqPoints_t * xCtl )
  1590. {
  1591. sNFMGetFreqPoints_t * pCtl = (sNFMGetFreqPoints_t*)(xCtl);
  1592. // Checking arguments:
  1593. if( tableId >= eCh_MAX
  1594. || NULL == pFreqArray
  1595. || NULL == xCtl
  1596. || 0 == BufferCapacity )
  1597. {
  1598. return (eNFMGetPointError_InvalidValue); // error condition
  1599. }
  1600. // initialize the fields
  1601. pCtl->pDataArray = pFreqArray; // specify receiving buffer
  1602. pCtl->tableId = tableId; // specify table ID;
  1603. // Get the scale type (LIN | SEGM):
  1604. if( ! NFMClass->methods.xCharacterization.getScaleType( tableId, &pCtl->scaleType ) )
  1605. {
  1606. return (eNFMGetPointError_DataError); // error condition
  1607. }
  1608. // Get segments count for linear or segment scale
  1609. switch( pCtl->scaleType )
  1610. {
  1611. case eChScaleSegment:
  1612. {
  1613. // Get segments count
  1614. pCtl->nSegments = NFMClass->methods.xCharacterization.getScaleSegment( tableId, NULL, 0 );
  1615. // Check segments count
  1616. if( 0 == pCtl->nSegments )
  1617. {
  1618. return (eNFMGetPointError_DataError); // error condition: invalid segments count (=0)
  1619. }
  1620. }
  1621. break;
  1622. case eChScaleLinear:
  1623. {
  1624. // For linear scale: number of segments is 1
  1625. pCtl->nSegments = 1;
  1626. }
  1627. break;
  1628. default:
  1629. return (eNFMGetPointError_DataError); // error condition: invalid scale type
  1630. }
  1631. // Initialize the rest fields
  1632. pCtl->BufferCapacity = BufferCapacity; // set user buffer capacity
  1633. pCtl->nStartSegment = 0; // specify starting segment
  1634. pCtl->nStartPoint = 0; // specify starting point
  1635. pCtl->Segment.Points = 0; // forward set, will be updated in @NFMGetScaleFreqs_Continue
  1636. pCtl->Segment.Fstart = 0.0;
  1637. pCtl->Segment.Fstop = 0.0;
  1638. return eNFMGetPointError_Success;
  1639. }
  1640. // @NFMGetScaleFreqs_Continue
  1641. // Related SCPI command: 'MEM:TABL:FREQ:DATA?'
  1642. // Reads the frequencies of data characterization table's points (either for Linear and Segment scale)
  1643. // and stores it into the buffer specified by calling @NFMGetScaleFreqs_Begin
  1644. // Note: the points are stored to the top of the specified buffer each call.
  1645. //
  1646. // Parameters:
  1647. // @xCtl - retrieve context, must be initialized by @NFMGetScaleFreqs_Begin
  1648. // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
  1649. //
  1650. // !!! Attention: user shall control the @pFreqArray buffer range itself when calling @NFMGetScaleFreqs_Begin
  1651. // !!! and guarantee, that it has enough room to recevie specified number of points [@nPointsRetrieve].
  1652. //
  1653. // Returns:
  1654. // - eNFMGetPointError_DataError: error, can not load data;
  1655. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  1656. // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
  1657. // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
  1658. // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
  1659. int32_t NFMGetScaleFreqs_Continue( xNFMGetFreqPoints_t * xCtl, size_t * pnPointsRetrieve )
  1660. {
  1661. sNFMGetFreqPoints_t * pCtl = (sNFMGetFreqPoints_t*)(xCtl);
  1662. // Checking arguments:
  1663. if( NULL == xCtl || NULL == pnPointsRetrieve || 0 == *pnPointsRetrieve )
  1664. {
  1665. return (eNFMGetPointError_InvalidValue); // error condition
  1666. }
  1667. // Check input parameters from context:
  1668. if( 0 == pCtl->nSegments || eChScale_undefined == pCtl->scaleType || eCh_MAX <= pCtl->tableId || NULL == pCtl->pDataArray || 0 == pCtl->BufferCapacity )
  1669. {
  1670. return (eNFMGetPointError_InvalidValue); // error condition
  1671. }
  1672. size_t iPointRequested = 0;
  1673. bool bBreak = false;
  1674. int32_t rc = eNFMGetPointError_Success; // forward set to success code
  1675. // For each segment and each point:
  1676. for( (void)pCtl->nStartSegment;
  1677. (pCtl->nStartSegment < pCtl->nSegments) && (!bBreak);
  1678. ++ pCtl->nStartSegment )
  1679. {
  1680. for( (void)pCtl->nStartPoint;
  1681. ((void)pCtl->Segment.Points, (!bBreak));
  1682. ++ pCtl->nStartPoint )
  1683. {
  1684. // Check if the segment is loaded
  1685. if( 0 == pCtl->Segment.Points )
  1686. {
  1687. // load segment data:
  1688. switch( pCtl->scaleType )
  1689. {
  1690. case eChScaleSegment:
  1691. {
  1692. // Retrieve the segment data
  1693. if( 1 != NFMClass->methods.xCharacterization.getScaleSegment( pCtl->tableId, &pCtl->Segment, pCtl->nStartSegment ) )
  1694. {
  1695. return (eNFMGetPointError_DataError); // error condition: can not load segment data
  1696. }
  1697. }
  1698. break;
  1699. case eChScaleLinear:
  1700. {
  1701. // For linear scale: retrieve from the common characterization header
  1702. if( ! NFMClass->methods.xCharacterization.getPointsCountSafe( pCtl->tableId, &pCtl->Segment.Points )
  1703. || ! NFMClass->methods.xCharacterization.getStartFreq( pCtl->tableId, &pCtl->Segment.Fstart )
  1704. || ! NFMClass->methods.xCharacterization.getStopFreq( pCtl->tableId, &pCtl->Segment.Fstop ) )
  1705. {
  1706. return (eNFMGetPointError_DataError); // error condition: can not load segment data
  1707. }
  1708. }
  1709. break;
  1710. default:
  1711. return (eNFMGetPointError_DataError); // error condition: invalid scale type
  1712. }
  1713. // Calculate the discrette
  1714. pCtl->Fdesc = (pCtl->Segment.Fstop - pCtl->Segment.Fstart) / (pCtl->Segment.Points - 1);
  1715. pCtl->nStartPoint = 0; // Reset start point for current segment
  1716. }
  1717. // Segment loaded?
  1718. if( 0 != pCtl->Segment.Points )
  1719. {
  1720. // yes, check condition: all the points of segment have been processed?
  1721. if( pCtl->nStartPoint >= pCtl->Segment.Points ) break;
  1722. }
  1723. else
  1724. {
  1725. // Invalid segment
  1726. return (eNFMGetPointError_DataError); // error condition: can not load segment data
  1727. }
  1728. // Fill the output array from the begining
  1729. // Note @pDataArray have at least one cell due to input checking
  1730. pCtl->pDataArray[ iPointRequested++ ] = (pCtl->Segment.Fstart + pCtl->Fdesc * pCtl->nStartPoint);
  1731. // Check for overflow: user buffer overflow
  1732. if( iPointRequested >= pCtl->BufferCapacity )
  1733. {
  1734. bBreak = true;
  1735. rc = eNFMGetPointError_OutOfBuffer; // warning
  1736. /* break; DO NOT BREAK, need to increment @nStartPoint */
  1737. }
  1738. // Check for end condition: user limit
  1739. if( iPointRequested >= *pnPointsRetrieve )
  1740. {
  1741. bBreak = true;
  1742. rc = eNFMGetPointError_Limit; // warning
  1743. /* break; DO NOT BREAK, need to increment @nStartPoint */;
  1744. }
  1745. }
  1746. // Check for end condition: out of points in segment or out of segments
  1747. if( pCtl->nStartPoint >= pCtl->Segment.Points )
  1748. {
  1749. if( pCtl->nStartSegment >= pCtl->nSegments - 1 ) /* -1: because @nStartSegment has not been incremented yet */
  1750. {
  1751. pCtl->nStartSegment++; // instead of reaching the top of operator 'for'
  1752. bBreak = true;
  1753. (void)rc; // eNFMGetPointError_Success, end-of-data
  1754. }
  1755. pCtl->Segment.Points = 0; // Reset points count: make to load the segment data at next iteration
  1756. pCtl->nStartPoint = 0; // Reset start point for next segment
  1757. }
  1758. if( bBreak ) break; // do not increment @nStartSegment
  1759. }
  1760. (void)rc; // If no points are available, the @eNFMGetPointError_Success code is returned with *pnPointsRetrieve set to zero
  1761. *pnPointsRetrieve = iPointRequested; // write number of points read
  1762. return rc;
  1763. }
  1764. // @SWGetTablePoints_Begin
  1765. // Prepares a retrieving context for calling the @SWGetTablePoints_Continue routine.
  1766. // Initializes such values as:
  1767. // - a number of starting point to retrive
  1768. // - a buffer to retrieve the values to
  1769. // - points table (unit) identifier (@tableId)
  1770. // Parameters:
  1771. // @tableId - characterization table to operate with;
  1772. // @nStartPoint - starting point to begin retrieving from (default = 0);
  1773. // @nStartSegment - starting segment to begin retrieving from (default = 0);
  1774. // @pPointsArray - a floating point values buffer to store data to;
  1775. // @BufferCapacity - receiving buffer capacity [@pFreqArray]
  1776. // @xCtl - a control structure to intialize; use this structure to call @SWGetTablePoints_Continue.
  1777. //
  1778. // Returns: integer result (see @eNFMGetPointError_t):
  1779. // - eNFMGetPointError_DataError: error, can not load data;
  1780. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  1781. // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
  1782. int32_t SWGetTablePoints_Begin( eChrz_t tableId, sSWTablePoint_t * pPointsArray, size_t BufferCapacity, xSWGetTablePoints_t * xCtl )
  1783. {
  1784. sSWGetTablePoints_t * pCtl = (sSWGetTablePoints_t*)(xCtl);
  1785. // Checking arguments:
  1786. if( tableId >= eCh_MAX
  1787. || NULL == pPointsArray
  1788. || NULL == xCtl
  1789. || 0 == BufferCapacity )
  1790. {
  1791. return (eNFMGetPointError_InvalidValue); // error condition
  1792. }
  1793. // initialize the fields
  1794. pCtl->pDataArray = pPointsArray; // specify receiving buffer
  1795. pCtl->tableId = tableId; // specify table ID;
  1796. // Initialize the rest fields
  1797. pCtl->BufferCapacity = BufferCapacity; // set user buffer capacity
  1798. pCtl->nStartPoint = 0; // specify starting point
  1799. //pCtl->nNumberOfPoints = TableHandle.GetNumberOfPoints();
  1800. pCtl->nNumberOfPoints = TableHandle.GetNumberOfPoints();
  1801. pCtl->TablePoint.port1 = 0;
  1802. pCtl->TablePoint.port2 = 0;
  1803. return eNFMGetPointError_Success;
  1804. }
  1805. // @NFMGetScaleFreqs_Continue
  1806. // Related SCPI command: 'MEM:TABL:FREQ:DATA?'
  1807. // Reads the frequencies of data characterization table's points (either for Linear and Segment scale)
  1808. // and stores it into the buffer specified by calling @NFMGetScaleFreqs_Begin
  1809. // Note: the points are stored to the top of the specified buffer each call.
  1810. //
  1811. // Parameters:
  1812. // @xCtl - retrieve context, must be initialized by @NFMGetScaleFreqs_Begin
  1813. // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
  1814. //
  1815. // !!! Attention: user shall control the @pFreqArray buffer range itself when calling @NFMGetScaleFreqs_Begin
  1816. // !!! and guarantee, that it has enough room to recevie specified number of points [@nPointsRetrieve].
  1817. //
  1818. // Returns:
  1819. // - eNFMGetPointError_DataError: error, can not load data;
  1820. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  1821. // - eNFMGetPointError_Success: success, all the points from all the segments have been read;
  1822. // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
  1823. // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
  1824. int32_t SWGetTablePoints_Continue( xSWGetTablePoints_t * xCtl, size_t * pnPointsRetrieve )
  1825. {
  1826. sSWGetTablePoints_t * pCtl = (sSWGetTablePoints_t*)(xCtl);
  1827. // Checking arguments:
  1828. if( NULL == xCtl || NULL == pnPointsRetrieve || 0 == *pnPointsRetrieve )
  1829. {
  1830. return (eNFMGetPointError_InvalidValue); // error condition
  1831. }
  1832. // Check input parameters from context:
  1833. if( eCh_MAX <= pCtl->tableId || NULL == pCtl->pDataArray || 0 == pCtl->BufferCapacity )
  1834. {
  1835. return (eNFMGetPointError_InvalidValue); // error condition
  1836. }
  1837. size_t iPointRequested = 0;
  1838. bool bBreak = false;
  1839. int32_t rc = eNFMGetPointError_Success; // forward set to success code
  1840. // For each point:
  1841. for( (void)pCtl->nStartPoint;
  1842. ((void)pCtl->nNumberOfPoints, (!bBreak));
  1843. ++ pCtl->nStartPoint )
  1844. {
  1845. // Check if the point is loaded
  1846. if( 0 != pCtl->nNumberOfPoints )
  1847. {
  1848. // yes, check condition: all the points of segment have been processed?
  1849. if( pCtl->nStartPoint >= pCtl->nNumberOfPoints )
  1850. { // Check for end condition: out of points in segment or out of segments
  1851. bBreak = true;
  1852. (void)rc; // eNFMGetPointError_Success, end-of-data
  1853. pCtl->nNumberOfPoints = 0; // Reset points count: make to load the segment data at next iteration
  1854. pCtl->nStartPoint = 0; // Reset start point for next segment
  1855. break;
  1856. }
  1857. if( ! TableHandle.Get_Point(pCtl->nStartPoint, &pCtl->TablePoint))
  1858. {
  1859. return (eNFMGetPointError_DataError); // error condition: can not load segment data
  1860. }
  1861. }
  1862. else
  1863. {
  1864. // Invalid segment
  1865. return (eNFMGetPointError_DataError); // error condition: can not load segment data
  1866. }
  1867. // Fill the output array from the begining
  1868. // Note @pDataArray have at least one cell due to input checking
  1869. pCtl->pDataArray[ iPointRequested ].port1 = pCtl->TablePoint.port1;
  1870. pCtl->pDataArray[ iPointRequested ].port2 = pCtl->TablePoint.port2;
  1871. // To next point
  1872. iPointRequested++;
  1873. // Check for overflow: user buffer overflow
  1874. if( iPointRequested >= pCtl->BufferCapacity )
  1875. {
  1876. bBreak = true;
  1877. rc = eNFMGetPointError_OutOfBuffer; // warning
  1878. /* break; DO NOT BREAK, need to increment @nStartPoint */
  1879. }
  1880. // Check for end condition: user limit
  1881. if( iPointRequested >= *pnPointsRetrieve )
  1882. {
  1883. bBreak = true;
  1884. rc = eNFMGetPointError_Limit; // warning
  1885. /* break; DO NOT BREAK, need to increment @nStartPoint */;
  1886. }
  1887. }
  1888. (void)rc; // If no points are available, the @eNFMGetPointError_Success code is returned with *pnPointsRetrieve set to zero
  1889. *pnPointsRetrieve = iPointRequested; // write number of points read
  1890. return rc;
  1891. }
  1892. /*
  1893. /// --------------------------------------------------------------------------
  1894. ///
  1895. /// \brief createAbscissa
  1896. /// \details ������� ��� �������� ������������ �������� ��� ��������� ���������
  1897. /// \param[in] segment - QVector �� ��������� ��������� (Fmin, Fmax, NPoints)
  1898. /// \return ��������� �� ������ ������������ �������� � ���������� ������� � ��������� �����
  1899. /// �� ���� ��������� ��������� (RndAbscissa)
  1900. /// \note �������� � lambda ����� �� ���������� Hardware � ������������ ����� NfmKit.h,
  1901. /// �.�. ��� ��������� ����� ������ ������ ���������� ������.
  1902. /// \note ������� �����������, �� �������������� �� ������.
  1903. static auto createAbscissa( const QVector<Planar::VNA::Hardware::SegmentInfo>& segments )
  1904. {
  1905. // ���������� ����� �� ���� ���������:
  1906. size_t nPointsTotal = 0;
  1907. // ��������� ��� ������� ���������� �������� ���������� ������� ��������������:
  1908. // (��������� ������ ���������� ����� �� ���� ��������� ���������):
  1909. for ( auto& segment : segments )
  1910. {
  1911. // ���������� ����� � ��������:
  1912. size_t nPoints = static_cast<size_t>(segment.Points);
  1913. // ������������ ������ ���������� ����� � ���������
  1914. nPointsTotal += nPoints;
  1915. }
  1916. // �������� ������� ������������ ������� ��� ���� ��������� (����� ���������� �����):
  1917. Dsp::RndAbscissa* customAbscissa = new Dsp::RndAbscissa( nPointsTotal );
  1918. // �������� �������, ��������� ������� ������ �������������
  1919. // ����� � ��������: @abscissaPointIndex
  1920. size_t abscissaPointIndex = 0;
  1921. // ��������� ��� ������� ���������� �������� ���������� ������� ��������������:
  1922. // (���������� ������ � ���������� ��������� �����):
  1923. for ( auto& segment : segments )
  1924. {
  1925. // ���������� ����� � ��������:
  1926. size_t nPoints = static_cast<size_t>(segment.Points);
  1927. // �������� ��������� � ������� ��:
  1928. // - ��������� ������� ��������: @Fmin
  1929. auto Fmin = Unit(segment.Fmin).toSI().value();
  1930. // - �������� ������� ��������: @Fmax
  1931. auto Fmax = Unit(segment.Fmax).toSI().value();
  1932. // - ��� ����� ������ � ������� ��������: @Fstep
  1933. auto Fstep = (Fmax - Fmin) / nPoints;
  1934. // ���������� ��������� ����� �������:
  1935. for ( size_t p = 0; p < nPoints; ++p )
  1936. {
  1937. customAbscissa->setValue( abscissaPointIndex + p, Fmin + Fstep * p );
  1938. }
  1939. // �������� �������� ������� �� ���������� ����� � ������� ��������,
  1940. // ������������� � ���������� ��������:
  1941. abscissaPointIndex += nPoints;
  1942. }
  1943. return QSharedPointer<Dsp::RndAbscissa>(customAbscissa);
  1944. */
  1945. // MEM:TABL:FREQ:STAR?
  1946. // Reads the start frequency of the characterization table
  1947. bool NFMGetStartFreq( eChrz_t tableId, double * pStartFreq )
  1948. {
  1949. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  1950. if( NULL == pChrzHeader || NULL == pStartFreq )
  1951. return (false);
  1952. if( SWEEP_VERSION_LINEAR == pChrzHeader->Version )
  1953. {
  1954. double Fmin = 0.0;
  1955. // aligned access to the unaligned 'double' field
  1956. // memcpy( & Fmin,
  1957. // & pChrzHeader->Fmin_unaligned,
  1958. // sizeof(Fmin)
  1959. // ); // *pStartFreq = pChrzHeader->Fmin, fixed 28/08/18
  1960. Fmin = pChrzHeader->Fmin_unaligned;
  1961. *pStartFreq = Fmin;
  1962. return true;
  1963. }
  1964. else if( SWEEP_VERSION_SEGMENT == pChrzHeader->Version )
  1965. {
  1966. if( 0 < pChrzHeader->NSegm )
  1967. {
  1968. // double min = pChrzHeader->Segm[0].Fstart; // fixed 28/08/18
  1969. double Fstart_min = 0.0;
  1970. // aligned access to the unaligned 'double' field
  1971. // memcpy( & Fstart_min,
  1972. // & pChrzHeader->Segm[0].Fstart_unaligned,
  1973. // sizeof(Fstart_min)
  1974. // ); // min = pChrzHeader->Segm[0].Fstart
  1975. Fstart_min = pChrzHeader->Segm[0].Fstart_unaligned;
  1976. for( size_t n = 0; n < pChrzHeader->NSegm; ++n )
  1977. {
  1978. double Fstart_n = 0.0;
  1979. // aligned access to the unaligned 'double' field
  1980. // memcpy( & Fstart_n,
  1981. // & pChrzHeader->Segm[n].Fstart_unaligned,
  1982. // sizeof(Fstart_n)
  1983. // ); // min = pChrzHeader->Segm[n].Fstart, fixed 28/08/18
  1984. Fstart_n = pChrzHeader->Segm[n].Fstart_unaligned;
  1985. if( Fstart_n < Fstart_min )
  1986. {
  1987. Fstart_min = Fstart_n;
  1988. }
  1989. }
  1990. *pStartFreq = Fstart_min;
  1991. return true;
  1992. }
  1993. }
  1994. return false;
  1995. }
  1996. // MEM:TABL:FREQ:STOP?
  1997. // Reads the stop frequency of the characterization table
  1998. bool NFMGetStopFreq( eChrz_t tableId, double * pStopFreq )
  1999. {
  2000. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  2001. if( NULL == pChrzHeader || NULL == pStopFreq )
  2002. return (false);
  2003. if( SWEEP_VERSION_LINEAR == pChrzHeader->Version )
  2004. {
  2005. double Fmax = 0.0;
  2006. // aligned access to the unaligned 'double' field
  2007. // memcpy( & Fmax,
  2008. // & pChrzHeader->Fmax_unaligned,
  2009. // sizeof(Fmax)
  2010. // ); // *pStopFreq = pChrzHeader->Fmax;, fixed 28/08/18
  2011. Fmax = pChrzHeader->Fmax_unaligned;
  2012. *pStopFreq = Fmax;
  2013. return true;
  2014. }
  2015. else if( SWEEP_VERSION_SEGMENT == pChrzHeader->Version )
  2016. {
  2017. if( 0 < pChrzHeader->NSegm )
  2018. {
  2019. double Fstop_max = 0.0;
  2020. // aligned access to the unaligned 'double' field
  2021. // memcpy( & Fstop_max,
  2022. // & pChrzHeader->Segm[ pChrzHeader->NSegm - 1 ].Fstop_unaligned,
  2023. // sizeof(Fstop_max)
  2024. // ); // double max = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 ].Fstop;, fixed 28/08/18
  2025. Fstop_max = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 ].Fstop_unaligned;
  2026. for( size_t n = 0; n < pChrzHeader->NSegm; ++n )
  2027. {
  2028. double Fstop_n = 0.0;
  2029. // aligned access to the unaligned 'double' field
  2030. // memcpy( & Fstop_n,
  2031. // & pChrzHeader->Segm[ pChrzHeader->NSegm - 1 - n ].Fstop_unaligned,
  2032. // sizeof(Fstop_n)
  2033. // ); // max = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 - n ].Fstop;, fixed 28/08/18
  2034. Fstop_n = pChrzHeader->Segm[ pChrzHeader->NSegm - 1 - n ].Fstop_unaligned;
  2035. if( Fstop_n > Fstop_max )
  2036. {
  2037. Fstop_max = Fstop_n;
  2038. }
  2039. }
  2040. *pStopFreq = Fstop_max;
  2041. return true;
  2042. }
  2043. }
  2044. return false;
  2045. }
  2046. // MEM:TABL:TEMP?
  2047. // Reads the characterization temperature of characterization table
  2048. bool NFMGetChrzTemp( eChrz_t tableId, double * pTemperature )
  2049. {
  2050. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  2051. if( NULL == pChrzHeader || NULL == pTemperature )
  2052. return (false);
  2053. double temperature = 0.0;
  2054. // aligned access to the unaligned 'double' field
  2055. // memcpy( & temperature,
  2056. // & pChrzHeader->Temperature_unaligned,
  2057. // sizeof(temperature)
  2058. // ); // *pTemperature = pChrzHeader->Temperature;, fixed 28/08/18
  2059. temperature = pChrzHeader->Temperature_unaligned;
  2060. *pTemperature = temperature;
  2061. return true;
  2062. }
  2063. // MEM:TABL:CONN?
  2064. // Reads the connector type of the NFM
  2065. bool NFMGetConnectorType( ePortId_t portId, char * buffer, size_t size, size_t * bytes )
  2066. {
  2067. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( eChFactory, NULL, 0 );
  2068. if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
  2069. return (false);
  2070. uint16_t connector;
  2071. const char * pDescConnector = NULL;
  2072. size_t nCpy = 0;
  2073. switch( portId )
  2074. {
  2075. case ePortId_A:
  2076. connector = pChrzHeader->ConnectorA;
  2077. break;
  2078. case ePortId_B:
  2079. connector = pChrzHeader->ConnectorB;
  2080. break;
  2081. case ePortId_C:
  2082. connector = pChrzHeader->ConnectorC;
  2083. break;
  2084. case ePortId_D:
  2085. connector = pChrzHeader->ConnectorD;
  2086. break;
  2087. default: return (false);
  2088. }
  2089. if( connector >= sizeof(aConnectorsNames)/sizeof(aConnectorsNames[0]) )
  2090. {
  2091. pDescConnector = pcConnectorUndefined;
  2092. }
  2093. else
  2094. {
  2095. pDescConnector = aConnectorsNames[ connector ];
  2096. }
  2097. nCpy = static_StrCpyLimit(
  2098. (const char*)pDescConnector,
  2099. 0,
  2100. buffer,
  2101. size );
  2102. *bytes = nCpy;
  2103. return true;
  2104. }
  2105. // MEM:TABL:ADAP?
  2106. // Reads the adapter description of the NFM connector
  2107. bool NFMGetAdapterDesc( eChrz_t tableId, ePortId_t portId, char * buffer, size_t size, size_t * bytes )
  2108. {
  2109. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  2110. if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
  2111. return (false);
  2112. size_t nCpy = 0;
  2113. switch( portId )
  2114. {
  2115. case ePortId_A:
  2116. nCpy = static_StrCpyLimit(
  2117. (const char*)pChrzHeader->AdapterDescriptionA,
  2118. sizeof(pChrzHeader->AdapterDescriptionA),
  2119. buffer,
  2120. size );
  2121. break;
  2122. case ePortId_B:
  2123. nCpy = static_StrCpyLimit(
  2124. (const char*)pChrzHeader->AdapterDescriptionB,
  2125. sizeof(pChrzHeader->AdapterDescriptionB),
  2126. buffer,
  2127. size );
  2128. break;
  2129. case ePortId_C:
  2130. nCpy = static_StrCpyLimit(
  2131. (const char*)pChrzHeader->AdapterDescriptionC,
  2132. sizeof(pChrzHeader->AdapterDescriptionC),
  2133. buffer,
  2134. size );
  2135. break;
  2136. case ePortId_D:
  2137. nCpy = static_StrCpyLimit(
  2138. (const char*)pChrzHeader->AdapterDescriptionD,
  2139. sizeof(pChrzHeader->AdapterDescriptionD),
  2140. buffer,
  2141. size );
  2142. break;
  2143. default: return (false);
  2144. }
  2145. *bytes = nCpy;
  2146. return true;
  2147. }
  2148. // MEM:TABL:ANAL? ( =ANALyzer)
  2149. // Reads the analyzer type
  2150. bool NFMGetAnalyzer( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
  2151. {
  2152. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  2153. if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
  2154. return (false);
  2155. size_t nCpy = static_StrCpyLimit(
  2156. (const char*)pChrzHeader->Analyzer,
  2157. sizeof(pChrzHeader->Analyzer),
  2158. buffer,
  2159. size );
  2160. *bytes = nCpy;
  2161. return true;
  2162. }
  2163. // MEM:TABL:PLAC?
  2164. // Reads the place where the characterization had been created
  2165. bool NFMGetPlace( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
  2166. {
  2167. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  2168. if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
  2169. return (false);
  2170. size_t nCpy = static_StrCpyLimit(
  2171. (const char*)pChrzHeader->Location,
  2172. sizeof(pChrzHeader->Location),
  2173. buffer,
  2174. size );
  2175. *bytes = nCpy;
  2176. return true;
  2177. }
  2178. // MEM:TABL:OPER?
  2179. // Reads the the characterization operator's name
  2180. bool NFMGetOperator( eChrz_t tableId, char * buffer, size_t size, size_t * bytes )
  2181. {
  2182. const sEcalDataHeader_t * pChrzHeader = NFMClassExtended->private.methods.memory.getDataHeader( tableId, NULL, 0 );
  2183. if( NULL == pChrzHeader || NULL == buffer || size == 0 || NULL == bytes )
  2184. return (false);
  2185. size_t nCpy = static_StrCpyLimit(
  2186. (const char*)pChrzHeader->Operator,
  2187. sizeof(pChrzHeader->Operator),
  2188. buffer,
  2189. size );
  2190. *bytes = nCpy;
  2191. return true;
  2192. }
  2193. // MEM:TABL:THER:CORR:FREQ:START
  2194. // Reads the the start frequency of thermocompensation data
  2195. static bool NFMGetStartFreqThermo( double * pStartFreq )
  2196. {
  2197. const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
  2198. if( NULL == pTCompHeader || NULL == pStartFreq )
  2199. return (false);
  2200. double Fmin = 0.0;
  2201. // aligned access to the unaligned 'double' field
  2202. // memcpy( & Fmin,
  2203. // & pTCompHeader->Fmin_unaligned,
  2204. // sizeof(Fmin)
  2205. // ); // *pStartFreq = pTCompHeader->Fmin;, fixed 28/08/18
  2206. Fmin = pTCompHeader->Fmin_unaligned;
  2207. *pStartFreq = Fmin;
  2208. return true;
  2209. }
  2210. // MEM:TABL:THER:CORR:FREQ:STOP
  2211. // Reads the the stop frequency of thermocompensation data
  2212. static bool NFMGetStopFreqThermo( double * pStopFreq )
  2213. {
  2214. const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
  2215. if( NULL == pTCompHeader || NULL == pStopFreq )
  2216. return (false);
  2217. double Fmax = 0.0;
  2218. // aligned access to the unaligned 'double' field
  2219. // memcpy( & Fmax,
  2220. // & pTCompHeader->Fmax_unaligned,
  2221. // sizeof(Fmax)
  2222. // ); // *pStopFreq = pTCompHeader->Fmax;, fixed 28/08/18
  2223. Fmax = pTCompHeader->Fmax_unaligned;
  2224. *pStopFreq = Fmax;
  2225. return true;
  2226. }
  2227. // Reads the amount of points of thermocompensation data
  2228. static size_t NFMGetPointsThermo()
  2229. {
  2230. const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
  2231. if( NULL == pTCompHeader )
  2232. return (0);
  2233. return pTCompHeader->Points;
  2234. }
  2235. // MEM:TABL:THER:CORR:POIN?
  2236. // Reads the amount of points of thermocompensation data
  2237. static bool NFMGetPointsThermo_Safe( int16_t * count )
  2238. {
  2239. const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
  2240. if( NULL == pTCompHeader || NULL == count )
  2241. return false;
  2242. *count = pTCompHeader->Points;
  2243. return true;
  2244. }
  2245. // // MEM:TABL:THER:CORR:MAGN?
  2246. // // Reads the magnitude data points of the thermocompensation table
  2247. // static size_t NFMGetPointsMagnThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl )
  2248. // {
  2249. // if( portComb >= ePortComb_MAX
  2250. // || portComb == ePortComb_UNDEFINED
  2251. // || portState >= ePortStateId_MAX
  2252. // || portState == ePortStateId_UNDEFINED
  2253. // || NULL == pCtl
  2254. // || NULL == pCtl->in.pDataArray
  2255. // )
  2256. // {
  2257. // if( NULL != pCtl )
  2258. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2259. //
  2260. // return 0;
  2261. // }
  2262. //
  2263. // /* --- do it later: inside @getChrzTableHeader() call
  2264. // // Validate the combination of @portComb, @portState and
  2265. // // validate the @portComb and @portState itself.
  2266. // // Retrieve the table index (ordered index)
  2267. // size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
  2268. //
  2269. // if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  2270. // {
  2271. // // Invalid combination or value
  2272. // return 0;
  2273. // }
  2274. // */
  2275. //
  2276. // // Check the input parameter: @pCtl->in.nCount
  2277. // // For zero value: required to load the table header
  2278. // // During the loading the table header it is required:
  2279. // // - load the main thermocompensation header, check CRC
  2280. // // - retrieve number of points (@nPoints) from the header
  2281. // // - load the table header and check it's CRC
  2282. // // - retrieve the table address @TableAddress (for next operations)
  2283. // // - retrieve the @min and @max fields from the table header
  2284. // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  2285. // // - return (1) in case of success, or (0) on error
  2286. // if( 0 == pCtl->in.nCount )
  2287. // {
  2288. // // load thermocompensation main header
  2289. // // and check the CRC
  2290. // const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory
  2291. // .getTCompHeader( NULL, 0 );
  2292. //
  2293. // // check the TComp header: number of points
  2294. // if( NULL == pTCompHeader
  2295. // || 0 == pTCompHeader->Points )
  2296. // {
  2297. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVHDR;
  2298. // return (0);
  2299. // }
  2300. //
  2301. // // move @.Points into @nPoints
  2302. // // due to @pTCompHeader will be corrupted
  2303. // size_t nPoints = pTCompHeader->Points;
  2304. //
  2305. // sEcalTCompTableMagnHeader_t tableMicroHeader;
  2306. //
  2307. // // load the table base address
  2308. // // Note: the data by @pChrzHeader is not valid after this call,
  2309. // // due to the function uses the same internal buffer!
  2310. // size_t tableAddress = NFMClassExtended->private.methods.memory
  2311. // .getTCompMagnTableHeader( // load the table base address
  2312. // portComb, // for specified port combination
  2313. // portState, // for specified port state
  2314. // nPoints, // for retrieved number of points
  2315. // &tableMicroHeader, // and store the header into @tableMicroHeader
  2316. // &pCtl->svc.errCode // And fill up the error code
  2317. // );
  2318. //
  2319. // // check the result: @tableAddress
  2320. // // 0 - table corrupted or invalid port combination or port state.
  2321. // // but since the @portComb and @portState are validated above...
  2322. // // this result means only that the table is corrupted
  2323. // // non zero - this is the absolute address of the requested table.
  2324. // if( 0 == tableAddress )
  2325. // {
  2326. // (void)pCtl->svc.errCode;
  2327. // return 0; // error, sorry
  2328. // }
  2329. //
  2330. // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  2331. // pCtl->out.max = tableMicroHeader.MaxMagn;
  2332. // pCtl->out.min = tableMicroHeader.MinMagn;
  2333. // pCtl->out.TableAddress = tableAddress;
  2334. // pCtl->out.nPoints = nPoints;
  2335. //
  2336. // pCtl->svc.errCode = ERR_NFMGETPOINTS_NOERR;
  2337. // // success
  2338. // return 1;
  2339. // }
  2340. //
  2341. // // -----------------
  2342. // // User must call this function with (pCtl->in.nCount=0) first time
  2343. // // to initialize the @pCtl->out contents.
  2344. // // Here: 0 != pCtl->in.nCount
  2345. // // -----------------
  2346. //
  2347. // // Check the header data, loaded at previous step ( see pCtl->in.nCount == 0 )
  2348. // if( 0 == pCtl->out.nPoints // check the number of points in the table
  2349. // || 0 == pCtl->out.TableAddress ) // check the table base address
  2350. // {
  2351. // // error, invalid parameters
  2352. // // Call the function with (pCtl->in.nCount = 0) to load the header
  2353. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2354. //
  2355. // return 0;
  2356. // }
  2357. //
  2358. // // Check the input parameters
  2359. // if( pCtl->in.nCount > pCtl->out.nPoints // check the amount of requested points
  2360. // || pCtl->in.nStartPoint >= pCtl->out.nPoints // check the starting point
  2361. // || NULL == pCtl->in.pDataArray ) // check receiving data buffer
  2362. // {
  2363. // // error: invalid input parameters
  2364. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2365. //
  2366. // return 0;
  2367. // }
  2368. //
  2369. // return NFMClassExtended->private.methods.memory.getTCompMagnPoints( pCtl );
  2370. // }
  2371. // // MEM:TABL:THER:CORR:PHASE?
  2372. // // Reads the phase data points of the thermocompensation table
  2373. // static size_t NFMGetPointsPhaseThermo( ePortComb_t portComb, ePortStateId_t portState, sNFMGetPoints_t * pCtl )
  2374. // {
  2375. // if( portComb >= ePortComb_MAX
  2376. // || portComb == ePortComb_UNDEFINED
  2377. // || portState >= ePortStateId_MAX
  2378. // || portState == ePortStateId_UNDEFINED
  2379. // || NULL == pCtl
  2380. // || NULL == pCtl->in.pDataArray
  2381. // )
  2382. // {
  2383. // if( NULL != pCtl )
  2384. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2385. //
  2386. // return 0;
  2387. // }
  2388. //
  2389. // /* --- do it later: inside @getChrzTableHeader() call
  2390. // // Validate the combination of @portComb, @portState and
  2391. // // validate the @portComb and @portState itself.
  2392. // // Retrieve the table index (ordered index)
  2393. // size_t tableIdx = NFMClassExtended->private.methods.memory.getChrzTableIndex( portComb, portState );
  2394. //
  2395. // if( NFM_CHRZ_TABLEIDX_INVALID == tableIdx )
  2396. // {
  2397. // // Invalid combination or value
  2398. // return 0;
  2399. // }
  2400. // */
  2401. //
  2402. // // Check the input parameter: @pCtl->in.nCount
  2403. // // For zero value: required to load the table header
  2404. // // During the loading the table header it is required:
  2405. // // - load the main thermocompensation header, check CRC
  2406. // // - retrieve number of points (@nPoints) from the header
  2407. // // - load the table header and check it's CRC
  2408. // // - retrieve the table address @TableAddress (for next operations)
  2409. // // - retrieve the @min and @max fields from the table header
  2410. // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  2411. // // - return (1) in case of success, or (0) on error
  2412. // if( 0 == pCtl->in.nCount )
  2413. // {
  2414. // // load thermocompensation main header
  2415. // // and check the CRC
  2416. // const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory
  2417. // .getTCompHeader( NULL, 0 );
  2418. //
  2419. // // check the TComp header: number of points
  2420. // if( NULL == pTCompHeader
  2421. // || 0 == pTCompHeader->Points )
  2422. // {
  2423. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVHDR;
  2424. //
  2425. // return (0);
  2426. // }
  2427. //
  2428. // // move @.Points into @nPoints
  2429. // // due to @pTCompHeader will be corrupted
  2430. // size_t nPoints = pTCompHeader->Points;
  2431. //
  2432. // sEcalTCompTablePhaseHeader_t tableMicroHeader;
  2433. //
  2434. // // load the table base address
  2435. // // Note: the data by @pChrzHeader is not valid after this call,
  2436. // // due to the function uses the same internal buffer!
  2437. // size_t tableAddress = NFMClassExtended->private.methods.memory
  2438. // .getTCompPhaseTableHeader( // load the table base address
  2439. // portComb, // for specified port combination
  2440. // portState, // for specified port state
  2441. // nPoints, // for retrieved number of points
  2442. // &tableMicroHeader, // and store the header into @tableMicroHeader
  2443. // &pCtl->svc.errCode // And fill up the error code
  2444. // );
  2445. //
  2446. // // check the result: @tableAddress
  2447. // // 0 - table corrupted or invalid port combination or port state.
  2448. // // but since the @portComb and @portState are validated above...
  2449. // // this result means only that the table is corrupted
  2450. // // non zero - this is the absolute address of the requested table.
  2451. // if( 0 == tableAddress )
  2452. // {
  2453. // (void)pCtl->svc.errCode;
  2454. // return 0; // error, sorry
  2455. // }
  2456. //
  2457. // // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  2458. // pCtl->out.max = tableMicroHeader.MaxPhase;
  2459. // pCtl->out.min = tableMicroHeader.MinPhase;
  2460. // pCtl->out.TableAddress = tableAddress;
  2461. // pCtl->out.nPoints = nPoints;
  2462. //
  2463. // pCtl->svc.errCode = ERR_NFMGETPOINTS_NOERR;
  2464. //
  2465. // // success
  2466. // return 1;
  2467. // }
  2468. //
  2469. // // -----------------
  2470. // // User must call this function with (pCtl->in.nCount=0) first time
  2471. // // to initialize the @pCtl->out contents.
  2472. // // Here: 0 != pCtl->in.nCount
  2473. // // -----------------
  2474. //
  2475. // // Check the header data, loaded at previous step ( see pCtl->in.nCount == 0 )
  2476. // if( 0 == pCtl->out.nPoints // check the number of points in the table
  2477. // || 0 == pCtl->out.TableAddress ) // check the table base address
  2478. // {
  2479. // // error, invalid parameters
  2480. // // Call the function with (pCtl->in.nCount = 0) to load the header
  2481. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2482. //
  2483. // return 0;
  2484. // }
  2485. //
  2486. // // Check the input parameters
  2487. // if( pCtl->in.nCount > pCtl->out.nPoints // check the amount of requested points
  2488. // || pCtl->in.nStartPoint >= pCtl->out.nPoints // check the starting point
  2489. // || NULL == pCtl->in.pDataArray ) // check receiving data buffer
  2490. // {
  2491. // // error: invalid input parameters
  2492. // pCtl->svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2493. //
  2494. // return 0;
  2495. // }
  2496. //
  2497. // return NFMClassExtended->private.methods.memory.getTCompPhasePoints( pCtl );
  2498. // }
  2499. // MEM:TABL:THERmo:CORRection:MAGNitude?
  2500. // NFMGetPointsThermoMagn_Begin
  2501. // Prepares the context before reading the data points of the thermocompensation table of magnitudes
  2502. // This method is designed to replace the obsolete @NFMGetPointsMagnThermo
  2503. // Parameters:
  2504. // @portComb - port combination to request (NFM path);
  2505. // @portState - port state to request (S-parameter);
  2506. // @pDataBuffer - output data buffer;
  2507. // @szDataBuffer - output data buffer capacity;
  2508. // @xCtl - the control context to initialize;
  2509. // Returns: 0 in case error, or number of points in case success.
  2510. size_t NFMGetPointsThermoMagn_Begin( ePortComb_t portComb, ePortStateId_t portState,
  2511. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  2512. xNFMGetPointsSimplified_t * xCtl )
  2513. {
  2514. sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
  2515. if( NULL == pCtl )
  2516. {
  2517. return eNFMGetPointError_InvalidValue;
  2518. }
  2519. pCtl->isThermoPhase = 0;
  2520. return NFMGetPointsThermo_Begin( portComb, portState, pDataBuffer, szDataBuffer, pCtl );
  2521. }
  2522. // MEM:TABL:THERmo:CORRection:PHASe?
  2523. // NFMGetPointsThermoPhase_Begin
  2524. // Prepares the context before reading the data points of the thermocompensation table of magnitudes/phases
  2525. // This method is designed to replace the obsolete NFMGetPointsPhaseThermo.
  2526. // Parameters:
  2527. // @portComb - port combination to request (NFM path);
  2528. // @portState - port state to request (S-parameter);
  2529. // @pDataBuffer - output data buffer;
  2530. // @szDataBuffer - output data buffer capacity;
  2531. // @xCtl - the control context to initialize;
  2532. // Returns: 0 in case error, or number of points in case success.
  2533. size_t NFMGetPointsThermoPhase_Begin( ePortComb_t portComb, ePortStateId_t portState,
  2534. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  2535. xNFMGetPointsSimplified_t * xCtl )
  2536. {
  2537. sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
  2538. if( NULL == pCtl )
  2539. {
  2540. return eNFMGetPointError_InvalidValue;
  2541. }
  2542. pCtl->isThermoPhase = 1;
  2543. return NFMGetPointsThermo_Begin( portComb, portState, pDataBuffer, szDataBuffer, pCtl );
  2544. }
  2545. // MEM:TABL:THERmo:CORRection:MAGNitude?
  2546. // MEM:TABL:THERmo:CORRection:PHASe?
  2547. // NFMGetPointsThermo_Begin
  2548. // Prepares the context before reading the data points of the thermocompensation table of magnitudes/phases
  2549. // This method is designed to replace the obsolete @NFMGetPointsMagnThermo/NFMGetPointsPhaseThermo.
  2550. // Parameters:
  2551. // @portComb - port combination to request (NFM path);
  2552. // @portState - port state to request (S-parameter);
  2553. // @pDataBuffer - output data buffer;
  2554. // @szDataBuffer - output data buffer capacity;
  2555. // @xCtl - the control context to initialize;
  2556. // Returns: 0 in case error, or number of points in case success.
  2557. static size_t NFMGetPointsThermo_Begin( ePortComb_t portComb, ePortStateId_t portState,
  2558. sNFMChrzPoint_t * pDataBuffer, size_t szDataBuffer,
  2559. sNFMGetPointsSimplified_t * pCtl )
  2560. {
  2561. my_assert( pCtl ); // see @NFMGetPointsThermoMagn_Begin/NFMGetPointsThermoPhase_Begin
  2562. // Check if arguments are valid in general
  2563. if( ( portComb >= ePortComb_MAX )
  2564. || ( portState >= ePortStateId_MAX )
  2565. || ( portComb == ePortComb_UNDEFINED )
  2566. || ( 0 == szDataBuffer ) )
  2567. {
  2568. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2569. return 0;
  2570. }
  2571. // Check if arguments are valid particularly for this device
  2572. if( ! NFMClassExtended->public.methods.checkTableParams( portComb, portState ) )
  2573. {
  2574. // Invalid combination or value
  2575. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2576. return 0;
  2577. }
  2578. // Fill input parameters:
  2579. pCtl->BufferCapacity = szDataBuffer; // - output buffer capacity
  2580. pCtl->sectorId = eChFactory; // - don't care for Thermocompensation
  2581. pCtl->portComb = portComb; // - requested port combination (nfm path)
  2582. pCtl->portState = portState; // - requested state (S-parameter)
  2583. pCtl->intCtx.in.nCount = szDataBuffer; // - number of points to get
  2584. pCtl->intCtx.in.nStartPoint = 0; // - start point
  2585. pCtl->intCtx.in.pDataArray = pDataBuffer; // - output buffer
  2586. // During the loading the table header it is required:
  2587. // - load the main characterization header, check CRC
  2588. // - retrieve number of points (@nPoints) from the header for specified @sectorId
  2589. // - load the table header and check it's CRC
  2590. // - retrieve the table address @TableAddress (for next operations)
  2591. // - retrieve the @min and @max fields from the table header
  2592. // - store @min, @max, @TableAddress, @nPoints into @pCtl.intCtx.out
  2593. // load thermocompensation main header
  2594. // and check the CRC
  2595. const sEcalTCompHeader_t * pTCompHeader = NFMClassExtended->private.methods.memory.getTCompHeader( NULL, 0 );
  2596. // check the TComp header: number of points
  2597. if( NULL == pTCompHeader
  2598. || 0 == pTCompHeader->Points )
  2599. {
  2600. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVHDR;
  2601. return (0);
  2602. }
  2603. // move @.Points into @nPoints
  2604. // due to @pTCompHeader will be corrupted
  2605. size_t nPoints = pTCompHeader->Points;
  2606. union
  2607. {
  2608. sEcalTCompTableMagnHeader_t tableMicroHeaderMagn;
  2609. sEcalTCompTablePhaseHeader_t tableMicroHeaderPhase;
  2610. };
  2611. // load the table base address
  2612. // Note: the data by @pChrzHeader is not valid after this call,
  2613. // due to the function uses the same internal buffer!
  2614. size_t tableAddress = 0;
  2615. if( 0 == pCtl->isThermoPhase )
  2616. tableAddress = NFMClassExtended->private.methods.memory
  2617. .getTCompMagnTableHeader( // load the table base address: magnitude
  2618. portComb, // for specified port combination
  2619. portState, // for specified port state
  2620. nPoints, // for retrieved number of points
  2621. &tableMicroHeaderMagn, // and store the header into @tableMicroHeaderMagn
  2622. &pCtl->intCtx.svc.errCode // And fill up the error code
  2623. );
  2624. else
  2625. tableAddress = NFMClassExtended->private.methods.memory
  2626. .getTCompPhaseTableHeader( // load the table base address: phase
  2627. portComb, // for specified port combination
  2628. portState, // for specified port state
  2629. nPoints, // for retrieved number of points
  2630. &tableMicroHeaderPhase, // and store the header into @tableMicroHeaderPhase
  2631. &pCtl->intCtx.svc.errCode // And fill up the error code
  2632. );
  2633. // check the result: @tableAddress
  2634. // 0 - table corrupted or invalid port combination or port state.
  2635. // but since the @portComb and @portState are validated above...
  2636. // this result means only that the table is corrupted
  2637. // non zero - this is the absolute address of the requested table.
  2638. if( 0 == tableAddress )
  2639. {
  2640. (void)pCtl->intCtx.svc.errCode;
  2641. return 0; // error, sorry
  2642. }
  2643. // - store @min, @max, @TableAddress, @nPoints into @pCtl.out
  2644. if( 0 == pCtl->isThermoPhase )
  2645. {
  2646. pCtl->intCtx.out.max = tableMicroHeaderMagn.MaxMagn;
  2647. pCtl->intCtx.out.min = tableMicroHeaderMagn.MinMagn;
  2648. }
  2649. else
  2650. {
  2651. pCtl->intCtx.out.max = tableMicroHeaderPhase.MaxPhase;
  2652. pCtl->intCtx.out.min = tableMicroHeaderPhase.MinPhase;
  2653. }
  2654. pCtl->intCtx.out.TableAddress = tableAddress;
  2655. pCtl->intCtx.out.nPoints = nPoints;
  2656. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
  2657. // success
  2658. return nPoints;
  2659. }
  2660. // MEM:TABL:THER:CORR:MAGN?
  2661. // @NFMGetPointsThermoMagn_Continue
  2662. // Uses already prepared context and reads magnutude data points of the thermocompensation
  2663. // table to the top of specified buffer (see @NFMGetPointsThermo_Begin).
  2664. // This method is designed to replace the obsolete @NFMGetPointsMagnThermo.
  2665. // Parameters:
  2666. // @xCtl - control context prepared by previous NFMGetPointsThermo_Begin call
  2667. // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
  2668. //
  2669. // Returns:
  2670. // - eNFMGetPointError_DataError: error, can not load data;
  2671. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  2672. // - eNFMGetPointError_Success: success, all the points from the table have been read;
  2673. // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
  2674. // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
  2675. int32_t NFMGetPointsThermoMagn_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve )
  2676. {
  2677. sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
  2678. if( NULL == pCtl || NULL == pnPointsRetrieve || 0 != pCtl->isThermoPhase )
  2679. {
  2680. return eNFMGetPointError_InvalidValue;
  2681. }
  2682. return NFMGetPointsThermo_Continue( pCtl, pnPointsRetrieve );
  2683. }
  2684. // MEM:TABL:THER:CORR:PHAS?
  2685. // @NFMGetPointsThermoPhase_Continue
  2686. // Uses already prepared context and reads phase data points of the thermocompensation
  2687. // table to the top of specified buffer (see @NFMGetPointsThermo_Begin).
  2688. // This method is designed to replace the obsolete @NFMGetPointsPhaseThermo.
  2689. // Parameters:
  2690. // @xCtl - control context prepared by previous NFMGetPointsThermo_Begin call
  2691. // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
  2692. //
  2693. // Returns:
  2694. // - eNFMGetPointError_DataError: error, can not load data;
  2695. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  2696. // - eNFMGetPointError_Success: success, all the points from the table have been read;
  2697. // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
  2698. // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
  2699. int32_t NFMGetPointsThermoPhase_Continue( xNFMGetPointsSimplified_t * xCtl, size_t * pnPointsRetrieve )
  2700. {
  2701. sNFMGetPointsSimplified_t * pCtl = (sNFMGetPointsSimplified_t*)xCtl;
  2702. if( NULL == pCtl || NULL == pnPointsRetrieve || 0 == pCtl->isThermoPhase )
  2703. {
  2704. return eNFMGetPointError_InvalidValue;
  2705. }
  2706. return NFMGetPointsThermo_Continue( pCtl, pnPointsRetrieve );
  2707. }
  2708. // MEM:TABL:THER:CORR:MAGN?
  2709. // MEM:TABL:THER:CORR:PHAS?
  2710. // @NFMGetPointsThermo_Continue
  2711. // Uses already prepared context and reads magnutude/phase data points of the thermocompensation
  2712. // table to the top of specified buffer (see @NFMGetPointsThermo_Begin).
  2713. // This method is designed to replace the obsolete @NFMGetPointsMagnThermo/NFMGetPointsPhaseThermo.
  2714. // Parameters:
  2715. // @xCtl - control context prepared by previous NFMGetPointsThermo_Begin call
  2716. // @pnPointsRetrieve - IN/OUT; IN: specifies a number of points to retrieve; OUT: stores the value of actually read points;
  2717. //
  2718. // Returns:
  2719. // - eNFMGetPointError_DataError: error, can not load data;
  2720. // - eNFMGetPointError_InvalidValue: error, invalid parameters;
  2721. // - eNFMGetPointError_Success: success, all the points from the table have been read;
  2722. // - eNFMGetPointError_OutOfBuffer: warning, points have been read, but it is required to continue because user buffer ran out;
  2723. // - eNFMGetPointError_Limit: warning, points have been read, but the caller specified less points to read than actually available;
  2724. static int32_t NFMGetPointsThermo_Continue( sNFMGetPointsSimplified_t * pCtl, size_t * pnPointsRetrieve )
  2725. {
  2726. my_assert( pCtl ); // see @NFMGetPointsThermoMagn_Continue, @NFMGetPointsThermoPhase_Continue
  2727. my_assert( pnPointsRetrieve ); // see @NFMGetPointsThermoMagn_Continue, @NFMGetPointsThermoPhase_Continue
  2728. // Check if arguments are valid in general
  2729. if( ( pCtl->sectorId != eChFactory ) // Formal checking: actually it is does not matter what value is specified here
  2730. || ( pCtl->portComb >= ePortComb_MAX )
  2731. || ( pCtl->portState >= ePortStateId_MAX )
  2732. || ( pCtl->portComb == ePortComb_UNDEFINED )
  2733. || ( 0 == pCtl->BufferCapacity )
  2734. || ( 0 == pCtl->intCtx.out.nPoints )
  2735. || ( 0 == pCtl->intCtx.out.TableAddress )
  2736. || ( NULL == pCtl->intCtx.in.pDataArray ) )
  2737. {
  2738. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_INVAL;
  2739. return eNFMGetPointError_InvalidValue;
  2740. }
  2741. // check ranges
  2742. if( pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints;
  2743. if( pCtl->intCtx.in.nStartPoint >= pCtl->intCtx.out.nPoints ) pCtl->intCtx.in.nStartPoint = pCtl->intCtx.out.nPoints; // end-of-points
  2744. if( pCtl->intCtx.in.nStartPoint +
  2745. pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
  2746. {
  2747. pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
  2748. }
  2749. // check for end condition
  2750. if( 0 == pCtl->intCtx.in.nCount
  2751. || pCtl->intCtx.in.nStartPoint == pCtl->intCtx.out.nPoints )
  2752. {
  2753. *pnPointsRetrieve = 0; // number of points read is zero
  2754. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_NOERR;
  2755. return eNFMGetPointError_Success;
  2756. }
  2757. int32_t success_rc = eNFMGetPointError_Success;
  2758. // check buffer capacity range
  2759. if( pCtl->intCtx.in.nCount > pCtl->BufferCapacity )
  2760. {
  2761. pCtl->intCtx.in.nCount = pCtl->BufferCapacity;
  2762. success_rc = eNFMGetPointError_OutOfBuffer; // out of buffer, the number of points is limited
  2763. }
  2764. else
  2765. if( pCtl->intCtx.in.nStartPoint + pCtl->intCtx.in.nCount < pCtl->intCtx.out.nPoints )
  2766. {
  2767. success_rc = eNFMGetPointError_Limit; // number of points is limited by user
  2768. }
  2769. pCtl->intCtx.svc.errCode = ERR_NFMGETPOINTS_IO;
  2770. size_t nRead = 0;
  2771. if( 0 == pCtl->isThermoPhase )
  2772. nRead = NFMClassExtended->private.methods.memory.getTCompMagnPoints( &pCtl->intCtx );
  2773. else
  2774. nRead = NFMClassExtended->private.methods.memory.getTCompPhasePoints( &pCtl->intCtx );
  2775. // check for error condition
  2776. if( nRead == 0 )
  2777. {
  2778. *pnPointsRetrieve = 0; // number of points read is zero
  2779. (void)pCtl->intCtx.svc.errCode;
  2780. return eNFMGetPointError_DataError;
  2781. }
  2782. pCtl->intCtx.in.nStartPoint += nRead; // increment start point for next call
  2783. // check range
  2784. if( pCtl->intCtx.in.nStartPoint +
  2785. pCtl->intCtx.in.nCount > pCtl->intCtx.out.nPoints )
  2786. {
  2787. pCtl->intCtx.in.nCount = pCtl->intCtx.out.nPoints - pCtl->intCtx.in.nStartPoint;
  2788. }
  2789. *pnPointsRetrieve = nRead; // number of points read
  2790. return success_rc;
  2791. }
  2792. static bool NFMGetInterface( eNFMUSBInterface_t * pCurrentIface )
  2793. {
  2794. if( NULL != pCurrentIface )
  2795. {
  2796. if( sizeof(sNFMSettingsBlockCrc_t) == NFMClassExtended->private.methods.memory.getSettingsBlockSize() )
  2797. {
  2798. sNFMSettingsBlockCrc_t sSettingsBlock;
  2799. if( NFMClassExtended->private.methods.memory.getSettingsBlock( (uint8_t*)&sSettingsBlock,
  2800. 0,
  2801. sizeof(sSettingsBlock) ) )
  2802. {
  2803. *pCurrentIface = eNFM_IfaceUSBVendor;
  2804. if( sSettingsBlock.settings.rawBytes[0] == 'U' )
  2805. if( sSettingsBlock.settings.rawBytes[1] == 'S' )
  2806. if( sSettingsBlock.settings.rawBytes[2] == 'B' )
  2807. if( sSettingsBlock.settings.rawBytes[3] == 'T' )
  2808. if( sSettingsBlock.settings.rawBytes[4] == 'M' )
  2809. if( sSettingsBlock.settings.rawBytes[5] == 'C' )
  2810. if( sSettingsBlock.settings.rawBytes[6] == '!' )
  2811. if( sSettingsBlock.settings.rawBytes[7] == 0 )
  2812. *pCurrentIface = eNFM_IfaceUSBTMC;
  2813. return true;
  2814. }
  2815. }
  2816. }
  2817. return false;
  2818. }
  2819. static bool NFMSetInterface( eNFMUSBInterface_t activateInterface )
  2820. {
  2821. if( (activateInterface == eNFM_IfaceUSBVendor)
  2822. ||(activateInterface == eNFM_IfaceUSBTMC) )
  2823. {
  2824. if( sizeof(sNFMSettingsBlockCrc_t) == NFMClassExtended->private.methods.memory.getSettingsBlockSize() )
  2825. {
  2826. sNFMSettingsBlockCrc_t sSettingsBlock;
  2827. if( NFMClassExtended->private.methods.memory.getSettingsBlock( (uint8_t*)&sSettingsBlock,
  2828. 0,
  2829. sizeof(sSettingsBlock) ) )
  2830. {
  2831. if( eNFM_IfaceUSBTMC == activateInterface )
  2832. {
  2833. sSettingsBlock.settings.rawBytes[0] = 'U';
  2834. sSettingsBlock.settings.rawBytes[1] = 'S';
  2835. sSettingsBlock.settings.rawBytes[2] = 'B';
  2836. sSettingsBlock.settings.rawBytes[3] = 'T';
  2837. sSettingsBlock.settings.rawBytes[4] = 'M';
  2838. sSettingsBlock.settings.rawBytes[5] = 'C';
  2839. sSettingsBlock.settings.rawBytes[6] = '!';
  2840. sSettingsBlock.settings.rawBytes[7] = 0 ;
  2841. }
  2842. else
  2843. {
  2844. sSettingsBlock.settings.rawBytes[0] = 'V';
  2845. sSettingsBlock.settings.rawBytes[1] = 'E';
  2846. sSettingsBlock.settings.rawBytes[2] = 'N';
  2847. sSettingsBlock.settings.rawBytes[3] = 'D';
  2848. sSettingsBlock.settings.rawBytes[4] = 'O';
  2849. sSettingsBlock.settings.rawBytes[5] = 'R';
  2850. sSettingsBlock.settings.rawBytes[6] = '!';
  2851. sSettingsBlock.settings.rawBytes[7] = 0 ;
  2852. }
  2853. TCRC crc = ICRC32;
  2854. crc = CRC32( crc, (uint8_t *)&sSettingsBlock.settings, sizeof(sSettingsBlock.settings));
  2855. sSettingsBlock.CRCValue = crc;
  2856. return NFMClassExtended->private.methods.memory.setSettingsBlock( (uint8_t*)&sSettingsBlock,
  2857. 0,
  2858. sizeof(sSettingsBlock) );
  2859. }
  2860. }
  2861. }
  2862. return false;
  2863. }
  2864. static uint16_t* GetPort(uint16_t portNumber)
  2865. {
  2866. switch(portNumber)
  2867. {
  2868. case eNFMPort_1:
  2869. return &NFMClassExtended->public.properties.inputPortStates[ePort_1];
  2870. case eNFMPort_2:
  2871. return &NFMClassExtended->public.properties.inputPortStates[ePort_2];
  2872. default:
  2873. return 0;
  2874. }
  2875. }
  2876. static uint16_t NFMGetPortState (uint16_t portNumber)
  2877. {
  2878. return *GetPort(portNumber);
  2879. }
  2880. static bool NFMSetPortState (uint16_t portNumber, uint16_t portState)
  2881. {
  2882. uint16_t* port = GetPort(portNumber);
  2883. if(port == NULL)
  2884. return false;
  2885. *port = portState;
  2886. return true;
  2887. }
  2888. #endif