当前位置:网站首页>Gb28181 protocol -- alarm
Gb28181 protocol -- alarm
2022-06-12 22:39:00 【jimte_ pro】
1、 brief introduction
according to 《GBT 28181-2016 Public security video monitoring network system information transmission 、 In exchange for 、 Control technical requirements 》9.4 Chaste 《 Basic requirements for alarm event notification and distribution 》 describe :
When an alarm event occurs , The source device shall send alarm information to SIP The server ;SIP After the server receives the alarm event , Distribute the alarm information to the target device . Alarm event notification and distribution IETF RFC 3428 The method defined in Message Transmit alarm information . Source devices include SIP equipment 、 gateway 、SIP client 、 Networking system or integrated alarm receiving and handling system, bayonet system, etc , The target equipment includes... With alarm receiving function SIP client 、 Networking system or integrated alarm receiving and handling system, bayonet system, etc .
2、 technological process
The alarm event notification and distribution process is shown in the figure below :
The command flow is described below :
- (1): After the alarm event occurs , Source device to SIP The server sends an alarm notification command , The alarm notification command adopts Message How to carry ;
- (2): SIP After receiving the command, the server returns 200 OK;
- (3):SIP After the server receives the alarm event , Send alarm event notification response command to the source device , The alarm notification response command adopts Message How to carry ;
- (4): The source device returns... After receiving the command 200 OK;
- (5):SIP After the server receives the alarm event , Identify the target device that needs to be forwarded ,SIP The server sends an alarm event notification command to the target device , The alarm notification command adopts Message How to carry ;
- (6): After receiving the command, the target device returns 200 OK;
- (7): After the target device receives the alarm event , towards SIP The server sends alarm event notification response command , The alarm notification response command adopts Message How to carry ;
- (8):SIP After receiving the command, the server returns 200 OK
3、 Protocol interfaces
(1) Request command message body
The message header Content-type Field is Content-type: Application/ MANSCDP+xml.
The request command in the alarm event notification and distribution process adopts MANSCDP Protocol format definition , See for a detailed description A.2.5 Alarm notice .
Source device to SIP The server notifies the alarm 、SIP The server sends alarm notification commands to the target device in the form of Message Method belt . newspaper police things Pieces of through know life Make Should be package enclosed life Make class type (CmdType) 、 life Make order Column Number (SN) 、 set up To prepare Ed code (DeviceID) 、 Alarm level (AlarmPriority) etc. . optional : Alarm time (AlarmTime) 、 Alarm mode (AlarmMethod) 、 longitude (Longitude) 、 latitude (Latitude) 、 Extended alarm type (AlarmType) 、 Alarm type parameter (AlarmTypeParam) . The relevant equipment received Message After the news , Return immediately 200 OK The reply ,200 OK There is no message body in the response .(2) Reply command message body
The message header Content-type Field is Content-type: Application/ MANSCDP+xml.
The response command in the alarm event notification and distribution process adopts MANSCDP Protocol format definition , See for a detailed description A.2.6 Alarm notification response .SIP The server sends data to the source device 、 Target device to SIP The server sends alarm notification and response commands in Message The message body of the method carries . The alarm event notification response command shall include the command type (CmdType) 、 Command serial number (SN) 、 Equipment code (DeviceID) 、 Execution results (Result) .
The relevant equipment received Message After the news , Return immediately 200 OK The reply ,200 OK There is no message body in the response .
4、 Software code
Alarm sending interface :
int SipSendAlarm(GB28181Param_t *pGB28181Param, AlarmHander_t *pHander, int sn);
int SipSendAlarm(GB28181Param_t *pGB28181Param, AlarmHander_t *pHander, int sn)
{
int ret = 0;
char from[128] = {
0,};
char proxy[128] = {
0,};
char xmlBody[1024] = {
0,};
osip_message_t *rqt_msg = NULL;
// sip Not registered yet , Then don't send data
if (!SipGetRegStatus() || !pGB28181Param || !pHander)
{
return -1;
}
if (!IS_ALARM_CHN_VALID(pHander->alarmChn))
{
return -1;
}
snprintf(from, sizeof(from), "sip:%[email protected]%s:%s",
pGB28181Param->userParam.devSipID,
pGB28181Param->userParam.devSipIP,
pGB28181Param->userParam.devSipPort);
snprintf(proxy, sizeof(proxy), "sip:%[email protected]%s:%s",
pGB28181Param->userParam.sipServerID,
pGB28181Param->userParam.sipServerIP,
pGB28181Param->userParam.sipServerPort);
/* structure "MESSAGE" request */
if (eXosip_message_build_request(&rqt_msg, "MESSAGE", proxy, from, NULL)!=OSIP_SUCCESS)
{
return -1;
}
if (MakeAlarmBody(xmlBody, sizeof(xmlBody), sn, pGB28181Param, pHander))
{
return -1;
}
if (osip_message_set_content_type(rqt_msg, "Application/MANSCDP+xml")!=OSIP_SUCCESS)
{
osip_message_free(rqt_msg);
return -1;
}
if (osip_message_set_body(rqt_msg, xmlBody, strlen(xmlBody))!=OSIP_SUCCESS)
{
osip_message_free(rqt_msg);
return -1;
}
/* Send a message */
eXosip_lock();
ret = eXosip_message_send_request(rqt_msg);
eXosip_unlock();
return (ret==OSIP_SUCCESS)?0:-1;
}
Alarm message construction interface :
static int MakeAlarmBody(char *xmlBody, int xmlBodyLen, int sn, GB28181Param_t *pGB28181Param, AlarmHander_t *pHander);
static int MakeAlarmBody(char *xmlBody, int xmlBodyLen, int sn, GB28181Param_t *pGB28181Param, AlarmHander_t *pHander)
{
if (!xmlBody ||!pGB28181Param || !pHander)
{
return -1;
}
snprintf(xmlBody, xmlBodyLen, "<?xml version=\"1.0\"?>\r\n"
"<Notify>\r\n"
"<CmdType>Alarm</CmdType>\r\n" /* Command type */
"<SN>%d</SN>\r\n" /* Command serial number */
"<DeviceID>%s</DeviceID>\r\n" /* Equipment code */
"<AlarmPriority>%d</AlarmPriority>\r\n" /* Alarm level */
"<AlarmTime>%s</AlarmTime>\r\n" /* Alarm time */
"<AlarmMethod>%d</AlarmMethod>\r\n" /* Alarm mode */
"<AlarmDescription>%s</AlarmDescription>\r\n" /* Alarm description */
"<Longitude>0.000</Longitude>\r\n"
"<Latitude>0.000</Latitude>\r\n"
"<Info>\r\n"
"<AlarmType>%d</AlarmType>\r\n" /* Alarm type */
"<AlarmTypeParam>\r\n"
"</AlarmTypeParam>\r\n"
"</Info>\r\n"
"</Notify>\r\n",
sn,
pGB28181Param->userParam.iAlarmChn[pHander->alarmChn],
pGB28181Param->userParam.iAlarmPriority[pHander->alarmChn],
pHander->alarmTime,
pHander->alarmMethod,
pHander->alarmDescri,
pHander->alarmType
);
return 0;
}
Alarm response analysis :
receive sip Data interface :
int SipEventProcess(GB28181Param_t *pGB28181Param)
int SipEventProcess(GB28181Param_t *pGB28181Param)
{
int ret = 0;
int len = 0;
char *msg = NULL;
osip_header_t *dest = NULL;
eXosip_event_t *sipEvent = NULL;
sipEvent = eXosip_event_wait( 0, 100);
if (!sipEvent)
{
eXosip_lock();
eXosip_execute();
eXosip_automatic_action();
eXosip_unlock();
return -1;
}
eXosip_lock();
eXosip_execute();
eXosip_automatic_action();
eXosip_unlock();
switch(sipEvent->type)
{
case EXOSIP_MESSAGE_ANSWERED:
{
// Update the retention time
pthread_mutex_lock(&g_SipState.mutex);
g_SipState.keepliveAckTime = GetSysSec();
pthread_mutex_unlock(&g_SipState.mutex);
if(MSG_IS_MESSAGE(sipEvent->response))
{
ret = SipResponsMsgProcess(pGB28181Param, sipEvent);
}
}
break;
default:
GB_PrintWarn("error Event, Event type: %d\n", sipEvent->type);
break;
}
eXosip_event_free(sipEvent);
return ret;
}
Analyze the response interface :
static int SipResponsMsgProcess(GB28181Param_t *pGB28181Param, eXosip_event_t *sipEvent)
{
char xmlSN[32] = {
0,};
char deviceID[32] = {
0,};
char cmdType[32] = {
0,};
char rspXmlBody[2048] = {
0,};
osip_body_t *rspBody = NULL;
mxml_node_t *xml = NULL;
mxml_node_t *node = NULL;
osip_message_t *rsqMsg = NULL;
if (!pGB28181Param || !sipEvent)
{
return -1;
}
eXosip_lock();
/* Gets the of the received request XML Message body */
int ret = osip_message_get_body(sipEvent->response, 0, &rspBody);
if((NULL == rspBody) || (NULL == rspBody->body))
{
eXosip_unlock();
return -1;
}
eXosip_unlock();
xml = mxmlLoadString(NULL,rspBody->body, MXML_TEXT_CALLBACK);
if (!xml)
{
return -1;
}
// lookup CmdType
node = mxmlFindElement(xml, xml, "CmdType", NULL, NULL, MXML_DESCEND);
if (!node)
{
return -1;
}
strncpy(cmdType, mxmlGetText(node, NULL), sizeof(cmdType));
if (strlen(cmdType) <=0 )
{
return -1;
}
node = mxmlFindElement(xml, xml, "DeviceID", NULL, NULL, MXML_DESCEND);
if (!node)
{
return -1;
}
strncpy(deviceID, mxmlGetText(node, NULL), sizeof(deviceID));
if (strlen(deviceID) <=0)
{
return -1;
}
// For this SN You need to do some anti duplication treatment , Consider this function later
node = mxmlFindElement(xml, xml, "SN", NULL, NULL, MXML_DESCEND);
if (!node)
{
return -1;
}
// Response time , The equipment needs to be sent SN
strcpy(xmlSN, mxmlGetText(node, NULL));
if (strlen(xmlSN) <=0 )
{
return -1;
}
eXosip_lock();
if ((ret = eXosip_message_build_answer( sipEvent->tid, 200, &rsqMsg)) != OSIP_SUCCESS)
{
eXosip_unlock();
return -1;
}
if ((ret = eXosip_message_send_answer( sipEvent->tid, 200, rsqMsg)) != OSIP_SUCCESS)
{
eXosip_unlock();
return -1;
}
eXosip_unlock();
if (!strcmp(cmdType, "Alarm"))
{
AlarmMsgParase(xml, rspXmlBody, sizeof(rspXmlBody), xmlSN, deviceID, pGB28181Param);
}
else
{
mxmlDelete(xml);
return -1;
}
mxmlDelete(xml);
return 0;
}
Parse answer command :
static int AlarmMsgParase(mxml_node_t *xml, char *msg, int msgLen, char *sn, char *devID, GB28181Param_t *pGB28181Param)
{
char result[32] = {
0,};
if ( !pGB28181Param || !msg || msgLen<= 0 || !xml )
{
return -1;
}
memset(msg, 0, msgLen);
uint8_t iChn = GetChannelID(devID, pGB28181Param, GET_ALARM_TYPE);
if (!IS_ALARM_CHN_VALID(iChn))
{
return -1;
}
// lookup CmdType
mxml_node_t *node = mxmlFindElement(xml, xml, "Result", NULL, NULL, MXML_DESCEND);
if (!node)
{
return -1;
}
strncpy(result, mxmlGetText(node, NULL), sizeof(result));
if (!strcmp(result, "OK"))
{
}
return 0;
}
Recommended reading :
GB28181 agreement – Device registration and logout
Reference material :
《GBT 28181-2016 Public security video monitoring network system information transmission 、 In exchange for 、 Control technical requirements 》
边栏推荐
- Sword finger offer series - 47 Maximum value of gifts
- The "fourteenth five year plan" development plan and panoramic strategic analysis report of China's information and innovation industry 2022 ~ 2028
- Why is pain rating important?
- Anti aliasing / anti aliasing Technology
- 同花顺股票账户开户安全吗
- QT quick 3D learning: use mouse and keyboard to control node position and direction
- IPhone: save Boolean into core data - iphone: save Boolean into core data
- Market trend report, technical innovation and market forecast of Chinese stump crusher
- China embolic coil market trend report, technical innovation and market forecast
- Audio and video technology development weekly 𞓜 234
猜你喜欢

