mirror of
https://github.com/thelsing/knx.git
synced 2025-01-21 00:05:43 +01:00
add conversion from cemi-frame to tp-format
This commit is contained in:
parent
24150d155b
commit
1889c669e3
@ -60,6 +60,42 @@ uint16_t CemiFrame::totalLenght() const
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t CemiFrame::telegramLengthtTP() const
|
||||||
|
{
|
||||||
|
if (frameType() == StandardFrame)
|
||||||
|
return totalLenght() - 2; /*-AddInfo -MsgCode - only one CTRL + CRC, */
|
||||||
|
else
|
||||||
|
return totalLenght() - 1; /*-AddInfo -MsgCode + CRC, */
|
||||||
|
}
|
||||||
|
|
||||||
|
void CemiFrame::fillTelegramTP(uint8_t* data)
|
||||||
|
{
|
||||||
|
uint16_t len = telegramLengthtTP();
|
||||||
|
if (frameType() == StandardFrame)
|
||||||
|
{
|
||||||
|
uint8_t octet5 = (_ctrl1[1] & 0xF0) | (_ctrl1[6] & 0x0F);
|
||||||
|
data[0] = _ctrl1[0]; //CTRL
|
||||||
|
memcpy(data + 1, _ctrl1 + 2, 4); // SA, DA
|
||||||
|
data[5] = octet5; // LEN; Hopcount, ..
|
||||||
|
memcpy(data + 6, _ctrl1 + 8, len - 7); // APDU
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(data, _ctrl1, len - 1);
|
||||||
|
}
|
||||||
|
data[len - 1] = calcCRC(data, len - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CemiFrame::calcCRC(uint8_t * buffer, uint16_t len)
|
||||||
|
{
|
||||||
|
uint8_t crc = 0xFF;
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < len; i++)
|
||||||
|
crc ^= buffer[i];
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
FrameFormat CemiFrame::frameType() const
|
FrameFormat CemiFrame::frameType() const
|
||||||
{
|
{
|
||||||
return (FrameFormat)(_ctrl1[0] & StandardFrame);
|
return (FrameFormat)(_ctrl1[0] & StandardFrame);
|
||||||
|
@ -24,6 +24,8 @@ public:
|
|||||||
MessageCode messageCode() const;
|
MessageCode messageCode() const;
|
||||||
void messageCode(MessageCode value);
|
void messageCode(MessageCode value);
|
||||||
uint16_t totalLenght() const;
|
uint16_t totalLenght() const;
|
||||||
|
uint16_t telegramLengthtTP() const;
|
||||||
|
void fillTelegramTP(uint8_t* data);
|
||||||
|
|
||||||
FrameFormat frameType() const;
|
FrameFormat frameType() const;
|
||||||
void frameType(FrameFormat value);
|
void frameType(FrameFormat value);
|
||||||
@ -48,6 +50,7 @@ public:
|
|||||||
TPDU& tpdu();
|
TPDU& tpdu();
|
||||||
APDU& apdu();
|
APDU& apdu();
|
||||||
|
|
||||||
|
uint8_t calcCRC(uint8_t* buffer, uint16_t len);
|
||||||
bool valid() const;
|
bool valid() const;
|
||||||
private:
|
private:
|
||||||
uint8_t buffer[0xff + NPDU_LPDU_DIFF]; //only valid of add info is zero
|
uint8_t buffer[0xff + NPDU_LPDU_DIFF]; //only valid of add info is zero
|
||||||
|
@ -17,10 +17,9 @@ TpUartDataLinkLayer::TpUartDataLinkLayer(DeviceObject& devObj, AddressTableObjec
|
|||||||
|
|
||||||
bool TpUartDataLinkLayer::sendFrame(CemiFrame& frame)
|
bool TpUartDataLinkLayer::sendFrame(CemiFrame& frame)
|
||||||
{
|
{
|
||||||
uint16_t length = frame.totalLenght();
|
uint16_t length = frame.telegramLengthtTP();
|
||||||
uint8_t* buffer = new uint8_t[length];
|
uint8_t* buffer = new uint8_t[length];
|
||||||
|
frame.fillTelegramTP(buffer);
|
||||||
//TODO: Create TP standard frame or extended frame from cemi frame into buffer
|
|
||||||
|
|
||||||
bool success = sendBytes(buffer, length);
|
bool success = sendBytes(buffer, length);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user