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())
|
if (_appLayer.isConnected())
|
||||||
return false;
|
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.connectRequest(asap, SystemPriority);
|
||||||
_appLayer.deviceDescriptorReadRequest(AckRequested, SystemPriority, NetworkLayerParameter, asap, 0);
|
_appLayer.deviceDescriptorReadRequest(AckRequested, SystemPriority, NetworkLayerParameter, asap, 0);
|
||||||
return true;
|
return true;
|
||||||
@ -307,15 +307,15 @@ bool BauSystemB::restartRequest(uint16_t asap)
|
|||||||
|
|
||||||
void BauSystemB::connectConfirm(uint16_t tsap)
|
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 */
|
/* restart connection is confirmed, go to the next state */
|
||||||
_restartState = 2;
|
_restartState = Connected;
|
||||||
_restartDelay = millis();
|
_restartDelay = millis();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_restartState = 0;
|
_restartState = Idle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,27 +323,27 @@ void BauSystemB::nextRestartState()
|
|||||||
{
|
{
|
||||||
switch (_restartState)
|
switch (_restartState)
|
||||||
{
|
{
|
||||||
case 0:
|
case Idle:
|
||||||
/* inactive state, do nothing */
|
/* inactive state, do nothing */
|
||||||
break;
|
break;
|
||||||
case 1:
|
case Connecting:
|
||||||
/* wait for connection, we do nothing here */
|
/* wait for connection, we do nothing here */
|
||||||
break;
|
break;
|
||||||
case 2:
|
case Connected:
|
||||||
/* connection confirmed, we send restartRequest, but we wait a moment (sending ACK etc)... */
|
/* connection confirmed, we send restartRequest, but we wait a moment (sending ACK etc)... */
|
||||||
if (millis() - _restartDelay > 30)
|
if (millis() - _restartDelay > 30)
|
||||||
{
|
{
|
||||||
_appLayer.restartRequest(AckRequested, SystemPriority, NetworkLayerParameter);
|
_appLayer.restartRequest(AckRequested, SystemPriority, NetworkLayerParameter);
|
||||||
_restartState = 3;
|
_restartState = Restarted;
|
||||||
_restartDelay = millis();
|
_restartDelay = millis();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case Restarted:
|
||||||
/* restart is finished, we send a discommect */
|
/* restart is finished, we send a discommect */
|
||||||
if (millis() - _restartDelay > 30)
|
if (millis() - _restartDelay > 30)
|
||||||
{
|
{
|
||||||
_appLayer.disconnectRequest(SystemPriority);
|
_appLayer.disconnectRequest(SystemPriority);
|
||||||
_restartState = 0;
|
_restartState = Idle;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -65,6 +65,14 @@ class BauSystemB : protected BusAccessUnit
|
|||||||
void updateGroupObject(GroupObject& go, uint8_t* data, uint8_t length);
|
void updateGroupObject(GroupObject& go, uint8_t* data, uint8_t length);
|
||||||
void nextRestartState();
|
void nextRestartState();
|
||||||
|
|
||||||
|
enum RestartState
|
||||||
|
{
|
||||||
|
Idle,
|
||||||
|
Connecting,
|
||||||
|
Connected,
|
||||||
|
Restarted
|
||||||
|
};
|
||||||
|
|
||||||
DeviceObject _deviceObj;
|
DeviceObject _deviceObj;
|
||||||
Memory _memory;
|
Memory _memory;
|
||||||
AddressTableObject _addrTable;
|
AddressTableObject _addrTable;
|
||||||
@ -76,6 +84,6 @@ class BauSystemB : protected BusAccessUnit
|
|||||||
TransportLayer _transLayer;
|
TransportLayer _transLayer;
|
||||||
NetworkLayer _netLayer;
|
NetworkLayer _netLayer;
|
||||||
bool _configured = true;
|
bool _configured = true;
|
||||||
uint8_t _restartState = 0;
|
RestartState _restartState = Idle;
|
||||||
uint32_t _restartDelay = 0;
|
uint32_t _restartDelay = 0;
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user