bachelorproef

Dependencies:   mbed C12832

Files at this revision

API Documentation at this revision

Comitter:
jonivdh
Date:
Fri Mar 27 15:27:30 2020 +0000
Parent:
2:f65ff03fe1ac
Commit message:
k;

Changed in this revision

LM75B.lib Show diff for this revision Revisions of this file
lcd.cpp Show annotated file Show diff for this revision Revisions of this file
lcd.h Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show diff for this revision Revisions of this file
menu.cpp Show annotated file Show diff for this revision Revisions of this file
menu.h Show annotated file Show diff for this revision Revisions of this file
tcp.cpp Show annotated file Show diff for this revision Revisions of this file
tcp.h Show annotated file Show diff for this revision Revisions of this file
--- a/LM75B.lib	Thu Mar 26 19:53:41 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/neilt6/code/LM75B/#fc27dc535ea9
--- a/lcd.cpp	Thu Mar 26 19:53:41 2020 +0000
+++ b/lcd.cpp	Fri Mar 27 15:27:30 2020 +0000
@@ -37,7 +37,7 @@
     lcd.rect(83, 13, 115, 25, 1);
 }
 
-void LCD::printIP(char IP) {
+void LCD::printIP(unsigned int IP) {
     lcd.cls();
     lcd.locate(3,0);
     lcd.printf("Choose an ip address.");
@@ -70,7 +70,7 @@
     lcd.printf("%s", message);    
 }
 
-void LCD::printfreq(char freq) {
+void LCD::printfreq(unsigned int freq) {
     lcd.cls();
     lcd.locate(3,0);
     lcd.printf("Choose an frequency");
@@ -78,7 +78,7 @@
     lcd.printf("frequency: %d" , freq);
 
 }
-void LCD::printlength(char duration) {
+void LCD::printlength(unsigned int duration) {
     lcd.cls();
     lcd.locate(3,0);
     lcd.printf("Choose an length");
@@ -86,13 +86,4 @@
     lcd.printf("length: %d" , duration); 
 }
 
-void LCD::printback() {
-    lcd.cls();
-    lcd.locate(100,20);
-    lcd.printf("back");    
-}
 
-void LCD::printrectback() {
-    lcd.rect(98, 19, 110, 29, 1);    
-}
-
--- a/lcd.h	Thu Mar 26 19:53:41 2020 +0000
+++ b/lcd.h	Fri Mar 27 15:27:30 2020 +0000
@@ -4,10 +4,10 @@
     
     
     private:
-        char IP;
-        char freq;
-        char duration;
-        char message[];
+        unsigned int IP;
+        unsigned int freq;
+        unsigned int duration;
+        unsigned int message[];
 
         
     public:
@@ -17,15 +17,13 @@
         void printrectreceive();
         void printrectstatus();
         
-        void printIP(char IP);
+        void printIP(unsigned int IP);
         void sendpacket();
         void sendpacketconfirmed();
         void receivepacket();
         void receivepacketconfirmed(char message[]);
-        void printback();
-        void printrectback();
         
-        void printfreq(char freq);
-        void printlength(char duration);
+        void printfreq(unsigned int freq);
+        void printlength(unsigned int duration);
         
 };
\ No newline at end of file
--- a/mbed_app.json	Thu Mar 26 19:53:41 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-{
-    "macros": [
-        "MBED_HEAP_STATS_ENABLED=1",
-        "MBED_STACK_STATS_ENABLED=1",
-        "MBED_MEM_TRACING_ENABLED=1"
-    ],
-    "target_overrides": {
-        "*": {
-            "platform.stdio-baud-rate": 115200,
-            "platform.stdio-convert-newlines": true
-        }
-    }
-}
\ No newline at end of file
--- a/menu.cpp	Thu Mar 26 19:53:41 2020 +0000
+++ b/menu.cpp	Fri Mar 27 15:27:30 2020 +0000
@@ -1,12 +1,11 @@
 #include "menu.h"
-
+#include "tcp.h"
 #include "lcd.h"
-//#include "C12832.h"
-//C12832 lcd(D11, D13, D12, D7, D10);
+#include "platform/mbed_thread.h"
 
 Interrupt newinterrupt(A2,A3,A4,A5,D4);
 LCD newlcd;  
-//TCP tcp;
+TCP tcp;
 Menu::Menu (){
     lastnumberIP = 101;
     frequency = 98;
@@ -45,20 +44,20 @@
         
         case 3:
         newlcd.printrectstatus();
-        break;          
+        break;         
     }
+}
 
-}
 void Menu::receivepacket() {
     newlcd.receivepacket();
-    //tcp.receive();
-    //newlcd.receivepacketconfirmed(tcp.buffer);
+    tcp.receive();
+    newlcd.receivepacketconfirmed(tcp.buffer);
 }
 void Menu::sendpacket() {
         newlcd.sendpacket();
-        //tcp.send(lastnumberIP);
+        tcp.send(lastnumberIP);
         newlcd.sendpacketconfirmed();
-        wait(3.0);
+        thread_sleep_for(3.0);
         newinterrupt.nextScreen = 0;
 }
 
