Advertisement
safwan092

Untitled

Feb 25th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. unsigned char ReadMulti[10] = {0XAA, 0X00, 0X27, 0X00, 0X03, 0X22, 0XFF, 0XFF, 0X4A, 0XDD};
  2. unsigned int timeSec = 0;
  3. unsigned int timemin = 0;
  4. unsigned int dataAdd = 0;
  5. unsigned int incomedate = 0;
  6. unsigned int parState = 0;
  7. unsigned int codeState = 0;
  8.  
  9. unsigned long currentTime = 0;
  10. unsigned long time_To_Wait_For_Removal = 15; // time in seconds
  11. String Last_EPC_Number = "";
  12.  
  13.  
  14.  
  15.  
  16. // Define the maximum number of EPC numbers that can be stored
  17. const int MAX_EPC_NUMBERS = 10;
  18.  
  19. // Create a struct to store the EPC number and its counter
  20. struct EPCData {
  21. String epcNumber;
  22. int counter;
  23. unsigned long lastUpdateTime;
  24. };
  25.  
  26. // Create an array to store the identified EPC numbers and their respective counters
  27. EPCData identifiedEPC[MAX_EPC_NUMBERS];
  28. int numIdentifiedEPC = 0; // Variable to keep track of the number of identified EPC numbers
  29.  
  30. // Function to search for an EPC number in the identifiedEPC array
  31. bool searchEPC(const String& epcNumber) {
  32. for (int i = 0; i < numIdentifiedEPC; i++) {
  33. if (identifiedEPC[i].epcNumber == epcNumber) {
  34. return true; // Found the EPC number in the array
  35. }
  36. }
  37. return false; // EPC number not found in the array
  38. }
  39.  
  40.  
  41.  
  42.  
  43. void setup() {
  44. //pinMode(LED_BUILTIN, OUTPUT);
  45. Serial.begin(115200);
  46. Serial2.begin(115200);
  47. Serial.println("Hello world.");
  48. Serial2.write(ReadMulti, 10);
  49. }
  50.  
  51. void loop() {
  52. read_RFID_Tags_R200_Long_Range();
  53. }//end of LOOP
  54.  
  55.  
  56. void Send_Data_To_Firebase(String EPC_Number_string, int identified_EPC_counter_int){
  57.  
  58. }
  59.  
  60. void handel_EPC_Tag() {
  61. // Check if the new EPC number is already present in the identifiedEPC array
  62. if (searchEPC(Last_EPC_Number)) {
  63. // If the EPC number is found, check if 15 seconds have passed since the last update
  64. currentTime = millis();
  65. for (int i = 0; i < numIdentifiedEPC; i++) {
  66. if (identifiedEPC[i].epcNumber == Last_EPC_Number &&
  67. currentTime - identifiedEPC[i].lastUpdateTime >= (time_To_Wait_For_Removal * 1000)) {
  68. // Increment the counter and update the last update time
  69. identifiedEPC[i].counter = (identifiedEPC[i].counter + 1) % 8; // Increment and wrap around to 0 when reaching 8
  70. identifiedEPC[i].lastUpdateTime = currentTime;
  71.  
  72. // Output a Serial message indicating the updated counter
  73. Serial.print("EPC number: ");
  74. Serial.print(Last_EPC_Number);
  75. Serial.print(", Counter: ");
  76. Serial.println(identifiedEPC[i].counter);
  77. Send_Data_To_Firebase(Last_EPC_Number, identifiedEPC[i].counter);
  78. break; // Exit the loop once the EPC number is found and updated
  79. }
  80. }
  81. } else {
  82. // If the EPC number is not found, add it to the identifiedEPC array with an initial counter value of 1
  83. if (numIdentifiedEPC < MAX_EPC_NUMBERS) {
  84. identifiedEPC[numIdentifiedEPC].epcNumber = Last_EPC_Number;
  85. identifiedEPC[numIdentifiedEPC].counter = 0;
  86. identifiedEPC[numIdentifiedEPC].lastUpdateTime = millis();
  87. numIdentifiedEPC++;
  88.  
  89. // Output a Serial message indicating the new EPC number and counter
  90. Serial.print("New EPC number identified: ");
  91. Serial.print(Last_EPC_Number);
  92. Serial.print(", Counter: ");
  93. Serial.println(identifiedEPC[numIdentifiedEPC - 1].counter);
  94. Send_Data_To_Firebase(Last_EPC_Number, identifiedEPC[numIdentifiedEPC - 1].counter);
  95. } else {
  96. // Maximum number of EPC numbers reached, handle accordingly
  97. }
  98. }
  99. }
  100.  
  101.  
  102.  
  103.  
  104. void read_RFID_Tags_R200_Long_Range() {
  105. timeSec ++ ;
  106. if (timeSec >= 50000) {
  107. timemin ++;
  108. timeSec = 0;
  109. if (timemin >= 20) {
  110. timemin = 0;
  111. //digitalWrite(LED_BUILTIN, HIGH);
  112. Serial2.write(ReadMulti, 10);
  113. //digitalWrite(LED_BUILTIN, LOW);
  114. }
  115. }
  116. if (Serial2.available() > 0) {
  117. incomedate = Serial2.read();
  118. if ((incomedate == 0x02) & (parState == 0)) {
  119. parState = 1;
  120. }
  121. else if ((parState == 1) & (incomedate == 0x22) & (codeState == 0)) {
  122. codeState = 1;
  123. dataAdd = 3;
  124. }
  125. else if (codeState == 1) {
  126. dataAdd ++;
  127. if (dataAdd == 6) {
  128. //Serial.print("RSSI:");
  129. //Serial.println(incomedate, HEX);
  130. }
  131. else if ((dataAdd == 7) | (dataAdd == 8)) {
  132. if (dataAdd == 7) {
  133. //Serial.print("PC:");
  134. //Serial.print(incomedate, HEX);
  135. }
  136. else {
  137. //Serial.println(incomedate, HEX);
  138. }
  139. }
  140. else if ((dataAdd >= 9) & (dataAdd <= 20)) {
  141. if (dataAdd == 9) {
  142. //Serial.print("EPC:");
  143. }
  144. //Serial.print(incomedate, HEX);
  145. Last_EPC_Number += String(incomedate, HEX);
  146. Last_EPC_Number.toUpperCase();
  147.  
  148. }
  149.  
  150. else if (dataAdd >= 21) {
  151. //Serial.println(" ");
  152. //Serial.print("Saved:");;
  153. //Serial.println(Last_EPC_Number);
  154. handel_EPC_Tag();
  155. Last_EPC_Number = "";
  156. dataAdd = 0;
  157. parState = 0;
  158. codeState = 0;
  159. }
  160. }
  161. else {
  162. dataAdd = 0;
  163. parState = 0;
  164. codeState = 0;
  165. }
  166. }
  167. }
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement