|
@@ -0,0 +1,357 @@
|
|
|
|
+// SATService.cpp : 定义控制台应用程序的入口点。
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
+#include "stdafx.h"
|
|
|
|
+#include "SATService.h"
|
|
|
|
+#include <direct.h>
|
|
|
|
+
|
|
|
|
+#ifdef _DEBUG
|
|
|
|
+#define new DEBUG_NEW
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+__if_not_exists(NotifyJobStart)
|
|
|
|
+{
|
|
|
|
+ int NotifyJobStart(std::string url, const SATParameters::STNotifyJobStartReq &stNotifyJobStartReq, SATParameters::STNotifyJobStartResp &stNotifyJobStartResp) throw()
|
|
|
|
+ {
|
|
|
|
+ return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+__if_not_exists(ProcessJob)
|
|
|
|
+{
|
|
|
|
+ int ProcessJob(std::string url, const SATParameters::STJobProcessReq &stJobProcessReq, SATParameters::STJobProcessResp &stJobProcessResp) throw()
|
|
|
|
+ {
|
|
|
|
+ return SetResultList(url, stJobProcessReq, stJobProcessResp);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+// 唯一的应用程序对象
|
|
|
|
+
|
|
|
|
+CWinApp theApp;
|
|
|
|
+
|
|
|
|
+using namespace std;
|
|
|
|
+
|
|
|
|
+bool MKDIR(LPCTSTR dir)
|
|
|
|
+{
|
|
|
|
+ //////////////////////////////////////////////////////////////////////////
|
|
|
|
+ // 创建目录;
|
|
|
|
+ int nleft = 0;
|
|
|
|
+ int nIndex = -1;
|
|
|
|
+ std::string strdir = dir;
|
|
|
|
+ strdir = strdir.substr(0, strdir.find_last_of(_T("\\")));
|
|
|
|
+
|
|
|
|
+ if (strdir.at(strdir.size() - 1) != _T('\\'))
|
|
|
|
+ strdir.append(_T("\\"));
|
|
|
|
+
|
|
|
|
+ // 共享路径和硬盘盘符;
|
|
|
|
+ if (_tcscmp(strdir.substr(0, 2).c_str(), _T("\\\\")) == 0)
|
|
|
|
+ nleft = strdir.find_first_of(_T("\\"), 2) + 1; // 去除共享主机名;
|
|
|
|
+ else if (strdir.at(2) == _T('\\'))
|
|
|
|
+ nleft = 3;
|
|
|
|
+
|
|
|
|
+ do
|
|
|
|
+ {
|
|
|
|
+ nIndex = strdir.substr(nleft, -1).find_first_of(_T("\\"));
|
|
|
|
+
|
|
|
|
+ if (nIndex != string::npos)
|
|
|
|
+ {
|
|
|
|
+ if (_mkdir(strdir.substr(0, nIndex + nleft).c_str()) == -1 && (errno != EEXIST))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ nleft += nIndex + 1;
|
|
|
|
+ }
|
|
|
|
+ } while (nIndex != -1);
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
|
|
|
|
+{
|
|
|
|
+ int nRetCode = 0;
|
|
|
|
+
|
|
|
|
+ // 初始化 MFC 并在失败时显示错误
|
|
|
|
+ if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
|
|
|
|
+ {
|
|
|
|
+ // TODO: 更改错误代码以符合您的需要
|
|
|
|
+ _tprintf(_T("错误: MFC 初始化失败\n"));
|
|
|
|
+ nRetCode = 1;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ // TODO: 在此处为应用程序的行为编写代码。
|
|
|
|
+ //std::string host = "http://10.118.158.52:8580";//"http://10.118.158.198:8090";
|
|
|
|
+ std::string host = "http://10.118.158.198:8090";
|
|
|
|
+ SATParameters::STDevice stDevice;
|
|
|
|
+ stDevice.strStatus = "0";
|
|
|
|
+ stDevice.strDeviceSerial = "192.168.1.119:5555";
|
|
|
|
+ stDevice.strHardwareVersion = "MS6488";
|
|
|
|
+ stDevice.strManu = "MStar";
|
|
|
|
+ stDevice.strDeviceMac = "";
|
|
|
|
+ stDevice.strLastJobStartTime = "";
|
|
|
|
+ stDevice.strLastTimeBreak = "";
|
|
|
|
+ stDevice.strComments = "";
|
|
|
|
+ stDevice.strCPU = "";
|
|
|
|
+ stDevice.strSoftwareVersion = "1522659174";
|
|
|
|
+ stDevice.strPhoneNumber = "";
|
|
|
|
+ stDevice.strLastJobFinishTime = "";
|
|
|
|
+ stDevice.strMemory = "";
|
|
|
|
+ stDevice.strModel = "Generic Linux on tcl_ms6488_cn_64_n";
|
|
|
|
+ stDevice.strLastJob = "";
|
|
|
|
+ stDevice.strLastTimeConnected = "2019-12-16 10:16:01";
|
|
|
|
+ stDevice.strElectric = "";
|
|
|
|
+ // ##########################先登录##############################;
|
|
|
|
+ SATParameters::STLoginReq stLoginReq;
|
|
|
|
+ SATParameters::STLoginResp stLoginResp;
|
|
|
|
+ std::string url = host + "/btc_execute_se/ajaxInteractiveManage!executeLogin.action";
|
|
|
|
+ // 示例值;
|
|
|
|
+ stLoginReq.strUserName = "superAdmin";
|
|
|
|
+ stLoginReq.strStatus = "0";
|
|
|
|
+ stLoginReq.strDeleteStatus = "";
|
|
|
|
+ stLoginReq.strIP = "10.118.158.175";
|
|
|
|
+ stLoginReq.strStorage = "";
|
|
|
|
+ stLoginReq.strConnectTime = "";
|
|
|
|
+ stLoginReq.strExecuteName = "";
|
|
|
|
+ stLoginReq.strMAC = "40:16:7e:23:10:53";
|
|
|
|
+ stLoginReq.strDisconnectTime = "";
|
|
|
|
+ stLoginReq.strPassword = "123456";
|
|
|
|
+ stLoginReq.strCPU = "";
|
|
|
|
+
|
|
|
|
+ if ( !Login(url, stLoginReq, stLoginResp) )
|
|
|
|
+ {
|
|
|
|
+ system("pause");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ printf("登录返回:code=%s, msg=%s, str=%s, portCount=%d, companyid=%d, runnertoken=%s\n",
|
|
|
|
+ stLoginResp.strCode.c_str(),
|
|
|
|
+ stLoginResp.strMessage.c_str(),
|
|
|
|
+ stLoginResp.strStr.c_str(),
|
|
|
|
+ stLoginResp.nPortCount,
|
|
|
|
+ stLoginResp.nCompanyId,
|
|
|
|
+ stLoginResp.strRunnerToken.c_str()
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ while(true)
|
|
|
|
+ {
|
|
|
|
+ // ##########################更新设备信息##############################;
|
|
|
|
+ SATParameters::STUpdateDeviceReq stUpdateDeviceReq;
|
|
|
|
+ SATParameters::STUpdateDeviceResp stUpdateDeviceResp;
|
|
|
|
+ __if_not_exists(url)
|
|
|
|
+ {
|
|
|
|
+ std::string url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
|
|
|
|
+ }
|
|
|
|
+ __if_exists(url)
|
|
|
|
+ {
|
|
|
|
+ url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ stUpdateDeviceReq.strStatus = "0";
|
|
|
|
+ stUpdateDeviceReq.strUserName = "superAdmin";
|
|
|
|
+ stUpdateDeviceReq.strIP = "10.118.158.175";
|
|
|
|
+ stUpdateDeviceReq.strStorage = "228092536KB";
|
|
|
|
+ stUpdateDeviceReq.strRunnerName = "SAT-Admin";
|
|
|
|
+ stUpdateDeviceReq.strMAC = "40:16:7e:23:10:53";
|
|
|
|
+ stUpdateDeviceReq.strReportType = "1";
|
|
|
|
+ stUpdateDeviceReq.strStartTime = "2019-12-16 19:15:30";
|
|
|
|
+ stUpdateDeviceReq.strMemory = "8938544KB";
|
|
|
|
+ stUpdateDeviceReq.strEndTime = "";
|
|
|
|
+ stUpdateDeviceReq.strCPU = "24.7%";
|
|
|
|
+ stUpdateDeviceReq.devicelist.push_back(stDevice);
|
|
|
|
+
|
|
|
|
+ if ( UpdateDeviceMessage(url, stUpdateDeviceReq, stUpdateDeviceResp) )
|
|
|
|
+ {
|
|
|
|
+ printf("更新设备信息成功:code=%s, msg=%s, str=%s\n",
|
|
|
|
+ stLoginResp.strCode.c_str(),
|
|
|
|
+ stLoginResp.strMessage.c_str(),
|
|
|
|
+ stLoginResp.strStr.c_str());
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ printf("更新设备信息失败!\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // ##########################心跳包机制##############################;
|
|
|
|
+ SATParameters::STHeartbeatReq stHeartbeatReq;
|
|
|
|
+ SATParameters::STHeartbeatResp stHeartbeatResp;
|
|
|
|
+ __if_not_exists(url)
|
|
|
|
+ {
|
|
|
|
+ std::string url = host + "/btc_execute_se/ajaxInteractiveManage!executeHeartbeat.action";
|
|
|
|
+ }
|
|
|
|
+ __if_exists(url)
|
|
|
|
+ {
|
|
|
|
+ url = host + "/btc_execute_se/ajaxInteractiveManage!executeHeartbeat.action";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 示例值;
|
|
|
|
+ //stDevice.strStatus = "0";
|
|
|
|
+ //stDevice.strDeviceSerial = "192.168.1.119:5555";
|
|
|
|
+
|
|
|
|
+ stHeartbeatReq.strUserName = "superAdmin";
|
|
|
|
+ stHeartbeatReq.strRunnerMac = "40:16:7e:23:10:53";
|
|
|
|
+ stHeartbeatReq.devicelist.push_back(stDevice);
|
|
|
|
+ if ( Heartbeat(url, stHeartbeatReq, stHeartbeatResp) )
|
|
|
|
+ {
|
|
|
|
+ printf("登录返回:code=%s, msg=%s, str=%s\n",
|
|
|
|
+ stHeartbeatResp.strCode.c_str(),
|
|
|
|
+ stHeartbeatResp.strMessage.c_str(),
|
|
|
|
+ stHeartbeatResp.strStr.c_str());
|
|
|
|
+
|
|
|
|
+ // 判断是否有任务获取成功;
|
|
|
|
+ if ( stHeartbeatResp.vtTask.size() )
|
|
|
|
+ {
|
|
|
|
+ // #########################################################################################
|
|
|
|
+ // 通知SAT变更任务状态;
|
|
|
|
+ SATParameters::STTask stTask = stHeartbeatResp.vtTask[0];
|
|
|
|
+ SATParameters::STNotifyJobStartReq stNotifyJobStartReq;
|
|
|
|
+ SATParameters::STNotifyJobStartResp stNotifyJobStartResp;
|
|
|
|
+
|
|
|
|
+ __if_not_exists(url)
|
|
|
|
+ {
|
|
|
|
+ std::string url = host + "/btc_execute_se/ajaxInteractiveManage!setResult.action";
|
|
|
|
+ }
|
|
|
|
+ __if_exists(url)
|
|
|
|
+ {
|
|
|
|
+ url = host + "/btc_execute_se/ajaxInteractiveManage!setResult.action";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TCHAR szValue[36] = {0};
|
|
|
|
+ _itoa_s(stTask.nDeviceId, szValue, 10);
|
|
|
|
+ stNotifyJobStartReq.strDeviceId = szValue;
|
|
|
|
+
|
|
|
|
+ _itoa_s(stTask.nExecuteId, szValue, 10);
|
|
|
|
+ stNotifyJobStartReq.strExecuteId = szValue;
|
|
|
|
+
|
|
|
|
+ // _itoa_s(stTask.nInstanceId, szValue, 10); // 误导:应该使用id而不是nInstanceId
|
|
|
|
+ _itoa_s(stTask.Id, szValue, 10);
|
|
|
|
+ stNotifyJobStartReq.strInstanceId = szValue;
|
|
|
|
+
|
|
|
|
+ _itoa_s(stTask.nTaskId, szValue, 10);
|
|
|
|
+ stNotifyJobStartReq.strTaskId = szValue;
|
|
|
|
+
|
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl = "D:\\\\SAT\\\\Runner\\\\btc_runner_se\\\\runner\\\\output\\\\";//ODF_NPI_RT2841\\\\20191216101613370\\\\192.168.1.119_5555";
|
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl.append(stTask.strTaskName+"\\\\");
|
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl.append(stTask.Job.strUniqueId+"\\\\");
|
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl.append(stTask.Job.strDeviceId);
|
|
|
|
+
|
|
|
|
+ for( int n = 0; n < 2; n++)
|
|
|
|
+ {
|
|
|
|
+ // 查询任务是否已在SAT上存在;
|
|
|
|
+ if ( NotifyJobStart(url, stNotifyJobStartReq, stNotifyJobStartResp) )
|
|
|
|
+ {
|
|
|
|
+ // 更新设备为忙碌状态;
|
|
|
|
+ // 忙碌状态,此时请求Heartbeat将不会查询任务;
|
|
|
|
+ stDevice.strStatus = "2";
|
|
|
|
+ printf("NotifyJobStart 成功\n");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ printf("NotifyJobStart 失败\n");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ stDevice.strStatus = "0";
|
|
|
|
+ // #########################################################################################
|
|
|
|
+ // 开始Job;
|
|
|
|
+ SATParameters::STJobProcessReq stJobProcessReq;
|
|
|
|
+ SATParameters::STJobProcessResp stJobProcessResp;
|
|
|
|
+ __if_not_exists(url)
|
|
|
|
+ {
|
|
|
|
+ std::string url = host + "/btc_execute_se/ajaxInteractiveManage!setResultList.action";
|
|
|
|
+ }
|
|
|
|
+ __if_exists(url)
|
|
|
|
+ {
|
|
|
|
+ url = host + "/btc_execute_se/ajaxInteractiveManage!setResultList.action";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ stJobProcessReq.strResultState = "1";
|
|
|
|
+ stJobProcessReq.strCaseScene = "";
|
|
|
|
+ stJobProcessReq.strCaseStep = "0";
|
|
|
|
+ stJobProcessReq.strApkMD5 = "";
|
|
|
|
+ stJobProcessReq.strCrashTime = "";
|
|
|
|
+ // 就是Task中的ExecuteId
|
|
|
|
+ _itoa_s(stTask.nExecuteId, szValue, 10);
|
|
|
|
+ stJobProcessReq.strRunnerId = szValue;
|
|
|
|
+ stJobProcessReq.strCPUInfo = "0";
|
|
|
|
+ stJobProcessReq.strRunnedActionNameList = "";
|
|
|
|
+ stJobProcessReq.strArtificialResult = "";
|
|
|
|
+ stJobProcessReq.strArtificialModify = "";
|
|
|
|
+ stJobProcessReq.strRunnerName = "";
|
|
|
|
+ stJobProcessReq.strTaskType = "FUNCTIONALITY";
|
|
|
|
+ stJobProcessReq.strCaseRepeat = "";
|
|
|
|
+ stJobProcessReq.strApplicationGroup = "";
|
|
|
|
+ // 实例Id;
|
|
|
|
+ _itoa_s(stTask.nInstanceId, szValue, 10);
|
|
|
|
+ stJobProcessReq.strInstanceId = szValue;
|
|
|
|
+ stJobProcessReq.strCaseId = "";
|
|
|
|
+ stJobProcessReq.strProgress = "0";
|
|
|
|
+ stJobProcessReq.strReusltMessage = "任务开始";
|
|
|
|
+ stJobProcessReq.strJobRepeat = "";
|
|
|
|
+ stJobProcessReq.strScreenShot = "";
|
|
|
|
+ stJobProcessReq.strStartTime = "2019-12-16 10:16:43";
|
|
|
|
+ stJobProcessReq.strCrashNumber = "";
|
|
|
|
+ stJobProcessReq.strCaseName = "";
|
|
|
|
+ stJobProcessReq.strFailedReason = "";
|
|
|
|
+ stJobProcessReq.strImgName = "";
|
|
|
|
+ stJobProcessReq.strCaseIndex = "";
|
|
|
|
+ // 实例Id;
|
|
|
|
+ _itoa_s(stTask.nDeviceId, szValue, 10);
|
|
|
|
+ stJobProcessReq.strDeviceId = szValue;
|
|
|
|
+ stJobProcessReq.strSceneIndex = "";
|
|
|
|
+ // 实例Id;
|
|
|
|
+ _itoa_s(stTask.nTaskId, szValue, 10);
|
|
|
|
+ stJobProcessReq.strTaskId = szValue;
|
|
|
|
+ stJobProcessReq.strAnalysis = "";
|
|
|
|
+ // 设备名称:即DeviceSerial;
|
|
|
|
+ stJobProcessReq.strDevnceName = stDevice.strDeviceSerial;
|
|
|
|
+ // 固定为:TOTAL
|
|
|
|
+ stJobProcessReq.strInfoType = "TOTAL";
|
|
|
|
+ // 如果是Android设备,需要通过adb获取;
|
|
|
|
+ stJobProcessReq.strMemoryInfo = stDevice.strMemory;
|
|
|
|
+ stJobProcessReq.strEndTime = "2019-12-16 10:18:20";
|
|
|
|
+ stJobProcessReq.strRoundNumber = "1";
|
|
|
|
+ stJobProcessReq.strResultType = "0";
|
|
|
|
+ stJobProcessReq.strOperationStep = "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ if ( ProcessJob(url, stJobProcessReq, stJobProcessResp) )
|
|
|
|
+ {
|
|
|
|
+ // 开始下载脚本;
|
|
|
|
+ __if_not_exists(url)
|
|
|
|
+ {
|
|
|
|
+ std::string url = host + "/btc_caseManagement_se/ajaxInteractiveManage!getCaseFileListUrl.action";
|
|
|
|
+ }
|
|
|
|
+ __if_exists(url)
|
|
|
|
+ {
|
|
|
|
+ url = host + "/btc_caseManagement_se/ajaxInteractiveManage!getCaseFileListUrl.action";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SATParameters::STScriptUrlResp stScriptUrlResp;
|
|
|
|
+ std::vector<SATParameters::STCase>::iterator it = stTask.Job.vtCases.begin();
|
|
|
|
+ for ( ; it != stTask.Job.vtCases.end(); it++ )
|
|
|
|
+ {
|
|
|
|
+ if ( DownloadScript(url, it->strId, "D:\\SAT\\", stScriptUrlResp) )
|
|
|
|
+ {
|
|
|
|
+ printf("获取脚本下载地址成功:%s\n路径:%s\n", stScriptUrlResp.strURL.c_str(), stScriptUrlResp.strScripFile.c_str());
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ printf("获取脚本下载地址失败\n");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Sleep(3000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ system("pause");
|
|
|
|
+
|
|
|
|
+ return nRetCode;
|
|
|
|
+}
|