| | |
| | | #include <vector> |
| | | #include <stdint.h> |
| | | #include <iostream> |
| | | #include <fstream> |
| | | |
| | | #include <unistd.h> |
| | | |
| | | #include <json/json.h> |
| | | |
| | | #include "MD5Linux.h" |
| | | |
| | | #include "HCNetSDK/incCn/HCNetSDK.h" |
| | | #include "HCNetSDK64/incCn/HCNetSDK.h" |
| | | #define HPR_OK 0 |
| | | #define HPR_ERROR -1 |
| | | |
| | | #define MAX_NUM 16 |
| | | #define MAX_NUM 32 |
| | | #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__FIRST, |
| | | ET_PC_SERVER, |
| | | ET_HCNET_DECODER__FIRST, |
| | | ET_HCNET_DECODER_POPWIN, |
| | | ET_HCNET_DECODER_LOGO, |
| | | ET_HCNET_DECODER_ALARMOUT, |
| | | ET_HCNET_DECODER_POPWIN, // 3 |
| | | ET_HCNET_DECODER_LOGO, // 4 |
| | | ET_HCNET_DECODER_ALARMOUT, // 5 |
| | | ET_HCNET_DECODER_LOGO_ALARMOUT, // 6 |
| | | ET_HCNET_DECODER__LAST, |
| | | ET__LAST |
| | | }; |
| | | |
| | | struct HCNetSDKConfig |
| | | { |
| | | std::string serverIP; |
| | | int serverport; |
| | | std::string username; |
| | | std::string passwd; |
| | | }; |
| | | |
| | | HCNetSDKConfig g_hcnetsdkconfig; |
| | | |
| | | struct HCNetCameraConfig |
| | | { |
| | |
| | | int channel; |
| | | uint16_t byWallNo; |
| | | uint16_t dwSubWinNo; |
| | | uint16_t dwWinNo; |
| | | std::vector<uint16_t> dwWinNo; |
| | | uint16_t lAlarmOutPort; |
| | | }; |
| | | |
| | |
| | | pthread_t thread_no[MAX_NUM]; |
| | | pthread_t thread_noEQ[MAX_NUM]; |
| | | pthread_t thread_Real[MAX_NUM]; |
| | | sockinfo equipments[16]; |
| | | int sock_upper[16],sock_down[16]; |
| | | int rsock_down[16]; |
| | | sockinfo equipments[MAX_NUM]; |
| | | int sock_upper[MAX_NUM],sock_down[MAX_NUM]; |
| | | int rsock_down[MAX_NUM]; |
| | | char byte_array[2600]; |
| | | int bbbbb=0; |
| | | int CommandEquipIdx=0; |
| | | int CommandKind[16]; |
| | | char sessionIDs[16][5]; |
| | | int CommandKind[MAX_NUM]; |
| | | char sessionIDs[MAX_NUM][5]; |
| | | |
| | | char linkequip_ip[32]; |
| | | char linkequip_port[10]; |
| | |
| | | |
| | | int NUM=0,equip_num=0; |
| | | |
| | | int SupperConnectedflag[16]={0,},EquipConnectedflag[16]={0,},serverflag=0,GPIO_flag=0; |
| | | int EquipRealAlarmConnectedflag[16]; |
| | | int SupperConnectedflag[MAX_NUM]={0,},EquipConnectedflag[MAX_NUM]={0,},serverflag=0,GPIO_flag=0; |
| | | int EquipRealAlarmConnectedflag[MAX_NUM]; |
| | | timer_t* timerID; |
| | | |
| | | std::vector<std::string> SupperConnectedIP; |
| | |
| | | int GPIO_READ(int PortNum); |
| | | void GPIO_WRITE(int PortNum,unsigned char DATA); |
| | | int RealEventStart(int Idx); |
| | | int gCapturing[16]; |
| | | char sessions[16][10]; |
| | | int gCapturing[MAX_NUM]; |
| | | char sessions[MAX_NUM][10]; |
| | | |
| | | int n=0,m=0,k=0; |
| | | unsigned char DownBuffer[16][614000]; |
| | | int DownCount[16]; |
| | | unsigned char DownBuffer[MAX_NUM][614000]; |
| | | int DownCount[MAX_NUM]; |
| | | int gCount=0; |
| | | int gCount30s=0; |
| | | int gCount2s=0; |
| | |
| | | gCount2s++; |
| | | if(gCount2s>=8){ |
| | | gCount2s=0; |
| | | for(;CommandEquipIdx<16;CommandEquipIdx++){//connected |
| | | for(;CommandEquipIdx<MAX_NUM;CommandEquipIdx++){//connected |
| | | if(EquipConnectedflag[CommandEquipIdx]>0) break; |
| | | } |
| | | if(CommandEquipIdx>=16){ |
| | | if(CommandEquipIdx>=MAX_NUM){ |
| | | CommandEquipIdx = 0; |
| | | } |
| | | } |
| | |
| | | } |
| | | SupperConnectedflag[i]=1; |
| | | SupperConnectedIP[i] = equipments[i].serverIP; |
| | | printf("server connect Success=:%s:%s\n",equipments[i].serverIP,equipments[i].serverport); |
| | | //printf("server connect Success=:%s:%s\n",equipments[i].serverIP,equipments[i].serverport); |
| | | pthread_create(&thread_no[i],NULL,&createServerthread,(void*)i);//super |
| | | } |
| | | } |
| | |
| | | |
| | | int hcnetsdk_get_userid(const std::string& decode_ip) |
| | | { |
| | | hcnetsdk_user_t::const_iterator iter = g_hcnetsdk_user.find(decode_ip); |
| | | if(iter == g_hcnetsdk_user.end()) |
| | | return -1; |
| | | else |
| | | return iter->second; |
| | | return hcnetsdk_user; |
| | | //hcnetsdk_user_t::const_iterator iter = g_hcnetsdk_user.find(decode_ip); |
| | | //if(iter == g_hcnetsdk_user.end()) |
| | | // return -1; |
| | | //else |
| | | // return iter->second; |
| | | } |
| | | |
| | | void CALLBACK hcnetsdk_ExceptionCallBack(DWORD dwType, LONG lUserID, LONG lHandle, void *pUser) |
| | |
| | | printf("hcnetsdk_ExceptionCallBack: %d\n", int(dwType)); |
| | | } |
| | | |
| | | int hcnetsdk_alarm_alarmout(LONG lUserID, const HCNetCameraConfig& camConfig) |
| | | int hcnetsdk_alarm_alarmout(LONG lUserID, const HCNetCameraConfig& camConfig, bool isDisalarm) |
| | | { |
| | | //报警时间段 |
| | | NET_DVR_SCHEDTIME net_dvr_schedtime = {0}; |
| | |
| | | } |
| | | |
| | | //开启警报 |
| | | if(NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,1) == FALSE){ |
| | | printf("NET_DVR_SetAlarmOut failed, err: %d\n", NET_DVR_GetLastError()); |
| | | //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(2); |
| | | |
| | | if (isDisalarm) |
| | | { |
| | | //if (time(NULL) - last_alarmout >= 2) |
| | | //{ |
| | | //解除警报 |
| | | NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,0); |
| | | //} |
| | | } |
| | | |
| | | sleep(3); |
| | | |
| | | //解除警报 |
| | | NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,0); |
| | | else |
| | | { |
| | | //开启警报 |
| | | if(NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,1) == FALSE){ |
| | | printf("NET_DVR_SetAlarmOut failed, err: %d\n", NET_DVR_GetLastError()); |
| | | } |
| | | last_alarmout = time(NULL); |
| | | } |
| | | } |
| | | |
| | | int hcnetsdk_alarm_popwin(LONG lUserID, const HCNetCameraConfig& camConfig) |
| | |
| | | std::cout << "hcnetsdk_alarm_popwin" << std::endl; |
| | | } |
| | | |
| | | int hcnetsdk_alarm_logo() |
| | | { |
| | | } |
| | | |
| | | void hcnetsdk_finial() |
| | | { |
| | | //NET_DVR_Logout(lUserID); //#todo |
| | | NET_DVR_Cleanup(); |
| | | } |
| | | |
| | | int hcnetsdk_init_logo(LONG lUserID) |
| | | { |
| | | //logo信息 |
| | | NET_DVR_MATRIX_LOGO_INFO net_dvr_matrix_logocfg1; |
| | | net_dvr_matrix_logocfg1.byRes[32]=0; |
| | | net_dvr_matrix_logocfg1.dwSize=0; |
| | | net_dvr_matrix_logocfg1.dwLogoSize=0; |
| | | |
| | | char logobuf[5000]; |
| | | { |
| | | FILE * pFile; |
| | | pFile = fopen("./ico.bmp","rb"); |
| | | if (pFile!=NULL) |
| | | { |
| | | net_dvr_matrix_logocfg1.dwLogoSize = fread(logobuf, 1, sizeof(logobuf), pFile); |
| | | fclose (pFile); |
| | | } |
| | | else |
| | | { |
| | | perror ("Error opening file"); |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | net_dvr_matrix_logocfg1.dwSize= sizeof(net_dvr_matrix_logocfg1); |
| | | |
| | | //上传logo |
| | | if (TRUE != NET_DVR_UploadLogo_NEW(lUserID, 1, &net_dvr_matrix_logocfg1 , logobuf)) |
| | | { |
| | | printf("NET_DVR_UploadLogo_NEW error, err: %d\n", NET_DVR_GetLastError()); |
| | | return -1; |
| | | } |
| | | else |
| | | { |
| | | printf("NET_DVR_UploadLogo_NEW done.\n"); |
| | | return 0; |
| | | } |
| | | |
| | | return -1; |
| | | } |
| | | |
| | | int hcnetsdk_init() |
| | |
| | | LONG lUserID; |
| | | |
| | | NET_DVR_DEVICEINFO_V30 struDeviceInfo; |
| | | lUserID = NET_DVR_Login_V30("192.168.1.101", 8000, "admin", "a1234567", &struDeviceInfo); |
| | | hcnetsdk_user = 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))); |
| | | |
| | | hcnetsdk_init_logo(lUserID); |
| | | |
| | | return lUserID; |
| | | } |
| | | |
| | | HCNetCameraConfig* hcnetsdk_find_config(const std::string& decoder_ip) |
| | | HCNetCameraConfig* hcnetsdk_find_config(const sockinfo& oldEquipConfig, int newChannel) |
| | | { |
| | | for (size_t i = 0; i < NUM; i++) |
| | | { |
| | |
| | | if (equip->m_type > ET_HCNET_DECODER__FIRST || equip->m_type < ET_HCNET_DECODER__LAST) |
| | | { |
| | | HCNetCameraConfig* camConfig = (HCNetCameraConfig*)equip->user_config; |
| | | if (camConfig != NULL && equip->serverIP == decoder_ip) |
| | | return camConfig; |
| | | if (camConfig != NULL && strcmp(equip->ip, oldEquipConfig.ip) == 0) |
| | | { |
| | | if (camConfig->channel == newChannel) |
| | | return camConfig; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return NULL; |
| | | } |
| | | |
| | | sockinfo* hcnetsdk_find_equip(const std::string& decoder_ip) |
| | | { |
| | | for (size_t i = 0; i < NUM; i++) |
| | | { |
| | | sockinfo* equip = &(equipments[i]); |
| | | if (equip->m_type > ET_HCNET_DECODER__FIRST || equip->m_type < ET_HCNET_DECODER__LAST) |
| | | { |
| | | if (equip->serverIP == decoder_ip) |
| | | return equip; |
| | | } |
| | | } |
| | | |
| | | return NULL; |
| | | } |
| | | |
| | | sockinfo* hcnetsdk_find_equip(const std::string& decoder_ip, int channel) |
| | | { |
| | | for (size_t i = 0; i < NUM; i++) |
| | | { |
| | | sockinfo* equip = &(equipments[i]); |
| | | if (equip->m_type > ET_HCNET_DECODER__FIRST || equip->m_type < ET_HCNET_DECODER__LAST) |
| | | { |
| | | HCNetCameraConfig* camConfig = (HCNetCameraConfig*)equip->user_config; |
| | | if (camConfig != NULL && camConfig->channel == channel && equip->serverIP == decoder_ip) |
| | | return equip; |
| | | } |
| | | } |
| | | |
| | | return NULL; |
| | | } |
| | | |
| | | int hcnetsdk_alarm_logo(LONG lUserID, const HCNetCameraConfig& _camConfig, const std::string& ip, int channel, bool disalarm) |
| | | { |
| | | HCNetCameraConfig camConfig(_camConfig); |
| | | //if (camConfig.channel != channel) |
| | | //{ |
| | | // camConfig.channel = -1; |
| | | // sockinfo* equipConfig = hcnetsdk_find_equip(ip, channel); |
| | | // if (equipConfig != NULL) |
| | | // camConfig = *(HCNetCameraConfig*)(equipConfig->user_config); |
| | | //} |
| | | |
| | | printf("hcnetsdk_alarm_logo, channel=%d, matchc=%d\n", channel, camConfig.channel); |
| | | |
| | | if (camConfig.channel < 0) |
| | | return -1; |
| | | |
| | | //窗口配置信息 |
| | | NET_DVR_WIN_LOGO_CFG net_dvr_win_logo_cfg; |
| | | net_dvr_win_logo_cfg.dwLogoNo = 1; |
| | | net_dvr_win_logo_cfg.byEnable = (disalarm ? 0 : 1);//0:hidden,1:visible |
| | | net_dvr_win_logo_cfg.byRes1[3] =0; |
| | | net_dvr_win_logo_cfg.dwCoordinateX = 5; |
| | | net_dvr_win_logo_cfg.dwCoordinateY =5; |
| | | net_dvr_win_logo_cfg.byFlash = 1; |
| | | net_dvr_win_logo_cfg.byTranslucent = 0; |
| | | net_dvr_win_logo_cfg.byRes2[34] = 0; |
| | | |
| | | net_dvr_win_logo_cfg.dwSize = sizeof(net_dvr_win_logo_cfg); |
| | | //设置窗口输出logo |
| | | int byWallNo=1,dwSubWinNo=2,dwWinNo=1; |
| | | |
| | | for (int i= 0; i < camConfig.dwWinNo.size(); i++) |
| | | { |
| | | DWORD dwDecChanNum=(camConfig.byWallNo << 24) | (camConfig.dwSubWinNo << 16) | camConfig.dwWinNo[i]; |
| | | if(!NET_DVR_SetDVRConfig(lUserID,NET_DVR_SET_WIN_LOGO_CFG,dwDecChanNum,&net_dvr_win_logo_cfg,net_dvr_win_logo_cfg.dwSize)) |
| | | { |
| | | printf("NET_DVR_SetDVRConfig2 error, err: %d\n", NET_DVR_GetLastError()); |
| | | //return -1; |
| | | } |
| | | else |
| | | { |
| | | printf("NET_DVR_SetDVRConfig2 done.\n"); |
| | | //return 0; |
| | | } |
| | | } |
| | | |
| | | return 0; |
| | | |
| | | //sleep(3); |
| | | //net_dvr_win_logo_cfg.byEnable = 0; |
| | | //NET_DVR_SetDVRConfig(lUserID,NET_DVR_SET_WIN_LOGO_CFG,dwDecChanNum,&net_dvr_win_logo_cfg,net_dvr_win_logo_cfg.dwSize); |
| | | } |
| | | |
| | | |
| | | int hcnetsdk_alarm_logo_alarmout(LONG lUserID, const HCNetCameraConfig& _camConfig, const std::string& ip, int channel, bool disalarm) |
| | | { |
| | | HCNetCameraConfig camConfig(_camConfig); |
| | | //if (camConfig.channel != channel) |
| | | //{ |
| | | // camConfig.channel = -1; |
| | | // sockinfo* equipConfig = hcnetsdk_find_equip(ip, channel); |
| | | // if (equipConfig != NULL) |
| | | // camConfig = *(HCNetCameraConfig*)(equipConfig->user_config); |
| | | //} |
| | | |
| | | printf("hcnetsdk_alarm_logo, channel=%d, matchc=%d\n", channel, camConfig.channel); |
| | | |
| | | if (camConfig.channel < 0) |
| | | return -1; |
| | | |
| | | //窗口配置信息 |
| | | NET_DVR_WIN_LOGO_CFG net_dvr_win_logo_cfg; |
| | | net_dvr_win_logo_cfg.dwLogoNo = 1; |
| | | net_dvr_win_logo_cfg.byEnable = (disalarm ? 0 : 1);//0:hidden,1:visible |
| | | net_dvr_win_logo_cfg.byRes1[3] =0; |
| | | net_dvr_win_logo_cfg.dwCoordinateX = 5; |
| | | net_dvr_win_logo_cfg.dwCoordinateY =5; |
| | | net_dvr_win_logo_cfg.byFlash = 1; |
| | | net_dvr_win_logo_cfg.byTranslucent = 0; |
| | | net_dvr_win_logo_cfg.byRes2[34] = 0; |
| | | |
| | | net_dvr_win_logo_cfg.dwSize = sizeof(net_dvr_win_logo_cfg); |
| | | //设置窗口输出logo |
| | | int byWallNo=1,dwSubWinNo=2,dwWinNo=1; |
| | | |
| | | for (int i= 0; i < camConfig.dwWinNo.size(); i++) |
| | | { |
| | | DWORD dwDecChanNum=(camConfig.byWallNo << 24) | (camConfig.dwSubWinNo << 16) | camConfig.dwWinNo[i]; |
| | | if(!NET_DVR_SetDVRConfig(lUserID,NET_DVR_SET_WIN_LOGO_CFG,dwDecChanNum,&net_dvr_win_logo_cfg,net_dvr_win_logo_cfg.dwSize)) |
| | | { |
| | | printf("NET_DVR_SetDVRConfig2 error, err: %d\n", NET_DVR_GetLastError()); |
| | | //return -1; |
| | | } |
| | | else |
| | | { |
| | | printf("NET_DVR_SetDVRConfig2 done.\n"); |
| | | //return 0; |
| | | } |
| | | } |
| | | |
| | | //if (!disalarm) |
| | | //{ |
| | | //int hcnetsdk_alarm_alarmout(LONG lUserID, const HCNetCameraConfig& camConfig) |
| | | hcnetsdk_alarm_alarmout(lUserID, camConfig, disalarm); |
| | | //} |
| | | |
| | | return 0; |
| | | |
| | | //sleep(3); |
| | | //net_dvr_win_logo_cfg.byEnable = 0; |
| | | //NET_DVR_SetDVRConfig(lUserID,NET_DVR_SET_WIN_LOGO_CFG,dwDecChanNum,&net_dvr_win_logo_cfg,net_dvr_win_logo_cfg.dwSize); |
| | | } |
| | | |
| | | |
| | | int main(int argc,char **argv) |
| | | { |
| | |
| | | if (hcnetsdk_user < 0) |
| | | { |
| | | printf("hcnetsdk_user < 0"); |
| | | exit(EXIT_FAILURE); |
| | | exit(EXIT_FAILURE);//#todo if debug equipment(analizer), remove this |
| | | } |
| | | |
| | | /*Install timer_handler as th siganl handler for SIGVTALRM */ |
| | |
| | | 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) |
| | |
| | | } |
| | | data[idx++]=0x16; |
| | | write(sock_upper[sidx],&data,idx);//send to equipment; |
| | | printf("Send equipment's info to Server OK! len=:%d\n",idx); |
| | | //printf("Send equipment's info to Server OK! len=:%d\n",idx); |
| | | //=======================================data================================================ |
| | | while(1) |
| | | { |
| | | int j; |
| | | length=read(sock_upper[sidx],&buff,sizeof(buff)-1); |
| | | printf("from Server received data===============:%d\n",length); |
| | | //printf("from Server received data===============:%d\n",length); |
| | | if(length<=0) |
| | | { |
| | | printf(" Upper Socket closed \n"); |
| | | //printf(" Upper Socket closed \n"); |
| | | break; |
| | | } |
| | | else { |
| | |
| | | // length-=3; |
| | | // if(length<=0) continue; |
| | | //} |
| | | |
| | | |
| | | if(buff[0]==0x68 && buff[1]==0x03 ) |
| | | { |
| | | |
| | |
| | | continue; |
| | | } |
| | | } |
| | | puts("Server Thread is stoped.."); |
| | | //puts("Server Thread is stoped.."); |
| | | close(sock_upper[sidx]); |
| | | sock_upper[sidx] = -1; |
| | | SupperConnectedflag[sidx]=0;//?//#todo |
| | |
| | | void* MyEquipmentthread(void* arg) |
| | | { |
| | | int eidx = (int)arg; |
| | | const sockinfo& equipConfig(equipments[eidx]); |
| | | printf("Step.3 ===%d=====>RealTimeEvent Thread is strarted......\n",eidx); |
| | | |
| | | int length=0; |
| | |
| | | } |
| | | else if(length>0) |
| | | { |
| | | if (strstr(buff, "ViqEventNotificationAlert") == NULL) // <urn |
| | | std::cout << "buff: " << buff<<std::endl; |
| | | |
| | | bool isDisalarm = false; |
| | | if (strstr(buff, "ViqEventNotificationAlert") == NULL) // <urn |
| | | continue; |
| | | if (strstr(buff, "startTime") == NULL) // <urn |
| | | continue; |
| | | std::cout << buff<<std::endl; |
| | | isDisalarm = true; |
| | | |
| | | int channel = -1; |
| | | { |
| | | const char* strChannel = strstr(buff, "<urn:channelId>"); |
| | | if (strChannel != NULL) |
| | | { |
| | | channel = strtol(strChannel + strlen("<urn:channelId>"), NULL, 10); |
| | | } |
| | | } |
| | | |
| | | if (channel==1) |
| | | { |
| | | int aa=1;//#todo break |
| | | } |
| | | |
| | | if(gCapturing[eidx]==1) |
| | | { |
| | | //add 20170327 |
| | | const std::string& ip(equipConfig.ip); |
| | | const HCNetCameraConfig* camConfig = (HCNetCameraConfig*)equipConfig.user_config; |
| | | camConfig = hcnetsdk_find_config(equipConfig, channel); |
| | | int lUserData = hcnetsdk_get_userid(ip); |
| | | if (camConfig != NULL && hcnetsdk_user >= 0) |
| | | { |
| | | std::cout << "......alarm begin k=" << k << std::endl; |
| | | if (equipConfig.m_type == ET_HCNET_DECODER_ALARMOUT && !isDisalarm) |
| | | hcnetsdk_alarm_alarmout(lUserData, *camConfig, isDisalarm); |
| | | else if (equipConfig.m_type == ET_HCNET_DECODER_LOGO) |
| | | hcnetsdk_alarm_logo(lUserData, *camConfig, ip, channel, isDisalarm); |
| | | else if (equipConfig.m_type == ET_HCNET_DECODER_LOGO_ALARMOUT) |
| | | hcnetsdk_alarm_logo_alarmout(lUserData, *camConfig, ip, channel, isDisalarm); |
| | | std::cout << "......alarm end k=" << k << std::endl; |
| | | } |
| | | else |
| | | { |
| | | std::cout << "alarm lost k=" << k << std::endl; |
| | | } |
| | | |
| | | |
| | | int k; |
| | | for(k=0;k<16;k++) |
| | | for(k=0;k<MAX_NUM;k++) |
| | | { |
| | | //if(SupperConnectedflag[k]==1) |
| | | //{ |
| | |
| | | //printf("%s",buff); |
| | | //} |
| | | //else |
| | | { |
| | | if(SupperConnectedIP.size() > k) |
| | | { |
| | | const std::string& ip(SupperConnectedIP[k]); |
| | | HCNetCameraConfig* camConfig = hcnetsdk_find_config(ip); |
| | | int lUserData = hcnetsdk_get_userid(ip); |
| | | if (camConfig != NULL && lUserData >= 0) |
| | | { |
| | | std::cout << "alarm begin k=" << k << std::endl; |
| | | hcnetsdk_alarm_alarmout(lUserData, *camConfig); |
| | | std::cout << "alarm end k=" << k << std::endl; |
| | | } |
| | | else |
| | | { |
| | | //std::cout << "alarm lost k=" << k << std::endl; |
| | | } |
| | | } |
| | | } |
| | | //{ |
| | | // if(SupperConnectedIP.size() > k) |
| | | // { |
| | | // const std::string& ip(SupperConnectedIP[k]); |
| | | // sockinfo* equipConfig = hcnetsdk_find_equip(ip); |
| | | // HCNetCameraConfig* camConfig = hcnetsdk_find_config(ip); |
| | | // int lUserData = hcnetsdk_get_userid(ip); |
| | | // if (camConfig != NULL && equipConfig != NULL && lUserData >= 0) |
| | | // { |
| | | // std::cout << "......alarm begin k=" << k << std::endl; |
| | | // if (equipConfig->m_type == ET_HCNET_DECODER_ALARMOUT && !isDisalarm) |
| | | // hcnetsdk_alarm_alarmout(lUserData, *camConfig); |
| | | // else if (equipConfig->m_type == ET_HCNET_DECODER_LOGO) |
| | | // hcnetsdk_alarm_logo(lUserData, *camConfig, ip, channel, isDisalarm); |
| | | // std::cout << "......alarm end k=" << k << std::endl; |
| | | // } |
| | | // else |
| | | // { |
| | | // std::cout << "alarm lost k=" << k << std::endl; |
| | | // } |
| | | // } |
| | | //} |
| | | } |
| | | continue; |
| | | } |
| | |
| | | |
| | | 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(); |
| | | |
| | | Json::Value dwWinNoArrays = jsonUserConfig["dwWinNo"]; |
| | | if (dwWinNoArrays.isArray()) |
| | | { |
| | | const int s = (int)(dwWinNoArrays.size()); |
| | | for(int i = 0; i < s; i++) |
| | | { |
| | | camConfig->dwWinNo.push_back(dwWinNoArrays[i].asInt()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | camConfig->dwWinNo.push_back(dwWinNoArrays.asInt()); |
| | | } |
| | | |
| | | camConfig->lAlarmOutPort = jsonUserConfig["lAlarmOutPort"].asInt(); |
| | | } |
| | | |
| | | memcpy(&(equipments[NUM]), &equip, sizeof(equip)); |
| | | NUM++; |
| | | |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | |
| | | int i; |
| | | int retVal; |
| | | int result; |
| | | printf("Step.3 ========>GPIO manupulation===> AnalyEquipmentNum=%d \n",equip_num); |
| | | //printf("Step.3 ========>GPIO manupulation===> AnalyEquipmentNum=%d \n",equip_num); |
| | | for(i=0;i<equip_num;i++) |
| | | { |
| | | retVal = -1; |
| | | result=-1; |
| | | printf("=============================:%d \n",equipments[i].reboot); |
| | | //printf("=============================:%d \n",equipments[i].reboot); |
| | | result=net_test(equipments[i].ip,equipments[i].port); |
| | | if(result<0) |
| | | { |
| | | printf("Equipment(%d) check=%s:%s\n",i+1,equipments[i].ip,equipments[i].port); |
| | | //printf("Equipment(%d) check=%s:%s\n",i+1,equipments[i].ip,equipments[i].port); |
| | | retVal = GPIO_OPEN(PortNum); |
| | | if(retVal == 0) |
| | | { |
| | |
| | | } |
| | | else printf("GPIO OPEN FAIL! \n"); |
| | | } |
| | | else printf("Equipment(%d) Check Success!=%s:%s\n",i+1,equipments[i].ip,equipments[i].port); |
| | | else |
| | | { |
| | | //printf("Equipment(%d) Check Success!=%s:%s\n",i+1,equipments[i].ip,equipments[i].port); |
| | | } |
| | | } |
| | | } |
| | | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| | |
| | | return n; |
| | | } |
| | | //for real event |
| | | void MakeAuthorizedPacketReal(char* buff,int length, char* Method,char* uri,int Idx) |
| | | void MakeAuthorizedPacketReal_Digest(char* buff,int length, char* Method,char* uri,int Idx) |
| | | { |
| | | char Device[150] ; |
| | | char Realm_buf1[512] ; |
| | |
| | | memset(domain_buf4,0,512); |
| | | |
| | | CharToByte((char*)buff, Device, length,Realm_buf1,nonce_buf2,auth_buf3,domain_buf4, len); |
| | | const char* cnonce_buf="163acd0e58793a190f29ee879d4b224f";//"08a9d86c1b5e45963cf82f43dca59c51"; |
| | | const char* cnonce_buf="1oBAAAqkwXP9q9MorVCzgw5LNPc";//"08a9d86c1b5e45963cf82f43dca59c51"; |
| | | Realm_buf1[len[0]]=0; |
| | | nonce_buf2[len[1]]=0; |
| | | auth_buf3[len[2]]=0; |
| | |
| | | byte_array[iidx]=0; |
| | | |
| | | } |
| | | |
| | | void MakeAuthorizedPacketReal_Basic(char* buff,int length, char* Method,char* uri,int Idx) |
| | | { |
| | | /* |
| | | POST /PSIA/VIQ/System/sessions HTTP/1.1 |
| | | Content-Length: 0 |
| | | Host: 192.168.1.5:80 |
| | | Connection: Keep-Alive |
| | | Authorization: Basic c3VwZXJ2aXNvcjpzdXBlcnZpc29y |
| | | */ |
| | | |
| | | int i = 0; |
| | | sprintf(byte_array, |
| | | "%s %s HTTP/1.1\r\n" |
| | | "Content-Length: 0\r\n" |
| | | "Host: %s:80\r\n" |
| | | "Connection: Keep-Alive\r\n" |
| | | "Authorization: Basic %s\r\n" |
| | | "\r\n", |
| | | Method, |
| | | uri, |
| | | equipments[Idx].ip, |
| | | "c3VwZXJ2aXNvcjpzdXBlcnZpc29y" // base64(supervisor:supervisor) |
| | | ); |
| | | } |
| | | |
| | | //// 功能:开始查看实时监控 |
| | | //// 输入:分析器IP,用户,密码 |
| | | //// 输出:0(成功), -1(初始化失败),-2(连接失败) |
| | |
| | | sigset(SIGALRM, u_alarm_handler);//add 2016.11.22 |
| | | alarm(2); |
| | | length=read(rsock_down[Idx],&buff,sizeof(buff)); |
| | | //printf("RESPONSE: %s\n",&buff); |
| | | alarm(0); |
| | | sigrelse(SIGALRM); |
| | | printf("Myequipment connect ==================length =%d:\n",length); |
| | | //printf("Myequipment connect ==================length =%d:\n",length); |
| | | if(length<=0) |
| | | { |
| | | close(rsock_down[Idx]); |
| | |
| | | if(memorycmp((unsigned char*)buff,length, "WWW-Authenticate:",17)>0 && bbbb==0) |
| | | { |
| | | // analyse reception |
| | | MakeAuthorizedPacketReal(buff,length,"POST","/PSIA/VIQ/System/sessions/permanent",Idx); |
| | | zclock_sleep(100); |
| | | write(rsock_down[Idx],byte_array,strlen(byte_array)); |
| | | // printf("%s\n",(char*)byte_array); |
| | | MakeAuthorizedPacketReal_Basic(buff,length,"POST","/PSIA/VIQ/System/sessions/permanent",Idx); |
| | | //for(int ii=0;ii<4;ii++) |
| | | //{ |
| | | zclock_sleep(100); |
| | | write(rsock_down[Idx],byte_array,strlen(byte_array)); |
| | | //} |
| | | printf("%s\n",(char*)byte_array); |
| | | bbbb=1; |
| | | continue; |
| | | continue;//#todo 20170325 |
| | | //break; |
| | | } |
| | | if(bbbb==1){ |
| | | //if (strstr((char*)buff,"Unauthorized") != NULL) |
| | | //{ |
| | | // bbbb=0; |
| | | //} |
| | | |
| | | int sidx = stringcmp((char*)buff,"<urn:id>",8); |
| | | if(sidx >=0){//<urn:ViqDateTimeInterval urn:version="1.0" xmlns:urn="urn:videoiq-com"><urn:startTime urn:version="1.0"><urn:date>2016-08-18T01:07:20.749</urn:date><urn:offset>0</urn:offset></urn:startTime><urn:endTime urn:version="1.0"><urn:date>2016-08-29T08:33:48.231</urn:date><urn:offset>0</urn:offset></urn:endTime></urn:ViqDateTimeInterval> |
| | | int eidx = stringcmp((char*)buff,"</urn:id>",9); |
| | |
| | | } |
| | | char uri[200]; |
| | | sprintf(uri,"/PSIA/Custom/Event/notification/notificationStream?sessionId=%s",sessions[Idx]); |
| | | //sprintf(uri,"/PSIA/Custom/Event/notification/notificationStream?sessionId=5"); |
| | | printf("/PSIA/Custom/Event/notification/notificationStream?sessionId=%s\n",sessions[Idx]); |
| | | length = sprintf(byte_array,"GET %s HTTP/1.1\r\nContent-Type: text/xml\r\nHost: %s\r\nContent-Length: 0\r\nConnection: Keep-Alive\r\n\r\n",uri,equipments[Idx].ip); |
| | | write(rsock_down[Idx],byte_array,strlen(byte_array)); |
| | | while(1){ |
| | |
| | | { |
| | | char uri[200]; |
| | | sprintf(uri,"/PSIA/Custom/Event/notification/notificationStream?sessionId=%s",sessions[Idx]); |
| | | MakeAuthorizedPacketReal(buff,length,"GET",uri,Idx); |
| | | MakeAuthorizedPacketReal_Basic(buff,length,"GET",uri,Idx); |
| | | //for(int ii=0;ii<4;ii++) |
| | | //{ |
| | | zclock_sleep(100); |
| | | write(rsock_down[Idx],byte_array,strlen(byte_array)); |
| | | // printf("%s\n",(char*)byte_array); |
| | | //} |
| | | printf("%s\n",(char*)byte_array); |
| | | bbbb=3; |
| | | continue; |
| | | } |