idn.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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",
  60. NFMClass->properties.manufacturerId,
  61. NFMClass->properties.modelName,
  62. NFMClass->properties.serialNumber,
  63. NFMClass->properties.firmwareId );
  64. }
  65. // Since @done flag is set, this dispatcher shall not be called anymore.
  66. // Since this handler is implemented as a single-state automat, there no
  67. // ... other states to go to:
  68. (void)nextstate;
  69. // modify current postion index:
  70. SCPI_RESPONSE_HELPER( common_ctx, common_ctx->IDN.idx );
  71. }
  72. break;
  73. }
  74. return nextstate;
  75. }