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 LM75B mbed-rtos mbed
Diff: Slave.cpp
- Revision:
- 3:fbf3c92f10ee
- Parent:
- 2:ecc0c5c14bc1
- Child:
- 7:2de256f902c8
diff -r ecc0c5c14bc1 -r fbf3c92f10ee Slave.cpp --- a/Slave.cpp Fri Mar 16 13:05:57 2018 +0000 +++ b/Slave.cpp Fri Mar 16 16:11:17 2018 +0000 @@ -1,16 +1,4 @@ #include "slave.h" -#include "string.h" -#include "temperature.h" -#include "potentiometer.h" -#include "lcdcontrol.h" -#include "led.h" -#include "buzzer.h" - -Temperature temperature; -Potentiometer potentiometer; -LcdControl screen; -Led led; -Buzzer buzzer; Slave::Slave() :answer() @@ -18,8 +6,9 @@ //Constructor } -void Slave::slaveRun(const char* ip) +void Slave::slaveRun(const char* ip, int identity) { + sprintf(id,"%ld",identity); EthernetInterface ethernet; ethernet.init(ip,"255.255.255.0", "192.168.0.1"); ethernet.connect(); @@ -59,7 +48,8 @@ } else { - answerAppend("ACK 4.0 ID"); + answerAppend("ACK 4.0 "); + answerAppend(id); } } @@ -69,47 +59,72 @@ if(strcmp(action, "/temperature") == 0) { sprintf(temp, "%.3f", temperature.getTemperature()); - answerAppend("ACK 2.05 ID "); + answerAppend("ACK 2.05 "); + answerAppend(id); + answerAppend(" "); answerAppend(temp); } else if(strcmp(action, "/potentiometer") == 0) { sprintf(temp, "%.0f", potentiometer.getPotentiometer()*255); - answerAppend("ACK 2.05 ID "); + answerAppend("ACK 2.05 "); + answerAppend(id); + answerAppend(" "); answerAppend(temp); } else { - answerAppend("ACK 4.0 ID"); + answerAppend("ACK 4.0 "); + answerAppend(id); } } void Slave::putRequest(char* action) { - if(strcmp(action, "/lcd") == 0) + if(strcmp(action, "/LCD") == 0) { - answerAppend("ACK 2.04 ID"); + answerAppend("ACK 2.04 "); + answerAppend(id); screen.lcdSlave(strtok(NULL, "\0")); } else - if(strcmp(action, "/led") == 0) + if(strcmp(action, "/LED") == 0) { - answerAppend("ACK 2.04 ID"); + if(led.setColor(strtok(NULL, " ")) == 0) + { + answerAppend("ACK 2.04 "); + answerAppend(id); + } + else + { + answerAppend("ACK 4.0 "); + answerAppend(id); + } led.setColor(strtok(NULL, " ")); } else - if(strcmp(action, "/buzzer") == 0) + if(strcmp(action, "/BUZZER") == 0) { - answerAppend("ACK 2.04 ID"); int one = atoi(strtok(NULL, " -")); int two = atoi(strtok(NULL, " -")); - printf("%d %d", one,two); - buzzer.playBuzzer(one, two); + if(one > 0 && one < 17 && two <18 && two > 0) + { + buzzer.playBuzzer(one,two); + answerAppend("ACK 2.04 "); + answerAppend(id); + } + else + { + answerAppend("ACK 4.0 "); + answerAppend(id); + answerAppend(" Doet da eki nie, danke"); + } } else { - answerAppend("ACK 4.0 ID"); + answerAppend("ACK 4.0 "); + answerAppend(id); } }