Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned char ReadMulti[10] = {0XAA, 0X00, 0X27, 0X00, 0X03, 0X22, 0XFF, 0XFF, 0X4A, 0XDD};
- unsigned int timeSec = 0;
- unsigned int timemin = 0;
- unsigned int dataAdd = 0;
- unsigned int incomedate = 0;
- unsigned int parState = 0;
- unsigned int codeState = 0;
- unsigned long currentTime = 0;
- unsigned long time_To_Wait_For_Removal = 15; // time in seconds
- String Last_EPC_Number = "";
- // Define the maximum number of EPC numbers that can be stored
- const int MAX_EPC_NUMBERS = 10;
- // Create a struct to store the EPC number and its counter
- struct EPCData {
- String epcNumber;
- int counter;
- unsigned long lastUpdateTime;
- };
- // Create an array to store the identified EPC numbers and their respective counters
- EPCData identifiedEPC[MAX_EPC_NUMBERS];
- int numIdentifiedEPC = 0; // Variable to keep track of the number of identified EPC numbers
- // Function to search for an EPC number in the identifiedEPC array
- bool searchEPC(const String& epcNumber) {
- for (int i = 0; i < numIdentifiedEPC; i++) {
- if (identifiedEPC[i].epcNumber == epcNumber) {
- return true; // Found the EPC number in the array
- }
- }
- return false; // EPC number not found in the array
- }
- void setup() {
- //pinMode(LED_BUILTIN, OUTPUT);
- Serial.begin(115200);
- Serial2.begin(115200);
- Serial.println("Hello world.");
- Serial2.write(ReadMulti, 10);
- }
- void loop() {
- read_RFID_Tags_R200_Long_Range();
- }//end of LOOP
- void Send_Data_To_Firebase(String EPC_Number_string, int identified_EPC_counter_int){
- }
- void handel_EPC_Tag() {
- // Check if the new EPC number is already present in the identifiedEPC array
- if (searchEPC(Last_EPC_Number)) {
- // If the EPC number is found, check if 15 seconds have passed since the last update
- currentTime = millis();
- for (int i = 0; i < numIdentifiedEPC; i++) {
- if (identifiedEPC[i].epcNumber == Last_EPC_Number &&
- currentTime - identifiedEPC[i].lastUpdateTime >= (time_To_Wait_For_Removal * 1000)) {
- // Increment the counter and update the last update time
- identifiedEPC[i].counter = (identifiedEPC[i].counter + 1) % 8; // Increment and wrap around to 0 when reaching 8
- identifiedEPC[i].lastUpdateTime = currentTime;
- // Output a Serial message indicating the updated counter
- Serial.print("EPC number: ");
- Serial.print(Last_EPC_Number);
- Serial.print(", Counter: ");
- Serial.println(identifiedEPC[i].counter);
- Send_Data_To_Firebase(Last_EPC_Number, identifiedEPC[i].counter);
- break; // Exit the loop once the EPC number is found and updated
- }
- }
- } else {
- // If the EPC number is not found, add it to the identifiedEPC array with an initial counter value of 1
- if (numIdentifiedEPC < MAX_EPC_NUMBERS) {
- identifiedEPC[numIdentifiedEPC].epcNumber = Last_EPC_Number;
- identifiedEPC[numIdentifiedEPC].counter = 0;
- identifiedEPC[numIdentifiedEPC].lastUpdateTime = millis();
- numIdentifiedEPC++;
- // Output a Serial message indicating the new EPC number and counter
- Serial.print("New EPC number identified: ");
- Serial.print(Last_EPC_Number);
- Serial.print(", Counter: ");
- Serial.println(identifiedEPC[numIdentifiedEPC - 1].counter);
- Send_Data_To_Firebase(Last_EPC_Number, identifiedEPC[numIdentifiedEPC - 1].counter);
- } else {
- // Maximum number of EPC numbers reached, handle accordingly
- }
- }
- }
- void read_RFID_Tags_R200_Long_Range() {
- timeSec ++ ;
- if (timeSec >= 50000) {
- timemin ++;
- timeSec = 0;
- if (timemin >= 20) {
- timemin = 0;
- //digitalWrite(LED_BUILTIN, HIGH);
- Serial2.write(ReadMulti, 10);
- //digitalWrite(LED_BUILTIN, LOW);
- }
- }
- if (Serial2.available() > 0) {
- incomedate = Serial2.read();
- if ((incomedate == 0x02) & (parState == 0)) {
- parState = 1;
- }
- else if ((parState == 1) & (incomedate == 0x22) & (codeState == 0)) {
- codeState = 1;
- dataAdd = 3;
- }
- else if (codeState == 1) {
- dataAdd ++;
- if (dataAdd == 6) {
- //Serial.print("RSSI:");
- //Serial.println(incomedate, HEX);
- }
- else if ((dataAdd == 7) | (dataAdd == 8)) {
- if (dataAdd == 7) {
- //Serial.print("PC:");
- //Serial.print(incomedate, HEX);
- }
- else {
- //Serial.println(incomedate, HEX);
- }
- }
- else if ((dataAdd >= 9) & (dataAdd <= 20)) {
- if (dataAdd == 9) {
- //Serial.print("EPC:");
- }
- //Serial.print(incomedate, HEX);
- Last_EPC_Number += String(incomedate, HEX);
- Last_EPC_Number.toUpperCase();
- }
- else if (dataAdd >= 21) {
- //Serial.println(" ");
- //Serial.print("Saved:");;
- //Serial.println(Last_EPC_Number);
- handel_EPC_Tag();
- Last_EPC_Number = "";
- dataAdd = 0;
- parState = 0;
- codeState = 0;
- }
- }
- else {
- dataAdd = 0;
- parState = 0;
- codeState = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement