Skip to content

Commit

Permalink
first changes to prepare code for esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
a-marcel committed Aug 15, 2022
1 parent 6ac3876 commit 1200ca0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tools/esp8266/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,12 @@ bool app::buildPayload(uint8_t id) {
for(uint8_t i = 0; i < mPayload[id].maxPackId; i ++) {
if(mPayload[id].len[i] > 0) {
if(i == (mPayload[id].maxPackId-1)) {
crc = crc16(mPayload[id].data[i], mPayload[id].len[i] - 2, crc);
crc = Hoymiles::crc16(mPayload[id].data[i], mPayload[id].len[i] - 2, crc);
crcRcv = (mPayload[id].data[i][mPayload[id].len[i] - 2] << 8)
| (mPayload[id].data[i][mPayload[id].len[i] - 1]);
}
else
crc = crc16(mPayload[id].data[i], mPayload[id].len[i], crc);
crc = Hoymiles::crc16(mPayload[id].data[i], mPayload[id].len[i], crc);
}
yield();
}
Expand Down
2 changes: 1 addition & 1 deletion tools/esp8266/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class app {
while(length > 0) {
len = (length < 32) ? length : 32;
mEep->read(start, buf, len);
crc = crc16(buf, len, crc);
crc = Hoymiles::crc16(buf, len, crc);
start += len;
length -= len;
}
Expand Down
3 changes: 3 additions & 0 deletions tools/esp8266/crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "crc.h"

namespace Hoymiles {

uint8_t crc8(uint8_t buf[], uint8_t len) {
uint8_t crc = CRC8_INIT;
for(uint8_t i = 0; i < len; i++) {
Expand Down Expand Up @@ -33,3 +35,4 @@ uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
}
return crc;
}
} // namespace Hoymiles
7 changes: 5 additions & 2 deletions tools/esp8266/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

#define CRC16_MODBUS_POLYNOM 0xA001

uint8_t crc8(uint8_t buf[], uint8_t len);
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff);
namespace Hoymiles {

uint8_t crc8(uint8_t buf[], uint8_t len);
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff);

}
#endif /*__CRC_H__*/
16 changes: 11 additions & 5 deletions tools/esp8266/hmRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ template <uint8_t CE_PIN, uint8_t CS_PIN, class BUFFER, uint64_t DTU_ID=DTU_RADI
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) + ")");
DPRINT(DBG_VERBOSE, F("hmRadio.h : HmRadio():mNrf24(CE_PIN: "));
DPRINT(DBG_VERBOSE, String(CE_PIN));
DPRINT(DBG_VERBOSE, F(", CS_PIN: "));
DPRINT(DBG_VERBOSE, String(CS_PIN));
DPRINT(DBG_VERBOSE, F(", SPI_SPEED: "));
DPRINTLN(DBG_VERBOSE, String(SPI_SPEED) + ")");

// Depending on the program, the module can work on 2403, 2423, 2440, 2461 or 2475MHz.
// Channel List 2403, 2423, 2440, 2461, 2475MHz
Expand Down Expand Up @@ -101,7 +106,8 @@ class HmRadio {
// enable only receiving interrupts
mNrf24.maskIRQ(true, true, false);

DPRINTLN(DBG_INFO, F("RF24 Amp Pwr: RF24_PA_") + String(rf24AmpPowerNames[config->amplifierPower]));
DPRINT(DBG_INFO, F("RF24 Amp Pwr: RF24_PA_"));
DPRINTLN(DBG_INFO, String(rf24AmpPowerNames[config->amplifierPower]));
mNrf24.setPALevel(config->amplifierPower & 0x03);
mNrf24.startListening();

Expand Down Expand Up @@ -180,12 +186,12 @@ class HmRadio {
mTxBuf[10 + (++cnt)] = (powerLimitSetting ) & 0xff; // setting for persistens handling
}
// crc control data
uint16_t crc = crc16(&mTxBuf[10], cnt+1);
uint16_t crc = Hoymiles::crc16(&mTxBuf[10], cnt+1);
mTxBuf[10 + (++cnt)] = (crc >> 8) & 0xff;
mTxBuf[10 + (++cnt)] = (crc ) & 0xff;
// crc over all
cnt +=1;
mTxBuf[10 + cnt] = crc8(mTxBuf, 10 + cnt);
mTxBuf[10 + cnt] = Hoymiles::crc8(mTxBuf, 10 + cnt);

sendPacket(invId, mTxBuf, 10 + (++cnt), true);
}
Expand All @@ -204,7 +210,7 @@ class HmRadio {
mTxBuf[18] = 0x00;
mTxBuf[19] = 0x00;
}
uint16_t crc = crc16(&mTxBuf[10], 14);
uint16_t crc = Hoymiles::crc16(&mTxBuf[10], 14);
mTxBuf[24] = (crc >> 8) & 0xff;
mTxBuf[25] = (crc ) & 0xff;
mTxBuf[26] = crc8(mTxBuf, 26);
Expand Down
5 changes: 4 additions & 1 deletion tools/esp8266/hmSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class HmSystem {
case 0x21: p->type = INV_TYPE_1CH; break;
case 0x41: p->type = INV_TYPE_2CH; break;
case 0x61: p->type = INV_TYPE_4CH; break;
default: DPRINTLN(DBG_ERROR, F("unknown inverter type: 11") + String(p->serial.b[4], HEX)); break;
default:
DPRINT(DBG_ERROR, F("unknown inverter type: 11"));
DPRINTLN(DBG_ERROR, String(p->serial.b[4], HEX));
break;
}
}
else
Expand Down

0 comments on commit 1200ca0

Please sign in to comment.