-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintDatabase.ino
93 lines (76 loc) · 2.47 KB
/
PrintDatabase.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Database.h"
#include "UHFRecv.h"
#define RS485_CONTROL 4 //< Pin for RS485 Direction Control
#define LED 17 //< LED Pin
#define BAUD_RATE 9600
#define DEBUG
void flash();
/*
* If you change this initialisation to `Database database`, the program would
* be crashed. I still dont know the reasons yet. But better using pointer.
*/
Database* database;
UHFRecv TictagUhf(Serial1, BAUD_RATE, RS485_CONTROL);
// UHFRecv can also be instantiated like this
// UHFRecv TictagUhf(Serial1, BAUD_RATE, SERIAL_8N1, RS485_CONTROL);
uint32_t now = 0;
uint32_t period = 600; //< Change this value to modify time between inventory
// sessions (600 means 600 ms).
void setup()
{
/* Setting Serial */
Serial.begin(BAUD_RATE);
flash();
/* Setting UHF Receiver */
Serial.println("Initialise UHF Receiver.");
flash();
TictagUhf.begin();
/* Setting database */
Serial.println("Initialise Database");
flash();
database = new Database;
database->begin();
/* Setting prefix */
String prefix = "";
Serial.print("Setting prefix to ");
if (prefix == "")
Serial.println("default prefix: empty string");
else
Serial.println(prefix);
_setPrefix(prefix);
delay(300);
Serial.println("Scanning cards...");
}
void loop()
{
Status status = 0x00;
byte reData[INV_MAX_SIZE] = {0};
byte* cmd = TictagUhf.setCommand(READER_ADDRESS, TID_ARRESSS, LENGTH_TID);
size_t sizeCmd = TictagUhf.getSizeCommand();
if (millis() > (now + period)) {
now = millis();
TictagUhf.getRawData(reData, cmd, sizeCmd); //< Get raw data from
// inventory command
if (TictagUhf.isDataPreserved(reData, sizeof(reData))) {
if ((status = database->updateDB(reData)) != STATUS_SUCCESS) {
Serial.print("[ERROR ");
Serial.print(status, HEX);
if (status == 0xFB) {
Serial.println("] No cards in the effective field.");
}
// Add more potential errors here
return ;
}
if (Serial1.available() > 0)
database->_debugPrintDB(database->getDB());
} else {
Serial.println("Error: Data are not preserved.");
}
}
}
void flash()
{
digitalWrite(LED, HIGH);
delay(800);
digitalWrite(LED, LOW);
}