mirror of
https://github.com/thelsing/knx.git
synced 2025-09-09 17:51:55 +02:00
- removed magic numbers
- added enum for restart states
This commit is contained in:
parent
301358f29f
commit
185fadfcd8
@ -299,7 +299,7 @@ bool BauSystemB::restartRequest(uint16_t asap)
|
||||
{
|
||||
if (_appLayer.isConnected())
|
||||
return false;
|
||||
_restartState = 1; // order important, has to be set BEFORE connectRequest
|
||||
_restartState = Connecting; // order important, has to be set BEFORE connectRequest
|
||||
_appLayer.connectRequest(asap, SystemPriority);
|
||||
_appLayer.deviceDescriptorReadRequest(AckRequested, SystemPriority, NetworkLayerParameter, asap, 0);
|
||||
return true;
|
||||
@ -307,15 +307,15 @@ bool BauSystemB::restartRequest(uint16_t asap)
|
||||
|
||||
void BauSystemB::connectConfirm(uint16_t tsap)
|
||||
{
|
||||
if (_restartState == 1 && tsap >= 0)
|
||||
if (_restartState == Connecting && tsap >= 0)
|
||||
{
|
||||
/* restart connection is confirmed, go to the next state */
|
||||
_restartState = 2;
|
||||
_restartState = Connected;
|
||||
_restartDelay = millis();
|
||||
}
|
||||
else
|
||||
{
|
||||
_restartState = 0;
|
||||
_restartState = Idle;
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,27 +323,27 @@ void BauSystemB::nextRestartState()
|
||||
{
|
||||
switch (_restartState)
|
||||
{
|
||||
case 0:
|
||||
case Idle:
|
||||
/* inactive state, do nothing */
|
||||
break;
|
||||
case 1:
|
||||
case Connecting:
|
||||
/* wait for connection, we do nothing here */
|
||||
break;
|
||||
case 2:
|
||||
case Connected:
|
||||
/* connection confirmed, we send restartRequest, but we wait a moment (sending ACK etc)... */
|
||||
if (millis() - _restartDelay > 30)
|
||||
{
|
||||
_appLayer.restartRequest(AckRequested, SystemPriority, NetworkLayerParameter);
|
||||
_restartState = 3;
|
||||
_restartState = Restarted;
|
||||
_restartDelay = millis();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
case Restarted:
|
||||
/* restart is finished, we send a discommect */
|
||||
if (millis() - _restartDelay > 30)
|
||||
{
|
||||
_appLayer.disconnectRequest(SystemPriority);
|
||||
_restartState = 0;
|
||||
_restartState = Idle;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -65,6 +65,14 @@ class BauSystemB : protected BusAccessUnit
|
||||
void updateGroupObject(GroupObject& go, uint8_t* data, uint8_t length);
|
||||
void nextRestartState();
|
||||
|
||||
enum RestartState
|
||||
{
|
||||
Idle,
|
||||
Connecting,
|
||||
Connected,
|
||||
Restarted
|
||||
};
|
||||
|
||||
DeviceObject _deviceObj;
|
||||
Memory _memory;
|
||||
AddressTableObject _addrTable;
|
||||
@ -76,6 +84,6 @@ class BauSystemB : protected BusAccessUnit
|
||||
TransportLayer _transLayer;
|
||||
NetworkLayer _netLayer;
|
||||
bool _configured = true;
|
||||
uint8_t _restartState = 0;
|
||||
RestartState _restartState = Idle;
|
||||
uint32_t _restartDelay = 0;
|
||||
};
|
Loading…
Reference in New Issue
Block a user