houxiao
2017-01-20 5419fe2dc93bde4d2f19489c6b79ec92bbb39181
add alarm logo

git-svn-id: http://192.168.1.226/svn/proxy@97 454eff88-639b-444f-9e54-f578c98de674
1个文件已添加
2个文件已修改
237 ■■■■ 已修改文件
ProxyConsole/config.json 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ProxyConsole/ico.bmp 补丁 | 查看 | 原始文档 | blame | 历史
ProxyConsole/proxyconsole-hc.cpp 179 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ProxyConsole/config.json
@@ -11,7 +11,7 @@
        {
            "id" : 1,
            "type" : 4,
            "type_str" : "ET_HCNET_DECODER_ALARMOUT",
            "type_str" : "ET_HCNET_DECODER_LOGO",
            "ip" : "192.168.1.5",
            "port" : "80",
            "user" : "supervisor",
@@ -22,14 +22,64 @@
            "reboot" : 0,
            
            "user_config" : {
                "ip" : "192.168.1.63",
                "ip" : "192.168.1.64",
                "port" : 8000,
                "username" : "admin",
                "passwd" : "admin12345",
                "channel" : 0,
                "byWallNo" : 1,
                "dwSubWinNo" : 1,
                "dwWinNo" : 1,
                "lAlarmOutPort" : 1
            }
        },
        {
            "id" : 1,
            "type" : 4,
            "type_str" : "ET_HCNET_DECODER_LOGO",
            "ip" : "192.168.1.5",
            "port" : "80",
            "user" : "supervisor",
            "pass" : "supervisor",
            "serverIP" : "192.168.1.101",
            "serverport" : "8000",
            "reboot" : 0,
            "user_config" : {
                "ip" : "192.168.1.66",
                "port" : 8000,
                "username" : "admin",
                "passwd" : "admin12345",
                "channel" : 1,
                "byWallNo" : 1,
                "dwSubWinNo" : 1,
                "dwWinNo" : 0,
                "dwSubWinNo" : 2,
                "dwWinNo" : 1,
                "lAlarmOutPort" : 1
            }
        },
        {
            "id" : 1,
            "type" : 4,
            "type_str" : "ET_HCNET_DECODER_LOGO",
            "ip" : "192.168.1.5",
            "port" : "80",
            "user" : "supervisor",
            "pass" : "supervisor",
            "serverIP" : "192.168.1.101",
            "serverport" : "8000",
            "reboot" : 0,
            "user_config" : {
                "ip" : "192.168.1.66",
                "port" : 8000,
                "username" : "admin",
                "passwd" : "admin12345",
                "channel" : 2,
                "byWallNo" : 1,
                "dwSubWinNo" : 3,
                "dwWinNo" : 1,
                "lAlarmOutPort" : 1
            }
        }
ProxyConsole/ico.bmp
ProxyConsole/proxyconsole-hc.cpp
@@ -51,9 +51,9 @@
    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__LAST,
    ET__LAST
};
@@ -231,7 +231,7 @@
                }
                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
            }
        }
@@ -422,14 +422,51 @@
    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()
@@ -452,6 +489,8 @@
    
    g_hcnetsdk_user.insert(std::make_pair(g_hcnetsdkconfig.serverIP, int(lUserID)));
    
    hcnetsdk_init_logo(lUserID);
    return lUserID;
}
@@ -469,6 +508,84 @@
    }
    
    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;
    DWORD dwDecChanNum=(camConfig.byWallNo << 24) | (camConfig.dwSubWinNo << 16) | camConfig.dwWinNo;
    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;
    }
    //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)
@@ -536,7 +653,7 @@
   int length=0;
   char buff[102400];
  
   puts("Step.1 ========>Server Thread is strarted......");
   //puts("Step.1 ========>Server Thread is strarted......");
   unsigned char data[4096];  
  //=======================================equipment data================================
  int idx=0;  
@@ -555,16 +672,16 @@
  }
  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 {            
@@ -636,7 +753,7 @@
            continue;
        }
  }
  puts("Server Thread is stoped..");
  //puts("Server Thread is stoped..");
  close(sock_upper[sidx]);
  sock_upper[sidx] = -1;
  SupperConnectedflag[sidx]=0;//?//#todo
@@ -692,7 +809,7 @@
void* MyEquipmentthread(void* arg)
 {
   int eidx = (int)arg;   
   printf("Step.3 ===%d=====>RealTimeEvent Thread is strarted......\n",eidx);
   //printf("Step.3 ===%d=====>RealTimeEvent Thread is strarted......\n",eidx);
   int length=0;
   char buff[102400];
@@ -707,11 +824,22 @@
        }
       else if(length>0)
       {
           bool isDisalarm = false;
            if (strstr(buff, "ViqEventNotificationAlert") == NULL) // <urn
                continue;
            if (strstr(buff, "startTime") == NULL) // <urn
                continue;
                isDisalarm = true;
            //std::cout << buff<<std::endl;
            int channel = -1;
            {
                const char* strChannel = strstr(buff, "<urn:channelId>");
                if (strChannel != NULL)
                {
                    channel = strtol(strChannel + strlen("<urn:channelId>"), NULL, 10);
                }
            }
            if(gCapturing[eidx]==1)
            {
                int k;
@@ -753,12 +881,16 @@
                        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 && lUserData >= 0)
                            if (camConfig != NULL && equipConfig != NULL && lUserData >= 0)
                            {
                                std::cout << "alarm begin k=" << k << std::endl;
                                hcnetsdk_alarm_alarmout(lUserData, *camConfig);
                                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
@@ -1060,16 +1192,16 @@
   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)
                            {
@@ -1079,7 +1211,10 @@
                             }
                        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);
           }
    }  
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1327,7 +1462,7 @@
        length=read(rsock_down[Idx],&buff,sizeof(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]);