Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function prototypes
- void setup(void);
- void loop(void);
- // RDM6300 packet details
- #define RDM6300_PACKET_SIZE 14
- #define RDM6300_PACKET_BEGIN 0x02
- #define RDM6300_PACKET_END 0x03
- // Globack for reading RFID data
- char buff[RDM6300_PACKET_SIZE];
- uint32_t tag_id;
- uint8_t checksum;
- void setup(void) {
- Serial.begin(9600);
- Serial.println("Setting up...");
- // RFID board setup
- Serial1.begin(9600);
- Serial.println("READY. Scanning tags...");
- }
- void loop(void) {
- while (Serial1.available() > 0) {
- if (Serial1.peek() == RDM6300_PACKET_BEGIN || Serial1.read()) {
- Serial1.readBytes(buff, RDM6300_PACKET_SIZE);
- if (buff[13] != RDM6300_PACKET_END) {
- Serial.println("Bad1");
- }
- else {
- buff[13] = 0;
- checksum = strtol(buff + 11, NULL, 16);
- buff[11] = 0;
- tag_id = strtol(buff + 3, NULL, 16);
- buff[3] = 0;
- checksum ^= strtol(buff + 1, NULL, 16);
- for (uint8_t i = 0; i < 32; i += 8) checksum ^= ((tag_id >> i) & 0xFF);
- if (checksum) {
- Serial.println("Bad2");
- }
- else {
- Serial.println(tag_id);
- }
- }
- }
- else {
- Serial.println("Bad3");
- Serial.println(Serial1.peek(), HEX);
- }
- Serial.println("END");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement