| | |
| | | #include <vector> |
| | | #include <stdint.h> |
| | | #include <iostream> |
| | | #include <fstream> |
| | | |
| | | #include <unistd.h> |
| | | |
| | | #include <jsoncpp/json/json.h> |
| | | |
| | | #include "MD5Linux.h" |
| | | |
| | |
| | | #define MAX_NUM 16 |
| | | #define MAX 1024 |
| | | #define fileread_buf 128 |
| | | |
| | | volatile time_t last_alarmout; |
| | | |
| | | typedef std::map<std::string, int> hcnetsdk_user_t; // decoder_ip, userid |
| | | hcnetsdk_user_t g_hcnetsdk_user; |
| | |
| | | ET_HCNET_DECODER__LAST, |
| | | ET__LAST |
| | | }; |
| | | |
| | | struct HCNetSDKConfig |
| | | { |
| | | std::string serverIP; |
| | | int serverport; |
| | | std::string username; |
| | | std::string passwd; |
| | | }; |
| | | |
| | | HCNetSDKConfig g_hcnetsdkconfig; |
| | | |
| | | struct HCNetCameraConfig |
| | | { |
| | |
| | | if(NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,1) == FALSE){ |
| | | printf("NET_DVR_SetAlarmOut failed, err: %d\n", NET_DVR_GetLastError()); |
| | | } |
| | | last_alarmout = time(NULL); |
| | | |
| | | sleep(3); |
| | | |
| | | //解除警报 |
| | | NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,0); |
| | | if (time(NULL) - last_alarmout >= 3) |
| | | { |
| | | //解除警报 |
| | | NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,0); |
| | | } |
| | | } |
| | | |
| | | int hcnetsdk_alarm_popwin(LONG lUserID, const HCNetCameraConfig& camConfig) |
| | |
| | | LONG lUserID; |
| | | |
| | | NET_DVR_DEVICEINFO_V30 struDeviceInfo; |
| | | lUserID = NET_DVR_Login_V30("192.168.1.101", 8000, "admin", "a1234567", &struDeviceInfo); |
| | | lUserID = NET_DVR_Login_V30((char*)g_hcnetsdkconfig.serverIP.c_str(), g_hcnetsdkconfig.serverport, |
| | | (char*)g_hcnetsdkconfig.username.c_str(), (char*)g_hcnetsdkconfig.passwd.c_str(), &struDeviceInfo); |
| | | if (lUserID < 0) { |
| | | printf("NET_DVR_Login_V30 failed, err: %d\n", NET_DVR_GetLastError()); |
| | | NET_DVR_Cleanup(); |
| | | return -1; |
| | | } |
| | | |
| | | g_hcnetsdk_user.insert(std::make_pair("192.168.1.101", int(lUserID))); |
| | | g_hcnetsdk_user.insert(std::make_pair(g_hcnetsdkconfig.serverIP, int(lUserID))); |
| | | |
| | | return lUserID; |
| | | } |
| | |
| | | timer.it_interval.tv_usec=250000; |
| | | /*Start a virtual timer.It counts down whenever this process is executing.*/ |
| | | |
| | | setitimer(ITIMER_VIRTUAL,&timer,NULL); |
| | | //setitimer(ITIMER_VIRTUAL,&timer,NULL); |
| | | |
| | | |
| | | |
| | | |
| | | while(1); |
| | | while ( 1 ) |
| | | { |
| | | zclock_sleep(250); |
| | | timer_handler(0); |
| | | } |
| | | } |
| | | |
| | | void* createServerthread_hcnetsdk(void* arg) |
| | |
| | | } |
| | | else if(length>0) |
| | | { |
| | | if (strstr(buff, "ViqEventNotificationAlert") == NULL) // <urn |
| | | if (strstr(buff, "ViqEventNotificationAlert") == NULL) // <urn |
| | | continue; |
| | | if (strstr(buff, "startTime") == NULL) // <urn |
| | | continue; |
| | | std::cout << buff<<std::endl; |
| | | //std::cout << buff<<std::endl; |
| | | if(gCapturing[eidx]==1) |
| | | { |
| | | int k; |
| | |
| | | |
| | | int Read_MysqlData() |
| | | { |
| | | static sockinfo equipments_config[1] = { |
| | | //{ |
| | | // .m_id = 1, |
| | | // .ip = "192.168.1.5", // equipmentip (analizer) |
| | | // .port = "80", // equipmentport |
| | | // .user = "supervisor", // equipment username |
| | | // .pass = "supervisor", // equipment password |
| | | // .serverIP = "192.168.1.2", // serverip (accept alarm) |
| | | // .serverport = "5015", // serverport |
| | | // .reboot = 0 |
| | | //}, |
| | | |
| | | //{ .m_id = 1, .ip = "192.168.1.5", .port = "80", .user = "supervisor", .pass = "supervisor", .serverIP = "192.168.1.2", .serverport = "5015", .reboot = 0 }, |
| | | }; |
| | | if (NUM > 0) |
| | | return 1; |
| | | |
| | | std::vector<sockinfo> equipments_config; |
| | | |
| | | std::ifstream ifs; |
| | | ifs.open("config.json"); |
| | | |
| | | Json::Reader reader; |
| | | Json::Value root; |
| | | if (!reader.parse(ifs, root, false)) |
| | | { |
| | | equipments_config[0].m_id = 1; |
| | | equipments_config[0].m_type = ET_HCNET_DECODER_ALARMOUT; |
| | | strcpy(equipments_config[0].ip, "192.168.1.5"); |
| | | strcpy(equipments_config[0].port, "80"); |
| | | strcpy(equipments_config[0].user, "supervisor"); |
| | | strcpy(equipments_config[0].pass, "supervisor"); |
| | | strcpy(equipments_config[0].serverIP, "192.168.1.101"); |
| | | strcpy(equipments_config[0].serverport, "8000"); |
| | | //strcpy(equipments_config[0].serverIP, "192.168.1.10"); |
| | | //strcpy(equipments_config[0].serverport, "5015"); |
| | | equipments_config[0].reboot = 0; |
| | | HCNetCameraConfig* camConfig = new HCNetCameraConfig; // #todo delete when exit |
| | | equipments_config[0].user_config = camConfig; |
| | | |
| | | camConfig->ip = "192.168.1.63"; |
| | | camConfig->port = 8000; |
| | | camConfig->username = "admin"; |
| | | camConfig->passwd = "admin12345"; |
| | | camConfig->channel = 1; |
| | | camConfig->byWallNo = 1; |
| | | camConfig->dwSubWinNo = 1; |
| | | camConfig->dwWinNo = 0; |
| | | camConfig->lAlarmOutPort = 0x0001; |
| | | std::cout << "open config.json error" << std::endl; |
| | | exit(EXIT_FAILURE); |
| | | } |
| | | |
| | | //HCNetSDKConfig |
| | | Json::Value jsonHcsdk = root["hcsdk"]; |
| | | g_hcnetsdkconfig.serverIP = jsonHcsdk["serverIP"].asString(); |
| | | g_hcnetsdkconfig.serverport = jsonHcsdk["serverport"].asInt(); |
| | | g_hcnetsdkconfig.username = jsonHcsdk["username"].asString(); |
| | | g_hcnetsdkconfig.passwd = jsonHcsdk["passwd"].asString(); |
| | | |
| | | memcpy(equipments, equipments_config, sizeof(equipments_config)); |
| | | NUM = sizeof(equipments_config) / sizeof(sockinfo); |
| | | Json::Value jsonEquipments = root["equipments"]; |
| | | for (int i = 0; i < jsonEquipments.size() && i < sizeof(equipments) / sizeof(sockinfo); i++) |
| | | { |
| | | Json::Value jsonEquip = jsonEquipments[i]; |
| | | |
| | | sockinfo equip; |
| | | equip.m_id = jsonEquip["id"].asInt();; |
| | | equip.m_type = (EquipmentType)jsonEquip["type"].asInt();; |
| | | strcpy(equip.ip, jsonEquip["ip"].asString().c_str()); |
| | | strcpy(equip.port, jsonEquip["port"].asString().c_str()); |
| | | strcpy(equip.serverIP, jsonEquip["serverIP"].asString().c_str()); |
| | | strcpy(equip.serverport, jsonEquip["serverport"].asString().c_str()); |
| | | strcpy(equip.user, jsonEquip["user"].asString().c_str()); |
| | | strcpy(equip.pass, jsonEquip["pass"].asString().c_str()); |
| | | equip.reboot = jsonEquip["reboot"].asInt(); |
| | | equip.user_config = NULL; |
| | | |
| | | if (equip.m_type > ET_HCNET_DECODER__FIRST || equip.m_type < ET_HCNET_DECODER__LAST) |
| | | { |
| | | Json::Value jsonUserConfig = jsonEquip["user_config"]; |
| | | |
| | | HCNetCameraConfig* camConfig = new HCNetCameraConfig; // #todo delete when exit |
| | | equip.user_config = camConfig; |
| | | |
| | | camConfig->ip = jsonUserConfig["ip"].asString(); |
| | | camConfig->port = jsonUserConfig["port"].asInt(); |
| | | camConfig->username = jsonUserConfig["username"].asString(); |
| | | camConfig->passwd = jsonUserConfig["passwd"].asString(); |
| | | camConfig->channel = jsonUserConfig["channel"].asInt(); |
| | | camConfig->byWallNo = jsonUserConfig["byWallNo"].asInt(); |
| | | camConfig->dwSubWinNo = jsonUserConfig["dwSubWinNo"].asInt(); |
| | | camConfig->dwWinNo = jsonUserConfig["dwWinNo"].asInt(); |
| | | camConfig->lAlarmOutPort = jsonUserConfig["lAlarmOutPort"].asInt(); |
| | | } |
| | | |
| | | memcpy(&(equipments[NUM]), &equip, sizeof(equip)); |
| | | NUM++; |
| | | |
| | | } |
| | | |
| | | return 1; |
| | | } |