mirror of
https://github.com/thelsing/knx.git
synced 2025-04-05 01:15:46 +02:00
implement acking
This commit is contained in:
parent
349b49299e
commit
96f8a1bffb
@ -10,6 +10,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// NCN5120
|
// NCN5120
|
||||||
|
//#define NCN5120
|
||||||
|
|
||||||
// services Host -> Controller :
|
// services Host -> Controller :
|
||||||
// internal commands, device specific
|
// internal commands, device specific
|
||||||
@ -18,7 +19,7 @@
|
|||||||
#define U_SET_BUSY_REQ 0x03
|
#define U_SET_BUSY_REQ 0x03
|
||||||
#define U_QUIT_BUSY_REQ 0x04
|
#define U_QUIT_BUSY_REQ 0x04
|
||||||
#define U_BUSMON_REQ 0x05
|
#define U_BUSMON_REQ 0x05
|
||||||
#define U_SET_ADDRESS_REQ 0xF1
|
#define U_SET_ADDRESS_REQ 0xF1 // different on TP-UART
|
||||||
#define U_SET_REPETITION_REQ 0xF2
|
#define U_SET_REPETITION_REQ 0xF2
|
||||||
#define U_L_DATA_OFFSET_REQ 0x08 //-0x0C
|
#define U_L_DATA_OFFSET_REQ 0x08 //-0x0C
|
||||||
#define U_SYSTEM_STATE 0x0D
|
#define U_SYSTEM_STATE 0x0D
|
||||||
@ -86,6 +87,7 @@ void TpUartDataLinkLayer::resetChip()
|
|||||||
|
|
||||||
void TpUartDataLinkLayer::stopChip()
|
void TpUartDataLinkLayer::stopChip()
|
||||||
{
|
{
|
||||||
|
#ifdef NCN5120
|
||||||
uint8_t cmd = U_STOP_MODE_REQ;
|
uint8_t cmd = U_STOP_MODE_REQ;
|
||||||
_platform.writeUart(cmd);
|
_platform.writeUart(cmd);
|
||||||
while (true)
|
while (true)
|
||||||
@ -94,31 +96,12 @@ void TpUartDataLinkLayer::stopChip()
|
|||||||
if (resp == U_STOP_MODE_IND)
|
if (resp == U_STOP_MODE_IND)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void printHex(const char* suffix, const uint8_t *data, size_t length);
|
void printHex(const char* suffix, const uint8_t *data, size_t length);
|
||||||
|
|
||||||
|
|
||||||
void TpUartDataLinkLayer::setAddress(uint16_t addr)
|
|
||||||
{
|
|
||||||
if (addr == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint8_t cmd[4];
|
|
||||||
cmd[1] = (uint8_t)(addr >> 8);
|
|
||||||
cmd[2] = (uint8_t)(addr & 0xff);
|
|
||||||
//cmd[3] is don't care
|
|
||||||
|
|
||||||
_platform.writeUart(cmd, 4);
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
uint8_t resp = _platform.readUart();
|
|
||||||
resp &= U_CONFIGURE_MASK;
|
|
||||||
if (resp == U_CONFIGURE_IND)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TpUartDataLinkLayer::TpUartDataLinkLayer(DeviceObject& devObj, AddressTableObject& addrTab,
|
TpUartDataLinkLayer::TpUartDataLinkLayer(DeviceObject& devObj, AddressTableObject& addrTab,
|
||||||
NetworkLayer& layer, Platform& platform) : DataLinkLayer(devObj, addrTab, layer, platform)
|
NetworkLayer& layer, Platform& platform) : DataLinkLayer(devObj, addrTab, layer, platform)
|
||||||
{
|
{
|
||||||
@ -228,9 +211,11 @@ bool TpUartDataLinkLayer::checkDataInd(uint8_t firstByte)
|
|||||||
|
|
||||||
printHex("=>", buffer, len);
|
printHex("=>", buffer, len);
|
||||||
CemiFrame frame(buffer, len);
|
CemiFrame frame(buffer, len);
|
||||||
if (_deviceObject.induvidualAddress() == 0 && frame.destinationAddress() == 0)
|
|
||||||
|
if (frame.addressType() == InduvidualAddress && _deviceObject.induvidualAddress() == frame.destinationAddress()
|
||||||
|
|| frame.addressType() == GroupAddress && _groupAddressTable.contains(frame.destinationAddress()))
|
||||||
{
|
{
|
||||||
//send ack. Otherwise we have autoacknowledge
|
//send ack.
|
||||||
_platform.writeUart(U_ACK_REQ + 1);
|
_platform.writeUart(U_ACK_REQ + 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -433,7 +418,6 @@ void TpUartDataLinkLayer::enabled(bool value)
|
|||||||
_platform.setupUart();
|
_platform.setupUart();
|
||||||
|
|
||||||
resetChip();
|
resetChip();
|
||||||
setAddress(_deviceObject.induvidualAddress());
|
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ class TpUartDataLinkLayer: public DataLinkLayer
|
|||||||
{
|
{
|
||||||
using DataLinkLayer::_deviceObject;
|
using DataLinkLayer::_deviceObject;
|
||||||
using DataLinkLayer::_platform;
|
using DataLinkLayer::_platform;
|
||||||
|
using DataLinkLayer::_groupAddressTable;
|
||||||
public:
|
public:
|
||||||
TpUartDataLinkLayer(DeviceObject& devObj, AddressTableObject& addrTab, NetworkLayer& layer,
|
TpUartDataLinkLayer(DeviceObject& devObj, AddressTableObject& addrTab, NetworkLayer& layer,
|
||||||
Platform& platform);
|
Platform& platform);
|
||||||
@ -36,5 +37,4 @@ private:
|
|||||||
void frameBytesReceived(uint8_t* buffer, uint16_t length);
|
void frameBytesReceived(uint8_t* buffer, uint16_t length);
|
||||||
void resetChip();
|
void resetChip();
|
||||||
void stopChip();
|
void stopChip();
|
||||||
void setAddress(uint16_t addr);
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user