![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
Interpreter.cpp@20:fe6a58e84929, 2018-04-18 (annotated)
- Committer:
- KlaasGovaerts
- Date:
- Wed Apr 18 14:34:31 2018 +0000
- Revision:
- 20:fe6a58e84929
- Parent:
- 18:5ee34e60a31d
- Child:
- 24:bf62c46acb3e
Pakket ontvangen en interpreteren werkt.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KlaasGovaerts | 18:5ee34e60a31d | 1 | #include "Interpreter.h" |
KlaasGovaerts | 18:5ee34e60a31d | 2 | |
KlaasGovaerts | 18:5ee34e60a31d | 3 | Interpreter::Interpreter(int* LEDinput){ |
KlaasGovaerts | 18:5ee34e60a31d | 4 | LED=LEDinput; |
KlaasGovaerts | 18:5ee34e60a31d | 5 | } |
KlaasGovaerts | 18:5ee34e60a31d | 6 | |
KlaasGovaerts | 18:5ee34e60a31d | 7 | void Interpreter::executeCommand(char* command){ |
KlaasGovaerts | 20:fe6a58e84929 | 8 | char *ID=strtok(command,"-"); |
KlaasGovaerts | 18:5ee34e60a31d | 9 | char *direction=strtok(NULL," "); |
KlaasGovaerts | 18:5ee34e60a31d | 10 | while((ID!=NULL)&&(direction!=NULL)){ |
KlaasGovaerts | 18:5ee34e60a31d | 11 | int IDNumber=atoi(ID); |
KlaasGovaerts | 18:5ee34e60a31d | 12 | int directionNumber=directionToNumber(direction); |
KlaasGovaerts | 18:5ee34e60a31d | 13 | if((IDNumber>=0)&&(IDNumber<=11)&&(directionNumber>=-1)&&(directionNumber<=3)){ |
KlaasGovaerts | 18:5ee34e60a31d | 14 | //lock->lock(); |
KlaasGovaerts | 18:5ee34e60a31d | 15 | LED[IDNumber]=directionNumber; |
KlaasGovaerts | 18:5ee34e60a31d | 16 | //lock->unlock(); |
KlaasGovaerts | 18:5ee34e60a31d | 17 | } |
KlaasGovaerts | 20:fe6a58e84929 | 18 | ID=strtok(NULL,"-"); |
KlaasGovaerts | 18:5ee34e60a31d | 19 | direction=strtok(NULL," "); |
KlaasGovaerts | 18:5ee34e60a31d | 20 | } |
KlaasGovaerts | 18:5ee34e60a31d | 21 | } |
KlaasGovaerts | 18:5ee34e60a31d | 22 | |
KlaasGovaerts | 18:5ee34e60a31d | 23 | int Interpreter::directionToNumber(char* direction){ |
KlaasGovaerts | 20:fe6a58e84929 | 24 | if(strcmp(direction,"left")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 25 | return 0; |
KlaasGovaerts | 20:fe6a58e84929 | 26 | else if(strcmp(direction,"right")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 27 | return 1; |
KlaasGovaerts | 20:fe6a58e84929 | 28 | else if(strcmp(direction,"up")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 29 | return 2; |
KlaasGovaerts | 20:fe6a58e84929 | 30 | else if(strcmp(direction,"down")==0) |
KlaasGovaerts | 18:5ee34e60a31d | 31 | return 3; |
KlaasGovaerts | 18:5ee34e60a31d | 32 | else |
KlaasGovaerts | 18:5ee34e60a31d | 33 | return -1; |
KlaasGovaerts | 18:5ee34e60a31d | 34 | } |