diff --git a/common/vscp_firmware.c b/common/vscp_firmware.c index e0eb0d54..f4c9f373 100644 --- a/common/vscp_firmware.c +++ b/common/vscp_firmware.c @@ -1291,6 +1291,10 @@ int8_t vscp_sendEvent(void) vscp_omsg.priority, (vscp_omsg.flags & 0x0f), vscp_omsg.data ) ) ) { + // One would expect us sending an error event here but the most usual + // cause of this problem is that the bus is jammed with events so an + // error event sent here would have mad things even worse (and probably + // not being delivered anyway ). vscp_errorcnt++; } @@ -1325,3 +1329,51 @@ int8_t vscp_getEvent(void) return rv; } + +/////////////////////////////////////////////////////////////////////////////// +// vscp_sendErrorEvent +// + +#ifdef VSCP_FIRMWARE_ENABLE_ERROR_REPORTING +uint8_t vscp_sendErrorEvent( uint8_t type, uint8_t idx ) +{ + vscp_omsg.data[ 0 ] = idx; + vscp_omsg.data[ 1 ] = 0; // Zone always zero + vscp_omsg.data[ 2 ] = 0; // Sub zone always zero + + vscp_omsg.priority = VSCP_PRIORITY_MEDIUM; + vscp_omsg.flags = VSCP_VALID_MSG + 3; + vscp_omsg.vscp_class = VSCP_CLASS1_ERROR; + vscp_omsg.vscp_type = type; + + // Write event + return vscp_sendEvent(); +} +#endif + + +/////////////////////////////////////////////////////////////////////////////// +// vscp_sendLogEvent +// + +#ifdef VSCP_FIRMWARE_ENABLE_LOGGING +uint8_t vscp_sendLogEvent( uint8_t type, + uint8_t id, + uint8_t level, + uint8_t idx, + uint8_t data ) +{ + vscp_omsg.data[ 0 ] = id; + vscp_omsg.data[ 1 ] = level; + vscp_omsg.data[ 2 ] = idx; + memcpy( vscp_omsg.data, data, 5 ); + + vscp_omsg.priority = VSCP_PRIORITY_MEDIUM; + vscp_omsg.flags = VSCP_VALID_MSG + 8; + vscp_omsg.vscp_class = VSCP_CLASS1_LOG; + vscp_omsg.vscp_type = type; + + // Write event + return vscp_sendEvent(); +} +#endif \ No newline at end of file diff --git a/common/vscp_firmware.h b/common/vscp_firmware.h index 8cea4dce..be40b8b0 100644 --- a/common/vscp_firmware.h +++ b/common/vscp_firmware.h @@ -336,7 +336,8 @@ void vscp_init(void); /*! - Set VSCP error state + Set VSCP error state. + This is a unit that is sleeping. */ void vscp_error(void); @@ -461,7 +462,39 @@ int8_t vscp_sendEvent(void); */ int8_t vscp_getEvent(void); +/*! + Send error event (CLASS=508). + http://www.vscp.org/docs/vscpspec/doku.php?id=class1.error + idx can be used to identify the internal part ("submodule") that was the + origin of the error. Both zone and sub zone are always set to zero. + @param type This is the VSCP type + @param idx Index to identify possible sub module. Normally set to zero. + @return True if event was sent. + */ +#ifdef VSCP_FIRMWARE_ENABLE_ERROR_REPORTING +uint8_t vscp_sendErrorEvent( uint8_t type, uint8_t idx ); +#endif +/*! + Send log event (CLASS=509). + http://www.vscp.org/docs/vscpspec/doku.php?id=class1.log + For loging first send Type = 2(0x01) Log Start then logging events and when + log is closed send Type = 3 (0x03) Log Stop. To log several things use a + unique if for each and open/close each. + @param type VSCP logevent type. + @param id Identifier for the logging channel. + @param level Loglevel for this log event. + @param idx index for multiframe log event starting at zero. + @param pData Log data (Allways 5 bytes). + @return TRUE if event was sent. + */ +#ifdef VSCP_FIRMWARE_ENABLE_LOGGING +uint8_t vscp_sendLogEvent( uint8_t type, + uint8_t id, + uint8_t level, + uint8_t idx, + uint8_t data ); +#endif // --------------------------- External Functions ----------------------------- //