Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. // Function prototypes
  2. void setup(void);
  3. void loop(void);
  4.  
  5. // RDM6300 packet details
  6. #define RDM6300_PACKET_SIZE 14
  7. #define RDM6300_PACKET_BEGIN 0x02
  8. #define RDM6300_PACKET_END 0x03
  9.  
  10. // Globack for reading RFID data
  11. char buff[RDM6300_PACKET_SIZE];
  12. uint32_t tag_id;
  13. uint8_t checksum;
  14.  
  15. void setup(void) {
  16. Serial.begin(9600);
  17. Serial.println("Setting up...");
  18.  
  19. // RFID board setup
  20. Serial1.begin(9600);
  21.  
  22. Serial.println("READY. Scanning tags...");
  23. }
  24.  
  25. void loop(void) {
  26. while (Serial1.available() > 0) {
  27. if (Serial1.peek() == RDM6300_PACKET_BEGIN || Serial1.read()) {
  28. Serial1.readBytes(buff, RDM6300_PACKET_SIZE);
  29. if (buff[13] != RDM6300_PACKET_END) {
  30. Serial.println("Bad1");
  31. }
  32. else {
  33. buff[13] = 0;
  34. checksum = strtol(buff + 11, NULL, 16);
  35. buff[11] = 0;
  36. tag_id = strtol(buff + 3, NULL, 16);
  37. buff[3] = 0;
  38. checksum ^= strtol(buff + 1, NULL, 16);
  39. for (uint8_t i = 0; i < 32; i += 8) checksum ^= ((tag_id >> i) & 0xFF);
  40. if (checksum) {
  41. Serial.println("Bad2");
  42. }
  43. else {
  44. Serial.println(tag_id);
  45. }
  46. }
  47. }
  48. else {
  49. Serial.println("Bad3");
  50. Serial.println(Serial1.peek(), HEX);
  51. }
  52. Serial.println("END");
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement