|
@@ -72,19 +72,22 @@ CSATClient::~CSATClient(void)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-bool CSATClient::OnSend(const byte* pData, int nLen)
|
|
|
+bool CSATClient::OnSend(const byte* pData, int nLen, BOOL bShowGif)
|
|
|
{
|
|
|
if (!m_bSocket) {
|
|
|
if (!Start())
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- CDlgProBar dlg;
|
|
|
- g_pDlgProBar = &dlg;
|
|
|
DWORD dwLen = m_SocketClient.Write((const LPBYTE)pData, nLen);
|
|
|
if (dwLen == nLen)
|
|
|
{
|
|
|
- dlg.DoModal();
|
|
|
+ if (bShowGif) {
|
|
|
+ CDlgProBar dlg;
|
|
|
+ g_pDlgProBar = &dlg;
|
|
|
+ dlg.DoModal();
|
|
|
+ }
|
|
|
+
|
|
|
OutputDebugString(_T("发送数据成功!\n"));
|
|
|
return true;
|
|
|
}
|
|
@@ -267,10 +270,22 @@ void CSATClient::TaskProcess(SATProtocol::Package* pak)
|
|
|
}
|
|
|
break;
|
|
|
case SATProtocol::CMD_ADD_DEVICE:
|
|
|
- break;
|
|
|
case SATProtocol::CMD_DEL_DEVICE:
|
|
|
+ {
|
|
|
+ // 无须处理返回值;
|
|
|
+ }
|
|
|
break;
|
|
|
case SATProtocol::CMD_QUERY_DEVICES:
|
|
|
+ {
|
|
|
+ SATProtocol::DeviceResp* resp = (SATProtocol::DeviceResp*)pak->buf;
|
|
|
+ //SATData::device_resp.nSize = resp->nSize;
|
|
|
+ //memcpy(SATData::device_resp.szDevs, resp->szDevs, 30*MAX_PATH);
|
|
|
+ SATData::devices.clear();
|
|
|
+ for (size_t i = 0; i < resp->nSize; i++)
|
|
|
+ {
|
|
|
+ SATData::devices.push_back(resp->szDevs[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
@@ -281,7 +296,7 @@ void CSATClient::TaskProcess(SATProtocol::Package* pak)
|
|
|
BOOL CSATClient::Start()
|
|
|
{
|
|
|
int nFamily = (m_nMode == AF_IPV4) ? AF_INET : AF_INET6;
|
|
|
- if (!m_SocketClient.StartClient(NULL, Global::g_Config.strServiceIP.c_str(), Global::g_Config.strSATPassword.c_str(), nFamily, (m_nSockType + 1)))
|
|
|
+ if (!m_SocketClient.StartClient(NULL, Global::g_Config.strServiceIP.c_str(), Global::g_Config.strServicePort.c_str(), nFamily, (m_nSockType + 1)))
|
|
|
{
|
|
|
#ifdef _DEBUG
|
|
|
OutputDebugString("连接服务器失败\n");
|
|
@@ -335,7 +350,7 @@ void CSATClient::GetAddress(const SockAddrIn& addrIn, CString& rString) const
|
|
|
rString.Format(_T("%s : %d"), szIPAddr, static_cast<int>(static_cast<UINT>(ntohs(addrIn.GetPort()))));
|
|
|
}
|
|
|
|
|
|
-bool CSATClient::TCPLogin(std::string strUserName, std::string strPassword, BOOL bLogin)
|
|
|
+bool CSATClient::TCPLogin(std::string strUserName, std::string strPassword, std::string strActuator, BOOL bLogin, BOOL bShowGif )
|
|
|
{
|
|
|
SATData::login_resp = {0};
|
|
|
int len = HEADER_LEN + sizeof(SATProtocol::UserInfo);
|
|
@@ -350,14 +365,57 @@ bool CSATClient::TCPLogin(std::string strUserName, std::string strPassword, BOOL
|
|
|
SATProtocol::UserInfo* pUserInfo = (SATProtocol::UserInfo*)pData->buf;
|
|
|
memcpy(pUserInfo->szUserName, strUserName.c_str(), strUserName.size());
|
|
|
memcpy(pUserInfo->szPassword, strPassword.c_str(), strPassword.size());
|
|
|
+ memcpy(pUserInfo->szActuatorName, strActuator.c_str(), strActuator.size());
|
|
|
|
|
|
- bool bret = OnSend(pbuff, len);
|
|
|
+ bool bret = OnSend(pbuff, len, bShowGif);
|
|
|
delete[]pbuff;
|
|
|
|
|
|
return bret;
|
|
|
}
|
|
|
|
|
|
-bool CSATClient::TCPLogout(std::string strUserName, std::string strPassword)
|
|
|
+bool CSATClient::TCPLogout(std::string strUserName, std::string strPassword, std::string strActuator, BOOL bShowGif)
|
|
|
+{
|
|
|
+ return TCPLogin(strUserName, strPassword, strActuator, FALSE, bShowGif);
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATClient::TCPAddDevice(std::string strDevice, bool bDel, BOOL bShowGif)
|
|
|
+{
|
|
|
+ int len = HEADER_LEN + MAX_PATH;
|
|
|
+ byte* pbuff = new byte[len];
|
|
|
+ memset(pbuff, 0, len);
|
|
|
+ SATProtocol::Package* pData = (SATProtocol::Package*)pbuff;
|
|
|
+
|
|
|
+ pData->header.protocol = 0xAA;
|
|
|
+ pData->header.len = len;
|
|
|
+ pData->header.cmd = bDel ? SATProtocol::CMD_DEL_DEVICE : SATProtocol::CMD_ADD_DEVICE;
|
|
|
+
|
|
|
+ // 赋值;
|
|
|
+ memcpy(pData->buf, strDevice.c_str(), strDevice.size());
|
|
|
+
|
|
|
+ bool bret = OnSend(pbuff, len, bShowGif);
|
|
|
+ delete[]pbuff;
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATClient::TCPDelDevice(std::string strDevice, BOOL bShowGif)
|
|
|
{
|
|
|
- return TCPLogin(strUserName, strPassword, FALSE);
|
|
|
+ return TCPAddDevice(strDevice, false, bShowGif);
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATClient::TCPQueryDevices(BOOL bShowGif)
|
|
|
+{
|
|
|
+ int len = HEADER_LEN;
|
|
|
+ byte* pbuff = new byte[len];
|
|
|
+ memset(pbuff, 0, len);
|
|
|
+ SATProtocol::Package* pData = (SATProtocol::Package*)pbuff;
|
|
|
+
|
|
|
+ pData->header.protocol = 0xAA;
|
|
|
+ pData->header.len = len;
|
|
|
+ pData->header.cmd = SATProtocol::CMD_QUERY_DEVICES;
|
|
|
+
|
|
|
+ bool bret = OnSend(pbuff, len, bShowGif);
|
|
|
+ delete[]pbuff;
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|