|
|
|
@ -1418,6 +1418,7 @@ bool bSetPointTableValueYC(float v, unsigned int adr)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool bSetPointTableValueYC(const std::vector<IEC_OBJVAL_NEW>& values)
|
|
|
|
|
{
|
|
|
|
|
// Save the origin data into database first
|
|
|
|
@ -1426,109 +1427,116 @@ bool bSetPointTableValueYC(const std::vector<IEC_OBJVAL_NEW>& values)
|
|
|
|
|
addOriginDataListNew(*it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string tableName;
|
|
|
|
|
std::string dtimeFildName;
|
|
|
|
|
std::string devidFildName;
|
|
|
|
|
unsigned int devId = 0;
|
|
|
|
|
bool one_dtime = true;
|
|
|
|
|
time_t ts = 0;
|
|
|
|
|
std::map<unsigned int, IEC_POINT>::const_iterator itPoint;
|
|
|
|
|
std::map<unsigned int, IEC_DEVICE>::const_iterator itDev;
|
|
|
|
|
std::string fields, fieldValues;
|
|
|
|
|
|
|
|
|
|
char dataBuf[32] = { 0 };
|
|
|
|
|
mutex_lock(g_map_iec_mutex_new);
|
|
|
|
|
for (std::vector<IEC_OBJVAL_NEW>::const_iterator it = values.begin(); it != values.end(); ++it)
|
|
|
|
|
if (g_TConfig.shouldParseBusiData() != 0)
|
|
|
|
|
{
|
|
|
|
|
itPoint = g_map_iec_new.find(it->sadr);
|
|
|
|
|
if (itPoint != g_map_iec_new.end())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
itDev = g_map_devices.find(itPoint->second.sensor_id);
|
|
|
|
|
if (itDev != g_map_devices.end())
|
|
|
|
|
time_t ts = 0;
|
|
|
|
|
std::map<unsigned int, IEC_POINT>::const_iterator itPoint;
|
|
|
|
|
std::map<unsigned int, IEC_DEVICE>::const_iterator itDev;
|
|
|
|
|
std::string fields, fieldValues;
|
|
|
|
|
|
|
|
|
|
std::map<unsigned int, std::vector<IEC_FIELD> > records;
|
|
|
|
|
std::map<unsigned int, std::vector<IEC_FIELD> >::iterator itRecord;
|
|
|
|
|
std::vector<IEC_FIELD>::iterator itField;
|
|
|
|
|
|
|
|
|
|
char dataBuf[32] = { 0 };
|
|
|
|
|
IEC_FIELD field;
|
|
|
|
|
mutex_lock(g_map_iec_mutex_new);
|
|
|
|
|
for (std::vector<IEC_OBJVAL_NEW>::const_iterator it = values.begin(); it != values.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!tableName.empty())
|
|
|
|
|
{
|
|
|
|
|
tableName = (const char *)itDev->second.tableName;
|
|
|
|
|
dtimeFildName = (const char *)itDev->second.dtimeFieldName;
|
|
|
|
|
devidFildName = (const char *)itDev->second.devidFieldName;
|
|
|
|
|
devId = itDev->second.sensor_id;
|
|
|
|
|
one_dtime = (itDev->second.one_dtime != 0);
|
|
|
|
|
ts = it->dtime;
|
|
|
|
|
|
|
|
|
|
vPrtLogMsg(LOG_DEBUG, RET_OK, "Table: %s oneTime=%u", tableName.c_str(), (unsigned int)itDev->second.one_dtime);
|
|
|
|
|
if (tableName.empty())
|
|
|
|
|
itPoint = g_map_iec_new.find(it->sadr);
|
|
|
|
|
if (itPoint == g_map_iec_new.end() || strlen((const char*)itPoint->second.fieldName) == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
itRecord = records.find(itPoint->second.sensor_id);
|
|
|
|
|
if (itRecord == records.end())
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
itRecord = records.insert(records.end(), std::make_pair<>(itPoint->second.sensor_id, std::vector<IEC_FIELD>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
field.name = (const char*)itPoint->second.fieldName;
|
|
|
|
|
field.ts = it->dtime;
|
|
|
|
|
field.value = it->fval;
|
|
|
|
|
|
|
|
|
|
itRecord->second.push_back(field);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
std::string sql;
|
|
|
|
|
for (itRecord = records.begin(); itRecord != records.end(); ++itRecord)
|
|
|
|
|
{
|
|
|
|
|
if (tableName.compare((const char *)itDev->second.tableName) != 0)
|
|
|
|
|
itDev = g_map_devices.find(itRecord->first);
|
|
|
|
|
if (itDev == g_map_devices.end() || strlen((const char*)itDev->second.tableName) == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fields.append((const char *)itPoint->second.fieldName);
|
|
|
|
|
fields.append(",");
|
|
|
|
|
|
|
|
|
|
fieldValues.append("'");
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%0.4f", it->fval);
|
|
|
|
|
fieldValues.append(dataBuf);
|
|
|
|
|
fieldValues.append("',");
|
|
|
|
|
fields.clear();
|
|
|
|
|
fieldValues.clear();
|
|
|
|
|
sql.clear();
|
|
|
|
|
|
|
|
|
|
if (!one_dtime)
|
|
|
|
|
{
|
|
|
|
|
fields.append((const char *)itPoint->second.fieldName);
|
|
|
|
|
fields.append("_time,");
|
|
|
|
|
for (itField = itRecord->second.begin(); itField != itRecord->second.end(); ++itField)
|
|
|
|
|
{
|
|
|
|
|
ts = itField->ts;
|
|
|
|
|
fields.append(itField->name);
|
|
|
|
|
fields.append(",");
|
|
|
|
|
|
|
|
|
|
fieldValues.append("FROM_UNIXTIME(");
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%lld", (long long)it->dtime);
|
|
|
|
|
fieldValues.append(dataBuf);
|
|
|
|
|
fieldValues.append("),");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mutex_unlock(g_map_iec_mutex_new);
|
|
|
|
|
fieldValues.append("'");
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%0.4f", itField->value);
|
|
|
|
|
fieldValues.append(dataBuf);
|
|
|
|
|
fieldValues.append("',");
|
|
|
|
|
|
|
|
|
|
if (!tableName.empty())
|
|
|
|
|
{
|
|
|
|
|
// Assume they belongs the same object
|
|
|
|
|
std::string sql = "INSERT INTO ";
|
|
|
|
|
sql.append(tableName);
|
|
|
|
|
sql.append("(");
|
|
|
|
|
sql.append(devidFildName);
|
|
|
|
|
sql.append(",");
|
|
|
|
|
if ((itDev->second.one_dtime == 0))
|
|
|
|
|
{
|
|
|
|
|
fields.append((const char *)itPoint->second.fieldName);
|
|
|
|
|
fields.append("_time,");
|
|
|
|
|
|
|
|
|
|
fieldValues.append("FROM_UNIXTIME(");
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%lld", (long long)ts);
|
|
|
|
|
fieldValues.append(dataBuf);
|
|
|
|
|
fieldValues.append("),");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql.append(fields, 0, fields.size() - 1);
|
|
|
|
|
sql.append(" VALUES(");
|
|
|
|
|
sql = "INSERT INTO ";
|
|
|
|
|
sql.append((const char *)itDev->second.tableName);
|
|
|
|
|
sql.append("(");
|
|
|
|
|
sql.append((const char *)itDev->second.devidFieldName);
|
|
|
|
|
sql.append(",");
|
|
|
|
|
if (itDev->second.one_dtime != 0)
|
|
|
|
|
{
|
|
|
|
|
sql.append((const char *)itDev->second.dtimeFieldName);
|
|
|
|
|
sql.append(",");
|
|
|
|
|
}
|
|
|
|
|
sql.append(fields, 0, fields.size() - 1);
|
|
|
|
|
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%u", devId);
|
|
|
|
|
sql.append(dataBuf);
|
|
|
|
|
sql.append(",");
|
|
|
|
|
sql.append(") VALUES(");
|
|
|
|
|
|
|
|
|
|
if (one_dtime)
|
|
|
|
|
{
|
|
|
|
|
sql.append("FROM_UNIXTIME(");
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%lld", (long long)ts);
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%u", itDev->second.sensor_id);
|
|
|
|
|
sql.append(dataBuf);
|
|
|
|
|
sql.append("),");
|
|
|
|
|
}
|
|
|
|
|
sql.append(",");
|
|
|
|
|
if (itDev->second.one_dtime != 0)
|
|
|
|
|
{
|
|
|
|
|
sql.append("FROM_UNIXTIME(");
|
|
|
|
|
snprintf(dataBuf, sizeof(dataBuf), "%lld", (long long)ts);
|
|
|
|
|
sql.append(dataBuf);
|
|
|
|
|
sql.append("),");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql.append(fieldValues, 0, fieldValues.size() - 1);
|
|
|
|
|
sql.append(")");
|
|
|
|
|
sql.append(fieldValues, 0, fieldValues.size() - 1);
|
|
|
|
|
sql.append(")");
|
|
|
|
|
|
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
mutex_lock(g_list_busi_data_mutex);
|
|
|
|
|
it = g_list_busi_data.insert(g_list_busi_data.end(), std::string());
|
|
|
|
|
it->swap(sql);
|
|
|
|
|
mutex_unlock(g_list_busi_data_mutex);
|
|
|
|
|
}
|
|
|
|
|
vPrtLogMsg(LOG_DEBUG, RET_OK, "Insert busi data %s", sql.c_str());
|
|
|
|
|
|
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
mutex_lock(g_list_busi_data_mutex);
|
|
|
|
|
it = g_list_busi_data.insert(g_list_busi_data.end(), std::string());
|
|
|
|
|
it->swap(sql);
|
|
|
|
|
mutex_unlock(g_list_busi_data_mutex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mutex_unlock(g_map_iec_mutex_new);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
IEC_OBJVAL_NEW objVal = { 0 };
|
|
|
|
|
objVal.stype = 2;
|
|
|
|
|