summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lock/bend.c30
-rw-r--r--lock/fend.c40
2 files changed, 19 insertions, 51 deletions
diff --git a/lock/bend.c b/lock/bend.c
index 896c0b3..8436770 100644
--- a/lock/bend.c
+++ b/lock/bend.c
@@ -130,36 +130,16 @@ int main(void)
uart_write_line("reset...");
for (;;) {
- if (!rxd)
- _delay_ms(500);
-
if (rxd) {
n = radio_recv(buf, WDLEN);
buf[n] = '\0';
+ rxd = 0;
uart_write("recv: ");
uart_write(buf);
- itoa(n, s, 10);
- uart_write(s);
- uart_write_line(" bytes");
- if (!sync) {
- xor(KEY, buf, msg, WDLEN);
- if (strncmp(msg, SYN, WDLEN) == 0) {
- keygen(key, WDLEN + 1);
- xor(KEY, key, buf, WDLEN);
- sync = radio_sendto(txaddr, buf, WDLEN);
- } else {
- uart_write_line("not syn");
- }
- } else {
- sync = 0;
- xor(key, buf, msg, WDLEN);
- if (strncmp(msg, LOCK, WDLEN) == 0)
- lock();
- else if (strncmp(msg, UNLOCK, WDLEN) == 0)
- unlock();
- keydel(buf, WDLEN);
- }
- rxd = 0;
+ if (strncmp(buf, LOCK, WDLEN) == 0)
+ lock();
+ else if (strncmp(buf, UNLOCK, WDLEN) == 0)
+ unlock();
}
}
return 0;
diff --git a/lock/fend.c b/lock/fend.c
index 4b63759..927c310 100644
--- a/lock/fend.c
+++ b/lock/fend.c
@@ -61,36 +61,24 @@ int main(void)
sei();
for (;;) {
- if ((islock || isunlock) && !sync) {
- xor(KEY, SYN, buf, WDLEN);
+ if (islock) {
do {
- sync = radio_sendto(txaddr, buf, WDLEN);
- _delay_ms(10);
+ sync = radio_sendto(txaddr, LOCK, WDLEN);
+ _delay_ms(50);
} while (!sync);
- sync = 1;
- uart_write_line("sent syn");
+ sync = 0;
+ islock = 0;
+ uart_write_line("sent LOCK");
}
- if (rxd) {
- if (sync) {
- n = radio_recv(buf, WDLEN);
- buf[n] = '\0';
- xor(KEY, buf, key, WDLEN);
- uart_write_line("read key");
- if (islock) {
- islock = 0;
- xor(key, LOCK, buf, WDLEN);
- } else if (isunlock) {
- isunlock = 0;
- xor(key, UNLOCK, buf, WDLEN);
- }
- radio_sendto(txaddr, buf, WDLEN);
- sync = 0;
- uart_write_line("sent command");
- } else {
- radio_flush_rx();
- }
- rxd = 0;
+ if (isunlock) {
+ do {
+ sync = radio_sendto(txaddr, UNLOCK, WDLEN);
+ _delay_ms(50);
+ } while (!sync);
+ sync = 0;
+ isunlock = 0;
+ uart_write_line("sent UNLOCK");
}
}
return 0;