Skip to content

Commit

Permalink
Rename (max)send(Busy)Tries and fix initialization
Browse files Browse the repository at this point in the history
As the fields contain the number of retries, they should be named
accordingly to prevent confusion. Furthermore, initialization to the
default values should happen in the constructor instead of the `begin()`
method.

Closes #66
  • Loading branch information
dallmair committed Jan 30, 2024
1 parent bc8da30 commit 3d9d5b3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions examples/example-txstresstest/src/app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define TEST_FILLBYTE (0x00) //!< Value the payload bytes should be filled with
#define TEST_DELAY_MS (1) //!< Delay in milliseconds between two test telegrams
#define TEST_TELEGRAM_SIZE (24) //!< Length of the test telegram, including trailing 0x00 byte and checksum byte (sblib supports up to 24 Bytes)
#define TEST_MAX_SEND_RETIES (100) //!< maximum retries in case of no ACK
#define TEST_MAX_SEND_RETRIES (100) //!< maximum retries in case of no ACK
#define TEST_STARTUP_DELAY_MS (1000) //!< Delay in milliseconds before the test starts


Expand Down Expand Up @@ -82,7 +82,7 @@ BcuBase* setup()
{
bcu.begin(MANUFACTURER, DEVICETYPE, APPVERSION);
bcu.setOwnAddress(KNX_PHYS_ADDRESS);
bcu.bus->maxSendTries(TEST_MAX_SEND_RETIES);
bcu.bus->maxSendRetries(TEST_MAX_SEND_RETRIES);
bcu.setHardwareType(hardwareVersion, sizeof(hardwareVersion));
// prepare test telegram
initTestTelegram();
Expand Down
32 changes: 16 additions & 16 deletions sblib/inc/sblib/eib/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ class Bus
void discardReceivedTelegram();

/**
* Set the number of tries that we do sent a telegram when it is not ACKed.
* Set the number of retries that we do send a telegram when it is not ACKed.
*
* @param tries - the number of tries. Default: 3.
* @param retries - the number of retries. Default: 3.
*/
void maxSendTries(int tries);
void maxSendRetries(int retries);

/**
* Set the number of busy tries that we do sent a telegram when we received a BUSY from remote.
* Set the number of busy retries that we do send a telegram when we receive a BUSY from remote.
*
* @param tries - the number of tries. Default: 3.
* @param retries - the number of retries. Default: 3.
*/
void maxSendBusyTries(int tries);
void maxSendBusyRetries(int retries);



Expand Down Expand Up @@ -244,12 +244,12 @@ class Bus
volatile int sendAck; //!< Send an acknowledge or not-acknowledge byte if != 0

private:
volatile State state; //!< The state of the lib's telegram sending/receiving
volatile int sendTries; //!< The number of repeats when sending a telegram
volatile int sendTriesMax; //!< The maximum number of repeats when sending a telegram. Default: 3 todo hora: load from EPROM
volatile int sendBusyTries; //!< The number of busy repeats when sending a telegram
volatile int sendBusyTriesMax; //!< The maximum number of busy repeats when sending a telegram. Default: 3 todo hora: load from EPROM
int nextByteIndex; //!< The number of the next byte in the telegram
volatile State state; //!< The state of the lib's telegram sending/receiving
volatile int sendRetries; //!< The number of repeats when sending a telegram
volatile int sendRetriesMax; //!< The maximum number of repeats when sending a telegram. Default: 3
volatile int sendBusyRetries; //!< The number of busy repeats when sending a telegram
volatile int sendBusyRetriesMax; //!< The maximum number of busy repeats when sending a telegram. Default: 3
int nextByteIndex; //!< The number of the next byte in the telegram

int currentByte; //!< The current byte that is received/sent, including the parity bit
int sendTelegramLen; //!< The size of the to be sent telegram in bytes (including the checksum).
Expand Down Expand Up @@ -284,14 +284,14 @@ class Bus
//
// Inline functions
//
inline void Bus::maxSendTries(int tries)
inline void Bus::maxSendRetries(int retries)
{
sendTriesMax = tries;
sendRetriesMax = retries;
}

inline void Bus::maxSendBusyTries(int tries)
inline void Bus::maxSendBusyRetries(int retries)
{
sendBusyTriesMax = tries;
sendBusyRetriesMax = retries;
}

inline bool Bus::sendingTelegram() const
Expand Down
48 changes: 24 additions & 24 deletions sblib/src/eib/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Bus::Bus(BcuBase* bcuInstance, Timer& aTimer, int aRxPin, int aTxPin, TimerCaptu
{
timeChannel = (TimerMatch) ((pwmChannel + 2) & 3); // +2 to be compatible to old code during refactoring
state = Bus::INIT;
sendRetriesMax = NACK_RETRY_DEFAULT;
sendBusyRetriesMax = BUSY_RETRY_DEFAULT;
}

/**
Expand All @@ -47,11 +49,9 @@ Bus::Bus(BcuBase* bcuInstance, Timer& aTimer, int aRxPin, int aTxPin, TimerCaptu
*/
void Bus::begin()
{
//todo load send-retries from eprom
//sendTriesMax = userEeprom.maxRetransmit & 0x03;
//sendBusyTriesMax = (userEeprom.maxRetransmit >>5) & 0x03; // default
sendTriesMax = NACK_RETRY_DEFAULT;
sendBusyTriesMax = BUSY_RETRY_DEFAULT; // default
//todo load send-retries from eprom -- this should actually be done by the BCU
//sendRetriesMax = userEeprom.maxRetransmit & 0x03;
//sendBusyRetriesMax = (userEeprom.maxRetransmit >> 5) & 0x03;

telegramLen = 0;
rx_error = RX_OK;
Expand Down Expand Up @@ -99,8 +99,8 @@ void Bus::begin()
serial.print("Bus begin - Timer prescaler: ", (unsigned int)TIMER_PRESCALER, DEC, 6);
serial.print(" ttimer prescaler: ", ttimer.prescaler(), DEC, 6);
serial.println(" ttimer value: ", ttimer.value(), DEC, 6);
serial.print("nak retries: ", sendTriesMax, DEC, 6);
serial.print(" busy retries: ", sendBusyTriesMax, DEC, 6);
serial.print("nak retries: ", sendRetriesMax, DEC, 6);
serial.print(" busy retries: ", sendBusyRetriesMax, DEC, 6);
serial.print(" phy addr: ", PHY_ADDR_AREA(bcu->ownAddress()), DEC);
serial.print(".", PHY_ADDR_LINE(bcu->ownAddress()), DEC);
serial.print(".", PHY_ADDR_DEVICE(bcu->ownAddress()), DEC);
Expand Down Expand Up @@ -293,8 +293,8 @@ void Bus::prepareForSending()
{
tx_error = TX_OK;

sendTries = 0;
sendBusyTries = 0;
sendRetries = 0;
sendBusyRetries = 0;
sendTelegramLen = 0;
wait_for_ack_from_remote = false;
repeatTelegram = false;
Expand Down Expand Up @@ -457,10 +457,10 @@ void Bus::handleTelegram(bool valid)
rx_error &= ~RX_CHECKSUM_ERROR;

// received telegram is ACK or repetition max -> send next telegram
if ((parity && currentByte == SB_BUS_ACK) || sendTries >= sendTriesMax || sendBusyTries >= sendBusyTriesMax)
if ((parity && currentByte == SB_BUS_ACK) || sendRetries >= sendRetriesMax || sendBusyRetries >= sendBusyRetriesMax)
{
// last sending to remote was ok or max retry, prepare for next tx telegram
if (sendTries >= sendTriesMax || sendBusyTries >= sendBusyTriesMax)
if (sendRetries >= sendRetriesMax || sendBusyRetries >= sendBusyRetriesMax)
tx_error |= TX_RETRY_ERROR;
tb_h( 906, tx_error, tb_in);
finishSendingTelegram();
Expand Down Expand Up @@ -504,7 +504,7 @@ void Bus::handleTelegram(bool valid)

DB_TELEGRAM(telrxerror = rx_error);

tb_d( 901, state, tb_in); tb_d( 902, sendTries, tb_in); tb_d( 903, sendBusyTries, tb_in); tb_h( 904, sendAck, tb_in);
tb_d( 901, state, tb_in); tb_d( 902, sendRetries, tb_in); tb_d( 903, sendBusyRetries, tb_in); tb_h( 904, sendAck, tb_in);
tb_h( 905, rx_error, tb_in); tb_d( 910, telegramLen, tb_in); tb_d( 911, nextByteIndex, tb_in);

#endif
Expand Down Expand Up @@ -839,9 +839,9 @@ __attribute__((optimize("Os"))) void Bus::timerInterruptHandler()

// timeout - check if there is anything to send
// check if we have max resend for last telegram.
if (sendTries >= sendTriesMax || sendBusyTries >= sendBusyTriesMax)
if (sendRetries >= sendRetriesMax || sendBusyRetries >= sendBusyRetriesMax)
{
tb_h( state+ 100,sendTries + 10* sendBusyTries, tb_in);
tb_h( state+ 100, sendRetries + 10 * sendBusyRetries, tb_in);
tx_error |= TX_RETRY_ERROR;
finishSendingTelegram(); // then send next, this also informs upper layer on sending error of last telegram
}
Expand All @@ -856,8 +856,8 @@ __attribute__((optimize("Os"))) void Bus::timerInterruptHandler()

if (repeatTelegram && (sendCurTelegram[0] & SB_TEL_REPEAT_FLAG) )
{// If it is the first repeat, then mark the telegram as being repeated and correct the checksum
tb_d( state+ 700, sendTries, tb_in);
tb_d( state+ 800, sendBusyTries, tb_in);
tb_d( state+ 700, sendRetries, tb_in);
tb_d( state+ 800, sendBusyRetries, tb_in);
sendCurTelegram[0] &= ~SB_TEL_REPEAT_FLAG;
sendCurTelegram[sendTelegramLen - 1] ^= SB_TEL_REPEAT_FLAG;
}
Expand Down Expand Up @@ -1191,8 +1191,8 @@ __attribute__((optimize("Os"))) void Bus::timerInterruptHandler()
DB_TELEGRAM(
txtelBuffer[0] = sendAck;
txtelLength = 1;
tx_rep_count = sendTries;
tx_busy_rep_count = sendBusyTries;
tx_rep_count = sendRetries;
tx_busy_rep_count = sendBusyRetries;
tx_telrxerror = tx_error;
);

Expand All @@ -1214,9 +1214,9 @@ __attribute__((optimize("Os"))) void Bus::timerInterruptHandler()
if (repeatTelegram) // if last telegram was repeated, increase respective counter
{
if (busy_wait_from_remote)
sendBusyTries++;
sendBusyRetries++;
else
sendTries++;
sendRetries++;
}
// dump previous tx-telegram and repeat counter and busy retry
DB_TELEGRAM(
Expand All @@ -1225,14 +1225,14 @@ __attribute__((optimize("Os"))) void Bus::timerInterruptHandler()
txtelBuffer[i] = sendCurTelegram[i];
}
txtelLength = sendTelegramLen;
tx_rep_count = sendTries;
tx_busy_rep_count = sendBusyTries;
tx_rep_count = sendRetries;
tx_busy_rep_count = sendBusyRetries;
tx_telrxerror = tx_error;
);
}
tb_d( SEND_END_OF_TX+300, wait_for_ack_from_remote , tb_in);
tb_d( SEND_END_OF_TX+400, sendTries , tb_in);
tb_d(SEND_END_OF_TX+500, sendBusyTries , tb_in);
tb_d( SEND_END_OF_TX+400, sendRetries, tb_in);
tb_d(SEND_END_OF_TX+500, sendBusyRetries, tb_in);

timer.match(timeChannel, time - 1); // we wait respective time - pre-send-time for next rx/tx window, cap intr disabled
break;
Expand Down

0 comments on commit 3d9d5b3

Please sign in to comment.