some minor improvements from first code review

This commit is contained in:
Ing-Dom 2023-05-26 12:48:50 +02:00
parent 1f3a5fe5a9
commit 49ae48eacb
2 changed files with 8 additions and 14 deletions

View File

@ -26,11 +26,10 @@ IpDataLinkLayer::IpDataLinkLayer(DeviceObject& devObj, IpParameterObject& ipPara
bool IpDataLinkLayer::sendFrame(CemiFrame& frame) bool IpDataLinkLayer::sendFrame(CemiFrame& frame)
{ {
KnxIpRoutingIndication packet(frame); KnxIpRoutingIndication packet(frame);
if(countFrames()) // only send 50 packet per second: see KNX 3.2.6 p.6
if(CheckSendLimit())
return false; return false;
bool success = sendBytes(packet.data(), packet.totalLength()); bool success = sendBytes(packet.data(), packet.totalLength());
// only send 50 packet per second: see KNX 3.2.6 p.6
//delay(20);
dataConReceived(frame, success); dataConReceived(frame, success);
return success; return success;
} }
@ -114,13 +113,8 @@ bool IpDataLinkLayer::sendBytes(uint8_t* bytes, uint16_t length)
return _platform.sendBytesMultiCast(bytes, length); return _platform.sendBytesMultiCast(bytes, length);
} }
bool IpDataLinkLayer::countFrames() bool IpDataLinkLayer::CheckSendLimit()
{ {
// _frameCount[_frameCountBase] => frames sent since now and millis() % 100
// _frameCount[(_frameCountBase - 1) % 10] => frames sent since millis() % 100 and millis() % 100 - 100
// _frameCount[(_frameCountBase - 2) % 10] => frames sent since millis() % 100 - 100 and millis() % 100 - 200
// ... => information about the number of frames sent in the last 1000 ms
uint32_t curTime = millis() / 100; uint32_t curTime = millis() / 100;
// check if the countbuffer must be adjusted // check if the countbuffer must be adjusted
@ -157,10 +151,10 @@ bool IpDataLinkLayer::countFrames()
else else
{ {
_frameCount[_frameCountBase]++; _frameCount[_frameCountBase]++;
print("go for it: "); //print("sent packages in last 1000ms: ");
print(sum); //print(sum);
print(" curTime: "); //print(" curTime: ");
println(curTime); //println(curTime);
return true; return true;
} }
} }

View File

@ -27,7 +27,7 @@ class IpDataLinkLayer : public DataLinkLayer
uint32_t _frameCountTimeBase = 0; uint32_t _frameCountTimeBase = 0;
bool sendFrame(CemiFrame& frame); bool sendFrame(CemiFrame& frame);
bool sendBytes(uint8_t* buffer, uint16_t length); bool sendBytes(uint8_t* buffer, uint16_t length);
bool countFrames(); bool CheckSendLimit();
IpParameterObject& _ipParameters; IpParameterObject& _ipParameters;
}; };