FreeCalypso > hg > freecalypso-tools
annotate rvinterf/asyncshell/battery.c @ 763:4eaad91f4d68
CHANGES: document rvinterf -b PID addition
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 02 Dec 2020 20:32:02 +0000 |
parents | b55a81ce7497 |
children |
rev | line source |
---|---|
748
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Functions for sending MMI_BATTERY_IND primitives with simulated |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * battery actions. |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <ctype.h> |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "pktmux.h" |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "limits.h" |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "exitcodes.h" |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static u_char mmi_battery_ind_fixedpart[24] = { |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 RVT_L23_HEADER, 0x97, 24, 0, |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 0, 0, 0, 0, |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 'P', 'C', 'O', ' ', |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 'M', 'M', 'I', ' ', |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 'M', 'M', 'I', ' ', |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 0x03, 0x4E, 0, 0 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 }; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 send_mmi_battery_ind(byte1, byte2) |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 u_char pkt[28]; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 bcopy(mmi_battery_ind_fixedpart, pkt, 24); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 pkt[24] = byte1; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 pkt[25] = byte2; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 /* 2 padding bytes */ |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 pkt[26] = 0; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 pkt[27] = 0; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 send_pkt_to_target(pkt, 28); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(0); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 cmd_batt_common(argc, argv) |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 char **argv; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 u_char bytes[2]; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int i; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 char *endp; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 for (i = 0; i < 2; i++) { |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 bytes[i] = strtoul(argv[i], &endp, 0); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (*endp) { |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 printf("error: invalid batt argument\n"); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 return(ERROR_USAGE); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return send_mmi_battery_ind(bytes[0], bytes[1]); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 void |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 cmd_batt_interactive(argstr) |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 char *argstr; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 char *argv[3]; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 int argc, rc; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 rc = parse_interactive_command_into_argv(argstr, argv, 2, 2, &argc); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (rc < 0) |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 cmd_batt_common(argc, argv); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 cmd_batt_oneshot(argc, argv) |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 char **argv; |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return cmd_batt_common(argc - 1, argv + 1); |
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |