idn.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <stdio.h>
  2. #define SCPI_ARGS_N 0
  3. #include "app/scpi/scpi_handler.h"
  4. #include "app/scpi/commandHandlers/idn.h"
  5. #include "app/nfm/nfm_base.h"
  6. // =================================================================================
  7. // @fsqvbl_CommandHandlerIDN
  8. // State's virtual table
  9. static void fsqe_CommandHandlerIDN( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  10. static void fsql_CommandHandlerIDN( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx );
  11. static const struct fFSeqEntry_t * fsqf_CommandHandlerIDN( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx, const struct fFSeqEntry_t * * pDeferredNext );
  12. const fFSeqVTable_t fsqvbl_CommandHandlerIDN =
  13. {
  14. .f = fsqf_CommandHandlerIDN,
  15. .enter = fsqe_CommandHandlerIDN,
  16. .leave = fsql_CommandHandlerIDN
  17. };
  18. static void fsqe_CommandHandlerIDN( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  19. {
  20. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  21. common_ctx->IDN.idx = 0; // reset position
  22. SCPI_PARSE_ARGUMENTS( common_ctx ); (void)common_ctx->argsParserStatus; // status is modified
  23. }
  24. static void fsql_CommandHandlerIDN( const struct fFSeqEntry_t * this, tFSeqCtx_t ctx )
  25. {
  26. }
  27. static const struct fFSeqEntry_t * fsqf_CommandHandlerIDN( const struct fFSeqEntry_t * this,
  28. tFSeqCtx_t ctx,
  29. const struct fFSeqEntry_t * * pDeferredNext )
  30. {
  31. const fFSeqEntry_t * nextstate = NULL;
  32. sProcessProgramDataCommonContext_t * common_ctx = ctx;
  33. switch( common_ctx->event )
  34. {
  35. case eProgramData_Event_Write:
  36. {
  37. if( ! common_ctx->isQuery )
  38. {
  39. common_ctx->status = eProgramDataSyntaxError; // invalid command header type: COMMAND not supported
  40. }
  41. else if( eScpiStatus_success != common_ctx->argsParserStatus ) // check argument parser status
  42. {
  43. common_ctx->status = eProgramDataArgumentSyntax; // parameter syntax error, caller should generate error message
  44. }
  45. else
  46. {
  47. common_ctx->status = eProgramDataNeedRead; // request processed, wait for reading...
  48. (void)nextstate; // stay in this state
  49. }
  50. }
  51. break;
  52. case eProgramData_Event_Read:
  53. {
  54. // @idx - current position of the source data to be outputed
  55. if( 0 == common_ctx->IDN.idx )
  56. {
  57. memset( common_ctx->tempBuffer, 0, sizeof(common_ctx->tempBuffer) );
  58. // first call: prepare buffer
  59. _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%s,%s,%s,%s""%s",
  60. NFMClass->properties.manufacturerId,
  61. NFMClass->properties.modelName,
  62. NFMClass->properties.serialNumber,
  63. NFMClass->properties.firmwareId,
  64. "\n" );
  65. }
  66. // Since @done flag is set, this dispatcher shall not be called anymore.
  67. // Since this handler is implemented as a single-state automat, there no
  68. // ... other states to go to:
  69. (void)nextstate;
  70. // modify current postion index:
  71. SCPI_RESPONSE_HELPER( common_ctx, common_ctx->IDN.idx );
  72. }
  73. break;
  74. }
  75. return nextstate;
  76. }