essential classes for arianna station protocol
SnHeaderFrame.h
- Committer:
- uci1
- Date:
- 2013-05-23
- Revision:
- 0:df529a435193
- Child:
- 1:28f2a824223d
File content as of revision 0:df529a435193:
#ifndef SNS_SnHeaderFrame #define SNS_SnHeaderFrame #include <stdint.h> #include "SnBitUtils.h" #include "SnCommWin.h" class SnHeaderFrame { public: // // A simple class to function like namespace. // The header for each i/o message is read/sent from here, in order to // ensure consistency across the communication methods. // static const uint32_t kMaxSizeOf = sizeof(uint8_t) + sizeof(uint32_t); // these are not in an enum so that we can control their size in bytes (1 byte) static const uint8_t kStatusCode = 0x10; static const uint8_t kFileCode = 0x20; static const uint8_t kFilenameCode = 0x23; static const uint8_t kFileNevtsCode = 0x26; static const uint8_t kFileNpwrsCode = 0x28; static const uint8_t kFileHeadrCode = 0x2A; static const uint8_t kFileReadFailCode= 0x2C; static const uint8_t kMbedFileCode = 0x30; static const uint8_t kMbedFilenameCode= 0x33; static const uint8_t kMbedFileChksCode= 0x35; static const uint8_t kConfigCode = 0x40; static const uint8_t kEventCode = 0x50; static const uint8_t kHndShkBits = 0x60; // all handshakes have these bits set static const uint8_t kHnShOkComplCode = 0x61; static const uint8_t kHnShOkPartlCode = 0x64; static const uint8_t kHnShOkStopCode = 0x66; static const uint8_t kHnShOkDelRnCode = 0x67; static const uint8_t kHnShOkDelAlCode = 0x68; static const uint8_t kHnShFailPrtCode = 0x6A; static const uint8_t kHnShFailNonCode = 0x6C; static const uint8_t kPowerCode = 0x70; static const uint8_t kHeartbeatCode = 0x78; static const uint8_t kNoConfigCode = 0x80; static const uint8_t kSbdMsgCode = 0x90; static const uint8_t kStringCode = 0xA0; // a debug string private: static char fgHdBuf[kMaxSizeOf]; public: static char* GetHdBuf(const uint8_t mcode, const uint32_t mlen) { char* b = fgHdBuf; WriteTo(b, mcode, mlen); return fgHdBuf; } template<class T> static SnCommWin::ECommWinResult WriteTo(T& x, const uint8_t msgCode, const uint32_t msgLen) { // expect 'x' to be a MODSERIAL or a char const* x = SnBitUtils::WriteTo(x, msgCode); x = SnBitUtils::WriteTo(x, msgLen); return SnCommWin::kOkMsgSent; } template<class T> static SnCommWin::ECommWinResult ReadFrom(T& b, uint8_t& msgCode, uint32_t& msgLen) { b = SnBitUtils::ReadFrom(b, msgCode); b = SnBitUtils::ReadFrom(b, msgLen); return SnCommWin::kOkWithMsg; } static uint32_t SizeOf() { return kMaxSizeOf; } }; #endif // SNS_SnHeaderFrame