Code for RFID Robot

Dependencies:   DebounceIn HTTPClient ID12RFID SDFileSystem TextLCD WiflyInterface iniparser mbed

Committer:
4180skrw
Date:
Tue Dec 10 02:17:48 2013 +0000
Revision:
0:9fd64882c5aa
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180skrw 0:9fd64882c5aa 1 #include "mbed.h"
4180skrw 0:9fd64882c5aa 2 #include "WiflyInterface.h"
4180skrw 0:9fd64882c5aa 3 #include "HTTPClient.h"
4180skrw 0:9fd64882c5aa 4 #include <vector>
4180skrw 0:9fd64882c5aa 5 #include "SD.h"
4180skrw 0:9fd64882c5aa 6
4180skrw 0:9fd64882c5aa 7 WiflyInterface wifly(p13, p14, p29, p30, "GTother", "GeorgeP@1927", WPA);
4180skrw 0:9fd64882c5aa 8
4180skrw 0:9fd64882c5aa 9 HTTPClient http;
4180skrw 0:9fd64882c5aa 10 char str[512];
4180skrw 0:9fd64882c5aa 11
4180skrw 0:9fd64882c5aa 12 void setupWiFi()
4180skrw 0:9fd64882c5aa 13 {
4180skrw 0:9fd64882c5aa 14 printf("trying to connect");
4180skrw 0:9fd64882c5aa 15 wifly.init();
4180skrw 0:9fd64882c5aa 16 while (!wifly.connect()) wait (0.1);
4180skrw 0:9fd64882c5aa 17 printf("IP Address is %s\n\r", wifly.getIPAddress());
4180skrw 0:9fd64882c5aa 18 }
4180skrw 0:9fd64882c5aa 19
4180skrw 0:9fd64882c5aa 20 vector<robotCommand>* getTagCommands(int tagID)
4180skrw 0:9fd64882c5aa 21 {
4180skrw 0:9fd64882c5aa 22 vector<robotCommand>* commandVector = new vector<robotCommand>();
4180skrw 0:9fd64882c5aa 23 printLCD("Translating", "Web Server");
4180skrw 0:9fd64882c5aa 24 char url[512];
4180skrw 0:9fd64882c5aa 25 char str[512];
4180skrw 0:9fd64882c5aa 26 sprintf(url, "http://sabacai.com/index.php?tag=%d", tagID);
4180skrw 0:9fd64882c5aa 27 printf("url is %s", url);
4180skrw 0:9fd64882c5aa 28 int ret = http.get(url, str, 512);
4180skrw 0:9fd64882c5aa 29 if (!ret) {
4180skrw 0:9fd64882c5aa 30 printf("Tag String Received - read %d characters\n", strlen(str));
4180skrw 0:9fd64882c5aa 31 str[strlen(str)-1] = '\0'; // remove the last column
4180skrw 0:9fd64882c5aa 32 printf("Result: %s\n", str);
4180skrw 0:9fd64882c5aa 33 }
4180skrw 0:9fd64882c5aa 34
4180skrw 0:9fd64882c5aa 35 char * pch;
4180skrw 0:9fd64882c5aa 36 printf ("Splitting string \"%s\" into tokens:\n",str);
4180skrw 0:9fd64882c5aa 37 pch = strtok (str,",");
4180skrw 0:9fd64882c5aa 38
4180skrw 0:9fd64882c5aa 39 int i = 0;
4180skrw 0:9fd64882c5aa 40 CommandType commandID = None;
4180skrw 0:9fd64882c5aa 41
4180skrw 0:9fd64882c5aa 42 while (pch != NULL)
4180skrw 0:9fd64882c5aa 43 {
4180skrw 0:9fd64882c5aa 44 printf ("%s\n",pch);
4180skrw 0:9fd64882c5aa 45 double magnitude = 0.0;
4180skrw 0:9fd64882c5aa 46
4180skrw 0:9fd64882c5aa 47 if ((i&0x1) == 0)
4180skrw 0:9fd64882c5aa 48 {
4180skrw 0:9fd64882c5aa 49 // this is the command type
4180skrw 0:9fd64882c5aa 50 if (strcmp(pch, "FORWARD") == 0)
4180skrw 0:9fd64882c5aa 51 commandID = Forward;
4180skrw 0:9fd64882c5aa 52 else if (strcmp(pch, "REVERSE") == 0)
4180skrw 0:9fd64882c5aa 53 commandID = Reverse;
4180skrw 0:9fd64882c5aa 54 else if (strcmp(pch, "LEFT") == 0)
4180skrw 0:9fd64882c5aa 55 commandID = Left;
4180skrw 0:9fd64882c5aa 56 else if (strcmp(pch, "RIGHT") == 0)
4180skrw 0:9fd64882c5aa 57 commandID = Right;
4180skrw 0:9fd64882c5aa 58 else if (strcmp(pch, "PLAYSOUND") == 0)
4180skrw 0:9fd64882c5aa 59 commandID = PlaySound;
4180skrw 0:9fd64882c5aa 60
4180skrw 0:9fd64882c5aa 61 printf("command name is %s, id is %d", pch, commandID);
4180skrw 0:9fd64882c5aa 62 }
4180skrw 0:9fd64882c5aa 63 else
4180skrw 0:9fd64882c5aa 64 {
4180skrw 0:9fd64882c5aa 65 // this is the magnitude
4180skrw 0:9fd64882c5aa 66 magnitude = atof(pch);
4180skrw 0:9fd64882c5aa 67 printf("magnitude is %f", magnitude);
4180skrw 0:9fd64882c5aa 68 }
4180skrw 0:9fd64882c5aa 69
4180skrw 0:9fd64882c5aa 70 // do some stuff here
4180skrw 0:9fd64882c5aa 71 if (i != 0 && ((i&0x1) == 1))
4180skrw 0:9fd64882c5aa 72 {
4180skrw 0:9fd64882c5aa 73 // add the command to the vector
4180skrw 0:9fd64882c5aa 74 printf(" now adding %d, %f", commandID, magnitude);
4180skrw 0:9fd64882c5aa 75 commandVector->push_back(robotCommand(commandID, magnitude));
4180skrw 0:9fd64882c5aa 76 }
4180skrw 0:9fd64882c5aa 77 i+=1;
4180skrw 0:9fd64882c5aa 78 pch = strtok (NULL, ",");
4180skrw 0:9fd64882c5aa 79 }
4180skrw 0:9fd64882c5aa 80
4180skrw 0:9fd64882c5aa 81 return commandVector;
4180skrw 0:9fd64882c5aa 82 }