blob: 43a3d1932ab29b67dc4b09b9e0edd89d775c477b
1 | #include <unistd.h> |
2 | #include <stdio.h> |
3 | #include <string.h> |
4 | #include <errno.h> |
5 | #include <unistd.h> |
6 | #include <sys/ioctl.h> |
7 | #include <sys/types.h> |
8 | #include <sys/stat.h> |
9 | #include <sys/socket.h> |
10 | #include <sys/un.h> |
11 | #include <fcntl.h> |
12 | #include <ctype.h> |
13 | #include <sys/prctl.h> |
14 | #include <stdlib.h> |
15 | #include <android/log.h> |
16 | #include <cutils/android_reboot.h> |
17 | #include "../tvconfig/tvconfig.h" |
18 | #include "../tvsetting/CTvSetting.h" |
19 | #include "../audio/audio_api.h" |
20 | #include "../tv/CFbcCommunication.h" |
21 | #include <cutils/properties.h> |
22 | #include <dirent.h> |
23 | using namespace android; |
24 | |
25 | #include "tvutils.h" |
26 | |
27 | #define LOG_TAG "LibTvMISC" |
28 | #include "CTvLog.h" |
29 | |
30 | #define CS_I2C_1_DEV_PATH "/dev/i2c-1" |
31 | #define CS_I2C_2_DEV_PATH "/dev/i2c-2" |
32 | |
33 | /* number of times a device address should be polled when not acknowledging */ |
34 | #define I2C_RETRIES 0x0701 |
35 | |
36 | /* set timeout in units of 10 ms */ |
37 | #define I2C_TIMEOUT 0x0702 |
38 | |
39 | /* NOTE: Slave address is 7 or 10 bits, but 10-bit addresses |
40 | * are NOT supported! (due to code brokenness) |
41 | */ |
42 | |
43 | /* Use this slave address */ |
44 | #define I2C_SLAVE 0x0703 |
45 | |
46 | /* Use this slave address, even if it is already in use by a driver! */ |
47 | #define I2C_SLAVE_FORCE 0x0706 |
48 | |
49 | #define I2C_TENBIT 0x0704 /* 0 for 7 bit addrs, != 0 for 10 bit */ |
50 | #define I2C_FUNCS 0x0705 /* Get the adapter functionality mask */ |
51 | #define I2C_RDWR 0x0707 /* Combined R/W transfer (one STOP only) */ |
52 | #define I2C_PEC 0x0708 /* != 0 to use PEC with SMBus */ |
53 | #define I2C_SMBUS 0x0720 /* SMBus transfer */ |
54 | |
55 | struct i2c_msg { |
56 | unsigned short addr; /* slave address */ |
57 | unsigned short flags; |
58 | #define I2C_M_TEN 0x0010 /* this is a ten bit chip address */ |
59 | #define I2C_M_WR 0x0000 /* write data, from master to slave */ |
60 | #define I2C_M_RD 0x0001 /* read data, from slave to master */ |
61 | #define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */ |
62 | #define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */ |
63 | #define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */ |
64 | #define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */ |
65 | #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */ |
66 | |
67 | unsigned short len; /* msg length */ |
68 | unsigned char *buf; /* pointer to msg data */ |
69 | }; |
70 | |
71 | struct i2c_rdwr_ioctl_data { |
72 | struct i2c_msg *msgs; |
73 | unsigned int nmsgs; |
74 | }; |
75 | |
76 | static volatile int mDreamPanelResumeLastBLFlag = 0; |
77 | static volatile int mDreamPanelDemoFlag = 0; |
78 | |
79 | static pthread_mutex_t dream_panel_resume_last_bl_flag_mutex = PTHREAD_MUTEX_INITIALIZER; |
80 | static pthread_mutex_t dream_panel_demo_flag_mutex = PTHREAD_MUTEX_INITIALIZER; |
81 | static pthread_mutex_t file_attr_control_flag_mutex = PTHREAD_MUTEX_INITIALIZER; |
82 | |
83 | static pthread_t UserPet_ThreadId = 0; |
84 | static unsigned char is_turnon_user_pet_thread = false; |
85 | static unsigned char is_user_pet_thread_start = false; |
86 | static unsigned int user_counter = 0; |
87 | static unsigned int user_pet_terminal = 1; |
88 | |
89 | static int iw_duty = 0; |
90 | |
91 | static int Miscioctl(const char *file_path, int request, ...) |
92 | { |
93 | int fd = -1, tmp_ret = -1; |
94 | int bus_status = 0; |
95 | va_list ap; |
96 | void *arg; |
97 | |
98 | if (file_path == NULL) { |
99 | LOGE("%s, file path is NULL!!!\n", "TV"); |
100 | return -1; |
101 | } |
102 | |
103 | fd = open(file_path, O_RDWR); |
104 | if (fd < 0) { |
105 | LOGE("%s, Open %s ERROR(%s)!!\n", "TV", file_path, strerror(errno)); |
106 | return -1; |
107 | } |
108 | |
109 | va_start(ap, request); |
110 | arg = va_arg(ap, void *); |
111 | va_end(ap); |
112 | |
113 | tmp_ret = ioctl(fd, request, arg); |
114 | |
115 | close(fd); |
116 | fd = -1; |
117 | |
118 | return tmp_ret; |
119 | } |
120 | |
121 | int cfg_get_one_item(const char *key_str, const char *strDelimit, int item_index, char cfg_str[]) |
122 | { |
123 | int cfg_item_ind = 0; |
124 | char *token = NULL; |
125 | const char *config_value; |
126 | char data_str[CC_CFG_VALUE_STR_MAX_LEN] = { 0 }; |
127 | |
128 | if (key_str == NULL) { |
129 | LOGE("%s, key_str's pointer is NULL.\n", "TV"); |
130 | return -1; |
131 | } |
132 | |
133 | if (cfg_str == NULL) { |
134 | LOGE("%s, cfg_str's pointer is NULL.\n", "TV"); |
135 | return -1; |
136 | } |
137 | |
138 | if (item_index < 0) { |
139 | LOGE("%s, item_index can't be less than 0.\n", "TV"); |
140 | return -1; |
141 | } |
142 | |
143 | config_value = config_get_str("TV", key_str, "null"); |
144 | if (strcasecmp(config_value, "null") == 0) { |
145 | cfg_str[0] = '\0'; |
146 | LOGE("%s, can't get config \"%s\"!!!\n", "TV", key_str); |
147 | return -1; |
148 | } |
149 | |
150 | cfg_item_ind = 0; |
151 | |
152 | memset((void *)data_str, 0, sizeof(data_str)); |
153 | strncpy(data_str, config_value, sizeof(data_str) - 1); |
154 | |
155 | token = strtok(data_str, strDelimit); |
156 | while (token != NULL) { |
157 | if (cfg_item_ind == item_index) { |
158 | strcpy(cfg_str, token); |
159 | break; |
160 | } |
161 | |
162 | token = strtok(NULL, strDelimit); |
163 | cfg_item_ind += 1; |
164 | } |
165 | |
166 | if (token == NULL) { |
167 | cfg_str[0] = '\0'; |
168 | return -1; |
169 | } |
170 | |
171 | return 0; |
172 | } |
173 | |
174 | int cfg_split(char *line_data, char *strDelimit, int *item_cnt, char **item_bufs) |
175 | { |
176 | int i = 0, tmp_cnt = 0; |
177 | char *token = NULL; |
178 | |
179 | if (line_data == NULL) { |
180 | LOGE("%s, line_data is NULL", "TV"); |
181 | return -1; |
182 | } |
183 | |
184 | if (strDelimit == NULL) { |
185 | LOGE("%s, strDelimit is NULL", "TV"); |
186 | return -1; |
187 | } |
188 | |
189 | if (item_cnt == NULL) { |
190 | LOGE("%s, item_cnt is NULL", "TV"); |
191 | return -1; |
192 | } |
193 | |
194 | if (item_bufs == NULL) { |
195 | LOGE("%s, item_bufs is NULL", "TV"); |
196 | return -1; |
197 | } |
198 | |
199 | for (i = 0; i < *item_cnt; i++) { |
200 | item_bufs[i] = NULL; |
201 | } |
202 | |
203 | token = strtok(line_data, strDelimit); |
204 | |
205 | while (token != NULL) { |
206 | item_bufs[tmp_cnt] = token; |
207 | |
208 | token = strtok(NULL, strDelimit); |
209 | |
210 | tmp_cnt += 1; |
211 | if (tmp_cnt >= *item_cnt) { |
212 | break; |
213 | } |
214 | } |
215 | |
216 | *item_cnt = tmp_cnt; |
217 | |
218 | return 0; |
219 | } |
220 | |
221 | int ReadADCSpecialChannelValue(int adc_channel_num) |
222 | { |
223 | FILE *fp = NULL; |
224 | int rd_data = 0; |
225 | char ch_sysfs_path[256] = { 0 }; |
226 | |
227 | if (adc_channel_num < CC_MIN_ADC_CHANNEL_VAL || adc_channel_num > CC_MAX_ADC_CHANNEL_VAL) { |
228 | LOGD("adc channel num must between %d and %d.", CC_MIN_ADC_CHANNEL_VAL, CC_MAX_ADC_CHANNEL_VAL); |
229 | return 0; |
230 | } |
231 | |
232 | sprintf(ch_sysfs_path, "/sys/class/saradc/saradc_ch%d", adc_channel_num); |
233 | |
234 | fp = fopen(ch_sysfs_path, "r"); |
235 | |
236 | if (fp == NULL) { |
237 | LOGE("open %s ERROR(%s)!!\n", ch_sysfs_path, strerror(errno)); |
238 | return 0; |
239 | } |
240 | |
241 | fscanf(fp, "%d", &rd_data); |
242 | |
243 | fclose(fp); |
244 | |
245 | return rd_data; |
246 | } |
247 | |
248 | int Tv_MiscRegs(const char *cmd) |
249 | { |
250 | //#ifdef BRING_UP_DEBUG |
251 | FILE *fp = NULL; |
252 | fp = fopen("/sys/class/register/reg", "w"); |
253 | |
254 | if (fp != NULL && cmd != NULL) { |
255 | fprintf(fp, "%s", cmd); |
256 | } else { |
257 | LOGE("Open /sys/class/register/reg ERROR(%s)!!\n", strerror(errno)); |
258 | fclose(fp); |
259 | return -1; |
260 | } |
261 | fclose(fp); |
262 | //#endif |
263 | |
264 | return 0; |
265 | } |
266 | |
267 | int TvMisc_SetUserCounterTimeOut(int timeout) |
268 | { |
269 | FILE *fp; |
270 | |
271 | fp = fopen("/sys/devices/platform/aml_wdt/user_pet_timeout", "w"); |
272 | |
273 | if (fp != NULL) { |
274 | fprintf(fp, "%d", timeout); |
275 | fclose(fp); |
276 | } else { |
277 | LOGE("=OSD CPP=> open /sys/devices/platform/aml_wdt/user_pet_timeout ERROR(%s)!!\n", strerror(errno)); |
278 | return -1; |
279 | } |
280 | return 0; |
281 | } |
282 | |
283 | int TvMisc_SetUserCounter(int count) |
284 | { |
285 | FILE *fp; |
286 | |
287 | fp = fopen("/sys/module/aml_wdt/parameters/user_pet", "w"); |
288 | |
289 | if (fp != NULL) { |
290 | fprintf(fp, "%d", count); |
291 | fclose(fp); |
292 | } else { |
293 | LOGE("=OSD CPP=> open /sys/devices/platform/aml_wdt/user_pet ERROR(%s)!!\n", strerror(errno)); |
294 | return -1; |
295 | } |
296 | |
297 | fclose(fp); |
298 | |
299 | return 0; |
300 | } |
301 | |
302 | int TvMisc_SetUserPetResetEnable(int enable) |
303 | { |
304 | FILE *fp; |
305 | |
306 | fp = fopen("/sys/module/aml_wdt/parameters/user_pet_reset_enable", "w"); |
307 | |
308 | if (fp != NULL) { |
309 | fprintf(fp, "%d", enable); |
310 | fclose(fp); |
311 | } else { |
312 | LOGE("=OSD CPP=> open /sys/devices/platform/aml_wdt/user_pet_reset_enable ERROR(%s)!!\n", strerror(errno)); |
313 | return -1; |
314 | } |
315 | |
316 | fclose(fp); |
317 | |
318 | return 0; |
319 | } |
320 | |
321 | int TvMisc_SetSystemPetResetEnable(int enable) |
322 | { |
323 | FILE *fp; |
324 | |
325 | fp = fopen("/sys/devices/platform/aml_wdt/reset_enable", "w"); |
326 | |
327 | if (fp != NULL) { |
328 | fprintf(fp, "%d", enable); |
329 | fclose(fp); |
330 | } else { |
331 | LOGE("=OSD CPP=> open /sys/devices/platform/aml_wdt/reset_enable ERROR(%s)!!\n", strerror(errno)); |
332 | return -1; |
333 | } |
334 | |
335 | fclose(fp); |
336 | |
337 | return 0; |
338 | } |
339 | |
340 | int TvMisc_SetSystemPetEnable(int enable) |
341 | { |
342 | FILE *fp; |
343 | |
344 | fp = fopen("/sys/devices/platform/aml_wdt/ping_enable", "w"); |
345 | |
346 | if (fp != NULL) { |
347 | fprintf(fp, "%d", enable); |
348 | fclose(fp); |
349 | } else { |
350 | LOGE("=OSD CPP=> open /sys/devices/platform/aml_wdt/ping_enable ERROR(%s)!!\n", strerror(errno)); |
351 | return -1; |
352 | } |
353 | |
354 | fclose(fp); |
355 | |
356 | return 0; |
357 | } |
358 | |
359 | int TvMisc_SetSystemPetCounterTimeOut(int timeout) |
360 | { |
361 | FILE *fp; |
362 | |
363 | fp = fopen("/sys/devices/platform/aml_wdt/wdt_timeout", "w"); |
364 | |
365 | if (fp != NULL) { |
366 | fprintf(fp, "%d", timeout); |
367 | fclose(fp); |
368 | } else { |
369 | LOGE("=OSD CPP=> open /sys/devices/platform/aml_wdt/wdt_timeout ERROR(%s)!!\n", strerror(errno)); |
370 | return -1; |
371 | } |
372 | |
373 | fclose(fp); |
374 | |
375 | return 0; |
376 | } |
377 | |
378 | #define MEMERASE _IOW('M', 2, struct erase_info_user) |
379 | static int memerase(int fd, struct erase_info_user *erase) |
380 | { |
381 | return (ioctl (fd, MEMERASE, erase)); |
382 | } |
383 | |
384 | #define CS_ATV_SOCKET_FILE_NAME "/dev/socket/datv_sock" |
385 | |
386 | static int setServer(const char *fileName) |
387 | { |
388 | int ret = -1, sock = -1; |
389 | struct sockaddr_un srv_addr; |
390 | |
391 | sock = socket(PF_UNIX, SOCK_STREAM, 0); |
392 | if (sock < 0) { |
393 | LOGE("%s, socket create failed (errno = %d: %s).\n", "TV", errno, strerror(errno)); |
394 | return -1; |
395 | } |
396 | |
397 | //set server addr_param |
398 | srv_addr.sun_family = AF_UNIX; |
399 | strncpy(srv_addr.sun_path, CS_ATV_SOCKET_FILE_NAME, sizeof(srv_addr.sun_path) - 1); |
400 | unlink(CS_ATV_SOCKET_FILE_NAME); |
401 | |
402 | //bind sockfd & addr |
403 | ret = bind(sock, (struct sockaddr *) &srv_addr, sizeof(srv_addr)); |
404 | if (ret == -1) { |
405 | LOGE("%s, cannot bind server socket.\n", "TV"); |
406 | close(sock); |
407 | unlink(CS_ATV_SOCKET_FILE_NAME); |
408 | return -1; |
409 | } |
410 | |
411 | //listen sockfd |
412 | ret = listen(sock, 1); |
413 | if (ret == -1) { |
414 | LOGE("%s, cannot listen the client connect request.\n", "TV"); |
415 | close(sock); |
416 | unlink(CS_ATV_SOCKET_FILE_NAME); |
417 | return -1; |
418 | } |
419 | |
420 | return sock; |
421 | } |
422 | |
423 | static int acceptMessage(int listen_fd) |
424 | { |
425 | int ret, com_fd; |
426 | socklen_t len; |
427 | struct sockaddr_un clt_addr; |
428 | |
429 | //have connect request use accept |
430 | len = sizeof(clt_addr); |
431 | com_fd = accept(listen_fd, (struct sockaddr *) &clt_addr, &len); |
432 | if (com_fd < 0) { |
433 | LOGE("%s, cannot accept client connect request.\n", "TV"); |
434 | close(listen_fd); |
435 | unlink(CS_ATV_SOCKET_FILE_NAME); |
436 | return -1; |
437 | } |
438 | |
439 | LOGD("%s, com_fd = %d\n", "TV", com_fd); |
440 | |
441 | return com_fd; |
442 | } |
443 | |
444 | static int parse_socket_message(char *msg_str, int *para_cnt, int para_buf[]) |
445 | { |
446 | int para_count = 0, set_mode = 0; |
447 | char *token = NULL; |
448 | |
449 | set_mode = -1; |
450 | |
451 | token = strtok(msg_str, ","); |
452 | if (token != NULL) { |
453 | if (strcasecmp(token, "quit") == 0) { |
454 | set_mode = 0; |
455 | } else if (strcasecmp(token, "SetAudioVolumeCompensationVal") == 0) { |
456 | set_mode = 1; |
457 | } else if (strcasecmp(token, "set3dmode") == 0) { |
458 | set_mode = 2; |
459 | } else if (strcasecmp(token, "setdisplaymode") == 0) { |
460 | set_mode = 3; |
461 | } |
462 | } |
463 | |
464 | if (set_mode != 1 && set_mode != 2 && set_mode != 3) { |
465 | return set_mode; |
466 | } |
467 | |
468 | para_count = 0; |
469 | |
470 | token = strtok(NULL, ","); |
471 | while (token != NULL) { |
472 | para_buf[para_count] = strtol(token, NULL, 10); |
473 | para_count += 1; |
474 | |
475 | token = strtok(NULL, ","); |
476 | } |
477 | |
478 | *para_cnt = para_count; |
479 | |
480 | return set_mode; |
481 | } |
482 | |
483 | /*static void* socket_thread_entry(void *arg) |
484 | { |
485 | int ret = 0, listen_fd = -1, com_fd = -1, rd_len = 0; |
486 | int para_count = 0, set_mode = 0; |
487 | int tmp_val = 0; |
488 | int para_buf[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; |
489 | static char recv_buf[1024]; |
490 | |
491 | listen_fd = setServer(CS_ATV_SOCKET_FILE_NAME); |
492 | chmod(CS_ATV_SOCKET_FILE_NAME, 0666); |
493 | prctl(PR_SET_NAME, (unsigned long) "datv.sock.thread"); |
494 | |
495 | if (listen_fd < 0) { |
496 | return NULL; |
497 | } |
498 | |
499 | while (1) { |
500 | com_fd = acceptMessage(listen_fd); |
501 | |
502 | if (com_fd >= 0) { |
503 | //read message from client |
504 | memset((void *) recv_buf, 0, sizeof(recv_buf)); |
505 | rd_len = read(com_fd, recv_buf, sizeof(recv_buf)); |
506 | LOGD("%s, message from client (%d)) : %s\n", "TV", rd_len, recv_buf); |
507 | |
508 | set_mode = parse_socket_message(recv_buf, ¶_count, para_buf); |
509 | if (set_mode == 0) { |
510 | LOGD("%s, receive quit message, starting to quit.\n", "TV"); |
511 | sprintf(recv_buf, "%s", "quiting now..."); |
512 | write(com_fd, recv_buf, strlen(recv_buf) + 1); |
513 | break; |
514 | } else if (set_mode == 1) { |
515 | ret = -1; |
516 | |
517 | if (para_count == 1) { |
518 | LOGD("%s, SetAudioVolumeCompensationVal value = %d\n", "TV", para_buf[0]); |
519 | |
520 | ret = SetAudioVolumeCompensationVal(para_buf[0]); |
521 | } else if (para_count == 2) { |
522 | LOGD("%s, SetAudioVolumeCompensationVal value = %d, type = %d\n", "TV", para_buf[0], para_buf[1]); |
523 | |
524 | ret = SetAudioVolumeCompensationVal(para_buf[0]); |
525 | |
526 | if (para_buf[1] == 1) { |
527 | tmp_val = GetAudioMasterVolume(); |
528 | ret |= SetAudioMasterVolume(tmp_val); |
529 | } |
530 | } |
531 | |
532 | sprintf(recv_buf, "%d", ret); |
533 | write(com_fd, recv_buf, strlen(recv_buf) + 1); |
534 | } else if (set_mode == 2) { |
535 | ret = -1; |
536 | |
537 | if (para_count == 1) { |
538 | LOGE("%s, mode = %d ------->\n", "TV", para_buf[0]); |
539 | |
540 | switch (para_buf[0]) { |
541 | case 4: //BT |
542 | ret = Tvin_Set3DFunction(MODE3D_BT); |
543 | break; |
544 | case 5: //LR |
545 | ret = Tvin_Set3DFunction(MODE3D_LR); |
546 | break; |
547 | case 8: // |
548 | ret = Tvin_Set3DFunction(MODE3D_DISABLE); |
549 | break; |
550 | case 0: |
551 | ret = Tvin_Set3DFunction(MODE3D_DISABLE); |
552 | break; |
553 | case 9: // |
554 | ret = Tvin_Set3DFunction(MODE3D_L_3D_TO_2D); |
555 | break; |
556 | } |
557 | if (ret == 0) { |
558 | LOGE("%s, sk_hdi_av_set_3d_mode return sucess.\n", "TV"); |
559 | } else { |
560 | LOGE("%s, sk_hdi_av_set_3d_mode return error(%d).\n", "TV", ret); |
561 | } |
562 | } |
563 | |
564 | sprintf(recv_buf, "%d", ret); |
565 | write(com_fd, recv_buf, strlen(recv_buf) + 1); |
566 | |
567 | } |
568 | |
569 | close(com_fd); |
570 | com_fd = -1; |
571 | } |
572 | } |
573 | |
574 | if (com_fd >= 0) { |
575 | close(com_fd); |
576 | com_fd = -1; |
577 | } |
578 | |
579 | if (listen_fd >= 0) { |
580 | close(listen_fd); |
581 | listen_fd = -1; |
582 | } |
583 | |
584 | unlink(CS_ATV_SOCKET_FILE_NAME); |
585 | |
586 | return NULL; |
587 | }*/ |
588 | |
589 | #if !defined(SUN_LEN) |
590 | #define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) |
591 | #endif |
592 | |
593 | static int connectToServer(char *file_name) |
594 | { |
595 | int tmp_ret = 0, sock = -1; |
596 | struct sockaddr_un addr; |
597 | |
598 | if (file_name == NULL) { |
599 | LOGE("%s, file name is NULL\n", "TV"); |
600 | return -1; |
601 | } |
602 | |
603 | sock = socket(AF_UNIX, SOCK_STREAM, 0); |
604 | if (sock < 0) { |
605 | LOGE("%s, socket create failed (errno = %d: %s)\n", "TV", errno, strerror(errno)); |
606 | return -1; |
607 | } |
608 | |
609 | /* connect to socket; fails if file doesn't exist */ |
610 | strcpy(addr.sun_path, file_name); // max 108 bytes |
611 | addr.sun_family = AF_UNIX; |
612 | tmp_ret = connect(sock, (struct sockaddr *) &addr, SUN_LEN(&addr)); |
613 | if (tmp_ret < 0) { |
614 | // ENOENT means socket file doesn't exist |
615 | // ECONNREFUSED means socket exists but nobody is listening |
616 | LOGE("%s, AF_UNIX connect failed for '%s': %s\n", "TV", file_name, strerror(errno)); |
617 | close(sock); |
618 | return -1; |
619 | } |
620 | |
621 | return sock; |
622 | } |
623 | |
624 | static int realSendSocketMsg(char *file_name, char *msg_str, char recv_buf[]) |
625 | { |
626 | int sock = -1, rd_len = 0; |
627 | char tmp_buf[1024]; |
628 | |
629 | if (file_name == NULL) { |
630 | LOGE("%s, file name is NULL\n", "TV"); |
631 | return -1; |
632 | } |
633 | |
634 | if (msg_str == NULL) { |
635 | LOGE("%s, msg string is NULL\n", "TV"); |
636 | return -1; |
637 | } |
638 | |
639 | LOGD("%s, message to server (%d)) : %s\n", "TV", strlen(msg_str), msg_str); |
640 | |
641 | sock = connectToServer(file_name); |
642 | |
643 | if (sock >= 0) { |
644 | write(sock, msg_str, strlen(msg_str) + 1); |
645 | |
646 | if (recv_buf == NULL) { |
647 | memset((void *) tmp_buf, 0, sizeof(tmp_buf)); |
648 | rd_len = read(sock, tmp_buf, sizeof(tmp_buf)); |
649 | LOGD("%s, message from server (%d)) : %s\n", "TV", rd_len, tmp_buf); |
650 | } else { |
651 | rd_len = read(sock, recv_buf, 1024); |
652 | LOGD("%s, message from server (%d)) : %s\n", "TV", rd_len, recv_buf); |
653 | } |
654 | |
655 | close(sock); |
656 | sock = -1; |
657 | |
658 | return 0; |
659 | } |
660 | |
661 | return -1; |
662 | } |
663 | |
664 | int I2C_WriteNbyte(int i2c_no, int dev_addr, int slave_addr, int len, unsigned char data_buf[]) |
665 | { |
666 | int tmp_ret = 0; |
667 | struct i2c_rdwr_ioctl_data ctl_data; |
668 | struct i2c_msg msg; |
669 | unsigned char msg_buf[52]; |
670 | int device_fd = -1; |
671 | |
672 | memset((void *) msg_buf, 0, 52); |
673 | |
674 | msg_buf[0] = (unsigned char) (slave_addr >> 8); |
675 | msg_buf[1] = (unsigned char) (slave_addr & 0x00ff); |
676 | |
677 | if (data_buf == NULL) { |
678 | return -1; |
679 | } |
680 | |
681 | if (len < 50) { |
682 | memcpy((void *) &msg_buf[2], data_buf, len); |
683 | } else { |
684 | LOGE("I2C_WriteNbyte len(%d) > 50, error!\n", len); |
685 | return -1; |
686 | } |
687 | |
688 | msg.addr = dev_addr; |
689 | msg.flags = I2C_M_WR; |
690 | msg.len = 2 + len; |
691 | msg.buf = msg_buf; |
692 | ctl_data.nmsgs = 1; |
693 | ctl_data.msgs = &msg; |
694 | |
695 | if (i2c_no == 1) { |
696 | device_fd = open(CS_I2C_1_DEV_PATH, O_RDWR); |
697 | if (device_fd < 0) { |
698 | LOGE("%s, Open device file %S error: %s.\n", "TV", CS_I2C_1_DEV_PATH, strerror(errno)); |
699 | return -1; |
700 | } |
701 | } else if (i2c_no == 2) { |
702 | device_fd = open(CS_I2C_2_DEV_PATH, O_RDWR); |
703 | if (device_fd < 0) { |
704 | LOGE("%s, Open device file %S error: %s.\n", "TV", CS_I2C_2_DEV_PATH, strerror(errno)); |
705 | return -1; |
706 | } |
707 | } else { |
708 | LOGE("%s, invalid i2c no (%d).\n", "TV", i2c_no); |
709 | return -1; |
710 | } |
711 | |
712 | tmp_ret = ioctl(device_fd, I2C_RDWR, &ctl_data); |
713 | |
714 | usleep(10 * 1000); |
715 | if (device_fd >= 0) { |
716 | close(device_fd); |
717 | device_fd = -1; |
718 | } |
719 | return tmp_ret; |
720 | } |
721 | |
722 | int I2C_ReadNbyte(int i2c_no, int dev_addr, int slave_addr, int len, unsigned char data_buf[]) |
723 | { |
724 | int tmp_ret = 0; |
725 | struct i2c_rdwr_ioctl_data ctl_data; |
726 | struct i2c_msg msg; |
727 | unsigned char msg_buf[52]; |
728 | int device_fd = -1; |
729 | |
730 | memset((void *) msg_buf, 0, 52); |
731 | |
732 | if (data_buf == NULL) { |
733 | return -1; |
734 | } |
735 | |
736 | if (len < 50) { |
737 | memcpy((void *) &msg_buf[2], data_buf, len); |
738 | } else { |
739 | LOGE("I2C_WriteNbyte len(%d) > 50, error!\n", len); |
740 | return -1; |
741 | } |
742 | |
743 | msg_buf[0] = (unsigned char) (slave_addr >> 8); |
744 | msg_buf[1] = (unsigned char) (slave_addr & 0x00ff); |
745 | msg.addr = dev_addr; |
746 | msg.flags = I2C_M_WR; |
747 | msg.len = 2; |
748 | msg.buf = msg_buf; |
749 | ctl_data.nmsgs = 1; |
750 | ctl_data.msgs = &msg; |
751 | |
752 | if (i2c_no == 1) { |
753 | device_fd = open(CS_I2C_1_DEV_PATH, O_RDWR); |
754 | if (device_fd < 0) { |
755 | LOGE("%s, Open device file %S error: %s.\n", "TV", CS_I2C_1_DEV_PATH, strerror(errno)); |
756 | return -1; |
757 | } |
758 | } else if (i2c_no == 2) { |
759 | device_fd = open(CS_I2C_2_DEV_PATH, O_RDWR); |
760 | if (device_fd < 0) { |
761 | LOGE("%s, Open device file %S error: %s.\n", "TV", CS_I2C_2_DEV_PATH, strerror(errno)); |
762 | return -1; |
763 | } |
764 | } else { |
765 | LOGE("%s, invalid i2c no (%d).\n", "TV", i2c_no); |
766 | return -1; |
767 | } |
768 | |
769 | tmp_ret = ioctl(device_fd, I2C_RDWR, &ctl_data); |
770 | |
771 | msg.addr = dev_addr; |
772 | msg.flags |= I2C_M_RD; |
773 | msg.len = len; |
774 | msg.buf = data_buf; |
775 | ctl_data.nmsgs = 1; |
776 | ctl_data.msgs = &msg; |
777 | |
778 | tmp_ret = ioctl(device_fd, I2C_RDWR, &ctl_data); |
779 | |
780 | usleep(10 * 1000); |
781 | |
782 | if (device_fd >= 0) { |
783 | close(device_fd); |
784 | device_fd = -1; |
785 | } |
786 | return tmp_ret; |
787 | } |
788 | |
789 | int SetFileAttrValue(const char *fp, const char value[]) |
790 | { |
791 | int fd = -1, ret = -1; |
792 | |
793 | pthread_mutex_lock(&file_attr_control_flag_mutex); |
794 | |
795 | fd = open(fp, O_RDWR); |
796 | |
797 | if (fd < 0) { |
798 | LOGE("open %s ERROR(%s)!!\n", fp, strerror(errno)); |
799 | pthread_mutex_unlock(&file_attr_control_flag_mutex); |
800 | return -1; |
801 | } |
802 | |
803 | ret = write(fd, value, strlen(value)); |
804 | close(fd); |
805 | |
806 | pthread_mutex_unlock(&file_attr_control_flag_mutex); |
807 | return ret; |
808 | } |
809 | |
810 | int GetFileAttrIntValue(const char *fp) |
811 | { |
812 | int fd = -1, ret = -1; |
813 | int temp = -1; |
814 | char temp_str[32]; |
815 | |
816 | memset(temp_str, 0, 32); |
817 | |
818 | fd = open(fp, O_RDWR); |
819 | |
820 | if (fd <= 0) { |
821 | LOGE("open %s ERROR(%s)!!\n", fp, strerror(errno)); |
822 | return -1; |
823 | } |
824 | |
825 | if (read(fd, temp_str, sizeof(temp_str)) > 0) { |
826 | if (sscanf(temp_str, "%d", &temp) >= 0) { |
827 | LOGD("%s -> get %s value =%d!\n", "TV", fp, temp); |
828 | close(fd); |
829 | return temp; |
830 | } else { |
831 | LOGE("%s -> get %s value error(%s)\n", "TV", fp, strerror(errno)); |
832 | close(fd); |
833 | return -1; |
834 | } |
835 | } |
836 | |
837 | close(fd); |
838 | return -1; |
839 | } |
840 | |
841 | int *GetFileAttrIntValueStr(const char *fp) |
842 | { |
843 | int fd = -1, ret = -1; |
844 | static int temp[4]; |
845 | char temp_str[32]; |
846 | int i = 0; |
847 | char *p = NULL; |
848 | |
849 | memset(temp_str, 0, 32); |
850 | |
851 | fd = open(fp, O_RDWR); |
852 | |
853 | if (fd <= 0) { |
854 | LOGE("open %s ERROR(%s)!!\n", fp, strerror(errno)); |
855 | return NULL; |
856 | } |
857 | |
858 | if(read(fd, temp_str, sizeof(temp_str)) > 0) { |
859 | LOGD("%s,temp_str = %s\n", "TV", temp_str); |
860 | p = strtok(temp_str, " "); |
861 | while(p != NULL) { |
862 | sscanf(p, "%d", &temp[i]); |
863 | p = strtok(NULL, " "); |
864 | i = i + 1; |
865 | } |
866 | close(fd); |
867 | return temp; |
868 | } |
869 | |
870 | close(fd); |
871 | return NULL; |
872 | } |
873 | |
874 | int Get_Fixed_NonStandard(void) |
875 | { |
876 | return GetFileAttrIntValue("/sys/module/tvin_afe/parameters/force_nostd"); |
877 | } |
878 | |
879 | //0-turn off |
880 | //1-force non-standard |
881 | //2-force normal |
882 | int Set_Fixed_NonStandard(int value) |
883 | { |
884 | int fd = -1, ret = -1; |
885 | char set_vale[32]; |
886 | memset(set_vale, '\0', 32); |
887 | |
888 | sprintf(set_vale, "%d", value); |
889 | |
890 | fd = open("/sys/module/tvin_afe/parameters/force_nostd", O_RDWR); |
891 | |
892 | if (fd >= 0) { |
893 | ret = write(fd, set_vale, strlen(set_vale)); |
894 | } |
895 | |
896 | if (ret <= 0) { |
897 | LOGE("%s -> set /sys/module/tvin_afe/parameters/force_nostd error(%s)!\n", "TV", strerror(errno)); |
898 | } |
899 | |
900 | close(fd); |
901 | |
902 | return ret; |
903 | } |
904 | |
905 | static void *UserPet_TreadRun(void *data) |
906 | { |
907 | while (is_turnon_user_pet_thread == true) { |
908 | if (is_user_pet_thread_start == true) { |
909 | usleep(1000 * 1000); |
910 | if (++user_counter == 0xffffffff) |
911 | user_counter = 1; |
912 | TvMisc_SetUserCounter(user_counter); |
913 | } else { |
914 | usleep(10000 * 1000); |
915 | } |
916 | } |
917 | if (user_pet_terminal == 1) { |
918 | user_counter = 0; |
919 | } else { |
920 | user_counter = 1; |
921 | } |
922 | TvMisc_SetUserCounter(user_counter); |
923 | return ((void *) 0); |
924 | } |
925 | |
926 | static int UserPet_CreateThread(void) |
927 | { |
928 | int ret = 0; |
929 | pthread_attr_t attr; |
930 | struct sched_param param; |
931 | |
932 | is_turnon_user_pet_thread = true; |
933 | is_user_pet_thread_start = true; |
934 | |
935 | pthread_attr_init(&attr); |
936 | pthread_attr_setschedpolicy(&attr, SCHED_RR); |
937 | param.sched_priority = 1; |
938 | pthread_attr_setschedparam(&attr, ¶m); |
939 | ret = pthread_create(&UserPet_ThreadId, &attr, &UserPet_TreadRun, NULL); |
940 | pthread_attr_destroy(&attr); |
941 | return ret; |
942 | } |
943 | |
944 | static void UserPet_KillThread(void) |
945 | { |
946 | int i = 0, dly = 600; |
947 | is_turnon_user_pet_thread = false; |
948 | is_user_pet_thread_start = false; |
949 | for (i = 0; i < 2; i++) { |
950 | usleep(dly * 1000); |
951 | } |
952 | pthread_join(UserPet_ThreadId, NULL); |
953 | UserPet_ThreadId = 0; |
954 | LOGD("%s, done.", "TV"); |
955 | } |
956 | |
957 | void TvMisc_EnableWDT(bool kernelpet_disable, unsigned int userpet_enable, unsigned int kernelpet_timeout, unsigned int userpet_timeout, unsigned int userpet_reset) |
958 | { |
959 | TvMisc_SetSystemPetCounterTimeOut(kernelpet_timeout); |
960 | TvMisc_SetSystemPetEnable(1); |
961 | if (kernelpet_disable) { |
962 | TvMisc_SetSystemPetResetEnable(0); |
963 | } else { |
964 | TvMisc_SetSystemPetResetEnable(1); |
965 | } |
966 | if (userpet_enable) { |
967 | TvMisc_SetUserCounterTimeOut(userpet_timeout); |
968 | TvMisc_SetUserPetResetEnable(userpet_reset); |
969 | UserPet_CreateThread(); |
970 | } else { |
971 | TvMisc_SetUserCounter(0); |
972 | TvMisc_SetUserPetResetEnable(0); |
973 | } |
974 | } |
975 | |
976 | void TvMisc_DisableWDT(unsigned int userpet_enable) |
977 | { |
978 | if (userpet_enable) { |
979 | user_pet_terminal = 0; |
980 | UserPet_KillThread(); |
981 | } |
982 | } |
983 | |
984 | static int get_hardware_info(char *hardware, unsigned int *revision) |
985 | { |
986 | char data[1024]; |
987 | int fd, n; |
988 | char *x, *hw, *rev; |
989 | |
990 | fd = open("/proc/cpuinfo", O_RDONLY); |
991 | if (fd < 0) { |
992 | return -1; |
993 | } |
994 | |
995 | n = read(fd, data, 1023); |
996 | close(fd); |
997 | if (n < 0) { |
998 | return -1; |
999 | } |
1000 | |
1001 | data[n] = 0; |
1002 | |
1003 | if (hardware != NULL) { |
1004 | hw = strstr(data, "\nHardware"); |
1005 | |
1006 | if (hw) { |
1007 | x = strstr(hw, ": "); |
1008 | if (x) { |
1009 | x += 2; |
1010 | n = 0; |
1011 | while (*x && *x != '\n' && !isspace(*x)) { |
1012 | hardware[n++] = tolower(*x); |
1013 | x++; |
1014 | if (n == 31) { |
1015 | break; |
1016 | } |
1017 | } |
1018 | |
1019 | hardware[n] = 0; |
1020 | } |
1021 | } |
1022 | } |
1023 | |
1024 | if (revision != NULL) { |
1025 | rev = strstr(data, "\nRevision"); |
1026 | |
1027 | if (rev) { |
1028 | x = strstr(rev, ": "); |
1029 | if (x) { |
1030 | *revision = strtoul(x + 2, 0, 16); |
1031 | } |
1032 | } |
1033 | } |
1034 | |
1035 | return 0; |
1036 | } |
1037 | |
1038 | int get_hardware_name(char *hardware) |
1039 | { |
1040 | int tmp_ret = 0; |
1041 | |
1042 | if (hardware == NULL) { |
1043 | return -1; |
1044 | } |
1045 | |
1046 | tmp_ret = get_hardware_info(hardware, NULL); |
1047 | if (tmp_ret < 0) { |
1048 | hardware[0] = '\0'; |
1049 | } |
1050 | |
1051 | return 0; |
1052 | } |
1053 | |
1054 | /*---------------delete dir---------------*/ |
1055 | int TvMisc_DeleteDirFiles(const char *strPath, int flag) |
1056 | { |
1057 | int status; |
1058 | char tmp[256]; |
1059 | switch (flag) { |
1060 | case 0: |
1061 | sprintf(tmp, "rm -f %s", strPath); |
1062 | LOGE("%s", tmp); |
1063 | system(tmp); |
1064 | break; |
1065 | case 1: |
1066 | sprintf(tmp, "cd %s", strPath); |
1067 | LOGE("%s", tmp); |
1068 | status = system(tmp); |
1069 | if (status > 0 || status < 0) |
1070 | return -1; |
1071 | sprintf(tmp, "cd %s;rm -rf *", strPath); |
1072 | system(tmp); |
1073 | LOGE("%s", tmp); |
1074 | break; |
1075 | case 2: |
1076 | sprintf(tmp, "rm -rf %s", strPath); |
1077 | LOGE("%s", tmp); |
1078 | system(tmp); |
1079 | break; |
1080 | } |
1081 | return 0; |
1082 | } |
1083 | /*---------------delete dir end-----------*/ |
1084 | |
1085 | #ifndef NELEM |
1086 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) |
1087 | #endif |
1088 | |
1089 | |
1090 | int Tv_Utils_CheckFs(void) |
1091 | { |
1092 | FILE *f; |
1093 | char mount_dev[256]; |
1094 | char mount_dir[256]; |
1095 | char mount_type[256]; |
1096 | char mount_opts[256]; |
1097 | int mount_freq; |
1098 | int mount_passno; |
1099 | int match; |
1100 | int found_ro_fs = 0; |
1101 | int data_status = 0; |
1102 | int cache_status = 0; |
1103 | int atv_status = 0; |
1104 | int dtv_status = 0; |
1105 | int param_status = 0; |
1106 | int cool_reboot = 0; |
1107 | int recovery_reboot = 0; |
1108 | |
1109 | f = fopen("/proc/mounts", "r"); |
1110 | if (! f) { |
1111 | /* If we can't read /proc/mounts, just give up */ |
1112 | return 1; |
1113 | } |
1114 | |
1115 | do { |
1116 | match = fscanf(f, "%255s %255s %255s %255s %d %d\n", |
1117 | mount_dev, mount_dir, mount_type, |
1118 | mount_opts, &mount_freq, &mount_passno); |
1119 | mount_dev[255] = 0; |
1120 | mount_dir[255] = 0; |
1121 | mount_type[255] = 0; |
1122 | mount_opts[255] = 0; |
1123 | if ((match == 6) && (!strncmp(mount_dev, "/dev/block", 10))) { |
1124 | LOGD("%s, %s %s %s %s %d %d!", "TV", mount_dev, mount_dir, mount_type, mount_opts, mount_freq, mount_passno); |
1125 | if (!strncmp(mount_dir, "/param", 6)) { |
1126 | param_status |= 0x01; |
1127 | } else if (!strncmp(mount_dir, "/atv", 4)) { |
1128 | atv_status |= 0x01; |
1129 | } else if (!strncmp(mount_dir, "/dtv", 4)) { |
1130 | dtv_status |= 0x01; |
1131 | } else if (!strncmp(mount_dir, "/data", 5)) { |
1132 | data_status |= 0x01; |
1133 | } else if (!strncmp(mount_dir, "/cache", 6)) { |
1134 | cache_status |= 0x01; |
1135 | } |
1136 | if (strstr(mount_opts, "ro")) { |
1137 | found_ro_fs += 1; |
1138 | if (!strncmp(mount_dir, "/param", 6)) { |
1139 | param_status |= 0x02; |
1140 | } else if (!strncmp(mount_dir, "/atv", 4)) { |
1141 | atv_status |= 0x02; |
1142 | } else if (!strncmp(mount_dir, "/dtv", 4)) { |
1143 | dtv_status |= 0x02; |
1144 | } else if (!strncmp(mount_dir, "/data", 5)) { |
1145 | data_status |= 0x02; |
1146 | } else if (!strncmp(mount_dir, "/cache", 6)) { |
1147 | cache_status |= 0x02; |
1148 | } |
1149 | } |
1150 | } |
1151 | } while (match != EOF); |
1152 | |
1153 | fclose(f); |
1154 | |
1155 | switch (param_status) { |
1156 | case 0x03: |
1157 | LOGW("%s, param partition is read-only!", "TV"); |
1158 | break; |
1159 | case 0x00: |
1160 | LOGW("%s, param partition can not be mounted!", "TV"); |
1161 | break; |
1162 | default: |
1163 | break; |
1164 | } |
1165 | switch (atv_status) { |
1166 | case 0x03: |
1167 | LOGW("%s, atv partition is read-only!", "TV"); |
1168 | cool_reboot = 1; |
1169 | //android_reboot(ANDROID_RB_RESTART2, 0, "cool_reboot"); |
1170 | break; |
1171 | case 0x00: |
1172 | LOGW("%s, atv partition can not be mounted!", "TV"); |
1173 | recovery_reboot = 1; |
1174 | //android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); |
1175 | default: |
1176 | break; |
1177 | } |
1178 | switch (dtv_status) { |
1179 | case 0x03: |
1180 | LOGW("%s, dtv partition is read-only!", "TV"); |
1181 | //android_reboot(ANDROID_RB_RESTART2, 0, "cool_reboot"); |
1182 | break; |
1183 | case 0x00: |
1184 | LOGW("%s, dtv partition can not be mounted!", "TV"); |
1185 | //android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); |
1186 | default: |
1187 | break; |
1188 | } |
1189 | switch (data_status) { |
1190 | case 0x03: |
1191 | LOGW("%s, data partition is read-only!", "TV"); |
1192 | cool_reboot = 1; |
1193 | //android_reboot(ANDROID_RB_RESTART2, 0, "cool_reboot"); |
1194 | break; |
1195 | case 0x00: |
1196 | LOGW("%s, data partition can not be mounted!", "TV"); |
1197 | recovery_reboot = 1; |
1198 | //android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); |
1199 | break; |
1200 | default: |
1201 | break; |
1202 | } |
1203 | switch (cache_status) { |
1204 | case 0x03: |
1205 | LOGW("%s, cache partition is read-only!", "TV"); |
1206 | cool_reboot = 1; |
1207 | //android_reboot(ANDROID_RB_RESTART2, 0, "cool_reboot"); |
1208 | break; |
1209 | case 0x00: |
1210 | LOGW("%s, cache partition can not be mounted!", "TV"); |
1211 | recovery_reboot = 1; |
1212 | //android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); |
1213 | break; |
1214 | default: |
1215 | break; |
1216 | } |
1217 | if (cool_reboot == 1) { |
1218 | android_reboot(ANDROID_RB_RESTART2, 0, "cool_reboot"); |
1219 | } |
1220 | if (recovery_reboot == 1) { |
1221 | android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); |
1222 | } |
1223 | return found_ro_fs; |
1224 | } |
1225 | |
1226 | |
1227 | int Tv_Utils_SetFileAttrStr(const char *file_path, char val_str_buf[]) |
1228 | { |
1229 | FILE *tmpfp = NULL; |
1230 | |
1231 | tmpfp = fopen(file_path, "w"); |
1232 | if (tmpfp == NULL) { |
1233 | LOGE("%s, write open file %s error(%s)!!!\n", "TV", file_path, strerror(errno)); |
1234 | return -1; |
1235 | } |
1236 | |
1237 | fputs(val_str_buf, tmpfp); |
1238 | |
1239 | fclose(tmpfp); |
1240 | tmpfp = NULL; |
1241 | |
1242 | return 0; |
1243 | } |
1244 | |
1245 | int Tv_Utils_GetFileAttrStr(const char *file_path, int buf_size, char val_str_buf[]) |
1246 | { |
1247 | FILE *tmpfp = NULL; |
1248 | |
1249 | tmpfp = fopen(file_path, "r"); |
1250 | if (tmpfp == NULL) { |
1251 | LOGE("%s, read open file %s error(%s)!!!\n", "TV", file_path, strerror(errno)); |
1252 | val_str_buf[0] = '\0'; |
1253 | return -1; |
1254 | } |
1255 | |
1256 | fgets(val_str_buf, buf_size, tmpfp); |
1257 | |
1258 | fclose(tmpfp); |
1259 | tmpfp = NULL; |
1260 | |
1261 | return 0; |
1262 | } |
1263 | |
1264 | |
1265 | int Tv_Utils_IsFileExist(const char *file_name) |
1266 | { |
1267 | struct stat tmp_st; |
1268 | |
1269 | return stat(file_name, &tmp_st); |
1270 | } |
1271 | |
1272 | #define CC_EDID_SIZE (256) |
1273 | #define CS_VGA_EDID_BUF_DATA_CFG_NAME "ssm.vga.edidbuf.data" |
1274 | /* |
1275 | static unsigned char customer_edid_buf[CC_EDID_SIZE + 4]; |
1276 | |
1277 | static unsigned char mDefHDMIEdidBuf[CC_EDID_SIZE] = { |
1278 | //256 bytes |
1279 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4d, 0x79, 0x02, 0x2c, 0x01, 0x01, 0x01, 0x01, //0x00~0x0F |
1280 | 0x01, 0x15, 0x01, 0x03, 0x80, 0x85, 0x4b, 0x78, 0x0a, 0x0d, 0xc9, 0xa0, 0x57, 0x47, 0x98, 0x27, //0x10~0x1F |
1281 | 0x12, 0x48, 0x4c, 0x21, 0x08, 0x00, 0x81, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, //0x20~0x2F |
1282 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c, //0x30~0x3F |
1283 | 0x45, 0x00, 0x30, 0xeb, 0x52, 0x00, 0x00, 0x1e, 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, //0x40~0x4F |
1284 | 0x6e, 0x28, 0x55, 0x00, 0x30, 0xeb, 0x52, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, //0x50~0x5F |
1285 | 0x6b, 0x79, 0x77, 0x6f, 0x72, 0x74, 0x68, 0x20, 0x54, 0x56, 0x0a, 0x20, 0x00, 0x00, 0x00, 0xfd, //0x60~0x6F |
1286 | 0x00, 0x30, 0x3e, 0x0e, 0x46, 0x0f, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x3e, //0x70~0x7F |
1287 | 0x02, 0x03, 0x38, 0xf0, 0x53, 0x1f, 0x10, 0x14, 0x05, 0x13, 0x04, 0x20, 0x22, 0x3c, 0x3e, 0x12, //0x80~0x8F |
1288 | 0x16, 0x03, 0x07, 0x11, 0x15, 0x02, 0x06, 0x01, 0x23, 0x09, 0x07, 0x01, 0x83, 0x01, 0x00, 0x00, //0x90~0x9F |
1289 | 0x78, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x88, 0x3c, 0x2f, 0xd0, 0x8a, 0x01, 0x02, 0x03, 0x04, 0x01, //0xA0~0xAF |
1290 | 0x40, 0x00, 0x7f, 0x20, 0x30, 0x70, 0x80, 0x90, 0x76, 0xe2, 0x00, 0xfb, 0x02, 0x3a, 0x80, 0xd0, //0xB0~0xBF |
1291 | 0x72, 0x38, 0x2d, 0x40, 0x10, 0x2c, 0x45, 0x80, 0x30, 0xeb, 0x52, 0x00, 0x00, 0x1e, 0x01, 0x1d, //0xC0~0xCF |
1292 | 0x00, 0xbc, 0x52, 0xd0, 0x1e, 0x20, 0xb8, 0x28, 0x55, 0x40, 0x30, 0xeb, 0x52, 0x00, 0x00, 0x1e, //0xD0~0xDF |
1293 | 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80, 0x30, 0xeb, 0x52, 0x00, //0xE0~0xEF |
1294 | 0x00, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, //0xF0~0xFF |
1295 | }; |
1296 | */ |
1297 | static unsigned char mVGAEdidDataBuf[CC_EDID_SIZE]; |
1298 | void monitor_info_set_date ( unsigned char *edidbuf ) |
1299 | { |
1300 | char prop_value[PROPERTY_VALUE_MAX]; |
1301 | char tmp[4]; |
1302 | struct tm *p; |
1303 | int week = 0; |
1304 | |
1305 | memset ( prop_value, '\0', PROPERTY_VALUE_MAX ); |
1306 | |
1307 | property_get ( "ro.build.date.utc", prop_value, "VERSION_ERROR" ); |
1308 | |
1309 | time_t timep = atoi ( prop_value ); |
1310 | |
1311 | p = localtime ( &timep ); |
1312 | |
1313 | mktime ( p ); |
1314 | |
1315 | strftime ( prop_value, PROPERTY_VALUE_MAX, "%W.", p ); |
1316 | |
1317 | week = atoi ( prop_value ); |
1318 | |
1319 | edidbuf[16] = week; |
1320 | edidbuf[17] = ( 1900 + p->tm_year ) - 1990; |
1321 | |
1322 | LOGD ( "###############%s##############", "TV" ); |
1323 | LOGD ( "Week number is %d", week ); |
1324 | LOGD ( "%d %02d %02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday ); |
1325 | LOGD ( "###############%s##############", "TV" ); |
1326 | } |
1327 | |
1328 | |
1329 | void monitor_info_set_imagesize ( unsigned char *edidbuf ) |
1330 | { |
1331 | //panel size info for edid: |
1332 | //39' : max_horizontal = 86; max_vertical = 48; |
1333 | //42' : max_horizontal = 93; max_vertical = 52; |
1334 | //47' : max_horizontal = 104; max_vertical = 60; |
1335 | //50' : max_horizontal = 110; max_vertical = 62; |
1336 | //55' : max_horizontal = 121; max_vertical = 71; |
1337 | int max_horizontal = 104; //47' |
1338 | int max_vertical = 60; //47' |
1339 | |
1340 | edidbuf[21] = max_horizontal; |
1341 | edidbuf[22] = max_vertical; |
1342 | |
1343 | LOGD ( "imagesize max_horizontal %d max_vertical %d", max_horizontal, max_vertical ); |
1344 | } |
1345 | |
1346 | |
1347 | |
1348 | void monitor_info_name_init ( unsigned char *edidbuf ) |
1349 | { |
1350 | int i = 0; |
1351 | |
1352 | for ( i = 90; i < 108; i++ ) { |
1353 | edidbuf[i] = 0; |
1354 | } |
1355 | |
1356 | edidbuf[93] = 252; |
1357 | } |
1358 | |
1359 | void monitor_info_set_name ( unsigned char *edidbuf ) |
1360 | { |
1361 | int i = 0; |
1362 | int config_value_len; |
1363 | const char *config_value; |
1364 | unsigned char str_manufacturer_name[14]; |
1365 | config_value = config_get_str ( "TV", "tvin.hdmiedid.name", "null" ); |
1366 | |
1367 | if ( strcmp ( config_value, "null" ) != 0 ) { |
1368 | config_value_len = strlen ( config_value ); |
1369 | |
1370 | if ( config_value_len < 13 ) { |
1371 | for ( i = 0; i < config_value_len; ++i ) { |
1372 | str_manufacturer_name[i] = config_value[i]; |
1373 | } |
1374 | |
1375 | for ( i = config_value_len; i < 13; ++i ) { |
1376 | str_manufacturer_name[i] = ' '; |
1377 | } |
1378 | } else { |
1379 | for ( i = 0; i < 13; ++i ) { |
1380 | str_manufacturer_name[i] = config_value[i]; |
1381 | } |
1382 | } |
1383 | |
1384 | } |
1385 | |
1386 | for ( i = 0; i < 13; i++ ) { |
1387 | edidbuf[95 + i] = str_manufacturer_name[i]; |
1388 | } |
1389 | } |
1390 | |
1391 | void monitor_info_edid_checksum ( unsigned char *edidbuf ) |
1392 | { |
1393 | int sum = 0, i = 0; |
1394 | |
1395 | for ( i = 0; i < 127; i++ ) { |
1396 | sum += edidbuf[i]; |
1397 | } |
1398 | |
1399 | sum = ( 256 - ( sum % 256 ) ) % 256; |
1400 | edidbuf[127] = sum; |
1401 | |
1402 | LOGD ( "checksum is 0x%x,so testBuf[127] = 0x%x", sum, edidbuf[127] ); |
1403 | } |
1404 | |
1405 | int reboot_sys_by_fbc_edid_info() |
1406 | { |
1407 | int ret = -1; |
1408 | int fd = -1; |
1409 | int edid_info_len = 256; |
1410 | unsigned char fbc_edid_info[edid_info_len]; |
1411 | int env_different_as_cur = 0; |
1412 | char outputmode_prop_value[256]; |
1413 | char lcd_reverse_prop_value[256]; |
1414 | |
1415 | LOGD("get edid info from fbc!"); |
1416 | memset(outputmode_prop_value, '\0', 256); |
1417 | memset(lcd_reverse_prop_value, '\0', 256); |
1418 | property_get("ubootenv.var.outputmode", outputmode_prop_value, "null" ); |
1419 | property_get("ubootenv.var.lcd_reverse", lcd_reverse_prop_value, "null" ); |
1420 | |
1421 | fd = open("/sys/class/amhdmitx/amhdmitx0/edid_info", O_RDWR); |
1422 | if(fd < 0) { |
1423 | LOGW("open edid node error\n"); |
1424 | return -1; |
1425 | } |
1426 | ret = read(fd, fbc_edid_info, edid_info_len); |
1427 | if(ret < 0) { |
1428 | LOGW("read edid node error\n"); |
1429 | return -1; |
1430 | } |
1431 | |
1432 | if((0xfb == fbc_edid_info[250]) && (0x0c == fbc_edid_info[251])) { |
1433 | LOGD("RX is FBC!"); |
1434 | // set outputmode env |
1435 | ret = 0;//is Fbc |
1436 | switch(fbc_edid_info[252] & 0x0f) { |
1437 | case 0x0: |
1438 | if(0 != strcmp(outputmode_prop_value, "1080p")) { |
1439 | if(0 == env_different_as_cur) { |
1440 | env_different_as_cur = 1; |
1441 | } |
1442 | property_set("ubootenv.var.outputmode", "1080p"); |
1443 | } |
1444 | break; |
1445 | case 0x1: |
1446 | if(0 != strcmp(outputmode_prop_value, "4k2k60hz420")) { |
1447 | if(0 == env_different_as_cur) { |
1448 | env_different_as_cur = 1; |
1449 | } |
1450 | property_set("ubootenv.var.outputmode", "4k2k60hz420"); |
1451 | } |
1452 | break; |
1453 | case 0x2: |
1454 | if(0 != strcmp(outputmode_prop_value, "1366*768")) { |
1455 | if(0 == env_different_as_cur) { |
1456 | env_different_as_cur = 1; |
1457 | } |
1458 | property_set("ubootenv.var.outputmode", "1366*768"); |
1459 | } |
1460 | break; |
1461 | default: |
1462 | break; |
1463 | } |
1464 | |
1465 | // set RX 3D Info |
1466 | //switch((fbc_edid_info[252]>>4)&0x0f) |
1467 | |
1468 | // set lcd_reverse env |
1469 | switch(fbc_edid_info[253]) { |
1470 | case 0x0: |
1471 | if(0 != strcmp(lcd_reverse_prop_value, "0")) { |
1472 | if(0 == env_different_as_cur) { |
1473 | env_different_as_cur = 1; |
1474 | } |
1475 | property_set("ubootenv.var.lcd_reverse", "0"); |
1476 | } |
1477 | break; |
1478 | case 0x1: |
1479 | if(0 != strcmp(lcd_reverse_prop_value, "1")) { |
1480 | if(0 == env_different_as_cur) { |
1481 | env_different_as_cur = 1; |
1482 | } |
1483 | property_set("ubootenv.var.lcd_reverse", "1"); |
1484 | } |
1485 | break; |
1486 | default: |
1487 | break; |
1488 | } |
1489 | } |
1490 | close(fd); |
1491 | fd = -1; |
1492 | //ret = -1; |
1493 | if(1 == env_different_as_cur) { |
1494 | LOGW("env change , reboot system\n"); |
1495 | system("reboot"); |
1496 | } |
1497 | return ret; |
1498 | } |
1499 | |
1500 | int reboot_sys_by_fbc_uart_panel_info() |
1501 | { |
1502 | int ret = -1; |
1503 | char outputmode_prop_value[256]; |
1504 | char lcd_reverse_prop_value[256]; |
1505 | CFbcCommunication *fbc = GetSingletonFBC(); |
1506 | int env_different_as_cur = 0; |
1507 | int panel_reverse = -1; |
1508 | int panel_outputmode = -1; |
1509 | |
1510 | |
1511 | char panel_model[64] = {0}; |
1512 | |
1513 | if (fbc == NULL) { |
1514 | LOGE("there is no fbc!!!\n"); |
1515 | return -1; |
1516 | } |
1517 | |
1518 | fbc->cfbc_Get_FBC_Get_PANel_INFO(COMM_DEV_SERIAL, panel_model); |
1519 | if(0 == panel_model[0]) { |
1520 | LOGD("device is not fbc\n"); |
1521 | return -1; |
1522 | } |
1523 | LOGD("device is fbc, get panel info from fbc!\n"); |
1524 | memset(outputmode_prop_value, '\0', 256); |
1525 | memset(lcd_reverse_prop_value, '\0', 256); |
1526 | property_get("ubootenv.var.outputmode", outputmode_prop_value, "null" ); |
1527 | property_get("ubootenv.var.lcd_reverse", lcd_reverse_prop_value, "null" ); |
1528 | |
1529 | fbc->cfbc_Get_FBC_PANEL_REVERSE(COMM_DEV_SERIAL, &panel_reverse); |
1530 | fbc->cfbc_Get_FBC_PANEL_OUTPUT(COMM_DEV_SERIAL, &panel_outputmode); |
1531 | LOGD("panel_reverse = %d, panel_outputmode = %d\n", panel_reverse, panel_outputmode); |
1532 | LOGD("panel_output prop = %s, panel reverse prop = %s\n", outputmode_prop_value, lcd_reverse_prop_value); |
1533 | switch(panel_outputmode) { |
1534 | case 0x0: |
1535 | if(0 != strcmp(outputmode_prop_value, "1080p")) { |
1536 | LOGD("panel_output changed to 1080p\n"); |
1537 | if(0 == env_different_as_cur) { |
1538 | env_different_as_cur = 1; |
1539 | } |
1540 | property_set("ubootenv.var.outputmode", "1080p"); |
1541 | } |
1542 | break; |
1543 | case 0x1: |
1544 | if(0 != strcmp(outputmode_prop_value, "4k2k60hz420")) { |
1545 | if(0 == env_different_as_cur) { |
1546 | env_different_as_cur = 1; |
1547 | } |
1548 | property_set("ubootenv.var.outputmode", "4k2k60hz420"); |
1549 | } |
1550 | break; |
1551 | case 0x2: |
1552 | if(0 != strcmp(outputmode_prop_value, "1366*768")) { |
1553 | if(0 == env_different_as_cur) { |
1554 | env_different_as_cur = 1; |
1555 | } |
1556 | property_set("ubootenv.var.outputmode", "1366*768"); |
1557 | } |
1558 | break; |
1559 | default: |
1560 | break; |
1561 | } |
1562 | |
1563 | // set RX 3D Info |
1564 | //switch((fbc_edid_info[252]>>4)&0x0f) |
1565 | |
1566 | // set lcd_reverse env |
1567 | switch(panel_reverse) { |
1568 | case 0x0: |
1569 | if(0 != strcmp(lcd_reverse_prop_value, "0")) { |
1570 | LOGD("panel_reverse changed to 0\n"); |
1571 | if(0 == env_different_as_cur) { |
1572 | env_different_as_cur = 1; |
1573 | } |
1574 | property_set("ubootenv.var.lcd_reverse", "0"); |
1575 | } |
1576 | break; |
1577 | case 0x1: |
1578 | if(0 != strcmp(lcd_reverse_prop_value, "1")) { |
1579 | if(0 == env_different_as_cur) { |
1580 | env_different_as_cur = 1; |
1581 | } |
1582 | property_set("ubootenv.var.lcd_reverse", "1"); |
1583 | } |
1584 | break; |
1585 | default: |
1586 | break; |
1587 | } |
1588 | |
1589 | ret = -1; |
1590 | if(1 == env_different_as_cur) { |
1591 | LOGW("env change , reboot system\n"); |
1592 | system("reboot"); |
1593 | } |
1594 | return 0; |
1595 | } |
1596 | |
1597 | static pid_t pidof(const char *name) |
1598 | { |
1599 | DIR *dir; |
1600 | struct dirent *ent; |
1601 | char *endptr; |
1602 | char tmp_buf[512]; |
1603 | |
1604 | if (!(dir = opendir("/proc"))) { |
1605 | LOGE("%s, can't open /proc", __FUNCTION__, strerror(errno)); |
1606 | return -1; |
1607 | } |
1608 | |
1609 | while ((ent = readdir(dir)) != NULL) { |
1610 | /* if endptr is not a null character, the directory is not |
1611 | * entirely numeric, so ignore it */ |
1612 | long lpid = strtol(ent->d_name, &endptr, 10); |
1613 | if (*endptr != '\0') { |
1614 | continue; |
1615 | } |
1616 | |
1617 | /* try to open the cmdline file */ |
1618 | snprintf(tmp_buf, sizeof(tmp_buf), "/proc/%ld/cmdline", lpid); |
1619 | FILE *fp = fopen(tmp_buf, "r"); |
1620 | |
1621 | if (fp) { |
1622 | if (fgets(tmp_buf, sizeof(tmp_buf), fp) != NULL) { |
1623 | /* check the first token in the file, the program name */ |
1624 | char *first = strtok(tmp_buf, " "); |
1625 | if (!strcmp(first, name)) { |
1626 | fclose(fp); |
1627 | closedir(dir); |
1628 | return (pid_t) lpid; |
1629 | } |
1630 | } |
1631 | fclose(fp); |
1632 | } |
1633 | } |
1634 | |
1635 | closedir(dir); |
1636 | return -1; |
1637 | } |
1638 | |
1639 | int GetPlatformHaveFBCFlag() |
1640 | { |
1641 | const char *config_value; |
1642 | |
1643 | config_value = config_get_str("TV", "platform.havefbc", "true"); |
1644 | if (strcmp(config_value, "true") == 0) { |
1645 | return 1; |
1646 | } |
1647 | |
1648 | return 0; |
1649 | } |
1650 | |
1651 | int GetPlatformHaveDDFlag() |
1652 | { |
1653 | const char *config_value; |
1654 | |
1655 | config_value = config_get_str("TV", "platform.havedd", "null"); |
1656 | if (strcmp(config_value, "true") == 0 || strcmp(config_value, "1") == 0) { |
1657 | return 1; |
1658 | } |
1659 | |
1660 | return 0; |
1661 | } |
1662 | |
1663 | int GetPlatformProjectInfoSrc() |
1664 | { |
1665 | const char *config_value; |
1666 | |
1667 | config_value = config_get_str("TV", "platform.projectinfo.src", "null"); |
1668 | if (strcmp(config_value, "null") == 0 || strcmp(config_value, "prop") == 0) { |
1669 | return 0; |
1670 | } else if (strcmp(config_value, "emmckey") == 0) { |
1671 | return 1; |
1672 | } else if (strcmp(config_value, "fbc_ver") == 0) { |
1673 | return 2; |
1674 | } |
1675 | |
1676 | return 0; |
1677 | } |
1678 | |
1679 | static unsigned int mCrc32Table[256]; |
1680 | |
1681 | static void initCrc32Table() |
1682 | { |
1683 | int i, j; |
1684 | unsigned int Crc; |
1685 | for (i = 0; i < 256; i++) { |
1686 | Crc = i; |
1687 | for (j = 0; j < 8; j++) { |
1688 | if (Crc & 1) |
1689 | Crc = (Crc >> 1) ^ 0xEDB88320; |
1690 | else |
1691 | Crc >>= 1; |
1692 | } |
1693 | mCrc32Table[i] = Crc; |
1694 | } |
1695 | } |
1696 | |
1697 | unsigned int CalCRC32(unsigned int crc, const unsigned char *ptr, unsigned int buf_len) |
1698 | { |
1699 | static const unsigned int s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, |
1700 | 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c |
1701 | }; |
1702 | unsigned int crcu32 = crc; |
1703 | if(buf_len < 0) |
1704 | return 0; |
1705 | if (!ptr) return 0; |
1706 | crcu32 = ~crcu32; |
1707 | while (buf_len--) { |
1708 | unsigned char b = *ptr++; |
1709 | crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)]; |
1710 | crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)]; |
1711 | } |
1712 | return ~crcu32; |
1713 | } |
1714 | |
1715 | #define CC_HEAD_CHKSUM_LEN (9) |
1716 | #define CC_VERSION_LEN (5) |
1717 | |
1718 | static int check_projectinfo_data_valid(char *data_str, int chksum_head_len, int ver_len) |
1719 | { |
1720 | int tmp_len = 0, tmp_ver = 0; |
1721 | char *endp = NULL; |
1722 | unsigned long src_chksum = 0, cal_chksum = 0; |
1723 | char tmp_buf[129] = { 0 }; |
1724 | |
1725 | if (data_str != NULL) { |
1726 | tmp_len = strlen(data_str); |
1727 | if (tmp_len > chksum_head_len + ver_len) { |
1728 | cal_chksum = CalCRC32(0, (unsigned char *)(data_str + chksum_head_len), tmp_len - chksum_head_len); |
1729 | memcpy(tmp_buf, data_str, chksum_head_len); |
1730 | tmp_buf[chksum_head_len] = 0; |
1731 | src_chksum = strtoul(tmp_buf, &endp, 16); |
1732 | if (cal_chksum == src_chksum) { |
1733 | memcpy(tmp_buf, data_str + chksum_head_len, ver_len); |
1734 | if ((tmp_buf[0] == 'v' || tmp_buf[0] == 'V') && isxdigit(tmp_buf[1]) && isxdigit(tmp_buf[2]) && isxdigit(tmp_buf[3])) { |
1735 | tmp_ver = strtoul(tmp_buf + 1, &endp, 16); |
1736 | if (tmp_ver <= 0) { |
1737 | LOGD("%s, project_info data version error!!!\n", __FUNCTION__); |
1738 | return -1; |
1739 | } |
1740 | } else { |
1741 | LOGD("%s, project_info data version error!!!\n", __FUNCTION__); |
1742 | return -1; |
1743 | } |
1744 | |
1745 | return tmp_ver; |
1746 | } else { |
1747 | LOGD("%s, cal_chksum = %x\n", __FUNCTION__, (unsigned int)cal_chksum); |
1748 | LOGD("%s, src_chksum = %x\n", __FUNCTION__, (unsigned int)src_chksum); |
1749 | } |
1750 | } |
1751 | |
1752 | LOGD("%s, project_info data error!!!\n", __FUNCTION__); |
1753 | return -1; |
1754 | } |
1755 | |
1756 | LOGD("%s, project_info data is NULL!!!\n", __FUNCTION__); |
1757 | return -1; |
1758 | } |
1759 | |
1760 | static int gFBCPrjInfoRDPass = 0; |
1761 | static char gFBCPrjInfoBuf[1024] = {0}; |
1762 | |
1763 | static int GetProjectInfoOriData(char data_str[]) |
1764 | { |
1765 | int tmp_val = 0; |
1766 | int src_type = GetPlatformProjectInfoSrc(); |
1767 | |
1768 | if (src_type == 0) { |
1769 | memset(data_str, '\0', sizeof(data_str)); |
1770 | property_get("ubootenv.var.project_info", data_str, "null"); |
1771 | if (strcmp(data_str, "null") == 0) { |
1772 | LOGE("%s, get project info data error!!!\n", __FUNCTION__); |
1773 | return -1; |
1774 | } |
1775 | |
1776 | return 0; |
1777 | } else if (src_type == 1) { |
1778 | return -1; |
1779 | } else if (src_type == 2) { |
1780 | int i = 0, tmp_len = 0, tmp_val = 0, item_cnt = 0; |
1781 | int tmp_rd_fail_flag = 0; |
1782 | unsigned int cal_chksum = 0; |
1783 | char sw_version[64]; |
1784 | char build_time[64]; |
1785 | char git_version[64]; |
1786 | char git_branch[64]; |
1787 | char build_name[64]; |
1788 | char tmp_buf[512] = {0}; |
1789 | |
1790 | CFbcCommunication *fbcIns = GetSingletonFBC(); |
1791 | if (fbcIns != NULL) { |
1792 | if (gFBCPrjInfoRDPass == 0) { |
1793 | memset((void *)gFBCPrjInfoBuf, 0, sizeof(gFBCPrjInfoBuf)); |
1794 | } |
1795 | |
1796 | if (gFBCPrjInfoRDPass == 1) { |
1797 | strcpy(data_str, gFBCPrjInfoBuf); |
1798 | LOGD("%s, rd once just return, data_str = %s\n", __FUNCTION__, data_str); |
1799 | return 0; |
1800 | } |
1801 | |
1802 | if (fbcIns->cfbc_Get_FBC_MAINCODE_Version(COMM_DEV_SERIAL, sw_version, build_time, git_version, git_branch, build_name) == 0) { |
1803 | if (sw_version[0] == '1' || sw_version[0] == '2') { |
1804 | strcpy(build_name, "2"); |
1805 | |
1806 | strcpy(tmp_buf, "v001,fbc_"); |
1807 | strcat(tmp_buf, build_name); |
1808 | strcat(tmp_buf, ",4k2k60hz420,no_rev,"); |
1809 | strcat(tmp_buf, "HV550QU2-305"); |
1810 | strcat(tmp_buf, ",8o8w,0,0"); |
1811 | cal_chksum = CalCRC32(0, (unsigned char *)tmp_buf, strlen(tmp_buf)); |
1812 | sprintf(data_str, "%08x,%s", cal_chksum, tmp_buf); |
1813 | LOGD("%s, data_str = %s\n", __FUNCTION__, data_str); |
1814 | } else { |
1815 | tmp_val = 0; |
1816 | if (fbcIns->cfbc_Get_FBC_project_id(COMM_DEV_SERIAL, &tmp_val) == 0) { |
1817 | sprintf(build_name, "fbc_%d", tmp_val); |
1818 | } else { |
1819 | tmp_rd_fail_flag = 1; |
1820 | strcpy(build_name, "fbc_0"); |
1821 | LOGD("%s, get project id from fbc error!!!\n", __FUNCTION__); |
1822 | } |
1823 | |
1824 | strcpy(tmp_buf, "v001,"); |
1825 | strcat(tmp_buf, build_name); |
1826 | strcat(tmp_buf, ",4k2k60hz420,no_rev,"); |
1827 | |
1828 | memset(git_branch, 0, sizeof(git_branch)); |
1829 | if (fbcIns->cfbc_Get_FBC_Get_PANel_INFO(COMM_DEV_SERIAL, git_branch) == 0) { |
1830 | strcat(tmp_buf, git_branch); |
1831 | } else { |
1832 | tmp_rd_fail_flag = 1; |
1833 | strcat(tmp_buf, build_name); |
1834 | LOGD("%s, get panel info from fbc error!!!\n", __FUNCTION__); |
1835 | } |
1836 | |
1837 | strcat(tmp_buf, ",8o8w,0,0"); |
1838 | cal_chksum = CalCRC32(0, (unsigned char *)tmp_buf, strlen(tmp_buf)); |
1839 | sprintf(data_str, "%08x,%s", cal_chksum, tmp_buf); |
1840 | LOGD("%s, data_str = %s\n", __FUNCTION__, data_str); |
1841 | |
1842 | if (tmp_rd_fail_flag == 0) { |
1843 | gFBCPrjInfoRDPass = 1; |
1844 | strcpy(gFBCPrjInfoBuf, data_str); |
1845 | } |
1846 | } |
1847 | |
1848 | return 0; |
1849 | } |
1850 | |
1851 | return -1; |
1852 | } |
1853 | } |
1854 | |
1855 | return -1; |
1856 | } |
1857 | |
1858 | int GetProjectInfo(project_info_t *proj_info_ptr) |
1859 | { |
1860 | int i = 0, tmp_ret = 0, tmp_val = 0, tmp_len = 0; |
1861 | int item_cnt = 0, handle_prj_info_data_flag = 0; |
1862 | char *token = NULL; |
1863 | const char *strDelimit = ","; |
1864 | char tmp_buf[1024] = { 0 }; |
1865 | char data_str[1024] = { 0 }; |
1866 | |
1867 | if (GetProjectInfoOriData(data_str) < 0) { |
1868 | return -1; |
1869 | } |
1870 | |
1871 | memset((void *)proj_info_ptr->version, 0, CC_PROJECT_INFO_ITEM_MAX_LEN); |
1872 | memset((void *)proj_info_ptr->panel_type, 0, CC_PROJECT_INFO_ITEM_MAX_LEN); |
1873 | memset((void *)proj_info_ptr->panel_outputmode, 0, CC_PROJECT_INFO_ITEM_MAX_LEN); |
1874 | memset((void *)proj_info_ptr->panel_rev, 0, CC_PROJECT_INFO_ITEM_MAX_LEN); |
1875 | memset((void *)proj_info_ptr->panel_name, 0, CC_PROJECT_INFO_ITEM_MAX_LEN); |
1876 | memset((void *)proj_info_ptr->amp_curve_name, 0, CC_PROJECT_INFO_ITEM_MAX_LEN); |
1877 | |
1878 | //check project info data is valid |
1879 | handle_prj_info_data_flag = check_projectinfo_data_valid(data_str, CC_HEAD_CHKSUM_LEN, CC_VERSION_LEN); |
1880 | |
1881 | //handle project info data |
1882 | if (handle_prj_info_data_flag > 0) { |
1883 | item_cnt = 0; |
1884 | memset((void *)tmp_buf, 0, sizeof(tmp_buf)); |
1885 | strncpy(tmp_buf, data_str + CC_HEAD_CHKSUM_LEN, sizeof(tmp_buf) - 1); |
1886 | if (handle_prj_info_data_flag == 1) { |
1887 | token = strtok(tmp_buf, strDelimit); |
1888 | while (token != NULL) { |
1889 | if (item_cnt == 0) { |
1890 | strncpy(proj_info_ptr->version, token, CC_PROJECT_INFO_ITEM_MAX_LEN - 1); |
1891 | } else if (item_cnt == 1) { |
1892 | strncpy(proj_info_ptr->panel_type, token, CC_PROJECT_INFO_ITEM_MAX_LEN - 1); |
1893 | } else if (item_cnt == 2) { |
1894 | strncpy(proj_info_ptr->panel_outputmode, token, CC_PROJECT_INFO_ITEM_MAX_LEN - 1); |
1895 | } else if (item_cnt == 3) { |
1896 | strncpy(proj_info_ptr->panel_rev, token, CC_PROJECT_INFO_ITEM_MAX_LEN - 1); |
1897 | } else if (item_cnt == 4) { |
1898 | strncpy(proj_info_ptr->panel_name, token, CC_PROJECT_INFO_ITEM_MAX_LEN - 1); |
1899 | } else if (item_cnt == 5) { |
1900 | strncpy(proj_info_ptr->amp_curve_name, token, CC_PROJECT_INFO_ITEM_MAX_LEN - 1); |
1901 | } |
1902 | |
1903 | token = strtok(NULL, strDelimit); |
1904 | item_cnt += 1; |
1905 | } |
1906 | } |
1907 | |
1908 | return 0; |
1909 | } |
1910 | |
1911 | return -1; |
1912 | } |