mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Rewrite KISS modem to be fully spec-compliant
This commit is contained in:
parent
bcb7a8067e
commit
5dcc377b77
5 changed files with 533 additions and 352 deletions
|
|
@ -12,14 +12,9 @@
|
|||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
#define NOISE_FLOOR_CALIB_INTERVAL_MS 2000
|
||||
#define AGC_RESET_INTERVAL_MS 30000
|
||||
|
||||
StdRNG rng;
|
||||
mesh::LocalIdentity identity;
|
||||
KissModem* modem;
|
||||
static uint32_t next_noise_floor_calib_ms = 0;
|
||||
static uint32_t next_agc_reset_ms = 0;
|
||||
|
||||
void halt() {
|
||||
while (1) ;
|
||||
|
|
@ -67,6 +62,18 @@ void onGetStats(uint32_t* rx, uint32_t* tx, uint32_t* errors) {
|
|||
*errors = radio_driver.getPacketsRecvErrors();
|
||||
}
|
||||
|
||||
void onSendPacket(const uint8_t* data, uint16_t len) {
|
||||
radio_driver.startSendRaw(data, len);
|
||||
}
|
||||
|
||||
bool onIsSendComplete() {
|
||||
return radio_driver.isSendComplete();
|
||||
}
|
||||
|
||||
void onSendFinished() {
|
||||
radio_driver.onSendFinished();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
board.begin();
|
||||
|
||||
|
|
@ -91,40 +98,25 @@ void setup() {
|
|||
modem->setTxPowerCallback(onSetTxPower);
|
||||
modem->setGetCurrentRssiCallback(onGetCurrentRssi);
|
||||
modem->setGetStatsCallback(onGetStats);
|
||||
modem->setSendPacketCallback(onSendPacket);
|
||||
modem->setIsSendCompleteCallback(onIsSendComplete);
|
||||
modem->setOnSendFinishedCallback(onSendFinished);
|
||||
modem->begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
modem->loop();
|
||||
|
||||
uint8_t packet[KISS_MAX_PACKET_SIZE];
|
||||
uint16_t len;
|
||||
if (!modem->isTxBusy()) {
|
||||
uint8_t rx_buf[256];
|
||||
int rx_len = radio_driver.recvRaw(rx_buf, sizeof(rx_buf));
|
||||
|
||||
// trigger noise floor calibration
|
||||
if ((uint32_t)(millis() - next_noise_floor_calib_ms) >= NOISE_FLOOR_CALIB_INTERVAL_MS) {
|
||||
radio_driver.triggerNoiseFloorCalibrate(0);
|
||||
next_noise_floor_calib_ms = millis();
|
||||
}
|
||||
radio_driver.loop();
|
||||
|
||||
if (modem->getPacketToSend(packet, &len)) {
|
||||
radio_driver.startSendRaw(packet, len);
|
||||
while (!radio_driver.isSendComplete()) {
|
||||
delay(1);
|
||||
if (rx_len > 0) {
|
||||
int8_t snr = (int8_t)(radio_driver.getLastSNR() * 4);
|
||||
int8_t rssi = (int8_t)radio_driver.getLastRSSI();
|
||||
modem->onPacketReceived(snr, rssi, rx_buf, rx_len);
|
||||
}
|
||||
radio_driver.onSendFinished();
|
||||
modem->onTxComplete(true);
|
||||
}
|
||||
|
||||
if ((uint32_t)(millis() - next_agc_reset_ms) >= AGC_RESET_INTERVAL_MS) {
|
||||
radio_driver.resetAGC();
|
||||
next_agc_reset_ms = millis();
|
||||
}
|
||||
uint8_t rx_buf[256];
|
||||
int rx_len = radio_driver.recvRaw(rx_buf, sizeof(rx_buf));
|
||||
if (rx_len > 0) {
|
||||
int8_t snr = (int8_t)(radio_driver.getLastSNR() * 4);
|
||||
int8_t rssi = (int8_t)radio_driver.getLastRSSI();
|
||||
modem->onPacketReceived(snr, rssi, rx_buf, rx_len);
|
||||
}
|
||||
radio_driver.loop();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue