Part One of my Project Course. Implementation of simple I/O and a custom defined protocol over UDP/IP.

Dependencies:   C12832 LM75B mbed EthernetInterface mbed-rtos

Revision:
0:88d3b9015f7c
Child:
1:b5c534165dfe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master.cpp	Mon Feb 26 11:25:59 2018 +0000
@@ -0,0 +1,97 @@
+#include "master.h"
+#include "command.h"
+#include <string.h>
+#include <stdio.h>
+
+namespace ProjectOne{
+    
+    Serial pc(USBTX, USBRX);
+     
+    Master::Master(void){
+        CurrentMasterState = STATE_INIT;
+        inputCommandArrayPtr = inputCommandArray;
+    }
+
+    void Master::handlePcData(void){
+        sendMessageToPc("Listening for commands.\r\n");
+        switch(CurrentMasterState){
+            case STATE_INIT:
+            {
+                //TO DO UDP init
+                pc.baud(9600);
+                sendMessageToPc("--------------------------------");
+                sendMessageToPc("Initiating serial Communication.");
+                sendMessageToPc("--------------------------------");
+                CurrentMasterState = STATE_RECEIVING;
+                break;
+            }
+            case STATE_RECEIVING:
+            {
+                sendMessageToPc("In state receiving.\r\n");
+                char temp;
+
+                sendMessageToPc("In state receiving in if loop.\r\n");
+                char_counter = 0;
+                for(int i = 0; i <= 19; i ++){
+                    temp = pc.getc();
+                    if((int)temp == 13){
+                        sendMessageToPc("Enter detected.\r\n");
+                        CurrentMasterState = STATE_HANDLE_STRING;
+                        break;
+                    }
+                    //appendChar(inputCommandArray, temp, char_counter);
+                    inputCommandArray[char_counter] = temp;
+                    sendMessageToPc("Appending character to array.\r\n");
+                    char_counter++;
+                }
+                CurrentMasterState = STATE_HANDLE_STRING;  
+
+                break;
+            }
+            case STATE_HANDLE_STRING:
+            {
+                sendMessageToPc("In state handle string.\r\n");
+                char_counter = 0;
+                
+                sendMessageToPc(inputCommandArray);
+                
+                char command_type[3];
+                char command[17];
+                
+                strncpy(command_type, inputCommandArray, 3);
+                strncpy(command, inputCommandArray + 4, 17);
+
+                sendMessageToPc(command_type); //type command PUT of GET
+                sendMessageToPc(command); //Welke command
+                
+                //Van hieruit frame maken en verzenden naar andere mbed met commando
+                
+                memset(&inputCommandArray[0], 0, sizeof(inputCommandArray));
+                CurrentMasterState = STATE_RECEIVING;
+                break;
+            }
+        }
+    }
+    
+    //ACK 2.05 = 1, ACK 2.04 = 2, ACK 4.00 = 3
+    void Master::sendAcknowledgement(int ack_type, int value_to_include){  //dit moet in UDP klasse
+        
+    }
+    
+    void Master::sendMessageToPc(char *message_to_pc){
+        printf(message_to_pc);
+        printf("\r\n");
+    }
+    
+    void Master::appendChar(char array[], char charToAppend, int position){
+        
+    }
+    
+   
+} 
+
+
+    
+
+   
+    
\ No newline at end of file