a01bbd9abf502eb3d5107555bab3dbcc237e6759.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. #include "ytcore.h"
  2. #include <stdio.h>
  3. #include "yt_unit_shm.h"
  4. YT_UNIT_SHM *ytShm;
  5. extern bool myLog;
  6. extern bool myDebug;
  7. BpCore::BpCore(QObject *parent) :
  8. QObject(parent)
  9. {
  10. CHour = QDateTime::currentDateTime().time().hour();
  11. Sid = "RQ0000000001";
  12. Skey = "44c2710b-f7ff-4487-a556-bfae08232a09";
  13. Spath = "http://sgdzpic.3322.org:8088";
  14. timer = new QTimer(this);
  15. connect(timer,SIGNAL(timeout()),this,SLOT(time_out()));
  16. db = QSqlDatabase::addDatabase("QSQLITE","conf_db");
  17. db.setDatabaseName(QString(CONF_DB));
  18. stadb = QSqlDatabase::addDatabase("QSQLITE","sta_db");
  19. stadb.setDatabaseName(QString(STA_DB));
  20. recdb = QSqlDatabase::addDatabase("QSQLITE","rec_db");
  21. recdb.setDatabaseName(QString(REC_DB));
  22. if((!db.open())||(!stadb.open())||(!recdb.open()))
  23. {
  24. system("echo 'Database open failed.\n'");
  25. exit(-1);
  26. }
  27. db_init();
  28. sender = new MessageSender(this,Spath+"/agbox/device/perception",Skey,Sid);
  29. connect(sender,SIGNAL(sent(QString)),this,SLOT(mse_send(QString)));
  30. if(!shm_load())
  31. {
  32. system("echo 'Memory load failed.\n'");
  33. exit(-1);
  34. }
  35. logThread = new LogThread(this);
  36. logThread->start();
  37. if(myLog)
  38. logThread->appendLog(QString("[%1] main appliction start\r\n")
  39. .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")));
  40. dbThread = new DBThread(this,&db,&stadb,&recdb);
  41. connect(dbThread,SIGNAL(log(QString)),this,SLOT(log(QString)));
  42. connect(dbThread,SIGNAL(dbg_log(QString)),this,SLOT(dbg_log(QString)));
  43. ytShm->dogTimeList.dogTime[CORE_MAIN].IDX = CORE_MAIN;
  44. ytShm->dogTimeList.dogTime[CORE_MAIN].WAITSEC = 30;
  45. ytShm->dogTimeList.dogTime[CORE_MAIN].ENABLED = 0x01;
  46. timer->start(500);
  47. dbThread->start();
  48. for(quint8 CommId=0;CommId<4;CommId++)
  49. {
  50. if(ytShm->commList.comm[CommId].ENABLED==0x01)
  51. {
  52. dnThread[CommId] = new DNCommThread(this,CommId,true,QString(ytShm->commList.comm[CommId].PATH));
  53. dnThread[CommId]->setCommType(ytShm->commList.comm[CommId].CommType);
  54. connect(dnThread[CommId],SIGNAL(log(QString)),this,SLOT(log(QString)));
  55. connect(dnThread[CommId],SIGNAL(dbg_log(QString)),this,SLOT(dbg_log(QString)));
  56. connect(dnThread[CommId],SIGNAL(recsql(QString)),this,SLOT(recsql(QString)));
  57. connect(dnThread[CommId],SIGNAL(stasql(QString)),this,SLOT(stasql(QString)));
  58. connect(dnThread[CommId],SIGNAL(confsql(QString)),this,SLOT(confsql(QString)));
  59. dnThread[CommId]->start();
  60. }
  61. }
  62. }
  63. void BpCore::run()
  64. {
  65. }
  66. void BpCore::log(QString txt)
  67. {
  68. if(myLog)
  69. logThread->appendLog(txt);
  70. }
  71. void BpCore::dbg_log(QString txt)
  72. {
  73. if(myDebug)
  74. logThread->appendDbgLog(txt);
  75. }
  76. void BpCore::confsql(QString sql)
  77. {
  78. dbThread->appendSQL(1,sql);
  79. }
  80. void BpCore::stasql(QString sql)
  81. {
  82. dbThread->appendSQL(2,sql);
  83. }
  84. void BpCore::recsql(QString sql)
  85. {
  86. dbThread->appendSQL(3,sql);
  87. }
  88. void BpCore::mse_send(QString id)
  89. {
  90. recsql(QString("update yt_rec_report set sent=1 where Id='%1'").arg(id));
  91. }
  92. void BpCore::time_out()
  93. {
  94. ytShm->dogTimeList.dogTime[CORE_MAIN].LASTFEED = QDateTime::currentDateTime().toTime_t();
  95. for(int cid=0;cid<4;cid++){
  96. for(int pid=0;pid<256;pid++){
  97. if(ytShm->sPointList.sPoint[cid][pid].ENABLED==0x01)
  98. {
  99. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_SENT==0x00)
  100. {
  101. if((ytShm->dogTimeList.dogTime[CORE_MAIN].LASTFEED-ytShm->spStatusList.spStatus[cid][pid].ALARM_TIMESTAMP)>ytShm->sPointList.sPoint[cid][pid].PNO_DLY){
  102. ytShm->spStatusList.spStatus[cid][pid].ALARM_SENT=0x01;
  103. int code = -1;
  104. if(pid==1){
  105. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_STATUS!=0x00)
  106. code = 89;
  107. else if(ytShm->spStatusList.spStatus[cid][2].ALARM_STATUS==0x00)
  108. code = 91;
  109. }else if(pid==2){
  110. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_STATUS!=0x00)
  111. code = 90;
  112. else if(ytShm->spStatusList.spStatus[cid][1].ALARM_STATUS==0x00)
  113. code = 91;
  114. }else if(pid==3){
  115. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_STATUS!=0x00)
  116. code = 92;
  117. else
  118. code = 93;
  119. }else if(pid==4){
  120. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_STATUS!=0x00)
  121. code = 94;
  122. else
  123. code = 95;
  124. }else if(pid==5){
  125. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_STATUS!=0x00)
  126. code = 96;
  127. else
  128. code = 97;
  129. }else if(pid==6){
  130. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_STATUS!=0x00)
  131. code = 98;
  132. else
  133. code = 99;
  134. }else if(pid==7){
  135. if(ytShm->spStatusList.spStatus[cid][pid].ALARM_STATUS!=0x00)
  136. code = 100;
  137. else
  138. code = 101;
  139. }
  140. if(code>=0){
  141. QString uid = QUuid::createUuid().toString().replace("{","").replace("}","");
  142. QString sql =QString("insert into yt_rec_report (Id, channel, code, time, note, sent) values ('%1',%2,%3,%4,'',0);")
  143. .arg(uid).arg(cid+1).arg(code).arg(ytShm->spStatusList.spStatus[cid][pid].ALARM_TIMESTAMP);
  144. // printf("%s\n",sql.toUtf8().data());
  145. dbThread->appendSQL(3,sql);
  146. Msg msg;
  147. msg.ID = uid;
  148. msg.MSG = QString("key=%1&json={\"jsonrpc\":\"2.0\",\"id\":\"%2\",\"method\":\"addEvent\",\"params\":{\"deviceId\":\"%2\",\"channel\":%3,\"triggerTime\":\"%4\",\"eventCode\":%5,\"note\":\"%6\"}}")
  149. .arg(Skey).arg(Sid).arg(cid+1)
  150. .arg(QDateTime::fromTime_t(ytShm->spStatusList.spStatus[cid][pid].ALARM_TIMESTAMP).toString("yyyy-MM-dd HH:mm:ss"))
  151. .arg(code).arg("");
  152. sender->appendMsg(msg);
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. if(CHour!=(QDateTime::currentDateTime().time().hour())){
  160. CHour = QDateTime::currentDateTime().time().hour();
  161. for(int cid=0;cid<4;cid++){
  162. for(int pid=0;pid<256;pid++){
  163. if(ytShm->sPointList.sPoint[cid][pid].ENABLED==0x01)
  164. {
  165. if(ytShm->spStatusList.spStatus[cid][pid].COUNT>0){
  166. QString sql = QString("insert into yt_rec_data (Id, CommId, BusAdd, AveValue, StoreTime, MaxValue, MaxTime, MinValue, MinTime) values (NULL,%1,%2,%3,%4,%5,%6,%7,%8)")
  167. .arg(cid).arg(pid).arg(ytShm->spStatusList.spStatus[cid][pid].TOTAL_VALUE/ytShm->spStatusList.spStatus[cid][pid].COUNT)
  168. .arg(ytShm->spStatusList.spStatus[cid][pid].REALTIME_TIMESTAMP).arg(ytShm->spStatusList.spStatus[cid][pid].MAX_VALUE)
  169. .arg(ytShm->spStatusList.spStatus[cid][pid].MAX_TIMESTAMP).arg(ytShm->spStatusList.spStatus[cid][pid].MIN_VALUE)
  170. .arg(ytShm->spStatusList.spStatus[cid][pid].MIN_TIMESTAMP);
  171. dbThread->appendSQL(3,sql);
  172. ytShm->spStatusList.spStatus[cid][pid].COUNT = 0;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }
  179. bool BpCore::chk_table(QString tbname, QStringList tables)
  180. {
  181. for(int i=0;i<tables.length();i++)
  182. {
  183. if(tables.at(i).compare(tbname)==0)
  184. return true;
  185. }
  186. return false;
  187. }
  188. void BpCore::db_init()
  189. {
  190. if(!chk_table("yt_t_upcom",db.tables()))
  191. {
  192. if(db.transaction())
  193. {
  194. db.exec(QString("create table yt_t_upcom (Id integer, SelfId text, Key text, UpUrl text)"));
  195. db.exec(QString("insert into yt_t_upcom (Id, SelfId, Key, UpUrl) values (0, '%1','%2','%3')").arg(Sid).arg(Skey).arg(Spath));
  196. db.commit();
  197. }
  198. }
  199. if(!chk_table("yt_t_comm",db.tables()))
  200. {
  201. if(db.transaction())
  202. {
  203. db.exec(QString("create table yt_t_comm (Id integer, CommType integer, CommPath text, Enabled integer)"));
  204. for(int i=0;i<4;i++)
  205. {
  206. if(i==0)
  207. db.exec(QString("insert into yt_t_comm (Id, CommType, CommPath, Enabled) values (0,1,'/dev/ttySAC2',1)"));
  208. else
  209. db.exec(QString("insert into yt_t_comm (Id, CommType, CommPath, Enabled) values (%1,1,'/dev/ttyO%2',%3)")
  210. .arg(i).arg(i).arg(0));
  211. }
  212. db.commit();
  213. }
  214. }
  215. if(!chk_table("yt_t_point",db.tables()))
  216. {
  217. if(db.transaction())
  218. {
  219. db.exec(QString("create table yt_t_point (CommId integer, BusAdd integer, Enabled integer, Name text(200), PnoType integer, PnoAlarm integer, PnoValue integer, PnoDly integer, PnoAd integer, Offset integer, OffsetFlag integer, PnoMax real, PnoMin real, AlarmH real, AlarmL real, SubType integer)"));
  220. for(int commid=0;commid<4;commid++)
  221. {
  222. for(int busadd=0;busadd<=255;busadd++)
  223. {
  224. if((commid==0)&&(((busadd<11)&&(busadd>0))||((busadd>127)&&(busadd<133)))){
  225. if(busadd<11){
  226. db.exec(QString("insert into yt_t_point (CommId, BusAdd, Enabled, Name, PnoType, PnoAlarm, PnoValue, PnoDly, PnoAd, Offset, OffsetFlag, PnoMax, PnoMin, AlarmH, AlarmL,SubType) values (%1,%2,1,'%3',1,1,0,0,0,0,0,0,0,0,0,%4)")
  227. .arg(commid).arg(busadd).arg(QString("P_%1_%2").arg(commid).arg(busadd,3,10,QChar('0'))).arg(0x01<<((busadd-1)/2)));
  228. }else{
  229. db.exec(QString("insert into yt_t_point (CommId, BusAdd, Enabled, Name, PnoType, PnoAlarm, PnoValue, PnoDly, PnoAd, Offset, OffsetFlag, PnoMax, PnoMin, AlarmH, AlarmL,SubType) values (%1,%2,1,'%3',2,0,0,0,0,0,0,0,0,0,0,%4)")
  230. .arg(commid).arg(busadd).arg(QString("P_%1_%2").arg(commid).arg(busadd,3,10,QChar('0'))).arg(0x01<<(busadd-128)));
  231. }
  232. }else
  233. db.exec(QString("insert into yt_t_point (CommId, BusAdd, Enabled, Name, PnoType, PnoAlarm, PnoValue, PnoDly, PnoAd, Offset, OffsetFlag, PnoMax, PnoMin, AlarmH, AlarmL,SubType) values (%1,%2,0,'%3',0,0,0,0,0,0,0,0,0,0,0,0)")
  234. .arg(commid).arg(busadd).arg(QString("P_%1_%2").arg(commid).arg(busadd,3,10,QChar('0'))));
  235. }
  236. }
  237. db.commit();
  238. }
  239. }
  240. if(!chk_table("yt_rec_report",recdb.tables()))
  241. {
  242. if(recdb.transaction())
  243. {
  244. recdb.exec(QString("create table yt_rec_report (Id text, channel integer, code integer, time integer, note text, sent integer)"));
  245. recdb.commit();
  246. }
  247. }
  248. if(!chk_table("yt_rec_data",recdb.tables()))
  249. {
  250. if(recdb.transaction())
  251. {
  252. recdb.exec(QString("create table yt_rec_data (Id integer primary key autoincrement, CommId integer, BusAdd integer, AveValue real, StoreTime integer, MaxValue real, MaxTime integer, MinValue real, MinTime integer)"));
  253. recdb.commit();
  254. }
  255. }
  256. if(!chk_table("yt_sta_comm",stadb.tables()))
  257. {
  258. if(stadb.transaction())
  259. {
  260. stadb.exec(QString("create table yt_sta_comm (CommId integer, Status integer, Updatetime integer, Sent integer)"));
  261. for(int commid=0;commid<4;commid++)
  262. {
  263. stadb.exec(QString("insert into yt_sta_comm (CommId, Status, Updatetime, Sent) values (%1, 1, 0, 1)").arg(commid));
  264. }
  265. stadb.commit();
  266. }
  267. }
  268. if(!chk_table("yt_sta_pno",stadb.tables()))
  269. {
  270. stadb.exec(QString("create table yt_sta_pno (CommId integer, BusAdd integer, RealtimeValue real, RealtimeTimestamp integer, AlarmStatus integer, AlarmTimestamp integer, AlarmSent integer, MaxValue real, MaxTimestamp integer, MinValue real, MinTimestamp integer, TotalValue real, AveValue real, Count integer)"));
  271. for(int commid=0;commid<4;commid++)
  272. {
  273. for(int busadd=0;busadd<=255;busadd++)
  274. {
  275. stadb.exec(QString("insert into yt_sta_pno (CommId, BusAdd, RealtimeValue, RealtimeTimestamp, AlarmStatus, AlarmTimestamp, AlarmSent, MaxValue, MaxTimestamp, MinValue, MinTimestamp, TotalValue, AveValue, Count) values (%1, %2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)")
  276. .arg(commid).arg(busadd));
  277. }
  278. }
  279. }
  280. QSqlQuery qry = db.exec("select Id, SelfId, Key, UpUrl from yt_t_upcom");
  281. if(qry.next())
  282. {
  283. Sid = qry.value(1).toString();
  284. Skey = qry.value(2).toString();
  285. Spath = qry.value(3).toString();
  286. }
  287. qry.clear();
  288. }
  289. void BpCore::shm_init()
  290. {
  291. QSqlQuery qry;
  292. qry = db.exec("select Id, CommType, CommPath, Enabled from yt_t_comm");
  293. while(qry.next())
  294. {
  295. quint8 id = qry.value(0).toUInt()&0xff;
  296. quint16 commType = qry.value(1).toUInt()&0xffff;
  297. QString commPath = qry.value(2).toString();
  298. quint8 enabled = ((qry.value(3).toUInt()&0xff)==0x01)?0x01:0x00;
  299. ytShm->commList.comm[id].IDX = id;
  300. ytShm->commList.comm[id].CommType = commType;
  301. sprintf(ytShm->commList.comm[id].PATH,"%s",commPath.toUtf8().data());
  302. ytShm->commList.comm[id].ENABLED = enabled;
  303. ytShm->commList.comm[id].UNSAVED = 0x00;
  304. // printf("ID:%d\t ENABLED:%d\tPATH:%s\n",id,enabled,commPath.toUtf8().data());
  305. }
  306. qry.clear();
  307. qry = db.exec("select CommId, BusAdd, Enabled, Name, PnoType, PnoAlarm, PnoValue, PnoDly, PnoAd, Offset, OffsetFlag, PnoMax, PnoMin, AlarmH, AlarmL,SubType from yt_t_point");
  308. while(qry.next())
  309. {
  310. quint8 commId = qry.value(0).toUInt()&0xff;
  311. quint8 busAdd = qry.value(1).toUInt()&0xff;
  312. quint8 enabled = ((qry.value(2).toUInt()&0xff)==0x01)?0x01:0x00;
  313. QString name = qry.value(3).toString();
  314. quint8 pnotype = qry.value(4).toUInt()&0xff;
  315. quint8 pnoalarm = qry.value(5).toUInt()&0xff;
  316. quint8 pnovalue = qry.value(6).toUInt()&0xff;
  317. quint8 pnodly = qry.value(7).toUInt()&0xff;
  318. quint8 pnoad = qry.value(8).toUInt()&0xff;
  319. quint8 offset = qry.value(9).toUInt()&0xff;
  320. quint8 offsetflag = qry.value(10).toUInt()&0xff;
  321. float pnomax = qry.value(11).toFloat();
  322. float pnomin = qry.value(12).toFloat();
  323. float alarmh = qry.value(13).toFloat();
  324. float alarml = qry.value(14).toFloat();
  325. uint subtype = qry.value(15).toUInt();
  326. if(commId<4){
  327. ytShm->sPointList.sPoint[commId][busAdd].COMM_IDX = commId;
  328. ytShm->sPointList.sPoint[commId][busAdd].BUS_ADD = busAdd;
  329. ytShm->sPointList.sPoint[commId][busAdd].ENABLED = enabled;
  330. bzero(ytShm->sPointList.sPoint[commId][busAdd].NAME,sizeof(ytShm->sPointList.sPoint[commId][busAdd].NAME));
  331. sprintf(ytShm->sPointList.sPoint[commId][busAdd].NAME,"%s",name.toUtf8().data());
  332. ytShm->sPointList.sPoint[commId][busAdd].PNO_TYPE = pnotype;
  333. ytShm->sPointList.sPoint[commId][busAdd].PNO_ALARM = pnoalarm;
  334. ytShm->sPointList.sPoint[commId][busAdd].PNO_VALUE = pnovalue;
  335. ytShm->sPointList.sPoint[commId][busAdd].PNO_DLY = pnodly;
  336. ytShm->sPointList.sPoint[commId][busAdd].PNO_AD = pnoad;
  337. ytShm->sPointList.sPoint[commId][busAdd].OFFSET = offset;
  338. ytShm->sPointList.sPoint[commId][busAdd].OFFSET_FLAG = offsetflag;
  339. ytShm->sPointList.sPoint[commId][busAdd].PNO_MAX = pnomax;
  340. ytShm->sPointList.sPoint[commId][busAdd].PNO_MIN = pnomin;
  341. ytShm->sPointList.sPoint[commId][busAdd].ALARM_H = alarmh;
  342. ytShm->sPointList.sPoint[commId][busAdd].ALARM_L = alarml;
  343. ytShm->sPointList.sPoint[commId][busAdd].SUB_TYPE = subtype;
  344. ytShm->sPointList.sPoint[commId][busAdd].UNSAVED = 0x00;
  345. }
  346. }
  347. qry.clear();
  348. qry = stadb.exec("select CommId, Status, Updatetime, Sent from yt_sta_comm");
  349. while(qry.next())
  350. {
  351. quint8 commid = qry.value(0).toUInt()&0xff;
  352. quint8 status = qry.value(1).toUInt()&0xff;
  353. uint updatetime = qry.value(2).toUInt();
  354. bool alarmsent = (qry.value(3).toUInt()==0x01);
  355. if(commid<4)
  356. {
  357. ytShm->commStatusList.commStatus[commid].STATUS = status;
  358. ytShm->commStatusList.commStatus[commid].TIMESTAMP = updatetime;
  359. ytShm->commStatusList.commStatus[commid].SENT = alarmsent;
  360. ytShm->commStatusList.commStatus[commid].UNSAVED = 0x00;
  361. }
  362. }
  363. qry.clear();
  364. qry = stadb.exec("select CommId, BusAdd, RealtimeValue, RealtimeTimestamp, AlarmStatus, AlarmTimestamp, AlarmSent, MaxValue, MaxTimestamp, MinValue, MinTimestamp, TotalValue, AveValue, Count from yt_sta_pno");
  365. while(qry.next())
  366. {
  367. quint8 commid = qry.value(0).toUInt()&0xff;
  368. quint8 busadd = qry.value(1).toUInt()&0xff;
  369. float realtimevalue = qry.value(2).toFloat();
  370. uint realtimetimestamp = qry.value(3).toUInt();
  371. quint8 alarmstatus =qry.value(4).toUInt()&0xff;
  372. uint alarmtimestamp = qry.value(5).toUInt();
  373. quint8 alarmsent = qry.value(6).toUInt()&0x01;
  374. float maxvalue = qry.value(7).toFloat();
  375. uint maxtimestamp = qry.value(8).toUInt()&0xff;
  376. float minvalue = qry.value(9).toFloat();
  377. uint mintimestamp = qry.value(10).toUInt();
  378. float totalvalue = qry.value(11).toFloat();
  379. float avevalue = qry.value(12).toFloat();
  380. uint count = qry.value(13).toUInt();
  381. if(commid<4){
  382. QDateTime vtime = QDateTime::fromTime_t(realtimetimestamp);
  383. ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE = realtimevalue;
  384. ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP = realtimetimestamp;
  385. ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS = alarmstatus;
  386. ytShm->spStatusList.spStatus[commid][busadd].ALARM_TIMESTAMP = alarmtimestamp;
  387. ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = alarmsent;
  388. ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = maxvalue;
  389. ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = maxtimestamp;
  390. ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = minvalue;
  391. ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = mintimestamp;
  392. ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE = totalvalue;
  393. ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE = avevalue;
  394. ytShm->spStatusList.spStatus[commid][busadd].COUNT = count;
  395. ytShm->spStatusList.spStatus[commid][busadd].UNSAVED = 0x00;
  396. }
  397. }
  398. qry.clear();
  399. qry = recdb.exec("select Id, channel, code, time, note from yt_rec_report where sent=0");
  400. while(qry.next()){
  401. Msg msg;
  402. msg.ID = qry.value(0).toString();
  403. msg.MSG = QString("key=%1&json={\"jsonrpc\":\"2.0\",\"id\":\"%2\",\"method\":\"addEvent\",\"params\":{\"deviceId\":\"%2\",\"channel\":%3,\"triggerTime\":\"%4\",\"eventCode\":%5,\"note\":\"%6\"}}")
  404. .arg(Skey).arg(Sid).arg(qry.value(1).toInt())
  405. .arg(QDateTime::fromTime_t(qry.value(3).toUInt()).toString("yyyy-MM-dd HH:mm:ss"))
  406. .arg(qry.value(2).toInt()).arg(qry.value(4).toString());
  407. sender->appendMsg(msg);
  408. }
  409. }
  410. bool BpCore::shm_load()
  411. {
  412. int shmid;
  413. key_t key;
  414. if((key = ftok(SHM_PATH,(int)SHM_PORT))==-1)
  415. return false;
  416. if((shmid = shmget(key,sizeof(YT_UNIT_SHM),IPC_CREAT|0666))==-1)
  417. return false;
  418. ytShm = (YT_UNIT_SHM *)shmat(shmid,NULL,0);
  419. shm_init();
  420. return true;
  421. }