Dependencies:   EthernetInterface FastPWM mbed-rtos mbed MODSERIAL

Revision:
14:e162b5fd0382
Parent:
13:787cabccb2be
Child:
15:15356e30738a
--- a/main.cpp	Wed Jun 20 12:24:37 2018 +0000
+++ b/main.cpp	Wed Jun 27 08:46:42 2018 +0000
@@ -1,14 +1,17 @@
-#include "mbed.h"
-#include "EthernetInterface.h"
-#include "rtos.h"
+// As an advice, stick to the revisions of the libraries as listed below. 
+// These libraries tend not to work on when updated, so be carefull
+
+#include "mbed.h"              //revision 116:c0f6e94411f5
+#include "EthernetInterface.h" //revision 49:2fc406e
+#include "rtos.h"              //revision 98:c825593
 #include <vector>
-#include "FastPWM.h"
+#include "FastPWM.h"           //revision 30:87e38b8
 #include <cmath>
-#include "MODSERIAL.h"
-
+#include "MODSERIAL.h"         //revision 41:d8422ef
+    
 
 //Master or Slave? 1=Master, 0=Slave
-static const int identity = 1;
+static const int identity = 0;
 
 //network config
 static const char* master_ip = "192.168.1.101"; //only for direct communication, otherwise set it up using router tables
@@ -363,7 +366,7 @@
 
 }
 
-void generateOutput(float variable) //generate packet to send to counterpart
+void generateOutput(float variable) //generate packet to send to other device
 {
     memcpy(&output[0],&counter,4);
     memcpy(&output[4],&transparancy,4);
@@ -389,7 +392,7 @@
             if(size>18) { //first check, an minimum amount of data must have arrived
                 memcpy(&check,&data[0],4);
                 if(counter_received < check) { //second check, data must be newer
-                    if((counter_received == check-1)&&(counter_not_missed<100)) {
+                    if((counter_received == check-1)&&(counter_not_missed<100)) { //the package loss check, at this point will only change the light. Total loss of connection is not detected. 
                         counter_not_missed++;
                     } else if((counter_not_missed)>10){
                         counter_not_missed = counter_not_missed + counter_received-check + 1;
@@ -444,7 +447,7 @@
     while(true) {
         if(controller_check==1) {
             debug = 1;
-            float received_input = update_delay(delayArrayINPUT,input);
+            float received_input = update_delay(delayArrayINPUT,input); //arrays used to simulate time delay. If actual timedelay is present, account for this in the initalization of variables.
             float current_transparancy = update_delay(delayArrayMODE,received_transparancy);
             float current_passivity = update_delay(delayArrayPASS,received_passivity);
             float package_in = update_delay(delayArrayENERGY,received_package);
@@ -500,7 +503,7 @@
                 }
             }
             socket.sendTo(counterpart, output, sizeof(output));
-            socket.sendTo(counterpart, output, sizeof(output));
+            socket.sendTo(counterpart, output, sizeof(output)); //this works, as a check on the other side prevents duplicate packets. This does help with package loss.
             counter ++;
             generateStatus();
             socket.sendTo(laptop,status,sizeof(status));
@@ -516,6 +519,5 @@
         osDelay(0.1); // This line is key, otherwise the MBED will not switch to the receive() thread.
     }
 }
+ 
 
-// Also, parts of this code is questionable. As in I don't know why it works. It can be advised to find a library that can have a interrupt on the UPD receive. Or just don't use UDP. although internet. 
-