|
|
@@ -104,21 +104,26 @@ uint8_t crc8(uint8_t crc, uint8_t Size, uint8_t *Buffer)
|
|
|
|
|
|
|
|
|
|
|
|
-DataFrame::DataFrame(uint8_t *frame, uint8_t size)
|
|
|
+DataFrame::DataFrame(uint8_t *frame, uint8_t size, DataframeType_t type)
|
|
|
{
|
|
|
_frame = frame;
|
|
|
_capacity = size;
|
|
|
- _frame[0] = HEADER_CHAR;
|
|
|
- _frame[1] = 0; //length of packet
|
|
|
- _length = 2;
|
|
|
-
|
|
|
+ _type = type;
|
|
|
+ this->Init();
|
|
|
}
|
|
|
|
|
|
void DataFrame::Init(void)
|
|
|
{
|
|
|
- _frame[0] = HEADER_CHAR;
|
|
|
- _frame[1] = 0; //length of packet
|
|
|
- _length = 2;
|
|
|
+ if(_type == TYPE_HEADER_CRC){
|
|
|
+ _frame[0] = HEADER_CHAR;
|
|
|
+ _frame[1] = 0; //length of packet
|
|
|
+ _length = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_type == TYPE_PLAIN){
|
|
|
+ _frame[1] = 0; //length of packet
|
|
|
+ _length = 1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool DataFrame::AddUint8(uint8_t d)
|
|
|
@@ -193,11 +198,16 @@ bool DataFrame::AddFloat(float f)
|
|
|
|
|
|
uint8_t DataFrame::Commit(void)
|
|
|
{
|
|
|
- // compute _length
|
|
|
- _length++;
|
|
|
- _frame[1] = _length - 2;
|
|
|
- _frame[_length - 1] = crc8(0, _length-1, _frame);
|
|
|
- // length of payload: from byte 2 to CRC byte (the last)
|
|
|
+ if(_type == TYPE_HEADER_CRC){
|
|
|
+ // compute _length
|
|
|
+ _length++;
|
|
|
+ _frame[1] = _length - 2;
|
|
|
+ _frame[_length - 1] = crc8(0, _length-1, _frame);
|
|
|
+ // length of payload: from byte 2 to CRC byte (the last)
|
|
|
+ }
|
|
|
+ if(_type == TYPE_PLAIN){
|
|
|
+ _frame[0] = _length;
|
|
|
+ }
|
|
|
return _length;
|
|
|
|
|
|
}
|