Skip to content

Commit

Permalink
added support for subghz raw rx (pr3y#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmaster committed Sep 1, 2024
1 parent ca5e2c8 commit 743fc27
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
20 changes: 16 additions & 4 deletions src/core/serialcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 29 additions & 19 deletions src/modules/rf/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -515,27 +515,31 @@ 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();
received.protocol="RcSwitch";
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; i<received.te*2;i++) {
int sign = +1;
//if(received.preset.invertedSignal) sign = -1;
for(int i=0; i<received.Bit*2; i++) {
if(i>0) 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?
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modules/rf/rf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 743fc27

Please sign in to comment.