| 48 | |
| 49 | |
| 50 | class Packet |
| 51 | { |
| 52 | public: // <<---------------------------------------//public |
| 53 | uint8_t txBuff[MAX_PACKET_SIZE]; |
| 54 | uint8_t rxBuff[MAX_PACKET_SIZE]; |
| 55 | uint8_t preamble[PREAMBLE_SIZE] = {START_BYTE, 0, 0, 0}; |
| 56 | uint8_t postamble[POSTAMBLE_SIZE] = {0, STOP_BYTE}; |
| 57 | |
| 58 | uint8_t bytesRead = 0; |
| 59 | int8_t status = 0; |
| 60 | |
| 61 | |
| 62 | void begin(const configST& configs); |
| 63 | void begin(const bool& _debug = true, Stream& _debugPort = Serial, const uint32_t& _timeout = DEFAULT_TIMEOUT); |
| 64 | uint8_t constructPacket(const uint16_t& messageLen, const uint8_t& packetID = 0); |
| 65 | uint8_t parse(const uint8_t& recChar, const bool& valid = true); |
| 66 | uint8_t currentPacketID(); |
| 67 | void reset(); |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | uint16_t Packet::txObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T)) |
| 72 | Description: |
| 73 | ------------ |
| 74 | * Stuffs "len" number of bytes of an arbitrary object (byte, int, |
| 75 | float, double, struct, etc...) into the transmit buffer (txBuff) |
| 76 | starting at the index as specified by the argument "index" |
| 77 | |
| 78 | Inputs: |
| 79 | ------- |
| 80 | * const T &val - Pointer to the object to be copied to the |
| 81 | transmit buffer (txBuff) |
| 82 | * const uint16_t &index - Starting index of the object within the |
| 83 | transmit buffer (txBuff) |
| 84 | * const uint16_t &len - Number of bytes of the object "val" to transmit |
| 85 | |
| 86 | Return: |
| 87 | ------- |
| 88 | * uint16_t maxIndex - uint16_t maxIndex - Index of the transmit buffer (txBuff) that directly follows the bytes processed |
| 89 | by the calling of this member function |
| 90 | */ |
| 91 | template <typename T> |
| 92 | uint16_t txObj(const T& val, const uint16_t& index = 0, const uint16_t& len = sizeof(T)) |
| 93 | { |
| 94 | uint8_t* ptr = (uint8_t*)&val; |
| 95 | uint16_t maxIndex; |
| 96 | |
| 97 | if ((len + index) > MAX_PACKET_SIZE) |
| 98 | maxIndex = MAX_PACKET_SIZE; |
| 99 | else |
| 100 | maxIndex = len + index; |
| 101 | |
| 102 | for (uint16_t i = index; i < maxIndex; i++) |
| 103 | { |
| 104 | txBuff[i] = *ptr; |
| 105 | ptr++; |
| 106 | } |
| 107 |
nothing calls this directly
no outgoing calls
no test coverage detected