| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include "stdafx.h"
- #include "315ClientManager.h"
- #include <spdlog-1.10.0/spdlog/spdlog.h>
- bool g_b315;
- C315ClientManager::C315ClientManager()
- {
- m_lptlManageFrame = NULL;
- }
- C315ClientManager::~C315ClientManager()
- {
- if (m_lptlManageFrame)
- {
- delete m_lptlManageFrame;
- }
- }
- bool C315ClientManager::Run(CString strIniPath)
- {
- TIEDA_ACQ_VALUE acq = {0, TIEDA_VAL_STATE::TVS_AFTER_MOVE};
- //读取配置
- ::GetPrivateProfileStringA("315", "server_ip", "", m_szServerIP, sizeof(m_szServerIP), strIniPath);
- m_dwServerPort = ::GetPrivateProfileInt("315", "server_port", 0, strIniPath);
- int nLogLen = ::GetPrivateProfileInt("315", "log_msg_maxlen", 50, strIniPath);//报文长度
- int ver = GetPrivateProfileInt("315", "CSMCmdRegion_DataVersion", 1, strIniPath);
- if (m_szServerIP[0x00] == 0x00 || m_dwServerPort == 0)
- return false;
- if (m_lptlManageFrame)
- {
- delete m_lptlManageFrame;
- }
- m_lptlManageFrame = new CCSM315Protocol(ver);
- m_tcpSocket.m_nLogMsgMaxLen = nLogLen;
- if (!m_tcpSocket.Connect(m_szServerIP, m_dwServerPort))
- {
- DWORD dwErr = GetLastError();
- SPDLOG_ERROR("[315]链接TCP链路失败:{}:{}=>[err:%d]", m_szServerIP, m_dwServerPort, dwErr);
- //return false;
- }
- else
- {
- SPDLOG_ERROR("[315]链接TCP链路成功:{}:{}", m_szServerIP, m_dwServerPort);
- }
- g_b315 = true;
- return true;
- }
- void C315ClientManager::Stop()
- {
- m_tcpSocket.Close();
- }
- void C315ClientManager::SendToServer(LPBYTE pPack, int nPackLen, E_315_PROTOCOL_TYPE protocol, uint8_t no)
- {
- if (g_b315 == false) return;
- m_tcpSocket.Insert(pPack, nPackLen, protocol, no);
- }
|