mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 15:36:38 +02:00
fix #112 switch both TX & RX channels in hmRadio.h
This commit is contained in:
parent
1a679130d8
commit
7c6e068562
2 changed files with 40 additions and 40 deletions
|
@ -124,8 +124,8 @@ void app::setup(uint32_t timeout) {
|
|||
|
||||
|
||||
// mqtt
|
||||
char mqttAddr[MQTT_ADDR_LEN];
|
||||
uint16_t mqttPort;
|
||||
char mqttAddr[MQTT_ADDR_LEN];
|
||||
char mqttUser[MQTT_USER_LEN];
|
||||
char mqttPwd[MQTT_PWD_LEN];
|
||||
char mqttTopic[MQTT_TOPIC_LEN];
|
||||
|
@ -209,9 +209,9 @@ void app::loop(void) {
|
|||
yield();
|
||||
|
||||
if(checkTicker(&mRxTicker, 5)) {
|
||||
DPRINTLN(DBG_DEBUG, F("app_loops =") + String(app_loops));
|
||||
//DPRINTLN(DBG_VERBOSE, F("app_loops =") + String(app_loops));
|
||||
app_loops=0;
|
||||
DPRINT(DBG_DEBUG, F("a"));
|
||||
DPRINT(DBG_VERBOSE, F("a"));
|
||||
|
||||
bool rxRdy = mSys->Radio.switchRxCh();
|
||||
|
||||
|
@ -222,7 +222,8 @@ void app::loop(void) {
|
|||
if(mSys->Radio.checkPaketCrc(p->packet, &len, p->rxCh)) {
|
||||
// process buffer only on first occurrence
|
||||
if(mSerialDebug) {
|
||||
DPRINT(DBG_DEBUG, "Received " + String(len) + " bytes channel " + String(p->rxCh) + ": ");
|
||||
DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | ");
|
||||
|
||||
mSys->Radio.dumpBuf(NULL, p->packet, len);
|
||||
}
|
||||
mFrameCnt++;
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#define DTU_RADIO_ID ((uint64_t)0x1234567801ULL)
|
||||
#define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL)
|
||||
|
||||
#define RX_CHANNELS 5
|
||||
#define RX_LOOP_CNT 300
|
||||
#define RF_CHANNELS 5
|
||||
#define RF_LOOP_CNT 300
|
||||
|
||||
|
||||
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||
|
@ -56,18 +56,18 @@ class HmRadio {
|
|||
public:
|
||||
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
|
||||
DPRINTLN(DBG_VERBOSE, F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")");
|
||||
mTxChLst[0] = 40;
|
||||
//mTxChIdx = 1;
|
||||
|
||||
// Depending on the program, the module can work on 2403, 2423, 2440, 2461 or 2475MHz.
|
||||
// Channel List 2403, 2423, 2440, 2461, 2475MHz
|
||||
mRxChLst[0] = 03;
|
||||
mRxChLst[1] = 23;
|
||||
mRxChLst[2] = 40;
|
||||
mRxChLst[3] = 61;
|
||||
mRxChLst[4] = 75;
|
||||
mRxChIdx = 0;
|
||||
mRxLoopCnt = RX_LOOP_CNT;
|
||||
mRfChLst[0] = 03;
|
||||
mRfChLst[1] = 23;
|
||||
mRfChLst[2] = 40;
|
||||
mRfChLst[3] = 61;
|
||||
mRfChLst[4] = 75;
|
||||
|
||||
mTxChIdx = 2; // Start TX with 40
|
||||
mRxChIdx = 0; // Start RX with 03
|
||||
mRxLoopCnt = RF_LOOP_CNT;
|
||||
|
||||
pinCs = CS_PIN;
|
||||
pinCe = CE_PIN;
|
||||
|
@ -109,7 +109,7 @@ class HmRadio {
|
|||
DPRINTLN(DBG_INFO, F("Radio Config:"));
|
||||
mNrf24.printPrettyDetails();
|
||||
|
||||
mTxCh = getDefaultChannel();
|
||||
mTxCh = setDefaultChannels();
|
||||
|
||||
if(!mNrf24.isChipConnected()) {
|
||||
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
|
||||
|
@ -128,7 +128,7 @@ class HmRadio {
|
|||
while(mNrf24.available(&pipe)) {
|
||||
if(!mBufCtrl->full()) {
|
||||
p = mBufCtrl->getFront();
|
||||
p->rxCh = mRxChLst[mRxChIdx];
|
||||
p->rxCh = mRfChLst[mRxChIdx];
|
||||
len = mNrf24.getPayloadSize();
|
||||
if(len > MAX_RF_PAYLOAD_SIZE)
|
||||
len = MAX_RF_PAYLOAD_SIZE;
|
||||
|
@ -152,19 +152,12 @@ class HmRadio {
|
|||
mIrqRcvd = true;
|
||||
}
|
||||
|
||||
uint8_t getDefaultChannel(void) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:getDefaultChannel"));
|
||||
return mTxChLst[0];
|
||||
uint8_t setDefaultChannels(void) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setDefaultChannels"));
|
||||
mTxChIdx = 2; // Start TX with 40
|
||||
mRxChIdx = 0; // Start RX with 03
|
||||
return mRfChLst[mTxChIdx];
|
||||
}
|
||||
/*uint8_t getLastChannel(void) {
|
||||
return mTxChLst[mTxChIdx];
|
||||
}
|
||||
|
||||
uint8_t getNxtChannel(void) {
|
||||
if(++mTxChIdx >= 4)
|
||||
mTxChIdx = 0;
|
||||
return mTxChLst[mTxChIdx];
|
||||
}*/
|
||||
|
||||
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket"));
|
||||
|
@ -257,7 +250,7 @@ class HmRadio {
|
|||
//DPRINTLN(DBG_VERBOSE, "sent packet: #" + String(mSendCnt));
|
||||
//dumpBuf("SEN ", buf, len);
|
||||
if(mSerialDebug) {
|
||||
DPRINT(DBG_INFO, "Transmit " + String(len) + " | ");
|
||||
DPRINT(DBG_INFO, "TX " + String(len) + "B Ch" + String(mRfChLst[mTxChIdx]) + " | ");
|
||||
dumpBuf(NULL, buf, len);
|
||||
}
|
||||
|
||||
|
@ -265,10 +258,10 @@ class HmRadio {
|
|||
mNrf24.stopListening();
|
||||
|
||||
if(clear)
|
||||
mRxLoopCnt = RX_LOOP_CNT;
|
||||
mRxLoopCnt = RF_LOOP_CNT;
|
||||
|
||||
mTxCh = getDefaultChannel();
|
||||
mNrf24.setChannel(mTxCh);
|
||||
mNrf24.setChannel(mRfChLst[mTxChIdx]);
|
||||
mTxCh = getTxNxtChannel(); // switch channel for next packet
|
||||
mNrf24.openWritingPipe(invId); // TODO: deprecated
|
||||
mNrf24.setCRCLength(RF24_CRC_16);
|
||||
mNrf24.enableDynamicPayloads();
|
||||
|
@ -279,7 +272,7 @@ class HmRadio {
|
|||
// Try to avoid zero payload acks (has no effect)
|
||||
mNrf24.openWritingPipe(DUMMY_RADIO_ID); // TODO: why dummy radio id?, deprecated
|
||||
mRxChIdx = 0;
|
||||
mNrf24.setChannel(mRxChLst[mRxChIdx]);
|
||||
mNrf24.setChannel(mRfChLst[mRxChIdx]);
|
||||
mNrf24.setAutoAck(false);
|
||||
mNrf24.setRetries(0, 0);
|
||||
mNrf24.disableDynamicPayloads();
|
||||
|
@ -290,18 +283,24 @@ class HmRadio {
|
|||
mSendCnt++;
|
||||
}
|
||||
|
||||
uint8_t getTxNxtChannel(void) {
|
||||
|
||||
if(++mTxChIdx >= RF_CHANNELS)
|
||||
mTxChIdx = 0;
|
||||
return mRfChLst[mTxChIdx];
|
||||
}
|
||||
|
||||
uint8_t getRxNxtChannel(void) {
|
||||
|
||||
if(++mRxChIdx >= RX_CHANNELS)
|
||||
if(++mRxChIdx >= RF_CHANNELS)
|
||||
mRxChIdx = 0;
|
||||
return mRxChLst[mRxChIdx];
|
||||
return mRfChLst[mRxChIdx];
|
||||
}
|
||||
|
||||
uint8_t mTxCh;
|
||||
uint8_t mTxChLst[1];
|
||||
//uint8_t mTxChIdx;
|
||||
uint8_t mTxChIdx;
|
||||
|
||||
uint8_t mRxChLst[RX_CHANNELS];
|
||||
uint8_t mRfChLst[RF_CHANNELS];
|
||||
|
||||
uint8_t mRxChIdx;
|
||||
uint16_t mRxLoopCnt;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue