void process_packet(uint8_t* data, uint16_t len) { uint8_t type = data[0]; len--; //len is now the length of the actual packet data++; //advance ptr to start of data if(type == PACKET_BASIC) { if (len != sizeof(struct packet_basic)) { debug_print("packet_receiver.c: wrong packet size!\r\n"); return; } struct packet_basic *pkt = (struct packet_basic *) data; stand_enabled = pkt->stand_enable; solenoid_state = pkt->solenoid_states; watchdog_pet(); } else { debug_print("packet_receiver got unknown packet type: "); debug_print_u32(type); debug_print("\r\n"); } }
/** * \brief Read an unsigned integer from the menu prompt * \param[in] prompt - the text to display * \return the unsigned integer read */ unsigned int menu_read_uint(const char *prompt) { unsigned int value = 0; uart_puts(prompt); while (1) { int c = uart_getchar(); watchdog_pet(); if ((c >= '0') && (c <= '9')) { value *= 10; value += c - '0'; uart_putchar(c); } else if ((c == '\n') || (c == '\r')) { uart_puts("\n"); break; } else { /* Not a valid character */ } } return value; }
/** * \brief Enable the watchdog timer module * The watchdog timeout is set to an interval of 32768 cycles */ void watchdog_enable(void) { /* Read the watchdog interrupt flag */ if (IFG1 & WDTIFG) { /* Clear if set */ IFG1 &= ~WDTIFG; } watchdog_pet(); }