uint8_t Packet::constructPacket(const uint16_t& messageLen, const uint8_t& packetID) Description: ------------ * Calculate, format, and insert the packet protocol metadata into the packet transmit buffer Inputs: ------- * const uint16_t& messageLen - Number of values in txBuff to send as the payload in the next packet * const uint8_t& packetID - The packet 8-bit identifier
| 66 | * uint8_t - Number of payload bytes included in packet |
| 67 | */ |
| 68 | uint8_t Packet::constructPacket(const uint16_t& messageLen, const uint8_t& packetID) |
| 69 | { |
| 70 | if (messageLen > MAX_PACKET_SIZE) |
| 71 | { |
| 72 | calcOverhead(txBuff, MAX_PACKET_SIZE); |
| 73 | stuffPacket(txBuff, MAX_PACKET_SIZE); |
| 74 | uint8_t crcVal = crc.calculate(txBuff, MAX_PACKET_SIZE); |
| 75 | |
| 76 | preamble[1] = packetID; |
| 77 | preamble[2] = overheadByte; |
| 78 | preamble[3] = MAX_PACKET_SIZE; |
| 79 | |
| 80 | postamble[0] = crcVal; |
| 81 | |
| 82 | return MAX_PACKET_SIZE; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | calcOverhead(txBuff, (uint8_t)messageLen); |
| 87 | stuffPacket(txBuff, (uint8_t)messageLen); |
| 88 | uint8_t crcVal = crc.calculate(txBuff, (uint8_t)messageLen); |
| 89 | |
| 90 | preamble[1] = packetID; |
| 91 | preamble[2] = overheadByte; |
| 92 | preamble[3] = messageLen; |
| 93 | |
| 94 | postamble[0] = crcVal; |
| 95 | |
| 96 | return (uint8_t)messageLen; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /* |