Advertisement
Guest User

Untitled

a guest
Mar 27th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. /* frameHandler.h
  2.  *
  3.  * Arduino library to read from Victron devices using VE.Direct protocol.
  4.  * Derived from Victron framehandler reference implementation.
  5.  *
  6.  * 2020.05.05 - 0.2 - initial release
  7.  * 2021.02.23 - 0.3 - change frameLen to 22 per VE.Direct Protocol version 3.30
  8.  *
  9.  */
  10.  
  11. #ifndef FRAMEHANDLER_H_
  12. #define FRAMEHANDLER_H_
  13.  
  14. const byte frameLen = 22;                       // VE.Direct Protocol: max frame size is 22
  15. const byte nameLen = 9;                         // VE.Direct Protocol: max name size is 9 including /0
  16. const byte valueLen = 33;                       // VE.Direct Protocol: max value size is 33 including /0
  17. const byte buffLen = 40;                        // Maximum number of lines possible from the device. Current protocol shows this to be the BMV700 at 33 lines.
  18.  
  19.  
  20. class VeDirectFrameHandler {
  21.  
  22. public:
  23.     VeDirectFrameHandler();
  24.     void rxData(uint8_t inbyte);                // byte of serial data to be passed by the application
  25.     void callback(std::function<void()> func);  // callback function
  26.     std::function<void()> requestCallback;
  27.  
  28.     char veName[buffLen][nameLen] = { };        // public buffer for received names
  29.     char veValue[buffLen][valueLen] = { };      // public buffer for received values
  30.  
  31.     int frameIndex;                             // which line of the frame are we on
  32.     int veEnd;                                  // current size (end) of the public buffer
  33.     int veError = 1;                            //error flag for ve
  34.  
  35. private:
  36.     //bool mStop;                               // not sure what Victron uses this for, not using
  37.  
  38.     enum States {                               // state machine
  39.         IDLE,
  40.         RECORD_BEGIN,
  41.         RECORD_NAME,
  42.         RECORD_VALUE,
  43.         CHECKSUM,
  44.         RECORD_HEX
  45.     };
  46.  
  47.     int mState;                                 // current state
  48.  
  49.     uint8_t mChecksum;                          // checksum value
  50.  
  51.     char * mTextPointer;                        // pointer to the private buffer we're writing to, name or value
  52.  
  53.     char mName[9];                              // buffer for the field name
  54.     char mValue[33];                            // buffer for the field value
  55.     char tempName[frameLen][nameLen];           // private buffer for received names
  56.     char tempValue[frameLen][valueLen];         // private buffer for received values
  57.  
  58.     void textRxEvent(char *, char *);
  59.     void frameEndEvent(bool);
  60.     void logE(char *, char *);
  61.     bool hexRxEvent(uint8_t);
  62. };
  63.  
  64. #endif // FRAMEHANDLER_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement