4 #if defined(DeviceFamily_CC13X0)
29 bool RfDataLinkLayer::sendFrame(
CemiFrame& frame)
49 if (frame.
rfLfn() == 0xFF)
52 frame.
rfLfn(_frameNumber);
54 _frameNumber = (_frameNumber + 1) & 0x7;
69 addFrameTxQueue(frame);
83 _rfMediumObj(rfMediumObj),
84 _rfPhy(*this, platform)
88 void RfDataLinkLayer::frameBytesReceived(uint8_t* rfPacketBuf, uint16_t length)
96 print(
"Received packet is too small. length: ");
101 #if defined(DeviceFamily_CC13X0)
109 uint16_t block1Crc = rfPacketBuf[10] << 8 | rfPacketBuf[11];
115 if ((rfPacketBuf[1] == 0x44) &&
116 (rfPacketBuf[2] == 0xFF) &&
117 (
crc16Dnp(rfPacketBuf, 10) == block1Crc))
121 uint16_t bytesLeft = length - 12;
123 uint8_t* pRfPacketBuf = &rfPacketBuf[12];
129 uint8_t* pBuffer = &_buffer[CEMI_HEADER_SIZE + 1];
131 uint16_t newLength = CEMI_HEADER_SIZE + 1;
138 while (bytesLeft > 18)
141 blockCrc = pRfPacketBuf[16] << 8 | pRfPacketBuf[17];
143 if (
crc16Dnp(pRfPacketBuf, 16) == blockCrc)
146 memcpy(pBuffer, pRfPacketBuf, 16);
161 blockCrc = pRfPacketBuf[bytesLeft - 2] << 8 | pRfPacketBuf[bytesLeft - 1];
162 crcOk = crcOk && (
crc16Dnp(&pRfPacketBuf[0], bytesLeft - 2) == blockCrc);
168 memcpy(pBuffer, pRfPacketBuf, bytesLeft - 2);
169 newLength += bytesLeft - 2;
182 uint8_t lfn = (_buffer[8] & 0x0E) >> 1;
186 uint8_t hopCount = (_buffer[8] & 0x70) >> 4;
192 _buffer[8] = newLength - NPDU_LPDU_DIFF - 1 - 1;
202 println(
"RX domain address does not match. Skipping...");
219 frame.
rfInfo(rfPacketBuf[3]);
237 if (value && !_enabled)
248 println(
"ERROR, RF transceiver not responding");
254 if (!value && _enabled)
272 void RfDataLinkLayer::fillRfFrame(
CemiFrame& frame, uint8_t* data)
277 data[0] = 9 + length;
292 uint16_t bytesLeft = length;
293 uint8_t* pBuffer = &_buffer[0];
294 uint8_t* pData = &data[12];
296 while (bytesLeft > 16)
298 memcpy(pData, pBuffer, 16);
308 memcpy(pData, pBuffer, bytesLeft);
314 void RfDataLinkLayer::addFrameTxQueue(
CemiFrame& frame)
316 _tx_queue_frame_t* tx_frame =
new _tx_queue_frame_t;
319 uint8_t nrFullBlocks = length / 16;
320 uint8_t bytesLeft = length % 16;
326 uint16_t totalLength = 12 + (nrFullBlocks * 18) + bytesLeft + 2;
328 tx_frame->length = totalLength;
329 tx_frame->data =
new uint8_t[tx_frame->length];
330 tx_frame->next = NULL;
333 fillRfFrame(frame, tx_frame->data);
344 if (_tx_queue.back == NULL)
346 _tx_queue.front = _tx_queue.back = tx_frame;
350 _tx_queue.back->next = tx_frame;
351 _tx_queue.back = tx_frame;
355 bool RfDataLinkLayer::isTxQueueEmpty()
357 if (_tx_queue.front == NULL)
365 void RfDataLinkLayer::loadNextTxFrame(uint8_t** sendBuffer, uint16_t* sendBufferLength)
367 if (_tx_queue.front == NULL)
372 _tx_queue_frame_t* tx_frame = _tx_queue.front;
373 *sendBuffer = tx_frame->data;
374 *sendBufferLength = tx_frame->length;
375 _tx_queue.front = tx_frame->next;
377 if (_tx_queue.front == NULL)
379 _tx_queue.back = NULL;
uint16_t crc16Dnp(uint8_t *input, uint16_t length)
uint8_t * pushByteArray(const uint8_t *src, uint32_t size, uint8_t *data)
uint8_t * pushWord(uint16_t w, uint8_t *data)
void fillTelegramRF(uint8_t *data)
SystemBroadcast systemBroadcast() const
uint8_t * rfSerialOrDoA() const
AddressType addressType() const
FrameFormat frameType() const
Priority priority() const
uint16_t telegramLengthtRF() const
void frameReceived(CemiFrame &frame)
void dataConReceived(CemiFrame &frame, bool success)
uint16_t individualAddress()
const uint8_t * propertyData(PropertyID id)
DptMedium mediumType() const override
RfDataLinkLayer(DeviceObject &devObj, RfMediumObject &rfMediumObj, NetworkLayerEntity &netLayerEntity, Platform &platform)
const uint8_t * rfDomainAddress()
@ SystemPriority
Mainly used by ETS for device programming.
@ AckDontCare
We don't care about DataLinkLayer acknowledgement.