Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TX Retry #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions firmware/lib/SiedleClient/SiedleClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void SiedleClient::bitTimerISR() {
if (bitNumber-- < -3) {
// timeout
done = true;
txError = true;
} else {
auto voltage = getBusvoltage();
if (voltage >= ADC_CARRIER_HIGH_THRESHOLD_VOLTAGE) {
Expand Down Expand Up @@ -193,6 +194,7 @@ void SiedleClient::sendCmdAsync(siedle_cmd_t tx_cmd) {
cmd_tx_buf = tx_cmd;
state = transmitting;
bitNumber = 31;
txError = false;

// Output the first bit (#31). Remaining bits will be transmitted using the ISR
auto bit = bitRead(cmd_tx_buf, bitNumber--);
Expand Down
3 changes: 3 additions & 0 deletions firmware/lib/SiedleClient/SiedleClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class SiedleClient {
return cmd;
}

// last transmit was not successful
bool txError = false;

private:
int readBit();
uint8_t inputPin;
Expand Down
20 changes: 18 additions & 2 deletions firmware/src/siedle-service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,29 @@ void SiedleServiceClass::loop() {

noInterrupts();
auto now = millis();
auto doSend = !siedleTxQueue.isEmpty()

if (siedleClient.state == idle) {
if (siedleClient.txError) {
if (retryCounter == -1) {
retryCounter = 3;
}
} else {
retryCounter = -1;
}
}

auto doSend = (!siedleTxQueue.isEmpty() || retryCounter > 0)
&& (now - lastTxMillis > BUS_MAX_SEND_RATE_MS)
&& siedleClient.state == idle;
siedle_cmd_t cmd;

if (doSend) {
cmd = siedleTxQueue.pop();
if (retryCounter > 0) {
retryCounter--;
cmd = lastTxCmd;
} else {
cmd = siedleTxQueue.pop();
}
siedleClient.sendCmdAsync(cmd);
lastTxCmd = cmd;
}
Expand Down
1 change: 1 addition & 0 deletions firmware/src/siedle-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SiedleServiceClass {
unsigned long lastTxMillis;
unsigned int lastTxCounter;
siedle_cmd_t lastTxCmd;
int retryCounter = -1;
};

extern SiedleServiceClass SiedleService;
Expand Down