mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-02 18:51:38 +02:00
* PR #76 updated debug messages: now 5 different levels are available
* fixed CRC loop issue
This commit is contained in:
parent
7e2df351d9
commit
0347a3df44
10 changed files with 245 additions and 196 deletions
|
@ -22,12 +22,6 @@
|
|||
#define RX_LOOP_CNT 300
|
||||
|
||||
|
||||
#ifdef DEBUG_HMRADIO
|
||||
#define DBGHMR(f) (DPRINTLN(f))
|
||||
#else
|
||||
#define DBGHMR(f)
|
||||
#endif
|
||||
|
||||
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||
|
||||
|
||||
|
@ -60,7 +54,7 @@ template <uint8_t CE_PIN, uint8_t CS_PIN, uint8_t IRQ_PIN, class BUFFER, uint64_
|
|||
class HmRadio {
|
||||
public:
|
||||
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
|
||||
DBGHMR(F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(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;
|
||||
|
||||
|
@ -87,7 +81,7 @@ class HmRadio {
|
|||
~HmRadio() {}
|
||||
|
||||
void setup(BUFFER *ctrl) {
|
||||
DBGHMR(F("hmRadio.h:setup"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
|
||||
pinMode(pinIrq, INPUT_PULLUP);
|
||||
|
||||
mBufCtrl = ctrl;
|
||||
|
@ -107,17 +101,17 @@ class HmRadio {
|
|||
// enable only receiving interrupts
|
||||
mNrf24.maskIRQ(true, true, false);
|
||||
|
||||
DPRINTLN(F("RF24 Amp Pwr: RF24_PA_") + String(rf24AmpPower[AmplifierPower]));
|
||||
DPRINTLN(DBG_INFO, F("RF24 Amp Pwr: RF24_PA_") + String(rf24AmpPower[AmplifierPower]));
|
||||
mNrf24.setPALevel(AmplifierPower & 0x03);
|
||||
mNrf24.startListening();
|
||||
|
||||
DPRINTLN(F("Radio Config:"));
|
||||
DPRINTLN(DBG_INFO, F("Radio Config:"));
|
||||
mNrf24.printPrettyDetails();
|
||||
|
||||
mTxCh = getDefaultChannel();
|
||||
|
||||
if(!mNrf24.isChipConnected()) {
|
||||
DPRINTLN(F("WARNING! your NRF24 module can't be reached, check the wiring"));
|
||||
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,12 +147,12 @@ class HmRadio {
|
|||
}
|
||||
|
||||
void handleIntr(void) {
|
||||
//DBGHMR(F("hmRadio.h:handleIntr"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:handleIntr"));
|
||||
mIrqRcvd = true;
|
||||
}
|
||||
|
||||
uint8_t getDefaultChannel(void) {
|
||||
//DBGHMR(F("hmRadio.h:getDefaultChannel"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:getDefaultChannel"));
|
||||
return mTxChLst[0];
|
||||
}
|
||||
/*uint8_t getLastChannel(void) {
|
||||
|
@ -172,7 +166,7 @@ class HmRadio {
|
|||
}*/
|
||||
|
||||
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
||||
//DBGHMR(F("hmRadio.h:sendTimePacket"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket"));
|
||||
sendCmdPacket(invId, 0x15, 0x80, false);
|
||||
mTxBuf[10] = 0x0b; // cid
|
||||
mTxBuf[11] = 0x00;
|
||||
|
@ -188,7 +182,7 @@ class HmRadio {
|
|||
}
|
||||
|
||||
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) {
|
||||
//DBGHMR(F("hmRadio.h:sendCmdPacket"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendCmdPacket"));
|
||||
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
|
||||
mTxBuf[0] = mid; // message id
|
||||
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
|
||||
|
@ -201,7 +195,7 @@ class HmRadio {
|
|||
}
|
||||
|
||||
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
|
||||
//DBGHMR(F("hmRadio.h:checkPaketCrc"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:checkPaketCrc"));
|
||||
*len = (buf[0] >> 2);
|
||||
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
|
||||
*len = MAX_RF_PAYLOAD_SIZE - 2;
|
||||
|
@ -216,8 +210,8 @@ class HmRadio {
|
|||
}
|
||||
|
||||
bool switchRxCh(uint16_t addLoop = 0) {
|
||||
//DBGHMR(F("hmRadio.h:switchRxCh"));
|
||||
//DBGHMR(F("R"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:switchRxCh"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("R"));
|
||||
|
||||
mRxLoopCnt += addLoop;
|
||||
if(mRxLoopCnt != 0) {
|
||||
|
@ -232,18 +226,18 @@ class HmRadio {
|
|||
}
|
||||
|
||||
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
|
||||
//DBGHMR(F("hmRadio.h:dumpBuf"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:dumpBuf"));
|
||||
if(NULL != info)
|
||||
DPRINT(String(info));
|
||||
DBGPRINT(String(info));
|
||||
for(uint8_t i = 0; i < len; i++) {
|
||||
DHEX(buf[i]);
|
||||
DPRINT(" ");
|
||||
DBGPRINT(" ");
|
||||
}
|
||||
DPRINTLN("");
|
||||
DBGPRINTLN("");
|
||||
}
|
||||
|
||||
bool isChipConnected(void) {
|
||||
//DBGHMR(F("hmRadio.h:isChipConnected"));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:isChipConnected"));
|
||||
return mNrf24.isChipConnected();
|
||||
}
|
||||
|
||||
|
@ -258,11 +252,11 @@ class HmRadio {
|
|||
|
||||
private:
|
||||
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
|
||||
//DBGHMR(F("hmRadio.h:sendPacket"));
|
||||
//DBGHMR("sent packet: #" + String(mSendCnt));
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendPacket"));
|
||||
//DPRINTLN(DBG_VERBOSE, "sent packet: #" + String(mSendCnt));
|
||||
//dumpBuf("SEN ", buf, len);
|
||||
if(mSerialDebug) {
|
||||
DPRINT("Transmit " + String(len) + " | ");
|
||||
DPRINT(DBG_INFO, "Transmit " + String(len) + " | ");
|
||||
dumpBuf(NULL, buf, len);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue