Skip to content

Commit

Permalink
Added error event and logger event
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Mar 23, 2016
1 parent 71fd452 commit fe77bf7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
52 changes: 52 additions & 0 deletions common/vscp_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down Expand Up @@ -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
35 changes: 34 additions & 1 deletion common/vscp_firmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 -----------------------------
//
Expand Down

0 comments on commit fe77bf7

Please sign in to comment.