summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tv/CFbcCommunication.cpp (plain)
blob: 48193d777524fe1b0182e50422c278588f8d1f43
1#include <time.h>
2#include "CFbcCommunication.h"
3#include "CTvLog.h"
4#include "../tvconfig/tvconfig.h"
5#include "../tvutils/tvutils.h"
6#define LOG_TAG "FBC"
7
8static CFbcCommunication *gSingletonFBC = NULL;
9CFbcCommunication *GetSingletonFBC()
10{
11 if (GetPlatformHaveFBCFlag() == 1) {
12 if (gSingletonFBC == NULL) {
13 gSingletonFBC = new CFbcCommunication();
14 gSingletonFBC->start();
15 }
16
17 return gSingletonFBC;
18 }
19
20 LOGE("%s, the platform has no fbc!!!\n", __FUNCTION__);
21 return NULL;
22}
23
24CFbcCommunication::CFbcCommunication()
25{
26 initCrc32Table();
27
28 m_event.data.fd = -1;
29 m_event.events = EPOLLIN | EPOLLET;
30
31 mpRevDataBuf = new unsigned char[512];
32
33 mUpgradeFlag = 0;
34 mbDownHaveSend = 0;//false
35 //mFbcMsgQueue.startMsgQueue();
36 mbFbcKeyEnterDown = 0;//false
37 mFbcEnterKeyDownTime = -1;
38}
39
40CFbcCommunication::~CFbcCommunication()
41{
42 m_event.data.fd = mSerialPort.getFd();
43 m_event.events = EPOLLIN | EPOLLET;
44 mEpoll.del(mSerialPort.getFd(), &m_event);
45 closeAll();
46 delete[] mpRevDataBuf;
47}
48
49int CFbcCommunication::start()
50{
51#if 1
52 //int serial_port = config_get_int("TV", "fbc.communication.serial", SERIAL_C);
53 if (mSerialPort.OpenDevice(SERIAL_C) < 0) {
54 } else {
55#if 0
56 LOGD("%s %d be called......\n", __FUNCTION__, __LINE__);
57 mSerialPort.set_opt(115200, 8, 1, 'N', 5000, 1);
58#else
59 LOGD("%s %d be called......\n", __FUNCTION__, __LINE__);
60 mSerialPort.setup_serial();
61#endif
62 }
63
64 if (mEpoll.create() < 0) {
65 return -1;
66 }
67
68 m_event.data.fd = mSerialPort.getFd();
69 m_event.events = EPOLLIN | EPOLLET;
70 mEpoll.add(mSerialPort.getFd(), &m_event);
71#endif
72
73#if 0
74 mHdmiCec.openFile(CEC_PATH);
75 m_event.data.fd = mHdmiCec.getFd();
76 m_event.events = EPOLLIN | EPOLLET;
77 mEpoll.add(mHdmiCec.getFd(), &m_event);
78#endif
79
80 //timeout for long
81 mEpoll.setTimeout(3000);
82
83 this->run();
84 mTvInput.run();
85 return 0;
86}
87
88void CFbcCommunication::testUart()
89{
90 unsigned char write_buf[64], read_buf[64];
91 int idx = 0;
92 memset(write_buf, 0, sizeof(write_buf));
93 memset(read_buf, 0, sizeof(read_buf));
94
95 write_buf[0] = 0x5a;
96 write_buf[1] = 0x5a;
97 write_buf[2] = 0xb;
98 write_buf[3] = 0x0;
99 write_buf[4] = 0x0;
100 write_buf[5] = 0x40;
101 write_buf[6] = 0x0;
102
103 write_buf[7] = 0x2;
104 write_buf[8] = 0x3c;
105 write_buf[9] = 0x75;
106 write_buf[10] = 0x30;
107 //LOGD("to write ..........\n");
108 mSerialPort.writeFile(write_buf, 11);
109 sleep(1);
110 //LOGD("to read........\n");
111 mSerialPort.readFile(read_buf, 12);
112 for (idx = 0; idx < 12; idx++)
113 LOGD("the data is:0x%x\n", read_buf[idx]);
114 LOGD("end....\n");
115}
116
117void CFbcCommunication::showTime(struct timeval *_time)
118{
119 struct timeval curTime;
120
121 if (_time == NULL) {
122 gettimeofday(&curTime, NULL);
123 } else {
124 curTime.tv_sec = _time->tv_sec;
125 curTime.tv_usec = _time->tv_usec;
126 }
127 if (curTime.tv_usec > 100000) {
128 LOGD("[%d.%d]", curTime.tv_sec, curTime.tv_usec);
129 } else if (curTime.tv_usec > 10000) {
130 LOGD("[%d.0%d]", curTime.tv_sec, curTime.tv_usec);
131 } else if (curTime.tv_usec > 1000) {
132 LOGD("[%d.00%d]", curTime.tv_sec, curTime.tv_usec);
133 } else if (curTime.tv_usec > 100) {
134 LOGD("[%d.000%d]", curTime.tv_sec, curTime.tv_usec);
135 } else if (curTime.tv_usec > 10) {
136 LOGD("[%d.0000%d]", curTime.tv_sec, curTime.tv_usec);
137 } else if (curTime.tv_usec > 1) {
138 LOGD("[%d.00000%d]", curTime.tv_sec, curTime.tv_usec);
139 }
140}
141long CFbcCommunication::getTime(void)
142{
143 struct timeval tv;
144 gettimeofday(&tv, NULL);
145 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
146}
147void CFbcCommunication::initCrc32Table()
148{
149 //生成Crc32的查询表
150 int i, j;
151 unsigned int Crc;
152 for (i = 0; i < 256; i++) {
153 Crc = i;
154 for (j = 0; j < 8; j++) {
155 if (Crc & 1)
156 Crc = (Crc >> 1) ^ 0xEDB88320;
157 else
158 Crc >>= 1;
159 }
160 mCrc32Table[i] = Crc;
161 }
162}
163
164void CFbcCommunication::sendAckCmd(bool isOk)
165{
166 int crc32value = 0;
167 unsigned char ackcmd[12];
168 ackcmd[0] = 0x5A;
169 ackcmd[1] = 0x5A;
170 ackcmd[2] = 12;//little endian
171 ackcmd[3] = 0x00;
172 ackcmd[4] = 0x80;//ack flag
173 ackcmd[5] = 0xff;//cmd id
174 if (isOk) {
175 ackcmd[6] = 0xfe;
176 ackcmd[7] = 0x7f;
177 } else {
178 ackcmd[6] = 0x80;
179 ackcmd[7] = 0x01;
180 }
181 //*((unsigned int*) (ackcmd + 8)) = GetCrc32(ackcmd, 8);
182 crc32value = Calcrc32(0, ackcmd, 8);
183 ackcmd[8] = (crc32value >> 0) & 0xFF;
184 ackcmd[9] = (crc32value >> 8) & 0xFF;
185 ackcmd[10] = (crc32value >> 16) & 0xFF;
186 ackcmd[11] = (crc32value >> 24) & 0xFF;
187 LOGD("to send ack and crc is:0x%x\n", crc32value);
188 sendDataOneway(COMM_DEV_SERIAL, ackcmd, 12, 0x00000000);
189}
190
191/* 函数名:GetCrc32
192* 函数原型:unsigned int GetCrc32(char* InStr,unsigned int len)
193* 参数:InStr ---指向需要计算CRC32值的字符? * len ---为InStr的长帿 * 返回值为计算出来的CRC32结果? */
194unsigned int CFbcCommunication::GetCrc32(unsigned char *InStr, unsigned int len)
195{
196 //开始计算CRC32校验便
197 unsigned int Crc = 0xffffffff;
198 for (int i = 0; i < len; i++) {
199 Crc = (Crc >> 8) ^ mCrc32Table[(Crc & 0xFF) ^ InStr[i]];
200 }
201
202 Crc ^= 0xFFFFFFFF;
203 return Crc;
204}
205
206unsigned int CFbcCommunication::Calcrc32(unsigned int crc, const unsigned char *ptr, unsigned int buf_len)
207{
208 static const unsigned int s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
209 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
210 };
211 unsigned int crcu32 = crc;
212 if (buf_len < 0)
213 return 0;
214 if (!ptr) return 0;
215 crcu32 = ~crcu32;
216 while (buf_len--) {
217 unsigned char b = *ptr++;
218 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)];
219 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)];
220 }
221 return ~crcu32;
222}
223
224int CFbcCommunication::sendDataOneway(int devno, unsigned char *pData, int dataLen, int flags)
225{
226 int ret = -1;
227 switch (devno) {
228 case COMM_DEV_CEC: {
229 ret = mHdmiCec.writeFile(pData, dataLen);
230 break;
231 }
232 case COMM_DEV_SERIAL: {
233 ret = mSerialPort.writeFile(pData, dataLen);
234 break;
235 }
236 default:
237 break;
238 }
239 return ret;
240}
241
242int CFbcCommunication::rmFromRequestList()
243{
244 return 0;
245}
246
247int CFbcCommunication::addToRequestList()
248{
249 return 0;
250}
251//timeout ms
252int CFbcCommunication::sendDataAndWaitReply(int devno, int waitForDevno, int waitForCmd, unsigned char *pData, int dataLen, int timeout, unsigned char *pReData, int *reDataLen, int flags)
253{
254 int ret = sendDataOneway(devno, pData, dataLen, flags);
255 if (ret < 0) return ret;
256
257 mReplyList.WaitDevNo = waitForDevno;
258 mReplyList.WaitCmd = waitForCmd;
259 mReplyList.WaitTimeOut = timeout;
260 mReplyList.reDataLen = 0;
261 mReplyList.replyData = mpRevDataBuf;
262 addToRequestList();
263 LOGD("wait dev:%d, cmd:0x%x, timeout:%d", mReplyList.WaitDevNo, mReplyList.WaitCmd, mReplyList.WaitTimeOut);
264
265 mLock.lock();
266 ret = mReplyList.WaitReplyCondition.waitRelative(mLock, timeout);//wait reply
267 LOGD("wait reply return = %d", __FUNCTION__, __LINE__, ret);
268 mLock.unlock();
269
270 //
271 if (mReplyList.reDataLen > 0) { //data have come in
272 *reDataLen = mReplyList.reDataLen;
273 memcpy(pReData, mReplyList.replyData, mReplyList.reDataLen);
274 mReplyList.reDataLen = 0;
275 return *reDataLen;
276 } else {
277 //timeout,not to wait continue
278 mReplyList.WaitDevNo = -1;
279 mReplyList.WaitCmd = 0xff;
280 return -1;//timeout but data not come.
281 }
282 return 0;
283}
284
285int CFbcCommunication::closeAll()
286{
287 mSerialPort.CloseDevice();
288 return 0;
289}
290
291int CFbcCommunication::SetUpgradeFlag(int flag)
292{
293 mUpgradeFlag = flag;
294 return 0;
295}
296
297/*
298** cmd[0] cmd_type; cmd[1] cmd length; cmd[2] para1 cmd[3] para2 ...
299*/
300int CFbcCommunication::handleCmd(COMM_DEV_TYPE_E fromDev, int *pData, int *pRetValue)
301{
302 fbc_command_t cmd_type = VPU_CMD_NULL;
303 int ret_value = 0;
304
305 if ((fromDev != COMM_DEV_SERIAL && fromDev != COMM_DEV_CEC) || pData == NULL || pRetValue == NULL) {
306 //LOGD("para error and returned!");
307 return -1;
308 }
309
310 cmd_type = (fbc_command_t)pData[0];
311 LOGD("the cmd type is:0x%02x\n", cmd_type);
312 switch (cmd_type) {
313 case VPU_CMD_RED_GAIN_DEF:
314 cfbc_Set_Gain_Red(fromDev, pData[2]);
315 break;
316
317 case VPU_CMD_RED_GAIN_DEF|0x80:
318 cfbc_Get_Gain_Red(fromDev, &ret_value);
319 pRetValue[0] = VPU_CMD_RED_GAIN_DEF | 0x80;
320 pRetValue[1] = 3;
321 pRetValue[2] = ret_value;
322 break;
323
324 case VPU_CMD_PATTEN_SEL:
325 cfbc_Set_Test_Pattern(fromDev, pData[2]);
326 break;
327
328 case VPU_CMD_BACKLIGHT_DEF:
329 cfbc_Set_Backlight(fromDev, pData[2]);
330 break;
331
332 case VPU_CMD_PATTEN_SEL|0x80:
333 cfbc_Get_Test_Pattern(fromDev, &ret_value);
334 pRetValue[0] = VPU_CMD_RED_GAIN_DEF | 0x80;
335 pRetValue[1] = 3;
336 pRetValue[2] = ret_value;
337 break;
338
339 default:
340 return -1;
341 }
342
343 return 0;
344}
345
346int CFbcCommunication::uartReadStream(unsigned char *retData, int rd_max_len, int timeout)
347{
348 int readLen = 0, bufIndex = 0, haveRead = 0;
349 clock_t start_tm = clock();
350
351 do {
352 readLen = mSerialPort.readFile(retData + bufIndex, rd_max_len - haveRead);
353 haveRead += readLen;
354 bufIndex += readLen;
355 if (haveRead == rd_max_len) {
356 return haveRead;
357 }
358
359 LOGD("readLen = %d, haveRead = %d\n", readLen, haveRead);
360
361 if (((clock() - start_tm) / (CLOCKS_PER_SEC / 1000)) > timeout) {
362 return haveRead;
363 }
364 } while (true);
365
366 return haveRead;
367}
368
369int CFbcCommunication::uartReadData(unsigned char *retData, int *retLen)
370{
371 unsigned char tempBuf[512];
372 int cmdLen = 0;
373 int bufIndex = 0;
374 int readLen = 0;
375
376 if (retData == NULL) {
377 LOGD("the retData is NULL\n");
378 return 0;
379 }
380
381 //leader codes 2 byte
382 memset(tempBuf, 0, sizeof(tempBuf));
383 do {
384 readLen = mSerialPort.readFile(tempBuf + 0, 1);
385 if (tempBuf[0] == 0x5A) {
386 bufIndex = 1;
387 readLen = mSerialPort.readFile(tempBuf + 1, 1);
388 if (tempBuf[1] == 0x5A) {
389 bufIndex = 2;
390 LOGD("leading code coming...\n");
391 break;
392 } else {
393 continue;
394 }
395 } else {
396 continue;
397 }
398 } while (true);
399
400 //data len 2 byte
401 int needRead = 2, haveRead = 0;
402 do {
403 readLen = mSerialPort.readFile(tempBuf + bufIndex, needRead - haveRead);
404 haveRead += readLen;
405 bufIndex += readLen;
406 if (haveRead == needRead) {
407 break;
408 }
409 } while (true);
410
411 //little endian
412 cmdLen = (tempBuf[3] << 8) + tempBuf[2];
413 //cmd data cmdLen - 2 -2
414 needRead = cmdLen - 4, haveRead = 0;
415 LOGD("cmdLen is:%d\n", cmdLen);
416
417 do {
418 readLen = mSerialPort.readFile(tempBuf + bufIndex, needRead - haveRead);
419 haveRead += readLen;
420 bufIndex += readLen;
421 if (readLen > 0) {
422 LOGD("data readLen is:%d\n", readLen);
423 }
424 if (haveRead == needRead) {
425 break;
426 }
427 } while (true);
428
429 unsigned int crc = 0;
430 if (cmdLen > 4) {
431 crc = Calcrc32(0, tempBuf, cmdLen - 4);//not include crc 4byte
432 }
433 unsigned int bufCrc = tempBuf[cmdLen - 4] |
434 tempBuf[cmdLen - 3] << 8 |
435 tempBuf[cmdLen - 2] << 16 |
436 tempBuf[cmdLen - 1] << 24;
437 int idx = 0;
438
439 if (crc == bufCrc) {
440 memcpy(retData, tempBuf, cmdLen % 512);
441 *retLen = cmdLen;
442 return cmdLen;
443 } else {
444 return -1;
445 }
446}
447
448int CFbcCommunication::processData(COMM_DEV_TYPE_E fromDev, unsigned char *pData, int dataLen)
449{
450 switch (fromDev) {
451 case COMM_DEV_CEC: {
452 if (mReplyList.WaitDevNo == fromDev && mReplyList.WaitCmd == pData[1]) {
453 mReplyList.reDataLen = dataLen;
454 memcpy(mReplyList.replyData, pData, dataLen);
455 mReplyList.WaitReplyCondition.signal();
456 } else if (0) {
457 }
458 break;
459 }
460 case COMM_DEV_SERIAL: {
461 LOGD("to signal wait dataLen:0x%x, cmdId:0x%x\n", dataLen, pData[5]);
462 if (mReplyList.WaitDevNo == fromDev && mReplyList.WaitCmd == pData[5]) {
463 mReplyList.reDataLen = dataLen;
464 memcpy(mReplyList.replyData, pData, dataLen);
465 mReplyList.WaitReplyCondition.signal();
466 } else {
467 unsigned char cmd = pData[5];
468 //just test
469 const char *value;
470 if (!mbSendKeyCode) {
471 value = config_get_str("FBCUART", "fbc_key_event_handle", "null");
472 if ( strcmp ( value, "true" ) == 0 )
473 mbSendKeyCode = true;
474 else mbSendKeyCode = false;
475 }
476#if(0)
477 switch (cmd) {
478 case 0x14:
479 if (mbSendKeyCode ) {
480 if (pData[6] >= 12 && pData[6] <= 16 ) { //left ---enter
481 unsigned char key = pData[6] ;
482 LOGD(" key:0x%x\n", key);
483
484 //16 key 28 DPAD_CENTER
485 //12 key 103 DPAD_UP
486 //13 key 108 DPAD_DOWN
487 //14 key 105 DPAD_LEFT
488 //15 key 106 DPAD_RIGHT
489 int checkKey = 0;
490 if (key == 16)
491 checkKey = 28 ;
492 else if (key == 12)
493 checkKey = 103 ;
494 else if (key == 13)
495 checkKey = 108 ;
496 else if (key == 14)
497 checkKey = 105 ;
498 else if (key == 15)
499 checkKey = 106 ;
500 mTvInput.sendkeyCode(checkKey);
501 }
502 }
503 break;
504
505 default:
506 break;
507 }
508#else
509 static long curTime, lastTime;
510 int tmp;
511 static int st = 0, st_key_up = 0;
512 static int st_key_down = 0;
513 static int st_key_left = 0;
514 static int st_key_right = 0;
515 static int checkKey = 0, last_checkKey = 0;
516
517
518 switch (pData[6]) { //different key
519 case 12: //DPAD_UP
520 st_key_up = pData[5];
521 if (st_key_up == 0x1D) { //CMD_INPUT_DOWN
522 last_checkKey = checkKey;
523 checkKey = 103;
524 mTvInput.sendkeyCode(checkKey);
525 } else if (st_key_up == 0x1E) { //CMD_INPUT_UP
526 //checkKey = 103;
527 //mTvInput.sendkeyCode_Up(checkKey);
528 }
529 break;
530
531 case 13: //DPAD_DOWN
532 st_key_down = pData[5];
533 if (st_key_down == 0x1D) { //CMD_INPUT_DOWN
534 last_checkKey = checkKey;
535 checkKey = 108;
536 mTvInput.sendkeyCode(checkKey);
537 } else if (st_key_down == 0x1E) { //CMD_INPUT_UP
538 //checkKey = 108;
539 //mTvInput.sendkeyCode_Up(checkKey);
540 }
541 break;
542
543 case 14: //DPAD_LEFT
544 st_key_left = pData[5];
545 if (st_key_left == 0x1D) { //CMD_INPUT_DOWN
546 last_checkKey = checkKey;
547 checkKey = 105;
548 mTvInput.sendkeyCode(checkKey);
549 } else if (st_key_left == 0x1E) { //CMD_INPUT_UP
550 //checkKey = 105;
551 //mTvInput.sendkeyCode_Up(checkKey);
552 }
553 break;
554
555 case 15: //DPAD_RIGHT
556 st_key_right = pData[5];
557 if (st_key_right == 0x1D) { //CMD_INPUT_DOWN
558 last_checkKey = checkKey;
559 checkKey = 106;
560 mTvInput.sendkeyCode(checkKey);
561 } else if (st_key_right == 0x1E) { //CMD_INPUT_UP
562 //checkKey = 106;
563 //mTvInput.sendkeyCode_Up(checkKey);
564 }
565 break;
566
567 case 16: //DPAD_ENTER
568 st = pData[5];
569 if (st == 0x1D) { //CMD_INPUT_DOWN
570 last_checkKey = checkKey;
571 checkKey = 28;
572 lastTime = 0;
573 mbFbcKeyEnterDown = 1;//true
574 mFbcEnterKeyDownTime = mTvInput.getNowMs();
575 mTvInput.sendKeyRepeatStart(158, 1200, 1500);//code 4, dis 3, repeatTime 2
576 } else if (st == 0x1E) { //CMD_INPUT_UP
577 checkKey = 28;
578 if (mbFbcKeyEnterDown == 1) {
579 mbFbcKeyEnterDown = 0;//false
580 mTvInput.sendKeyRepeatStop();
581 int disFbcEnterKeyDown = mTvInput.getNowMs() - mFbcEnterKeyDownTime;
582 LOGD("disFbcEnterKeyDown = %d", disFbcEnterKeyDown);
583 if (disFbcEnterKeyDown > 1200) { //long down
584 } else {
585 mTvInput.sendkeyCode(28);
586 }
587 }
588 }
589 break;
590
591 case 20: //7key power
592 st_key_right = pData[5];
593 if (st_key_right == 0x1D) { //CMD_INPUT_DOWN
594 last_checkKey = checkKey;
595 checkKey = 116;
596 //mTvInput.sendIRkeyCode_Down(checkKey);
597 mTvInput.sendIRkeyCode(checkKey);
598 } else if (st_key_right == 0x1E) { //CMD_INPUT_UP
599 checkKey = 116;
600 //mTvInput.sendIRkeyCode_Up(checkKey);
601 }
602 break;
603
604 case 26: //7key source
605 st_key_right = pData[5];
606 if (st_key_right == 0x1D) { //CMD_INPUT_DOWN
607 last_checkKey = checkKey;
608 checkKey = 466;
609 mTvInput.sendIRkeyCode_Down(checkKey);
610 } else if (st_key_right == 0x1E) { //CMD_INPUT_UP
611 checkKey = 466;
612 mTvInput.sendIRkeyCode_Up(checkKey);
613 }
614 break;
615
616 case 27: //7key menu
617 st_key_right = pData[5];
618 if (st_key_right == 0x1D) { //CMD_INPUT_DOWN
619 last_checkKey = checkKey;
620 checkKey = 139;
621 mTvInput.sendkeyCode(checkKey);
622 } else if (st_key_right == 0x1E) { //CMD_INPUT_UP
623 //checkKey = 139;
624 //mTvInput.sendkeyCode_Up(checkKey);
625 }
626 break;
627
628 case 40: //7key vol -
629 st_key_right = pData[5];
630 if (st_key_right == 0x1D) { //CMD_INPUT_DOWN
631 last_checkKey = checkKey;
632 checkKey = 114;
633 mTvInput.sendIRkeyCode_Down(checkKey);
634 } else if (st_key_right == 0x1E) { //CMD_INPUT_UP
635 checkKey = 114;
636 mTvInput.sendIRkeyCode_Up(checkKey);
637 }
638 break;
639
640 case 41: //7key vol +
641 st_key_right = pData[5];
642 if (st_key_right == 0x1D) { //CMD_INPUT_DOWN
643 last_checkKey = checkKey;
644 checkKey = 115;
645 mTvInput.sendIRkeyCode_Down(checkKey);
646 } else if (st_key_right == 0x1E) { //CMD_INPUT_UP
647 checkKey = 115;
648 mTvInput.sendIRkeyCode_Up(checkKey);
649 }
650 break;
651 }
652#endif
653 }
654 break;
655 }
656 default: {
657 break;
658 }
659 }
660 return 0;
661}
662bool CFbcCommunication::threadLoop()
663{
664 unsigned char readFrameBuf[512];
665 while (!exitPending()) { //requietexit() or requietexitWait() not call
666 while (mUpgradeFlag == 1) {
667 usleep(1000 * 1000);
668 }
669
670 int num = mEpoll.wait();
671
672 while (mUpgradeFlag == 1) {
673 usleep(1000 * 1000);
674 }
675
676 for (int i = 0; i < num; ++i) {
677 int fd = (mEpoll)[i].data.fd;
678 /**
679 * EPOLLIN event
680 */
681 if ((mEpoll)[i].events & EPOLLIN) {
682 if (fd == mHdmiCec.getFd()) { //ce-----------------------------c
683 int bufIndex = 0;
684 int needRead = 4;
685 int haveRead = 0;
686 int idx = 0, readLen = 0;
687 do {
688 readLen = mHdmiCec.readFile(readFrameBuf + bufIndex, needRead - haveRead);
689 haveRead += readLen;
690 bufIndex += readLen;
691 //if(haveRead == needRead) break;
692 } while (0);
693
694 if (readLen > 0) {
695 processData(COMM_DEV_CEC, readFrameBuf, readLen);
696 } else {
697 }
698 } else if (fd == mSerialPort.getFd()) {
699 //seria---------------------------l
700 int cmdLen = 0, idx = 0;
701 LOGD("serial data come");
702 memset(readFrameBuf, 0, 512);
703 int ret = uartReadData(readFrameBuf, &cmdLen);
704
705 if (ret == -1) { //data error
706 sendAckCmd(false);
707 } else if (readFrameBuf[4] == 0x80) { //ack
708 LOGD("is ack come");
709 } else { //not ack
710 sendAckCmd(true);
711 processData(COMM_DEV_SERIAL, readFrameBuf, cmdLen);
712 }
713 }
714 }
715
716 /**
717 * EPOLLOUT event
718 */
719 if ((mEpoll)[i].events & EPOLLOUT) {
720
721 }
722 }
723 }
724 //exit
725 //return true, run again, return false,not run.
726 LOGD("thread exited..........\n");
727 return false;
728}
729
730
731
732int CFbcCommunication::Fbc_Set_Value_INT8(COMM_DEV_TYPE_E toDev, int cmd_type, int value)
733{
734 if (mUpgradeFlag == 1) {
735 return 0;
736 }
737 LOGD("%s cmd =0x%x, value=%d", __FUNCTION__, cmd_type, value);
738 if (toDev == COMM_DEV_CEC) {
739 unsigned char cmd[16], rxbuf[16];
740 int rxlen = 0, idx = 0;
741 memset(cmd, 0, 16);
742 memset(rxbuf, 0, 16);
743 cmd[0] = 0x40;
744 cmd[1] = cmd_type;
745 cmd[2] = value;
746 sendDataOneway(COMM_DEV_CEC, cmd, 4, 0);
747 } else if (toDev == COMM_DEV_SERIAL) {
748 int crc32value = 0;
749 unsigned char write_buf[512];
750 unsigned char rxbuf[512];
751 int rxlen = 0, idx = 0;
752
753 //leading code
754 write_buf[0] = 0x5a;
755 write_buf[1] = 0x5a;
756 //package length from begin to end
757 write_buf[2] = 0xb;
758 write_buf[3] = 0x0;
759 //Ack byte
760 write_buf[4] = 0x0;
761 //cmd ID
762 write_buf[5] = cmd_type;
763 //parameter
764 write_buf[6] = value;
765 //crc32 little Endian
766 crc32value = Calcrc32(0, write_buf, 7);
767 write_buf[7] = (crc32value >> 0) & 0xFF;
768 write_buf[8] = (crc32value >> 8) & 0xFF;
769 write_buf[9] = (crc32value >> 16) & 0xFF;
770 write_buf[10] = (crc32value >> 24) & 0xFF;
771 sendDataOneway(COMM_DEV_SERIAL, write_buf, write_buf[2], 0);
772 }
773 return 0;
774}
775int CFbcCommunication::Fbc_Set_Value_INT32(COMM_DEV_TYPE_E toDev, int cmd_type, int value)
776{
777 if (mUpgradeFlag == 1) {
778 return 0;
779 }
780
781 if (toDev == COMM_DEV_SERIAL) {
782 int crc32value = 0;
783 unsigned char write_buf[512];
784 unsigned char rxbuf[512];
785 int rxlen = 0, idx = 0;
786
787 //leading code
788 write_buf[0] = 0x5a;
789 write_buf[1] = 0x5a;
790 //package length from begin to end
791 write_buf[2] = 14;
792 write_buf[3] = 0x0;
793 //Ack byte
794 write_buf[4] = 0x0;
795 //cmd ID
796 write_buf[5] = cmd_type;
797 //parameter
798 write_buf[6] = (value >> 0) & 0xFF;
799 write_buf[7] = (value >> 8) & 0xFF;
800 write_buf[8] = (value >> 16) & 0xFF;
801 write_buf[9] = (value >> 24) & 0xFF;
802 //crc32 little Endian
803 crc32value = Calcrc32(0, write_buf, 10);
804 write_buf[10] = (crc32value >> 0) & 0xFF;
805 write_buf[11] = (crc32value >> 8) & 0xFF;
806 write_buf[12] = (crc32value >> 16) & 0xFF;
807 write_buf[13] = (crc32value >> 24) & 0xFF;
808
809 return sendDataOneway(COMM_DEV_SERIAL, write_buf, write_buf[2], 0);
810 }
811 return -1;
812}
813int CFbcCommunication::Fbc_Get_Value_INT8(COMM_DEV_TYPE_E fromDev, int cmd_type, int *value)
814{
815 if (mUpgradeFlag == 1) {
816 return 0;
817 }
818
819 LOGD("%s cmd =0x%x", __FUNCTION__, cmd_type);
820
821 if (fromDev == COMM_DEV_CEC) {
822 unsigned char cmd[16], rxbuf[16];
823 int rxlen = 0, idx = 0;
824 memset(cmd, 0, 16);
825 memset(rxbuf, 0, 16);
826 cmd[0] = 0x40;
827 cmd[1] = cmd_type;
828 sendDataAndWaitReply(COMM_DEV_CEC, COMM_DEV_CEC, cmd[1], cmd, 4, 0, rxbuf, &rxlen, 0);
829 *value = rxbuf[6];
830 } else if (fromDev == COMM_DEV_SERIAL) {
831 int crc32value = 0, idx = 0, rxlen = 0;
832 unsigned char write_buf[16];
833 unsigned char rxbuf[16];
834 memset(rxbuf, 0, 16);
835
836 //leading code
837 idx = 0;
838 write_buf[idx++] = 0x5a;
839 write_buf[idx++] = 0x5a;
840 //package length from begin to end
841 write_buf[idx++] = 0xa;
842 write_buf[idx++] = 0x0;
843 //Ack byte
844 write_buf[idx++] = 0x0;
845 //cmd ID
846 write_buf[idx++] = cmd_type;
847 //crc32 little Endian
848 crc32value = Calcrc32(0, write_buf, idx);
849 write_buf[idx++] = (crc32value >> 0) & 0xFF;
850 write_buf[idx++] = (crc32value >> 8) & 0xFF;
851 write_buf[idx++] = (crc32value >> 16) & 0xFF;
852 write_buf[idx++] = (crc32value >> 24) & 0xFF;
853
854 sendDataAndWaitReply(COMM_DEV_SERIAL, COMM_DEV_SERIAL, write_buf[5], write_buf, write_buf[2], 2000, rxbuf, &rxlen, 0);
855 *value = rxbuf[6];
856 }
857 return 0;
858}
859
860int CFbcCommunication::Fbc_Set_BatchValue(COMM_DEV_TYPE_E toDev, unsigned char *cmd_buf, int count)
861{
862 if (mUpgradeFlag == 1) {
863 return 0;
864 }
865
866 if ( 512 <= count) {
867 return -1;
868 }
869
870 if (toDev == COMM_DEV_CEC) {
871 unsigned char cmd[512], rxbuf[512];
872 int rxlen = 0, idx = 0;
873 memset(cmd, 0, 512);
874 memset(rxbuf, 0, 512);
875 cmd[0] = 0x40;
876 for (idx = 0; idx < count; idx++) {
877 cmd[idx + 1] = cmd_buf[idx];
878 }
879 sendDataOneway(COMM_DEV_CEC, cmd, count + 1, 0);
880 } else if (toDev == COMM_DEV_SERIAL) {
881 int crc32value = 0;
882 unsigned char write_buf[512];
883 unsigned char rxbuf[512];
884 int rxlen = 0, idx = 0;
885
886 //leading code
887 write_buf[0] = 0x5a;
888 write_buf[1] = 0x5a;
889 //package length from begin to end
890 write_buf[2] = (count + 9) & 0xFF;
891 write_buf[3] = ((count + 9) >> 8) & 0xFF;
892 //Ack byte : 0x80-> ack package;0x00->normal package;
893 write_buf[4] = 0x00;
894
895 for (idx = 0; idx < count; idx++) {
896 write_buf[idx + 5] = cmd_buf[idx];
897 }
898 //crc32 little Endian
899 crc32value = Calcrc32(0, write_buf, count + 5);
900 write_buf[count + 5] = (crc32value >> 0) & 0xFF;
901 write_buf[count + 6] = (crc32value >> 8) & 0xFF;
902 write_buf[count + 7] = (crc32value >> 16) & 0xFF;
903 write_buf[count + 8] = (crc32value >> 24) & 0xFF;
904 sendDataOneway(COMM_DEV_SERIAL, write_buf, count + 9, 0);
905 }
906 return 0;
907}
908
909int CFbcCommunication::Fbc_Get_BatchValue(COMM_DEV_TYPE_E fromDev, unsigned char *cmd_buf, int count)
910{
911 if (mUpgradeFlag == 1) {
912 return 0;
913 }
914
915 if ( 512 <= count) {
916 return -1;
917 }
918 int ret = 0;
919 // TODO: read value
920 if (fromDev == COMM_DEV_CEC) {
921 unsigned char cmd[512], rxbuf[512];
922 int rxlen = 0, idx = 0;
923 memset(cmd, 0, 512);
924 memset(rxbuf, 0, 512);
925 cmd[0] = 0x40;
926 cmd[1] = cmd_buf[0];
927 sendDataAndWaitReply(COMM_DEV_CEC, COMM_DEV_CEC, cmd[1], cmd, count + 1, 0, rxbuf, &rxlen, 0);
928
929 if (rxlen > 2) {
930 for (idx = 0; idx < rxlen; idx++) {
931 cmd_buf[idx] = cmd[idx + 1];
932 }
933 }
934 } else if (fromDev == COMM_DEV_SERIAL) {
935 int crc32value = 0, idx = 0, rxlen = 0;
936 unsigned char write_buf[512];
937 unsigned char rxbuf[512];
938 memset(write_buf, 0, 512);
939 memset(rxbuf, 0, 512);
940
941 //leading code
942 write_buf[0] = 0x5a;
943 write_buf[1] = 0x5a;
944 //package length from begin to end
945 write_buf[2] = (count + 9) & 0xFF;
946 write_buf[3] = ((count + 9) >> 8) & 0xFF;
947 //Ack byte
948 write_buf[4] = 0x00;
949 //cmd ID
950 for (idx = 0; idx < count; idx++) {
951 write_buf[idx + 5] = cmd_buf[idx];
952 }
953 //crc32 little Endian
954 crc32value = Calcrc32(0, write_buf, count + 5);
955 write_buf[count + 5] = (crc32value >> 0) & 0xFF;
956 write_buf[count + 6] = (crc32value >> 8) & 0xFF;
957 write_buf[count + 7] = (crc32value >> 16) & 0xFF;
958 write_buf[count + 8] = (crc32value >> 24) & 0xFF;
959 sendDataAndWaitReply(COMM_DEV_SERIAL, COMM_DEV_SERIAL, write_buf[5], write_buf, write_buf[2], 2000, rxbuf, &rxlen, 0);
960
961 if (rxlen > 9) {
962 for (idx = 0; idx < (rxlen - 9); idx++) {
963 cmd_buf[idx] = rxbuf[idx + 5];
964 }
965 }
966 ret = rxlen;
967 }
968
969 return ret;
970}
971
972int CFbcCommunication::cfbc_Set_Gain_Red(COMM_DEV_TYPE_E fromDev, int value)
973{
974 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_RED_GAIN_DEF, value);
975}
976
977int CFbcCommunication::cfbc_Get_Gain_Red(COMM_DEV_TYPE_E fromDev, int *value)
978{
979 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_RED_GAIN_DEF | 0x80, value);
980}
981
982int CFbcCommunication::cfbc_Set_Gain_Green(COMM_DEV_TYPE_E fromDev, int value)
983{
984 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_GREEN_GAIN_DEF, value);
985}
986
987int CFbcCommunication::cfbc_Get_Gain_Green(COMM_DEV_TYPE_E fromDev, int *value)
988{
989 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_GREEN_GAIN_DEF | 0x80, value);
990}
991
992int CFbcCommunication::cfbc_Set_Gain_Blue(COMM_DEV_TYPE_E fromDev, int value)
993{
994 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_BLUE_GAIN_DEF, value);
995}
996
997int CFbcCommunication::cfbc_Get_Gain_Blue(COMM_DEV_TYPE_E fromDev, int *value)
998{
999 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_BLUE_GAIN_DEF | 0x80, value);
1000}
1001
1002int CFbcCommunication::cfbc_Set_Offset_Red(COMM_DEV_TYPE_E fromDev, int value)
1003{
1004 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_PRE_RED_OFFSET_DEF, value);
1005}
1006
1007int CFbcCommunication::cfbc_Get_Offset_Red(COMM_DEV_TYPE_E fromDev, int *value)
1008{
1009 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_PRE_RED_OFFSET_DEF | 0x80, value);
1010}
1011
1012int CFbcCommunication::cfbc_Set_Offset_Green(COMM_DEV_TYPE_E fromDev, int value)
1013{
1014 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_PRE_GREEN_OFFSET_DEF, value);
1015}
1016
1017int CFbcCommunication::cfbc_Get_Offset_Green(COMM_DEV_TYPE_E fromDev, int *value)
1018{
1019 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_PRE_GREEN_OFFSET_DEF | 0x80, value);
1020}
1021
1022int CFbcCommunication::cfbc_Set_Offset_Blue(COMM_DEV_TYPE_E fromDev, int value)
1023{
1024 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_PRE_BLUE_OFFSET_DEF, value);
1025}
1026
1027int CFbcCommunication::cfbc_Get_Offset_Blue(COMM_DEV_TYPE_E fromDev, int *value)
1028{
1029 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_PRE_BLUE_OFFSET_DEF | 0x80, value);
1030}
1031
1032int CFbcCommunication::cfbc_Set_WB_Initial(COMM_DEV_TYPE_E fromDev, int value)
1033{
1034 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_WB, value);
1035}
1036
1037int CFbcCommunication::cfbc_Get_WB_Initial(COMM_DEV_TYPE_E fromDev, int *value)
1038{
1039 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_WB | 0x80, value);
1040}
1041
1042int CFbcCommunication::cfbc_Set_ColorTemp_Mode(COMM_DEV_TYPE_E fromDev, int value)
1043{
1044 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_COLOR_TEMPERATURE_DEF, value);
1045}
1046
1047int CFbcCommunication::cfbc_Get_ColorTemp_Mode(COMM_DEV_TYPE_E fromDev, int *value)
1048{
1049 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_COLOR_TEMPERATURE_DEF | 0x80, value);
1050}
1051
1052int CFbcCommunication::cfbc_Set_Test_Pattern(COMM_DEV_TYPE_E fromDev, int value)
1053{
1054 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_PATTEN_SEL, value);
1055}
1056
1057int CFbcCommunication::cfbc_Get_Test_Pattern(COMM_DEV_TYPE_E fromDev, int *value)
1058{
1059 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_PATTEN_SEL | 0x80, value);
1060}
1061
1062int CFbcCommunication::cfbc_Set_Picture_Mode(COMM_DEV_TYPE_E fromDev, int value)
1063{
1064 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_PICTURE_MODE, value);
1065}
1066
1067int CFbcCommunication::cfbc_Get_Picture_Mode(COMM_DEV_TYPE_E fromDev, int *value)
1068{
1069 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_PICTURE_MODE | 0x80, value);
1070}
1071
1072int CFbcCommunication::cfbc_Set_Contrast(COMM_DEV_TYPE_E fromDev, int value)
1073{
1074 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_CONTRAST_DEF, value);
1075}
1076
1077int CFbcCommunication::cfbc_Get_Contrast(COMM_DEV_TYPE_E fromDev, int *value)
1078{
1079 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_CONTRAST_DEF | 0x80, value);
1080}
1081
1082int CFbcCommunication::cfbc_Set_Brightness(COMM_DEV_TYPE_E fromDev, int value)
1083{
1084 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_BRIGHTNESS_DEF, value);
1085}
1086
1087int CFbcCommunication::cfbc_Get_Brightness(COMM_DEV_TYPE_E fromDev, int *value)
1088{
1089 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_BRIGHTNESS_DEF | 0x80, value);
1090}
1091
1092int CFbcCommunication::cfbc_Set_Saturation(COMM_DEV_TYPE_E fromDev, int value)
1093{
1094 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_COLOR_DEF, value);
1095}
1096
1097int CFbcCommunication::cfbc_Get_Saturation(COMM_DEV_TYPE_E fromDev, int *value)
1098{
1099 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_COLOR_DEF | 0x80, value);
1100}
1101
1102int CFbcCommunication::cfbc_Set_HueColorTint(COMM_DEV_TYPE_E fromDev, int value)
1103{
1104 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_HUE_DEF, value);
1105}
1106
1107int CFbcCommunication::cfbc_Get_HueColorTint(COMM_DEV_TYPE_E fromDev, int *value)
1108{
1109 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_HUE_DEF | 0x80, value);
1110}
1111
1112int CFbcCommunication::cfbc_Set_Backlight(COMM_DEV_TYPE_E fromDev, int value)
1113{
1114 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_BACKLIGHT_DEF, value);
1115}
1116
1117int CFbcCommunication::cfbc_Get_Backlight(COMM_DEV_TYPE_E fromDev, int *value)
1118{
1119 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_BACKLIGHT_DEF | 0x80, value);
1120}
1121
1122int CFbcCommunication::cfbc_Set_Source(COMM_DEV_TYPE_E fromDev, int value)
1123{
1124 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_SOURCE, value);
1125}
1126
1127int CFbcCommunication::cfbc_Get_Source(COMM_DEV_TYPE_E fromDev, int *value)
1128{
1129 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_SOURCE | 0x80, value);
1130}
1131
1132int CFbcCommunication::cfbc_Set_Mute(COMM_DEV_TYPE_E fromDev, int value)
1133{
1134 LOGD("cfbc_Set_Mute = %d", value);
1135 return Fbc_Set_Value_INT8(fromDev, AUDIO_CMD_SET_MUTE, value);
1136}
1137int CFbcCommunication::cfbc_Set_FBC_Audio_Source(COMM_DEV_TYPE_E fromDev, int value)
1138{
1139 return Fbc_Set_Value_INT8(fromDev, AUDIO_CMD_SET_SOURCE, value);
1140}
1141
1142int CFbcCommunication::cfbc_Get_Mute(COMM_DEV_TYPE_E fromDev, int *value)
1143{
1144 return Fbc_Get_Value_INT8(fromDev, AUDIO_CMD_GET_MUTE, value);
1145}
1146
1147int CFbcCommunication::cfbc_Set_Volume_Bar(COMM_DEV_TYPE_E fromDev, int value)
1148{
1149 return Fbc_Set_Value_INT8(fromDev, AUDIO_CMD_SET_VOLUME_BAR, value);
1150}
1151
1152int CFbcCommunication::cfbc_Get_Volume_Bar(COMM_DEV_TYPE_E fromDev, int *value)
1153{
1154 return Fbc_Get_Value_INT8(fromDev, AUDIO_CMD_GET_VOLUME_BAR, value);
1155}
1156
1157int CFbcCommunication::cfbc_Set_Balance(COMM_DEV_TYPE_E fromDev, int value)
1158{
1159 return Fbc_Set_Value_INT8(fromDev, AUDIO_CMD_SET_BALANCE, value);
1160}
1161
1162int CFbcCommunication::cfbc_Get_Balance(COMM_DEV_TYPE_E fromDev, int *value)
1163{
1164 return Fbc_Get_Value_INT8(fromDev, AUDIO_CMD_GET_BALANCE, value);
1165}
1166
1167int CFbcCommunication::cfbc_Set_Master_Volume(COMM_DEV_TYPE_E fromDev, int value)
1168{
1169 return Fbc_Set_Value_INT8(fromDev, AUDIO_CMD_SET_MASTER_VOLUME, value);
1170}
1171
1172int CFbcCommunication::cfbc_Get_Master_Volume(COMM_DEV_TYPE_E fromDev, int *value)
1173{
1174 return Fbc_Get_Value_INT8(fromDev, AUDIO_CMD_GET_MASTER_VOLUME, value);
1175}
1176
1177int CFbcCommunication::cfbc_Set_CM(COMM_DEV_TYPE_E fromDev, unsigned char value)
1178{
1179 unsigned char cmd[512];
1180 memset(cmd, 0, 512);
1181
1182 cmd[0] = VPU_CMD_ENABLE;
1183 cmd[1] = VPU_MODULE_CM2;
1184 cmd[2] = value;//value:0~1
1185 return Fbc_Set_BatchValue(fromDev, cmd, 3);
1186}
1187
1188int CFbcCommunication::cfbc_Get_CM(COMM_DEV_TYPE_E fromDev, int *value)
1189{
1190 unsigned char cmd[512];
1191 memset(cmd, 0, 512);
1192
1193 cmd[0] = VPU_CMD_ENABLE | 0x80;
1194 cmd[1] = VPU_MODULE_CM2;
1195
1196 Fbc_Get_BatchValue(fromDev, cmd, 2);
1197 *value = cmd[2];
1198
1199 return 0;
1200}
1201int CFbcCommunication::cfbc_Set_DNLP(COMM_DEV_TYPE_E fromDev, unsigned char value)
1202{
1203 unsigned char cmd[512];
1204 memset(cmd, 0, 512);
1205
1206 cmd[0] = VPU_CMD_ENABLE;
1207 cmd[1] = VPU_MODULE_DNLP;
1208 cmd[2] = value;//value:0~1
1209
1210 return Fbc_Set_BatchValue(fromDev, cmd, 3);
1211}
1212
1213int CFbcCommunication::cfbc_Get_DNLP(COMM_DEV_TYPE_E fromDev, int *value)
1214{
1215 unsigned char cmd[512];
1216 memset(cmd, 0, 512);
1217
1218 cmd[0] = VPU_CMD_ENABLE | 0x80;
1219 cmd[1] = VPU_MODULE_DNLP;
1220
1221 Fbc_Get_BatchValue(fromDev, cmd, 2);
1222 *value = cmd[2];
1223
1224 return 0;
1225}
1226
1227int CFbcCommunication::cfbc_Get_FBC_MAINCODE_Version(COMM_DEV_TYPE_E fromDev, char sw_ver[], char build_time[], char git_ver[], char git_branch[], char build_name[])
1228{
1229 int rx_len = 0, tmp_ind = 0;
1230 unsigned char cmd[512];
1231
1232 if (sw_ver == NULL || build_time == NULL || git_ver == NULL || git_branch == NULL || build_name == NULL) {
1233 return -1;
1234 }
1235
1236 memset(cmd, 0, 512);
1237 cmd[0] = CMD_FBC_MAIN_CODE_VERSION;
1238 rx_len = Fbc_Get_BatchValue(fromDev, cmd, 1);
1239
1240 sw_ver[0] = 0;
1241 build_time[0] = 0;
1242 git_ver[0] = 0;
1243 git_branch[0] = 0;
1244 build_name[0] = 0;
1245
1246 if (rx_len <= 0) {
1247 return -1;
1248 }
1249
1250 if (cmd[0] != CMD_FBC_MAIN_CODE_VERSION || cmd[1] != 0x88 || cmd[2] != 0x99) {
1251 return -1;
1252 }
1253
1254 tmp_ind = 3;
1255
1256 strcpy(sw_ver, (char *)(cmd + tmp_ind));
1257 tmp_ind += strlen(sw_ver);
1258 tmp_ind += 1;
1259
1260 strcpy(build_time, (char *)(cmd + tmp_ind));
1261 tmp_ind += strlen(build_time);
1262 tmp_ind += 1;
1263
1264 strcpy(git_ver, (char *)(cmd + tmp_ind));
1265 tmp_ind += strlen(git_ver);
1266 tmp_ind += 1;
1267
1268 strcpy(git_branch, (char *)(cmd + tmp_ind));
1269 tmp_ind += strlen(git_branch);
1270 tmp_ind += 1;
1271
1272 strcpy(build_name, (char *)(cmd + tmp_ind));
1273 tmp_ind += strlen(build_name);
1274 tmp_ind += 1;
1275 LOGD("sw_ver=%s, buildt=%s, gitv=%s, gitb=%s,bn=%s", sw_ver, build_time, git_ver, git_branch, build_name);
1276 return 0;
1277}
1278
1279int CFbcCommunication::cfbc_Set_FBC_Factory_SN(COMM_DEV_TYPE_E fromDev, const char *pSNval)
1280{
1281 unsigned char cmd[512];
1282 int len = strlen(pSNval);
1283
1284 memset(cmd, 0, 512);
1285
1286 cmd[0] = CMD_SET_FACTORY_SN;
1287
1288 memcpy(cmd + 1, pSNval, len);
1289
1290 LOGD("cmd : %s\n", cmd);
1291
1292 return Fbc_Set_BatchValue(fromDev, cmd, len + 1);
1293}
1294
1295int CFbcCommunication::cfbc_Get_FBC_Factory_SN(COMM_DEV_TYPE_E fromDev, char FactorySN[])
1296{
1297 int rx_len = 0;
1298 unsigned char cmd[512];
1299 memset(cmd, 0, 512);
1300 cmd[0] = CMD_GET_FACTORY_SN;
1301 rx_len = Fbc_Get_BatchValue(fromDev, cmd, 1);
1302 if (rx_len <= 0) {
1303 return -1;
1304 }
1305 strncpy(FactorySN, (char *)(cmd + 1), 17);
1306
1307 LOGD("panelModel=%s", FactorySN);
1308 return 0;
1309}
1310
1311int CFbcCommunication::cfbc_Get_FBC_Get_PANel_INFO(COMM_DEV_TYPE_E fromDev, char panel_model[])
1312{
1313 int rx_len = 0;
1314 unsigned char cmd[512];
1315 memset(cmd, 0, 512);
1316 cmd[0] = CMD_DEVICE_ID;
1317 rx_len = Fbc_Get_BatchValue(fromDev, cmd, 1);
1318 if (rx_len <= 0) {
1319 return -1;
1320 }
1321 strcpy(panel_model, (char *)(cmd + 1));
1322
1323 LOGD("panelModel=%s", panel_model);
1324 return 0;
1325}
1326
1327int CFbcCommunication::cfbc_Set_FBC_panel_power_switch(COMM_DEV_TYPE_E fromDev, int switch_val)
1328{
1329 unsigned char cmd[512];
1330
1331 memset(cmd, 0, 512);
1332
1333 cmd[0] = FBC_PANEL_POWER;
1334 cmd[1] = switch_val; //0 is fbc panel power off, 1 is panel power on.
1335
1336 return Fbc_Set_BatchValue(fromDev, cmd, 2);
1337}
1338
1339int CFbcCommunication::cfbc_Set_FBC_suspend(COMM_DEV_TYPE_E fromDev, int switch_val)
1340{
1341 unsigned char cmd[512];
1342
1343 memset(cmd, 0, 512);
1344
1345 cmd[0] = FBC_SUSPEND_POWER;
1346 cmd[1] = switch_val; //0
1347
1348 return Fbc_Set_BatchValue(fromDev, cmd, 2);
1349}
1350int CFbcCommunication::cfbc_Set_FBC_User_Setting_Default(COMM_DEV_TYPE_E fromDev, int param)
1351{
1352 unsigned char cmd[512];
1353
1354 memset(cmd, 0, 512);
1355
1356 cmd[0] = FBC_USER_SETTING_DEFAULT;
1357 cmd[1] = param; //0
1358
1359 return Fbc_Set_BatchValue(fromDev, cmd, 2);
1360}
1361int CFbcCommunication::cfbc_SendRebootToUpgradeCmd(COMM_DEV_TYPE_E fromDev, int value)
1362{
1363 return Fbc_Set_Value_INT32(fromDev, FBC_REBOOT_UPGRADE, value);
1364}
1365int CFbcCommunication::cfbc_FBC_Send_Key_To_Fbc(COMM_DEV_TYPE_E fromDev, int keycode, int param)
1366{
1367 unsigned char cmd[512];
1368
1369 memset(cmd, 0, 512);
1370
1371 cmd[0] = CMD_ACTIVE_KEY;
1372 cmd[1] = keycode; //0
1373
1374 return Fbc_Set_BatchValue(fromDev, cmd, 2);
1375}
1376
1377int CFbcCommunication::cfbc_Get_FBC_PANEL_REVERSE(COMM_DEV_TYPE_E fromDev, int *value)
1378{
1379 unsigned char cmd[512];
1380 memset(cmd, 0, 512);
1381
1382 cmd[0] = CMD_PANEL_INFO;
1383 //0://panel reverse
1384 //1://panel output_mode
1385 //2://panel byte num
1386 cmd[1] = 0;
1387
1388 Fbc_Get_BatchValue(fromDev, cmd, 2);
1389 //cmd[0] cmdid-PANEL-INFO
1390 //cmd[1] param[0] - panel reverse
1391 *value = cmd[2];
1392
1393 return 0;
1394}
1395
1396int CFbcCommunication::cfbc_Get_FBC_PANEL_OUTPUT(COMM_DEV_TYPE_E fromDev, int *value)
1397{
1398 unsigned char cmd[512];
1399 memset(cmd, 0, 512);
1400
1401 cmd[0] = CMD_PANEL_INFO;
1402 //0://panel reverse
1403 //1://panel output_mode
1404 //2://panel byte num
1405 cmd[1] = 1;
1406
1407 Fbc_Get_BatchValue(fromDev, cmd, 2);
1408 //cmd[0] cmdid-PANEL-INFO
1409 //cmd[1] param[0] - panel reverse
1410 *value = cmd[2];
1411
1412 return 0;
1413}
1414
1415int CFbcCommunication::cfbc_Set_FBC_project_id(COMM_DEV_TYPE_E fromDev, int prj_id)
1416{
1417 unsigned char cmd[512];
1418
1419 memset(cmd, 0, 512);
1420
1421 cmd[0] = CMD_SET_PROJECT_SELECT;
1422 cmd[1] = prj_id;
1423
1424 return Fbc_Set_BatchValue(fromDev, cmd, 2);
1425}
1426
1427int CFbcCommunication::cfbc_Get_FBC_project_id(COMM_DEV_TYPE_E fromDev, int *prj_id)
1428{
1429 return Fbc_Get_Value_INT8(fromDev, CMD_GET_PROJECT_SELECT, prj_id);
1430}
1431
1432int CFbcCommunication::cfbc_Set_Gamma(COMM_DEV_TYPE_E fromDev, unsigned char value)
1433{
1434 unsigned char cmd[512];
1435 memset(cmd, 0, 512);
1436
1437 cmd[0] = VPU_CMD_ENABLE;
1438 cmd[1] = VPU_MODULE_GAMMA;
1439 cmd[2] = value;//value:0~1
1440
1441 return Fbc_Set_BatchValue(fromDev, cmd, 3);
1442}
1443
1444int CFbcCommunication::cfbc_Get_Gamma(COMM_DEV_TYPE_E fromDev, int *value)
1445{
1446 unsigned char cmd[512];
1447 memset(cmd, 0, 512);
1448
1449 cmd[0] = VPU_CMD_ENABLE | 0x80;
1450 cmd[1] = VPU_MODULE_GAMMA;
1451
1452 Fbc_Get_BatchValue(fromDev, cmd, 2);
1453 *value = cmd[2];
1454
1455 return 0;
1456}
1457
1458int CFbcCommunication::cfbc_Set_WhiteBalance_OnOff(COMM_DEV_TYPE_E fromDev, unsigned char value)
1459{
1460 unsigned char cmd[512];
1461 memset(cmd, 0, 512);
1462
1463 cmd[0] = VPU_CMD_ENABLE;
1464 cmd[1] = VPU_MODULE_WB;
1465 cmd[2] = value;//value:0~1
1466
1467 return Fbc_Set_BatchValue(fromDev, cmd, 3);
1468}
1469
1470int CFbcCommunication::cfbc_Get_WhiteBalance_OnOff(COMM_DEV_TYPE_E fromDev, int *value)
1471{
1472 unsigned char cmd[512];
1473 memset(cmd, 0, 512);
1474
1475 cmd[0] = VPU_CMD_ENABLE | 0x80;
1476 cmd[1] = VPU_MODULE_WB;
1477
1478 Fbc_Get_BatchValue(fromDev, cmd, 2);
1479 *value = cmd[2];
1480
1481 return 0;
1482}
1483
1484int CFbcCommunication::cfbc_Set_WB_Batch(COMM_DEV_TYPE_E fromDev, unsigned char mode, unsigned char r_gain, unsigned char g_gain, unsigned char b_gain, unsigned char r_offset, unsigned char g_offset, unsigned char b_offset)
1485{
1486 unsigned char cmd[512];
1487 memset(cmd, 0, 512);
1488
1489 cmd[0] = VPU_CMD_WB_VALUE;
1490 cmd[1] = mode;
1491 cmd[2] = r_gain;
1492 cmd[3] = g_gain;
1493 cmd[4] = b_gain;
1494 cmd[5] = r_offset;
1495 cmd[6] = g_offset;
1496 cmd[7] = b_offset;
1497
1498 return Fbc_Set_BatchValue(fromDev, cmd, 8);
1499}
1500
1501int CFbcCommunication::cfbc_WhiteBalance_GrayPattern_OnOff(COMM_DEV_TYPE_E fromDev, int onOff)
1502{
1503 int ret = -1;
1504 unsigned char cmd[512];
1505 memset(cmd, 0, 512);
1506 if (onOff == 0) { //On
1507 LOGD("Call vpp 63 2 1");
1508 cmd[0] = VPU_CMD_SRCIF;
1509 cmd[1] = 2;
1510 cmd[2] = 1;
1511 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);//close csc0
1512 if (ret == 0) {
1513 LOGD("Call vpp 9 9 0");
1514 cmd[0] = VPU_CMD_ENABLE;
1515 cmd[1] = 9;
1516 cmd[2] = 0;
1517 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);//close csc1
1518 if (ret == 0) {
1519 LOGD("Call vpp 9 10 0");
1520 cmd[0] = VPU_CMD_ENABLE;
1521 cmd[1] = 10;
1522 cmd[2] = 0;
1523 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);//close dnlp
1524 if (ret == 0) {
1525 LOGD("Call vpp 9 8 0");
1526 cmd[0] = VPU_CMD_ENABLE;
1527 cmd[1] = 8;
1528 cmd[2] = 0;
1529 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);//close cm
1530 }
1531 }
1532 }
1533
1534 } else { //Off
1535 LOGD("Call vpp 63 2 2");
1536 cmd[0] = VPU_CMD_SRCIF;
1537 cmd[1] = 2;
1538 cmd[2] = 2;
1539 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);
1540 if (ret == 0) {
1541 LOGD("Call vpp 9 9 1");
1542 cmd[0] = VPU_CMD_ENABLE;
1543 cmd[1] = 9;
1544 cmd[2] = 1;
1545 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);//open csc1
1546 if (ret == 0) {
1547 LOGD("Call vpp 9 10 1");
1548 cmd[0] = VPU_CMD_ENABLE;
1549 cmd[1] = 10;
1550 cmd[2] = 1;
1551 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);//open dnlp
1552 if (ret == 0) {
1553 LOGD("Call vpp 9 8 1");
1554 cmd[0] = VPU_CMD_ENABLE;
1555 cmd[1] = 8;
1556 cmd[2] = 1;
1557 ret = Fbc_Set_BatchValue(fromDev, cmd, 3);//open cm
1558 }
1559 }
1560 }
1561 }
1562 return ret;
1563}
1564
1565int CFbcCommunication::cfbc_WhiteBalance_SetGrayPattern(COMM_DEV_TYPE_E fromDev, unsigned char value)
1566{
1567 int ret = -1;
1568 unsigned char cmd[512];
1569 memset(cmd, 0, 512);
1570 cmd[0] = VPU_CMD_GRAY_PATTERN;
1571 cmd[1] = value;
1572 cmd[2] = value;
1573 cmd[3] = value;
1574 ret = Fbc_Set_BatchValue(fromDev, cmd, 4);
1575 return ret;
1576}
1577
1578int CFbcCommunication::cfbc_Get_WB_Batch(COMM_DEV_TYPE_E fromDev, unsigned char mode, unsigned char *r_gain, unsigned char *g_gain, unsigned char *b_gain, unsigned char *r_offset, unsigned char *g_offset, unsigned char *b_offset)
1579{
1580 unsigned char cmd[512];
1581 memset(cmd, 0, 512);
1582
1583 cmd[0] = VPU_CMD_WB_VALUE | 0x80;
1584 cmd[1] = mode;
1585
1586 Fbc_Get_BatchValue(fromDev, cmd, 2);
1587 //*mode = cmd[1];
1588 *r_gain = cmd[2];
1589 *g_gain = cmd[3];
1590 *b_gain = cmd[4];
1591 *r_offset = cmd[5];
1592 *g_offset = cmd[6];
1593 *b_offset = cmd[7];
1594
1595 return 0;
1596}
1597
1598int CFbcCommunication::cfbc_Set_backlight_onoff(COMM_DEV_TYPE_E fromDev, int value)
1599{
1600 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_BACKLIGHT_EN, value);
1601}
1602
1603int CFbcCommunication::cfbc_Get_backlight_onoff(COMM_DEV_TYPE_E fromDev, int *value)
1604{
1605 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_BACKLIGHT_EN, value);
1606}
1607
1608int CFbcCommunication::cfbc_Set_LVDS_SSG_Set(COMM_DEV_TYPE_E fromDev, int value)
1609{
1610 return Fbc_Set_Value_INT8(fromDev, CMD_LVDS_SSG_SET, value);
1611}
1612
1613int CFbcCommunication::cfbc_Set_AUTO_ELEC_MODE(COMM_DEV_TYPE_E fromDev, int value)
1614{
1615 LOGD("%s cmd =0x%x, value=%d~~~~~~~~", __FUNCTION__, VPU_CMD_SET_ELEC_MODE, value);
1616 return Fbc_Set_Value_INT8(fromDev, VPU_CMD_SET_ELEC_MODE, value);
1617}
1618
1619int CFbcCommunication::cfbc_Get_AUTO_ELEC_MODE(COMM_DEV_TYPE_E fromDev, int *value)
1620{
1621 LOGD("%s cmd =0x%x~~~~~~~~~", __FUNCTION__, VPU_CMD_SET_ELEC_MODE);
1622 return Fbc_Get_Value_INT8(fromDev, VPU_CMD_GET_ELEC_MODE, value);
1623}
1624
1625int CFbcCommunication::cfbc_Set_Thermal_state(COMM_DEV_TYPE_E fromDev, int value)
1626{
1627 LOGD("%s cmd =0x%x, data%d ~~~~~~~~~\n", __FUNCTION__, CMD_HDMI_STAT, value);
1628 //return Fbc_Set_Value_INT8(fromDev, CMD_HDMI_STAT, value);
1629 return Fbc_Set_Value_INT32(fromDev, CMD_HDMI_STAT, value);
1630}
1631
1632int CFbcCommunication::cfbc_Set_LightSensor_N310(COMM_DEV_TYPE_E fromDev, int value)
1633{
1634 // return Fbc_Set_Value_INT8(fromDev, CMD_LIGHT_SENSOR, value);
1635 return 0;
1636}
1637
1638int CFbcCommunication::cfbc_Get_LightSensor_N310(COMM_DEV_TYPE_E fromDev, int *value)
1639{
1640 // return Fbc_Get_Value_INT8(fromDev, CMD_LIGHT_SENSOR|0x80, value);
1641 return 0;
1642}
1643
1644int CFbcCommunication::cfbc_Set_Dream_Panel_N310(COMM_DEV_TYPE_E fromDev, int value)
1645{
1646 // return Fbc_Set_Value_INT8(fromDev, CMD_DREAM_PANEL, value);
1647 return 0;
1648}
1649
1650int CFbcCommunication::cfbc_Get_Dream_Panel_N310(COMM_DEV_TYPE_E fromDev, int *value)
1651{
1652 // return Fbc_Get_Value_INT8(fromDev, CMD_DREAM_PANEL|0x80, value);
1653 return 0;
1654}
1655
1656int CFbcCommunication::cfbc_Set_MULT_PQ_N310(COMM_DEV_TYPE_E fromDev, int value)
1657{
1658 // return Fbc_Set_Value_INT8(fromDev, CMD_MUTI_PQ, value);
1659 return 0;
1660}
1661
1662int CFbcCommunication::cfbc_Get_MULT_PQ_N310(COMM_DEV_TYPE_E fromDev, int *value)
1663{
1664 // return Fbc_Get_Value_INT8(fromDev, CMD_MUTI_PQ|0x80, value);
1665 return 0;
1666}
1667
1668int CFbcCommunication::cfbc_Set_MEMC_N310(COMM_DEV_TYPE_E fromDev, int value)
1669{
1670 // return Fbc_Set_Value_INT8(fromDev, CMD_MEMC, value);
1671 return 0;
1672}
1673
1674int CFbcCommunication::cfbc_Get_MEMC_N310(COMM_DEV_TYPE_E fromDev, int *value)
1675{
1676 // return Fbc_Get_Value_INT8(fromDev, CMD_MEMC|0x80, value);
1677 return 0;
1678}
1679
1680
1681void CFbcCommunication::CFbcMsgQueue::handleMessage ( CMessage &msg )
1682{
1683 LOGD ( "%s, CFbcCommunication::CFbcMsgQueue::handleMessage type = %d", __FUNCTION__, msg.mType );
1684
1685 switch ( msg.mType ) {
1686 case TV_MSG_COMMON:
1687 break;
1688
1689 case TV_MSG_SEND_KEY: {
1690 LOGD("CFbcMsgQueue msg type = %d", msg.mType);
1691 //CFbcCommunication *pFbc = ( CFbcCommunication * ) ( msg.mpData );
1692 //pFbc->mTvInput.sendkeyCode_Down(4);
1693 //pFbc->mbDownHaveSend = 1;//true
1694 break;
1695 }
1696
1697 default:
1698 break;
1699 }
1700}
1701