Browse Source

Merge branch 'main' into main

pull/63/head
lumapu 3 years ago
committed by GitHub
parent
commit
e0800bd87e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      tools/esp8266/app.cpp
  2. 2
      tools/esp8266/config.h
  3. 2
      tools/esp8266/defines.h
  4. 63
      tools/esp8266/hmRadio.h
  5. 4
      tools/esp8266/hmSystem.h
  6. 4
      tools/esp8266/main.cpp
  7. 3
      tools/esp8266/mqtt.h

9
tools/esp8266/app.cpp

@ -157,6 +157,8 @@ void app::loop(void) {
//app_loops++; //app_loops++;
Main::loop(); Main::loop();
mSys->Radio.loop();
if(checkTicker(&mRxTicker, 5)) { if(checkTicker(&mRxTicker, 5)) {
//DPRINTLN(F("app_loops =") + String(app_loops)); //DPRINTLN(F("app_loops =") + String(app_loops));
//app_loops=0; //app_loops=0;
@ -195,6 +197,7 @@ void app::loop(void) {
} }
mSys->BufCtrl.popBack(); mSys->BufCtrl.popBack();
yield();
} }
@ -319,6 +322,7 @@ bool app::buildPayload(uint8_t id) {
else else
crc = crc16(mPayload[id].data[i], mPayload[id].len[i], crc); crc = crc16(mPayload[id].data[i], mPayload[id].len[i], crc);
} }
yield();
} }
if(crc == crcRcv) if(crc == crcRcv)
return true; return true;
@ -353,7 +357,7 @@ void app::processPayload(bool retransmit) {
else else
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts); mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts);
} }
mSys->Radio.switchRxCh(100); mSys->Radio.switchRxCh(300);
} }
} }
else { else {
@ -364,6 +368,7 @@ void app::processPayload(bool retransmit) {
for(uint8_t i = 0; i < (mPayload[iv->id].maxPackId); i ++) { for(uint8_t i = 0; i < (mPayload[iv->id].maxPackId); i ++) {
memcpy(&payload[offs], mPayload[iv->id].data[i], (mPayload[iv->id].len[i])); memcpy(&payload[offs], mPayload[iv->id].data[i], (mPayload[iv->id].len[i]));
offs += (mPayload[iv->id].len[i]); offs += (mPayload[iv->id].len[i]);
yield();
} }
offs-=2; offs-=2;
if(mSerialDebug) { if(mSerialDebug) {
@ -379,6 +384,7 @@ void app::processPayload(bool retransmit) {
} }
} }
} }
yield();
} }
} }
@ -650,6 +656,7 @@ void app::showLiveData(void) {
} }
} }
modHtml += "</div>"; modHtml += "</div>";
yield();
} }
modHtml += F("<div class=\"ts\">Last received data requested at: ") + getDateTimeStr(iv->ts) + F("</div>"); modHtml += F("<div class=\"ts\">Last received data requested at: ") + getDateTimeStr(iv->ts) + F("</div>");
modHtml += F("</div>"); modHtml += F("</div>");

2
tools/esp8266/config.h

@ -21,7 +21,7 @@
// time during the ESP will act as access point on connection failure (to // time during the ESP will act as access point on connection failure (to
// station) in seconds // station) in seconds
#define WIFI_AP_ACTIVE_TIME 3*60 #define WIFI_AP_ACTIVE_TIME 60
// default device name // default device name
#define DEF_DEVICE_NAME "AHOY-DTU" #define DEF_DEVICE_NAME "AHOY-DTU"

2
tools/esp8266/defines.h

@ -16,7 +16,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 4 #define VERSION_MINOR 4
#define VERSION_PATCH 13 #define VERSION_PATCH 14
//------------------------------------- //-------------------------------------

63
tools/esp8266/hmRadio.h

