|
|
@ -398,6 +398,8 @@ static void vLoadIECPointTableNew()
|
|
|
|
IEC_POINT stPoint;
|
|
|
|
IEC_POINT stPoint;
|
|
|
|
IEC_DEVICE stSensor;
|
|
|
|
IEC_DEVICE stSensor;
|
|
|
|
size_t idx = 0;
|
|
|
|
size_t idx = 0;
|
|
|
|
|
|
|
|
map<unsigned int, CACHED_DEV_DATA>::iterator itCachedDev;
|
|
|
|
|
|
|
|
map<unsigned int, IEC_DEVICE>::iterator itDev;
|
|
|
|
while (row = pdbHandle->GetRecord(res))
|
|
|
|
while (row = pdbHandle->GetRecord(res))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
memset(&stPoint, 0x00, sizeof(IEC_POINT));
|
|
|
|
memset(&stPoint, 0x00, sizeof(IEC_POINT));
|
|
|
@ -453,13 +455,141 @@ static void vLoadIECPointTableNew()
|
|
|
|
// vPrtLogMsg(LOG_WARNG, RET_OK, "----TABLE %s oneTime=%u", (const char*)stSensor.tableName, (unsigned int)stSensor.one_dtime);
|
|
|
|
// vPrtLogMsg(LOG_WARNG, RET_OK, "----TABLE %s oneTime=%u", (const char*)stSensor.tableName, (unsigned int)stSensor.one_dtime);
|
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(g_map_iec_mutex_new);
|
|
|
|
mutex_lock(g_map_iec_mutex_new);
|
|
|
|
|
|
|
|
itDev = g_map_devices.find(stSensor.sensor_id);
|
|
|
|
|
|
|
|
if (itDev == g_map_devices.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
itDev = g_map_devices.insert(g_map_devices.end(), std::make_pair<>(stSensor.sensor_id, stSensor));
|
|
|
|
|
|
|
|
}
|
|
|
|
g_map_devices[stSensor.sensor_id] = stSensor;
|
|
|
|
g_map_devices[stSensor.sensor_id] = stSensor;
|
|
|
|
g_map_iec_new[stPoint.sadr] = stPoint;
|
|
|
|
g_map_iec_new[stPoint.sadr] = stPoint;
|
|
|
|
|
|
|
|
itCachedDev = g_map_dev_data.find(stSensor.sensor_id);
|
|
|
|
|
|
|
|
if (itCachedDev == g_map_dev_data.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CACHED_DEV_DATA cachedData;
|
|
|
|
|
|
|
|
cachedData.device = &(itDev->second);
|
|
|
|
|
|
|
|
cachedData.firstTs = 0;
|
|
|
|
|
|
|
|
cachedData.assignedFields = 0;
|
|
|
|
|
|
|
|
itCachedDev = g_map_dev_data.insert(g_map_dev_data.end(), std::make_pair<>(stSensor.sensor_id, cachedData));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEC_FIELD stField;
|
|
|
|
|
|
|
|
stField.name = (const char*)stPoint.fieldName;
|
|
|
|
|
|
|
|
stField.ts = 0;
|
|
|
|
|
|
|
|
stField.fval = 0.0;
|
|
|
|
|
|
|
|
itCachedDev->second.fields[stPoint.sadr] = std::make_pair<>(stField, false);
|
|
|
|
mutex_unlock(g_map_iec_mutex_new);
|
|
|
|
mutex_unlock(g_map_iec_mutex_new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pdbHandle->FreeRecord(res);
|
|
|
|
pdbHandle->FreeRecord(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ResetCachedDeviceData()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
map<unsigned int, CACHED_DEV_DATA>::iterator it;
|
|
|
|
|
|
|
|
std::map<unsigned int, std::pair<IEC_FIELD, bool> >::iterator itField;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(g_map_iec_mutex_new);
|
|
|
|
|
|
|
|
for (it = g_map_dev_data.begin(); it != g_map_dev_data.end(); ++it)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
it->second.firstTs = 0;
|
|
|
|
|
|
|
|
it->second.assignedFields = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (itField = it->second.fields.begin(); itField != it->second.fields.end(); ++itField)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
itField->second.first.ts = 0;
|
|
|
|
|
|
|
|
itField->second.first.fval = 0.0;
|
|
|
|
|
|
|
|
itField->second.second = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(g_map_iec_mutex_new);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string BuildSqlForDeviceData(CACHED_DEV_DATA& cachedDev)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string fields, fieldValues, sql;
|
|
|
|
|
|
|
|
char dataBuf[32] = { 0 };
|
|
|
|
|
|
|
|
#if __cplusplus < 201103L
|
|
|
|
|
|
|
|
std::map<unsigned int, std::pair<IEC_FIELD, bool> >::iterator it;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (it = cachedDev.fields.begin(); it != cachedDev.fields.end(); ++it)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
std::map<unsigned int, std::pair<IEC_FIELD, bool> >::const_iterator it;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (it = cachedDev.fields.cbegin(); it != cachedDev.fields.cend(); ++it)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fields.append(it->second.first.name);
|
|
|
|
|
|
|
|
fields.append(",");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldValues.append("'");
|
|
|
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%0.4f", it->second.first.fval);
|
|
|
|
|
|
|
|
fieldValues.append(dataBuf);
|
|
|
|
|
|
|
|
fieldValues.append("',");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((cachedDev.device->one_dtime == 0))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fields.append(it->second.first.name);
|
|
|
|
|
|
|
|
fields.append("_time,");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldValues.append("FROM_UNIXTIME(");
|
|
|
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%lld", (long long)it->second.first.ts);
|
|
|
|
|
|
|
|
fieldValues.append(dataBuf);
|
|
|
|
|
|
|
|
fieldValues.append("),");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql = "INSERT INTO ";
|
|
|
|
|
|
|
|
sql.append((const char *)cachedDev.device->tableName);
|
|
|
|
|
|
|
|
sql.append("(");
|
|
|
|
|
|
|
|
sql.append((const char *)cachedDev.device->devidFieldName);
|
|
|
|
|
|
|
|
sql.append(",");
|
|
|
|
|
|
|
|
if (cachedDev.device->one_dtime != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sql.append((const char *)cachedDev.device->dtimeFieldName);
|
|
|
|
|
|
|
|
sql.append(",");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sql.append(fields, 0, fields.size() - 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql.append(") VALUES(");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%u", cachedDev.device->sensor_id);
|
|
|
|
|
|
|
|
sql.append(dataBuf);
|
|
|
|
|
|
|
|
sql.append(",");
|
|
|
|
|
|
|
|
if (cachedDev.device->one_dtime != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sql.append("FROM_UNIXTIME(");
|
|
|
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%lld", (long long)cachedDev.firstTs);
|
|
|
|
|
|
|
|
sql.append(dataBuf);
|
|
|
|
|
|
|
|
sql.append("),");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql.append(fieldValues, 0, fieldValues.size() - 1);
|
|
|
|
|
|
|
|
sql.append(")");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sql;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AssignValueToDeviceData(CACHED_DEV_DATA& cachedDev, const IEC_OBJVAL_NEW& val)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::map<unsigned int, std::pair<IEC_FIELD, bool> >::iterator it = cachedDev.fields.find(val.sadr);
|
|
|
|
|
|
|
|
if (it != cachedDev.fields.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!(it->second.second))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cachedDev.firstTs == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cachedDev.firstTs = val.dtime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedDev.assignedFields++;
|
|
|
|
|
|
|
|
it->second.first.fval = val.fval;
|
|
|
|
|
|
|
|
it->second.first.ts = val.dtime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 刷新设备更新时间
|
|
|
|
// 刷新设备更新时间
|
|
|
|
void SethDevTimeStat(unsigned char *sys_code, unsigned char ws)
|
|
|
|
void SethDevTimeStat(unsigned char *sys_code, unsigned char ws)
|
|
|
|
{
|
|
|
|
{
|
|
|
|