#pragma once #include "ZJ_cctv.h" #include "ZJ_cctvClient.h" #include "iostream" #include "fstream" #ifdef WIN32 #include #include #else #include #include #include #include #include #endif #ifndef WIN32 #include #endif #define far typedef void far *LPVOID; unsigned long long GetTimeStamp() { unsigned long long stampNow = 0; time_t timer; timer = time(NULL); stampNow = timer; return stampNow; } unsigned int rxprocess(LPVOID rxptr) { ZJ_CCTV* rtxpPara = NULL; rtxpPara = (ZJ_CCTV*)rxptr; sint32 rtuno = rtxpPara->Get_rtuno(); while (rtxpPara->rxflag) { //rtxpPara->getallResources(); // rtxpPara->realplay("api/tvwall/1/device/1/floatwnd/16846849/subwnd/3","e3c1c32b86154dcea0e9fb2dc701a015"); // rtxpPara->getToken();//wyf test 20230517 SeSleep(10000); } return 0; } unsigned int txprocess(LPVOID txptr) { ZJ_CCTV* rtxpPara = NULL; rtxpPara = (ZJ_CCTV*)txptr; sint32 rtuno = rtxpPara->Get_rtuno(); while (rtxpPara->txflag) { S_RAWCMD rawcmd; while (rtxpPara->Get_CmdNum() > 0) { if (rtxpPara->Get_ACmd(rtuno, &rawcmd) == 0) break; rtxpPara->PrintLog(LOG_INFORMATION, "收到%d号终端 命令:%d ", rtuno, rawcmd.type); uint8 len = 0; ST_TRACK_ADDR m_cmdaddr; //处理外部命令,通过此变量保存外部命令地址信息 m_cmdaddr = rawcmd.src; switch (rawcmd.type) { case DC_K_CMD_AOOPER: { S_AO_CTL* aoinfo; aoinfo = (S_AO_CTL*)(&rawcmd.data); int i; switch (aoinfo->funcCode) { case DC_K_CTL_AOSEL://选择 //直接返校 rawcmd.type = DC_K_CMDRET_AOOPER; rawcmd.len = sizeof(aoinfo); rawcmd.src = m_cmdaddr; aoinfo->retCode = 1; rtxpPara->Rpt_AResult(rtuno, rawcmd); break; case DC_K_CTL_AOEXE://执行 { sint32 ytvalue = (sint32)(aoinfo->ptVal); uint16 ptno = aoinfo->ptAddr; rtxpPara->PrintLog(1, "<<<<<< YT no=%d val=%d ", ptno, ytvalue); int wid = ytvalue / 100; ytvalue = ytvalue - wid * 100; if (ptno >= 1 && ptno <= 4 &&rtxpPara->Cameramap.count(ytvalue)>0 && rtxpPara->Wndmap.count(ptno * 100)>0) { rtxpPara->getToken(); rtxpPara->realplay(rtxpPara->Wndmap[ptno * 100], rtxpPara->Cameramap[ytvalue]); rtxpPara->PrintLog(1, "发令切摄像头%d:%s 视频上墙到%d x100:%s", ytvalue,rtxpPara->Cameramap[ytvalue].c_str(),ptno,rtxpPara->Wndmap[ptno * 100].c_str()); } else { rtxpPara->PrintLog(3, "未配置下控值 %d 对应的监控点编号 或者 窗口号,下控制错误", ytvalue); } } break; case DC_K_CTL_AODEL://撤销 break; default: break; } } break; default: //对其它的下发命令不处理 break; } rtxpPara->Del_ACmd(rtuno); } SeSleep(500); } return 0; } sint32 ZJ_CCTV::Get_rtuno() { return (pLink->GetRtuNo()); } sint32 ZJ_CCTV::Get_CmdNum() { sint32 rtuno = pLink->GetRtuNo(); return (pCmdMem->GetCmdNum(rtuno)); } sint32 ZJ_CCTV::Get_ACmd(sint32 rtuno, S_RAWCMD* cmd) { return pCmdMem->GetACmd(rtuno, cmd); } sint32 ZJ_CCTV::Del_ACmd(sint32 rtuno) { return pCmdMem->DelACmd(rtuno); } sint32 ZJ_CCTV::Rpt_AResult(sint32 rtuno, S_RAWCMD cmd) { return pCmdMem->RptAResult(rtuno, cmd); } void ZJ_CCTV::Init(S_PROTOCOLCFG* pcfg) { PRawCtrl = pcfg->PRawCtrl; pCmdMem = pcfg->pCmdMem; pRtu = pcfg->pRtu; pLink = pcfg->pLink; rxflag = true; txflag = true; ReadIni(); if (rxflag) { sint32 rxthread = SE_CreateThread((PTHREAD_FUNC_DEF)rxprocess, this, 100); } PrintLog(LOG_INFORMATION, "启动rx线程 !"); if (txflag) { sint32 txthread = SE_CreateThread((PTHREAD_FUNC_DEF)txprocess, this, 100); } PrintLog(LOG_INFORMATION, "启动tx线程 !"); } int ZJ_CCTV::getallResources() { int status = 0; sint32 rtuno = Get_rtuno(); string url = logininfo.urlheader + "/artemis/api/tvms/v1/public/all"; string header = "Content-Type:application/json\r\n"; //header = header + logininfo.appkey + "\r\nx-ca-signature-headers:x-ca-key\r\nx-ca-signature:" + Signaturemap["getallResources"]; string body; string callback; Json::Value bodysender; bodysender; Json::FastWriter bodywrite; body = bodywrite.write(bodysender); status = Fclient::Sendreq(url, header, body, callback, 1); if (callback.size() <= 0) { PrintLog(LOG_ERROR, "getallResources callback is NULL! "); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value data; if (reader.parse(callback, data)) { string state = data["code"].asString(); if (!(state.compare("0"))) { int size = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"].size(); for (int i = 0; i < size; i++) { /*WndInfo wnd; wnd.wnd_uri = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["wnd_uri"].asString(); wnd.status = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["status"].asInt(); wnd.decode_channel = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["decode_channel"].asInt(); int id = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["wnd_id"].asInt(); Wndmap[id] = wnd;*/ } } else { PrintLog(LOG_ERROR, "获取电视墙大屏信息返回错误码 :%s ",state.c_str()); } } return 1; } int ZJ_CCTV::getToken() {//{"access_token":"CBI2JCUP8cZvQFwPZJZTEs0EZkC9ridr","expires_in":43199} int ret=-1; int status = 0; sint32 rtuno = Get_rtuno(); m_seq=rand(); string seq_tmp=to_string(m_seq); //seq_tmp="192051860833485581719661"; string url = logininfo.urlheader + "/artemis/oauth/token"; // string header = "Content-Type:application/json\r\n"; string header = "Content-Type: multipart/form-data; boundary=--------------------------"+seq_tmp+"\r\n";//492051860833485581719660\r\n"; // header = header +"User-Agent: PostmanRuntime/7.28.4\r\nAccept: */*\r\n"; // header = header +"Postman-Token: b90f3dd3-2c85-49f6-844e-e2f838f8d380\r\n"; // header = header +"Accept-Encoding: gzip, deflate, br\r\n"; string body="----------------------------" + seq_tmp + "\r\n";//492051860833485581719660\r\n"; body = body +"Content-Disposition: form-data; name=\"client_id\"\r\n\r\n"+logininfo.appkey; body = body +"\r\n----------------------------" + seq_tmp + "\r\n";//492051860833485581719660\r\n"; body = body +"Content-Disposition: form-data; name=\"client_secret\"\r\n\r\n"+logininfo.secret; body = body +"\r\n----------------------------" + seq_tmp + "--\r\n";//492051860833485581719660--\r\n"; string callback; Json::Value bodysender; // bodysender["client_id"] = logininfo.appkey; // bodysender["client_secret"] = logininfo.secret; // Json::FastWriter bodywrite; // body = bodywrite.write(bodysender); status = Fclient::Sendreq(url, header, body, callback, 1); //callback="{\"access_token\":\"CBI2JCUP8cZvQFwPZJZTEs0EZkC9ridr\",\"expires_in\":43199}";//wyf test if (callback.size() <= 0) { PrintLog(LOG_ERROR, "getToken callback is NULL!status=%d ",status); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value data; if (reader.parse(callback, data)) { m_token=""; m_token = data["access_token"].asString(); if (0!=m_token.compare("")) { ret=1; PrintLog(1, "access_token=%s ",m_token.c_str()); } else { ret=-1; PrintLog(LOG_ERROR, "access_token获取失败"); } } return ret; } int ZJ_CCTV::realplay(string wnd,string camera) { int status = 0; sint32 rtuno = Get_rtuno(); string url = logininfo.urlheader + "/artemis/api/tvms/v1/public/tvwall/wnds/realplay/addition"; // string header = "Content-Type:application/json\r\nx-ca-key:23013291\r\n"; string header = "Content-Type:application/json\r\naccess_token:" + m_token + "\r\n"; string body; string callback; Json::Value bodysender; bodysender["realplay_list"][0]["wnd_uri"] = wnd; bodysender["realplay_list"][0]["camera_indexcode"] = camera; bodysender["realplay_list"][0]["stream_type"] = 0; Json::FastWriter bodywrite; body = bodywrite.write(bodysender); status = Fclient::Sendreq(url, header, body, callback, 1); if (callback.size() <= 0) { PrintLog(LOG_ERROR, "realplay callback is NULL! "); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value data; if (reader.parse(callback, data)) { string state = data["code"].asString(); if (!(state.compare("0"))) { PrintLog(1, "电视墙上墙操作成功! "); } else { PrintLog(LOG_ERROR, "电视墙上墙返回错误码 :%d ", state); } } return 1; } int ZJ_CCTV::ReadIni() { char *home = getenv("SEROOT"); if (NULL == home) { PrintLog(LOG_ERROR, "环境变量SEROOT未设置"); return 0; } char filename[256] = { 0 }; #if defined(__unix) sprintf(filename, "%s%s", home, "/cfg/ZJ_CCTV.ini"); #else sprintf(filename, "%s%s", home, "\\cfg\\ZJ_CCTV.ini"); #endif CReadConf readconf; char http_tmp[128]={0}; char appkey_tmp[128]={0}; char secret_tmp[128]={0}; char ip_tmp[128]={0}; readconf.ReadString("LoginInfo", "http_type", http_tmp, filename, "http"); string head_tmp = http_tmp;//"https://"; readconf.ReadString("LoginInfo", "server_ip", ip_tmp, filename, "10.151.1.80:443"); readconf.ReadString("LoginInfo", "appkey", appkey_tmp, filename, "23013291"); readconf.ReadString("LoginInfo", "secret", secret_tmp, filename, "N63QsR6vnHHu73laueHH"); logininfo.appkey = appkey_tmp; logininfo.secret = secret_tmp; // logininfo.urlheader = head_tmp + ip_tmp; logininfo.urlheader = head_tmp + "://" + ip_tmp; int wndnum = 0; wndnum = readconf.ReadLong("Wnd_uri", "winNum", filename, "0"); int i; char sSection[20]; char wnd_tmp[128]; for (i = 0; i < wndnum; i++) { memset(sSection, 0, sizeof(char)* 10); sprintf(sSection, "win_%d", i + 1); readconf.ReadString("Wnd_uri", sSection, wnd_tmp, filename, "0"); Wndmap[(i + 1) * 100] = wnd_tmp; } int cameranum = 0; cameranum = readconf.ReadLong("Camera", "cameraNum", filename, "0"); char cam_tmp[128]; for (i = 0; i < cameranum; i++) { memset(sSection, 0, sizeof(char)* 10); sprintf(sSection, "camera_%d", i + 1); readconf.ReadString("Camera", sSection, cam_tmp, filename, "0"); Cameramap[i + 1] = cam_tmp; } return 1; } sint32 ZJ_CCTV::TxProc() { return 1; } sint32 ZJ_CCTV::RxProc() { return 1; } #if defined(WIN32) extern "C" __declspec(dllexport) #else extern "C" #endif CProtocol *CreateProtocol(char *defpara) { return (CProtocol*)(new ZJ_CCTV()); } /* #ifdef __unix extern "C" CProtocol* CreateProtocol(char *defpara) #else extern "C" __declspec(dllexport) CProtocol* CreateProtocol(char *defpara) #endif { CProtocol *pEpv = new ZJ_CCTV; return pEpv; } */