ded4788bfe9f3186979dab7cde0f94142e6d35a2.svn-base 21 KB

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