VSCP Helper Libraries

Trace: helper_lib_api_helpers


|

Meta

Table of Contents





VSCP Helper library API - Helpers

This part of the library describes the many helpers that are available to handle events, GUIDs, etc, etc.



Misc helpers

vscphlp_readStringValue

long vscphlp_readStringValue( const char * pStrValue )

Convert a string to an integer value. The string can be expressed as a decimal (10, 00001 ) or a hexadecimal value(0xff).

pStrValue

String representation of value.

Return value

The converted number.

Example
long readValue = vscphlp_readStringValue("0x22");

vscphlp_replaceBackslash

int vscphlp_replaceBackslash( const char *pStr )

Replace all backslashes (“\”) in a string with forward slashes (“/”).

pStr

Null terminated string to convert.

Return value

VSCP_ERROR_SUCCESS on success.






vscphlp_getTimeString

int vscphlp_getTimeString( char *buf, size_t buf_len, time_t *t )

Get GMT time (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3).

Example result: Sun, “06 Nov 1994 08:49:37 GMT”

buf

Buffer that will get timestring after a successful call.

buf_len

Length of the buffer.

t

Pointer to an object of type time_t that contains a time value. time_t is an alias of a fundamental arithmetic type capable of representing times as returned by function time.

Return value

VSCP_ERROR_SUCCESS on success.






vscphlp_getISOTimeString

int vscphlp_getISOTimeString( char *buf, size_t buf_len, time_t *t )
buf

Buffer that will get ISO timestring after a successful call.

Example result: “2003-11-02T12:23:10Z”

buf_len

Length of the buffer.

t

Pointer to an object of type time_t that contains a time value. time_t is an alias of a fundamental arithmetic type capable of representing times as returned by function time.

Return value

VSCP_ERROR_SUCCESS on success.






Event handling

vscphlp_copyVSCPEvent

int vscphlp_copyVSCPEvent( vscpEvent *pEventTo, 
                              const vscpEvent *pEventFrom )

Copy VSCP event.

pEventTo

VSCP event that will get the result.

pEventFrom

VSCP event that should be copied

Return value

VSCP_ERROR_SUCCESS on success.

Example
vscpEvent *pEventFrom = new vscpEvent;
vscpEvent *pEventTo = new vscpEvent;
pEventFrom->head = 0;
pEventFrom->vscp_class = 10;
pEventFrom->vscp_type = 6;
pEventFrom->obid = 0;
pEventFrom->timestamp = 0;
memset( pEventFrom->GUID, 0, 16 );
pEventFrom->sizeData = 2;
pEventFrom->pdata = new unsigned char[2];
pEventFrom->pdata[ 0 ] = 0xAA;
pEventFrom->pdata[ 1 ] = 0x55;
 
if ( VSCP_ERROR_SUCCESS == vscphlp_copyVSCPEvent( pEventTo, pEventFrom ) ) {
    printf( "OK vscphlp_copyVSCPEvent %02X %02X \n", pEventTo->pdata[0], pEventTo->pdata[1] );
}
else {
    printf( "\aError: vscphlp_copyVSCPEvent\n");
}
 
// Free the events
vscphlp_deleteVSCPevent( pEventFrom );
vscphlp_deleteVSCPevent( pEventTo );

vscphlp_writeVscpDataToString

int vscphlp_writeVscpDataToString( const vscpEvent *pEvent, 
                                       char *pstr, 
                                       size_t len,
                                       int bUseHtmlBreak )

Write VSCP data in readable form to a possibly multi line string.

pEvent

The event that contains the data to be written

bUseHtmlBreak

Set to true (non zero) to use “<br>” instead of “\n” as linebreak in string.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
char dataBuf[80];
 
if ( VSCP_ERROR_SUCCESS == vscphlp_writeVscpDataToString( pEvent, 
                                                            dataBuf, 
                                                            sizeof( dataBuf )-1,
                                                            0 ) ) {
    printf( "OK vscphlp_writeVscpDataToString \n%s \n", dataBuf );
}
else {
    printf( "\aError: vscphlp_writeVscpDataToString\n");
}

vscphlp_writeVscpDataWithSizeToString

int vscphlp_writeVscpDataWithSizeToString( const unsigned char *pdata,
                                              const unsigned short. 
                                              char *pstr, 
                                              size_t len,
                                              int bUseHtmlBreak,
                                              int bBreak )

Write VSCP data in readable form to a possibly multi line string from a data array with size.

pData

Pointer to VSCP data array.

size

Number of bytes in data array.

pstr

Pointer to string buffer that will receive string.

len

Size of string receive buffer.

bUseHtmlBreak

Set to true (non zero) to use “<br>” instead of “\n” as linebreak in string.

bBreak

Set to true (non zero) to add the break character.

Return value

VSCP_ERROR_SUCCESS is returned on success.

vscphlp_setVscpDataFromString

int vscphlp_setVscpDataFromString( vscpEvent *pEvent, 
                                   const char *pstr )

Set data in VSCP event from a string.

pEvent

VSCP Event which will have its data set.

pstr

Pointer to null terminated string that contains data on comma separated form.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
vscpEvent e;
 
if ( VSCP_ERROR_SUCCESS == 
    setVscpDataFromString( e,
                           "1,2,3,4,5,6,0x07,0x55,3,4,0xaa,0xff,0xff" ) ) {
        printf( "OK vscphlp_setVscpDataFromString size=%d Data = \n", e.sizeData );
        for ( int i=0; i<e.sizeData; i++ ) {
            printf("%d ", e.data[i] );
        }
        printf("\n");
}
else {
   printf( "\aError: vscphlp_setVscpDataFromString\n");
}

vscphlp_writeVscpEventToString

int vscphlp_writeVscpEventToString( const vscpEvent *pEvent, char *pstr, size_t len )

Write VSCP event content to a string.

pEvent

The VSCP event which will be written to the string buffer.

pstr

Pointer to string buffer that will receive result.

len

Size of buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
char eventBuf[128];
if ( VSCP_ERROR_SUCCESS == vscphlp_writeVscpEventToString( pEvent, eventBuf, sizeof( eventBuf )-1 ) ) {
    printf( "OK vscphlp_writeVscpEventToString Event = %s\n", eventBuf );    
}
else {
    printf( "\aError: vscphlp_writeVscpEventToString\n");
}

vscphlp_writeVscpEventExToString

int vscphlp_writeVscpEventExToString( const vscpEventEx *pEvent, char *pstr, size_t len )

Write VSCP event ex content to a string.

pEvent

The VSCP event which will be written to the string buffer.

pstr

Pointer to string buffer that will receive result.

len

Size of buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
char eventBuf[128];
if ( VSCP_ERROR_SUCCESS == vscphlp_writeVscpEventExToString( &ex, 
                                           eventBuf, 
                                           sizeof( eventBuf )-1 ) ) {
    printf( "OK vscphlp_writeVscpEventExToString Event = %s\n", eventBuf );    
}
else {
    printf( "\aError: vscphlp_writeVscpEventExToString\n");
}

vscphlp_setVscpEventFromString

int vscphlp_setVscpEventFromString( vscpEvent *pEvent, const char *pstr )

Set VSCP event from a string.

pEvent

The VSCP event which will be written to.

pstr

Pointer to string buffer that contain an event in string form

head,class,type,obid,timestamp,GUID,data1,data2,data3....
Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
vscpEvent *pEventString1 = new vscpEvent;
pEventString1->pdata = NULL;
 
if ( VSCP_ERROR_SUCCESS == vscphlp_setVscpEventFromString( pEventString1,                
       "0,10,6,0,0,FF:FF:FF:FF:FF:FF:FF:00:00:00:00:7F:00:01:01:FD,0x8A,0x00,0x1E" ) ) {
    printf( "OK vscphlp_setVscpEventFromString class=%d Type=%d\n", 
                   pEventString1->vscp_class, pEventString1->vscp_type );
}
else {
    printf( "\aError: vscphlp_setVscpEventFromString\n");
}
 
// Free the events
vscphlp_deleteVSCPevent( pEventString1 );

vscphlp_setVscpEventExFromString

int vscphlp_setVscpEventExFromString( vscpEventEx *pEvent, const char *pstr )

Set VSCP event ex from a string.

pEvent

The VSCP event ex which will be written to.

pstr

Pointer to string buffer that contain an event in string form

head,class,type,obid,timestamp,GUID,data1,data2,data3....
Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
vscpEventEx ex6;
if ( VSCP_ERROR_SUCCESS == vscphlp_setVscpEventExFromString( &ex6,  
      "0,10,6,0,0,FF:FF:FF:FF:FF:FF:FF:00:00:00:00:7F:00:01:01:FD,0x8A,0x00,0x1E" ) ) 
    printf( "OK vscphlp_setVscpEventExFromString class=%d Type=%d\n", 
                   ex6.vscp_class, ex6.vscp_type );
}
else {
    printf( "\aError: vscphlp_setVscpEventExFromString\n");
}

vscphlp_getVscpPriority

unsigned char vscphlp_getVscpPriority( const vscpEvent *pEvent )

Extract the event priority from a VSCP event. Priority is defined as a value between 0-7 where 0 is the highest priority.

pEvent

VSCP event.

Return value

Priority.

Example
pEvent = new vscpEvent;
pEvent->head = 0;
pEvent->vscp_class = 10;
pEvent->vscp_type = 6;
pEvent->obid = 0;
pEvent->timestamp = 0;
memset( pEvent->GUID, 0, 16 );
pEvent->sizeData = 3;
pEvent->pdata = new unsigned char[3];
pEvent->pdata[ 0 ] = 138;
pEvent->pdata[ 1 ] = 0;
pEvent->pdata[ 2 ] = 30;
 
unsigned char eventPriority;
if ( 0 == ( eventPriority = vscphlp_getVscpPriority( pEvent ) ) ) {
    printf("Event priority = %d\n", eventPriority );
}
else {
    printf("\aError: Event priority = %d\n", eventPriority );
}
 
// Free the event
vscphlp_deleteVSCPevent( pEvent );

vscphlp_getVscpPriorityEx

unsigned char vscphlp_getVscpPriorityEx( const vscpEventEx *pEvent )

Extract the event priority from a VSCP event. Priority is defined as a value between 0-7 where 0 is the highest priority.

pEvent

VSCP event.

Return value

Priority.

Example
vscpEventEx ex3;
ex3.head = 0;
ex3.vscp_class = 10;
ex3.vscp_type = 6;
ex3.obid = 0;
ex3.timestamp = 0;
memset( ex3.GUID, 0, 16 );
ex3.sizeData = 3;
ex3.data[ 0 ] = 138;
ex3.data[ 1 ] = 0;
ex3.data[ 2 ] = 30;
 
unsigned char eventPriority;
if ( 0 == ( eventPriority = vscphlp_getVscpPriorityEx( &ex3 ) ) ) {
    printf("EventEx priority = %d\n", eventPriority );
}
else {
    printf("\aError: EventEx priority = %d\n", eventPriority );
}

vscphlp_setVscpPriority

void vscphlp_setVscpPriority( vscpEvent *pEvent, unsigned char priority )

Set Event priority. Priority is defined as a value between 0-7 where 0 is the highest priority.

pEvent

VSCP event.

priority

Priority to set.

Example
pEvent = new vscpEvent;
pEvent->head = 0;
pEvent->vscp_class = 10;
pEvent->vscp_type = 6;
pEvent->obid = 0;
pEvent->timestamp = 0;
memset( pEvent->GUID, 0, 16 );
pEvent->sizeData = 3;
pEvent->pdata = new unsigned char[3];
pEvent->pdata[ 0 ] = 138;
pEvent->pdata[ 1 ] = 0;
pEvent->pdata[ 2 ] = 30;
 
unsigned char eventPriority;
vscphlp_setVscpPriority( pEvent, VSCP_PRIORITY_NORMAL );
if ( VSCP_PRIORITY_NORMAL == ( eventPriority = vscphlp_getVscpPriority( pEvent ) ) ) {
    printf("Event priority = %d\n", eventPriority );
}
else {
    printf("\aError: Set Event priority = %d\n", eventPriority );
}
 
// Free the event
vscphlp_deleteVSCPevent( pEvent );

vscphlp_setVscpPriorityEx

unsigned char eventPriority;
void vscphlp_setVscpPriorityEx( vscpEventEx *pEvent, unsigned char priority )

Set Event priority. Priority is defined as a value between 0-7 where 0 is the highest priority.

pEvent

VSCP ex event.

priority

Priority to set.

Example
vscpEventEx ex3;
ex3.head = 0;
ex3.vscp_class = 10;
ex3.vscp_type = 6;
ex3.obid = 0;
ex3.timestamp = 0;
memset( ex3.GUID, 0, 16 );
ex3.sizeData = 3;
ex3.data[ 0 ] = 138;
ex3.data[ 1 ] = 0;
ex3.data[ 2 ] = 30;
 
unsigned char eventPriority;
vscphlp_setVscpPriorityEx( &ex3, VSCP_PRIORITY_LOW );
if ( VSCP_PRIORITY_LOW == ( eventPriority = vscphlp_getVscpPriorityEx( &ex3 ) ) ) {
    printf("Event priority = %d\n", eventPriority );
}
else {
    printf("\aError: Set EventEx priority = %d\n", eventPriority );
}

vscphlp_getVSCPheadFromCANALid

unsigned unsigned char vscphlp_getVSCPheadFromCANALid( const unsigned long id ))

Get the VSCP head from a CANAL message id. The VSCP head is defined as shown in the vscp.h header file.

id

Extended 29-bit CAN id to get head from.

Return value

VSCP head byte.

Example
unsigned char vscphead;
unsigned long canalid = 0x0c0a0601;
vscphead = vscphlp_getVSCPheadFromCANALid( canalid );
if ( 96 == vscphead ) {  // Priority == 3 Not hard coded
    printf("VSCP head = %d\n", vscphead );
}
else {
   printf("\aError: vscphlp_getVSCPheadFromCANALid = %d\n", vscphead );
}

vscphlp_getVSCPclassFromCANALid

unsigned short vscphlp_getVSCPclassFromCANALid( unsigned long id )

Get the VSCP class from a CANAL message id.

id

Extended 29-bit CANAL id to get head from.

Return value

VSCP class.

Example
unsigned long canalid = 0x0c0a0601;
unsigned short can_vscpclass = vscphlp_getVSCPclassFromCANALid( canalid );
if ( 10 == can_vscpclass ) {
    printf("VSCP Class = %d\n", can_vscpclass );
}
else {
    printf("\aError: vscphlp_getVSCPclassFromCANAALid = %d\n", can_vscpclass );
}

vscphlp_getVSCPtypeFromCANALid

unsigned short vscphlp_getVSCPtypeFromCANANALid( const unsigned long id )

Get the VSCP type from a a CANAL message id (CAN id).

id

Extended 29-bit CANAL id to get head from.

Return value

VSCP type.

Example
unsigned long cananalid = 0x0c0a0601;
 
unsigned short canal_vscptype = vscphlp_getVSCPtypeFromCANALid( canalid );
if ( 6 == canal_vscptype ) {
    printf("VSCP Type = %d\n", canal_vscptype );
}
else {
    printf("\aError: vscphlp_getVSCPtypeFromCANALid = %d\n", canal_vscptype );
}

vscphlp_getVSCPnicknameFromCANALid

unsigned short vscphlp_getVSCPnicknameFromCANALid( unsigned long id )

Get the VSCP 8-bit nickname from a a CANAL message id.

id

Extended 29-bit CAN id to get head from.

Return value

VSCP 8-bit nickname.

Example
unsigned long canalid = 0x0c0a0601;
unsigned char canal_nickname = vscphlp_getVSCPnicknameFromCANALid( canalid );
if ( 1 == canal_nickname ) {
    printf("VSCP Type = %d\n", canal_vscptype );
}
else {
    printf("\aError: vscphlp_getVSCPnicknameFromCANALid = %d\n", canal_nickname );
}

vscphlp_getCANALidFromVSCPdata

unsigned long vscphlp_getCANALidFromVSCPdata( unsigned char priority, 
                                                unsigned short vscp_class, 
                                                unsigned short vscp_type )

Construct a CANAL id (CAN id ) from a VSCP event.

priority

VSCP event priority (0-7).

vscp_class

VSCP Class.

vscp_type

VSCP type.

Return value

CANAL (CAN) id.

Example
unsigned long constr_canal_id2 = vscphlp_getCANALidFromVSCPdata( 3, 10, 6 ); 
if ( 0x0c0a0600 == constr_canal_id2 ) {
    printf("Nickname = %08X\n", constr_canal_id2 );
}
else {
   printf("\aError: vscphlp_getVSCPnicknameFromCANALid = %08X\n", constr_canal_id2 );
} 

vscphlp_getCANALidFromVSCPevent

unsigned long vscphlp_getCANALidFromVSCPevent( const vscpEvent *pEvent )

Get CANAL id (CAN id) from VSCP event.

pEvent

VSCP event.

Return value

CANAL (CAN) id.

Example
constr_canal_id2 = vscphlp_getCANALidFromVSCPevent( pEvent ); 
if ( 0x0c0a0600 == constr_canal_id2 ) {
    printf("Nickname = %08X\n", constr_canal_id2 );
}
else {
    printf("\aError: vscphlp_getCANALidFromVSCPevent = %08X\n", constr_canal_id2 );
}  

vscphlp_getCANALidFromVSCPeventEx

unsigned long vscphlp_getCANALidFromVSCPeventEx( const vscpEventEx *pEvent )

Get CANAL id (CAN id) from VSCP event.

pEvent

VSCP event.

Return value

CANAL (CAN) id.

Example
constr_canal_id2 = vscphlp_getCANALidFromVSCPeventEx( &ex ); 
if ( 0x0c0a0600 == constr_canal_id2 ) {
    printf("Nickname = %08X\n", constr_canal_id2 );
}
else {
    printf("\aError: vscphlp_getCANALidFromVSCPeventEx = %08X\n", constr_canal_id2 );
}  

vscphlp_calc_crc_Event

short vscphlp_calc_crc_Event ( vscpEvent *pEvent, int bSet )

Calculate VSCP CRC and optionally set it.

pEvent

VSCP event.

bSet

If true (non zero) write the CRC into the event structure crc member.

Return value

VSCP CRC.

Example
unsigned short crc = vscphlp_calc_crc_Event( pEvent, false );
printf("CRC = %04X\n", crc );

vscphlp_calc_crc_EventEx

short vscphlp_calc_crc_EventEx( vscpEvent *pEvent, int bSet )

Calculate VSCP CRC and optionally set it.

pEvent

VSCP event.

bSet

If true (non zero) write the CRC into the event structure crc member.

Return value

VSCP CRC.

Example
unsigned short crc = vscphlp_calc_crc_EventEx( pEvent, false );
printf("CRC = %04X\n", crc );

vscphlp_convertVSCPtoEx

int vscphlp_convertVSCPtoEx( vscpEventEx *pEventEx, 
                              const vscpEvent *pEvent )

Convert VSCP standard event form to ex form.

pEventEx

VSCP event ex to convert to

pEvent

VSCP event to convert to.

Return value

VSCP_ERROR_SUCCESS on success.

Example
vscpEventEx ex4;
if ( VSCP_ERROR_SUCCESS != vscphlp_convertVSCPtoEx( &ex4, pEvent ) ) {
    printf( "\aError: vscphlp_getGuidFromStringToArray\n");
}

vscphlp_convertVSCPfromEx

int vscphlp_convertVSCPfromEx( vscpEvent *pEvent, 
                                        const vscpEventEx *pEventEx )

Convert VSCP ex. event form to standard form.

pEvent

VSCP event to convert to.

pEventEx

VSCP event ex to convert from.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS != vscphlp_convertVSCPfromEx( pEvent, &ex4 ) ) {
    printf( "\aError: vscphlp_convertVSCPfromEx\n");
}

vscphlp_newVSCPevent

bool vscphlp_newVSCPevent( vscpEvent **ppEvent )

Creates a new VSCP event.

pEvent

Pointer to pointer to a VSCP event.

Return value

Return VSCP_ERROR_SUCCESS on success, VSCP_ERROR_ERROR on failure.

Example

vscpEvent *pEvent;
vscphlp_newVSCPevent( &pEvent );

vscphlp_deleteVSCPevent

void vscphlp_deleteVSCPevent( vscpEvent *pEvent )

Delete VSCP event.

pEvent

VSCP event.

Example
vscphlp_deleteVSCPevent( pEvent );

vscphlp_deleteVSCPevent_v2

void vscphlp_deleteVSCPevent_v2( vscpEvent **ppEvent )

Delete VSCP event and set to NULL.

pEvent

Pointer to pointer to a valid VSCP event.

Example
vscphlp_deleteVSCPevent_v2( pEvent );

vscphlp_deleteVSCPeventEx

void vscphlp_deleteVSCPeventEx( vscpEventEx *pEventEx )

Delete VSCP event ex.

pEventEx

VSCP event ex.

Example
vscphlp_deleteVSCPeventEx( &ex )

vscphlp_convertCanalToEvent

int vscphlp_convertCanalToEvent( vscpEvent *pvscpEvent,
                                    const canalMsg *pcanalMsg,
                                    unsigned char *pGUID )

Convert CANAL message to VSCP event.

pvscpEvent

VSCP event that will hold the conversion result.

pcanalMsg

CANAL message that should be converted.

pGUID

GUID for event.

Return value

VSCP_ERROR_SUCCESS on success.

Example
canalMsg canalMsg;
canalMsg.id = 0x0c0a0601;
canalMsg.sizeData = 3;
canalMsg.data[0] = 138;
canalMsg.data[1] = 0;
canalMsg.data[2] = 30;
if ( VSCP_ERROR_SUCCESS == vscphlp_convertCanalToEvent( pEvent,
                                                          &canalMsg,
                                                          GUID2 ) ) {
    printf( "OK vscphlp_convertCanalToEvent VSCP class=%d Type=%d\n", 
                   pEvent->vscp_class, pEvent->vscp_type );
}
else {
    printf( "\aError: vscphlp_convertCanalToEvent\n");
}

vscphlp_convertCanalToEventEx

int vscphlp_convertCanalToEventEx( vscpEvent *pvscpEvent, 
                                      const canalMsg *pcanalMsg, 
                                      unsigned char *pGUID )

Convert CANAL message to VSCP ex event.

pvscpEvent

VSCP event ex that will hold the conversion result.

pcanalMsg

CANAL message that should be converted.

pGUID

GUID for event.

Return value

VSCP_ERROR_SUCCESS on success.

Example
canalMsg canalMsg;
canalMsg.id = 0x0c0a0601;
canalMsg.sizeData = 3;
canalMsg.data[0] = 138;
canalMsg.data[1] = 0;
canalMsg.data[2] = 30;
 
vscpEventEx ex5;
if ( VSCP_ERROR_SUCCESS == vscphlp_convertCanalToEventEx( &ex5,
                                                            &canalMsg,
                                                            GUID2 ) ) {
    printf( "OK vscphlp_convertCanalToEventEx VSCP class=%d Type=%d\n",
                       ex5.vscp_class, ex5.vscp_type );
}
else {
    printf( "\aError: vscphlp_convertCanalToEvent\n");
}

vscphlp_convertEventToCanal

bool vscphlp_convertEventToCanal( canalMsg *pcanalMsg, 
                                  const vscpEvent *pvscpEvent )

Convert VSCP event to CANAL message.

pcanalMsg

CANAL message that will hold result.

pvscpEvent

VSCP event that will be converted.

Return value

VSCP_ERROR_SUCCESS on succes.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_convertEventToCanal( &canalMsg, pEvent ) ) {
    printf( "OK vscphlp_convertEventToCanal id=%08X\n", canalMsg.id );
}
else {
    printf( "\aError: vscphlp_convertEventToCanal\n");
}

vscphlp_convertEventExToCanal

bool vscphlp_convertEventExToCanal( canalMsg *pcanalMsg, 
                                       const vscpEventEx *pvscpEvent )

Convert VSCP event ex to CANAL message.

pcanalMsg

CANAL message that will hold result.

pvscpEvent

VSCP ex event that will be converted.

Return value

VSCP_ERROR_SUCCESS on succes.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_convertEventExToCanal( &canalMsg, &ex5 ) ) {
    printf( "OK vscphlp_convertEventExToCanal id=%08X\n", canalMsg.id );
}
else {
    printf( "\aError: vscphlp_convertEventExToCanal\n");
}

vscphlp makeTimeStamp

unsigned long vscphlp_makeTimeStamp( void )

Get new VSCP timestamp.

Return value

Timestamp in microseconds.

Example
printf( "vscphlp_makeTimeStamp  %04X\n", vscphlp_makeTimeStamp() );






vscphlp_setEventDateTimeBlockToNow

int vscphlp_setEventDateTimeBlockToNow( vscpEvent *pEvent )

Get date/time block for an event.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
vscpEvent *pEvent;
vscphlp_setEventDateTimeBlockToNow( pEvent );






vscphlp_setEventExDateTimeBlockToNow

int vscphlp_setEventExDateTimeBlockToNow( vscpEventEx *pEventEx )

Get date/time block for an ex event.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
vscpEventEx *pEventEx;
vscphlp_setEventExDateTimeBlockToNow( pEventEx );






vscphlp_getDateStringFromEvent

int vscphlp_getDateStringFromEvent( char *buf, size_t buf_len, vscpEvent *pEvent )
buf

Buffer that will get datestring from event

Example result: “2003-11-02T12:23:10Z”

buf_len

Length of the buffer.

pEvent

Event to get datestring from.

Return value

VSCP_ERROR_SUCCESS on success.






vscphlp_getDateStringFromEventEx

int vscphlp_getDateStringFromEventEx( char *buf, size_t buf_len, vscpEventEx *pEventEx )
buf

Buffer that will get datestring from event ex.

Example result: “2003-11-02T12:23:10Z”

buf_len

Length of the buffer.

pEventEx

Event to get datestring from.

Return value

VSCP_ERROR_SUCCESS on success.






Filter handling

vscphlp_clearVSCPFilter

void vscphlp_clearVSCPFilter( vscpEventFilter *pFilter )

Clear VSCP filter.

pFilter

Pointer to VSCP filter structure.

Example
vscphlp_clearVSCPFilter( pFilter )

vscphlp_copyVSCPFilter

void vscphlp_copyVSCPFilter( vscpEventFilter *pToFilter, const vscpEventFilter *pFromFilter )

Copy VSCP filter from one to another.

pToFilter

Pointer to VSCP filter structure that will receive data.

pFromFilter

Pointer to VSCP filter structure that data will be copied from.

Example
vscphlp_clearVSCPFilter( pFilter )

vscphlp_readFilterFromString

int vscphlp_readFilterFromString( vscpEventFilter *pFilter, 
                                   char *strFilter )

Read a filter from a string. If strFilter is an empty string all elements in filter will be set to zero. Arguments is

      priority,class,type,GUID 

and all is optional but if given must be given in order.

pFilter

Filter structure to write filter to.

strFilter

Filter in string form

 filter-priority, filter-class, filter-type, filter-GUID

as in this example

1,0x0000,0x0006,ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00

and all is optional but if given must be given in order. This means

1,0x0000,0x0006

for example is OK setting GUID to all zeros.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS != vscphlp_readFilterFromString( &filter, 
                "1,0x0000,0x0006,ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00" ) ) {
    printf( "\aError: vscphlp_readFilterFromString\n");   
}

vscphlp_writeFilterToString

    bool vscp_writeFilterToString(vscpEventFilter *pFilter, char * strFilter);

Write a filter on comma separated form to a string (priority,class,type,GUID).

pFilter

Filter structure to write filter to.

strFilter

Will get the filter in string form priority,class,type,GUID. Must be at least 65 bytes.

filter-priority, filter-class, filter-type, filter-GUID
Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS != vscphlp_writeFilterToString( &filter, str ) ) {
    printf( "\aError: vscphlp_writeFilterToString\n");   
}

vscphlp_readMaskFromString

int vscphlp_readMaskFromString( vscpEventFilter *pFilter, 
                                   const char * strMask )

Read a mask from a string. If strMask is an empty string elements in mask will be set to zero.

pFilter

Filter structure to write mask to.

strMask

Mask in string form

mask-priority, mask-class, mask-type, mask-GUID

as in this example

1,0x00ff,0x00ff,ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff  

and all is optional but if given must be given in order.This means that

1,0x00ff

will be interpreted as

1,0x00ff,0x0000,00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00  
Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS != vscphlp_readMaskFromString( &filter, 
                "1,0x0000,0x0006,ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00" ) ) {
    printf( "\aError: vscphlp_readMaskFromString\n");   
}

vscphlp_writeMaskToString

int vscphlp_writeMaskToString( vscpEventFilter *pFilter, 
                                   char * strMask )

Write the mask in comma separated form to a string. If strMask is an empty string elements in mask will be set to zero.

pFilter

Filter structure to write mask from.

strMask

String that will get mask in comma separated string form. Must be at least 65 bytes.

mask-priority, mask-class, mask-type, mask-GUID
Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS != vscphlp_writeMaskToString( &filter, 
                "1,0x0000,0x0006,ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00" ) ) {
    printf( "\aError: vscphlp_writeMaskToString\n");   
}

vscphlp_doLevel2Filter

int vscphlp_doLevel2Filter( const vscpEvent *pEvent, 
                             const vscpEventFilter *pFilter )

Check VSCP filter condition.

Return value

Return true (non-zero) if the event is accepted by the filter.

Example
if ( vscphlp_doLevel2Filter( pEvent, &filter ) ) {
    printf( "Event pass:  vscphlp_doLevel2Filter\n");
}
else {
   printf( "Event does NOT pass:  vscphlp_doLevel2Filter\n");
}






GUID Handling

vscphlp_getGuidFromString

int vscphlp_getGuidFromString( vscpEvent *pEvent, const char * pGUID )

Write GUID into VSCP event from a string.

pEvent

VSCP event.

pGUID

Pointer to GUID in string form.

Return value

VSCP_ERROR_SUCCESS on success.

Example
char strguid[64], strguid2[64];
 
if ( VSCP_ERROR_SUCCESS == vscphlp_getGuidFromString( pEvent, strguid ) )  { 
    vscphlp_writeGuidToString( pEvent, strguid2, sizeof( strguid2 )-1 );
    printf( "GUID=%s\n", strguid2 );
}
else {
    printf( "\aError: vscphlp_writeGuidArrayToString\n");
}

vscphlp_getGuidFromStringEx

int vscphlp_getGuidFromStringEx( vscpEvent *pEvent, const char * pGUID )

Write GUID into VSCP event ex from a string.

pEvent

VSCP event ex.

pGUID

Pointer to GUID in string form.

Return value

VSCP_ERROR_SUCCESS on success.

Example
char strguid[64], strguid2[64];
 
if ( VSCP_ERROR_SUCCESS == vscphlp_getGuidFromStringEx( &ex3, strguid ) ) {        
    vscphlp_writeGuidToStringEx( &ex3, strguid2, sizeof( strguid2 )-1 );
    printf( "GUID=%s\n", strguid2 );
}
else {
    printf( "\aError: vscphlp_writeGuidArrayToString\n");
}

vscphlp_getGuidFromStringToArray

int vscphlp_getGuidFromStringToArray( uint8_t *pGUID, const char * pStr )

Write GUID from string into array.

pGUID

Pointer to VSCP GUID array to fill.

pStr

Pointer to GUID in string form.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_getGuidFromStringToArray( GUID2, strguid ) ) {
    vscphlp_writeGuidArrayToString( GUID2, strguid2, sizeof( strguid2 )-1 );
    printf( "GUID  after reverse = %s\n", strguid2 );
}
else {
    printf( "\aError: vscphlp_getGuidFromStringToArray\n");
}

vscphlp_writeGuidToString

int vscphlp_writeGuidToString( const vscpEvent *pEvent, char *pStr, size_t len )

Write GUID from VSCP event to string.

pEvent

VSCP event.

pStr

Pointer to GUID in string form.

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_getGuidFromString( pEvent, strguid ) ) {
   vscphlp_writeGuidToString( pEvent, strguid2, sizeof( strguid2 )-1 );
   printf( "GUID=%s\n", strguid2 );
}
else {
    printf( "\aError: vscphlp_writeGuidArrayToString\n");
}

vscphlp_writeGuidToStringEx

int vscphlp_writeGuidToStringEc( const vscpEventEx *pEvent, char *pStr, size_t len )

Write GUID from VSCP event to string.

pEvent

VSCP event.

pStr

Pointer to GUID in string form.

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_getGuidFromStringEx( &ex3, strguid ) ) {
    vscphlp_writeGuidToStringEx( &ex3, strguid2, sizeof( strguid2 )-1 );
    printf( "GUID=%s\n", strguid2 );
}
else {
    printf( "\aError: vscphlp_writeGuidArrayToString\n");
}

vscphlp_writeGuidToString4Rows

int vscphlp_writeGuidToString4Rows( const vscpEvent *pEvent, 
                                      char *strGUID,
                                      size_t len )

Write GUID from VSCP event to string with four bytes on each row separated by “\r\n”.

pEvent

VSCP event.

strGUID

String that get formatted GUID.

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_writeGuidToString4Rows( pEvent, strguid2, sizeof( strguid2 )-1 ) ) {
    printf( "GUID\n%s\n", strguid2 );
}
else {
    printf( "Error: vscphlp_writeGuidArrayToString\n");
}

vscphlp_writeGuidToString4RowsEx

int vscphlp_writeGuidToString4RowsEx( const vscpEventEx *pEvent, 
                                          char *strGUID,
                                          size_t len )

Write GUID from VSCP event to string with four bytes on each row separated by “\r\n”.

pEvent

VSCP event.

strGUID

String that get formatted GUID.

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_writeGuidToString4RowsEx( &ex3, strguid2, sizeof( strguid2 )-1 ) ) {
    printf( "GUID\n%s\n", strguid2 );
}
else {
    printf( "Error: vscphlp_writeGuidArrayToString\n");
}

vscphlp_writeGuidArrayToString

int vscphlp_writeGuidArrayToString( const unsigned char * pGUID, 
                                     char *strGUID,
                                     size_t len )

Write GUID from byte array to string.

pGUID

A 16 byte GUID array.

strGUID

Pointer to buffer that can hold the GUID in string form.

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS on success.

Example
if ( VSCP_ERROR_SUCCESS == vscphlp_writeGuidArrayToString( GUID2, strguid2, sizeof( strguid2 )-1 ) ) {
    printf( "GUID=%s\n", strguid2 );
}
else {
    printf( "Error: vscphlp_writeGuidArrayToString\n");
}

vscphlp_isGUIDEmpty

int vscphlp_isGUIDEmpty( unsigned char *pGUID )

Check if GUID is empty (all nulls).

pGUID

xxx

Return value

True (non-zero) if GUID are empty.

Example
unsigned char emptyGUID[16];
memset( emptyGUID,0, 16 );
if ( vscphlp_isGUIDEmpty( emptyGUID ) ) {
    printf( "vscphlp_isGUIDEmpty  - GUID is detected as empty as it should be\n" );    
}
else {
    printf( "\aError: vscphlp_isGUIDEmpty\n");
}
 
if ( vscphlp_isGUIDEmpty( GUID2 ) ) {
    printf( "\aError: vscphlp_isGUIDEmpty\n");    
}
else {
    printf( "vscphlp_isGUIDEmpty  - GUID is detected as NOT empty as it should be\n" );
}

vscphlp_isSameGUID

int vscphlp_isSameGUID( const unsigned char *pGUID1, 
                         const unsigned char *pGUID2 )

Check if two GUID's is equal to each other.

pGUID1

GUID1 to compare.

pGUID2

GUID2 to compare.

Return value

True (non-zero) if GUIDs are the same.

Example
if ( vscphlp_isSameGUID( emptyGUID, GUID2) ) {
    printf( "\aError: vscphlp_isSameGUID\n");
}
else {
    printf( "vscphlp_isSameGUID  - Correct, GUIDs are not the same.\n" );
}

vscphlp_reverseGUID

int vscphlp_reverseGUID(unsigned char *pGUID)

Reverse a GUID array.

pGUID1

