FreeCalypso > hg > freecalypso-sw
comparison rvinterf/packetrx.c @ 133:56b53c289785
rvtdump: some restructuring
| author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
|---|---|
| date | Sat, 02 Nov 2013 22:24:14 +0000 |
| parents | 811b138f1bed |
| children |
comparison
equal
deleted
inserted
replaced
| 132:2c5160a9d652 | 133:56b53c289785 |
|---|---|
| 12 | 12 |
| 13 #define MAXPKT 512 | 13 #define MAXPKT 512 |
| 14 u_char rxpkt[MAXPKT]; | 14 u_char rxpkt[MAXPKT]; |
| 15 size_t rxpkt_len; | 15 size_t rxpkt_len; |
| 16 | 16 |
| 17 extern char pr_item[]; | |
| 18 | |
| 17 static int in_pkt, dle_state, toobig; | 19 static int in_pkt, dle_state, toobig; |
| 18 | 20 |
| 19 static void | 21 static void |
| 20 process_inbyte(inb) | 22 process_inbyte(inb) |
| 21 { | 23 { |
| 22 if (!in_pkt) { | 24 if (!in_pkt) { |
| 23 if (inb != STX || dle_state) { | 25 if (inb != STX || dle_state) { |
| 26 rxpkt_len++; | |
| 24 dle_state = (inb == DLE); | 27 dle_state = (inb == DLE); |
| 25 return; | 28 return; |
| 26 } | 29 } |
| 30 if (rxpkt_len) { | |
| 31 sprintf(pr_item, | |
| 32 "Warning: Rx %u byte%s outside of a packet", | |
| 33 (unsigned)rxpkt_len, rxpkt_len != 1 ? "s" : ""); | |
| 34 print_item(); | |
| 35 rxpkt_len = 0; | |
| 36 } | |
| 27 in_pkt = 1; | 37 in_pkt = 1; |
| 28 rxpkt_len = 0; | |
| 29 toobig = 0; | 38 toobig = 0; |
| 30 return; | 39 return; |
| 31 } | 40 } |
| 32 if (dle_state) { | 41 if (dle_state) { |
| 33 dle_state = 0; | 42 dle_state = 0; |
| 34 if (inb != STX && inb != DLE) { | 43 if (inb != STX && inb != DLE) { |
| 35 printf("Rx framing error: %02X after DLE\n", inb); | 44 sprintf(pr_item, |
| 45 "Rx framing error: %02X after DLE\n", inb); | |
| 46 print_item(); | |
| 36 in_pkt = 0; | 47 in_pkt = 0; |
| 48 rxpkt_len = 0; | |
| 37 return; | 49 return; |
| 38 } | 50 } |
| 39 goto data; | 51 goto data; |
| 40 } | 52 } |
| 41 if (inb == DLE) { | 53 if (inb == DLE) { |
| 44 } else if (inb == STX) { | 56 } else if (inb == STX) { |
| 45 if (!rxpkt_len) | 57 if (!rxpkt_len) |
| 46 return; | 58 return; |
| 47 in_pkt = 0; | 59 in_pkt = 0; |
| 48 handle_rx_packet(); | 60 handle_rx_packet(); |
| 61 rxpkt_len = 0; | |
| 49 return; | 62 return; |
| 50 } | 63 } |
| 51 data: if (rxpkt_len >= MAXPKT) { | 64 data: if (rxpkt_len >= MAXPKT) { |
| 52 if (!toobig) { | 65 if (!toobig) { |
| 53 printf("Rx packet too big!\n"); | 66 sprintf(pr_item, "Error: Rx packet too big!\n"); |
| 67 print_item(); | |
| 54 toobig = 1; | 68 toobig = 1; |
| 55 } | 69 } |
| 56 return; | 70 return; |
| 57 } | 71 } |
| 58 rxpkt[rxpkt_len++] = inb; | 72 rxpkt[rxpkt_len++] = inb; |
