Pārlūkot izejas kodu

Added working rfid card read command

tags/lab06
Arti Zirk pirms 3 gadiem
vecāks
revīzija
111699cae1
5 mainītis faili ar 61 papildinājumiem un 5 dzēšanām
  1. +25
    -1
      src/cli_microrl.c
  2. +1
    -0
      src/cli_microrl.h
  3. +2
    -0
      src/hmi_msg.c
  4. +5
    -0
      src/hmi_msg.h
  5. +28
    -4
      src/main.c

+ 25
- 1
src/cli_microrl.c Parādīt failu

@@ -6,6 +6,7 @@
#include "hmi_msg.h"
#include "print_helper.h"
#include "cli_microrl.h"
#include "../lib/matejx_avr_lib/mfrc522.h"

typedef struct cli_cmd {
PGM_P cmd;
@@ -19,7 +20,8 @@ const cli_cmd_t cli_cmds[] = {
{help_cmd, help_help, cli_print_help, 0},
{ver_cmd, ver_help, cli_print_ver, 0},
{ascii_cmd, ascii_help, cli_print_ascii_tbls, 0},
{month_cmd, month_help, cli_handle_month, 1}
{month_cmd, month_help, cli_handle_month, 1},
{read_cmd, read_help, cli_rfid_read, 0}
};


@@ -111,6 +113,28 @@ void cli_handle_month(const char *const *argv)
}


void cli_rfid_read(const char *const *argv)
{
(void) argv;
Uid uid;
Uid *uid_ptr = &uid;
printf_P(PSTR("\n"));
if (PICC_IsNewCardPresent()) {
printf("Card selected!\n");
PICC_ReadCardSerial(uid_ptr);
printf("UID size: 0x%02X\n", uid.size);
printf("UID sak: 0x%02X\n", uid.sak);
printf("Card UID: ");
for (byte i = 0; i < uid.size; i++) {
printf("%02X", uid.uidByte[i]);
}
printf_P(PSTR("\n"));
} else {
printf_P((PSTR("Unable to select card.\n")));
}
}


void cli_print_cmd_error(void)
{
putc('\n', stdout);


+ 1
- 0
src/cli_microrl.h Parādīt failu

@@ -11,6 +11,7 @@ void print_version(FILE *stream);
void cli_print_ver(const char *const *argv);
void cli_print_ascii_tbls(const char *const *argv);
void cli_handle_month(const char *const *argv);
void cli_rfid_read(const char *const *argv);
void cli_print_cmd_error(void);
void cli_print_cmd_arg_error(void);
int cli_execute(int argc, const char *const *argv);


+ 2
- 0
src/hmi_msg.c Parādīt failu

@@ -18,3 +18,5 @@ const char ascii_cmd[] PROGMEM = ASCII_CMD;
const char ascii_help[] PROGMEM = ASCII_HELP;
const char month_cmd[] PROGMEM = MONTH_CMD;
const char month_help[] PROGMEM = MONTH_HELP;
const char read_cmd[] PROGMEM = READ_CMD;
const char read_help[] PROGMEM = READ_HELP;

+ 5
- 0
src/hmi_msg.h Parādīt failu

@@ -18,6 +18,9 @@
#define CLI_HELP_MSG "Implemented commands:"
#define CLI_NO_CMD "Command not implemented.\n Use <help> to get help."
#define CLI_ARGS_MSG "To few or to many arguments for this command\nUse <help>"
#define READ_CMD "read"
#define READ_HELP "Read and print out card info that is currently\nin proximity of the reader"


extern PGM_P const months[];

@@ -29,5 +32,7 @@ extern const char ascii_cmd[];
extern const char ascii_help[];
extern const char month_cmd[];
extern const char month_help[];
extern const char read_cmd[];
extern const char read_help[];

#endif /* _HMI_MSG_H_ */

+ 28
- 4
src/main.c Parādīt failu

@@ -1,6 +1,6 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <util/atomic.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
@@ -12,6 +12,7 @@
#include "../lib/hd44780_111/hd44780.h"
#include "../lib/helius_microrl/microrl.h"
#include "cli_microrl.h"
#include "../lib/matejx_avr_lib/mfrc522.h"


#define BAUDRATE 9600
@@ -21,10 +22,14 @@
#define LED_TOGGLE PORTA ^= _BV(PORTA3)
#define UART_STATUS_MASK 0x00FF

// Current system time
volatile uint32_t system_time;

// Create microrl object and pointer on it
static microrl_t rl;
static microrl_t *prl = &rl;


static inline void init_system_clock(void)
{
TCCR5A = 0; // Clear control register A
@@ -34,6 +39,22 @@ static inline void init_system_clock(void)
TIMSK5 |= _BV(OCIE5A); // Output Compare A Match Interrupt Enable
}

static inline uint32_t time(void)
{
uint32_t cur_time;
ATOMIC_BLOCK(ATOMIC_FORCEON) {
cur_time = system_time;
}
return cur_time;
}


static inline void init_rfid_reader(void)
{
MFRC522_init();
PCD_Init();
}


static inline void init_hw (void)
{
@@ -53,6 +74,9 @@ static inline void init_hw (void)
// LCD init
lcd_init();
lcd_clrscr();
// Init RFID-RC522
init_rfid_reader();

// Enable interupts
sei();
@@ -78,8 +102,8 @@ static inline void start_cli(void)

static inline void heartbeat (void)
{
static time_t time_prev;
time_t time_cur = time(NULL);
static uint32_t time_prev;
uint32_t time_cur = time();
if (time_cur <= time_prev) {
return;
}
@@ -106,5 +130,5 @@ int main (void)
// System clock
ISR(TIMER5_COMPA_vect)
{
system_tick();
system_time++;
}

Notiek ielāde…
Atcelt
Saglabāt