GUID array to be reversed.

Return value

Return VSCP_ERROR_SUCCESS on success.

Example
vscphlp_writeGuidArrayToString( GUID2, strguid2, sizeof( strguid2 )-1 );
printf( "GUID before reverse = %s\n", strguid2 );
if ( VSCP_ERROR_SUCCESS == vscphlp_reverseGUID( GUID2 ) ) {
    vscphlp_writeGuidArrayToString( GUID2, strguid2, sizeof( strguid2 )-1 );
    printf( "GUID  after reverse = %s\n", strguid2 );
}
else {
    printf( "\aError: vscphlp_reverseGUID\n");
}

vscphlp_calcCRC4GUIDArray

unsigned char vscphlp_calcCRC4GUIDArray( unsigned char *pguid )

Calculate 8-bit crc for a GUID array.

pguid

Array of sixteen bytes containing GUID on MSB→LSB order.

Return value

8-bit CRC for GUID.

Example
// Calculate CRC for GID array
unsigned char GUID2[16];
memset( GUID2, 0, 16 );
for ( int i=0;i<16; i++ ) {
    GUID2[i] = i;
}
unsigned char crc8 = vscphlp_calcCRC4GUIDArray( GUID2 );
printf("CRC = %02X\n", crc8 );

vscphlp_calcCRC4GUIDString

unsigned char vscphlp_calcCRC4GUIDString( unsigned char *strguid)

Calculate 8-bit crc for a GUID string.

strguid

String containing GUID on standard string form.

Return value

8-bit CRC for GUID.

Example
// Calculate GUID for GUID string
char strguid[64];
strcpy( strguid, "FF:FF:FF:FF:FF:FF:FF:00:00:00:00:7F:00:01:01:FD" );
crc8 = vscphlp_calcCRC4GUIDString( strguid);
printf("CRC = %02X\n", crc8 )






Measurement helpers

vscphlp_getMeasurementDataCoding

unsigned char vscphlp_getMeasurementDataCoding( const vscpEvent *pEvent )

Get the measurement data coding byte from an event. The measurement data coding byte specifies how the data in the event should be interpreted.

pEvent

Event that the data coding is fetched from.

Return value

Data coding

Example
pEvent = new vscpEvent;
pEvent->head = 0;
pEvent->vscp_class = 10;
pEvent->vscp_type = 6;
pEvent->obid = 0;
pEvent->timestamp = 0;
memset( pEvent->GUID, 0, 16 );
pEvent->sizeData = 3;
pEvent->pdata = new unsigned char[3];
pEvent->pdata[ 0 ] = 138;
pEvent->pdata[ 1 ] = 0;
pEvent->pdata[ 2 ] = 30;
 
unsigned char dataCoding = vscphlp_getMeasurementDataCoding( pEvent );
if ( dataCoding = 138 ) {
    printf("Data Coding = %d\n", dataCoding );
}
else {
    printf("Error: Data Coding = %d\n", dataCoding );
}

vscphlp_getDataCodingBitArray

unsigned long long vscphlp_getDataCodingBitArray( const unsigned char *pNorm,
                                                    int size)

Get measurement data that is coed as bits as a unsigned 64-bit value.

pNorm

Pointer to the data coding byte of event measurement data.

size

Number of bytes the measurement data consist of including the initial data coding byte.

Return value

A 64-bit unsigned integer is returned. The bits in the measurement data array are in MSB - LSB order and this is preserved in the unsigned 64-bit integer.

Example
unsigned char bitarry[3];
bitarry[0] = VSCP_DATACODING_BIT; // Data cding byte. Default unit, sensoridx=0
bitarry[1] = 0x55;
bitarry[2] = 0xAA;
unsigned long long bitarray64 = vscphlp_getDataCodingBitArray( bitarry, sizeof( bitarry ) )

vscphlp_getDataCodingInteger

unsigned long long vscphlp_getDataCodingInteger(const unsigned char *pCode, 
                                                   int size )

Get measurement data that is coded as a aigned integer (1-7 bytes) as a 64-bit integer.

pCode

A pointer to the data coding byte of the measurement data.

size

The size of the measurement data including the data coding byte.

Return value

A double precision floating point value that is the decimal representation of the measurement data.

Example
unsigned char normarry[4];
normarry[0] = 0x60; // Data coding byte:integer, unit=0, sensoridx=0
normarry[1] = 0xFF;
normarry[2] = 0xFF;
normarry[3] = 0xFF;
double value =  vscphlp_getDataCodingInteger (normarry, sizeof( normarry ) );
if ( 3.1 == value ) {
    printf("OK - vscphlp_getDataCodingInteger value = %f \n", value );
}
else {
    printf("Error - vscphlp_getDataCodingNormalizedInteger value = %f \n", value );
}

vscphlp_getDataCodingNormalizedInteger

double vscphlp_getDataCodingNormalizedInteger(const unsigned char *pCode, 
                                                 int size )

Get measurement data that is coded as a normalized integer as a floating point value.

pCode

A pointer to the data coding byte of the measurement data.

size

The size of the measurement data including the data coding byte.

Return value

A double precision floating point value that is the decimal representation of the measurement data.

Example
unsigned char normarry[4];
normarry[0] = 0x89; // Data coding byte: Normalized integer, unit=1, sensoridx=1
normarry[1] = 0x02;
normarry[2] = 0x01;
normarry[3] = 0x36;
double value =  vscphlp_getDataCodingNormalizedInteger (normarry, sizeof( normarry ) );
if ( 3.1 == value ) {
    printf("OK - vscphlp_getDataCodingNormalizedInteger value = %f \n", value );
}
else {
    printf("Error - vscphlp_getDataCodingNormalizedInteger value = %f \n", value );
}

vscphlp_getDataCodingString

int vscphlp_getDataCodingString(const unsigned char *pData,
                                   unsigned char dataLength, 
                                   char *strResult,
                                   size_t len )
pData

Pointer to the data coding byte of the data.

dataLength

Total length of the data including the data coding byte.

strResult

Pointer to the buffer that will receive the resulting string.

len

Size of the supplied buffer (strResult). Max size of the string is 7 bytes + the terminating zero so the supplied size should be 8 bytes or larger.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
unsigned char stringarry[6];
stringarry[0] = VSCP_DATACODING_STRING; // Data cding byte. Default unit, sensoridx=0
stringarry[1] = 0x32;
stringarry[2] = 0x33;
stringarry[3] = 0x34;
stringarry[4] = 0x2E;
stringarry[5] = 0x35;
char stringbuf[32];
if ( VSCP_ERROR_SUCCESS == vscphlp_getDataCodingString( stringarry,
                                                           sizeof( stringarry ), 
                                                           stringbuf,
                                                           sizeof( stringbuf ) ) ) {
    printf("OK - vscphlp_getDataCodingString value = %s \n", stringbuf );
}
else {
    printf("Error - vscphlp_getDataCodingString value = %s \n", stringbuf );
}

vscphlp_getVSCPMeasurementAsString

int vscphlp_getVSCPMeasurementAsString( const vscpEvent *pEvent, 
                                           char *pResult, 
                                           size_t len )

This method returns a string representing the measurement data. It recognize all data coding forms and give sensible output back.

pEvent

The event the measurement string should be collected from.

pResult

The resulting measurement in string form.

len

Size for the buffer in which the resulting string is written.

Return value

VSCP_ERROR_SUCCESS is return on success.

