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

WIP: Ethernet / Serial output via callback #11

Open
wants to merge 4 commits into
base: dev-cc1101-cb
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
38 changes: 26 additions & 12 deletions SIGNALESP/SIGNALESP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#define DEBUG 1






#define ETHERNET_PRINT
#include <EEPROM.h>
#include <ESP8266WiFi.h>
Expand Down Expand Up @@ -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);

Expand All @@ -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());
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -247,6 +254,7 @@ void loop() {
if (!command_available) { cmdstring = ""; }
blinkLED = true;
}

if (fifousage < FiFo.count())
fifousage = FiFo.count();

Expand Down Expand Up @@ -552,14 +560,17 @@ 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;
case 0x04: // CC1101_VERSION 0x31
case 0x14: // CC1101_VERSION 0xF1
MSG_PRINT(F(" 868MHz"));
break;
default:
MSG_PRINT(" chip unknown 0x" + String(cc1101::chipVersion(), HEX));
break;
}
}
#endif
Expand Down Expand Up @@ -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);
Expand All @@ -616,15 +627,16 @@ 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<reg> Command Strobes
cc1101::commandStrobes();
}
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);
}
Expand Down Expand Up @@ -660,6 +672,7 @@ void HandleCommand()
}
else if (cmdstring.charAt(0) == cmd_ccFactoryReset && hasCC1101) {
cc1101::ccFactoryReset();
EEPROM.commit();
cc1101::CCinit();
}
#endif
Expand Down Expand Up @@ -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()
Expand Down
47 changes: 38 additions & 9 deletions SIGNALESP/cc1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -491,6 +517,7 @@ namespace cc1101 {
DBG_PRINTLN("POR Done");
delay(10);


cc1101_Select();

sendSPI(CC1100_WRITE_BURST);
Expand All @@ -506,6 +533,8 @@ namespace cc1101 {
setReceiveMode();
}



bool regCheck()
{

Expand Down
12 changes: 6 additions & 6 deletions src/_micro-api/libraries/signalDecoder/src/signalDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 -- ");
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -1316,7 +1317,6 @@ const bool ManchesterpatternDecoder::doDecode() {
}
//MSG_PRINT(" S MC ");
i++;
yield();
}
pdec->mend = i - (ht ? 0 : 1); // keep short in buffer;

Expand Down