Exemple #1
0
// returns the next byte to send - first the packet type, then the data length
// then the channel and then the data (len bytes).
//
// Used by UART code to include type and length in packet
//
// returns -1 if empty
static int16_t read_char_from_packet(packet_t *buf) {
        int16_t rv = -1;
        switch (txstate) {
        case TX_TYPE:
                txstate = TX_LEN;
                rv = 0xff & packet_get_type(buf);
//if (rv == FS_TERM && packet_get_chan(buf) == FSFD_SETOPT) led_on();
                break;
        case TX_LEN:
                txstate = TX_CHANNEL;
                rv = (0xff & packet_get_contentlen(buf)) + 3;	// plus 2 to adhere to packet wire format
		break;
	case TX_CHANNEL:
		rv = 0xff & packet_get_chan(buf);
                if (packet_get_contentlen(buf) == 0) {
                        txstate = TX_IDLE;
                } else {
                        txstate = TX_DATA;
                }
                break;
        case TX_DATA:
                rv = 0xff & packet_read_char(buf);
                if (!packet_has_data(buf)) {
                        txstate = TX_IDLE;
                }
                break;
        default:
                break;
        }
        return rv;
}
Exemple #2
0
// there shouldn't be much debug output, as sending it may invariably 
// receive the next option, triggering the option again. But it isn't
// re-entrant!
static uint8_t setopt_callback(int8_t channelno, int8_t errno, packet_t *rxpacket) {

        //debug_printf("setopt cb err=%d\n", errno);
        if (errno == CBM_ERROR_OK) {
                //debug_printf("rx command: %s\n", buf);

		uint8_t cmd = packet_get_type(rxpacket);
		uint8_t len = packet_get_contentlen(rxpacket);

		switch(cmd) {
		case FS_SETOPT:
			do_setopt(buf, len);
			break;
		case FS_RESET:
			rtconfig_pullconfig(0, NULL);
			break;
		}
        }
	// callback returns 1 to continue receiving on this channel
        return 1;
}