diff --git a/SIGNALESP/SIGNALESP.ino b/SIGNALESP/SIGNALESP.ino index 072da9a..3f07030 100644 --- a/SIGNALESP/SIGNALESP.ino +++ b/SIGNALESP/SIGNALESP.ino @@ -20,6 +20,10 @@ #define DEBUG 1 + + + + #define ETHERNET_PRINT #include #include @@ -124,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); @@ -137,11 +145,10 @@ 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 - musterDec.setRSSICallback(&rssiCallback); // Provide the RSSI Callback + } +#endif #ifdef DEBUG Serial.printf("\nTry connecting to WiFi with SSID '%s'\n", WiFi.SSID().c_str()); @@ -213,12 +220,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")); } @@ -247,6 +254,7 @@ void loop() { if (!command_available) { cmdstring = ""; } blinkLED = true; } + if (fifousage < FiFo.count()) fifousage = FiFo.count(); @@ -552,7 +560,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 +568,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 @@ -606,7 +617,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 +627,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(); @@ -624,7 +635,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 +672,7 @@ void HandleCommand() } else if (cmdstring.charAt(0) == cmd_ccFactoryReset && hasCC1101) { cc1101::ccFactoryReset(); + EEPROM.commit(); cc1101::CCinit(); } #endif @@ -745,14 +758,15 @@ 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 // WiFiClient newClient = Server.available(); // newClient.stop(); } - yield(); +// yield(); } void serialEvent() diff --git a/SIGNALESP/cc1101.h b/SIGNALESP/cc1101.h index 5684084..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,6 +195,8 @@ namespace cc1101 { 0x00, // 28 RCCTRL0 }; + + 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,14 +395,30 @@ namespace cc1101 { EEPROM.write(EE_CC1100_PA + i, 0); } } + 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)); @@ -438,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() @@ -450,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() @@ -491,6 +517,7 @@ namespace cc1101 { DBG_PRINTLN("POR Done"); delay(10); + cc1101_Select(); sendSPI(CC1100_WRITE_BURST); @@ -506,6 +533,8 @@ namespace cc1101 { setReceiveMode(); } + + 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;