📄 net_cmdtcp.cpp
字号:
kit ppt = find_login(ip, port);
if(!ppt)
{
login_information tt;
memset(&tt, 0, sizeof(login_information));
tt.ip = ip;
tt.port = port;
tt.priv = priv;
tt.p = (net_logintcp *)id;
login_list.push_back(tt);
}
else
{
ppt->m_id = id;
ppt->priv = priv;
}
}
bool net_cmdtcp::delete_login(ULONG ip, USHORT port)
{
kit ppt = find_login(ip, port);
if(ppt)
{
net_logintcp *p = ppt->p;
p->destroy();
delete p;
login_list.erase(ppt);
return true;
}
return false;
}
dbit net_cmdtcp::find_bak_talk_inf(ULONG ip, USHORT port, bak_talk_list & list)
{
for(dbit bit = list.begin(); bit!= list.end(); bit++)
{
bak_talk_information & ref = *bit ;
if(ref.ip == ip && ref.port == port)
return bit;
}
return NULL;
}
void net_cmdtcp::insert_bak_talk_inf(ULONG ip, USHORT port, net_bktcp *p, bak_talk_list & list)
{
dbit ppt = find_bak_talk_inf(ip, port, list);
if(!ppt)
{
bak_talk_information tt;
memset(&tt, 0, sizeof(bak_talk_information));
tt.p = p;
tt.ip = ip;
tt.port = port;
p->backup_is_start = true;
list.push_back(tt);
}
}
bool net_cmdtcp::delete_bak_talk_inf(ULONG ip, USHORT port, bak_talk_list & list, bool m_bool)
{
dbit ppt = find_bak_talk_inf(ip, port, list);
if(ppt)
{
net_bktcp *p = ppt->p;
if(p)
{
if(m_bool)
p->destroy() ;
else
p->terimt_destroy();
delete p ;
}
list.erase(ppt);
return true;
}
return false;
}
//##ModelId=3F9A1D2300F4
void net_cmdtcp::on_net_tcp_recv(byte* buf, int length, ULONG from_ip, USHORT from_port, int group)
{
#define IPPORT_PARAM last_ip, last_port
if( CMD_OF(buf) is NETCOM_LOGIN_OK )
{
nt_cmd_login_ok clo;
clo.ip = from_ip;
clo.port = from_port;
ULONG id = *(DWORD*)(buf+4);
clo.channel_count = DATA_OF(buf)[0];
if(length >= 21)
clo.privilege = get_login_station_version(DATA_OF(buf)[9]);
else
clo.privilege = privADMIN;
clo.version =true;
clo.portpopedom = *(DWORD*)DATA_OF(buf+1);
clo.actionpopedom = *(DWORD*)DATA_OF(buf+5);
insert_login(from_ip, from_port, id, clo.privilege);
SEND_NOTIFY(cmdcb, NTM_CMD_LOGIN_OK, (WPARAM)&clo, DATA_OF(buf)[10]);
}
// 登出成功
if( CMD_OF(buf) is NETCOM_LOGOUT_OK )
{
POST_NOTIFY(cmdcb, NTM_CMD_LOGOUT_OK, from_ip, from_port);
}
// 请求实时图像成功
if( CMD_OF(buf) is NETCOM_OPEN_REALIMAGE_OK )
{
ULONG mip = 0;
USHORT mport = 0;
int channel = DATA_OF(buf)[0];
mip = *(ULONG*)DATA_OF(buf+1);
mport = *(USHORT*)DATA_OF(buf+1+sizeof(ULONG));
char m_mip = mip;
if((m_mip & 0xf0) != 0xe0)
return;
if(avtcp[group]->svr_ip() != from_ip || avtcp[group]->svr_chnl() != channel)
return;
SOCKET sock = avtcp[group]->get_socket();
net_addr local;
int len = sizeof(net_addr);
getsockname(sock,local,&len);
if(local.port() != mport)
{
if(!avtcp[group]->create_udp_socket(mip,mport))
{
AfxMessageBox("加入组播失败.如想开启此路图像请重启客户端");
return;
}
}
avtcp[group]->join(mip,mport);
}
// 关闭实时图像成功
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,from_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 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 id = *(DWORD*)DATA_OF(buf);
avtcp[group]->set_vod_id(id);
}
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 == avtcp[i]->svr_ip())&&(from_port == avtcp[i]->svr_port()))
{
close_vod(i);
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)
{
}
if( CMD_OF(buf) is NETCOM_TALK_NOTOK)
{
delete_bak_talk_inf(rip, rport, talk_list, false) ;
POST_NOTIFY(talkcb, NTM_TALK_FAILED, from_ip, from_port) ;
}
// 备份
if (CMD_OF(buf) is NETCOM_BACKUP_RECFILE_OK)
{
POST_NOTIFY(bkcb, NTM_BK_BEGIN, rip, rport) ;
}
if( CMD_OF(buf) is NETCOM_BACKUP_RECFILE_NOK)
{
delete_bak_talk_inf(from_ip, from_port, bak_list, false) ;
POST_NOTIFY(bkcb, NTM_BK_FAILED, from_ip, from_port) ;
}
if( CMD_OF(buf) is NETCOM_BACKUP_STOP_OK )
{
delete_bak_talk_inf(from_ip, from_port, bak_list, false) ; ;
POST_NOTIFY(bkcb, NTM_BK_CANCELED, from_ip, from_port);
}
if( CMD_OF(buf) is NETCOM_BACKUP_END )
{
delete_bak_talk_inf(from_ip, from_port, bak_list, false) ; ;
POST_NOTIFY(bkcb, NTM_BK_FINISHED, from_ip, from_port) ;
}
//
if( CMD_OF(buf) is NETCOM_SHAKE_HAND )
{
if(length < 18)
{
byte * temp = (byte *)DATA_OF(buf+10);
temp[0]=0;
temp[1]=0;
}
process_alarm(from_ip, from_port, 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))
//##ModelId=3F9A1D2301F9
void net_cmdtcp::process_alarm(ULONG ip, USHORT port, byte* data)
{
TREC_ALARMINFO *pAlarm = (TREC_ALARMINFO *)data ;
if (login_list.empty())
return ;
for (kit it = login_list.begin(); it != login_list.end(); it++)
{
login_information& 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_cmdtcp::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_cmdtcp::snapshot(int group, LPCTSTR bmpfile)
{
return avtcp[group]->snapshot(bmpfile);
}
//##ModelId=3F9A1D23034D
int net_cmdtcp::get_audio_group()
{
return net_avtcp::get_audio_group();
}
//##ModelId=3F9A1D2302D5
void net_cmdtcp::update_window(int group)
{
avtcp[group]->update_window();
}
//##ModelId=3F9A1D24001A
void net_cmdtcp::set_video_renderer(COLOR_SPACE cs, BOOL video_mem)
{
net_avtcp::set_video_renderer(cs, video_mem);
}
//##ModelId=3F9A1D240037
PRIVILEGE net_cmdtcp::get_privilege(ULONG ip, USHORT port)
{
kit ppt = find_login(ip, port);
if(ppt)
return ppt->priv;
return privNONE;
}
//##ModelId=3F9A1D24004B
BOOL net_cmdtcp::is_muted()
{
return net_avtcp::is_muted() ;
}
void net_cmdtcp::clear_alarm(ULONG ip, USHORT port)
{
send_cmd(ip, port, NETCOM_CLEAR_ALARM, 0, 0);
}
void net_cmdtcp::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);
}
ULONG net_cmdtcp::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_cmdtcp::set_cb_showhandle(int group, VIDEO_CALLEE cb)
{
return avtcp[group]->set_cb_showhandle(cb);
}
BOOL net_cmdtcp::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_cmdtcp::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_cmdtcp::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_cmdtcp::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_cmdtcp::close_alarm_server()
{
if(palarmserver)
{
palarmserver->destroy();
delete palarmserver;
palarmserver = NULL;
return TRUE;
}
return FALSE;
}
BOOL net_cmdtcp::set_update_statue(ULONG ip, USHORT port)
{
send_cmd(ip, port, NETCOM_UPGRATE, NULL, 0);
return TRUE;
}
BOOL net_cmdtcp::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_cmdtcp::set_dvrrestart(ULONG ip, USHORT port)
{
send_cmd(ip, port, NETCOM_SET_RESTART, NULL, 0);
return TRUE;
}
BOOL net_cmdtcp::sendcardid(ULONG ip, USHORT port, void * buf)
{
send_cmd(ip, port, NETCOM_SERIAL_PORT_ID, (char *)buf, 12);
return TRUE;
}
BOOL net_cmdtcp::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_cmdtcp::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_cmdtcp::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_cmdtcp::is_opened(int group)
{
return avtcp[group]->is_opened();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -