FreeCalypso > hg > freecalypso-tools
comparison rvinterf/tmsh/bsimresp.c @ 817:9706832b740b
fc-tmsh: ETM_BSIM response handling implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 15 May 2021 01:00:52 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
816:b3724fe6c581 | 817:9706832b740b |
---|---|
1 /* | |
2 * Handling of ETM_BSIM responses (FreeCalypso addition to fw) | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include "bsim_etm_cmd.h" | |
8 | |
9 extern u_char rvi_msg[]; | |
10 extern int rvi_msg_len; | |
11 | |
12 static char *cmd_names[] = { | |
13 "query", "disch", "start", "ci2cv", "complete", "ichg", "start-enable" | |
14 }; | |
15 | |
16 static void | |
17 handle_bsim_error() | |
18 { | |
19 char *errstr; | |
20 char msg[80]; | |
21 | |
22 if (rvi_msg_len != 6) { | |
23 print_etm_pkt_raw("ETM_BSIM long error packet"); | |
24 return; | |
25 } | |
26 switch (rvi_msg[3]) { | |
27 case BSIM_ERR_BAD_CMD: | |
28 errstr = "bad command opcode"; | |
29 break; | |
30 case BSIM_ERR_WRONG_STATE: | |
31 errstr = "wrong state"; | |
32 break; | |
33 case BSIM_ERR_INV_PERCENT: | |
34 errstr = "invalid percent"; | |
35 break; | |
36 case BSIM_ERR_INV_DISCHARGE: | |
37 errstr = "invalid discharge"; | |
38 break; | |
39 default: | |
40 errstr = "unknown"; | |
41 } | |
42 sprintf(msg, "bsim %s error 0x%02X (%s)", cmd_names[rvi_msg[4]], | |
43 rvi_msg[3], errstr); | |
44 async_msg_output(msg); | |
45 } | |
46 | |
47 void | |
48 handle_bsim_response() | |
49 { | |
50 char msg[80]; | |
51 | |
52 if (rvi_msg_len == 5 && rvi_msg[3] == 0x3C) { | |
53 async_msg_output("bsim: ETM_NOSYS response"); | |
54 return; | |
55 } | |
56 if (rvi_msg_len < 6) { | |
57 print_etm_pkt_raw("ETM_BSIM response too short"); | |
58 return; | |
59 } | |
60 if (rvi_msg[4] > BSIM_CMD_START_ENABLE) { | |
61 print_etm_pkt_raw("ETM_BSIM unknown opcode"); | |
62 return; | |
63 } | |
64 if (rvi_msg[3]) { | |
65 handle_bsim_error(); | |
66 return; | |
67 } | |
68 if (rvi_msg_len == 6) { | |
69 sprintf(msg, "bsim %s OK", cmd_names[rvi_msg[4]]); | |
70 async_msg_output(msg); | |
71 return; | |
72 } | |
73 if (rvi_msg[4] == BSIM_CMD_QUERY && rvi_msg_len == 9) { | |
74 sprintf(msg, "bsim: state=%u percent=%u start_enable=%u", | |
75 rvi_msg[5], rvi_msg[6], rvi_msg[7]); | |
76 async_msg_output(msg); | |
77 return; | |
78 } | |
79 print_etm_pkt_raw("ETM_BSIM response wrong length"); | |
80 } |