@ -14,7 +14,8 @@
#define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL) #define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL)
#define RX_CHANNELS 5 #define RX_CHANNELS 5
#define RX_LOOP_CNT 400 #define RX_LOOP_CNT 600
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"}; const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
@ -70,6 +71,7 @@ class HmRadio {
mSendCnt = 0; mSendCnt = 0;
mSerialDebug = false; mSerialDebug = false;
mIrqRcvd = false;
} }
~HmRadio() {} ~HmRadio() {}
@ -107,32 +109,40 @@ class HmRadio {
} }
} }
void handleIntr(void) { void loop(void) {
DPRINTLN(F("hmRadio.h:handleIntr"));
uint8_t pipe, len;
packet_t *p;
DISABLE_IRQ; DISABLE_IRQ;
while(mNrf24.available(&pipe)) { if(mIrqRcvd) {
if(!mBufCtrl->full()) { mIrqRcvd = false;
p = mBufCtrl->getFront(); bool tx_ok, tx_fail, rx_ready;
memset(p->packet, 0xcc, MAX_RF_PAYLOAD_SIZE); mNrf24.whatHappened(tx_ok, tx_fail, rx_ready); // resets the IRQ pin to HIGH
p->rxCh = mRxChLst[mRxChIdx]; RESTORE_IRQ;
len = mNrf24.getPayloadSize(); uint8_t pipe, len;
if(len > MAX_RF_PAYLOAD_SIZE) packet_t *p;
len = MAX_RF_PAYLOAD_SIZE; while(mNrf24.available(&pipe)) {
if(!mBufCtrl->full()) {
mNrf24.read(p->packet, len); p = mBufCtrl->getFront();
mBufCtrl->pushFront(p); p->rxCh = mRxChLst[mRxChIdx];
} len = mNrf24.getPayloadSize();
else { if(len > MAX_RF_PAYLOAD_SIZE)
bool tx_ok, tx_fail, rx_ready; len = MAX_RF_PAYLOAD_SIZE;
mNrf24.whatHappened(tx_ok, tx_fail, rx_ready); // reset interrupt status
mNrf24.flush_rx(); // drop the packet mNrf24.read(p->packet, len);
break; mBufCtrl->pushFront(p);
}
else {
mNrf24.flush_rx(); // drop the packet
break;
}
yield();
} }
} }
RESTORE_IRQ; else
RESTORE_IRQ;
}
void handleIntr(void) {
DPRINTLN(F("hmRadio.h:handleIntr"));
mIrqRcvd = true;
} }
uint8_t getDefaultChannel(void) { uint8_t getDefaultChannel(void) {
@ -196,6 +206,7 @@ class HmRadio {
bool switchRxCh(uint8_t addLoop = 0) { bool switchRxCh(uint8_t addLoop = 0) {
//DPRINTLN(F("hmRadio.h:switchRxCh")); //DPRINTLN(F("hmRadio.h:switchRxCh"));
//DPRINT(F("R")); //DPRINT(F("R"));
mRxLoopCnt += addLoop; mRxLoopCnt += addLoop;
if(mRxLoopCnt != 0) { if(mRxLoopCnt != 0) {
mRxLoopCnt--; mRxLoopCnt--;
@ -278,6 +289,7 @@ class HmRadio {
} }
uint8_t getRxNxtChannel(void) { uint8_t getRxNxtChannel(void) {
if(++mRxChIdx >= RX_CHANNELS) if(++mRxChIdx >= RX_CHANNELS)
mRxChIdx = 0; mRxChIdx = 0;
return mRxChLst[mRxChIdx]; return mRxChLst[mRxChIdx];
@ -288,12 +300,15 @@ class HmRadio {
//uint8_t mTxChIdx; //uint8_t mTxChIdx;
uint8_t mRxChLst[RX_CHANNELS]; uint8_t mRxChLst[RX_CHANNELS];
uint8_t mRxChIdx; uint8_t mRxChIdx;
uint16_t mRxLoopCnt; uint16_t mRxLoopCnt;
RF24 mNrf24; RF24 mNrf24;
BUFFER *mBufCtrl; BUFFER *mBufCtrl;
uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE]; uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE];
volatile bool mIrqRcvd;
}; };
#endif /*__RADIO_H__*/ #endif /*__RADIO_H__*/

4
tools/esp8266/hmSystem.h

@ -38,8 +38,8 @@ class HmSystem {
p->id = mNumInv; p->id = mNumInv;
p->serial.u64 = serial; p->serial.u64 = serial;
memcpy(p->chMaxPwr, chMaxPwr, (4*2)); memcpy(p->chMaxPwr, chMaxPwr, (4*2));
DPRINT("SERIAL: " + String(p->serial.b[5], HEX)); //DPRINT("SERIAL: " + String(p->serial.b[5], HEX));
DPRINTLN(" " + String(p->serial.b[4], HEX)); //DPRINTLN(" " + String(p->serial.b[4], HEX));
if(p->serial.b[5] == 0x11) { if(p->serial.b[5] == 0x11) {
switch(p->serial.b[4]) { switch(p->serial.b[4]) {
case 0x21: p->type = INV_TYPE_1CH; break; case 0x21: p->type = INV_TYPE_1CH; break;

4
tools/esp8266/main.cpp

@ -108,10 +108,10 @@ void Main::loop(void) {
} }
} }
if(++mHeapStatCnt >= 10) { /*if(++mHeapStatCnt >= 10) {
mHeapStatCnt = 0; mHeapStatCnt = 0;
stats(); stats();
} }*/
} }
} }

3
tools/esp8266/mqtt.h

@ -38,7 +38,8 @@ class mqtt {
if(!mClient->connected()) if(!mClient->connected())
reconnect(); reconnect();
mClient->publish(top, msg); if(mClient->connected())
mClient->publish(top, msg);
} }
} }

Loading…
Cancel
Save