a

Fork of ESE519_Lab6_part1_skeleton by Carter Sharer

Revision:
7:ca226305d28b
Parent:
6:e0c358a351aa
Child:
9:b8801ba7d7c2
--- a/main.cpp	Mon Oct 15 18:29:01 2018 +0000
+++ b/main.cpp	Wed Oct 24 20:54:43 2018 +0000
@@ -6,12 +6,10 @@
 //Contains a communication protocol for sending a receiving 
 
 #include "mbed.h"
-#include "MRF24J40.h"
 #include <string>
 #include "Joystick.h"
-
-#define SEND        //Uncomment if you want to transmit data
-#define RECEIVE     //Uncomment if you want to receive data
+#include "wifiGETWrapper.h"
+//#define SEND        //Uncomment if you want to transmit data
 
 #define NONE 250
 
@@ -26,15 +24,9 @@
 //JoyStick
 #define POTV p19 //Vertial
 #define POTH p20 //Horizontal
-//MRF24J
-#define SDI p11
-#define SDO p12
-#define SCK p13
-#define CS p7
-#define RESET p8
 //Button
 #define BUTTON1 p21
-#define COMMUNICATION_FORMAT "Jstick_h: %0.0f Jstick_v: %0.0f Knob1 %0.2f Knob2 %0.2f Knob3 %0.2f Knob4 %0.2f Button: %d"
+#define COMMUNICATION_FORMAT "Jstick_h:|%0.0f|Jstick_v:|%0.0f|Knob1|%0.2f|Knob2|%0.2f|Knob3|%0.2f|Knob4|%0.2f|Button:|%d"
 
 //============================
 //==        Objects         ==
@@ -50,15 +42,6 @@
 Joystick jstick(POTV, POTH);
 float jstick_h, jstick_v;
 
-//MRF24J40
-PinName mosi(SDI);
-PinName miso(SDO);
-PinName sck(SCK);
-PinName cs(CS);
-PinName reset(RESET);
-// RF tranceiver
-MRF24J40 mrf(mosi, miso, sck, cs, reset);
-
 //Button
 DigitalIn Button(BUTTON1);
 bool button;
@@ -83,57 +66,6 @@
 char txBuffer[128];
 char rxBuffer[128];
 int rxLen;
-
-//***************** Do not change these methods (please) *****************//
-/**
-* Receive data from the MRF24J40.
-*
-* @param data A pointer to a char array to hold the data
-* @param maxLength The max amount of data to read.
-*/
-int rf_receive(char *data, uint8_t maxLength)
-{
-    uint8_t len = mrf.Receive((uint8_t *)data, maxLength);
-    uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00};
-
-    if(len > 10) {
-        //Remove the header and footer of the message
-        for(uint8_t i = 0; i < len-2; i++) {
-            if(i<8) {
-                //Make sure our header is valid first
-                if(data[i] != header[i])
-                    return 0;
-            } else {
-                data[i-8] = data[i];
-            }
-        }
-        //pc.printf("Received: %s length:%d\r\n", data, ((int)len)-10);
-    }
-    return ((int)len)-10;
-}
-
-/**
-* Send data to another MRF24J40.
-*
-* @param data The string to send
-* @param maxLength The length of the data to send.
-*                  If you are sending a null-terminated string you can pass strlen(data)+1
-*/
-void rf_send(char *data, uint8_t len)
-{
-    //We need to prepend the message with a valid ZigBee header
-    uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00};
-    uint8_t *send_buf = (uint8_t *) malloc( sizeof(uint8_t) * (len+8) );
-
-    for(uint8_t i = 0; i < len+8; i++) {
-        //prepend the 8-byte header
-        send_buf[i] = (i<8) ? header[i] : data[i-8];
-    }
-    //pc.printf("Sent: %s\r\n", send_buf+8);
-
-    mrf.Send(send_buf, len+8);
-    free(send_buf);
-}
 //***************** You can start coding here *****************//
 
 //Returns true if c is a letter (upper or lower case), false otherwise
@@ -188,7 +120,7 @@
             }
         }
         //Is is a 'end of name' charater? Check for ' ', ':', '-'
-        else if(((c == ' ') | (c == ':') | (c == '-')) & found_name & !complete_name) {// found end name character
+        else if(((c == '|') | (c == ':') | (c == '-')) & found_name & !complete_name) {// found end name character
             if(found_name) {
                 complete_name = true;
                 name_end = i;
@@ -205,7 +137,7 @@
             }
         }
         //Is it a 'end of number' character? Check if its a ' ', ':', '-', or a letter
-        else if( (((c==' ')|(c==':')|(c=='-')) | isLetter(c)) & found_num & complete_name) {
+        else if( (((c=='|')|(c==':')|(c=='-')) | isLetter(c)) & found_num & complete_name) {
             if(found_num) {
                 complete_num = true;
                 num_end = i;
@@ -259,14 +191,12 @@
 
 int main (void)
 {
-    //Set the Channel. 0 is default, 15 is max
-    uint8_t channel = 9; //channel = (Group# - 1)
-    mrf.SetChannel(channel);
-
+    
     //Set Baud rate (9600-115200 is ideal)
     pc.baud(115200);
     pc.printf("\r\n Start! \r\n");
-
+    //This is the wifi network in Detkin that we will be using. If you are somewhere else, change this line.
+    initConnection("hp-setup-1","WelcomeHal");
     //Start Timer
     timer.start();
 
@@ -288,24 +218,6 @@
         //(3)Read Button Val, Add to buffer
         button = !Button.read(); //button is active low
 
-#ifdef RECEIVE
-        //RECEIVE DATA: Try to receive some data
-        rxLen = rf_receive(rxBuffer, 128);
-        if(rxLen > 0) {
-            //Toggle the Led
-            led1 = led1^1;
-           
-            //(4) Process data with our protocal 
-            communication_protocal(rxLen);
-            counter++;
-            //Print values once we recieve and process data
-            pc.printf("Received| ");
-            pc.printf(COMMUNICATION_FORMAT, jstick_h, jstick_v, knob1, knob2, knob3, knob4, button);
-            pc.printf("\r\n");
-        }//main if
-        pc.printf("Received %d transmissions \r\n", counter);
-#endif
-
 #ifdef SEND    
         //SEND DATA: Send some data every 1/2 second
         if(timer.read_ms() >= 500) {
@@ -318,7 +230,7 @@
             sprintf(txBuffer, COMMUNICATION_FORMAT, jstick_h, jstick_v, knob1, knob2, knob3, knob4, button);
     
             //(6) Send the buffer
-            rf_send(txBuffer, strlen(txBuffer) + 1);
+            sendGET(txBuffer);
             pc.printf("Sent| %s\r\n", txBuffer);
         }   
 #endif