FreeCalypso > hg > freecalypso-tools
annotate rvinterf/etmsync/fsnew.c @ 943:31a36b400cdf
fc-shell: replace libg23 with libprint
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 24 May 2023 07:11:18 +0000 |
parents | 37b38b1a1136 |
children |
rev | line source |
---|---|
321
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we are going to implement the commands that upload |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * new FreeCalypso-invented stuff into the FFS of our FC devices. |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/wait.h> |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <unistd.h> |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "exitcodes.h" |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
754
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
12 char batterytab_compile_tool[] = "/opt/freecalypso/bin/compile-fc-batt"; |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
13 char batterytab2_compile_tool[] = "/opt/freecalypso/bin/compile-fc-batt2"; |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
14 char charging_compile_tool[] = "/opt/freecalypso/bin/compile-fc-chg"; |
321
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 upload_fc_table_from_ascii(asciisrc, compiletool, ffs_pathname) |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char *asciisrc, *compiletool, *ffs_pathname; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char tmpfile[] = "/tmp/fc-fsioXXXXXX"; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int tmpfd; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 pid_t child, waitres; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int status, rc; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 tmpfd = mkstemp(tmpfile); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (tmpfd < 0) { |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fprintf(stderr, "unable to get temp file via mkstemp()\n"); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return(ERROR_UNIX); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 close(tmpfd); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 child = vfork(); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (child < 0) { |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, "unable to vfork to run compiler tool\n"); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 unlink(tmpfile); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(ERROR_UNIX); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (!child) { |
465
003e48f8ebe1
rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel
Mychaela Falconia <falcon@freecalypso.org>
parents:
321
diff
changeset
|
37 execl(compiletool, compiletool, asciisrc, tmpfile, (char *) 0); |
321
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 perror(compiletool); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 _exit(ERROR_UNIX); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 waitres = waitpid(child, &status, 0); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (waitres != child || !WIFEXITED(status)) { |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 fprintf(stderr, "unexpected wait result after compiler run\n"); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 unlink(tmpfile); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(ERROR_UNIX); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 rc = WEXITSTATUS(status); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (rc) { |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 unlink(tmpfile); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 return rc; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 rc = fwrite_from_file(ffs_pathname, tmpfile); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 unlink(tmpfile); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return rc; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
754
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
57 cmd_write_battery_table_v1(argc, argv) |
321
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 char **argv; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return upload_fc_table_from_ascii(argv[1], batterytab_compile_tool, |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 "/etc/batterytab"); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
754
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
64 cmd_write_battery_table_v2(argc, argv) |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
65 char **argv; |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
66 { |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
67 return upload_fc_table_from_ascii(argv[1], batterytab2_compile_tool, |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
68 "/etc/batterytab2"); |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
69 } |
2cd5ac909e23
fc-fsio write-battery-table replaced with write-battery-table-{v1,v2}
Mychaela Falconia <falcon@freecalypso.org>
parents:
465
diff
changeset
|
70 |
321
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 cmd_write_charging_config(argc, argv) |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 char **argv; |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 { |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 return upload_fc_table_from_ascii(argv[1], charging_compile_tool, |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 "/etc/charging"); |
0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
813
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
77 |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
78 cmd_write_bsim_config(argc, argv) |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
79 char **argv; |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
80 { |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
81 static char filename[] = "/etc/batterysim"; |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
82 u_char bytes[4]; |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
83 |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
84 bytes[0] = strtoul(argv[1], 0, 0); |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
85 bytes[1] = strtoul(argv[2], 0, 0); |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
86 bytes[2] = 0; /* RFU */ |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
87 bytes[3] = 0; /* RFU */ |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
88 return do_short_fwrite(filename, bytes, 4); |
37b38b1a1136
fc-fsio write-bsim-config implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
754
diff
changeset
|
89 } |