Skip to content

Commit

Permalink
Not fully working but still proof of concept node discovery in place.…
Browse files Browse the repository at this point in the history
… Release time.
  • Loading branch information
grodansparadis committed Nov 4, 2015
1 parent 50aeddf commit d805a97
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 84 deletions.
2 changes: 1 addition & 1 deletion config_examples/variables.xml_distro
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<variable type="guid">
<name>SIM1_GUID0</name>
<note>GUID for the node.</note>
<value>FF:FF:FF:FF:FF:FF:FF:F7:03:00:00:00:00:00:00:00</value>
<value>FF:FF:FF:FF:FF:FF:FF:F7:03:11:22:33:44:55:66:77</value>
</variable>

<variable type="string">
Expand Down
2 changes: 1 addition & 1 deletion src/common/rapidxml/rapidxml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ namespace rapidxml

Ch * nullstr()
{
if (!m_nullstr);
if (!m_nullstr)
m_nullstr = allocate_string("");
return m_nullstr;
}
Expand Down
95 changes: 64 additions & 31 deletions src/vscp/common/daemonvscp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ void *daemonVSCPThread::Entry()
}
}

///////////////////////////////////////////////////////////////////////
// Input queue
///////////////////////////////////////////////////////////////////////

int rv = pClientItem->m_clientInputQueue.GetCount();
// Wait for incoming event
if ( wxSEMA_TIMEOUT == pClientItem->m_semClientInputQueue.WaitTimeout( 100 ) ) continue;
Expand Down Expand Up @@ -347,7 +351,7 @@ void *daemonVSCPThread::Entry()

// New node on-line - collect
else if ( ( VSCP_CLASS1_PROTOCOL == pEvent->vscp_class ) &&
( VSCP_TYPE_PROTOCOL_NEW_NODE_ONLINE == pEvent->vscp_type ) ) {
( VSCP_TYPE_PROTOCOL_NEW_NODE_ONLINE == pEvent->vscp_type ) ) {

// Add node to knows nodes or return info if known
CNodeInformation *pNode = addNodeIfNotKnown( pEvent );
Expand All @@ -363,7 +367,7 @@ void *daemonVSCPThread::Entry()

// Level I node heart beat - collect
else if ( ( VSCP_CLASS1_INFORMATION == pEvent->vscp_class ) &&
( VSCP_TYPE_INFORMATION_NODE_HEARTBEAT == pEvent->vscp_type ) ) {
( VSCP_TYPE_INFORMATION_NODE_HEARTBEAT == pEvent->vscp_type ) ) {

// Add node to knows nodes or return info if known
CNodeInformation *pNode = addNodeIfNotKnown( pEvent );
Expand Down Expand Up @@ -415,7 +419,7 @@ void *daemonVSCPThread::Entry()

// Level II node heart beat - collect
else if ( ( VSCP_CLASS2_INFORMATION == pEvent->vscp_class ) &&
( VSCP_TYPE_INFORMATION_NODE_HEARTBEAT == pEvent->vscp_type ) ) {
( VSCP_TYPE_INFORMATION_NODE_HEARTBEAT == pEvent->vscp_type ) ) {

// Send event on multicast information channel
sendMulticastEvent( sock_mc, pEvent, mc_port );
Expand Down Expand Up @@ -492,18 +496,20 @@ CNodeInformation * daemonVSCPThread::addNodeIfNotKnown( vscpEvent *pEvent )
m_pCtrlObject->m_knownNodes.m_nodes[ strGUID ] = pNode;
m_pCtrlObject->m_mutexKnownNodes.Unlock();

// Is there a device realted to this node
// Is there a device related to this node
m_pCtrlObject->m_mutexDeviceList.Lock();
CDeviceItem *pDeviceItem =
m_pCtrlObject->m_deviceList.getDeviceItemFromClientId( pEvent->obid );
if ( NULL != pDeviceItem ) {

// Construct a name if no name set
// 'device.nickname'
if ( pNode->m_strNodeName.IsEmpty() ) {
pNode->m_strNodeName = pDeviceItem->m_strName;
pNode->m_strNodeName += _( "." );
pNode->m_strNodeName += wxString::Format( _( "%lu" ), pDeviceItem->m_pClientItem->m_clientID );
pNode->m_level = pDeviceItem->m_driverLevel;

// Construct a devicename if no devicename set
// 'devicename_clientid'
if ( pNode->m_deviceName.IsEmpty() ) {
pNode->m_deviceName = pDeviceItem->m_strName;
pNode->m_deviceName += _( "_" );
pNode->m_deviceName += wxString::Format( _( "%lu" ), pDeviceItem->m_pClientItem->m_clientID );
}

// Save interface
Expand All @@ -512,12 +518,12 @@ CNodeInformation * daemonVSCPThread::addNodeIfNotKnown( vscpEvent *pEvent )
// Save Client ID
pNode->m_clientID = pEvent->obid;

// We set name fron client id
// 'client|clientid|.nickname'
// We set name from client id
// 'client_clientid_nickname'
if ( pNode->m_strNodeName.IsEmpty() ) {
pNode->m_strNodeName = _( "client" );
pNode->m_strNodeName = _( "client_" );
pNode->m_strNodeName += wxString::Format( _( "%lu" ), pDeviceItem->m_pClientItem->m_clientID );
pNode->m_strNodeName += _( "." );
pNode->m_strNodeName += _( "_" );
pNode->m_strNodeName += wxString::Format( _( "%u" ), ( pEvent->GUID[ 14 ] << 8 ) + pEvent->GUID[ 15 ] );
}

Expand All @@ -541,11 +547,11 @@ CNodeInformation * daemonVSCPThread::addNodeIfNotKnown( vscpEvent *pEvent )
m_pCtrlObject->m_mutexDeviceList.Unlock();

// We set name fron client id
// 'client|clientid|.nickname'
// 'client_clientid_nickname'
if ( pNode->m_strNodeName.IsEmpty() ) {
pNode->m_strNodeName = _( "client" );
pNode->m_strNodeName = _( "client_" );
pNode->m_strNodeName += wxString::Format( _( "%lu" ), pClientItem->m_clientID );
pNode->m_strNodeName += _( "." );
pNode->m_strNodeName += _( "_" );
pNode->m_strNodeName += wxString::Format( _( "%u" ), ( pEvent->GUID[ 14 ] << 8 ) + pEvent->GUID[ 15 ] );
}

Expand Down Expand Up @@ -723,6 +729,16 @@ bool daemonVSCPThread::sendMulticastInformationProxyEvent( int sock,
// 28 - n data limited to max 512 - 25 = 487 bytes
// len - 2 CRC MSB( Calculated on HEAD + CLASS + TYPE + ADDRESS + SIZE + DATA� )
// len - 1 CRC LSB
//
// Data
// ====================================================================================
// 0-15 Real GUID for node (not interface GUID)
// 16-31 Reserved
// 32-47 GUID for interface on server the node is connected to.
// 48 Interface Level( 0 == Level I, 1 == Level II )
// 49-63 Reserved
// 64-127 Real text name of node( if any ).Set to all zero if not available.
// 128-191 Real text name of interface ( if any ).Set to all zero if not available.

// Packe type
buf[ VSCP_MULTICAST_PACKET0_POS_PKTTYPE ] = SET_VSCP_MULTICAST_TYPE( VSCP_MULTICAST_TYPE_EVENT , VSCP_MULTICAST_ENCRYPTION_NONE );
Expand Down Expand Up @@ -754,32 +770,49 @@ bool daemonVSCPThread::sendMulticastInformationProxyEvent( int sock,
// Originating GUID - Daemon GUID
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_GUID, m_pCtrlObject->m_guid.m_id, 16 );

// Size of payload = 128 bytes
// Size of payload
buf[ VSCP_MULTICAST_PACKET0_POS_VSCP_SIZE + 0 ] = 0x00;
buf[ VSCP_MULTICAST_PACKET0_POS_VSCP_SIZE + 1 ] = 0x80;
buf[ VSCP_MULTICAST_PACKET0_POS_VSCP_SIZE + 1 ] = VSCP_MULTICAST_PROXY_HEARTBEAT_DATA_SIZE;

// Real GUID of node
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA, pNode->m_realguid.getGUID(), 16 );
// Real GUID of node
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA,
pNode->m_realguid.getGUID(),
16 );

// Interface GUID of node
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + 32, pNode->m_interfaceguid.getGUID(), 16 );
// Interface GUID of node
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + VSCP_MULTICAST_PROXY_HEARTBEAT_POS_IFGUID,
pNode->m_interfaceguid.getGUID(),
16 );

buf[ VSCP_MULTICAST_PROXY_HEARTBEAT_POS_IFLEVEL ] = pNode->m_level;

// Name of node
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + 64,
pNode->m_deviceName.mbc_str(),
MIN( 64, strlen( pNode->m_deviceName.mbc_str() ) ) );
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + VSCP_MULTICAST_PROXY_HEARTBEAT_POS_NODENAME,
pNode->m_strNodeName.mbc_str(),
MIN( 64, strlen( pNode->m_strNodeName.mbc_str() ) ) );

// Name of interface node is on
memcpy( buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + VSCP_MULTICAST_PROXY_HEARTBEAT_POS_IFNAME,
pNode->m_deviceName.mbc_str(),
MIN( 64, strlen( pNode->m_deviceName.mbc_str() ) ) );

// CRC
crcInit();
crc chksum = crcFast( buf, VSCP_MULTICATS_PACKET0_HEADER_LENGTH + 128 );
crc chksum = crcFast( buf,
VSCP_MULTICATS_PACKET0_HEADER_LENGTH +
VSCP_MULTICAST_PROXY_HEARTBEAT_DATA_SIZE );
wxUINT32_SWAP_ON_LE( chksum );
buf[ VSCP_MULTICATS_PACKET0_HEADER_LENGTH + 128 + 0 ] = ( chksum >> 8 ) & 0xff;
buf[ VSCP_MULTICATS_PACKET0_HEADER_LENGTH + 128 + 1 ] = chksum & 0xff;
buf[ VSCP_MULTICATS_PACKET0_HEADER_LENGTH +
VSCP_MULTICAST_PROXY_HEARTBEAT_DATA_SIZE + 0 ] = ( chksum >> 8 ) & 0xff;
buf[ VSCP_MULTICATS_PACKET0_HEADER_LENGTH +
VSCP_MULTICAST_PROXY_HEARTBEAT_DATA_SIZE + 1 ] = chksum & 0xff;

return ( ( VSCP_MULTICATS_PACKET0_HEADER_LENGTH + 128 + 2 ) ==
return ( ( VSCP_MULTICATS_PACKET0_HEADER_LENGTH +
VSCP_MULTICAST_PROXY_HEARTBEAT_DATA_SIZE + 2 ) ==
sendto( sock,
(const char *)buf,
VSCP_MULTICATS_PACKET0_HEADER_LENGTH + 128 + 2,
VSCP_MULTICATS_PACKET0_HEADER_LENGTH +
VSCP_MULTICAST_PROXY_HEARTBEAT_DATA_SIZE + 2,
0,
( struct sockaddr * )&mc_addr,
sizeof( mc_addr ) ) );
Expand Down
1 change: 1 addition & 0 deletions src/vscp/common/knownnodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ CNodeInformation::CNodeInformation()
m_strNodeName.Empty();
m_deviceName.Empty();
m_clientID = 0;
m_level = 0;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions src/vscp/common/knownnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class CNodeInformation
m_strNodeName = node.m_strNodeName;
m_deviceName = node.m_deviceName;
m_address = node.m_address;
m_level = node.m_level;

return *this;
};
Expand Down Expand Up @@ -182,6 +183,9 @@ class CNodeInformation
// IP/MAC/... address (if any) associated with the node
wxString m_address;

// Node level 0=Level I, 1 = Level II
uint8_t m_level;

};

// GUID -> Node info
Expand Down
4 changes: 2 additions & 2 deletions src/vscp/common/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#define VSCPD_SUB_VERSION 0


#define VSCPD_SUB_SUB_VERSION 4
#define VSCPD_SUB_SUB_VERSION 5

#define VSCPD_DISPLAY_VERSION "1.1.0.4 Sodium"
#define VSCPD_DISPLAY_VERSION "1.1.0.5 Sodium"

#define VSCPD_COPYRIGHT "Copyright (C) 2000-2015, Paradise of the Frog AB, http://www.paradiseofthefrog.com"
#define VSCPD_COPYRIGHT_HTML "Copyright (C) 2000-2015, <a href=\"mailto:[email protected]\">Paradise of the Frog</a>, <a href=\"http://www.paradiseofthefrog.com\">http://www.paradiseofthefrog.com</a>"
Expand Down
12 changes: 10 additions & 2 deletions src/vscp/common/vscp.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ typedef unsigned short uint64_t;

#define VSCP_MAX_DATA (512-25)

#define VSCP_LEVEL1 1
#define VSCP_LEVEL2 2
#define VSCP_LEVEL1 0 // Changed 151104 Was 1/2
#define VSCP_LEVEL2 1

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -399,6 +399,14 @@ typedef VSCPChannelInfo *PVSCPCHANNELINFO;
#define GET_VSCP_MULTICAST_PACKET_TYPE( type) ( (type>>4) & 0x0f)
#define GET_VSCP_MULTICAST_PACKET_ENCRYPTION( type) ( (type) & 0x0f)

// Multicast proxy CLASS=1026, TYPE=3 http://www.vscp.org/docs/vscpspec/doku.php?id=class2.information#type_3_0x0003_level_ii_proxy_node_heartbeat
#define VSCP_MULTICAST_PROXY_HEARTBEAT_DATA_SIZE 192
#define VSCP_MULTICAST_PROXY_HEARTBEAT_POS_REALGUID 0 // The real GUID for the node
#define VSCP_MULTICAST_PROXY_HEARTBEAT_POS_IFGUID 32 // GUID for interface node is on
#define VSCP_MULTICAST_PROXY_HEARTBEAT_POS_IFLEVEL 48 // 0=Level I node, 1=Level II node
#define VSCP_MULTICAST_PROXY_HEARTBEAT_POS_NODENAME 64 // Name of node
#define VSCP_MULTICAST_PROXY_HEARTBEAT_POS_IFNAME 128 // Name of interface

// Bootloaders
#define VSCP_BOOTLOADER_VSCP 0x00 // VSCP boot loader algorithm
#define VSCP_BOOTLOADER_PIC1 0x01 // PIC algorithm 0
Expand Down
42 changes: 28 additions & 14 deletions src/vscp/common/vscpmulticast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void *worksMulticastThread::Entry()
break;
}*/

originatingAddress.FromAscii( s );
originatingAddress = wxString::FromAscii( s );
//free( s );
#else
char *s = NULL;
Expand Down Expand Up @@ -343,25 +343,33 @@ void *worksMulticastThread::Entry()

// This will use the correct GUID as originator

// GUID is sending nodes/servers GUID
// For a Level I node connected to a server this is the GUID for the server.
cguid guid;
// Interface GUID is used as identifier
guid.getFromArray( ( unsigned const char * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + 32 );
CNodeInformation *pNode = m_knownNodes.addNode( guid );
guid.getFromArray( ( unsigned const char * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_GUID );

// Interface GUID is the GUID the node uses. This is not the real GUID of a node
// but instead a GUID constructed from the interface the node is on. But this is the
// GUID the node is identified as here so it is used as identifier for the node.
cguid ifguid;
ifguid.getFromArray( ( unsigned const char * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + 32 );

CNodeInformation *pNode = m_knownNodes.addNode( ifguid );
if ( NULL != pNode ) {

// Not a proxy
pNode->m_bProxy = true;

// Save the nodes real GUID
guid.getFromArray( ( unsigned const char * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA );
if ( !guid.isNULL() ) {
cguid realguid;
realguid.getFromArray( ( unsigned const char * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA );
if ( !realguid.isNULL() ) {
pNode->m_realguid = guid;
}

// Save the nodes interface GUID
guid.getFromArray( ( unsigned const char * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + 32 );
if ( !guid.isNULL() ) {
pNode->m_interfaceguid = guid;
if ( !ifguid.isNULL() ) {
pNode->m_interfaceguid = ifguid;
}

// Time for last heatbeat
Expand All @@ -373,17 +381,23 @@ void *worksMulticastThread::Entry()
memcpy( wrkbuf, ( unsigned const char * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_DATA + 64, 64 );
pNode->m_strNodeName = wxString::FromUTF8( ( const char * )wrkbuf );

// Save Name for interface this node is on
// If the node does not have a name give it one
if ( 0 == pNode->m_strNodeName.Length() ) {
wxString wxstr;
guid.toString( wxstr );
pNode->m_strNodeName = _("Node without name @ ");
pNode->m_strNodeName += wxstr;
pNode->m_strNodeName += _(" IP=");
pNode->m_strNodeName += originatingAddress;
}

// Save name for interface this node is on

// Save the servers address
pNode->m_address = originatingAddress;

// Get server GUID
guid.getFromArray( ( uint8_t * )buf + VSCP_MULTICAST_PACKET0_POS_VSCP_GUID );

}


}
// Server capabilities
else if ( ( VSCP_CLASS2_PROTOCOL == vscp_class ) &&
Expand Down
2 changes: 1 addition & 1 deletion src/vscp/drivers/level2/sim/common/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ CWrkTread::Entry()

}

}
} // while

return NULL;

Expand Down
Loading

0 comments on commit d805a97

Please sign in to comment.