scpi_core.h 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef SCPI_CORE_H
  2. #define SCPI_CORE_H
  3. #include <stdbool.h>
  4. #include "my_assert.h"
  5. #include "core/main.h" // _snprintf
  6. #include "app/fseq/fseq.h"
  7. #include "app/scpi/scpi_tools.h"
  8. #include "app/scpi/scpi_base.h" // eScpiStatus_t
  9. // ==============================================================================================
  10. // typedef struct
  11. // {
  12. // eScpiStatus_t ( * fInit)();
  13. // eScpiStatus_t ( * fWrite)();
  14. // eScpiStatus_t ( * fRead)();
  15. // eScpiStatus_t ( * fClear)();
  16. // eScpiStatus_t ( * fDeInit)();
  17. // }
  18. // sSCPIErrorQueueIface_t;
  19. // ==============================================================================================
  20. #define SCPILIB_ERROR_SUCCESS (0)
  21. #define SCPILIB_ERROR_BUFFER_OVERFLOW (-1)
  22. // ==============================================================================================
  23. typedef struct
  24. {
  25. eScpiStatus_t ( * fInit)( );
  26. eScpiStatus_t ( * fReset)();
  27. eScpiStatus_t ( * fNewTransfer)();
  28. eScpiStatus_t ( * fWrite)( const uint8_t * pData, size_t nDataLen, bool bEndOfMessage, bool bNewTransfer );
  29. eScpiStatus_t ( * fRead)( uint8_t * pBuffer, size_t nBufferLen, size_t *pnBytesOut, bool *pEOM );
  30. eScpiStatus_t ( * fNotificationRead)( uint8_t * pBuffer, size_t nBufferLen, size_t *pnBytesOut, uint8_t * pSTB );
  31. // @fError
  32. // Error notification from USBTMC level.
  33. // @error - error id, see @SCPILIB_ERROR_* macro group
  34. // @errorCtx - error dependent context, optional;
  35. // Return:
  36. // - eScpiStatus_success: error processed successfully
  37. // - eScpiStatus_failed: unrecoveral error, need to process it on USBTMC level.
  38. eScpiStatus_t ( * fError)( int32_t error, const void * errorCtx );
  39. eScpiStatus_t ( * fDeInit)();
  40. }
  41. sSCPILibHandle_t;
  42. // ==============================================================================================
  43. // @fsq_GetPrivateCtxRef
  44. // Get access to the state's private context by pointer
  45. // @this - the state entry, passed into main state function, or
  46. // ... entry-/leave- routines.
  47. // Returns: the state private context pointer that represented by the
  48. // @ctx_ref field in @sScpiParserStateEntry_t structure.
  49. void * fsq_GetPrivateCtxRef( const struct fFSeqEntry_t * this );
  50. // ==============================================================================================
  51. // @fsq_RaiseErrorEx
  52. // Generate internal error event to place it into SCPI Error Log
  53. // @scpiError - SCPI error code
  54. // @msgHandler - optional null-terminated string prefix, if exist, the function also adds additional prefix with error number
  55. // @msgDescription - optional string message with @msgDescLength length
  56. // @msgDescriptionEnd - end of optional message string, is used to determine the string length (@msgDescription)
  57. // @msgDescriptionEx - extended optional string message with @msgDescLength length
  58. // @msgDescriptionEndEx - end of extended optional message string, is used to determine the string length (@msgDescriptionEx)
  59. void fsq_RaiseErrorEx( int scpiError, const char * msgHeader, const char * msgDescription, const char * msgDescriptionEnd,
  60. const char * msgDescriptionEx, const char * msgDescriptionEndEx );
  61. // -----------------------------------------------------------
  62. // @fsq_RaiseError
  63. // Generate internal error event to place it into SCPI Error Log
  64. // @scpiError - SCPI error code
  65. // @msgHandler - optional null-terminated string prefix, if exist, the function also adds additional prefix with error number
  66. // @msgDescription - optional string message with @msgDescLength length
  67. // @msgDescriptionEnd - end of optional message string, is used to determine the string length (@msgDescription)
  68. void fsq_RaiseError( int scpiError, const char * msgHeader, const char * msgDescription, const char * msgDescriptionEnd );
  69. // -----------------------------------------------------------
  70. // @scpi_WriteChunkOutput
  71. // Write data to output buffer
  72. // @src - pointer to data to be written
  73. // @length - length of data @src
  74. // Returns: a number of bytes copied (may be less than @length)
  75. int32_t scpi_WriteChunkOutput( const void * src, size_t length );
  76. // @scpi_WriteCharOutput
  77. // Write a character to output buffer
  78. // @ch - character to be written
  79. // Returns: 1 if a character successfully placed into the buffer, or 0 otherwise
  80. int32_t scpi_WriteCharOutput( uint8_t ch );
  81. // -----------------------------------------------------------
  82. // @scpi_UpdateMessageAvailable
  83. // Updates the message available status, MAV
  84. // "6.1.10.2.1 Message Available Message (MAV)", [1]
  85. void scpi_UpdateMessageAvailable();
  86. // ==============================================================================================
  87. extern const sSCPILibHandle_t sSCPILibHandle;
  88. #endif