dncommthread.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. #include "dncommthread.h"
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <termios.h>
  8. #include <errno.h>
  9. #include <sys/ioctl.h>
  10. #include "yt_unit_shm.h"
  11. #include "realvalue.h"
  12. extern YT_UNIT_SHM *ytShm;
  13. int speed_arr[] = { B115200, B57600, B38400, B19200, B9600, B4800,
  14. B2400, B1200};
  15. int name_arr[] = {115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200};
  16. unsigned char ef_cmd_0[] = {0x01, 0x03, 0x10, 0x00, 0x00, 0x64, 0x00, 0x00};
  17. unsigned char ef_cmd_1[] = {0x01, 0x03, 0x12, 0x00, 0x00, 0x3e, 0x00, 0x00};
  18. unsigned char ef_cmd_2[] = {0x02, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
  19. unsigned char ef_cmd_si[] = {0x01, 0x10, 0x10, 0x63, 0x00, 0x01, 0x02, 0x72, 0x59, 0x5a, 0x98};
  20. unsigned char ef_cmd_cl[] = {0x01, 0x10, 0x10, 0x63, 0x00, 0x01, 0x02, 0x12, 0x34, 0xb3, 0x75};
  21. unsigned char ef_cmd_st[] = {0x01, 0x10, 0x10, 0x34, 0x00, 0x01, 0x02, 0x00, 0x3c, 0x00, 0x00};
  22. unsigned char ef_cmd_sc[] = {0x01, 0x10, 0x12, 0x3c, 0x00, 0x01, 0x02, 0x00, 0x64, 0x00, 0x00};
  23. unsigned short T0 = 0x0000;//线缆1温度上限
  24. unsigned short T0W = 0x0000;//线缆1温度上限过滤时间
  25. unsigned short T1 = 0x0000;//线缆2温度上限
  26. unsigned short T1W = 0x0000;//线缆2温度上限过滤时间
  27. unsigned short T2 = 0x0000;//电流上限
  28. unsigned short T2W = 0x0000;//电流上限过滤时间
  29. bool need_st0, need_st1, need_st2, need_cls, isWaitting;
  30. typedef union {
  31. float f;
  32. unsigned short s[2];
  33. }UNFI;
  34. DNCommThread::DNCommThread(QObject *parent, quint8 id, bool enabled, QString commpath) :
  35. QThread(parent)
  36. {
  37. Id = id;
  38. isWaitting = false;
  39. ef_idx = 0;
  40. noEcho0 = 0;
  41. noEcho1 = 0;
  42. Enabled = enabled;
  43. CommOpened = false;
  44. CommPath = commpath;
  45. CommType = 1;
  46. reopen = false;
  47. need_st0 = false;
  48. need_st1 = false;
  49. need_st2 = false;
  50. }
  51. void DNCommThread::setCommType(quint16 type)
  52. {
  53. CommType = type;
  54. }
  55. void DNCommThread::setparam(QString path, bool enabled)
  56. {
  57. Enabled = enabled;
  58. CommPath = path;
  59. if(CommOpened)
  60. {
  61. reopen = true;
  62. }
  63. }
  64. void DNCommThread::set_speed(int speed)
  65. {
  66. uint i;
  67. int status;
  68. struct termios Opt;
  69. tcgetattr(fd, &Opt);
  70. for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++)
  71. {
  72. if (speed == name_arr[i])
  73. {
  74. tcflush(fd, TCIOFLUSH);
  75. cfsetispeed(&Opt, speed_arr[i]);
  76. cfsetospeed(&Opt, speed_arr[i]);
  77. status = tcsetattr(fd, TCSANOW, &Opt);
  78. if (status != 0)
  79. perror("tcsetattr fd1");
  80. return;
  81. }
  82. tcflush(fd,TCIOFLUSH);
  83. }
  84. }
  85. int DNCommThread::set_Parity(int databits, int stopbits, int parity)
  86. {
  87. struct termios options;
  88. if ( tcgetattr( fd,&options) != 0)
  89. {
  90. perror("SetupSerial 1");
  91. return -1;
  92. }
  93. options.c_cflag &= ~CSIZE;
  94. switch (databits)
  95. {
  96. case 7:
  97. options.c_cflag |= CS7;
  98. break;
  99. case 8:
  100. options.c_cflag |= CS8;
  101. break;
  102. default:
  103. fprintf(stderr,"Unsupported data size\n");
  104. return -1;
  105. }
  106. switch (parity)
  107. {
  108. case 'n':
  109. case 'N':
  110. options.c_cflag &= ~PARENB;
  111. options.c_iflag &= ~INPCK;
  112. break;
  113. case 'o':
  114. case 'O':
  115. options.c_cflag |= (PARODD | PARENB);
  116. options.c_iflag |= INPCK;
  117. break;
  118. case 'e':
  119. case 'E':
  120. options.c_cflag |= PARENB;
  121. options.c_cflag &= ~PARODD;
  122. options.c_iflag |= INPCK;
  123. break;
  124. case 'S':
  125. case 's':
  126. options.c_cflag &= ~PARENB;
  127. options.c_cflag &= ~CSTOPB;
  128. break;
  129. default:
  130. fprintf(stderr,"Unsupported parity\n");
  131. return -1;
  132. }
  133. switch (stopbits)
  134. {
  135. case 1:
  136. options.c_cflag &= ~CSTOPB;
  137. break;
  138. case 2:
  139. options.c_cflag |= CSTOPB;
  140. break;
  141. default:
  142. fprintf(stderr,"Unsupported stop bits\n");
  143. return -1;
  144. }
  145. options.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
  146. options.c_oflag &= ~OPOST;
  147. options.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
  148. /* Set input parity option */
  149. if (parity != 'n')
  150. options.c_iflag |= INPCK;
  151. options.c_cc[VTIME] = 150; // 15 seconds
  152. options.c_cc[VMIN] = 0;
  153. tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */
  154. if (tcsetattr(fd,TCSANOW,&options) != 0)
  155. {
  156. perror("SetupSerial 3");
  157. return -1;
  158. }
  159. return 0;
  160. }
  161. int DNCommThread::open_comm()
  162. {
  163. // printf("open comm %d %s\n",Id,CommPath.toUtf8().data());
  164. fd = open(CommPath.toUtf8().data(),O_RDWR);
  165. if(fd==-1)
  166. return -1;
  167. set_speed(9600);
  168. if(set_Parity(8,1,'N')==-1){
  169. close(fd);
  170. return -1;
  171. }
  172. return 0;
  173. }
  174. void DNCommThread::chk_rtn(QByteArray Rtn)
  175. {
  176. // printf("Rtn length:%d\n",Rtn.length());
  177. if(Rtn.length()>0){
  178. QDateTime dt = QDateTime::currentDateTime();
  179. QString str = QString("[%1] %2 recv: ").arg(dt.toString("yyyy-MM-dd HH:mm:ss")).arg(Id);
  180. for(int i=0;i<Rtn.length();i++)
  181. str.append(QString("%1 ").arg(Rtn[i]&0xff,2,16,QChar('0')));
  182. emit log(str);
  183. uint t = dt.toTime_t();
  184. if(((Rtn[0]&0xff)==0xdc)
  185. &&((Rtn[1]&0xff)==0xcd)
  186. &&((Rtn[2]&0xff)==0xaa)
  187. &&((Rtn[3]&0xff)==0xaa)
  188. &&((Rtn[4]&0xff)==0xe0)
  189. &&((Rtn[Rtn.length()-2]&0xff)==0xcd)
  190. &&((Rtn[Rtn.length()-1]&0xff)==0xdc))
  191. {
  192. if((Rtn.at(5)&0xff)==0xc1){//定时上报
  193. int cure2 = Rtn.indexOf((char)(0xe2),0);
  194. int cur55 = Rtn.indexOf((char)(0x55),0);
  195. int cure3 = Rtn.indexOf((char)(0xe3),0);
  196. int cure6 = Rtn.indexOf((char)(0xe6),0);
  197. if(((Rtn.at(cure2+1)&0xff)==0x01)
  198. &&((cur55-cure2)>=6)){
  199. chk_e2(Rtn.mid(cure2+2,cur55-cure2-2),t);
  200. }
  201. if(((Rtn.at(cure3+1)&0xff)==0x01)
  202. &&((cure6-cure3)>=10)
  203. &&((cure6-cure3)<=18))
  204. {
  205. chk_e3(Rtn.mid(cure3+2,cure6-cure3-1),t);
  206. }
  207. QByteArray e6 = Rtn.mid(cure6);
  208. int base=0;
  209. while(e6.length()>=7)
  210. {
  211. if(((e6.at(1)&0xff)>=1)
  212. &&((e6.at(1)&0xff)<=16)
  213. &&((e6.at(2)&0xff)==0x01)
  214. &&((e6.at(5)&0xff)==0x02)
  215. &&((e6.at(6)&0xff)==0x01))
  216. {
  217. if(ytShm->sPointList.sPoint[Id][128+base].ENABLED==0x01)
  218. {
  219. float v = ((e6.at(3)&0xff)*256.0+(e6.at(4)&0xff)*1.0)/150.0;
  220. set_realtime_value(Id,128+base,v,t);
  221. }
  222. base++;
  223. cure6 = e6.indexOf((char)(0xe6),6);
  224. if(cure6>0)
  225. e6 = e6.mid(cure6);
  226. else
  227. break;
  228. }else{
  229. break;
  230. }
  231. }
  232. }else if((Rtn.at(5)&0xff)==0xf1){//主动上报
  233. int cure2 = Rtn.indexOf((char)(0xe2),0);
  234. int cur55 = Rtn.indexOf((char)(0x55),0);
  235. int cure3 = Rtn.indexOf((char)(0xe3),0);
  236. int cure6 = Rtn.indexOf((char)(0xe6),0);
  237. if(((Rtn.at(cure2+1)&0xff)==0x01)
  238. &&((cur55-cure2)>=6)){
  239. chk_e2(Rtn.mid(cure2+2,cur55-cure2-2),t);
  240. }
  241. if(((Rtn.at(cure3+1)&0xff)==0x01)
  242. &&((cure6-cure3)==4))
  243. {
  244. quint8 e3id = ((Rtn.at(cure3+2)&0xf0)>>4)*10+(Rtn.at(cure3+2)&0x0f);
  245. if((e3id>=1)&&(e3id<=16))
  246. {
  247. if(ytShm->sPointList.sPoint[Id][e3id].ENABLED==0x01)
  248. {
  249. if((Rtn.at(cure3+3)&0xff)==0x00)
  250. set_realtime_value(Id,e3id,0,t);
  251. else
  252. set_realtime_value(Id,e3id,1,t);
  253. }
  254. }
  255. }
  256. QByteArray e6 = Rtn.mid(cure6);
  257. int base=0;
  258. while(e6.length()>=7)
  259. {
  260. if(((e6.at(1)&0xff)>=1)
  261. &&((e6.at(1)&0xff)<=16)
  262. &&((e6.at(2)&0xff)==0x01)
  263. &&((e6.at(5)&0xff)==0x02)
  264. &&((e6.at(6)&0xff)==0x01))
  265. {
  266. if(ytShm->sPointList.sPoint[Id][128+base].ENABLED==0x01)
  267. {
  268. float v = ((e6.at(3)&0xff)*256.0+(e6.at(4)&0xff)*1.0)/150.0;
  269. set_realtime_value(Id,128+base,v,t);
  270. }
  271. base++;
  272. cure6 = e6.indexOf((char)(0xe6),6);
  273. if(cure6>0)
  274. e6 = e6.mid(cure6);
  275. else
  276. break;
  277. }else{
  278. break;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. quint16 DNCommThread::chk_crcc(quint8 *d, int len)
  286. {
  287. int j,i;
  288. quint16 default_data = 0xa001;
  289. quint16 crc = 0xffff;
  290. for(j=0;j<(len-2);j++){
  291. crc ^= (quint16)(d[j]&0x00ff);
  292. for(i=0;i<8;i++){
  293. if(crc&0x01){
  294. crc >>= 1;
  295. crc ^= default_data;//a001,1021
  296. }else
  297. crc >>= 1;
  298. }
  299. }
  300. return crc;
  301. }
  302. void DNCommThread::ef_comm2_read()
  303. {
  304. int t_len,len;
  305. fd_set reads;
  306. struct timeval timeout;
  307. unsigned char cmd[8];
  308. unsigned char tmp[1024];
  309. unsigned char rtn[1024];
  310. quint32 v_tmp;
  311. uint t = QDateTime::currentDateTime().toTime_t();
  312. read(fd,tmp,1024);
  313. FD_ZERO(&reads);
  314. FD_SET(fd,&reads);
  315. timeout.tv_sec = 1;
  316. timeout.tv_usec = 500000;
  317. cmd[0] = 0x01;
  318. cmd[1] = 0x03;
  319. cmd[2] = 0x00;
  320. cmd[3] = 0x00;
  321. cmd[4] = 0x00;
  322. cmd[5] = 0x10;
  323. cmd[6] = 0x44;
  324. cmd[7] = 0x06;
  325. write(fd,cmd,8);
  326. noEcho0++;
  327. if(select(fd+1,&reads,NULL,NULL,&timeout)>=0)
  328. {
  329. if(FD_ISSET(fd,&reads))
  330. {
  331. t_len= read(fd,tmp,1024);
  332. len=t_len;
  333. if(t_len>0){
  334. for(int i=0;i<t_len;i++)
  335. {
  336. rtn[i] = tmp[i]&0xff;
  337. printf("%02x ",rtn[i]);
  338. }
  339. if(len<((rtn[2]&0xff)+5)){
  340. usleep(200000);
  341. t_len=read(fd,tmp,1024);
  342. if(t_len>0){
  343. for(int i=0;i<t_len;i++)
  344. {
  345. rtn[i+len]=tmp[i]&0xff;
  346. printf("%02x ",rtn[i+len]);
  347. }
  348. len += t_len;
  349. }
  350. }
  351. printf("\n");
  352. if(len>=69){
  353. quint16 crc = chk_crcc((quint8 *)rtn, len);
  354. // printf("%02x%02x %04x\n",rtn[len-1],rtn[len-2],crc);
  355. if((rtn[len-1]==((crc>>8)&0xff))&&(rtn[len-2]==(crc&0xff))){
  356. noEcho0 = 0;
  357. v_tmp = static_cast<quint32>(((rtn[7]&0x000000ff)<<24)|((rtn[8]&0x000000ff)<<16)|((rtn[9]&0x000000ff)<<8)|(rtn[10]&0x000000ff));
  358. float value = *(float*)&v_tmp;
  359. set_realtime_value(Id,1,value*1.0,t);
  360. v_tmp = static_cast<quint32>(((rtn[11]&0x000000ff)<<24)|((rtn[12]&0x000000ff)<<16)|((rtn[13]&0x000000ff)<<8)|(rtn[14]&0x000000ff));
  361. value = *(float*)&v_tmp;
  362. set_realtime_value(Id,2,value*1.0,t);
  363. v_tmp = static_cast<quint32>(((rtn[15]&0x000000ff)<<24)|((rtn[16]&0x000000ff)<<16)|((rtn[17]&0x000000ff)<<8)|(rtn[18]&0x000000ff));
  364. value = *(float*)&v_tmp;
  365. set_realtime_value(Id,3,value*1.0,t);
  366. v_tmp = static_cast<quint32>(((rtn[19]&0x000000ff)<<24)|((rtn[20]&0x000000ff)<<16)|((rtn[21]&0x000000ff)<<8)|(rtn[22]&0x000000ff));
  367. value = *(float*)&v_tmp;
  368. set_realtime_value(Id,4,value*1.0,t);
  369. v_tmp = static_cast<quint32>(((rtn[23]&0x000000ff)<<24)|((rtn[24]&0x000000ff)<<16)|((rtn[25]&0x000000ff)<<8)|(rtn[26]&0x000000ff));
  370. value = *(float*)&v_tmp;
  371. set_realtime_value(Id,5,value*1.0,t);
  372. v_tmp = static_cast<quint32>(((rtn[27]&0x000000ff)<<24)|((rtn[28]&0x000000ff)<<16)|((rtn[29]&0x000000ff)<<8)|(rtn[30]&0x000000ff));
  373. value = *(float*)&v_tmp;
  374. set_realtime_value(Id,6,value*1.0,t);
  375. v_tmp = static_cast<quint32>(((rtn[31]&0x000000ff)<<24)|((rtn[32]&0x000000ff)<<16)|((rtn[33]&0x000000ff)<<8)|(rtn[34]&0x000000ff));
  376. value = *(float*)&v_tmp;
  377. set_realtime_value(Id,7,value*1.0,t);
  378. v_tmp = static_cast<quint32>(((rtn[35]&0x000000ff)<<24)|((rtn[36]&0x000000ff)<<16)|((rtn[37]&0x000000ff)<<8)|(rtn[38]&0x000000ff));
  379. value = *(float*)&v_tmp;
  380. set_realtime_value(Id,8,value*1.0,t);
  381. v_tmp = static_cast<quint32>(((rtn[39]&0x000000ff)<<24)|((rtn[40]&0x000000ff)<<16)|((rtn[41]&0x000000ff)<<8)|(rtn[42]&0x000000ff));
  382. value = *(float*)&v_tmp;
  383. set_realtime_value(Id,9,value*1.0,t);
  384. v_tmp = static_cast<quint32>(((rtn[43]&0x000000ff)<<24)|((rtn[44]&0x000000ff)<<16)|((rtn[45]&0x000000ff)<<8)|(rtn[46]&0x000000ff));
  385. value = *(float*)&v_tmp;
  386. set_realtime_value(Id,10,value*1.0,t);
  387. v_tmp = static_cast<quint32>(((rtn[47]&0x000000ff)<<24)|((rtn[48]&0x000000ff)<<16)|((rtn[49]&0x000000ff)<<8)|(rtn[50]&0x000000ff));
  388. value = *(float*)&v_tmp;
  389. set_realtime_value(Id,11,value*1.0,t);
  390. v_tmp = static_cast<quint32>(((rtn[51]&0x000000ff)<<24)|((rtn[52]&0x000000ff)<<16)|((rtn[53]&0x000000ff)<<8)|(rtn[54]&0x000000ff));
  391. value = *(float*)&v_tmp;
  392. set_realtime_value(Id,12,value*1.0,t);
  393. v_tmp = static_cast<quint32>(((rtn[55]&0x000000ff)<<24)|((rtn[56]&0x000000ff)<<16)|((rtn[57]&0x000000ff)<<8)|(rtn[58]&0x000000ff));
  394. value = *(float*)&v_tmp;
  395. set_realtime_value(Id,13,value*1.0,t);
  396. v_tmp = static_cast<quint32>(((rtn[59]&0x000000ff)<<24)|((rtn[60]&0x000000ff)<<16)|((rtn[61]&0x000000ff)<<8)|(rtn[62]&0x000000ff));
  397. value = *(float*)&v_tmp;
  398. set_realtime_value(Id,14,value*1.0,t);
  399. v_tmp = static_cast<quint32>(((rtn[63]&0x000000ff)<<24)|((rtn[64]&0x000000ff)<<16)|((rtn[65]&0x000000ff)<<8)|(rtn[66]&0x000000ff));
  400. value = *(float*)&v_tmp;
  401. set_realtime_value(Id,15,value*1.0,t);
  402. }
  403. }
  404. }
  405. }
  406. }
  407. }
  408. void DNCommThread::chk_e2(QByteArray d, uint t)
  409. {
  410. if(d.length()>=4){
  411. for(int i=0;i<d.length();i++)
  412. {
  413. if(ytShm->sPointList.sPoint[Id][64+i].ENABLED==0x01)
  414. {
  415. if((d.at(i)&0xff)==0x00)
  416. set_realtime_value(Id,64+i,0,t);
  417. else
  418. set_realtime_value(Id,64+i,1,t);
  419. }
  420. }
  421. }
  422. }
  423. void DNCommThread::chk_e3(QByteArray d, uint t)
  424. {
  425. for(int i=0;i<d.length();i++)
  426. {
  427. if(ytShm->sPointList.sPoint[Id][1+i].ENABLED==0x01)
  428. {
  429. if((d.at(i)&0xff)==0x00)
  430. set_realtime_value(Id,1+i,0,t);
  431. else
  432. set_realtime_value(Id,1+i,1,t);
  433. }
  434. }
  435. }
  436. void DNCommThread::run()
  437. {
  438. if(Enabled)
  439. {
  440. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].IDX = DNCOMM_THREAD_0+Id;
  441. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].WAITSEC = 30;
  442. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].ENABLED = 0x01;
  443. emit log(QString("[%1] dncomm[%2] thread start\r\n")
  444. .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  445. .arg(Id));
  446. }
  447. else
  448. {
  449. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].IDX = DNCOMM_THREAD_0+Id;
  450. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].WAITSEC = 0;
  451. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].ENABLED = 0x00;
  452. emit log(QString("[%1] dncomm[%2] thread disabled\r\n")
  453. .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  454. .arg(Id));
  455. }
  456. while(1)
  457. {
  458. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].IDX = DNCOMM_THREAD_0+Id;
  459. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].WAITSEC = 30;
  460. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].ENABLED = 0x01;
  461. ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].LASTFEED
  462. = QDateTime::currentDateTime().toTime_t();
  463. printf("dncomm %d last feed %d\n",Id,ytShm->dogTimeList.dogTime[DNCOMM_THREAD_0+Id].LASTFEED);
  464. if(!Enabled)
  465. {
  466. if(CommOpened){
  467. close(fd);
  468. emit log(QString("[%1] dncomm[%2] thread stop\r\n")
  469. .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  470. .arg(Id));
  471. return;
  472. }
  473. }else{
  474. if(!CommOpened){
  475. if(open_comm()==-1)
  476. {
  477. emit log(QString("[%1] dncomm[%2] open failed\r\n")
  478. .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  479. .arg(CommPath));
  480. return;
  481. }else{
  482. emit log(QString("[%1] dncomm[%2] opened\r\n")
  483. .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  484. .arg(CommPath));
  485. CommOpened = true;
  486. }
  487. }else if(reopen){
  488. if(CommOpened){
  489. close(fd);
  490. emit log(QString("[%1] dncomm[%2] thread stop\r\n")
  491. .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  492. .arg(Id));
  493. CommOpened = false;
  494. }
  495. reopen = false;
  496. }else{//read and write
  497. if(CommType==3){
  498. ef_comm2_read();
  499. }
  500. }
  501. }
  502. usleep(300000);
  503. }
  504. }