From df1725177b16d43e3467f51ec1281f60db92a33a Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Sat, 18 Nov 2023 17:24:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=E5=86=85=E5=AD=98=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MySQLAdo.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/MySQLAdo.cpp b/src/MySQLAdo.cpp index 096e615..4285568 100644 --- a/src/MySQLAdo.cpp +++ b/src/MySQLAdo.cpp @@ -219,6 +219,8 @@ bool LoadIecPoints() g_iec_points.push_back(pt); } + + printf("IEC Points: %lld\n", (long long)g_iec_points.size()); } #endif @@ -249,10 +251,9 @@ int GetAIPntMsg(int j, unsigned int *igno, unsigned int* iItemNo, DAY_TIME* sCur } char buf[16] = { 0 }; - sprintf(buf, "%u", pt.sadr); - std::string sql = "SELECT sadr,state,stype,ival,fval,d_time FROM niec_origin_data WHERE sadr="; + snprintf(buf, sizeof(buf), "%u", pt.sadr); + std::string sql = "SELECT sadr,state,stype,ival,fval,d_time FROM niec_latest_org_data WHERE sadr="; sql += buf; - sql += " ORDER BY `id` DESC LIMIT 1"; if (mysql_query(mysql, sql.c_str())) { @@ -273,7 +274,17 @@ int GetAIPntMsg(int j, unsigned int *igno, unsigned int* iItemNo, DAY_TIME* sCur if (igno != NULL) *igno = pt.sensorGroupNo; if (iItemNo != NULL) *iItemNo = pt.itemNo; if (iaddr != NULL) *iaddr = pt.sensorId; - if (pfValue != NULL) *pfValue = atof(row[4]); + if (pfValue != NULL) + { + if (row[4] != NULL && strlen(row[4]) > 0) + { + *pfValue = atof(row[4]); + } + else + { + *pfValue = 0.0f; + } + } if (sCurTime != NULL && row[5] != NULL) { sscanf(row[5], "%04d-%02d-%2d %02d:%02d:%02d", &year, &mon, &day, &hour, &min, &sec);