109#include "lwip/icmp.h"
110#include "lwip/tcpip.h"
118#define DEFAULT_BROADCAST_PACKET_COUNT 10
120#define DEFAULT_UDP_PORT 1337
122#define DEFAULT_PACKET_INTERVAL_MS 10000
124#define BROADCAST_PACKET_MAX_TX_PAYLOAD_LEN 35
126#define BROADCAST_PACKET_TX_PAYLOAD_FMT "G'day World, packet no. %lu."
128#define DEFAULT_UDP_BROADCAST_MODE TX_MODE
130#define DEFAULT_UDP_BROADCAST_ID 0
133#define MMBC_KEY 0x43424d4d
190 const ip_addr_t *addr,
193 LWIP_UNUSED_ARG(pcb);
194 LWIP_UNUSED_ARG(addr);
195 LWIP_UNUSED_ARG(port);
207 uint32_t min_payload_len =
208 sizeof(payload->
key) + (
sizeof(payload->
data[0]) * (metadata->
id + 1));
210 if (p->len < min_payload_len)
212 printf(
"Payload length to short. Len: %u. Min len: %lu\n", p->len, min_payload_len);
218 printf(
"Invalid payload received.\n");
222 printf(
"Valid payload received. \n"
223 " Time since last: %lums\n"
224 " Data recieved: 0x%02x%02x%02x\n\n",
275 for (count = 0; (count < packet_count) || (packet_count == 0); count++)
277 printf(
"Sending Broadcast UDP packet no. %lu.\n", count);
282 printf(
"Failed to allocate pbuf for transmit\n");
288 err = udp_send(pcb, p);
291 printf(
"Failed to send, err:%d.\n", err);
311 struct udp_pcb *pcb = NULL;
316 if (port_num > UINT16_MAX)
319 printf(
"Specified port number is too large. Falling back to %lu\n", port_num);
327 printf(
"Error creating PCB.\n");
331 err = udp_bind(pcb, IP_ADDR_ANY, (uint16_t)port_num);
334 printf(
"Failed to bind, err:%d.\n", err);
357 if (strcasecmp(mode_str,
"tx") == 0)
361 else if (strcasecmp(mode_str,
"rx") == 0)
367 printf(
"Unknown mode: %s. Reverting to default.\n", mode_str);
383 printf(
"\n\nMorse UDP broadcast Demo (Built " __DATE__
" " __TIME__
")\n\n");
int mmconfig_read_string(const char *key, char *buffer, int bufsize)
Returns the persistent store string value identified by the key.
int mmconfig_read_uint32(const char *key, uint32_t *value)
Returns the unsigned integer stored in persistent store identified by the key.
void mmhal_set_led(uint8_t led, uint8_t level)
Set the specified LED to the requested level.
void mmosal_task_sleep(uint32_t duration_ms)
Sleep for a period of time, yielding during that time.
uint32_t mmosal_get_time_ms(void)
Get the system time in milliseconds.
Morse Micro application helper routines for initializing/de-initializing the Wireless LAN interface a...
void app_wlan_stop(void)
Disconnects from Wi-Fi and de-initializes the WLAN interface.
void app_wlan_init(void)
Initializes the WLAN interface (and dependencies) using settings specified in the config store.
void app_wlan_start(void)
Starts the WLAN interface and connects to Wi-Fi using settings specified in the config store.
UDP broadcast rx payload format.
uint8_t blue
Blue intensity.
uint8_t red
Red intensity.
uint32_t key
Key used to identify payload.
uint8_t green
Green intensity.
struct udp_broadcast_rx_payload::@0 data[]
Flexible array member used to access color data for each ID.
static struct udp_pcb * init_udp_pcb(void)
Initialize the UDP protocol control block.
#define BROADCAST_PACKET_MAX_TX_PAYLOAD_LEN
Maximum length of broadcast tx packet payload.
#define DEFAULT_UDP_PORT
UDP port to bind too.
#define BROADCAST_PACKET_TX_PAYLOAD_FMT
Format string to use for the tx packet payload.
static enum udp_broadcast_mode get_mode(void)
Get the mode from config store.
static void udp_broadcast_rx_start(struct udp_pcb *pcb)
Set a receive callback for the UDP PCB.
static void udp_broadcast_tx_start(struct udp_pcb *pcb)
Broadcast a udp packet every DEFAULT_PACKET_INTERVAL_MS until DEFAULT_BROADCAST_PACKET_COUNT packets ...
static void udp_raw_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
Callback function to handle received data from the UDP pcb.
udp_broadcast_mode
Enumeration of the various broadcast modes that can be used.
#define DEFAULT_PACKET_INTERVAL_MS
Interval between successive packet transmission.
#define DEFAULT_UDP_BROADCAST_MODE
Default mode for the application.
void app_init(void)
Main entry point to the application.
static struct udp_broadcast_rx_metadata rx_metadata
Global data structure used in RX mode to record metadata.
#define MMBC_KEY
Key used to identify received broadcast packets.
#define DEFAULT_BROADCAST_PACKET_COUNT
Number of broadcast packet to transmit.