void B9PrinterComm::startWatchDogTimer() { // We call the watchdog every 10 seconds QTimer::singleShot(10000, this, SLOT(watchDog())); // Check in 10 seconds }
int main(int argc, char *argv[]) { int boothID =0,nTag=0; int ret; int TagMode=1; int HostType = 1; char result[4096]; //Max Receive data char EPC[300]; char oldEPC[300]; char buf[256]; char URL[256]; char PAValue[6]; char Rssi[6]; LinuxWatchDog watchDog(60); if(argc == 1) { printf("Usage:\n"); printf("ART3x0 command boothID\n"); return 0; } // Read setting from ini file memset(oldEPC,'\0', sizeof(oldEPC)); ReadIni(buf,"wpc.cfg","Mode","GetTag"); TagMode = atoi(buf); printf("Mode:%d\n",TagMode); memset(URL,'\0', sizeof(URL)); ReadIni(URL,"wpc.cfg","WebService","URL"); printf("URL:%s\n",URL); memset(PAValue,'\0', sizeof(PAValue)); ReadIni(PAValue,"wpc.cfg","RFIDPOWER","PAValue"); printf("PAValue:%s\n",PAValue); memset(Rssi,'\0', sizeof(Rssi)); ReadIni(Rssi,"wpc.cfg","RFIDPOWER","ValidRSSI"); printf("Rssi:%s\n",Rssi); memset(buf,'\0', sizeof(buf)); ReadIni(buf,"wpc.cfg","Mode","HostType"); printf("HostType:%s\n",buf); HostType = atoi(buf); RU25Lib art3x0; printf("Reader connect...\n"); if(art3x0.Open(COM1) != 0) { // UTC-DS31 is use COM1, COM2 is debug port //printf("Open COM1 fail! \n"); return 1; } if(TagMode == 1) { // set PA Gain printf("Set internal PA.\n"); art3x0.SetParameter("internalpagain",PAValue); printf("Set run milisecond.\n"); art3x0.SetParameter("runmilisecond","400"); } else if(TagMode == 2) { // set PA Gain printf("Set internal PA\n"); art3x0.SetParameter("internalpagain",PAValue); printf("Set antennaswitchmode PA.\n"); art3x0.SetParameter("antennaswitchmode","0"); // 使用2支天線 Attena1,2輪流 } // set frequency 915.xx Enable printf("Set setchanneldisable PA.\n"); art3x0.SetParameter("setchannel Disable","927.75"); //art3x0.SetParameter("setchanneldisable","924.75"); art3x0.SetParameter("setchanneldisable","927.25"); //art3x0.SetParameter("setchanneldisable","924.25"); art3x0.SetParameter("setchanneldisable","926.75"); art3x0.SetParameter("setchanneldisable","923.75"); art3x0.SetParameter("setchanneldisable","926.25"); art3x0.SetParameter("setchanneldisable","923.25"); //art3x0.SetParameter("setchanneldisable","925.75"); art3x0.SetParameter("setchanneldisable","922.75"); //art3x0.SetParameter("setchanneldisable","925.25"); art3x0.SetParameter("setchanneldisable","922.25"); printf("Set setchannel Enable PA\n"); art3x0.SetParameter("setchannelenable","915.25"); art3x0.SetParameter("setchannelenable","915.75"); //art3x0.SetParameter("setchannelenable","916.25"); art3x0.SetParameter("setchannelenable","914.75"); printf("Set run milisecond\n"); art3x0.SetParameter("runmilisecond","400"); watchDog.Start(); while(1) { memset(result,'\0', sizeof(result)); memset(EPC,'\0', sizeof(EPC)); //printf("Inventory:\n"); //WriteLog("- art3x0.Inventory Start -"); ret = art3x0.Inventory(result, &nTag); //WriteLog("- art3x0.Inventory End -"); //printf(" Ret: %d \r\n",ret); if(nTag > 0) { printf("Result:\n%s\n\n",result); } if(strlen(result) > 6) { //ScreenNearTag((char*)(&EPC),result); if(TagMode == 1) { if(art3x0.GetNearestEPC((char*)(&EPC),atoi(Rssi)) == true) { //if(strcmp(EPC,oldEPC) != 0) // Filter same Tag //{ printf("EPC:%s, ID:%s \n",EPC,argv[1]); if(HostType == 1) { ret = SendTagToWPCServer(EPC,argv[1],URL); //test ret = SendTagToWPCServer("3400E2003412013C100009380D9E",argv[1],URL); if(ret == 1) { printf("Return True.\n"); } else { printf("Return False.\n"); } } //else if(HostType == 2) //{ // // system("/www/SendStrings 'this is first line' 'this is second line' "); //} //} } //else //{ // memset(oldEPC,'\0', sizeof(oldEPC)); //} } else if(TagMode == 2) { ret = SendTagListToWPCServer(result,argv[1],URL); if(ret == 1) { printf("Return True.\n"); } else { printf("Return False.\n"); } } } watchDog.KeepAlive(); if(TagMode == 1) { usleep(200000); //200ms } else { usleep(100000); //100ms } } watchDog.Stop(); return 0; };
//This is the main function that gets called from the Arduino program void Ospom::Run(int SensorReadDelayMS) { //Having these written out twice as const int's saves a lot of RAM const int EEPIDLoc[23] = {9,28,47,66,85,104,123,142,161,180,199,218,237,256,275,294,313,332,351,370}; //Location of Element Type (Sensor, actuator, nothing) const int EEPTypLoc[23] = {17,36,55,74,93,112,131,150,169,188,207,226,245,264,283,302,321,340,359,378}; //Location of Element Function (Analog Read, Digital Read, Analog Write, ect) const int EEPFuncLoc[23] = {18,37,56,75,94,113,132,151,170,189,208,227,246,265,284,303,322,341,360,379}; //Location of Element Slope(if sensor) or Fail Safe(if actuator) value const int EEPSlopeFSLoc[23] = {20,39,58,77,96,115,134,153,172,191,210,229,248,267,286,305,324,343,362,381}; //Location of Element Y-intercept(if sensor) or Extra(if actuator) const int EEPYintExLoc[23] = {24,43,62,81,100,119,138,157,176,195,214,233,252,271,290,309,328,347,366,385}; unsigned long TimeNow = 0; static unsigned long SensorStreamStartTime; static unsigned long LastMeasurement; static unsigned long LastSend; static unsigned int SendDelay; if (TriacDimming) { triacDimming(); } if (incomingUSBmsg()) { if (groupCommand) { //Do Group Command Stuff switch (groupCommandVal()) { case 0: sendGroupID(); break; case 10: sendSensorData(); break; case 11: SendDelay = GroupCommandInt; //Grab the time in milliseconds SensorStreamStartTime = millis(); //to delay before sending again SendData = true; break; case 13: sendActuatorData(); break; case 17: watchDog(); break; case 18: setGroupID(); break; default: fail(); break; } } //Element Command Section accepts commands and takes action else if (ElementCommand) { //Store the Element ID we are working with in a temporary variable char ElementID[9] = " "; //A temporary Variable for the ELement ID EEPROM.readBlock<char>(EEPIDLoc[ElementNumber], ElementID, 8); //Reads the Element ID from EEPROM //Do what the command Character says if (ElementCommandChar == 'R') { //Read the element value, and send it back to the odroid Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(ElementCalVal[ElementNumber]); } else if (ElementCommandChar == 'I') { //Change the Elements ID EEPROM.updateBlock<char>(EEPIDLoc[ElementNumber], CommandCharArray, 8); success(); } else if (ElementCommandChar == 'T') { //Change the Elements Type (s = sensor, a = actuator, n = nothing, z=SetBy EEPROM Loader Program) EEPROM.write(EEPTypLoc[ElementNumber],CommandCharArray[0]); ElementType[ElementNumber] = EEPROM.read(EEPTypLoc[ElementNumber]); success(); } else if (ElementCommandChar == 'C') { //Change the Elements Function (0=unused, 1=analogRead, 2=digitalRead, 3=analogWrite, // 4=digitalWrite, 5=Triac, 10=SetBy EEPROM Loader Program) EEPROM.updateInt(EEPFuncLoc[ElementNumber], ElementCommandInt); ElementFunction[ElementNumber] = EEPROM.readInt(EEPFuncLoc[ElementNumber]); success(); } else if (ElementCommandChar == 'A') { //Read the Element Type and Send it back to the odroid Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(ElementType[ElementNumber]); } else if (ElementCommandChar == 'D') { //Read the Element Function and Send it back to the odroid Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(ElementFunction[ElementNumber]); } else if (ElementCommandChar == 'M') { //Change the Elements Calibration Slope EEPROM.updateFloat(EEPSlopeFSLoc[ElementNumber], ElementCommandFloat); //Save value to EEPROM); ElementSlopeFS[ElementNumber] = ElementCommandFloat; success(); } else if (ElementCommandChar == 'B') { //Change the Elements Calibration Slope EEPROM.updateFloat(EEPYintExLoc[ElementNumber], ElementCommandFloat); //Save value to EEPROM); ElementYintEx[ElementNumber] = ElementCommandFloat; success(); } else if (ElementCommandChar == 'W') { //Write (Set) the Actuator if (ElementType[ElementNumber] == 'a') { //Make sure it's an actuator (so we don't break sensors) if ((ElementFunction[ElementNumber] == 3) && (ElementCommandInt != 100) && (ElementCommandInt != 0)) { //AnalogWrite if ((ElementCommandInt > 0) && (ElementCommandInt < 100)) { ElementCalVal[ElementNumber] = ElementCommandInt; //Save the Actuator Value so it can tell what it is if asked ElementCommandInt = ElementCommandInt * 255 / 100; //convert to 0-255 for PWM analogWrite(ElementPin[ElementNumber], ElementCommandInt); //AnalogWrite (PWM) if it's a 1-99 value success(); } else { fail(); } } //This does the digital writes, and also takes care of 100% on and 100% off PWM dimming else if ((ElementFunction[ElementNumber] == 4) || (ElementFunction[ElementNumber] == 3)) { //DigitalWrite ElementCalVal[ElementNumber] = ElementCommandInt; //Save the Actuator Value so it can tell what it is if asked if (ElementCommandInt == 0) { //0 means turn off the actuator digitalWrite(ElementPin[ElementNumber], LOW); success(); } else if (ElementCommandInt == 100) { //100 means turn on the actuator digitalWrite(ElementPin[ElementNumber], HIGH); success(); } else { fail(); } } else if (ElementFunction[ElementNumber] == 5) { //Triac Dimming 115v/240v AC Outlets //Decides if the input was appropriate, and sets the Stored Value betwenn 0 and 100 % if (ElementCommandInt == 0) { digitalWrite(ElementPin[ElementNumber], LOW); ElementCalVal[ElementNumber] = ElementCommandInt; //Save the Actuator Value so it can tell what it is if asked success(); } else if (ElementCommandInt == 100) { //100 means turn on the outlet all the way digitalWrite(ElementPin[ElementNumber], HIGH); ElementCalVal[ElementNumber] = ElementCommandInt; success(); } else if ((ElementCommandInt > 0.00) && (ElementCommandInt < 100.00)) { ElementCalVal[ElementNumber] = ElementCommandInt; ElementTotalValue[ElementNumber] = ElementCalVal[ElementNumber]; ElementTotalValue[ElementNumber] = 80 * ElementTotalValue[ElementNumber]; ElementTotalValue[ElementNumber] = 8000 - ElementTotalValue[ElementNumber]; ElementYintEx[ElementNumber] = 1; // ElementCalVal[ElementNumber] = 80 * ElementCalVal[ElementNumber]; //convert to Delay: // ElementCalVal[ElementNumber] = 8000 - ElementCalVal[ElementNumber]; // MilliDelay=8300-(83*%Dim) Serial.println(ElementCalVal[ElementNumber]); Serial.println(ElementTotalValue[ElementNumber]); success(); } else { fail(); } //Sets the TriacDimming Boolean to true if any of the outlets are dimmed between 1 and 99% TriacDimming = false; for (int i = 0; i < 20; i++) { if (ElementType[i] == 'a') { //s = sensor, a = actuator, n = nothing if (ElementFunction[i] == 5) { // 5=Triac Dimming if ((ElementCalVal[i] < 100.00) && (ElementCalVal[i] > 0.00)) { TriacDimming = true; } } } } } else { fail(); } } else { fail(); } } else if (ElementCommandChar == 'S') { //Not sure if storing an in where a float goes sometimes will matter //Set Fail Safe Value EEPROM.updateInt(EEPSlopeFSLoc[ElementNumber], ElementCommandInt); ElementSlopeFS[ElementNumber] = ElementCommandInt; success(); } else if (ElementCommandChar == 'F') { //Read Fail Safe Value Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(EEPROM.readInt(EEPSlopeFSLoc[ElementNumber])); } else { fail(); //Return a -1 } clearTheMsg(); } else { fail(); } clearTheMsg(); } //Measure sensor elements (with the delay decided in the main sketch), put them in an array TimeNow = millis(); //Check the time if (TimeNow > LastMeasurement + SensorReadDelayMS) { LastMeasurement = millis(); readSensors(); } //Send a Stream of Sensor Data for 1 minute if it has been requested if (SendData) { if (SensorStreamStartTime + 60000 > TimeNow) { //Send Data Stream if (Pause) { Pause = false; } else { if (TimeNow > LastSend + SendDelay) { sendSensorData(); LastSend = millis(); } } } else { // Stop Sending Data SendData = false; SensorStreamStartTime = 0; SendDelay = 0; LastSend = 0; } } }