diff options
Diffstat (limited to 'utils/nwztools/plattools/dest_tool.c')
-rw-r--r-- | utils/nwztools/plattools/dest_tool.c | 65 |
1 files changed, 18 insertions, 47 deletions
diff --git a/utils/nwztools/plattools/dest_tool.c b/utils/nwztools/plattools/dest_tool.c index d137239f7f..9fb075e9b3 100644 --- a/utils/nwztools/plattools/dest_tool.c +++ b/utils/nwztools/plattools/dest_tool.c | |||
@@ -23,29 +23,6 @@ | |||
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include "nwz_plattools.h" | 24 | #include "nwz_plattools.h" |
25 | 25 | ||
26 | extern char **environ; | ||
27 | |||
28 | static const char *white_list[] = | ||
29 | { | ||
30 | "NWZ-E463", "NWZ-E464", "NWZ-E465", | ||
31 | "NWZ-A863", "NWZ-A864", "NWZ-A865", "NWZ-A866", "NWZ-A867", | ||
32 | NULL, | ||
33 | }; | ||
34 | |||
35 | /* get model id from ICX_MODEL_ID environment variable */ | ||
36 | static unsigned long find_model_id(void) | ||
37 | { | ||
38 | const char *mid = getenv("ICX_MODEL_ID"); | ||
39 | if(mid == NULL) | ||
40 | return 0; | ||
41 | char *end; | ||
42 | unsigned long v = strtoul(mid, &end, 0); | ||
43 | if(*end) | ||
44 | return 0; | ||
45 | else | ||
46 | return v; | ||
47 | } | ||
48 | |||
49 | static unsigned long read32(unsigned char *buf) | 26 | static unsigned long read32(unsigned char *buf) |
50 | { | 27 | { |
51 | return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; | 28 | return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; |
@@ -111,7 +88,7 @@ int NWZ_TOOL_MAIN(dest_tool)(int argc, char **argv) | |||
111 | sleep(2); | 88 | sleep(2); |
112 | return 1; | 89 | return 1; |
113 | } | 90 | } |
114 | unsigned long model_id = find_model_id(); | 91 | unsigned long model_id = nwz_get_model_id(); |
115 | if(model_id == 0) | 92 | if(model_id == 0) |
116 | { | 93 | { |
117 | nwz_key_close(input_fd); | 94 | nwz_key_close(input_fd); |
@@ -119,37 +96,39 @@ int NWZ_TOOL_MAIN(dest_tool)(int argc, char **argv) | |||
119 | sleep(2); | 96 | sleep(2); |
120 | return 1; | 97 | return 1; |
121 | } | 98 | } |
122 | const char *model_name = nwz_get_model_name(model_id); | 99 | const char *model_name = nwz_get_model_name(); |
123 | if(model_name == NULL) | 100 | if(model_name == NULL) |
124 | model_name = "Unknown"; | 101 | model_name = "Unknown"; |
102 | const char *series_name = "Unknown"; | ||
103 | bool ok_model = false; | ||
104 | if(nwz_get_series() != -1) | ||
105 | { | ||
106 | series_name = nwz_series[nwz_get_series()].name; | ||
107 | ok_model = true; | ||
108 | } | ||
125 | nwz_lcdmsgf(false, 0, 2, "Model ID: %#x", model_id); | 109 | nwz_lcdmsgf(false, 0, 2, "Model ID: %#x", model_id); |
126 | nwz_lcdmsgf(false, 0, 3, "Model Name: %s", model_name); | 110 | nwz_lcdmsgf(false, 0, 3, "Model: %s", model_name); |
111 | nwz_lcdmsgf(false, 0, 4, "Series: %s", series_name); | ||
127 | nwz_lcdmsg(false, 0, 5, "BACK: quit"); | 112 | nwz_lcdmsg(false, 0, 5, "BACK: quit"); |
128 | nwz_lcdmsg(false, 0, 6, "LEFT/RIGHT: change dest"); | 113 | nwz_lcdmsg(false, 0, 6, "LEFT/RIGHT: change dest"); |
129 | nwz_lcdmsg(false, 0, 7, "PLAY/PAUSE: change sps"); | 114 | nwz_lcdmsg(false, 0, 7, "PLAY/PAUSE: change sps"); |
130 | bool ok_model = false; | ||
131 | for(int i = 0; white_list[i]; i++) | ||
132 | if(strcmp(white_list[i], model_name) == 0) | ||
133 | ok_model = true; | ||
134 | /* display input state in a loop */ | 115 | /* display input state in a loop */ |
135 | while(1) | 116 | while(1) |
136 | { | 117 | { |
137 | unsigned char nvp_buf[20]; | 118 | unsigned char nvp_buf[32]; |
138 | bool ok_nvp = false; | 119 | bool ok_nvp = false; |
139 | if(ok_model) | 120 | if(ok_model) |
140 | { | 121 | { |
141 | int fd = open("/dev/icx_nvp/011", O_RDONLY); | 122 | /* make sure node has the right size... */ |
142 | if(fd >= 0) | 123 | if(nwz_nvp_read(NWZ_NVP_SHP, NULL) == sizeof(nvp_buf)) |
143 | { | 124 | { |
144 | ssize_t cnt = read(fd, nvp_buf, sizeof(nvp_buf)); | 125 | if(nwz_nvp_read(NWZ_NVP_SHP, nvp_buf) == sizeof(nvp_buf)) |
145 | if(cnt == (ssize_t)sizeof(nvp_buf)) | ||
146 | ok_nvp = true; | 126 | ok_nvp = true; |
147 | else | 127 | else |
148 | nwz_lcdmsg(false, 1, 9, "Cannot read NVP.\n"); | 128 | nwz_lcdmsg(false, 1, 9, "Cannot read NVP.\n"); |
149 | close(fd); | ||
150 | } | 129 | } |
151 | else | 130 | else |
152 | nwz_lcdmsg(false, 1, 9, "Cannot open NVP.\n"); | 131 | nwz_lcdmsg(false, 1, 9, "NVP node has the wrong size.\n"); |
153 | } | 132 | } |
154 | else | 133 | else |
155 | { | 134 | { |
@@ -203,16 +182,8 @@ int NWZ_TOOL_MAIN(dest_tool)(int argc, char **argv) | |||
203 | /* write nvp */ | 182 | /* write nvp */ |
204 | if(ok_nvp && write_nvp) | 183 | if(ok_nvp && write_nvp) |
205 | { | 184 | { |
206 | int fd = open("/dev/icx_nvp/011", O_RDWR); | 185 | if(nwz_nvp_write(NWZ_NVP_SHP, nvp_buf) != 0) |
207 | if(fd >= 0) | 186 | nwz_lcdmsg(false, 1, 12, "Cannot write NVP.\n"); |
208 | { | ||
209 | ssize_t cnt = write(fd, nvp_buf, sizeof(nvp_buf)); | ||
210 | if(cnt != (ssize_t)sizeof(nvp_buf)) | ||
211 | nwz_lcdmsg(false, 1, 12, "Cannot write NVP.\n"); | ||
212 | close(fd); | ||
213 | } | ||
214 | else | ||
215 | nwz_lcdmsg(false, 1, 12, "Cannot open NVP.\n"); | ||
216 | } | 187 | } |
217 | } | 188 | } |
218 | /* finish nicely */ | 189 | /* finish nicely */ |