Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension for receiving WMBus messages #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 46 additions & 24 deletions src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ extern SignalDetectorClass musterDec;
extern volatile bool blinkLED;
extern uint8_t ccmode;; // xFSK
#ifdef CMP_CC1101
extern bool AfcEnabled;
extern bool AfcEnabled;
#if defined (ESP8266) || defined (ESP32)
extern bool wmbus;
extern bool wmbus_t;
#endif
#endif

namespace commands {
Expand All @@ -69,34 +73,41 @@ namespace commands {
}
}

/*
void printHex2(const byte hex) { // Todo: printf oder scanf nutzen <<<<----- printf benoetigt mehr Speicher als diese Variante
if (hex < 16) {
MSG_PRINT("0");
}
MSG_PRINT(hex, HEX);
}
*/

inline void getConfig()
{
MSG_PRINT(F("MS="));
MSG_PRINT(musterDec.MSenabled, DEC);
MSG_PRINT(F(";MU="));
MSG_PRINT(musterDec.MUenabled, DEC);
MSG_PRINT(F(";MC="));
MSG_PRINT(musterDec.MCenabled, DEC);
#ifdef CMP_CC1101
if (cc1101::ccmode != 3) { // ASK/OOK = 3 (default)
MSG_PRINT(F(";MN=1;AFC="));
MSG_PRINT(AfcEnabled, DEC);
if (cc1101::ccmode == 3) { // ASK/OOK = 3 (default)
MSG_PRINT(F("MS="));
MSG_PRINT(musterDec.MSenabled, DEC);
MSG_PRINT(F(";MU="));
MSG_PRINT(musterDec.MUenabled, DEC);
MSG_PRINT(F(";MC="));
MSG_PRINT(musterDec.MCenabled, DEC);
MSG_PRINT(F(";Mred="));
MSG_PRINTLN(musterDec.MredEnabled, DEC);
} else { // FSK
MSG_PRINT(F("MN=1"));
#if defined (ESP8266) || defined (ESP32)
MSG_PRINT(F(";WMBus="));
MSG_PRINT(wmbus, DEC);
MSG_PRINT(F(";WMBus_T="));
MSG_PRINT(wmbus_t, DEC);
#endif
MSG_PRINT(F(";AFC="));
MSG_PRINTLN(AfcEnabled, DEC);
}
#else
MSG_PRINT(F("MS="));
MSG_PRINT(musterDec.MSenabled, DEC);
MSG_PRINT(F(";MU="));
MSG_PRINT(musterDec.MUenabled, DEC);
MSG_PRINT(F(";MC="));
MSG_PRINT(musterDec.MCenabled, DEC);
MSG_PRINT(F(";Mred="));
MSG_PRINTLN(musterDec.MredEnabled, DEC);
#endif
MSG_PRINT(F(";Mred="));
MSG_PRINTLN(musterDec.MredEnabled, DEC);
}


inline void configCMD()
{
bool *bptr;
Expand All @@ -119,6 +130,14 @@ namespace commands {
case 'A' : //Afc
bptr = &AfcEnabled;
break;
#if defined (ESP8266) || defined (ESP32)
case 'W' : //WMBus
bptr = &wmbus;
break;
case 'T' : //WMBus_T
bptr = &wmbus_t;
break;
#endif
#endif
default:
return;
Expand All @@ -135,8 +154,11 @@ namespace commands {
default:
return;
}

storeFunctions(musterDec.MSenabled, musterDec.MUenabled, musterDec.MCenabled, musterDec.MredEnabled, AfcEnabled);
#if defined (CMP_CC1101) && (defined (ESP8266) || defined (ESP32))
storeFunctions(musterDec.MSenabled, musterDec.MUenabled, musterDec.MCenabled, musterDec.MredEnabled, AfcEnabled, wmbus, wmbus_t);
#else
storeFunctions(musterDec.MSenabled, musterDec.MUenabled, musterDec.MCenabled, musterDec.MredEnabled, AfcEnabled);
#endif
}

inline void configSET()
Expand Down
8 changes: 4 additions & 4 deletions src/compile_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
#define PIN_RECEIVE 3
#define PIN_MARK433 A0
#elif ARDUINO_MAPLEMINI_F103CB
const uint8_t pinReceive[] = {11, 18, 16, 14}; // compatible to variant -> Circuit board for four connected cc110x devices
// https://wiki.fhem.de/wiki/Maple-SignalDuino - CC1101_1 (B) - 433 MHz für OOK/ASK
#define PIN_LED 33
#define PIN_SEND 17 // GDO Pin TX out
#define PIN_RECEIVE pinReceive[1] // GDO2
#define PIN_WIZ_RST 27 // for LAN
#define PIN_SEND 17 // GD00 (send)
#define PIN_RECEIVE 18 // GD02 (Receive)
#define PIN_WIZ_RST 27 // for LAN
#elif defined(ESP8266)
#define PIN_RECEIVE 5 // D1
#define PIN_LED 16 // some boards have no LED or this LED has a different PIN defined
Expand Down
59 changes: 47 additions & 12 deletions src/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
extern void DBG_PRINTtoHEX(uint8_t b);
extern bool AfcEnabled;
#ifdef CMP_CC1101
extern int8_t cc1101::freqOffAcc;
extern float cc1101::freqErrAvg;
#if defined (ESP8266) || defined (ESP32)
extern bool wmbus;
extern bool wmbus_t;
#endif
extern int8_t cc1101::freqOffAcc;
extern float cc1101::freqErrAvg;
#endif

#define pulseMin 90
Expand Down Expand Up @@ -100,33 +104,56 @@ void disableReceive() {


//================================= EEProm commands ======================================
void storeFunctions(const int8_t ms, int8_t mu, int8_t mc, int8_t red, int8_t afc) {
#if defined (CMP_CC1101) && (defined (ESP8266) || defined (ESP32))
void storeFunctions(const int8_t ms, int8_t mu, int8_t mc, int8_t red, int8_t afc, int8_t wmbus, int8_t wmbus_t) {
#else
void storeFunctions(const int8_t ms, int8_t mu, int8_t mc, int8_t red, int8_t afc) {
#endif
#ifdef CMP_CC1101
if (afc == 0) { // reset AFC
cc1101::freqOffAcc = 0;
cc1101::freqErrAvg = 0;
cc1101::writeReg(static_cast<uint8_t>(0x0C), static_cast<uint8_t>(afc) ); // reset 0x0C: FSCTRL0 – Frequency Synthesizer Control
}
if (afc == 0) { // reset AFC
cc1101::freqOffAcc = 0;
cc1101::freqErrAvg = 0;
cc1101::writeReg(static_cast<uint8_t>(0x0C), static_cast<uint8_t>(afc) ); // reset 0x0C: FSCTRL0 – Frequency Synthesizer Control
}
#if defined (ESP8266) || defined (ESP32)
if (wmbus == 1) { // WMBus
mbus_init(wmbus_t + 1); // WMBus mode S or T
}
#endif
#endif
mu = mu << 1;
mc = mc << 2;
red = red << 3;
afc = afc << 4;
int8_t dat = ms | mu | mc | red | afc;
#if defined (CMP_CC1101) && (defined (ESP8266) || defined (ESP32))
wmbus = wmbus << 5;
wmbus_t = wmbus_t << 6;
int8_t dat = ms | mu | mc | red | afc | wmbus | wmbus_t;
#else
int8_t dat = ms | mu | mc | red | afc;
#endif
EEPROM.write(addr_features, dat);
#if defined(ESP8266) || defined(ESP32)
EEPROM.commit();
#endif
}

void getFunctions(bool *ms, bool *mu, bool *mc, bool *red, bool *afc) {
#if defined (CMP_CC1101) && (defined (ESP8266) || defined (ESP32))
void getFunctions(bool *ms, bool *mu, bool *mc, bool *red, bool *afc, bool *wmbus, bool *wmbus_t) {
#else
void getFunctions(bool *ms, bool *mu, bool *mc, bool *red, bool *afc) {
#endif
int8_t dat = EEPROM.read(addr_features);

*ms = bool(dat &(1 << 0));
*mu = bool(dat &(1 << 1));
*mc = bool(dat &(1 << 2));
*red = bool(dat &(1 << 3));
*afc = bool(dat &(1 << 4));
#if defined (CMP_CC1101) && (defined (ESP8266) || defined (ESP32))
*wmbus = bool(dat &(1 << 5));
*wmbus_t = bool(dat &(1 << 6));
#endif
}

void dumpEEPROM() {
Expand All @@ -149,7 +176,11 @@ void initEEPROM(void) {
if (EEPROM.read(EE_MAGIC_OFFSET) == VERSION_1 && EEPROM.read(EE_MAGIC_OFFSET + 1) == VERSION_2) {
DBG_PRINT(F("Reading values from ")); DBG_PRINT(FPSTR(TXT_EEPROM)); DBG_PRINT(FPSTR(TXT_DOT)); DBG_PRINT(FPSTR(TXT_DOT));
} else {
storeFunctions(1, 1, 1, 1, 0); // Init EEPROM with all flags enabled, AFC disabled
#if defined (CMP_CC1101) && (defined (ESP8266) || defined (ESP32))
storeFunctions(1, 1, 1, 1, 0, 0, 0); // Init EEPROM with all flags enabled, AFC, WMBus and WMBus_T disabled
#else
storeFunctions(1, 1, 1, 1, 0); // Init EEPROM with all flags enabled, AFC disabled
#endif
//hier fehlt evtl ein getFunctions()
MSG_PRINTLN(F("Init eeprom to defaults after flash"));
EEPROM.write(EE_MAGIC_OFFSET, VERSION_1);
Expand All @@ -162,7 +193,11 @@ void initEEPROM(void) {
EEPROM.commit();
#endif
}
getFunctions(&musterDec.MSenabled, &musterDec.MUenabled, &musterDec.MCenabled, &musterDec.MredEnabled, &AfcEnabled);
#if defined (CMP_CC1101) && (defined (ESP8266) || defined (ESP32))
getFunctions(&musterDec.MSenabled, &musterDec.MUenabled, &musterDec.MCenabled, &musterDec.MredEnabled, &AfcEnabled, &wmbus, &wmbus_t);
#else
getFunctions(&musterDec.MSenabled, &musterDec.MUenabled, &musterDec.MCenabled, &musterDec.MredEnabled, &AfcEnabled);
#endif
DBG_PRINTLN(F("done"));
dumpEEPROM();
}
Expand Down
Loading