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.
Diff: udp.cpp
- Revision:
- 1:9c211ac06a12
- Parent:
- 0:6df0a6ed91d4
- Child:
- 2:397316d97354
diff -r 6df0a6ed91d4 -r 9c211ac06a12 udp.cpp
--- a/udp.cpp Wed Mar 04 02:04:32 2015 +0000
+++ b/udp.cpp Thu Mar 05 00:18:25 2015 +0000
@@ -1,7 +1,6 @@
#include "flyer.h"
#include "snet.h"
-extern blackboard_t bb;
#if 0
extern Ethernet eth;
@@ -114,46 +113,17 @@
send_to_correspondent((const uint8_t *) s, strlen(s));
}
-void Snet::register_correspondent_for_updates(uint8_t *buf, int len, char updates) {
+void Snet::set_udp_correspondent(uint8_t *buf, int len) {
turn_udp_packet_around(buf);
memcpy(correspondent_facing_packet_header, buf, UDP_PAYLOAD_O);
- bb.updates_for_which_registered = updates;
+}
+
+void Snet::register_correspondent_for_updates(uint8_t *buf, int len, char updates) {
+ set_udp_correspondent(buf, len);
//printf("registered for updates: 0x%x\r\n", updates); //DEBUG
tell_correspondent("OK");
}
-// Hint: $ sudo tcpdump -i eth0 -vvv -Ump -X udp port 2497
-void Snet::handle_quaddb_packet(uint8_t *buf, int len) {
- uint16_t payload_length
- = (buf[UDP_LENGTH_O]<<8) + buf[UDP_LENGTH_O+1]
- - (UDP_PAYLOAD_O - UDP_HEADER_O);
-#if 0
- printf("quaddb %d bytes:", payload_length);
- print_hex(&buf[UDP_PAYLOAD_O], len-UDP_PAYLOAD_O);
-#endif
- char *payload = (char *) &buf[UDP_PAYLOAD_O];
- switch (payload[0]) {
- case '~':
- send_packet_to_radio((uint8_t *)payload+1, payload_length-1);
- break;
- case '?':
- if (strcmp(payload+1, "bb") == 0) {
-// printf("got '?bb'\r\n"); //DEBUG
- return_udp_packet(buf, (const uint8_t *) &bb, sizeof(bb));
- };
- break;
- case 'e': //echo
- //printf("echo %d bytes\r\n", payload_length-1); //DEBUG
- return_udp_packet(buf, (const uint8_t *) payload+1, payload_length-1);
- break;
- case 'r': //register
- register_correspondent_for_updates(buf, len, payload[1]);
- break;
- default:
- printf("Unknown request:");
- print_hex(&buf[UDP_PAYLOAD_O], payload_length);
- }
-};
void Snet::handle_udp_packet(uint8_t *buf, int len) {
@@ -161,10 +131,5 @@
printf("UDP:");
print_hex(&buf[UDP_HEADER_O], len-UDP_HEADER_O);
#endif
-// /etc/services has: quaddb 2497/udp # Quad DB
-// It appears to be defunct. Cute, we'll take it.
- if (buf[UDP_DST_PORT_O+0] == 0x09
- && buf[UDP_DST_PORT_O+1] == 0xc1) {
- handle_quaddb_packet(buf, len);
- }
+ if (registered_udp_handler) (*registered_udp_handler)(buf, len);
};