lab06 functionality done
This commit is contained in:
parent
41d61f9752
commit
fdfeabbcaa
@ -21,9 +21,9 @@
|
||||
#define READ_CMD "read"
|
||||
#define READ_HELP "Read and print out card info that is currently in proximity of the reader"
|
||||
#define ADD_CMD "add"
|
||||
#define ADD_HELP "Add a new card to the system"
|
||||
#define ADD_HELP "Add a new card to the system. Usage: add <username>"
|
||||
#define REMOVE_CMD "remove"
|
||||
#define REMOVE_HELP "Remove a card from the system"
|
||||
#define REMOVE_HELP "Remove a card from the system. Usage: remove <username>"
|
||||
#define LIST_CMD "list"
|
||||
#define LIST_HELP "List all added cards"
|
||||
|
||||
|
54
src/main.c
54
src/main.c
@ -13,13 +13,17 @@
|
||||
#include "../lib/helius_microrl/microrl.h"
|
||||
#include "cli_microrl.h"
|
||||
#include "../lib/matejx_avr_lib/mfrc522.h"
|
||||
#include "rfid.h"
|
||||
|
||||
|
||||
#define BAUDRATE 9600
|
||||
|
||||
// For configuring arduino mega pin 25
|
||||
#define LED_INIT DDRA |= _BV(DDA3);
|
||||
#define LED_INIT DDRA |= _BV(DDA3)
|
||||
#define DOOR_INIT DDRA |= _BV(DDA1)
|
||||
#define LED_TOGGLE PORTA ^= _BV(PORTA3)
|
||||
#define DOOR_OPEN PORTA |= _BV(PORTA1)
|
||||
#define DOOR_CLOSE PORTA &= ~_BV(PORTA1)
|
||||
#define UART_STATUS_MASK 0x00FF
|
||||
|
||||
// Current system time
|
||||
@ -59,8 +63,11 @@ static inline void init_rfid_reader(void)
|
||||
static inline void init_hw (void)
|
||||
{
|
||||
// IO init
|
||||
/// Set arduino pin 25 as output
|
||||
// Set arduino pin 25 as output
|
||||
LED_INIT;
|
||||
|
||||
// Set Arduino pin 23 as output
|
||||
DOOR_INIT;
|
||||
|
||||
// System clock
|
||||
init_system_clock();
|
||||
@ -112,6 +119,48 @@ static inline void heartbeat (void)
|
||||
LED_TOGGLE;
|
||||
}
|
||||
|
||||
static inline void handle_door() {
|
||||
Uid uid;
|
||||
card_t card;
|
||||
uint32_t time_cur = time();
|
||||
static uint32_t message_start;
|
||||
static uint32_t door_open_start;
|
||||
if (PICC_IsNewCardPresent()) {
|
||||
PICC_ReadCardSerial(&uid);
|
||||
card.uid_size = uid.size;
|
||||
memcpy(&card.uid, &uid.uidByte, uid.size);
|
||||
card.user = NULL;
|
||||
card_t *found_card = rfid_find_card(&card);
|
||||
if (found_card) {
|
||||
lcd_goto(0x40);
|
||||
lcd_puts(found_card->user);
|
||||
for (int8_t i=16-strlen(found_card->user); i > -1; i--) {
|
||||
lcd_putc(' ');
|
||||
}
|
||||
DOOR_OPEN;
|
||||
} else {
|
||||
DOOR_CLOSE;
|
||||
lcd_goto(0x40);
|
||||
lcd_puts("Access denied!");
|
||||
for (int8_t i=4; i > -1; i--) {
|
||||
lcd_putc(' ');
|
||||
}
|
||||
}
|
||||
door_open_start = time_cur;
|
||||
message_start = time_cur;
|
||||
}
|
||||
|
||||
if ((message_start+5) < time_cur) {
|
||||
lcd_goto(0x40);
|
||||
for (int8_t i=16; i > -1; i--) {
|
||||
lcd_putc(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if ((door_open_start+2) < time_cur) {
|
||||
DOOR_CLOSE;
|
||||
}
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
@ -123,6 +172,7 @@ int main (void)
|
||||
heartbeat();
|
||||
// CLI commands are handled in cli_execute()
|
||||
microrl_insert_char (prl, cli_get_char());
|
||||
handle_door();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ card_t* rfid_find_card(const card_t *card)
|
||||
while (current != NULL) {
|
||||
if ((current->uid_size != card->uid_size) ||
|
||||
!memcmp(current->uid, card->uid, current->uid_size) ||
|
||||
!strcmp(current->user, card->user)) {
|
||||
((card->user != NULL) && !strcmp(current->user, card->user))) {
|
||||
|
||||
return current;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ typedef struct card {
|
||||
} card_t;
|
||||
|
||||
extern card_t *head;
|
||||
extern card_t* rfid_find_card(const card_t *card);
|
||||
extern void rfid_add_card(const card_t *card);
|
||||
extern void rfid_list_cards(void);
|
||||
extern void rfid_remove_card_by_user(const char *user);
|
||||
|
Loading…
Reference in New Issue
Block a user