#pragma once #include "AxiomAcs.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; int AxionAcs::GetNowSecond() { CSeTime SE_T; TCriterionTime tmptime; SE_T.GetNow(&tmptime); return (int)tmptime; } std::string convertTime(int timestamp) { time_t tick = (time_t)(timestamp);//转换时间 struct tm tm; char s[40]; tm = *localtime(&tick); strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm); std::string str(s); return str; } unsigned long long GetTimeStamp() { unsigned long long stampNow = 0; time_t timer; timer = time(NULL); stampNow = timer; return stampNow; } void Inver2byte(uint8* Src, int num) { int t = 0; for (int i = 0; i < num / 2; i++) { t = Src[2 * i]; Src[2 * i] = Src[2 * i + 1]; Src[2 * i + 1] = t; } } unsigned int rxprocess(LPVOID rxptr) { AxionAcs* rtxpPara = NULL; rtxpPara = (AxionAcs*)rxptr; sint32 rtuno = rtxpPara->Get_Rtuno(); bool doorflag = true; while (doorflag) { if (rtxpPara->GetDoors() == 1) { //获取所有门数据成功 doorflag = false; } if (doorflag) { rtxpPara->PrintLog(LOG_ERROR, "门状态前置准备失败!等待2s"); SeSleep(2000); } } while (rtxpPara->rxflag) { for (int i = 0; i < rtxpPara->doorNum; i++) { if (rtxpPara->httpflag_doors == false) { rtxpPara->fclient_door.init_mg(); rtxpPara->httpflag_doors = true; rtxpPara->httpflag1_doors = true; rtxpPara->PrintLog(LOG_INFORMATION, "初始化门状态连接!"); } rtxpPara->GetDoorState(i + 1); } SeSleep(500); } return 0; } unsigned int txprocess(LPVOID txptr) { AxionAcs* rtxpPara = NULL; rtxpPara = (AxionAcs*)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_DOOPER:{ //遥控:控开关门 S_DO_CTL *cmdinfo; cmdinfo = (S_DO_CTL *)(&rawcmd.data); uint16 ykno = (uint16)cmdinfo->ptAddr;//遥控号 switch (cmdinfo->funcCode) { case DC_K_CTL_DOSEL: //选择 //直接返校 rawcmd.type = DC_K_CMDRET_DOOPER; rawcmd.len = sizeof(cmdinfo); rawcmd.src = m_cmdaddr; cmdinfo->retCode = 1; rtxpPara->Rpt_AResult(rtuno, rawcmd); break; case DC_K_CTL_DOEXE: //执行 uint16 ykvalue; ykvalue = cmdinfo->ctlVal; if (ykno % 10 == 4){ if (ykvalue == 1) { //远程开门 //控门ykno为打开 // rtxpPara->PrintLog(LOG_INFORMATION, "删除一条收到%d号终端命令 ", rtuno); rtxpPara->SetDoorOpen(ykno / 10); } if (ykvalue == 0) { //远程关门 //控门ykno为关闭 rtxpPara->SetDoorClose(ykno / 10); } } if ((ykno % 10 == 5) && (ykvalue == 1)){ //常开 rtxpPara->SetDoorMode(ykno / 10, "4"); } if ((ykno % 10 == 5) && (ykvalue == 0)){ //常闭 rtxpPara->SetDoorMode(ykno / 10, "5"); } if ((ykno % 10 == 5) && (ykvalue == 2)){ //自动 rtxpPara->SetDoorMode(ykno / 10, "0"); } break; case DC_K_CTL_DODEL://撤消 break; } } break; default: break; } rtxpPara->Del_ACmd(rtuno); rtxpPara->PrintLog(LOG_INFORMATION, "删除一条收到%d号终端命令 ", rtuno); } SeSleep(500); } return 0; } unsigned int xxprocess(LPVOID xxptr) { AxionAcs* rtxpPara = NULL; rtxpPara = (AxionAcs*)xxptr; sint32 rtuno = rtxpPara->Get_Rtuno(); int eventNum = 0; bool devicesflag = true; while (devicesflag) { if (rtxpPara->GetDevices() == 1) { //获取所有门禁设备数据成功 devicesflag = false; } if (devicesflag) { rtxpPara->PrintLog(LOG_ERROR, "事件前置准备失败!等待2s"); SeSleep(2000); } } while (rtxpPara->xxflag) { if (rtxpPara->httpflag_devices == false) { rtxpPara->fclient_device.init_mg(); rtxpPara->httpflag_devices = true; rtxpPara->httpflag1_devices = true; rtxpPara->PrintLog(LOG_INFORMATION, "初始化事件连接!"); } eventNum = rtxpPara->GetSwipecard(); if (eventNum != 0) { for (int i = 0; i < eventNum; i++) { if ((rtxpPara->lastEventId) < (rtxpPara->eventid[rtxpPara->eventidex[i]])) { rtxpPara->lastEventId = rtxpPara->eventid[rtxpPara->eventidex[i]]; string doorid = rtxpPara->GetDoorId(rtxpPara->eventidex[i]); string cardId = rtxpPara->GetCardId(rtxpPara->eventidex[i]); string eventtime = rtxpPara->GetEventTime(rtxpPara->eventidex[i]); int reason = rtxpPara->GetaccessBlockedReason(rtxpPara->eventidex[i]); int doorno; for (int j = 0; j < rtxpPara->doorNum; j++) { if (doorid == rtxpPara->Getmapdoor(j + 1)) { doorno = j + 1; } } if (reason == 0) { rtxpPara->PrintLog(LOG_INFORMATION, "门禁刷卡实时事件:刷卡成功!门[%d] 时间[%s] 卡号[%s]", doorno, eventtime.c_str(), cardId.c_str()); rtxpPara->PutSoe(rtuno, doorno * 10 + 2, eventtime, cardId); } else { rtxpPara->PrintLog(LOG_ERROR, "门禁刷卡实时事件:刷卡失败!门[%d] 时间[%s] 卡号[%s] 错误码[%d]", doorno, eventtime.c_str(), cardId.c_str(), reason); rtxpPara->PutSoe(rtuno, doorno * 10 + 3, eventtime, cardId); } } } } SeSleep(1000); } } void AxionAcs::Init(S_PROTOCOLCFG* pcfg) { PRawCtrl = pcfg->PRawCtrl; pCmdMem = pcfg->pCmdMem; pRtu = pcfg->pRtu; pLink = pcfg->pLink; deviceNum = 0; doorNum = 0; lastEventId = 0; eventid[100] = { 0 }; eventidex[100] = { 0 }; username[128] = { 0 }; password[128] = { 0 }; rxflag = true; txflag = true; xxflag = true; httpflag_doors = false; httpflag_devices = false; ReadIni(); PrintLog(LOG_INFORMATION, "启动rx线程%s %s !",username,password); if (rxflag) { rxthread = SE_CreateThread((PTHREAD_FUNC_DEF)rxprocess, this, 100); } PrintLog(LOG_INFORMATION, "启动rx线程 !"); if (txflag) { txthread = SE_CreateThread((PTHREAD_FUNC_DEF)txprocess, this, 100); } PrintLog(LOG_INFORMATION, "启动tx线程 !"); if (xxflag) { xxthread = SE_CreateThread((PTHREAD_FUNC_DEF)xxprocess, this, 100); } PrintLog(LOG_INFORMATION, "启动xx线程 !"); /* //开启restful服务,接受并处理推送消息 strCallback.iotprotocols = this; strCallback.rtuno = iotpLink->GetRtuNo(); restfulServer(); */ } //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------------- sint32 AxionAcs::Get_Rtuno() { return (pLink->GetRtuNo()); } void AxionAcs::Put_AYx(uint16 Rtuno, uint16 YxNo, uint8 YxValue) { PRawCtrl->PutAYx(Rtuno, YxNo, YxValue); } sint32 AxionAcs::Get_CmdNum() { sint32 rtuno = pLink->GetRtuNo(); return (pCmdMem->GetCmdNum(rtuno)); } sint32 AxionAcs::Get_ACmd(sint32 rtuno, S_RAWCMD* cmd) { return pCmdMem->GetACmd(rtuno, cmd); } sint32 AxionAcs::Del_ACmd(sint32 rtuno) { return pCmdMem->DelACmd(rtuno); } sint32 AxionAcs::Rpt_AResult(sint32 rtuno, S_RAWCMD cmd) { return pCmdMem->RptAResult(rtuno, cmd); } /* int AxionAcs::GetEventId(int i) { return events[i].eventId; } */ string AxionAcs::Getusername() { return username; } string AxionAcs::Getpassword() { return password; } string AxionAcs::GetDoorId(int i) { return events[i].subDeviceId; } string AxionAcs::GetEventTime(int i) { return events[i].eventTime; } string AxionAcs::GetCardId(int i) { return events[i].cardNo; } int AxionAcs::GetaccessBlockedReason(int i) { return events[i].accessBlockedReason; } string AxionAcs::Getmapdoor(int i) { return map_door[i]; } void AxionAcs::PutSoe(int rtuno, int yxno, string time, string cardId) { char ti[50] = { 0 }; char id[50] = { 0 }; if (time.length() < 50) { strcpy(ti, time.c_str()); } else { PrintLog(LOG_ERROR, "获取实时事件:非法的时间!"); return; } if (cardId.length() < 50) {strcpy(id, cardId.c_str()); } else { PrintLog(LOG_ERROR, "获取实时事件:非法的卡号!"); return; } sint8 year = (ti[0] - 48) * 1000 + (ti[1] - 48) * 100 + (ti[2] - 48) * 10 + (ti[3] - 48); sint8 month = (ti[5] - 48) * 10 + (ti[6] - 48); sint8 day = (ti[8] - 48) * 10 + (ti[9] - 48); sint8 hour = (ti[11] - 48) * 10 + (ti[12] - 48); sint8 minute = (ti[14] - 48) * 10 + (ti[15] - 48); sint8 second = (ti[17] - 48) * 10 + (ti[18] - 48); int length = strlen(id); if (length>15) { length = 15; PrintLog(LOG_ERROR, "获取实时事件:获取到的卡号过长,只取前15个!"); } S_RAWSOEEX soe; soe.Source = DC_K_RTUSOE; soe.Year = year; soe.Month = month; soe.Day = day; soe.Hour = hour; soe.Minute = minute; soe.Second = second; soe.Ms = 0; soe.Rtuno = rtuno; soe.Yxno = yxno; soe.Val = 1; soe.Type = DC_SOEEX_ACSCARD; for (int i = 0; i < length; i++) { soe.Data[i] = id[i]; } soe.Data[length] = 0; PRawCtrl->PutASoeEx(soe); } //获取所有区域数据 int AxionAcs::Getareas() { int status = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/areas"; string body = ""; string callback; status = Fclient::Sendreq(urls, start_header, body, callback, 1); if (status != -1) { Put_AYx(rtuno, 1, 1); } else { Put_AYx(rtuno, 1, 0); return 0; } if (callback.size() <= 0) { PrintLog(LOG_ERROR, "获取所有区域数据返回结果为空!"); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; if (reader.parse(callback, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); if (status != 0) { PrintLog(LOG_ERROR, "获取所有区域数据失败! 错误码[%d]: %s", status, msg.c_str()); return 0; } int size = 0; if (parse_callback["data"].isArray()) { size = parse_callback["data"].size(); } else { return 0; } PrintLog(LOG_INFORMATION, "获取到区域的总个数为:%d", size); for (int i = 0; i < size; i++) { int areaId = parse_callback["data"][i]["areaId"].asInt(); string areaName = parse_callback["data"][i]["areaName"].asString(); string areaCode = parse_callback["data"][i]["areaCode"].asString(); int parentId = parse_callback["data"][i]["parentId"].asInt(); area area_tmp; area_tmp.areaId = areaId; area_tmp.areaName = areaName; area_tmp.areaCode = areaCode; area_tmp.parentId = parentId; areas.push_back(area_tmp); } } return 1; } //获取所有门禁设备数据 int AxionAcs::GetDevices() { int status = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/acs/devices"; string body = ""; string callback; status = Fclient::Sendreq(urls, start_header, body, callback, 1); // PrintLog(3, "门禁设备%d %d",status,callback.size()); if (status != -1) { Put_AYx(rtuno, 1, 1); // PrintLog(3, "111111!"); } else { Put_AYx(rtuno, 1, 0); // PrintLog(3, "000000!"); return 0; } if (callback.size() <= 0) { PrintLog(LOG_ERROR, "获取所有门禁设备数据返回结果为空!"); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; if (reader.parse(callback, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); if (status != 0) { PrintLog(LOG_ERROR, "获取所有门禁设备数据失败! 错误码[%d]: %s", status, msg.c_str()); return 0; } int size = 0; if (parse_callback["data"].isArray()) { size = parse_callback["data"].size(); deviceNum = size; } else { return 0; } PrintLog(LOG_INFORMATION, "获取到门禁设备的总个数为:%d", size); for (int i = 0; i < size; i++) { string deviceId = parse_callback["data"][i]["deviceId"].asString(); string deviceName = parse_callback["data"][i]["deviceName"].asString(); int areaId = parse_callback["data"][i]["areaId"].asInt(); string areaName = parse_callback["data"][i]["areaName"].asString(); string deviceSn = parse_callback["data"][i]["deviceSn"].asString(); string commAddr = parse_callback["data"][i]["commAddr"].asString(); int isOnline = parse_callback["data"][i]["isOnline"].asInt(); string commErrorMsg = parse_callback["data"][i]["commErrorMsg"].asString(); device device_tmp; device_tmp.deviceNo = i + 1; device_tmp.deviceId = deviceId; device_tmp.deviceName = deviceName; device_tmp.areaId = areaId; device_tmp.areaName = areaName; device_tmp.deviceSn = deviceSn; device_tmp.commAddr = commAddr; device_tmp.isOnline = isOnline; device_tmp.commErrorMsg = commErrorMsg; devices.push_back(device_tmp); map_device[i + 1] = deviceId; } } // PrintLog(3, "222222!"); return 1; } //获取所有门数据 int AxionAcs::GetDoors() { int status = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/acs/device/doors"; string body = ""; string callback; status = Fclient::Sendreq(urls, start_header, body, callback, 1); // PrintLog(3, "门数据%d %d", status, callback.size()); if (status != -1) { Put_AYx(rtuno, 1, 1); } else { Put_AYx(rtuno, 1, 0); return 0; } /* doorNum = 5; map_door[1] = "fb6b37cf331f409d9b4e9c5161043707"; map_door[2] = "c034f795a2c0401584bc13c767d598b6"; map_door[3] = "80b3b27f29044b55b81b75cd8b3b10fc"; map_door[4] = "b15b2026ed104953be046f2b1924e0a9"; map_door[5] = "c733f78d42cb4f8d81174a3572d15957"; */ if (callback.size() <= 0) { PrintLog(LOG_ERROR, "获取所有门数据返回结果为空!"); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; PrintLog(LOG_ERROR, "出来出来!"); if (reader.parse(callback, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); if (status != 0) { PrintLog(LOG_ERROR, "获取所有门数据失败! 错误码[%d]: %s", status, msg.c_str()); return 0; } int size = 0; if (parse_callback["data"].isArray()) { size = parse_callback["data"].size(); doorNum = size; } else { return 0; } PrintLog(LOG_INFORMATION, "获取到门的总个数为:%d", size); std::string time; time = convertTime(GetNowSecond()); std::ofstream outfile; outfile.open(logName, std::ios_base::app); outfile << "[" << time << "] " << std::endl; for (int i = 0; i < size; i++) { string doorId = parse_callback["data"][i]["doorId"].asString(); string doorName = parse_callback["data"][i]["doorName"].asString(); string doorAddr = parse_callback["data"][i]["doorAddr"].asString(); int areaId = parse_callback["data"][i]["areaId"].asInt(); string areaName = parse_callback["data"][i]["areaName"].asString(); string deviceId = parse_callback["data"][i]["deviceId"].asString(); string deviceName = parse_callback["data"][i]["deviceName"].asString(); door door_tmp; door_tmp.doorNo = i + 1; door_tmp.doorId = doorId; door_tmp.doorName = doorName; door_tmp.doorAddr = doorAddr; door_tmp.areaId = areaId; door_tmp.areaName = areaName; door_tmp.deviceId = deviceId; door_tmp.deviceName = deviceName; doors.push_back(door_tmp); map_door[i + 1] = doorId; outfile << "[ door" << i + 1 << " ]" << std::endl; outfile << " doorId: " << doorId << std::endl; outfile << " doorName: " << doorName << std::endl; outfile << " doorAddr: " << doorAddr << std::endl; outfile << " areaId: " << areaId << std::endl; outfile << " areaName: " << areaName << std::endl; outfile << " deviceId: " << deviceId << std::endl; outfile << " deviceName:" << deviceName << std::endl; } outfile.close(); } return 1; } //获取第doorNo个门的状态 int AxionAcs::GetDoorState(int doorNo) { int status = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/acs/device/door/state/"+map_door[doorNo]; string body = ""; // string callback; string con_urls = "/api/v1/acs/device/door/state/" + map_door[doorNo]; // PrintLog(LOG_ERROR, "!!!!!%d %d ", httpflag1, con_urls.find("swipecard")); // PrintLog(LOG_ERROR, "!!!!!!%d!", httpflag1_doors); // PrintLog(LOG_ERROR, "%d%s%s%s%s!", httpflag1, urls.c_str(), start_header.c_str(), con_urls.c_str(), urls_tmp); // if (iii == 555) { PrintLog(LOG_INFORMATION, "停在这!"); sleep(1000000); } status = fclient_door.SendreqLong(urls, start_header, body, 1, httpflag1_doors, con_urls, urls_ip); // PrintLog(3, "门状态%d %d %s", status, fclient.call_back.size(), fclient.call_back.c_str()); //--------- // SeSleep(100000); // PrintLog(LOG_INFORMATION, "停在这!"); if (status != -1) { Put_AYx(rtuno, 1, 1); } else { Put_AYx(rtuno, 1, 0); fclient_door.free_mg(); httpflag_doors = false; PrintLog(LOG_ERROR, "门状态连接失败! 门[%d]ID:%s", doorNo, map_door[doorNo].c_str()); return 0; } if (fclient_door.call_back.size() <= 0) { PrintLog(LOG_ERROR, "获取第%d个门的状态数据返回结果为空!",doorNo); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; if (reader.parse(fclient_door.call_back, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); int isOnline = parse_callback["isOnLine"].asInt(); int isOpen = parse_callback["isOpen"].asInt(); if (status != 0) { PrintLog(LOG_ERROR, "获取第%d个门的状态数据失败! 错误码[%d]: %s", doorNo, status, msg.c_str()); return 0; } if (isOnline==0) { Put_AYx(rtuno, doorNo * 10, 0); // PrintLog(LOG_ERROR, "当前第%d个门处于离线状态!", doorNo); } else { Put_AYx(rtuno, doorNo * 10, 1); if (isOpen==1) { Put_AYx(rtuno, doorNo * 10 + 1, 1); // PrintLog(LOG_INFORMATION, "当前第%d个门的状态为:打开!", doorNo); } else { Put_AYx(rtuno, doorNo * 10 + 1, 0); // PrintLog(LOG_INFORMATION, "当前第%d个门的状态为:关闭!", doorNo); } } } return 1; } //控制第doorNO个门的状态为:打开 int AxionAcs::SetDoorOpen(int doorNo) { int status = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/acs/device/door/open/" + username + "/" + password + "/" + map_door[doorNo]; string body = ""; string callback; status = Fclient::Sendreq(urls, start_header, body, callback, 1); if (status != -1) { Put_AYx(rtuno, 1, 1); } else { Put_AYx(rtuno, 1, 0); return 0; } if (callback.size() <= 0) { PrintLog(LOG_ERROR, "控制第%d个门打开的数据返回结果为空!", doorNo); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; if (reader.parse(callback, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); if (status!=0) { Put_AYx(rtuno, 2, 0); PrintLog(LOG_ERROR, "控制第%d个门打开失败! 错误码[%d]: %s", doorNo, status, msg.c_str()); return 0; } else { Put_AYx(rtuno, 2, 1); PrintLog(LOG_INFORMATION, "控制第%d个门打开成功!", doorNo); } } return 1; } //控制第doorNO个门的状态为:关闭 int AxionAcs::SetDoorClose(int doorNo) { int status = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/acs/device/door/close/" + username + "/" + password + "/" + map_door[doorNo]; string body = ""; string callback; status = Fclient::Sendreq(urls, start_header, body, callback, 1); if (status != -1) { Put_AYx(rtuno, 1, 1); } else { Put_AYx(rtuno, 1, 0); return 0; } if (callback.size() <= 0) { PrintLog(LOG_ERROR, "控制第%d个门关闭的数据返回结果为空!", doorNo); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; if (reader.parse(callback, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); if (status != 0) { Put_AYx(rtuno, 2, 0); PrintLog(LOG_ERROR, "控制第%d个门关闭失败! 错误码[%d]: %s", doorNo, status, msg.c_str()); return 0; } else { Put_AYx(rtuno, 2, 1); PrintLog(LOG_INFORMATION, "控制第%d个门关闭成功!", doorNo); } } return 1; } //控制第doorNO个门的工作模式为mode 0:自动,1:刷卡,2:卡+密码,3:卡或密码,4:常开,5:常闭,6:卡数据 int AxionAcs::SetDoorMode(int doorNo, string mode) { int status = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/acs/device/door/workmode/" + username + "/" + password + "/" + map_door[doorNo] + "/" + mode; string body = ""; string callback; status = Fclient::Sendreq(urls, start_header, body, callback, 1); if (status != -1) { Put_AYx(rtuno, 1, 1); } else { Put_AYx(rtuno, 1, 0); return 0; } if (callback.size() <= 0) { PrintLog(LOG_ERROR, "设置第%d个门的工作模式为%s 返回结果为空!", doorNo, mode.c_str()); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; if (reader.parse(callback, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); if (status != 0) { Put_AYx(rtuno, 2, 0); PrintLog(LOG_ERROR, "设置第%d个门的工作模式为%s 失败! 错误码[%d]: %s", doorNo, mode.c_str(), status, msg.c_str()); return 0; } else { Put_AYx(rtuno, 2, 1); PrintLog(LOG_INFORMATION, "设置第%d个门的工作模式为%s 成功!", doorNo, mode.c_str()); } } return 1; } //获取所有设备的实时刷卡记录 int AxionAcs::GetSwipecard() { int status = 0; int size = 0; sint32 rtuno = Get_Rtuno(); char tmp_header[128] = { 0 }; sprintf(tmp_header, "Connection:keep-alive\r\n"); string start_header = tmp_header; string urls = server_urls + "/api/v1/acs/device/eventcache/swipecard/"; for (int i = 0; i < deviceNum; i++) { if (i==(deviceNum-1)) { urls = urls + map_device[i + 1]; } else { urls = urls + map_device[i + 1] + ","; } } string body = ""; // string callback; string con_urls = "/api/v1/acs/device/eventcache/swipecard/"; for (int i = 0; i < deviceNum; i++) { if (i == (deviceNum - 1)) { con_urls = con_urls + map_device[i + 1]; } else { con_urls = con_urls + map_device[i + 1] + ","; } } // PrintLog(LOG_ERROR, "!!!!!%d %d ", httpflag1_devices, con_urls.find("swipecard")); // SeSleep(10000000); // PrintLog(LOG_ERROR, "11111%s!", urls_ip.c_str()); status = fclient_device.SendreqLong(urls, start_header, body, 1, httpflag1_devices, con_urls, urls_ip); // status = Fclient::Sendreq(urls, start_header, body, callback, 2); // PrintLog(LOG_ERROR, "22222%s %d!", urls_ip.c_str(), status); // SeSleep(10000000); if (status != -1) { Put_AYx(rtuno, 1, 1); } else { Put_AYx(rtuno, 1, 0); fclient_device.free_mg(); httpflag_devices = false; PrintLog(LOG_ERROR, "事件连接失败!"); return 0; } if (fclient_device.call_back.size() <= 0) { PrintLog(LOG_ERROR, "获取实时刷卡记录返回结果为空!"); return 0; } Json::Reader reader(Json::Features::strictMode()); Json::Value parse_callback; if (reader.parse(fclient_device.call_back, parse_callback)) { int status = parse_callback["status"].asInt(); string msg = parse_callback["msg"].asString(); if (status != 0) { PrintLog(LOG_ERROR, "获取实时刷卡记录失败! 错误码[%d]: %s", status, msg.c_str()); return 0; } if (parse_callback["data"].isArray()) { size = parse_callback["data"].size(); } else { return 0; } // PrintLog(LOG_INFORMATION, "当前获取到实时刷卡记录个数为:%d", size); events.clear(); //获取实时刷卡记录之前先清空events容器 eventid[100] = { 0 }; //按获取到的顺序存放事件ID eventidex[100] = { 0 }; //按事件ID的大小从小到大存放eventid[]的索引 for (int i = 0; i < size; i++) { int eventId = parse_callback["data"][i]["eventId"].asInt(); //事件ID string areaName = parse_callback["data"][i]["areaName"].asString(); //区域名称 string deviceName = parse_callback["data"][i]["deviceName"].asString(); //门禁设备名称 string subDeviceId = parse_callback["data"][i]["subDeviceId"].asString(); //门ID string subDeviceName = parse_callback["data"][i]["subDeviceName"].asString(); //门名称 string eventTime = parse_callback["data"][i]["eventTime"].asString(); //事件时间 string eventName = parse_callback["data"][i]["eventName"].asString(); //事件名称 string cardNo = parse_callback["data"][i]["cardNo"].asString(); //卡号 string cardType = parse_callback["data"][i]["cardType"].asString(); //卡片类型 int accessBlockedReason = parse_callback["data"][i]["accessBlockedReason"].asInt(); //拒绝类型 event event_tmp; event_tmp.eventId = eventId; event_tmp.areaName = areaName; event_tmp.deviceName = deviceName; event_tmp.subDeviceId = subDeviceId; event_tmp.subDeviceName = subDeviceName; event_tmp.eventTime = eventTime; event_tmp.eventName = eventName; event_tmp.cardNo = cardNo; event_tmp.cardType = cardType; event_tmp.accessBlockedReason = accessBlockedReason; events.push_back(event_tmp); eventid[i] = eventId; } for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (eventid[i]>eventid[j]) { eventidex[i]++; } } } } return size; } //------------------------ void AxionAcs::ReadIni() { char filename[512] = { 0 }; CReadConf readconf; sint32 rtuno = pLink->GetRtuNo(); memset(logName, 0, 256); char* pWorkPath = getenv("SEROOT"); if (pWorkPath != NULL) { sprintf(filename, "%s%s%d%s", pWorkPath, "/cfg/AxiomAcsRTU", rtuno, ".ini"); sprintf(logName, "%s%s%d%s", pWorkPath, "/log/AxiomAcsRTU", rtuno, ".txt"); } else { PrintLog(LOG_ERROR, "环境变量未设置"); return; } char urls_tmp[128] = { 0 }; string head_tmp = "http://"; readconf.ReadString("LoginInfo", "server_urls", urls_tmp, filename, "10.44.1.90:6500"); readconf.ReadString("LoginInfo", "username",username, filename, "admin"); readconf.ReadString("LoginInfo", "password",password, filename, "1"); server_urls = head_tmp + urls_tmp; urls_ip = urls_tmp; } sint32 AxionAcs::TxProc() { return 1; } sint32 AxionAcs::RxProc() { return 1; } #if defined(WIN32) extern "C" __declspec(dllexport) #else extern "C" #endif CProtocol *CreateProtocol(char *defpara) { return (CProtocol*)(new AxionAcs()); } /* #ifdef __unix extern "C" CProtocol* CreateProtocol(char *defpara) #else extern "C" __declspec(dllexport) CProtocol* CreateProtocol(char *defpara) #endif { CProtocol *pEpv = new AxionAcs; return pEpv; } */