Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
Revision 21:fe6a58e84929, committed 2018-04-18
- Comitter:
- KlaasGovaerts
- Date:
- Wed Apr 18 14:34:31 2018 +0000
- Parent:
- 20:4997b02d6a88
- Child:
- 22:488d1b1c2e9d
- Child:
- 23:28e41b1c8a71
- Commit message:
- Pakket ontvangen en interpreteren werkt.
Changed in this revision
--- a/Interpreter.cpp Wed Apr 18 13:58:46 2018 +0000
+++ b/Interpreter.cpp Wed Apr 18 14:34:31 2018 +0000
@@ -5,7 +5,7 @@
}
void Interpreter::executeCommand(char* command){
- char *ID=strtok(command,",");
+ char *ID=strtok(command,"-");
char *direction=strtok(NULL," ");
while((ID!=NULL)&&(direction!=NULL)){
int IDNumber=atoi(ID);
@@ -15,19 +15,19 @@
LED[IDNumber]=directionNumber;
//lock->unlock();
}
- ID=strtok(NULL,",");
+ ID=strtok(NULL,"-");
direction=strtok(NULL," ");
}
}
int Interpreter::directionToNumber(char* direction){
- if(strcmp(direction,"links")==0)
+ if(strcmp(direction,"left")==0)
return 0;
- else if(strcmp(direction,"rechts")==0)
+ else if(strcmp(direction,"right")==0)
return 1;
- else if(strcmp(direction,"boven")==0)
+ else if(strcmp(direction,"up")==0)
return 2;
- else if(strcmp(direction,"onder")==0)
+ else if(strcmp(direction,"down")==0)
return 3;
else
return -1;
--- a/TCPlistener.cpp Wed Apr 18 13:58:46 2018 +0000
+++ b/TCPlistener.cpp Wed Apr 18 14:34:31 2018 +0000
@@ -9,28 +9,8 @@
server.bind(4000);
server.listen();
server.set_blocking(true);
- /*
- for(int i=0;i<10;i++){
- connections[i]=0;
- }*/
arraySize=10;
}
-/*
-void TCPlistener::listen(){
- //server.listen(10);//Accept 10 connections at a time.
- //Source:https://os.mbed.com/handbook/Socket
- bool incomingConnection=true;
- while(incomingConnection){
- TCPSocketConnection* connection=newConnection();
- if(connection!=0){
- if(server.accept(*connection)==-1)
- incomingConnection=false;
- else
- connection->set_blocking(false);
- printf("Connectie van: %s\n", connection->get_address());
- }
- }
-}*/
bool TCPlistener::receiveSegment(char *contents,int size){
printf("Maak een connectie.\r\n");
--- a/TCPlistener.h Wed Apr 18 13:58:46 2018 +0000
+++ b/TCPlistener.h Wed Apr 18 14:34:31 2018 +0000
@@ -9,9 +9,9 @@
private:
EthernetInterface eth;
TCPSocketServer server;
- TCPSocketConnection* connections[10];
+ //TCPSocketConnection* connections[10];
int arraySize;
- TCPSocketConnection* newConnection();
+ //TCPSocketConnection* newConnection();
public:
bool receiveSegment(char *contents,int size);
void listen();
--- a/main.cpp Wed Apr 18 13:58:46 2018 +0000
+++ b/main.cpp Wed Apr 18 14:34:31 2018 +0000
@@ -1,53 +1,23 @@
#include "mbed.h"
+#include "rtos.h"
#include "Interpreter.h"
#include "TCPlistener.h"
int main (void){
- int LED[12];
- for(int i=0;i<12;i++){
+ int LED[8];
+ for(int i=0;i<8;i++){
LED[i]=-1;
}
Interpreter interpreter(LED);
-
TCPlistener listener;
-
char command[512];
- listener.receiveSegment(command,sizeof(command));
- interpreter.executeCommand(command);
-
- for(int i=0;i<8;i++){
- printf("LED %i, oriëntatie: %i\r\n",i,LED[i]);
- }
-
- /*
- char command[512];
- listener.receiveSegment(command,sizeof(command));
- */
- #if 0
- Mutex* lock=new Mutex();
- int LED[12];
- for(int i=0;i<12;i++){
- LED[i]=-1;
- }
- Receiver receiver(LED,lock);
- reciever.init();
- #endif
-
- /*
- Thread receiverThread;
-
- receiverThread.start(receiver.run);
- */
-
-
- //std::thread receiverThread(&Receiver::run, &receiver);
-
-
- /*
-
- Thread ledThread;
-
- receiverThread.start(Receiver);
- */
+ while(true){
+ listener.receiveSegment(command,sizeof(command));
+ interpreter.executeCommand(command);
+
+ for(int i=0;i<8;i++){
+ printf("LED %i, richting: %i\r\n",i,LED[i]);
+ }
+ }
}
