158 lines
7.3 KiB
C++
158 lines
7.3 KiB
C++
#include "CommunicationCfg.h"
|
|
#include "../utils/StringHelper.h"
|
|
|
|
CommunicationCfg::CommunicationCfg()
|
|
: m_MachineId(new IntData("MachineId", u8"", 0))
|
|
, m_ClientCode(new StrData("ClientCode", u8"", ""))
|
|
, m_Name(new StrData("Name"))
|
|
, m_Type(new IntData("Type", u8"", COM))
|
|
, m_IP(new StrData("IP", u8"IP", "0.0.0.0"))
|
|
, m_Port(new IntData("Port", u8"port", 10000))
|
|
, m_Addr(new UcharData("Addr", u8"Addr", 1))
|
|
, m_COM(new StrData("COM", u8"COM", "COM1"))
|
|
, m_BaudRate(new IntData("BaudRate", u8"波特率", 9600))
|
|
, m_Parity(new IntData("Parity"))
|
|
, m_DataBits(new IntData("DataBits", u8"", 8))
|
|
, m_StopBits(new IntData("StopBits", u8"", 1))
|
|
, m_Interval(new UIntData("Interval", u8"", 1000))
|
|
, m_AlarmTimeoutTimes(new UIntData("AlarmTimeoutTimes", u8"", 3))
|
|
, m_Enable(new BoolData("Enable", u8"", false))
|
|
, m_szIp(new StrData("szIp"))
|
|
, m_szCom(new StrData("szCom"))
|
|
, m_ShowContent(new StrData("ShowContent", u8""))
|
|
{
|
|
}
|
|
|
|
CommunicationCfg::CommunicationCfg(int mid, string cc, string name, const string& sContent, int type)
|
|
: m_MachineId(new IntData("MachineId",u8"",mid))
|
|
, m_ClientCode(new StrData("ClientCode",u8"编码",cc))
|
|
, m_Name(new StrData("Name",u8"",name))
|
|
, m_Type(new IntData("Type",u8"",type))
|
|
, m_IP(new StrData("IP", u8"IP", "0.0.0.0"))
|
|
, m_Port(new IntData("Port", u8"port", 10000))
|
|
, m_Addr(new UcharData("Addr",u8"Addr", 1))
|
|
, m_COM(new StrData("COM", u8"COM", "COM1"))
|
|
, m_BaudRate(new IntData("BaudRate", u8"波特率", 9600))
|
|
, m_Parity(new IntData("Parity"))
|
|
, m_DataBits(new IntData("DataBits",u8"", 8))
|
|
, m_StopBits(new IntData("StopBits", u8"",1))
|
|
, m_Interval(new UIntData("Interval", u8"", 1000))
|
|
, m_AlarmTimeoutTimes(new UIntData("AlarmTimeoutTimes", u8"",3))
|
|
, m_Enable(new BoolData("Enable", u8"",true))
|
|
, m_szIp(new StrData("szIp"))
|
|
, m_szCom(new StrData("szCom"))
|
|
, m_ShowContent(new StrData("ShowContent", u8"", sContent))
|
|
{
|
|
size_t ptrSize = sizeof(nullptr); //指针大小
|
|
void* startPtr = &m_startFlag + 1;
|
|
size_t count = ((size_t)&m_endFlag - (size_t)startPtr) / ptrSize;
|
|
InsertMp(startPtr, count,"_"+ cc);
|
|
}
|
|
|
|
void CommunicationCfg::GetUpdateSql(vector<string>& ups)
|
|
{
|
|
char buffer[512];
|
|
string sql = "UPDATE " + TABLE_NAME + " SET " + FIELD_PARAM_VALUE + "='%s' WHERE " + FIELD_MACHINE_ID + "=%d AND " + FIELD_PARAM_CODE + "='%s' AND " + FIELD_CLIENT_CODE + "='" + m_ClientCode->GetValueStr() + "'";
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), m_Name->GetValueStr().c_str(), m_MachineId->GetValue(), PARAM_NAME.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_Type->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_TYPE.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), m_IP->GetValueStr().c_str(), m_MachineId->GetValue(), PARAM_IP.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_Port->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_PORT.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_Addr->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_ADDR.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), m_COM->GetValueStr().c_str(), m_MachineId->GetValue(), PARAM_COM.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_BaudRate->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_BAUD_RATE.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_DataBits->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_DATABITS.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_StopBits->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_STOPBITS.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_Interval->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_INTERVAL.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), to_string(m_AlarmTimeoutTimes->GetValue()).c_str(), m_MachineId->GetValue(), PARAM_ALARM_TIMEOUT_TIMES.c_str());
|
|
ups.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), m_Enable->GetValue() ? "1" : "0", m_MachineId->GetValue(), PARAM_ENABLE.c_str());
|
|
ups.push_back(buffer);
|
|
}
|
|
|
|
void CommunicationCfg::GetInitInsertSql(vector<string>& ins)
|
|
{
|
|
char buffer[512];
|
|
string sql = "INSERT INTO " + TABLE_NAME + "(" + FIELD_MACHINE_ID + "," + FIELD_CLIENT_CODE + "," + FIELD_PARAM_CODE + "," + FIELD_PARAM_VALUE + ") VALUES(" + to_string(m_MachineId->GetValue()) + "," + m_ClientCode->GetValueStr() + ",'%s','%s'";
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_NAME.c_str(), m_Name->GetValueStr().c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_TYPE.c_str(), to_string(m_Type->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_IP.c_str(), m_IP->GetValueStr().c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_PORT.c_str(), to_string(m_Port->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_ADDR.c_str(), to_string(m_Addr->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_COM.c_str(), m_COM->GetValueStr().c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_BAUD_RATE.c_str(), to_string(m_BaudRate->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_PARITY.c_str(), to_string(m_Parity->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_DATABITS.c_str(), to_string(m_DataBits->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_STOPBITS.c_str(), to_string(m_StopBits->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_INTERVAL.c_str(), to_string(m_Interval->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_ALARM_TIMEOUT_TIMES.c_str(), to_string(m_AlarmTimeoutTimes->GetValue()).c_str());
|
|
ins.push_back(buffer);
|
|
|
|
sprintf_s(buffer, sizeof(buffer), sql.c_str(), PARAM_ENABLE.c_str(), m_Enable->GetValue() ? "1" : "0");
|
|
ins.push_back(buffer);
|
|
}
|
|
|
|
const string CommunicationCfg::TABLE_NAME = "CommunicationCfg";
|
|
const string CommunicationCfg::FIELD_MACHINE_ID = "MachineId";
|
|
const string CommunicationCfg::FIELD_CLIENT_CODE = "ClientCode";
|
|
const string CommunicationCfg::FIELD_PARAM_CODE = "ParamCode";
|
|
const string CommunicationCfg::FIELD_PARAM_VALUE = "ParamValue";
|
|
|
|
const string CommunicationCfg::PARAM_NAME = "Name";
|
|
const string CommunicationCfg::PARAM_TYPE = "Type";
|
|
const string CommunicationCfg::PARAM_IP = "IP";
|
|
const string CommunicationCfg::PARAM_PORT = "Port";
|
|
const string CommunicationCfg::PARAM_ADDR = "Addr";
|
|
const string CommunicationCfg::PARAM_COM = "Com";
|
|
const string CommunicationCfg::PARAM_BAUD_RATE = "BaudRate";
|
|
const string CommunicationCfg::PARAM_PARITY = "Parity";
|
|
const string CommunicationCfg::PARAM_DATABITS = "Databits";
|
|
const string CommunicationCfg::PARAM_STOPBITS = "Stopbits";
|
|
const string CommunicationCfg::PARAM_INTERVAL = "Interval";
|
|
const string CommunicationCfg::PARAM_ALARM_TIMEOUT_TIMES = "AlarmTimeoutTimes";
|
|
const string CommunicationCfg::PARAM_ENABLE = "enable";
|