void uecmd_net_main() { if (!uip_newdata()) return; char *p = (char *) uip_appdata; /* This may be 1-2 chars too big in case there is a \r or \n, but it saves us a counting loop */ char cmd[uip_datalen() + 1]; char *dp = cmd; /* Copy over into temporary buffer, remove \r \n if present, add \0 */ while (p < (char *) uip_appdata + uip_datalen()) { if (*p == '\r' || *p == '\n') break; *dp++ = *p++; } *dp = 0; uip_slen = 0; while (uip_slen < UIP_BUFSIZE - UIP_IPUDPH_LEN) { int16_t len = ecmd_parse_command(cmd, ((char *) uip_appdata) + uip_slen, (UIP_BUFSIZE - UIP_IPUDPH_LEN) - uip_slen); uint8_t real_len = len; if (!is_ECMD_FINAL(len)) { /* what about the errors ? */ /* convert ECMD_AGAIN back to ECMD_FINAL */ real_len = (uint8_t) ECMD_AGAIN(len); } uip_slen += real_len + 1; ((char *) uip_appdata)[uip_slen - 1] = '\n'; if (real_len == len || len == 0) break; } /* Sent data out */ uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = BUF->srcport; echo_conn.lport = HTONS(ECMD_UDP_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
void debug_process_uart (void) { #if defined(ECMD_PARSER_SUPPORT) && !defined(SOFT_UART_SUPPORT) #define LEN 60 #define OUTPUTLEN 40 static char buf[LEN+1]; static char *ptr = buf; if (usart(UCSR,A) & _BV(usart(RXC))) { char data = usart(UDR); if (data == '\n' || data == '\r') { char *output = malloc(OUTPUTLEN); if (output == NULL) debug_printf("malloc() failed!\n"); *ptr = '\0'; printf_P(PSTR("\n")); #ifdef DEBUG_ECMD debug_printf("parsing command '%s'\n", buf); #endif int l; do { l = ecmd_parse_command(buf, output, LEN); if (is_ECMD_FINAL(l) || is_ECMD_AGAIN(l)) { output[is_ECMD_AGAIN(l) ? ECMD_AGAIN(l) : l] = 0; printf_P(PSTR("%s\n"), output); } } while (is_ECMD_AGAIN(l)); free(output); ptr = buf; } else { debug_uart_put(data, stdout); if (data == '\b') {if (ptr > &buf[0]) ptr--;} else { if (ptr < &buf[LEN-1]) *ptr++ = data; else debug_printf("not enough space for storing '%c'\n", data); } } } #endif /* ECMD_PARSER_SUPPORT && !SOFT_UART_SUPPORT*/ }
void cron_execute(struct cron_event_linkedlist *exec) { if (exec->event.cmd == CRON_JUMP) { #ifdef DEBUG_CRON debug_printf("cron: match (JUMP %p)\n", &(exec->event.handler)); #endif #ifndef DEBUG_CRON_DRYRUN exec->event.handler(&(exec->event.extradata)); #endif } else if (exec->event.cmd == CRON_ECMD) { // ECMD PARSER #ifdef DEBUG_CRON debug_printf("cron: match (%s)\n", (char *) &(exec->event.ecmddata)); #endif #ifndef DEBUG_CRON_DRYRUN char output[ECMD_INPUTBUF_LENGTH]; #ifdef DEBUG_CRON int16_t l = #endif ecmd_parse_command((char *) &(exec->event.ecmddata), output, sizeof(output) - 1); #ifdef DEBUG_CRON if (is_ECMD_AGAIN(l)) l = ECMD_AGAIN(l); if (is_ECMD_FINAL(l)) { output[l] = 0; debug_printf("cron output %s\n", output); } else { debug_printf("cron output error %d\n", l); } #endif #endif } /* Execute job endless if repeat value is equal to zero otherwise * decrement the value and check if is equal to zero. * If that is the case, it is time to kick out this cronjob. */ if (exec->event.repeat > 0 && !(--exec->event.repeat)) cron_jobrm(exec); }
void uecmd_net_main() { if (!uip_newdata ()) return; char *p = (char *)uip_appdata; /* Add \0 to the data and remove \n from the data */ do { if (*p == '\r' || *p == '\n') { break; } } while ( ++p <= ((char *)uip_appdata + uip_datalen())); /* Parse the Data */ *p = 0; char cmd[p - (char *)uip_appdata]; strncpy(cmd, uip_appdata, p - (char *)uip_appdata + 1); uip_slen = 0; while (uip_slen < UIP_BUFSIZE - UIP_IPUDPH_LEN) { int16_t len = ecmd_parse_command(cmd, ((char *)uip_appdata) + uip_slen, (UIP_BUFSIZE - UIP_IPUDPH_LEN) - uip_slen); uint8_t real_len = len; if (!is_ECMD_FINAL(len)) { /* what about the errors ? */ /* convert ECMD_AGAIN back to ECMD_FINAL */ real_len = (uint8_t) ECMD_AGAIN(len); } uip_slen += real_len + 1; ((char *)uip_appdata)[uip_slen - 1] = '\n'; if (real_len == len || len == 0) break; } /* Sent data out */ uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = BUF->srcport; echo_conn.lport = HTONS(ECMD_UDP_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }