Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BER.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
27 changes: 16 additions & 11 deletions src/SNMPMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down