9 static uint8_t cmd_buffer[15];
10 static uint8_t cmd_length = 0;
11 static uint8_t cmd_read_pos = 0;
13 static uint8_t dispatch_command(const uint8_t *, uint8_t);
15 void interface_init(void)
18 DDRD = (DDRD&0xFC)|0x02;
23 void interface_check(void)
26 if(serial_read_overrun())
27 interface_send1(RECEIVE_OVERRUN);
29 count = serial_read_available();
35 uint8_t l = ~serial_read();
39 interface_send1(FRAMING_ERROR);
48 if(cmd_read_pos<cmd_length)
51 if(cmd_read_pos+count>cmd_length)
52 count = cmd_length-cmd_read_pos;
53 for(i=0; i<count; ++i)
54 cmd_buffer[cmd_read_pos++] = serial_read();
56 if(cmd_read_pos>=cmd_length)
58 uint8_t result = dispatch_command(cmd_buffer, cmd_length);
59 interface_send1(result);
67 static uint8_t dispatch_command(const uint8_t *cmd, uint8_t length)
69 uint8_t type = cmd[0]>>4;
72 uint8_t subtype = (cmd[0]>>3)&1;
74 return output_command(cmd, length);
76 return monitor_command(cmd, length);
79 return motorola_command(cmd, length);
81 return s88_command(cmd, length);
83 return INVALID_COMMAND;
86 void interface_send(const uint8_t *cmd, uint8_t length)
90 serial_write(~length);
91 for(i=0; i<length; ++i)
95 void interface_send1(uint8_t cmd)