📄 net_cmd.cpp
字号:
//cb是发向video_channel的消息句柄
POST_NOTIFY(cmdcb, NTM_CMD_CHANNEL_OPENED, last_ip, MAKEDWORD(last_port, channel));
}
// 关闭实时图像成功
if( CMD_OF(buf) is NETCOM_CLOSE_REALIMAGE_OK )
{
int channel = DATA_OF(buf)[0];
}
//////////////////////////////////////////////////////////////////////////
if( (CMD_OF(buf) >= NETCOM_SETSYSTIME_CTRL &&
CMD_OF(buf) <= NETCOM_SET_VIDEOPARA) ) // 远程设置的回复
{
// SET ok
if( CMD_OF(buf) % 2 is 0 )
{
// for( int e=0; e<sc.cb.size(); e++ )
// {
// set_cb::callee& ref = sc.cb[e];
// ref->on_set_ok(last_ip, last_port, trans_net_com(CMD_OF(buf)) );
// }
// sc.clear_cb();
ip_port ipport(from->ip(),last_port);
SEND_NOTIFY(sc, NTM_OPT_SET_OK, trans_net_com(CMD_OF(buf)), (LPARAM)&ipport);
}
// GET ok
else
{
// for( int e=0; e<gc.cb.size(); e++ )
// {
// get_cb::callee& ref = gc.cb[e];
// ref->on_get_ok(last_ip, last_port, trans_net_com(CMD_OF(buf)), DATA_OF(buf));
// }
// gc.clear_cb();
if( CMD_OF(buf) is NETCOM_GETALARMREC_CTRL )
{
TREC_ALARMRECPARA* p = (TREC_ALARMRECPARA*)DATA_OF(buf);
shift(p->recchannel);
}
// byte *ptr ;
// ptr = DATA_OF(buf) ;
// fprintf(fppppp, "rcv get ok! %ld (%02x %02x %02x)...\n", CMD_OF(buf), *ptr, *(ptr+1), *(ptr+2)) ;
SEND_NOTIFY(gc, NTM_OPT_GET_OK, trans_net_com(CMD_OF(buf)), (LPARAM)(DATA_OF(buf)));
}
}
if( CMD_OF(buf) is NET_GET_16_MOTION_AREA)
{
SEND_NOTIFY(gc, NTM_OPT_GET_16_OK, (WPARAM)(DATA_OF(buf)), 0);
}
if( CMD_OF(buf) is NET_GET_4_MOTION_AREA)
{
SEND_NOTIFY(gc, NTM_OPT_GET_4_OK, (WPARAM)(DATA_OF(buf)), 0);
}
if( CMD_OF(buf) is NETCOM_RECORD_DATE || CMD_OF(buf) is NETCOM_RECORD_DATE_EXT ||
CMD_OF(buf) is NETCOM_RECORD_FILE || CMD_OF(buf) is NETCOM_RECORD_FILE_EXT )
{
// for( int e=0; e<gc.cb.size(); e++ )
// {
// get_cb::callee& ref = gc.cb[e];
// ref->on_get_ok(last_ip, last_port, trans_net_com(CMD_OF(buf)), DATA_OF(buf));
// }
// gc.clear_cb();
SEND_NOTIFY(gc, NTM_OPT_GET_OK, trans_net_com(CMD_OF(buf)), (LPARAM)(DATA_OF(buf)));
}
// 视频点播 开始
//
if (CMD_OF(buf) is NETCOM_VOD_RECFILE_OK) {
ULONG mip = *(DWORD*)DATA_OF(buf) ;
USHORT mport = *(USHORT*)DATA_OF(buf+sizeof(ULONG));
if(av[vod_group]->is_opened()) return;
if(!av[vod_group]->open_channel(from->ip(), last_port, mip, mport, VOD_GROUP))
return;
av[vod_group]->set_play_mode(VS_PLAYx1);
nVodLostVideoNum[vod_group] = nVodListRr[vod_group] = nVodListWr[vod_group] = 0 ;
if(m_vod_mport) mport = m_vod_mport;
vod_if[vod_group].mport = mport;
m_vod_mport = 0;
if(!timer_vod_ctl_pal.is_started())
timer_vod_ctl_pal.start(8, ::request_vod_frame, NULL);
if(!timer_vod_ctl_ntsc.is_started())
timer_vod_ctl_ntsc.start(vod_interval_ntsc, ::request_vod_frame_ntsc, NULL);
unsigned char SndBuf[30] ;
set_cmd_header((char *)SndBuf) ;
SndBuf[4] = NET_CLIENT_BURROW1 ;
SndBuf[5] = (mport>>8);
SndBuf[6] = mport & 0x00ff;
net_addr ad(from->ip(), htons(last_port)) ;
av[vod_group]->send(SndBuf, 7, ad) ;
}
if( CMD_OF(buf) is NETCOM_VOD_RECFILE_END )
{
USHORT mport = *(USHORT*)DATA_OF(buf);
for(int i=0;i<max_channel;i++)
{
if((from->ip() == vod_if[i].ip)&&(mport == vod_if[i].mport))
{
close_vod(vod_if[i].group);
break;
}
}
SEND_NOTIFY(gc, NTM_OPT_GET_OK, trans_net_com(CMD_OF(buf)), (LPARAM)(DATA_OF(buf)));
}
unsigned long rip = from->ip() ;
unsigned short rport = from->port() ;
//获得硬盘信息
/*if( CMD_OF(buf) is NETCOM_DISKINFO_OK )
{
DISK_SPACE m_disk_space;
m_disk_space = *(DISK_SPACE *)DATA_OF(buf);
SEND_NOTIFY(cmdcb, NTM_DISK_INFO_GET_OK, (WPARAM)(DATA_OF(buf)), 0);
}*/
//对讲
if (CMD_OF(buf) is NETCOM_TALK_OK) {
USHORT port = 0 ;
if (length < 6)
port = trans_port(3357) ;
else
port = *(USHORT*)DATA_OF(buf) ;
for (int i=0;i<MAX_TALKING_THREAD_NUM;i++) {
if (talk_ip[i] == rip) {
net_addr na((ULONG)0, port) ;
if(!ptalkTh[i]->create(na,2))
{
clear_talk(rip, last_port) ;
POST_NOTIFY(talkcb, NTM_TALK_FAILED, rip, last_port) ;
break;
}
ptalkTh[i]->m_send_buf.ClearAudioBuffer();
ptalkTh[i]->SetConnectIp(rip);
ptalkTh[i]->backup_is_start = true;
if(!m_psound.is_record())
m_psound.Start();
POST_NOTIFY(talkcb, NTM_TALK_BEGIN, rip, talk_port[i]);
break ;
}
}
}
if( CMD_OF(buf) is NETCOM_TALK_NOTOK)
{
clear_talk(rip, last_port) ;
POST_NOTIFY(talkcb, NTM_TALK_FAILED, rip, last_port) ;
}
// 备份
if (CMD_OF(buf) is NETCOM_BACKUP_RECFILE_OK) {
USHORT port = 0 ;
if (length < 6)
port = trans_port(3357) ;
else
port = *(USHORT*)DATA_OF(buf) ;
for (int i=0;i<MAX_BACKUP_THREAD_NUM;i++) {
if (bk_ip[i] == rip) {
net_addr na((ULONG)0, port) ;
if(!pBackupTh[i]->create(na,1))
{
POST_NOTIFY(bkcb, NTM_BK_FAILED, rip, 0) ;
clear_backup(rip, rport) ;
break;
}
pBackupTh[i]->SetConnectIp(rip) ;
pBackupTh[i]->backup_is_start = true;
POST_NOTIFY(bkcb, NTM_BK_BEGIN, rip, 0) ;
break ;
}
}
}
if( CMD_OF(buf) is NETCOM_BACKUP_RECFILE_NOK)
{
POST_NOTIFY(bkcb, NTM_BK_FAILED, rip, 0) ;
clear_backup(rip, rport) ;
}
if( CMD_OF(buf) is NETCOM_BACKUP_STOP_OK )
{
POST_NOTIFY(bkcb, NTM_BK_CANCELED, rip, 0);
clear_backup(rip, rport) ;
}
if( CMD_OF(buf) is NETCOM_BACKUP_END )
{
POST_NOTIFY(bkcb, NTM_BK_FINISHED, rip, 0) ;
clear_backup(rip, rport) ;
}
//
if( CMD_OF(buf) is NETCOM_SHAKE_HAND )
{
if(length < 17)
{
byte * temp = (byte *)DATA_OF(buf+10);
temp[0]=0;
temp[1]=0;
}
process_disconnect(rip, last_port);
process_alarm(from, DATA_OF(buf)) ;
}
if( CMD_OF(buf) is NET_ZH_DECSTATE )
{
SEND_NOTIFY(cmdcb, NTM_ZH_DECSTATE_GET_OK, (WPARAM)(DATA_OF(buf)), rip);
}
}
#define IS_BIT_SET(x, y) ((x & (1<<y)) == (1<<y))
void net_cmd::process_disconnect(ULONG ip, USHORT port)
{
for(int i=0;i<m_loginlength;i++)
{
if(ip == login_if[i].ip && port == login_if[i].port)
{
login_if[i].connecttime = 0;
break;
}
}
}
/*
* 2003-10-12, nodman
* 处理握手通讯传来的报警信息
*/
//##ModelId=3F9A1D2301F9
void net_cmd::process_alarm(net_addr* from, byte* data)
{
// 消息格式: NETCOM_SHAKE_HAND (4 bytes版本信息) (2 bytes探头报警) (2 bytes移动报警) (2 bytes视频丢失报警)
ULONG ip = from->ip();
TREC_ALARMINFO *pAlarm = (TREC_ALARMINFO *)data ;
if (connected.empty())
return ;
for (pit it = connected.begin(); it != connected.end(); it++)
{
server& ref = *it ;
if (ref.ip() == ip)
{
if (!(pAlarm->version == ref.alarm_info.version))
{
POST_NOTIFY(cmdcb, NTM_ALARM_VERSION, ip, (LONG)pAlarm->version);
}
if(pAlarm->probe_alarm != ref.alarm_info.probe_alarm)
{
post_alarm_message(ip, pAlarm->probe_alarm, 0);
}
if(pAlarm->motion_alarm != ref.alarm_info.motion_alarm)
{
post_alarm_message(ip, pAlarm->motion_alarm, 1);
}
if(pAlarm->vlost_alarm != ref.alarm_info.vlost_alarm)
{
post_alarm_message(ip, pAlarm->vlost_alarm, 2);
}
ref.alarm_info = *pAlarm;
return ;
}
}
}
void net_cmd::post_alarm_message(ULONG ip, USHORT m_new, USHORT m_type)
{
POST_NOTIFY(cmdcb, NTM_ALARM, ip, MAKEDWORD(m_new , m_type));
}
//##ModelId=3F9A1D240006
bool net_cmd::snapshot(int group, LPCTSTR bmpfile)
{
return av[group]->snapshot(bmpfile);
}
//##ModelId=3F9A1D23034D
int net_cmd::get_audio_group()
{
return net_av::get_audio_group();
}
//##ModelId=3F9A1D2302D5
void net_cmd::update_window(int group)
{
av[group]->update_window();
}
//##ModelId=3F9A1D24001A
void net_cmd::set_video_renderer(COLOR_SPACE cs, BOOL video_mem)
{
net_av::set_video_renderer(cs, video_mem);
}
//##ModelId=3F9A1D240037
PRIVILEGE net_cmd::get_privilege(ULONG ip, USHORT port)
{
for( pit it=connected.begin(); it!=connected.end(); it++ )
{
privilege& ref = *it;
if( ref == privilege(ip, port, privNONE) )
{
return ref.get_priv();
}
}
return privNONE;
}
//##ModelId=3F9A1D24004B
BOOL net_cmd::is_muted()
{
return net_av::is_muted() ;
}
UINT net_cmd::get_bitrate(int group)
{
return av[group]->bitrate;
}
UINT net_cmd::udp_get_bitrate()
{
return udp_bitrate;
}
void net_cmd::clear_alarm(ULONG ip, USHORT port)
{
send_cmd(ip, port, NETCOM_CLEAR_ALARM, 0, 0);
}
void net_cmd::get_zh_decstate(ULONG ip, USHORT port, int address)
{
char addr[1];
addr[0] = address;
send_cmd(ip, port, NET_QUERY_ZH_DECSTATE , addr, 1);
}
void net_cmd::send_bind_cmd(USHORT oldport, USHORT newport, BOOL image_type)
{
unsigned char m_char[5];
m_char[0] = oldport >> 8;
m_char[1] = oldport & 0x00ff;
m_char[2] = newport & 0x00ff;
m_char[3] = newport >>8;
ULONG ip;
if(!image_type)
{
ip = vod_if[vod_group].ip;
m_vod_mport = htons(newport);
}
else
{
ip = last_ip;
m_real_mport = htons(newport);
}
//fprintf(fppppp, "send operation : ip = %ld,group = %d old = %u, new = %u\n",ip, vod_group, oldport, newport) ;
for(int k=0; k<3; k++)
send_cmd(ip, last_port, NET_CLIENT_BURROW, (char *)m_char, 4);
}
ULONG net_cmd::get_host_by_name(LPCTSTR m_name)
{
struct hostent *ptr = gethostbyname(m_name);
if (ptr && ptr->h_length >= 4)
{
BYTE addr[4] ;
memcpy(addr, ptr->h_addr, 4) ;
ULONG nIpAddr = ((addr[3]<<24) + (addr[2]<<16) + (addr[1]<<8) + addr[0]) ;
return nIpAddr;
}
else return 0;
}
BOOL net_cmd::set_cb_showhandle(int group, VIDEO_CALLEE cb)
{
return av[group]->set_cb_showhandle(cb);
}
BOOL net_cmd::set_callbackfn(int group, PCALLBACKSTREAMPROD p, DWORD d1, DWORD d2)
{
pcallback[group] = p;
pcallback_user1[group] = d1;
pcallback_user2[group] = d2;
return TRUE;
}
BOOL net_cmd::set_decodedcallbackfn(int group, PCALLBACKDECODEDSTREAMPROD p, DWORD d1, DWORD d2)
{
pdecodedcallback[group] = p;
pdecodedcallback_user1[group] = d1;
pdecodedcallback_user2[group] = d2;
return TRUE;
}
BOOL net_cmd::setdrawaddimagecallback(int group, pDraw_Add_Image pimage, DWORD d1, DWORD d2)
{
pdrawcallback[group] = pimage;
pdrawcallback_user1[group] = d1;
pdrawcallback_user2[group] = d2;
return TRUE;
}
BOOL net_cmd::open_alarm_server(USHORT bindport)
{
palarmserver = new net_alarmserver;
if(!palarmserver)
return FALSE;
if(!palarmserver->create(bindport))
{
delete palarmserver;
palarmserver = NULL;
return FALSE;
}
return TRUE;
}
BOOL net_cmd::close_alarm_server()
{
if(palarmserver)
{
palarmserver->destroy();
delete palarmserver;
palarmserver = NULL;
return TRUE;
}
return FALSE;
}
BOOL net_cmd::set_update_statue(ULONG ip, USHORT port)
{
send_cmd(ip, port, NETCOM_UPGRATE, NULL, 0);
return TRUE;
}
BOOL net_cmd::set_netclub_info(ULONG ip, USHORT port, void * buf, int len)
{
send_cmd(ip, port, NETCOM_SET_NETCLUB_INFO, (char *)buf, len);
return TRUE;
}
BOOL net_cmd::set_dvrrestart(ULONG ip, USHORT port)
{
send_cmd(ip, port, NETCOM_SET_RESTART, NULL, 0);
return TRUE;
}
BOOL net_cmd::sendcardid(ULONG ip, USHORT port, void * buf)
{
send_cmd(ip, port, NETCOM_SERIAL_PORT_ID, (char *)buf, 12);
return TRUE;
}
BOOL net_cmd::opennet_alarm(ULONG ip, USHORT port, int channel)
{
char buf[1] = {(char)channel};
send_cmd(ip, port, NETCOM_OPEN_NETALARM, (char *)buf, 1);
return TRUE;
}
BOOL net_cmd::closenet_alarm(ULONG ip, USHORT port, int channel)
{
char buf[1] = {(char)channel};
send_cmd(ip, port, NETCOM_CLOSE_NETALARM, buf, 1);
return TRUE;
}
BOOL net_cmd::openalarm_output(ULONG ip, USHORT port, int output)
{
char buf[1] = {(char)output};
send_cmd(ip, port, NETCOM_SET_ALMOUTPUT, buf, 1);
return TRUE;
}
BOOL net_cmd::is_opened(int group)
{
return av[group]->is_opened();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -