summaryrefslogtreecommitdiffstats
path: root/lock/frnt.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/frnt.c
parentf36e0c51177979c57b3402676fe342c180f9cb5b (diff)
downloadsmart-home-014040f33f914a82031e15940924bc9c92236fec.tar.gz
Fix await_reply()
Diffstat (limited to 'lock/frnt.c')
-rw-r--r--lock/frnt.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/lock/frnt.c b/lock/frnt.c
index c3c36a7..4ad2d11 100644
--- a/lock/frnt.c
+++ b/lock/frnt.c
@@ -1,6 +1,7 @@
/* Door front, connected to the fingerprint scanner */
#include <stdint.h>
+#include <stdlib.h>
#include <avr/interrupt.h>
#include <util/delay.h>
@@ -22,7 +23,7 @@ static volatile int rxdr = 0;
static inline void await_reply(void)
{
- uint8_t i;
+ int i;
radio_listen();
for (i = 0; i < 500 && rxdr == 0; i += 100)
@@ -35,7 +36,7 @@ int main(void)
uint8_t rxaddr[ADDRLEN] = { 194, 178, 82 };
uint8_t txaddr[ADDRLEN] = { 194, 178, 83 };
- char key[WDLEN + 1], msg[WDLEN + 1];
+ char buf[WDLEN + 1], key[WDLEN + 1], msg[WDLEN + 1];
RX_DDR &= ~(1 << RX_PIN);
RX_PORT |= (1 << RX_PIN);
@@ -54,22 +55,25 @@ int main(void)
radio_sendto(txaddr, msg, WDLEN);
await_reply();
if (rxdr) {
- n = radio_recv(msg, WDLEN);
- msg[n] = '\0';
- rxdr = 0;
- xor(KEY, msg, key, WDLEN);
- // check btn press
- xor(key, LOCK, msg, WDLEN);
- radio_sendto(txaddr, msg, WDLEN);
- await_reply();
- if (rxdr) {
- n = radio_recv(msg, WDLEN);
- msg[n] = '\0';
+ uart_write_line("reply received");
+ n = radio_recv(buf, WDLEN);
+ buf[n] = '\0';
+ if (n > 0) {
rxdr = 0;
- uart_write_line(msg);
- } else {
- // power down
- uart_write_line("ERROR: no reply");
+ xor(KEY, buf, key, WDLEN);
+ xor(key, MSG, 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);
+ uart_write_line(msg);
+ } else {
+ // power down
+ uart_write_line("ERROR: no reply");
+ }
}
} else {
// power down