reverse engineer protocol 1 value
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
369b27fbdb
commit
361aa481da
40
gateway/include/RcDecoder.h
Normal file
40
gateway/include/RcDecoder.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#define RC_STATE(value) value & 0x1
|
||||||
|
#define RC_DEVICE(value) (value >> 1) & 0x1F
|
||||||
|
#define RC_GROUP(value) (value >> 6) & 0x1F
|
||||||
|
|
||||||
|
namespace RcDecoder {
|
||||||
|
|
||||||
|
struct RcSwitch {
|
||||||
|
bool state;
|
||||||
|
char group;
|
||||||
|
char device;
|
||||||
|
};
|
||||||
|
|
||||||
|
void decode(unsigned long value, RcSwitch decoded) {
|
||||||
|
value = value >> 2;
|
||||||
|
unsigned long res = 0;
|
||||||
|
for (int i = 0; i < 12; i++) {
|
||||||
|
res |= ((value & 1) ^ 1) << i;
|
||||||
|
value = value >> 2;
|
||||||
|
}
|
||||||
|
decoded.state = RC_STATE(res);
|
||||||
|
decoded.group = RC_GROUP(res);
|
||||||
|
switch (RC_DEVICE(res)) {
|
||||||
|
case 0b10000:
|
||||||
|
decoded.device = 1;
|
||||||
|
break;
|
||||||
|
case 0b01000:
|
||||||
|
decoded.device = 2;
|
||||||
|
break;
|
||||||
|
case 0b00100:
|
||||||
|
decoded.device = 3;
|
||||||
|
break;
|
||||||
|
case 0b00010:
|
||||||
|
decoded.device = 4;
|
||||||
|
break;
|
||||||
|
case 0b00001:
|
||||||
|
decoded.device = 5;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@
|
|||||||
#include "Tiny.h"
|
#include "Tiny.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include "Dht.h"
|
#include "Dht.h"
|
||||||
|
#include "RcDecoder.h"
|
||||||
|
|
||||||
#define RESET_PIN 10
|
#define RESET_PIN 10
|
||||||
#define SEND_PIN 11
|
#define SEND_PIN 11
|
||||||
@ -95,7 +95,15 @@ void readRcSwitch(JsonDocument& jsonDoc) {
|
|||||||
}
|
}
|
||||||
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
||||||
rcSwitch["protocol"] = mySwitch.getReceivedProtocol();
|
rcSwitch["protocol"] = mySwitch.getReceivedProtocol();
|
||||||
rcSwitch["value"] = value;
|
if (mySwitch.getReceivedProtocol() == 1) {
|
||||||
|
RcDecoder::RcSwitch decoded;
|
||||||
|
RcDecoder::decode(value, decoded);
|
||||||
|
rcSwitch["state"] = decoded.state;
|
||||||
|
rcSwitch["group"] = decoded.group;
|
||||||
|
rcSwitch["channel"] = decoded.device;
|
||||||
|
} else {
|
||||||
|
rcSwitch["value"] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user