Example
vscpEvent *pEventMeasurement = new vscpEvent;
pEventMeasurement->head = 0;
pEventMeasurement->vscp_class = 10;
pEventMeasurement->vscp_type = 6;
pEventMeasurement->obid = 0;
pEventMeasurement->timestamp = 0;
memset( pEventMeasurement->GUID, 0, 16 );
pEventMeasurement->sizeData = 4;
pEventMeasurement->pdata = new unsigned char[ pEventMeasurement->sizeData ];
pEventMeasurement->pdata[0] = 0x89;
pEventMeasurement->pdata[1] = 0x02;
pEventMeasurement->pdata[2] = 0x00;
pEventMeasurement->pdata[3] = 0xF1;
 
if ( VSCP_ERROR_SUCCESS == vscphlp_getVSCPMeasurementAsString( pEventMeasurement, 
                                                              stringbuf, 
                                                              sizeof( stringbuf ) ) ) {
    printf("OK - vscphlp_getVSCPMeasurementAsString value = %s \n", stringbuf );
}
else {
    printf("Error - vscphlp_getVSCPMeasurementAsString value = %s \n", stringbuf );
}
 
pEventMeasurement->pdata[0] = 0x89;
pEventMeasurement->pdata[1] = 0x02;
pEventMeasurement->pdata[2] = 0xFF;
pEventMeasurement->pdata[3] = 0xF1;
 
if ( VSCP_ERROR_SUCCESS == vscphlp_getVSCPMeasurementAsString( pEventMeasurement, 
                                                              stringbuf, 
                                                              sizeof( stringbuf ) ) ) {
    printf("OK - vscphlp_getVSCPMeasurementAsString value = %s \n", stringbuf );
}
else {
    printf("Error - vscphlp_getVSCPMeasurementAsString value = %s \n", stringbuf );
}
 
// Free the event
vscphlp_deleteVSCPevent( pEventMeasurement );

vscphlp_getVSCPMeasurementAsDouble

int vscphlp_getVSCPMeasurementAsDouble( const vscpEvent *pEvent, 
                                           double *pvalue)

This method returns a double representing the measurement data. It recognize all data coding forms and give sensible output back.

pEvent

The event that contain the measurement data.

pvalue

A pointer to a double that will get the measurement result.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
pEventMeasurement->pdata[0] = VSCP_DATACODING_INTEGER;
pEventMeasurement->pdata[1] = 0xFF;
pEventMeasurement->pdata[2] = 0xFF;
pEventMeasurement->pdata[3] = 0xFF;
 
if ( VSCP_ERROR_SUCCESS == vscphlp_getVSCPMeasurementAsDouble( pEventMeasurement, &value ) ) {
    printf("OK - vscphlp_getVSCPMeasurementAsDouble value = %lf\n", value );
}
else {
    printf("Error - vscphlp_getVSCPMeasurementAsDouble value = %slf \n", value );
}

vscphlp_getVSCPMeasurementFloat64AsString

int vscphlp_getVSCPMeasurementFloat64AsString(const vscpEvent *pEvent, 
                                                 char *pStrResult, 
                                                 size_t len )

This method displays data stored in 32-bit floating point form (IEEE 754) as a string

pEvent

The event that contain the measurement data.

pStrResult

Buffer that will get the string result as a null terminated string.

len

The size of the buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
vscpEvent *pEventfloat = new vscpEvent;
pEventfloat->head = 0;
pEventfloat->vscp_class = 10;
pEventfloat->vscp_type = 6;
pEventfloat->obid = 0;
pEventfloat->timestamp = 0;
memset( pEventfloat->GUID, 0, 16 );
pEventfloat->sizeData = 8;
pEventfloat->pdata = new unsigned char[ pEventfloat->sizeData ];
pEventfloat->pdata[0] = 234;
pEventfloat->pdata[1] = 46;
pEventfloat->pdata[2] = 68;
pEventfloat->pdata[3] = 84;
pEventfloat->pdata[4] = 251;
pEventfloat->pdata[5] = 33;
pEventfloat->pdata[6] = 9;
pEventfloat->pdata[7] = 64;
 
if ( VSCP_ERROR_SUCCESS == 
       vscphlp_getVSCPMeasurementFloat64AsString( pEventfloat, 
                                                    stringbuf,
                                                    sizeof( stringbuf ) ) ) {
    printf("OK - vscphlp_getVSCPMeasurementFloat64AsString value = %s \n", stringbuf );
}
else {
    printf("Error - vscphlp_getVSCPMeasurementFloat64AsString value = %s \n", stringbuf );
}
 
// Free the event
vscphlp_deleteVSCPevent( pEventfloat );

vscphlp_convertFloatToNormalizedEventData

int vscphlp_convertFloatToNormalizedEventData( 
                                   unsigned char *pdata,                                                        
                                   unsigned short *psize,    
                                   double value, 
                                   unsigned char unit,
                                   unsigned char sensoridx )

Write a 64-bit floating point value as event measurement data.

pdata

Pointer to data buffer that will get the result. The buffer should be large enough to hold the normalized data. That is bigger than eight bytes.

psize

The size of the written data will be returned here.

psize

Floating point value to write as a 64-bit double.

unit

A unit value 0-3

sensoridx

A sensor index value 0-7

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
Example will be added.

vscphlp_convertFloatToFloatEventData

int vscphlp_convertFloatToFloatEventData( unsigned char *pdata,
                                              unsigned short *psize, 
                                              float value,
                                              unsigned char unit,
                                              unsigned char sensoridx )

Write a 32-nit floating point value as measurement event data.

pdata

Pointer to data buffer that will get the result. The buffer should be large enough to hold the normalized data. That is bigger than eight bytes.

psize

The size of the written data will be returned here.

value

Floating point value to write as a 32-bit float.

unit

A unit value 0-3

sensoridx

A sensor index value 0-7

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
Example will be added.

vscphlp_convertIntegerToNormalizedEventData

int vscphlp_convertIntegerToNormalizedEventData( unsigned char *pdata,
                                                    unsigned short *psize,
                                                    unsigned long long val64,
                                                    unsigned char unit,
                                                    unsigned char sensoridx )

Write an integer value as measurement event data in normalized integer form.

pdata

Pointer to data buffer that will get the result. The buffer should be large enough to hold the normalized data. That is bigger than eight bytes.

psize

The size of the written data will be returned here.

value

Floating point value to write as a 64-bit float.

unit

A unit value 0-3

sensoridx

A sensor index value 0-7

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
Example will be added.

vscphlp_makeFloatMeasurementEvent

int vscphlp_makeFloatMeasurementEvent( vscpEvent *pEvent, 
                                          float value,
                                          unsigned char unit,
                                          unsigned char sensoridx )
pEvent

Pointer to a VSCP event that will get the result as it's data.

psize

The size of the written data will be returned here.

value

Floating point value to write as a 32-bit float.

unit

A unit value 0-3

sensoridx

A sensor index value 0-7

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
Example will be added.

vscphlp_makeFloatMeasurementEvent

int vscphlp_makeFloatMeasurementEvent( vscpEvent *pEvent, 
                                          float value,
                                          unsigned char unit,
                                          unsigned char sensoridx )

Construct a floating point (32-bit) measurement VCSP event.

pEvent

Pointer to a VSCP event that will get the result as it's data.

psize

The size of the written data will be returned here.

value

Floating point value to write as a 32-bit float.

unit

