From 133d3ee0b085043c0f14a50bbec2a527ff06b3d9 Mon Sep 17 00:00:00 2001 From: habeIchVergessen Date: Thu, 24 Aug 2017 18:07:39 +0200 Subject: [PATCH 1/4] bugfix ccconf --- SIGNALESP/SIGNALESP.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SIGNALESP/SIGNALESP.ino b/SIGNALESP/SIGNALESP.ino index 072da9a..8c484d3 100644 --- a/SIGNALESP/SIGNALESP.ino +++ b/SIGNALESP/SIGNALESP.ino @@ -606,7 +606,7 @@ void HandleCommand() else if (cmdstring.charAt(1) == 'S') { configSET(); } -#ifdef comp_cc1101 +#ifdef CMP_CC1101 else if (isHexadecimalDigit(cmdstring.charAt(1)) && isHexadecimalDigit(cmdstring.charAt(2)) && hasCC1101) { reg = cmdstringPos2int(1); cc1101::readCCreg(reg); @@ -616,7 +616,7 @@ void HandleCommand() MSG_PRINTLN(F("Unsupported command")); } } -#ifdef comp_cc1101 +#ifdef CMP_CC1101 else if (cmdstring.charAt(0) == cmd_write) { // write EEPROM und CC11001 register if (cmdstring.charAt(1) == 'S' && cmdstring.charAt(2) == '3' && hasCC1101) { // WS Command Strobes cc1101::commandStrobes(); From 47635a43ebb4c96286ece4c16ce79dea8ab33a21 Mon Sep 17 00:00:00 2001 From: habeIchVergessen Date: Wed, 30 Aug 2017 21:53:49 +0200 Subject: [PATCH 2/4] bugfix ccconf (write EEPROM fixed) # Conflicts: # SIGNALESP/SIGNALESP.ino # src/_micro-api/libraries/signalDecoder/src/signalDecoder.cpp --- SIGNALESP/SIGNALESP.ino | 16 ++++++++++---- SIGNALESP/cc1101.h | 21 +++++++++++++++++++ .../signalDecoder/src/signalDecoder.cpp | 12 +++++------ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/SIGNALESP/SIGNALESP.ino b/SIGNALESP/SIGNALESP.ino index 8c484d3..110d4b0 100644 --- a/SIGNALESP/SIGNALESP.ino +++ b/SIGNALESP/SIGNALESP.ino @@ -18,6 +18,7 @@ #define BAUDRATE 115200 #define FIFO_LENGTH 200 #define DEBUG 1 +#define _CC1101_DEBUG_CONFIG #define ETHERNET_PRINT @@ -137,7 +138,7 @@ void setup() { cc1101::CCinit(); hasCC1101 = cc1101::checkCC1101(); if (hasCC1101) { - DBG_PRINTLN("CC1101 found"); + DBG_PRINTLN("CC1101 found (rev. 0" + String(cc1101::getRevision(), HEX) + ")"); musterDec.setRSSICallback(&cc1101::getRSSI); // Provide the RSSI Callback } else #endif @@ -247,6 +248,7 @@ void loop() { if (!command_available) { cmdstring = ""; } blinkLED = true; } + if (fifousage < FiFo.count()) fifousage = FiFo.count(); @@ -552,7 +554,7 @@ void HandleCommand() if (hasCC1101) { MSG_PRINT(F("cc1101")); switch(cc1101::chipVersion()) { -// case 0x08: // CC1101_VERSION 0x31 + case 0x08: // CC1101_VERSION 0x31 case 0x18: // CC1101_VERSION 0xF1 MSG_PRINT(F(" 433MHz")); break; @@ -560,6 +562,9 @@ void HandleCommand() case 0x14: // CC1101_VERSION 0xF1 MSG_PRINT(F(" 868MHz")); break; + default: + MSG_PRINT(" chip unknown 0x" + String(cc1101::chipVersion(), HEX)); + break; } } #endif @@ -624,7 +629,8 @@ void HandleCommand() else if (isHexadecimalDigit(cmdstring.charAt(1)) && isHexadecimalDigit(cmdstring.charAt(2)) && isHexadecimalDigit(cmdstring.charAt(3)) && isHexadecimalDigit(cmdstring.charAt(4))) { reg = cmdstringPos2int(1); val = cmdstringPos2int(3); - EEPROM.write(reg, val); + EEPROM.write(reg+1, val); // scheinbar hat sich hier etwas um 1 Byte verschoben + EEPROM.commit(); if (hasCC1101) { cc1101::writeCCreg(reg, val); } @@ -660,6 +666,7 @@ void HandleCommand() } else if (cmdstring.charAt(0) == cmd_ccFactoryReset && hasCC1101) { cc1101::ccFactoryReset(); + EEPROM.commit(); cc1101::CCinit(); } #endif @@ -745,7 +752,8 @@ inline void ethernetEvent() if (!serverClient || !serverClient.connected()) { if (serverClient) serverClient.stop(); serverClient = Server.available(); - DBG_PRINTLN("New client: "); + DBG_PRINT("New client: "); + DBG_PRINTLN(serverClient.remoteIP()); return; } //no free/disconnected spot so reject diff --git a/SIGNALESP/cc1101.h b/SIGNALESP/cc1101.h index 5684084..cefe42b 100644 --- a/SIGNALESP/cc1101.h +++ b/SIGNALESP/cc1101.h @@ -188,6 +188,11 @@ namespace cc1101 { 0x00, // 28 RCCTRL0 }; + // prototypes +#ifdef _CC1101_DEBUG_CONFIG + void dumpConfigRegister(); +#endif + byte hex2int(byte hex) { // convert a hexdigit to int // Todo: printf oder scanf nutzen if (hex >= '0' && hex <= '9') hex = hex - '0'; else if (hex >= 'a' && hex <= 'f') hex = hex - 'a' + 10; @@ -386,6 +391,7 @@ namespace cc1101 { EEPROM.write(EE_CC1100_PA + i, 0); } } + EEPROM.commit(); MSG_PRINTLN("ccFactoryReset done"); } @@ -491,6 +497,9 @@ namespace cc1101 { DBG_PRINTLN("POR Done"); delay(10); +#ifdef _CC1101_DEBUG_CONFIG + dumpConfigRegister(); +#endif cc1101_Select(); sendSPI(CC1100_WRITE_BURST); @@ -506,6 +515,18 @@ namespace cc1101 { setReceiveMode(); } +#ifdef _CC1101_DEBUG_CONFIG + void dumpConfigRegister() { + Serial.printf("\ndump config register:\n"); + for (byte i=0; i<0x28; i++) { + Serial.printf("%02X ", readReg(i, CC1101_CONFIG)); + if (i % 16 == 15) + Serial.printf("\n"); + } + Serial.printf("\n"); + } +#endif + bool regCheck() { diff --git a/src/_micro-api/libraries/signalDecoder/src/signalDecoder.cpp b/src/_micro-api/libraries/signalDecoder/src/signalDecoder.cpp index 0ba1677..c314535 100644 --- a/src/_micro-api/libraries/signalDecoder/src/signalDecoder.cpp +++ b/src/_micro-api/libraries/signalDecoder/src/signalDecoder.cpp @@ -105,7 +105,8 @@ inline void SignalDetectorClass::doDetect() } else if (messageLen == minMessageLen) { state = detecting; // Set state to detecting, because we have more than minMessageLen data gathered, so this is no noise - rssiValue = _rssiCallback(); + if (_rssiCallback != NULL) // don't call uninitialized function pointer + rssiValue = _rssiCallback(); } int8_t fidx = findpatt(*first); @@ -338,7 +339,7 @@ void SignalDetectorClass::processMessage() } if ((mstart & 1) == 1) { // ungerade mstart--; - (message.getByte(mstart / 2, &n) & 15) | 128; // high nibble = 8 als Kennzeichen für ungeraden mstart + (message.getByte(mstart / 2, &n) & 15) | 128; // high nibble = 8 als Kennzeichen für ungeraden mstart MSG_WRITE(n); mstart += 2; } @@ -610,7 +611,7 @@ void SignalDetectorClass::processMessage() #endif } } - if (!m_truncated) // Todo: Eventuell auf vollen Puffer prüfen + if (!m_truncated) // Todo: Eventuell auf vollen Puffer prüfen { reset(); } @@ -792,7 +793,7 @@ bool SignalDetectorClass::getClock() bool SignalDetectorClass::getSync() { - // Durchsuchen aller Musterpulse und prueft ob darin ein Sync Faktor enthalten ist. Anschließend wird verifiziert ob dieser Syncpuls auch im Signal nacheinander uebertragen wurde + // Durchsuchen aller Musterpulse und prueft ob darin ein Sync Faktor enthalten ist. Anschließend wird verifiziert ob dieser Syncpuls auch im Signal nacheinander uebertragen wurde // #if DEBUGDETECT > 3 DBG_PRINTLN(" -- Searching Sync -- "); @@ -1270,7 +1271,7 @@ const bool ManchesterpatternDecoder::doDecode() { #endif //pdec->printOut(); - pdec->bufferMove(i); // Todo: BufferMove könnte in die Serielle Ausgabe verschoben werden, das würde ein paar Mikrosekunden Zeit sparen + pdec->bufferMove(i); // Todo: BufferMove könnte in die Serielle Ausgabe verschoben werden, das würde ein paar Mikrosekunden Zeit sparen //pdec->m_truncated = true; // Flag that we truncated the message array and want to receiver some more data mc_start_found = false; // This will break serval unit tests. Normaly setting this to false shoud be done by reset, needs to be checked if reset shoud be called after hex string is printed out @@ -1316,7 +1317,6 @@ const bool ManchesterpatternDecoder::doDecode() { } //MSG_PRINT(" S MC "); i++; - yield(); } pdec->mend = i - (ht ? 0 : 1); // keep short in buffer; From 17e18fde39c8c06d7dd7d0909a7ba43af137d59b Mon Sep 17 00:00:00 2001 From: habeIchVergessen Date: Sun, 3 Sep 2017 22:43:32 +0200 Subject: [PATCH 3/4] signalDecoder - remove yield() # Conflicts: # SIGNALESP/SIGNALESP.ino --- SIGNALESP/SIGNALESP.ino | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/SIGNALESP/SIGNALESP.ino b/SIGNALESP/SIGNALESP.ino index 110d4b0..fa3fdb4 100644 --- a/SIGNALESP/SIGNALESP.ino +++ b/SIGNALESP/SIGNALESP.ino @@ -18,7 +18,10 @@ #define BAUDRATE 115200 #define FIFO_LENGTH 200 #define DEBUG 1 -#define _CC1101_DEBUG_CONFIG + + + + #define ETHERNET_PRINT @@ -140,9 +143,8 @@ void setup() { if (hasCC1101) { DBG_PRINTLN("CC1101 found (rev. 0" + String(cc1101::getRevision(), HEX) + ")"); musterDec.setRSSICallback(&cc1101::getRSSI); // Provide the RSSI Callback - } else -#endif - musterDec.setRSSICallback(&rssiCallback); // Provide the RSSI Callback + } +#endif #ifdef DEBUG Serial.printf("\nTry connecting to WiFi with SSID '%s'\n", WiFi.SSID().c_str()); @@ -214,12 +216,12 @@ void setup() { os_timer_setfn(&cronTimer, cronjob, NULL); os_timer_arm(&cronTimer, 31, true); -#ifdef comp_cc1101 +#ifdef CMP_CC1101 if (!hasCC1101 || cc1101::regCheck()) { #endif enableReceive(); DBG_PRINTLN(F("receiver enabled")); -#ifdef comp_cc1101 +#ifdef CMP_CC1101 } else { DBG_PRINTLN(F("cc1101 is not correctly set. Please do a factory reset via command e")); } @@ -760,7 +762,7 @@ inline void ethernetEvent() // WiFiClient newClient = Server.available(); // newClient.stop(); } - yield(); +// yield(); } void serialEvent() From 21606b205062162591694e6e19be15053f6e4768 Mon Sep 17 00:00:00 2001 From: habeIchVergessen Date: Tue, 22 Aug 2017 12:40:06 +0200 Subject: [PATCH 4/4] hardware revision (cherry picked from commit 8c36432968b0f33f6a67e152f8998909bebeb45d) # Conflicts: # SIGNALESP/SIGNALESP.ino # SIGNALESP/cc1101.h --- SIGNALESP/SIGNALESP.ino | 4 +++ SIGNALESP/cc1101.h | 68 +++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/SIGNALESP/SIGNALESP.ino b/SIGNALESP/SIGNALESP.ino index fa3fdb4..3f07030 100644 --- a/SIGNALESP/SIGNALESP.ino +++ b/SIGNALESP/SIGNALESP.ino @@ -128,6 +128,10 @@ void setup() { Serial.println("\n\n"); +#ifdef DEBUG + Serial.println("SPI: MOSI " + String(MOSI) + ", MISO " + String(MISO) + ", SCK " + String(SCK) + ", CS " + String(SS)); +#endif + pinMode(PIN_RECEIVE, INPUT); pinMode(PIN_LED, OUTPUT); diff --git a/SIGNALESP/cc1101.h b/SIGNALESP/cc1101.h index cefe42b..67cbe51 100644 --- a/SIGNALESP/cc1101.h +++ b/SIGNALESP/cc1101.h @@ -48,11 +48,18 @@ namespace cc1101 { #define CC1100_IOCFG2 0x00 // GDO2 output configuration #define CC1100_PKTCTRL0 0x08 // Packet config register - // Status registers - older version base on 0x30 - #define CC1101_PARTNUM 0xF0 // Chip ID - #define CC1101_VERSION 0xF1 // Chip ID - #define CC1100_RSSI 0xF4 // Received signal strength indication - #define CC1100_MARCSTATE 0xF5 // Control state machine state + uint8_t revision = 0x01; + + // Status registers - newer version base on 0xF0 + #define CC1101_PARTNUM_REV01 0xF0 // Chip ID + #define CC1101_VERSION_REV01 0xF1 // Chip ID + #define CC1100_RSSI_REV01 0xF4 // Received signal strength indication + #define CC1100_MARCSTATE_REV01 0xF5 // Control state machine state + // Status registers - older version base on 0x30 + #define CC1101_PARTNUM_REV00 0x30 // Chip ID + #define CC1101_VERSION_REV00 0x31 // Chip ID + #define CC1100_RSSI_REV00 0x34 // Received signal strength indication + #define CC1100_MARCSTATE_REV00 0x35 // Control state machine state // Strobe commands #define CC1101_SRES 0x30 // reset @@ -188,11 +195,8 @@ namespace cc1101 { 0x00, // 28 RCCTRL0 }; - // prototypes -#ifdef _CC1101_DEBUG_CONFIG - void dumpConfigRegister(); -#endif - + + byte hex2int(byte hex) { // convert a hexdigit to int // Todo: printf oder scanf nutzen if (hex >= '0' && hex <= '9') hex = hex - '0'; else if (hex >= 'a' && hex <= 'f') hex = hex - 'a' + 10; @@ -391,15 +395,30 @@ namespace cc1101 { EEPROM.write(EE_CC1100_PA + i, 0); } } - EEPROM.commit(); + EEPROM.commit(); MSG_PRINTLN("ccFactoryReset done"); } - uint8_t chipVersion() { return readReg(CC1101_VERSION, CC1101_READ_SINGLE); }; + uint8_t chipVersionRev() + { + return readReg((revision == 0x01 ? CC1101_VERSION_REV01 : CC1101_VERSION_REV00), CC1101_READ_SINGLE); + }; + + uint8_t chipVersion() { + uint8_t version = chipVersionRev(); + + if (revision != 0x00 && (version == 0xFF || version == 0x00)) { + revision = 0x00; + version = chipVersionRev(); + } + + return version; + } + bool checkCC1101() { - uint8_t partnum = readReg(CC1101_PARTNUM, CC1101_READ_SINGLE); // Partnum uint8_t version = chipVersion(); // Version + uint8_t partnum = readReg((revision == 0x01 ? CC1101_PARTNUM_REV01 : CC1101_PARTNUM_REV00), CC1101_READ_SINGLE); // Partnum DBG_PRINT("CCVersion="); DBG_PRINTLN("0x" + String(version, HEX)); DBG_PRINT("CCPartnum="); DBG_PRINTLN("0x" + String(partnum, HEX)); @@ -444,9 +463,10 @@ namespace cc1101 { pinAsOutput(PIN_SEND); // gdo0Pi, sicherheitshalber bis zum CC1101 init erstmal input } + uint8_t getRevision() { return revision; } uint8_t getRSSI() { - return readReg(CC1100_RSSI, CC1101_STATUS);// Pruefen ob Umwandung von uint to int den richtigen Wert zurueck gibt + return readReg((revision == 0x01 ? CC1100_RSSI_REV01 : CC1100_RSSI_REV00), CC1101_STATUS);// Pruefen ob Umwandung von uint to int den richtigen Wert zurueck gibt } inline void setIdleMode() @@ -456,7 +476,7 @@ namespace cc1101 { } uint8_t currentMode() { - return readReg(CC1100_MARCSTATE, CC1100_READ_BURST); + return readReg((revision == 0x01 ? CC1100_MARCSTATE_REV01 : CC1100_MARCSTATE_REV00), CC1100_READ_BURST); } void setReceiveMode() @@ -497,9 +517,7 @@ namespace cc1101 { DBG_PRINTLN("POR Done"); delay(10); -#ifdef _CC1101_DEBUG_CONFIG - dumpConfigRegister(); -#endif + cc1101_Select(); sendSPI(CC1100_WRITE_BURST); @@ -515,18 +533,8 @@ namespace cc1101 { setReceiveMode(); } -#ifdef _CC1101_DEBUG_CONFIG - void dumpConfigRegister() { - Serial.printf("\ndump config register:\n"); - for (byte i=0; i<0x28; i++) { - Serial.printf("%02X ", readReg(i, CC1101_CONFIG)); - if (i % 16 == 15) - Serial.printf("\n"); - } - Serial.printf("\n"); - } -#endif - + + bool regCheck() {