diff options
author | 2019-06-09 23:08:36 +0300 | |
---|---|---|
committer | 2019-06-09 23:08:36 +0300 | |
commit | 7c5042af3c606081d3f4b917ef667f6ed05780a8 (patch) | |
tree | d6f7adcaca6cb22ca44002b41dba43e069ffbebd /src/device/device_network.cpp | |
parent | 613622e8cb3c1d32c50e19d7f446d0c00c91250e (diff) | |
download | usurpation-7c5042af3c606081d3f4b917ef667f6ed05780a8.tar.gz usurpation-7c5042af3c606081d3f4b917ef667f6ed05780a8.tar.bz2 usurpation-7c5042af3c606081d3f4b917ef667f6ed05780a8.zip |
hook various previously unused modules together.
This now allows us to send messages to the device and such. Yay? Yay.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/device/device_network.cpp')
-rw-r--r-- | src/device/device_network.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/device/device_network.cpp b/src/device/device_network.cpp index e526519..bd8467b 100644 --- a/src/device/device_network.cpp +++ b/src/device/device_network.cpp @@ -63,13 +63,17 @@ int udp_flush(void) size_t udp_get_data(char *buf, size_t size) { size_t ret; + + state.udp.parsePacket(); + if ((ret = state.udp.available())) { state.udp.read(buf, size); } + return ret; } -void discover_client(const int port) +IPAddress *discover_client(const int port) { IPAddress bcastip(255, 255, 255, 255); char buffer[128] = {0}; @@ -92,20 +96,19 @@ void discover_client(const int port) delay(5); expected_s = sizeof(field.head) + sizeof(heartbeat_server); - while (state.udp.parsePacket()) { - if (state.udp.available() >= expected_s) { - state.udp.read(buffer, sizeof(buffer)); - tlv_get(buffer, &field, NULL); - if (field.head.type == HEARTBEAT && !(strcmp(heartbeat_server, field.data))) { - state.daemon_ip = state.udp.remoteIP(); - ++state.acquired; - } + if (udp_get_data(buffer, sizeof(buffer)) >= expected_s) { + tlv_get(buffer, &field, NULL); + if (field.head.type == HEARTBEAT && !(strcmp(heartbeat_server, field.data))) { + state.daemon_ip = state.udp.remoteIP(); + ++state.acquired; } } delay(95); } while (!state.acquired); tlv_packet_destroy(&pack); + + return &state.daemon_ip; } IPAddress *get_daemon_address(void) |