diff --git a/src/BER.h b/src/BER.h index cda0a8f..c63ae31 100644 --- a/src/BER.h +++ b/src/BER.h @@ -156,7 +156,7 @@ struct Trap { /** Generic trap code. */ uint8_t _genericTrap; /** Specific trap code. */ - uint8_t _specificTrap; + uint32_t _specificTrap; /** Time elapsed since device startup. */ uint32_t _timeStamp; }; diff --git a/src/SNMPMessage.h b/src/SNMPMessage.h index fad7e2b..2a93731 100644 --- a/src/SNMPMessage.h +++ b/src/SNMPMessage.h @@ -339,25 +339,30 @@ class Message: public SequenceBER, private PDU { * @param generic Generic trap code. * @param specific Specific trap code. */ - void setTrap(const uint8_t generic, const uint8_t specific = 0) { + void setTrap(const uint8_t generic, const uint32_t specific = 0) { _trap._genericTrap = generic; _trap._specificTrap = specific; } /** - * @brief Sets the SNMPTRAPOID variable binding. - - * @warning Valid only for InformRequest or SNMPv2Trap PDU. + * @brief Adds the mandatory variable bindings for an SNMPv2 trap or inform. + * + * This function sets the required variable bindings for SNMPv2-Trap or InformRequest PDUs: + * - `sysUpTime.0` is automatically set at build time using `millis()` if not explicitly provided. + * - `snmpTrapOID.0` is set to the given `name` value. * - * - Adds mandatory variable binding *sysUpTime.0*. Value will be set at build - * time. - *- Adds variable binding *snmpTrapOID.0* with value name. + * @warning This function is only valid for InformRequest or SNMPv2-Trap PDUs. * - * @param name snmpTrapOID.0 value. + * @param name The value to assign to `snmpTrapOID.0` (typically a trap OID string). + * @param sysuptime The system uptime in hundredths of a second. If set to 0 (default), + * the value is automatically computed from `millis()`. */ - void setSNMPTrapOID(const char *name) { -// add(OID::SYSUPTIME, new TimeTicksBER(0)); - add(OID::SYSUPTIME, new TimeTicksBER(millis() / 10)); + void setSNMPTrapOID(const char *name, uint32_t sysuptime = 0) { + if(sysuptime == 0) { + add(OID::SYSUPTIME, new TimeTicksBER(millis() / 10)); + } else { + add(OID::SYSUPTIME, new TimeTicksBER(sysuptime)); + } add(OID::SNMPTRAPOID, new ObjectIdentifierBER(name)); }