From de17f95f87588e1068d55023ecf036a7c6e41e09 Mon Sep 17 00:00:00 2001 From: NBSgamesAT Date: Thu, 7 May 2020 18:04:38 +0200 Subject: [PATCH] Added Frequency reading. Also install new libraryies in README.md --- .gitignore | 5 ++++ README.md | 2 ++ src/main.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/README.md b/README.md index e69de29..c93203e 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,2 @@ +# Libraries: +SoftwareSerial (pio lib install 7212) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0d56f86..4fbdec1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,90 @@ #include +#include +SoftwareSerial ft817 = SoftwareSerial(2, 3); +String getMode(uint8_t byte); +unsigned long bcdtoi(uint8_t bcd); void setup() { // put your setup code here, to run once: + ft817.begin(9600); + Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: + uint8_t bytes[] = {0x00,0x00,0x00,0x00,0x03}; + + for (unsigned int i = 0; i < sizeof(bytes); i++){ + ft817.write(bytes[i]); + Serial.print(String(bytes[i])); + delay(1); + } + Serial.println(); + uint8_t buffer[5]; + ft817.readBytes(&buffer[0], sizeof(buffer)); + + String mode = getMode(buffer[4]); + + //int freq = getFreq(buffer[0], buffer[1], buffer[2], buffer[3]); + /*char buf[10]; + for(int i = 0; i<4; i++) { + snprintf(buf, sizeof(buf), "%x ", buffer[i]); + Serial.print(buf); + }*/ + + //Serial.println(); + unsigned long actualFrequency = 0; + actualFrequency = bcdtoi(buffer[0]) * 1000000; + actualFrequency += (bcdtoi(buffer[1]) * 10000); + actualFrequency += (bcdtoi(buffer[2]) * 100); + actualFrequency += bcdtoi(buffer[3]); + + + Serial.print(actualFrequency); + + Serial.write(0x20); + Serial.println(mode); + + delay(2000); + //String freq = Serial.readString(); + + +} + +String getMode(uint8_t byte){ + switch (byte) + { + case 0x00: + return "LSB"; + break; + case 0x01: + return "USB"; + break; + case 0x02: + return "CW"; + case 0x03: + return "CWR"; + case 0x04: + return "AM"; + case 0x06: + return "WFM"; + case 0x08: + return "FM"; + case 0x0A: + return "DIG"; + case 0x0C: + return "PKT"; + default: + return "IDENTIFICATION FAILURE"; + break; + } +} + +unsigned long bcdtoi(uint8_t bcd){ + int byte = (bcd & 0xF0) >> 4; + byte *= 10; + byte += bcd & 0x0F; + return byte; } \ No newline at end of file