Hi all,
I have prepared the code.
- trap_code.zip : the new code for trap management (V1 and V2), also supporting V2 inform (replaces code of MQX RTCS in traps.c)
- rtcs_snmp_inform.patch : the patch to MQX37 to add support for V2 inform response handler (modifies snmp.c; need to rebuild MQX)
First you have to declare a global_data_config_net structure and fill all its fields (see snmp_task.h).
You select V1 trap, V2 trap, or V2 inform
Also the retry period and the retry count to determine how many traps are sent or how many informs are sent without reply
For IP addresses if targets, fill each value with an IP address or 0.0.0.0; for example :
Shell_parse_ip_address("192.168.0.1", &ip_addr);
RTCS_to_IPbytes(ip_addr, global_data_config_net.snmp_notify_target_IP[0]);
Shell_parse_ip_address("0.0.0.0", &ip_addr);
RTCS_to_IPbytes(ip_addr, global_data_config_net.snmp_notify_target_IP[1]);
RTCS_to_IPbytes(ip_addr, global_data_config_net.snmp_notify_target_IP[2]);
(I don't use the standard "add_target" function)
You also need to define some MIB nodes related to you product (required for product specific traps/informs) :
extern RTCSMIB_NODE MIBNODE_myCompany;
extern const RTCSMIB_NODE MIBNODE_myProduct;
extern const RTCSMIB_NODE MIBNODE_myProductTrap1;
extern const RTCSMIB_NODE MIBNODE_myProductTrap2;
Then you call
void snmp_task_init(void)
and run
void snmp_task_main(uint_32 initial_data)
as a task (for example stack size 2048 and prio 8)
each time you want ot send a trap, you call snmp_task_update()
For example :snmp_task_update(SNMP_TASK_SEND_MYPRODUCTTRAP1);