/* Decode and do action for Action Code */ #include "mbed.h" #include "ActionCode.h" #include "GRPeachDevice.h" struct actioncodeID ad; char argument[MAX_ARGUMENTS] = ""; struct deviceAttr dev[MAX_DEVICES] = {{10,dLED1,"GEAR",LED1}, {11,dLED2,"GEAR",LED2}, {12,dLED3,"GEAR",LED3}, {13,RELAY1,"GEAR",P8_15}, {14,RELAY2,"GEAR",P3_2}, {15,SERVO,"GEAR",P8_8}, {16,SENSORDS1820,"GEAR",P10_15}, {17,IR,"GEAR",P8_14}, {18,WEBCAM,"GEAR",LED1} // Any pin is OK because it does not use PIN }; void decodeActionCode(char* pass, char* acode, char* arg, char* resp) { int value[ACTION_CODE_FIELD]; char *tok; // Seperate Action Code nad Argument char *code = strtok(acode, ARGUMENT_SEPARATOR); tok = strtok(NULL, ARGUMENT_SEPARATOR); // Next Argument strcpy (arg,tok); printf ( " Action code = %s ad.arg = %s \r\n",code,arg); // get first token tok = strtok(code, ACTION_CODE_SEPARATOR); int i = 0; // loop until no more tokens or out of space in array while ( tok != NULL && i < ACTION_CODE_FIELD ) { value[i] = atoi(tok); // get next token tok = strtok(NULL, ACTION_CODE_SEPARATOR); // move to next array element i++; } ad.process = value[0]; ad.org = value[1]; ad.projectID = value[2]; ad.objID = value[3]; // Match with deviceAttr ad.scene = value[4]; ad.actionID = value[5]; printf("Process = %d \r\n",ad.process); printf("Organize = %d \r\n",ad.org); printf("Project ID = %d \r\n",ad.projectID); printf("Object ID = %d \r\n",ad.objID); printf("Scene = %d \r\n",ad.scene); printf("Action ID = %d \r\n",ad.actionID); printf("Action Argument = %s \r\n",arg); // Check pass code if not match abort process int ind = ad.objID-10; // 0- 9 is rsvp now. start from 10 if (!strcmp (pass,dev[ind].security)) { if (ad.actionID) // Not 0 { i = processAction(dev[ind].deviceClass, ad.actionID, dev[ind].pin, arg ); // Argument use for return value if (i == ACTION_SUCCESS) { strcpy (resp, "Already processed !!"); } else if (i == DATA_RETURN) { printf("Data return from processAction = %s \r\n",arg); strcpy (resp, arg); } else { strcpy (resp, "Error in processed !!"); } } else // User Interact return DeviceClass { int j = ad.objID-10; //if 0- 9 Rsvp is use this line must be modified // printf ( "j = %d " ,j); sprintf (resp,"Device= %d",dev[j].deviceClass); } } else // Passcode not match { strcpy (resp,"Passcode not match or missing"); } };