diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 0f40e620..bbd5f626 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -329,14 +329,26 @@ bool processSerialCommand(String cmd_str) { } // end of ir commands if(cmd_str.startsWith("rf") || cmd_str.startsWith("subghz" )) { - - if(cmd_str.startsWith("subghz rx")) { + + if(cmd_str.startsWith("subghz rx")) { + /* const char* args = cmd_str.c_str() + strlen("subghz rx"); float frequency=RfFreq; // global default if(strlen(args)>1) sscanf(args, " %f", &frequency); + * */ + String args = cmd_str.substring(cmd_str.indexOf(" ", strlen("subghz rx"))); + float frequency=RfFreq; // global default + if(args.length()>1) { + sscanf(args.c_str(), " %f", &frequency); + frequency /= 1000000; // passed as a long int (e.g. 433920000) + } //Serial.print("frequency:"); - //Serial.println((int) frequency); - String r = RCSwitch_Read_Raw(frequency, 10); + //Serial.println(frequency); + String r = ""; + if(cmd_str.startsWith("subghz rx_raw")) + r = RCSwitch_Read_Raw(frequency, 10, true); // true -> raw mode + else + r = RCSwitch_Read_Raw(frequency, 10, false); // false -> decoded mode if(r.length()==0) return false; // else Serial.println(r); diff --git a/src/modules/rf/rf.cpp b/src/modules/rf/rf.cpp index 508fd305..7ae9db29 100644 --- a/src/modules/rf/rf.cpp +++ b/src/modules/rf/rf.cpp @@ -484,7 +484,7 @@ bool initRfModule(String mode, float frequency) { } -String RCSwitch_Read_Raw(float frequency, int max_loops) { +String RCSwitch_Read_Raw(float frequency, int max_loops, bool raw) { RCSwitch rcswitch = RCSwitch(); RfCodes received; @@ -515,11 +515,11 @@ String RCSwitch_Read_Raw(float frequency, int max_loops) { } while(!checkEscPress()) { if(rcswitch.available()) { - Serial.println("Available"); + //Serial.println("Available"); long value = rcswitch.getReceivedValue(); - Serial.println("getReceivedValue()"); + //Serial.println("getReceivedValue()"); if(value) { - Serial.println("has value"); + //Serial.println("has value"); unsigned int* raw = rcswitch.getReceivedRawdata(); received.frequency=long(frequency*1000000); received.key=rcswitch.getReceivedValue(); @@ -527,15 +527,19 @@ String RCSwitch_Read_Raw(float frequency, int max_loops) { received.preset=rcswitch.getReceivedProtocol(); received.te=rcswitch.getReceivedDelay(); received.Bit=rcswitch.getReceivedBitlength(); - received.filepath="Last copied"; - Serial.println(received.te*2); + received.filepath="unsaved"; + //Serial.println(received.te*2); received.data=""; - for(int i=0; i0) received.data+=" "; - received.data+=raw[i]; + if(i % 2 == 0) sign = +1; + else sign = -1; + received.data += String(sign * (int)raw[i]); } - Serial.println(received.protocol); - Serial.println(received.data); + //Serial.println(received.protocol); + //Serial.println(received.data); const char* b = dec2binWzerofill(received.key, received.Bit); decimalToHexString(received.key,hexString); // need to remove the extra padding 0s? @@ -560,16 +564,22 @@ String RCSwitch_Read_Raw(float frequency, int max_loops) { previousMillis = millis(); } if(received.key>0) { - String subfile_out = "Filetype: Bruce SubGhz RAW File\nVersion 1\n"; + String subfile_out = "Filetype: Bruce SubGhz File\nVersion 1\n"; subfile_out += "Frequency: " + String(int(frequency*1000000)) + "\n"; - if(received.preset=="1") received.preset="FuriHalSubGhzPresetOok270Async"; - else if (received.preset=="2") received.preset="FuriHalSubGhzPresetOok650Async"; - subfile_out += "Preset: " + String(received.preset) + "\n"; - subfile_out += "Protocol: RcSwitch\n"; - subfile_out += "Bit: " + String(received.Bit) + "\n"; - subfile_out += "Key: " + String(hexString) + "\n"; - // subfile_out += "RAW_Data: " + received.data; // not in flipper pattern - subfile_out += "TE: " + String(received.te) + "\n"; + if(!raw) { + subfile_out += "Preset: " + String(received.preset) + "\n"; + subfile_out += "Protocol: RcSwitch\n"; + subfile_out += "Bit: " + String(received.Bit) + "\n"; + subfile_out += "Key: " + String(hexString) + "\n"; + subfile_out += "TE: " + String(received.te) + "\n"; + } else { + // save as raw + if(received.preset=="1") received.preset="FuriHalSubGhzPresetOok270Async"; + else if (received.preset=="2") received.preset="FuriHalSubGhzPresetOok650Async"; + subfile_out += "Preset: " + String(received.preset) + "\n"; + subfile_out += "Protocol: RAW\n"; + subfile_out += "RAW_Data: " + received.data; + } #ifndef HAS_SCREEN // headless mode diff --git a/src/modules/rf/rf.h b/src/modules/rf/rf.h index 8162751c..6dd0730f 100644 --- a/src/modules/rf/rf.h +++ b/src/modules/rf/rf.h @@ -18,7 +18,7 @@ void rf_jammerIntermittent(); void rf_jammerFull(); void otherRFcodes(); bool txSubFile(FS *fs, String filepath); -String RCSwitch_Read_Raw(float frequency=0, int max_loops=-1); +String RCSwitch_Read_Raw(float frequency=0, int max_loops=-1, bool raw=false); void RCSwitch_send(uint64_t data, unsigned int bits, int pulse=0, int protocol=1, int repeat=10); void addToRecentCodes(struct RfCodes rfcode); void sendRfCommand(struct RfCodes rfcode);