--- a/menu.h	Thu Mar 26 19:53:41 2020 +0000
+++ b/menu.h	Fri Mar 27 15:27:30 2020 +0000
@@ -5,14 +5,14 @@
 class Menu {
     
     public:
-        char lastnumberIP;
-        char frequency;
-        char length;
-        char rectsend;
-        char rectreceive;
-        char rectstatus;
-        char i;
-        char count;
+        unsigned int lastnumberIP;
+        unsigned int frequency;
+        unsigned int length;
+        unsigned int rectsend;
+        unsigned int rectreceive;
+        unsigned int rectstatus;
+        unsigned int i;
+        unsigned int count;
    
     public:
         Menu();
@@ -26,4 +26,5 @@
         void receivepacket();
         void enter();
         void back();
+        void readvalue();
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tcp.cpp	Fri Mar 27 15:27:30 2020 +0000
@@ -0,0 +1,51 @@
+#include "tcp.h"
+ 
+        
+TCP::TCP () {
+    ip = 101;
+    IPString = "";
+    net.set_network ("192.168.0.118", "255.255.255.0", "0");
+    buffer [32];
+    net.connect();
+}
+
+void TCP::send(int ip) {
+    
+    IPString = "192.168.0." + to_string(ip);
+    // Open a socket on the network interface, and create a TCP connection to mbed.org
+    
+    socket.open(&net);
+    socket.connect(IPString.c_str(), 4000);
+    
+    // Send a simple http request
+    char number [] = "hallo";
+    socket.send(number,sizeof number);
+
+
+    // Close the socket to return its memory and bring down the network interface
+    socket.close();
+
+    // Bring down the ethernet interface
+    net.disconnect();
+    printf("Done\n");
+}
+
+
+void TCP::receive() {
+    int rcount = 0;
+    EthernetInterface net;
+    
+    TCPSocket server;
+    server.open(&net);
+
+    server.bind(4000);
+    
+    server.listen();
+    TCPSocket * receiv = server.accept();
+    
+    
+    rcount = receiv->recv(buffer, sizeof buffer);
+    printf("recv %d [%.*s]\n", rcount, strstr(buffer, "\r\n")-buffer, buffer);
+    
+    receiv->close();    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tcp.h	Fri Mar 27 15:27:30 2020 +0000
@@ -0,0 +1,18 @@
+#include "mbed.h"
+#include <EthernetInterface.h>
+#include <string> 
+
+class TCP {
+    
+    public:
+        int ip;
+        char buffer[32];
+        string IPString;
+        EthernetInterface net;
+        TCPSocket socket;
+        
+    public:
+        TCP ();
+        void send(int ip);
+        void receive();  
+};
\ No newline at end of file