#include "project.h" volatile int request_search; static void mqtt_cmd (char *type) { char *m; char *who, *what; m = rindex (type, ' '); if (!m) return; *m = 0; m++; while (index (type, ' ') == type) type++; who = index (type, ' '); if (who) *who = 0; who = index (type, '/'); if (!who) { who = ""; what = ""; } else { *who = 0; who++; what = index (who, '/'); if (!what) what = ""; else { *what = 0; what++; } } mqtt_dispatch (type, who, what, m); } static void cmd_dispatch (char *cmd) { if (!strcmp (cmd, "SEARCH")) { request_search = 1; return; } if (!strncmp (cmd, "MQTT ", 5)) { mqtt_cmd (cmd + 5); return; } printf ("Unknown command %s\n", cmd); } static void kbd_dispatch (void) { static char cmd_buf[80]; static unsigned cmd_ptr; uint8_t c; while (!ring_read_byte (&rx1_ring, &c)) { switch (c) { case ' ': case '\t': if (!cmd_ptr) break; /*fall through */ default: cmd_buf[cmd_ptr++] = c; cmd_buf[cmd_ptr] = 0; if (cmd_ptr < (sizeof (cmd_buf) - 1)) break; /*fall through*/ case '\r': case '\n': if (!cmd_ptr) break; cmd_dispatch (cmd_buf); cmd_ptr = 0; break; } } } int main (void) { /*set up pll */ rcc_clock_setup_in_hse_8mhz_out_72mhz(); /*turn on clocks which aren't done elsewhere */ rcc_periph_clock_enable (RCC_GPIOA); rcc_periph_clock_enable (RCC_GPIOB); rcc_periph_clock_enable (RCC_GPIOC); rcc_periph_clock_enable (RCC_GPIOD); rcc_periph_clock_enable (RCC_GPIOE); rcc_periph_clock_enable (RCC_AFIO); //watchdog_init (); /*Adjust interrupt priorities so that uarts trump timer */ nvic_set_priority (NVIC_USART1_IRQ, 0x40); nvic_set_priority (NVIC_USART2_IRQ, 0x40); nvic_set_priority (NVIC_USART3_IRQ, 0x40); nvic_set_priority (NVIC_SYSTICK_IRQ, 0xff); ticker_init(); usart_init(); led_init(); onewire_init(); inputs_init(); outputs_init(); logic_init(); printf ("D: RESET\n"); for (;;) { if (!ring_empty (&rx1_ring)) kbd_dispatch(); logic_dispatch(); } return 0; }