A unit value 0-3

sensoridx

A sensor index value 0-7

Return value

VSCP_ERROR_SUCCESS is returned on success.

Example
Example will be added.

vscphlp_getMeasurementAsFloat

int vscphlp_getMeasurementAsFloat(const unsigned char *pData, 
                                     unsigned char length,
                                     float *pResult )

This event is yet to be defined. Do not use.

Return value

VSCP_ERROR_SUCCESS is returned on success.

vscphlp_getMeasurementUnit

int vscphlp_getMeasurementUnit( const vscpEvent *pEvent )

Get unit for a measurement event. Some events does not have a unit defined and for then zero is always returned as it is understood that the default unit should be used.

Return value

Unit is returned as 0-3 for a Level I event and as 0-255 for a level II event.

vscphlp_getMeasurementSensorIndex

int vscphlp_getMeasurementSenzorIndex( const vscpEvent *pEvent )

Get the sensor index for a measurement event. Some events does not have a sensor index defined and for them zero is always returned.

Return value

Sensor index is returned as 0-7 for a Level I event and as 0-255 for a level II event. 1 is returned if the event is not a measurement event or is invalid.

vscphlp_getMeasurementZone

int vscphlp_getMeasurementZone( const vscpEvent *pEvent )

Get zone for a measurement event. Some events does not have a zone defined and for them zero is always returned.

Return value

Zone is returned as 0-255 where 255 means “all zones”. 1 is returned if the event is not a measurement event or is invalid.

vscphlp_getMeasurementSubZone

int vscphlp_getMeasurementSubZone( const vscpEvent *pEvent )

Get subzone for a measurement event.

Return value

Zone is returned as 0-255 where 255 means “all zones”. -1 is returned if the event is not a measurement event or is invalid. Some events does not have a subzone defined and for them zero is always returned.

vscphlp_isMeasurement

int vscphlp_isMeasurement( const vscpEvent *pEvent )

Check if an event is a measurement.

Return value

VSCP_ERROR_SUCCESS is returned if the event is a measurement, VSCP_ERROR_ERROR is returned if the event is not a measurement.

vscphlp_convertLevel1MeasuremenToLevel2Double

int vscphlp_convertLevel1MeasuremenToLevel2Double( vscpEvent *pEvent )

Convert Level I measurement to a Level II float measurement event (CLASS2.MEASUREMENT_FLOAT).

Return value

VSCP_ERROR_SUCCESS is returned if the measurement event is converted correctly, VSCP_ERROR_ERROR is returned if not.

vscphlp_convertLevel1MeasuremenToLevel2String

int vscphlp_convertLevel1MeasuremenToLevel2String( vscpEvent *pEvent )

Convert Level I measurement to a Level II string measurement event (CLASS2.MEASUREMENT_STRING).

Return value

VSCP_ERROR_SUCCESS is returned if the measurement event is converted correctly, VSCP_ERROR_ERROR is returned if not.

vscphlp_makeLevel2FloatMeasurementEvent

int vscphlp_makeLevel2FloatMeasurementEvent( vscpEvent *pEvent, 
                                                uint16_t type,
                                                double value,
                                                uint8_t unit,
                                                uint8_t sensoridx,
                                                uint8_t zone,
                                                uint8_t subzone )

Note that the GUID must be set externally.

pEvent

Pointer to event that data should be written to.

type

The VSCP type for the event. Must be one of the types in CLASS1.MEASUREMENT

value

Floating point measurement value.

unit

Unit (0-255) for the measurement.

sensoridx

Sensor index (0-255) for the measurement.

zone

Zone (0-255) for the measurement.

subzone

Sub zone (0-255) for the measurement.

Construct a Level II floating point measurement event from supplied data.

Return value

VSCP_ERROR_SUCCESS is returned if the measurement event is constructed correctly, VSCP_ERROR_ERROR is returned if not.

vscphlp_makeLevel2StringMeasurementEvent

int vscphlp_makeLevel2StringMeasurementEvent( vscpEvent *pEvent, 
                                                uint16_t type,
                                                double value,
                                                uint8_t unit,
                                                uint8_t sensoridx,
                                                uint8_t zone,
                                                uint8_t subzone )

Note that the GUID must be set externally.

pEvent

Pointer to event that data should be written to.

type

The VSCP type for the event. Must be one of the types in CLASS1.MEASUREMENT

value

Floating point measurement value.

unit

Unit (0-255) for the measurement.

sensoridx

Sensor index (0-255) for the measurement.

zone

Zone (0-255) for the measurement.

subzone

Sub zone (0-255) for the measurement.

Construct a Level II string measurement event from supplied data.

Return value

VSCP_ERROR_SUCCESS is returned if the measurement event is constructed correctly, VSCP_ERROR_ERROR is returned if not.

vscphlp_convertEventToJSON

int vscphlp_convertEventToJSON( vscpEvent *pEvent, char *pBuffer, size_t len );

Write VSCP event on JSON format to string. Format is specified in vscp.h.

pEvent

Pointer to event.

pBuffer

Buffer that will receive string result ==

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success, VSCP_ERROR_BUFFER_TO_SMALL is returned if the size of the supplied buffer is to small.

vscphlp_convertEventExToJSON

int vscphlp_convertEventExToJSON( vscpEventEx *pEventEx, char *pBuffer, size_t len );

Write VSCP event-ex on JSON format to string. Format is specified in vscp.h.

pEventEx

Pointer to eventex.

pBuffer

Buffer that will receive string result ==

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success, VSCP_ERROR_BUFFER_TO_SMALL is returned if the size of the supplied buffer is to small.

vscphlp_convertEventToXML

int vscphlp_convertEventToXML( vscpEvent *pEvent, char *pBuffer, size_t len );

Write VSCP event on XML format to string. Format is specified in vscp.h.

pEvent

Pointer to event.

pBuffer

Buffer that will receive string result ==

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success, VSCP_ERROR_BUFFER_TO_SMALL is returned if the size of the supplied buffer is to small.

vscphlp_convertEventExToXML

int vscphlp_convertEventExToXML( vscpEventEx *pEventEx, char *pBuffer, size_t len );

Write VSCP event-ex on XML format to string. Format is specified in vscp.h.

pEventEx

Pointer to eventex.

pBuffer

Buffer that will receive string result ==

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success, VSCP_ERROR_BUFFER_TO_SMALL is returned if the size of the supplied buffer is to small.

vscphlp_convertEventToHTML

int vscphlp_convertEventToHTML( vscpEvent *pEvent, char *pBuffer, size_t len );

Write VSCP event on HTML format to string. Format is specified in vscp.h.

pEvent

Pointer to event.

pBuffer

Buffer that will receive string result ==

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success, VSCP_ERROR_BUFFER_TO_SMALL is returned if the size of the supplied buffer is to small.

vscphlp_convertEventExToHTML

int vscphlp_convertEventExToHTML( vscpEventEx *pEventEx, char *pBuffer, size_t len );

Write VSCP event-ex on HTML format to string. Format is specified in vscp.h.

pEventEx

Pointer to eventex.

pBuffer

Buffer that will receive string result ==

len

Size of string buffer.

Return value

VSCP_ERROR_SUCCESS is returned on success, VSCP_ERROR_BUFFER_TO_SMALL is returned if the size of the supplied buffer is to small.



Copyright © 2000-2017 Åke Hedman, Paradise of the Frog / Grodans Paradis AB