Add rolling codes for remote and hub
This commit is contained in:
@@ -10,8 +10,10 @@
|
|||||||
#define REMOTE_ID (0x369E)
|
#define REMOTE_ID (0x369E)
|
||||||
#define HUB_ID (0x0000)
|
#define HUB_ID (0x0000)
|
||||||
|
|
||||||
uint8_t rollingCode1 = 0xAC;
|
uint8_t remoteRollingCode1 = 0xAC;
|
||||||
uint8_t rollingCode2 = 0x82;
|
uint8_t remoteRollingCode2 = 0x82;
|
||||||
|
uint8_t hubRollingCode1 = 0x00;
|
||||||
|
uint8_t hubRollingCode2 = 0x00;
|
||||||
|
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
|
|
||||||
@@ -131,10 +133,48 @@ void setTargetAddress(uint16_t targetID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setRollingCodes() {
|
void setRollingCodes() {
|
||||||
|
uint16_t physicalSourceID = (buf[7] << 8) | buf[8];
|
||||||
|
|
||||||
|
uint8_t rollingCode1 = 0x00;
|
||||||
|
if (physicalSourceID == REMOTE_ID) {
|
||||||
|
rollingCode1 = remoteRollingCode1;
|
||||||
|
} else if (physicalSourceID == HUB_ID) {
|
||||||
|
rollingCode1 = hubRollingCode1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t logicalSourceID = (buf[14] << 8) | buf[15];
|
||||||
|
|
||||||
|
uint8_t rollingCode2 = 0x00;
|
||||||
|
if (physicalSourceID == REMOTE_ID) {
|
||||||
|
rollingCode2 = remoteRollingCode2;
|
||||||
|
} else if (physicalSourceID == HUB_ID) {
|
||||||
|
rollingCode2 = hubRollingCode2;
|
||||||
|
}
|
||||||
|
|
||||||
buf[4] = rollingCode1; // Rolling code 1
|
buf[4] = rollingCode1; // Rolling code 1
|
||||||
buf[11] = rollingCode2; // Rolling code 2
|
buf[11] = rollingCode2; // Rolling code 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void incrementRollingCodes() {
|
||||||
|
uint16_t physicalSourceID = (buf[7] << 8) | buf[8];
|
||||||
|
|
||||||
|
uint8_t rollingCode1 = 0x00;
|
||||||
|
if (physicalSourceID == REMOTE_ID) {
|
||||||
|
remoteRollingCode1++;
|
||||||
|
} else if (physicalSourceID == HUB_ID) {
|
||||||
|
hubRollingCode1++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t logicalSourceID = (buf[14] << 8) | buf[15];
|
||||||
|
|
||||||
|
uint8_t rollingCode2 = 0x00;
|
||||||
|
if (physicalSourceID == REMOTE_ID) {
|
||||||
|
remoteRollingCode2++;
|
||||||
|
} else if (physicalSourceID == HUB_ID) {
|
||||||
|
hubRollingCode2++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setProtocolVersion(uint8_t version) {
|
void setProtocolVersion(uint8_t version) {
|
||||||
buf[10] = version; // Protocol version?
|
buf[10] = version; // Protocol version?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,8 +112,7 @@ void sendCommand(byte * byteArray) //transmit a command
|
|||||||
radio.txStandBy();
|
radio.txStandBy();
|
||||||
}
|
}
|
||||||
|
|
||||||
rollingCode1++;
|
incrementRollingCodes();
|
||||||
rollingCode2++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printHex(const uint8_t num) { //print a byte as two hex chars
|
void printHex(const uint8_t num) { //print a byte as two hex chars
|
||||||
|
|||||||
Reference in New Issue
Block a user