From 1193ef26a1f1431d4974a0235cd923786509bab1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 24 Feb 2015 23:23:30 +0100 Subject: moved tuer-rfid to realraum github repo --- tuer-rfid/Makefile | 62 ------------ tuer-rfid/ajar.c | 76 -------------- tuer-rfid/ajar.h | 34 ------- tuer-rfid/eventqueue.c | 61 ----------- tuer-rfid/eventqueue.h | 34 ------- tuer-rfid/heartbeat.c | 74 -------------- tuer-rfid/heartbeat.h | 30 ------ tuer-rfid/keystore.c | 110 -------------------- tuer-rfid/keystore.h | 33 ------ tuer-rfid/ledmatrix.c | 218 ---------------------------------------- tuer-rfid/ledmatrix.h | 34 ------- tuer-rfid/limits.c | 81 --------------- tuer-rfid/limits.h | 34 ------- tuer-rfid/manual.c | 61 ----------- tuer-rfid/manual.h | 30 ------ tuer-rfid/sl018.c | 245 --------------------------------------------- tuer-rfid/sl018.h | 40 -------- tuer-rfid/statemachine.c | 185 ---------------------------------- tuer-rfid/statemachine.dot | 45 --------- tuer-rfid/statemachine.h | 30 ------ tuer-rfid/stepper.c | 127 ----------------------- tuer-rfid/stepper.h | 32 ------ tuer-rfid/tuer-rfid.c | 155 ---------------------------- tuer-rfid/update-keys.c | 138 ------------------------- 24 files changed, 1969 deletions(-) delete mode 100644 tuer-rfid/Makefile delete mode 100644 tuer-rfid/ajar.c delete mode 100644 tuer-rfid/ajar.h delete mode 100644 tuer-rfid/eventqueue.c delete mode 100644 tuer-rfid/eventqueue.h delete mode 100644 tuer-rfid/heartbeat.c delete mode 100644 tuer-rfid/heartbeat.h delete mode 100644 tuer-rfid/keystore.c delete mode 100644 tuer-rfid/keystore.h delete mode 100644 tuer-rfid/ledmatrix.c delete mode 100644 tuer-rfid/ledmatrix.h delete mode 100644 tuer-rfid/limits.c delete mode 100644 tuer-rfid/limits.h delete mode 100644 tuer-rfid/manual.c delete mode 100644 tuer-rfid/manual.h delete mode 100644 tuer-rfid/sl018.c delete mode 100644 tuer-rfid/sl018.h delete mode 100644 tuer-rfid/statemachine.c delete mode 100644 tuer-rfid/statemachine.dot delete mode 100644 tuer-rfid/statemachine.h delete mode 100644 tuer-rfid/stepper.c delete mode 100644 tuer-rfid/stepper.h delete mode 100644 tuer-rfid/tuer-rfid.c delete mode 100644 tuer-rfid/update-keys.c (limited to 'tuer-rfid') diff --git a/tuer-rfid/Makefile b/tuer-rfid/Makefile deleted file mode 100644 index 82a3b87..0000000 --- a/tuer-rfid/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -## -## spreadspace avr utils -## -## -## Copyright (C) 2013-2014 Christian Pointner -## Othmar Gsenger -## -## This file is part of spreadspace avr utils. -## -## spreadspace avr utils is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## any later version. -## -## spreadspace avr utils is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with spreadspace avr utils. If not, see . -## - -NAME := tuer-rfid -BOARD_TYPE := teenstep -OBJ := $(NAME).o heartbeat.o stepper.o ledmatrix.o sl018.o keystore.o statemachine.o eventqueue.o limits.o manual.o ajar.o -LIBS := util led lufa-descriptor-usbserial anyio -EXTERNAL_LIBS := lufa -SPREADAVR_PATH := .. -RESET_FUNC := $(SPREADAVR_PATH)/tools/reset_lufa_cdc -RESET_PARAM := 'r' - -LUFA_PATH := $(SPREADAVR_PATH)/contrib/LUFA-120219 -LUFA_OPTS = -D USB_DEVICE_ONLY -LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 -LUFA_OPTS += -D ORDERED_EP_CONFIG -LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 -LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 -LUFA_OPTS += -D USE_FLASH_DESCRIPTORS -LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT - -LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" -D USB_MANUFACTURER_LEN=7 -LUFA_OPTS += -D USB_PRODUCT="L\"realraum door firmware\"" -D USB_PRODUCT_LEN=22 - -LUFA_COMPONENTS := USB USBCLASS TWI SERIAL - -CLEAN_TARGETS += clean-pdf clean-update-keys - -include $(SPREADAVR_PATH)/include.mk - -update-keys: update-keys.c - gcc -o $@ $< - -clean-update-keys: - rm -f update-keys - -pdf: statemachine.dot - dot -Tpdf statemachine.dot -o statemachine.pdf - -clean-pdf: - rm -f statemachine.pdf diff --git a/tuer-rfid/ajar.c b/tuer-rfid/ajar.c deleted file mode 100644 index 271aeb9..0000000 --- a/tuer-rfid/ajar.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include -#include "ajar.h" - -#define AJAR_PIN PINC -#define AJAR_PORT PORTC -#define AJAR_DDR DDRC -#define AJAR_BIT 7 - -#define AJAR_LP_MAX 20000 - -void ajar_init(void) -{ - AJAR_DDR = AJAR_DDR & ~(1<= AJAR_LP_MAX) { - last_state = state; - lp_cnt = 0; - } - - if(last_state) - return ajar; - return shut; -} - -const char* ajar_to_string(ajar_t a) -{ - return a == ajar ? "ajar" : "shut"; -} - -void ajar_task(void) -{ - static ajar_t last_state = shut; - - ajar_t state = ajar_get(); - if(last_state != state) - printf("Info(ajar): door is now %s\r\n", ajar_to_string(state)); - - last_state = state; -} diff --git a/tuer-rfid/ajar.h b/tuer-rfid/ajar.h deleted file mode 100644 index e4b2d06..0000000 --- a/tuer-rfid/ajar.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_ajar_h_INCLUDED -#define R3TUER_ajar_h_INCLUDED - -typedef enum { ajar, shut } ajar_t; - -void ajar_init(void); -ajar_t ajar_get(void); -const char* ajar_to_string(ajar_t a); -void ajar_task(void); - -#endif diff --git a/tuer-rfid/eventqueue.c b/tuer-rfid/eventqueue.c deleted file mode 100644 index 5841d63..0000000 --- a/tuer-rfid/eventqueue.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include "eventqueue.h" -#include - -static RingBuffer_t event_queue; -static uint8_t event_queue_data[16]; - -void eventqueue_init(void) -{ - RingBuffer_InitBuffer(&event_queue, event_queue_data, sizeof(event_queue_data)); -} - -event_t eventqueue_pop(void) -{ - if (RingBuffer_IsEmpty(&event_queue)) - return none; - return RingBuffer_Remove(&event_queue); -} - -void eventqueue_push(event_t event) -{ - RingBuffer_Insert(&event_queue,event); -} - -const char* event_to_string(event_t event) -{ - switch(event) { - case none: return "none"; - case cmd_open: return "cmd_open"; - case cmd_close: return "cmd_close"; - case cmd_toggle: return "cmd_toggle"; - case btn_toggle: return "btn_toggle"; - case card: return "card"; - case open_fin: return "open_fin"; - case close_fin: return "close_fin"; - case move_timeout: return "move_timeout"; - } - return "invalid"; // gcc - shut the fuck up!!! -} diff --git a/tuer-rfid/eventqueue.h b/tuer-rfid/eventqueue.h deleted file mode 100644 index 3397e63..0000000 --- a/tuer-rfid/eventqueue.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_eventqueue_h_INCLUDED -#define R3TUER_eventqueue_h_INCLUDED - -typedef enum { none, cmd_open, cmd_close, cmd_toggle, btn_toggle, card, close_fin, open_fin, move_timeout } event_t; - -void eventqueue_init(void); -event_t eventqueue_pop(void); -void eventqueue_push(event_t); -const char* event_to_string(event_t event); - -#endif diff --git a/tuer-rfid/heartbeat.c b/tuer-rfid/heartbeat.c deleted file mode 100644 index b656521..0000000 --- a/tuer-rfid/heartbeat.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include - -#include "led.h" -#include "heartbeat.h" - -#define HEARTBEAT_DURATION 10 // *10 ms, duration of heartbeat pulse -#define HEARTBEAT_DELAY 200 // *10 ms, 1/heartbeat-frequency -uint8_t heartbeat_cnt = 0; -uint8_t heartbeat_flag; - -#define FASTBEAT_PORT PORTD -#define FASTBEAT_DDR DDRD -#define FASTBEAT_BIT 5 - -// while running this gets called every ~10ms -ISR(TIMER0_COMPA_vect) -{ - heartbeat_cnt++; - if(heartbeat_cnt == HEARTBEAT_DURATION) - heartbeat_flag = 0; - else if(heartbeat_cnt >= HEARTBEAT_DELAY) { - heartbeat_flag = 1; - heartbeat_cnt = 0; - } -} - -void heartbeat_init(void) -{ - led_off(); - heartbeat_cnt = 0; - heartbeat_flag = 1; - - TCCR0A = 1< ~10 ms @ 16 MHz - TCNT0 = 0; - TIMSK0 = 1< - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_heatbeat_h_INCLUDED -#define R3TUER_heatbeat_h_INCLUDED - -void heartbeat_init(void); -void heartbeat_task(void); - -#endif diff --git a/tuer-rfid/keystore.c b/tuer-rfid/keystore.c deleted file mode 100644 index f02f9a2..0000000 --- a/tuer-rfid/keystore.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include "keystore.h" -#include -#include -#include - -#include "led.h" -#include "anyio.h" - -#define EEPROM_SIZE 1024 -typedef uint8_t keyslot_t[8]; -keyslot_t EEMEM keystore[EEPROM_SIZE/sizeof(keyslot_t)]; - - -void keystore_flash_from_stdio(void) -{ - keyslot_t ks; - uint8_t byte_pos=0; - printf("Info(keystore): flashing\r\n"); - fflush(stdout); - for(uint8_t ks_pos=0;ks_pos 0) { - ks[byte_pos++]=fgetc(stdin); - bytes_received--; - if (byte_pos == sizeof(ks)) { - byte_pos=0; - eeprom_update_block(&ks,&keystore[ks_pos],sizeof(ks)); - ks_pos++; - fputc('.', stdout); - fflush(stdout); - led_toggle(); - } - } - } - printf("\r\n"); - fputc(0, stdout); - led_off(); -} - -void keystore_dump_to_stdio(void) -{ - keyslot_t ks; - for(uint8_t ks_pos=0;ks_pos - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_keystore_h_INCLUDED -#define R3TUER_keystore_h_INCLUDED - -#include - -void keystore_flash_from_stdio(void); -void keystore_dump_to_stdio(void); -uint8_t keystore_check_card(const uint8_t * uid, uint8_t uid_len); - -#endif diff --git a/tuer-rfid/ledmatrix.c b/tuer-rfid/ledmatrix.c deleted file mode 100644 index 4cfbcc8..0000000 --- a/tuer-rfid/ledmatrix.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include - -#include "ledmatrix.h" - -#define LEDMATRIX_PORT PORTB -#define LEDMATRIX_DDR DDRB -#define LEDMATRIX_RED 6 -#define LEDMATRIX_GREEN 7 -#define LEDMATRIX_NUM_LEDS 6 -#define LEDMATRIX_MASK 0x3F -#define BLINK_DELAY 3 - -ledmatrix_mode_t mode = off; -uint8_t moving_cnt = 0; -uint8_t wait_cnt = 0; - -void ledmatrix_start_timer(void) -{ - TCCR3A = 0; // prescaler 1:1024, WGM = 4 (CTC) - TCCR3B = 1< ~100 ms @ 16 MHz - TCNT3 = 0; - TIMSK3 = 1<= LEDMATRIX_NUM_LEDS) - moving_cnt = 0; - LEDMATRIX_PORT = (1<= BLINK_DELAY) { - LEDMATRIX_PORT ^= 1<= LEDMATRIX_NUM_LEDS) - moving_cnt = 0; - LEDMATRIX_PORT = (1<= BLINK_DELAY) { - LEDMATRIX_PORT ^= 1<= 2*LEDMATRIX_NUM_LEDS) - moving_cnt = 0; - - if(moving_cnt >= LEDMATRIX_NUM_LEDS) { - uint8_t offset = moving_cnt - LEDMATRIX_NUM_LEDS; - LEDMATRIX_PORT = (1<= BLINK_DELAY) { - LEDMATRIX_PORT ^= ~(LEDMATRIX_MASK); - wait_cnt = 0; - } -} - - -void ledmatrix_init(void) -{ - LEDMATRIX_DDR = 0xFF; - LEDMATRIX_PORT = 0xFF; -} - -void ledmatrix_set(ledmatrix_mode_t m) -{ - if(m == mode) - return; - - mode = m; - ledmatrix_stop_timer(); - switch(mode) - { - case off: ledmatrix_off_init(); break; - case red: ledmatrix_red_init(); break; - case red_moving: ledmatrix_red_moving_init(); break; - case red_blink: ledmatrix_red_blink_init(); break; - case green: ledmatrix_green_init(); break; - case green_moving: ledmatrix_green_moving_init(); break; - case green_blink: ledmatrix_green_blink_init(); break; - case rg_moving: ledmatrix_rg_moving_init(); break; - case rg_blink: ledmatrix_rg_blink_init(); break; - } -} - -ISR(TIMER3_COMPA_vect) -{ - switch(mode) - { - case red_moving: ledmatrix_red_moving_handle(); break; - case red_blink: ledmatrix_red_blink_handle(); break; - case green_moving: ledmatrix_green_moving_handle(); break; - case green_blink: ledmatrix_green_blink_handle(); break; - case rg_moving: ledmatrix_rg_moving_handle(); break; - case rg_blink: ledmatrix_rg_blink_handle(); break; - default: break; - } -} diff --git a/tuer-rfid/ledmatrix.h b/tuer-rfid/ledmatrix.h deleted file mode 100644 index 3be7f0f..0000000 --- a/tuer-rfid/ledmatrix.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_ledmatrix_h_INCLUDED -#define R3TUER_ledmatrix_h_INCLUDED - -typedef enum { off, red, red_moving, red_blink, - green, green_moving, green_blink, - rg_moving, rg_blink } ledmatrix_mode_t; - -void ledmatrix_init(void); -void ledmatrix_set(ledmatrix_mode_t mode); - -#endif diff --git a/tuer-rfid/limits.c b/tuer-rfid/limits.c deleted file mode 100644 index 28c30ca..0000000 --- a/tuer-rfid/limits.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include "limits.h" -#include - -#define LIMITS_ADC_CHAN_NUM 8 -#define LIMITS_ADC_CHAN ADC_CHANNEL8 - -#define LIMITS_RINGBUF_SIZE 5 -/* HINT: this is compared to a sliding sum not an average! */ -#define LIMITS_TH_CLOSE 800 -#define LIMITS_TH_OPEN 2700 - -void limits_init(void) -{ - ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128); - ADC_SetupChannel(LIMITS_ADC_CHAN_NUM); - ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | LIMITS_ADC_CHAN); -} - -static uint16_t sum = 0; - -void limits_task(void) -{ - static uint16_t r[LIMITS_RINGBUF_SIZE] = { 0 }; - static uint8_t idx = 0; - - if(ADC_IsReadingComplete()) { - r[idx] = ADC_GetResult(); - idx = (idx + 1) % LIMITS_RINGBUF_SIZE; - cli(); - sum = 0; - uint8_t i; - for(i=0; i - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_limits_h_INCLUDED -#define R3TUER_limits_h_INCLUDED - -typedef enum { moving, open, close, both } limits_t; - -void limits_init(void); -void limits_task(void); -limits_t limits_get(void); -const char* limits_to_string(limits_t limits); - -#endif diff --git a/tuer-rfid/manual.c b/tuer-rfid/manual.c deleted file mode 100644 index 6d338ba..0000000 --- a/tuer-rfid/manual.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include -#include "manual.h" -#include "eventqueue.h" - -#define MANUAL_PIN PIND -#define MANUAL_PORT PORTD -#define MANUAL_DDR DDRD -#define MANUAL_BIT 7 - -#define MANUAL_LP_MAX 255 - -void manual_init(void) -{ - MANUAL_DDR = MANUAL_DDR & ~(1<= MANUAL_LP_MAX) { - if(!state) { - eventqueue_push(btn_toggle); - printf("Info(manual): manual button has been pressed\r\n"); - } - last_state = state; - lp_cnt = 0; - } -} diff --git a/tuer-rfid/manual.h b/tuer-rfid/manual.h deleted file mode 100644 index 13cf2be..0000000 --- a/tuer-rfid/manual.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_manual_h_INCLUDED -#define R3TUER_manual_h_INCLUDED - -void manual_init(void); -void manual_task(void); - -#endif diff --git a/tuer-rfid/sl018.c b/tuer-rfid/sl018.c deleted file mode 100644 index 9ef90f5..0000000 --- a/tuer-rfid/sl018.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include "sl018.h" -#include "LUFA/Drivers/Peripheral/TWI.h" -#include -#include - -#define SL018_TWI_ADDR 0xA0 -#define SL018_TAG_STA_PIN PINE -#define SL018_TAG_STA_BIT 6 -#define CARD_PRESENT (!((SL018_TAG_STA_PIN >> SL018_TAG_STA_BIT) & 1)) -#define MAX_UID_LEN 7 - - -const char* SL018_cmd_tostring(const uint8_t cmd) -{ - switch(cmd) { - case 0x01: return "Select Mifare card"; - case 0x02: return "Login to a sector"; - case 0x03: return "Read a data block"; - case 0x04: return "Write a data block"; - case 0x05: return "Read a value block"; - case 0x06: return "Initialize a value block"; - case 0x07: return "Write master key"; - case 0x08: return "Increment value"; - case 0x09: return "Decrement value"; - case 0x0A: return "Copy value"; - case 0x10: return "Read a data page"; - case 0x11: return "Write a data page"; - case 0x40: return "Control the red led"; - case 0xF0: return "Get firmware version"; - case 0xFF: return "Reset"; - default: return "unknown"; - } -} - -const char* SL018_status_tostring(const uint8_t status) -{ - switch(status) { - case 0x0: return "Operation succeed"; - case 0x1: return "No tag"; - case 0x2: return "Login succeed"; - case 0x3: return "Login fail"; - case 0x4: return "Read fail"; - case 0x5: return "Write fail"; - case 0x6: return "Unable to read after write"; - case 0xA: return "Collision occur"; - case 0xC: return "Load key fail"; - case 0xD: return "Not authenticate"; - case 0xE: return "Not a value block"; - default: return "unknown"; - } -} - -const char* SL018_tagtype_tostring(const uint8_t type) -{ - switch(type) { - case 0x1: return "Mifare 1k, 4 byte UID"; - case 0x2: return "Mifare 1k, 7 byte UID"; - case 0x3: return "Mifare Ultralight or NATG203, 7 byte UID"; - case 0x4: return "Mifare 4k, 4 byte UID"; - case 0x5: return "Mifare 4k, 7 byte UID"; - case 0x6: return "Mifare DesFire, 7 byte UID"; - default: return "unknown"; - } -} - -uint8_t SL018_tagtype_to_uidlen(const uint8_t type) -{ - switch(type) { - case 0x1: - case 0x4: return 4; - case 0x2: - case 0x3: - case 0x5: - case 0x6: return 7; - default: return 0; - } -} - -const uint8_t SL018_CMD_ComSelectCard[] = {1,0x01}; -const uint8_t SL018_CMD_ComRedLedOn[] = {2,0x40,1}; -const uint8_t SL018_CMD_ComRedLedOff[] = {2,0x40,0}; -const uint8_t SL018_CMD_ComGetFirmwareVersion[] = {1,0xF0}; -const uint8_t SL018_CMD_ComReset[] = {1,0xFF}; - -uint8_t twi_recv_buf[256]; -typedef struct __attribute__((__packed__)) -{ - uint8_t len; - uint8_t command; - uint8_t status; - uint8_t data[sizeof(twi_recv_buf)-3]; -} sl018_message_t; - -sl018_message_t* twi_recv_msg = (sl018_message_t *)&twi_recv_buf; - - -uint8_t sl018_cmd_raw(const uint8_t* twi_send_buf, bool wait_for_answer) -{ - uint8_t pos = 0; - - if (TWI_StartTransmission(SL018_TWI_ADDR | TWI_ADDRESS_WRITE,10) == TWI_ERROR_NoError) { - for(pos=0; pos<=twi_send_buf[0]; pos++) { - if( ! TWI_SendByte(twi_send_buf[pos])) { - TWI_StopTransmission(); - return 1; - } - } - TWI_StopTransmission(); - } else - return 1; - - if(!wait_for_answer) return 0; - - memset(twi_recv_buf, 0, sizeof(twi_recv_buf)); - _delay_ms(50); - - if (TWI_StartTransmission(SL018_TWI_ADDR | TWI_ADDRESS_READ,10) == TWI_ERROR_NoError) { - TWI_ReceiveByte(twi_recv_buf, 0); - for(pos=1; pos<=twi_recv_buf[0]; pos++) { - if (! TWI_ReceiveByte(&twi_recv_buf[pos], (pos == twi_recv_buf[0]) ? 1:0 ) ) { - TWI_StopTransmission(); - return 1; - } - } - TWI_StopTransmission(); - } else - return 1; - - return 0; -} - -uint8_t sl018_reset(void) -{ - if(sl018_cmd_raw(SL018_CMD_ComReset, 0)) { - printf("Error(i2c): bus error\r\n"); - return 1; - } - return 0; -} - -uint8_t sl018_cmd(const uint8_t* twi_send_buf) -{ - if(sl018_cmd_raw(twi_send_buf, 1)) { - printf("Error(i2c): bus error\r\n"); - return 1; - } else { - if(twi_recv_msg->len < 2) { - printf("Error(SL018): short message received\r\n"); - return 1; - } - if(twi_recv_msg->status) { - printf("Error(SL018): '%s','%s'\r\n",SL018_cmd_tostring(twi_recv_msg->command),SL018_status_tostring(twi_recv_msg->status)); - return 1; - } - sl018_message_t * twi_send_msg = (sl018_message_t *)twi_send_buf; - if(twi_send_msg->command != twi_recv_msg->command) { - printf("Error(SL018): mismatch of sent and received command code: %02X,%02X\r\n",twi_send_msg->command,twi_recv_msg->command); - } - } - return 0; -} - -void sl018_read_card_uid(uid_t * uid) -{ - uid->length=0; - uid->buffer=NULL; - printf( "Info(card): "); - if(!sl018_cmd(SL018_CMD_ComSelectCard)) - { - uint8_t uid_len = twi_recv_msg->len - sizeof(twi_recv_msg->command) - sizeof(twi_recv_msg->status) - 1; - if(uid_len == 255 || uid_len > MAX_UID_LEN) { - printf(" received UID length (%d) is to big for keystore \r\n", uid_len); - return; - } - uint8_t type = twi_recv_msg->data[uid_len]; - uint8_t expected_uid_len = SL018_tagtype_to_uidlen(type); - if(expected_uid_len != uid_len) { - printf(" Invalid uid length (%d) for tag type: %s\r\n", uid_len, SL018_tagtype_tostring(type)); - return; - } - - for (uint8_t pos=0; posdata[uid_len-pos-1]); - printf( ", %s\r\n", SL018_tagtype_tostring(type)); - - if (0 < type && type < 7) { - uid->length= uid_len; - uid->buffer=twi_recv_msg->data; - } else { - printf("Info(card): Ignoring unknown card type %02x\r\n",type); - } - } -} - -void sl018_set_led(uint8_t on) -{ - if(on) - sl018_cmd(SL018_CMD_ComRedLedOn); - else - sl018_cmd(SL018_CMD_ComRedLedOff); -} - -uint8_t sl018_check_for_new_card(void) -{ - static uint8_t card_status = 0; - if(CARD_PRESENT != card_status) { - card_status = CARD_PRESENT; - if(card_status) - return 1; - } - return 0; -} - -unsigned char * sl018_get_firmware_version(void) -{ - if(!sl018_cmd(SL018_CMD_ComGetFirmwareVersion)) { - twi_recv_msg->data[sizeof(twi_recv_msg->data) - 1] = 0; - return twi_recv_msg->data; - } else { - return NULL; - } -} diff --git a/tuer-rfid/sl018.h b/tuer-rfid/sl018.h deleted file mode 100644 index ca7df4b..0000000 --- a/tuer-rfid/sl018.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_sl018_h_INCLUDED -#define R3TUER_sl018_h_INCLUDED - -#include - -typedef struct { - uint8_t length; - unsigned char * buffer; -} uid_t; - -void sl018_set_led(uint8_t on); -uint8_t sl018_check_for_new_card(void); -void sl018_read_card_uid(uid_t * uid); -uint8_t sl018_reset(void); -unsigned char * sl018_get_firmware_version(void); - -#endif diff --git a/tuer-rfid/statemachine.c b/tuer-rfid/statemachine.c deleted file mode 100644 index ce54cc0..0000000 --- a/tuer-rfid/statemachine.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - - -#include "statemachine.h" -#include "stepper.h" -#include "eventqueue.h" -#include "limits.h" -#include "ledmatrix.h" -#include - -typedef enum {reset, closed, closing, opened, opening, timeout_after_open, timeout_after_close, error, manual_movement} state_t; -state_t state = reset; - -const char* state_to_string(state_t s) -{ - switch(s) { - case reset: return "reset"; - case error: return "error"; - case closing: return "closing"; - case opening: return "opening"; - case manual_movement: return "manual_movement"; - case timeout_after_open: return "timeout_after_open"; - case timeout_after_close: return "timeout_after_close"; - case closed: return "closed"; - case opened: return "opened"; - } - return "invalid"; // gcc - shut the fuck up!!! -} - -void change_state(state_t new_state) -{ - if (new_state == state) - return; - printf("State: %s\r\n", state_to_string(new_state)); - switch(new_state) { - case reset: - break; - case closed: ledmatrix_set(red); break; - case closing: - ledmatrix_set(red_moving); - stepper_start(dir_close); - break; - case opened: ledmatrix_set(green); break; - case opening: - ledmatrix_set(green_moving); - stepper_start(dir_open); - break; - case timeout_after_open: ledmatrix_set(green_blink); break; - case timeout_after_close: ledmatrix_set(red_blink); break; - case error: ledmatrix_set(rg_blink); break; - case manual_movement: ledmatrix_set(rg_moving); break; - break; - } - state = new_state; -} - -void statemachine_task_limits(void) -{ - limits_t limits = limits_get(); - if (limits == both) - return change_state(error); - - switch(state) { - case reset: - switch(limits) { - case open: - return change_state(opened); - case close: - return change_state(closed); - default: - return change_state(closing); - } - case error: - case closed: - case opened: - switch(limits) { - case open: - return change_state(opened); - case close: - return change_state(closed); - default: - return change_state(manual_movement); - } - case manual_movement: - case timeout_after_open: - case timeout_after_close: - switch(limits) { - case open: - return change_state(opened); - case close: - return change_state(closed); - default: - return; - } - case closing: - break; - case opening: - break; - } -} - -void statemachine_task_event(void) -{ - event_t event = eventqueue_pop(); - if(event == none) - return; - - switch(state) { - case closing: - case opening: - switch(event) { - case open_fin: - return change_state(opened); - case close_fin: - return change_state(closed); - case move_timeout: - return change_state(state==opening?timeout_after_open:timeout_after_close); - default: - printf("Error(state): event %s not allowed in state %s\r\n", event_to_string(event), state_to_string(state)); - return; - } - case reset: - case error: - printf("Error(state): Not accepting commands in state %s\r\n", state_to_string(state)); - break; // Not accepting commands - case manual_movement: - case timeout_after_open: - case timeout_after_close: - case closed: - case opened: - switch(event) { - case none: - return; - case cmd_open: - return change_state(opening); - case cmd_close: - return change_state(closing); - case cmd_toggle: - case btn_toggle: - case card: - return change_state( - (state==closed || state == timeout_after_close) ? - opening: - closing); - case open_fin: - case close_fin: - case move_timeout: - printf("Error(state): event %s not allowed in state %s\r\n", event_to_string(event), state_to_string(state)); - return; - } - } - -} - -void statemachine_task(void) -{ - statemachine_task_limits(); - statemachine_task_event(); -} - -const char* statemachine_get_state_as_string(void) -{ - return state_to_string(state); -} diff --git a/tuer-rfid/statemachine.dot b/tuer-rfid/statemachine.dot deleted file mode 100644 index d581de8..0000000 --- a/tuer-rfid/statemachine.dot +++ /dev/null @@ -1,45 +0,0 @@ -digraph G { - reset [shape=box]; - toggle [shape=diamond]; - btn_toggle [shape=diamond]; - cmd_toggle [shape=diamond]; - card [shape=diamond]; - card ->toggle; - btn_toggle ->toggle; - cmd_toggle ->toggle; - all_states [shape=box]; - opened [shape=box]; - closed [shape=box]; - opening [shape=box]; - closing [shape=box]; - timeout_after_open [shape=box]; - timeout_after_close [shape=box]; - manual_movement [shape=box]; - error [shape=box]; - reset -> closed [label="limit_closed"]; - reset -> closing [label="limit_none"]; - reset -> opened [label="limit_opened"]; - error -> closed [label="limit_closed"]; - error -> opened [label="limit_opened"]; - error -> manual_movement [label="limit_none"]; - manual_movement -> opening [label="cmd_open"]; - manual_movement -> closing [label="cmd_close"]; - manual_movement -> closing [label="toggle"]; - opened -> closing [label="cmd_close"]; - opened -> closing [label="toggle"]; - closed -> opening [label="cmd_open"]; - closed -> opening [label="toggle"]; - opening -> opened [label="open_fin"]; - closing -> closed [label="close_fin"]; - closing -> timeout_after_close [label="timeout"]; - opening -> timeout_after_open [label="timeout"]; - timeout_after_open -> closing [label="cmd_close"]; - timeout_after_open -> closing [label="toggle"]; - timeout_after_open -> opened [label="limit_open"]; - timeout_after_open -> closed [label="limit_close"]; - timeout_after_close -> opening [label="cmd_open"]; - timeout_after_close -> opening [label="toggle"]; - timeout_after_close -> opened [label="limit_open"]; - timeout_after_close -> closed [label="limit_close"]; - all_states -> error [label="limit_both"]; -} diff --git a/tuer-rfid/statemachine.h b/tuer-rfid/statemachine.h deleted file mode 100644 index c02a6d4..0000000 --- a/tuer-rfid/statemachine.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_statemachine_h_INCLUDED -#define R3TUER_statemachine_h_INCLUDED - -void statemachine_task(void); -const char* statemachine_get_state_as_string(void); - -#endif diff --git a/tuer-rfid/stepper.c b/tuer-rfid/stepper.c deleted file mode 100644 index b477419..0000000 --- a/tuer-rfid/stepper.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include - -#include "stepper.h" -#include "limits.h" -#include "eventqueue.h" - -uint8_t step_table [] = -{ - /* full steps */ - /* 6, // 0110 */ - /* 5, // 0101 */ - /* 9, // 1001 */ - /* 10, // 1010 */ - - /* half steps */ - 2, // 0010 - 6, // 0110 - 4, // 0100 - 5, // 0101 - 1, // 0001 - 9, // 1001 - 8, // 1000 - 10, // 1010 -}; - -#define STEPPER_PORT PORTF -#define STEPPER_DDR DDRF -#define STEPPER_FIRST_BIT 4 -#define STEPPER_ENABLE_A_BIT 0 -#define STEPPER_ENABLE_B_BIT 1 -#define LENGTH_STEP_TABLE (sizeof(step_table)/sizeof(uint8_t)) -#define STEPPER_OUTPUT_BITMASK (~(0xF << STEPPER_FIRST_BIT )) - -volatile uint16_t step_cnt = 0; -#define STEP_CNT_STOP (LENGTH_STEP_TABLE*172) -#define STEP_CNT_STOP_PLUS_EXTRA (STEP_CNT_STOP + (LENGTH_STEP_TABLE*20)) -stepper_direction_t step_direction = dir_open; - -inline void stepper_stop(void) -{ - STEPPER_PORT &= ~(0xF << STEPPER_FIRST_BIT | 1<= STEP_CNT_STOP_PLUS_EXTRA) - return 0; //stop - - return 1; // continue running -} - -void stepper_init(void) -{ - STEPPER_PORT &= ~(0xF << STEPPER_FIRST_BIT | 1< - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef R3TUER_stepper_h_INCLUDED -#define R3TUER_stepper_h_INCLUDED -#include -typedef enum { dir_open = 0, dir_close = 1 } stepper_direction_t; - -void stepper_init(void); -uint8_t stepper_start(stepper_direction_t direction); - -#endif diff --git a/tuer-rfid/tuer-rfid.c b/tuer-rfid/tuer-rfid.c deleted file mode 100644 index 1c540cd..0000000 --- a/tuer-rfid/tuer-rfid.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * Othmar Gsenger - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include -#include -#include -#include "LUFA/Drivers/Peripheral/TWI.h" - -#include -#include - -#include "util.h" -#include "led.h" -#include "anyio.h" - -#include "heartbeat.h" -#include "stepper.h" -#include "ledmatrix.h" -#include "sl018.h" -#include "keystore.h" -#include "statemachine.h" -#include "eventqueue.h" -#include "limits.h" -#include "manual.h" -#include "ajar.h" - -void handle_cmd(uint8_t cmd) -{ - switch(cmd) { - case 'r': - reset2bootloader(); - break; - case 'R': - if(!sl018_reset()) - printf("ok\r\n"); - break; - case 'f': { - unsigned char * firmware_str = sl018_get_firmware_version(); - if(firmware_str) - printf("%s\r\n",firmware_str); - - break; - } - case 'e': //flash eeprom - keystore_flash_from_stdio(); - break; - case 'd': //dump eeprom - this breaks security! - keystore_dump_to_stdio(); - break; - case 'o': - eventqueue_push(cmd_open); - break; - case 'c': - eventqueue_push(cmd_close); - break; - case 't': - eventqueue_push(cmd_toggle); - break; - case 's': - printf("Status: %s %s %s\r\n", limits_to_string(limits_get()), statemachine_get_state_as_string(), ajar_to_string(ajar_get())); - break; - /* case '0': ledmatrix_set(off); break; */ - /* case '1': ledmatrix_set(red); break; */ - /* case '2': ledmatrix_set(red_moving); break; */ - /* case '3': ledmatrix_set(red_blink); break; */ - /* case '4': ledmatrix_set(green); break; */ - /* case '5': ledmatrix_set(green_moving); break; */ - /* case '6': ledmatrix_set(green_blink); break; */ - /* case '7': ledmatrix_set(rg_moving); break; */ - /* case '8': ledmatrix_set(rg_blink); break; */ - default: printf("Error(cmd): unknown command %02X '%c'\r\n", cmd, cmd); return; - } -} - -void handle_card(void) -{ - uid_t uid; - sl018_read_card_uid(&uid); - if (uid.length) - { - printf("Info(card): card("); - for (uint8_t pos=0; pos 0) - handle_cmd(fgetc(stdin)); - - if (sl018_check_for_new_card()) - handle_card(); - - heartbeat_task(); - } -} diff --git a/tuer-rfid/update-keys.c b/tuer-rfid/update-keys.c deleted file mode 100644 index a47e075..0000000 --- a/tuer-rfid/update-keys.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2014 Christian Pointner - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#include -#include -#include -#include - -#define EEPROM_SIZE 1024 -typedef uint8_t keyslot_t[8]; - -/* this generates a Fletcher8 checksum */ -/* code from: http://stackoverflow.com/questions/13491700/8-bit-fletcher-checksum-of-16-byte-data */ -uint8_t generate_csum(keyslot_t data) -{ - uint16_t sum1 = 0xf, sum2 = 0xf, len = sizeof(keyslot_t)-1; - do { sum2 += ( sum1 += *data++ ); } while (--len); - return sum2<<4 | sum1; -} - -int send_key(keyslot_t key, FILE* dev) -{ - fwrite(key, sizeof(keyslot_t), 1, dev); - fflush(dev); - char tmp; - while(fread(&tmp, 1, 1, dev)) { - fwrite(&tmp, 1, 1, stdout); - if(tmp == 0) return 1; - if(tmp == '.') return 0; - } - return 0; -} - -int main(int argc, char* argv[]) -{ - if(argc<2) { - fprintf(stderr, "Usage: update-keys \n"); - return -1; - } - - FILE* dev; - dev = fopen(argv[1], "r+"); - if(!dev) { - fprintf(stderr, "fopen failed!\n"); - return -2; - } - - int fd = fileno(dev); - struct termios t; - tcgetattr(fd, &t); - t.c_lflag &= ~(ICANON | ECHO); - t.c_iflag &= ~(ICRNL | INLCR | IXON | IXOFF); - cfmakeraw(&t); - tcflush(fd, TCIOFLUSH); - tcsetattr(fd, TCSANOW, &t); - - fprintf(dev, "e"); - - char* line = NULL; - size_t len = 0; - int line_num = 0; - keyslot_t key; - int key_num = 0; - - for(;;) { - ssize_t ret = getline(&line, &len, stdin); - if(ret <= 0) break; - line_num++; - - int i; - for(i=0; i (sizeof(keyslot_t)-1)*2) { - fprintf(stderr, "ignoring invalid key (odd number of digits or empty string or too long) at line %d\n", line_num); - continue; - } - uint8_t tmp[3]; - int j; - tmp[2] = 0; - for(j = 0; j<(i/2); ++j) { - tmp[0] = line[j*2]; - tmp[1] = line[j*2 + 1]; - key[j] = (char)strtoul(tmp, NULL, 16); - } - for(j=i/2; j < sizeof(keyslot_t)-1; ++j) { - key[j] = 0; - } - key[sizeof(keyslot_t)-1] = generate_csum(key); - if(send_key(key, dev)) { - fprintf(stderr, "send_key failed at keyslot %d\n", key_num); - return 1; - } - - key_num++; - if(key_num > EEPROM_SIZE/sizeof(keyslot_t)) { - fprintf(stderr, "reached maximum number of key slots (%d), will ignore remaining keys\n", (int)(EEPROM_SIZE/sizeof(keyslot_t))); - break; - } - } - printf("\nread %d keys from STDIN - filling rest of keystore with invalid keys\n", key_num); - - int i; - for(i=0; i<=sizeof(keyslot_t)-1; ++i) key[i] = 0xFF; - for(i=key_num; i < EEPROM_SIZE/sizeof(keyslot_t); ++i) { - if(send_key(key, dev)) { - fprintf(stderr, "send_key failed at keyslot %d\n", key_num); - return 1; - } - key_num++; - } - - printf("\nwrite of %d keys finished\n", key_num); - - return 0; -} -- cgit v1.2.3