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:
- 7:2de256f902c8
- Parent:
- 3:fbf3c92f10ee
- Child:
- 8:556a5738c2fa
--- a/Slave.cpp Sun Mar 18 15:57:55 2018 +0000 +++ b/Slave.cpp Mon Mar 19 00:58:20 2018 +0000 @@ -1,5 +1,8 @@ #include "slave.h" +#define MAX_BUFFER_SIZE 512 +#define PORT 4000 + Slave::Slave() :answer() { @@ -12,14 +15,15 @@ EthernetInterface ethernet; ethernet.init(ip,"255.255.255.0", "192.168.0.1"); ethernet.connect(); - printf("Your ip is: %s", ethernet.getIPAddress()); + + //printf("Your ip is: %s", ethernet.getIPAddress()); UDPSocket slave; - slave.bind(4000); + slave.bind(PORT); Endpoint master; while(1){ - char buffer[512] = {0}; + char buffer[MAX_BUFFER_SIZE] = {0}; printf("\nWaiting for UDP packet...\n\r"); int n = slave.receiveFrom(master, buffer, sizeof(buffer)); @@ -29,13 +33,13 @@ printf("Received: '%s'\r\n", buffer); actionSlave(buffer); - slave.sendTo(master, answer, 50); + slave.sendTo(master, answer, MAX_BUFFER_SIZE); answerReset(); } } -void Slave::actionSlave(const char* bufferke){ - char* command = strtok((char*)bufferke, " "); +void Slave::actionSlave(const char* fullbuffer){ + char* command = strtok((char*)fullbuffer, " "); char* action = strtok(NULL, " "); if(strcmp(command, "GET") == 0) {