summaryrefslogtreecommitdiffstats
path: root/lock/back.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-04-08 17:01:41 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-04-08 17:05:56 +0800
commit014040f33f914a82031e15940924bc9c92236fec (patch)
tree7eae117615a04ff03b1b687ca4ffac64d98a7f38 /lock/back.c
parentf36e0c51177979c57b3402676fe342c180f9cb5b (diff)
downloadsmart-home-014040f33f914a82031e15940924bc9c92236fec.tar.gz
Fix await_reply()
Diffstat (limited to 'lock/back.c')
-rw-r--r--lock/back.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/lock/back.c b/lock/back.c
index f373d20..dd4938a 100644
--- a/lock/back.c
+++ b/lock/back.c
@@ -38,7 +38,7 @@ static uint8_t charslen = sizeof(chars) / sizeof(chars[0]);
static inline void await_reply(void)
{
- uint8_t i;
+ int i;
radio_listen();
for (i = 0; i < 500 && rxdr == 0; i += 100)
@@ -74,9 +74,7 @@ int main(void)
uint8_t rxaddr[ADDRLEN] = { 194, 178, 83 };
uint8_t txaddr[ADDRLEN] = { 194, 178, 82 };
- char buf[WDLEN + 1];
- char key[WDLEN + 1];
- char msg[WDLEN + 1];
+ char buf[WDLEN + 1], key[WDLEN + 1], msg[WDLEN + 1];
RX_DDR &= ~(1 << RX_PIN);
RX_PORT |= (1 << RX_PIN);
@@ -96,7 +94,11 @@ int main(void)
n = radio_recv(buf, WDLEN);
buf[n] = '\0';
rxdr = 0;
+
xor(KEY, buf, msg, WDLEN);
+ uart_write("DEBUG: msg recv = ");
+ uart_write_line(msg);
+
if (strncmp(msg, SYN, WDLEN) == 0) {
keygen(key, WDLEN);
uart_write("DEBUG: session key = ");
@@ -105,19 +107,17 @@ int main(void)
xor(KEY, key, msg, WDLEN);
radio_sendto(txaddr, msg, WDLEN);
await_reply();
+
if (rxdr) {
n = radio_recv(buf, WDLEN);
buf[n] = '\0';
rxdr = 0;
xor(key, buf, msg, WDLEN);
- if (strncmp(msg, LOCK, WDLEN) == 0) {
- uart_write_line("LOCKED");
- } else if (strncmp(msg, UNLOCK, WDLEN) == 0) {
- uart_write_line("UNLOCKED");
- } else {
- uart_write("ERROR: unknown message ");
- uart_write_line(msg);
- }
+ uart_write("DEBUG: msg = ");
+ uart_write_line(msg);
+
+ xor(key, ACK, msg, WDLEN);
+ radio_sendto(txaddr, msg, WDLEN);
}
} else {
uart_write_line("ERROR: handshake failed");