Projectlab Elektronica-ICT KULeuven

Dependencies:   EthernetInterface TMP102 TextLCD mbed-rtos mbed

werking.pdf

Files at this revision

API Documentation at this revision

Comitter:
seppeduwe
Date:
Mon Mar 17 18:40:46 2014 +0000
Parent:
3:344115c04cd0
Commit message:
Einde Labo

Changed in this revision

Frame.cpp Show annotated file Show diff for this revision Revisions of this file
Frame.h Show annotated file Show diff for this revision Revisions of this file
Server.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 344115c04cd0 -r 466d859bfb13 Frame.cpp
--- a/Frame.cpp	Sun Mar 16 18:56:08 2014 +0000
+++ b/Frame.cpp	Mon Mar 17 18:40:46 2014 +0000
@@ -58,7 +58,7 @@
             printf("IDs %d \n\r",IDs[i]);
         }
     }
-    return CheckCRC(frame);
+    return CheckCRC();
 }
 
 int Frame::Encode(char* encode)
@@ -129,7 +129,7 @@
     }
     printf("End testEncode\n\r");
 }
-int Frame::CheckCRC(char* frame)
+int Frame::CheckCRC()
 {
     if(crc == MakeCRC((char)(12+lengthIDs),(char)IdDestinationMbed,(char)(temperature>>8),(char)temperature,(char)pWMDutycycle,(char* )IDs,lengthIDs))
         return 1;
@@ -174,9 +174,9 @@
 {
     return (int) (0.026862*temperature-25);
 }
-void Frame::setPWMDutycycle(int pWMDutycycle)
+void Frame::setPWMDutycycle(float pWMDutycycle)
 {
-    this->pWMDutycycle=pWMDutycycle;
+    this->pWMDutycycle=(int) (pWMDutycycle*255);
 }
 void Frame::setTune(int tune)
 {
diff -r 344115c04cd0 -r 466d859bfb13 Frame.h
--- a/Frame.h	Sun Mar 16 18:56:08 2014 +0000
+++ b/Frame.h	Mon Mar 17 18:40:46 2014 +0000
@@ -22,7 +22,7 @@
     int Decode(char* frame);
     int MakeCRC(char LEN, char IDD, char TMP0, char TMP1, char PWM, char* data, int lenghtData);
     void testEncode(char* encode);
-    int CheckCRC(char* frame);
+    int CheckCRC();
     int CheckMyID(int id);
     void AddID(int id);
     //int Length(char* frame);
@@ -30,7 +30,7 @@
     int getIdDestinationMbed(void);
     void setTemperature(float temperature);
     int getTemperature(void);
-    void setPWMDutycycle(int pWMDutycycle);
+    void setPWMDutycycle(float pWMDutycycle);
     void setTune(int tune);
     int getTune(void);
     void setLengthIDs(int lengthIDs);
diff -r 344115c04cd0 -r 466d859bfb13 Server.cpp
--- a/Server.cpp	Sun Mar 16 18:56:08 2014 +0000
+++ b/Server.cpp	Mon Mar 17 18:40:46 2014 +0000
@@ -35,7 +35,7 @@
 void Server::send(char* data)
 {
     socket->send_all(data, 256);
-    printf("Send data %s\n\r",data);
+    printf("Send data");//,data);
     socket->close();
 }
 int Server::read(char* buffer)
diff -r 344115c04cd0 -r 466d859bfb13 main.cpp
--- a/main.cpp	Sun Mar 16 18:56:08 2014 +0000
+++ b/main.cpp	Mon Mar 17 18:40:46 2014 +0000
@@ -43,24 +43,25 @@
         if(server.read(buf)) {
             if(!dataFrame.Decode(buf))
                 printf("Frame CRC Error \n\r");
-            if(dataFrame.getIdDestinationMbed()==7) {
+            if((dataFrame.getIdDestinationMbed()==7) && (!dataFrame.CheckMyID(7))) {
                 printf("Voor mij\n\r");
                 PWMout=potentiometer.getPotentiometer();
                 PWMout.period(0.010);// set PWM period to 10 ms
                 tune.play(dataFrame.getTune());
-                display.setText("Temp: %d °C",dataFrame.getTemperature());
-                //display.setText("Temp: %d",dataFrame.getTemperature());
+                display.setText("Temp: %d C",dataFrame.getTemperature());
                 dataFrame.setIdDestinationMbed(IpDestination);
                 dataFrame.setTemperature(temp.getTemperature());
                 dataFrame.setPWMDutycycle(potentiometer.getPotentiometer());
                 dataFrame.setTune(dataFrame.getTune()+1);
                 dataFrame.AddID(7);
                 dataFrame.Encode(buf);
-            }
-            if(!dataFrame.CheckMyID(7)) {
                 server.connect(destIp);
                 server.send(buf);
             }
+          /*  if() {
+                server.connect(destIp);
+                server.send(buf);
+            }*/
         }
         if(BoolIpDestination) {
             if(IpDestination!=15)
@@ -68,7 +69,7 @@
             else
                 IpDestination=1;
             sprintf(destIp,"192.168.0.1%02i",IpDestination);
-            display.setText("IP: 192.168.0.1%02i",IpDestination);
+            display.setText("IP:192.168.0.1%02i",IpDestination);
             BoolIpDestination=0;
             wait(0.5);
         }
@@ -76,7 +77,8 @@
             dataFrame.setIdDestinationMbed(IpDestination);
             dataFrame.setTemperature(temp.getTemperature());
             dataFrame.setPWMDutycycle(potentiometer.getPotentiometer());
-            dataFrame.setTune(1);
+            tune.play(1);
+            dataFrame.setTune(2);
             dataFrame.AddID(7);
             //char testIDs[]= {0x08,0x09,0x0A};
             //dataFrame->setLengthIDs(3);