MySQL case when then function use

Use js to listen for Keydown event
![[image denoising] image denoising based on trilateral filter with matlab code](/img/f2/770a0e2938728e731c18c0a66f7c12.png)
[image denoising] image denoising based on trilateral filter with matlab code

Photoshop:PS如何实现放大图片不模糊

C language: how to give an alias to a global variable?

IPhone: save Boolean into core data - iphone: save Boolean into core data

iShot

JVM foundation - > talk about class loader two parent delegation model

Implementation of master-slave replication and master-master replication for MySQL and MariaDB databases

设计消息队列存储消息数据的 MySQL 表格
随机推荐
A 42 year old senior executive of a large factory reminds people aged 30-39 that these six habits that make you stronger should be developed as soon as possible
Flutter库推荐Sizer 可帮助您轻松创建响应式 UI
Implementation of master-slave replication and master-master replication for MySQL and MariaDB databases
【LeetCode】剑指 Offer II 020. 回文子字符串的个数
QT quick 3D learning: mouse picking up objects
The interface testing tool apipos3.0 is applicable to process testing and reference parameter variables
Use group_ Dplyr issues when using group_ by(multiple variables)
[image denoising] image denoising based on trilateral filter with matlab code
JVM foundation > G1 garbage collector
VIM use the lower right 4 keys
Anti aliasing / anti aliasing Technology
[proteus simulation] simple digital tube timer clock
JVM Basics - > how to troubleshoot JVM problems in your project
生成小程序菊花码(生成菊花码、更换中间logo、更改图片尺寸,加文字)
四元数简介
常见渲染管线整理
Use of map() function in JS
China's elastic belt market trend report, technical dynamic innovation and market forecast
【LeetCode】69. x 的平方根
flutter系列之:flutter中常用的GridView layout详解