2 Copyright (C) 2012 jaseg <s@jaseg.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 3 as published by the Free Software Foundation.
16 static uint8_t escape_state
= 0;
17 static uint8_t state
= 0;
18 static uint16_t pos
= 0;
19 static uint16_t funcid
= 0;
20 static uint16_t crcbuf
= 0;
21 static uint8_t argbuf
[ARGBUF_SIZE
];
22 static uint16_t arglen
= 0;
24 uint16_t v
= uart_getc_nonblocking();
27 if(!v
){ //a character was successfully received
40 //escape sequence handling completed. 'c' now contains the next char of the payload.
42 case 0: //receive funcid, payload length
63 case 1: //receive arg payload
69 case 2: //receive and check payload crc. finally, call the function and send the return value
75 //successfully received the crc
76 //FIXME add crc checking
77 if(funcid
< NUM_CALLBACKS
){
78 //HACK: The argument buffer is currently passed as the response buffer for ram efficiency.
79 //Only write to the response buffer *after* you are done reading from it.
80 comm_callbacks
[funcid
](arglen
, argbuf
);
82 //FIXME error handling
90 void putc_escaped(char c
){