bool Cudpdrv::open( const char *pUsername, const char *pPassword, const char *pHost, short port, const char *pPrefix, const char *pConfig, unsigned long flags ) { bool rv = true; m_flags = flags; wxString wxstr = pConfig; m_username = pUsername; m_password = pPassword; m_host = pHost; m_port = port; m_prefix = pPrefix; // Parse the configuration string. It should // have the following form // username;password;host;prefix;port;filename wxStringTokenizer tkz( pConfig, ";\n" ); // Interface if ( tkz.HasMoreTokens() ) { m_interface = tkz.GetNextToken(); } // Local Mac wxString localMac; if ( tkz.HasMoreTokens() ) { localMac = tkz.GetNextToken(); localMac.MakeUpper(); wxStringTokenizer tkzmac( localMac, ":\n" ); for ( int i = 0; i < 6; i++ ) { if ( !tkzmac.HasMoreTokens() ) break; wxString str = _("0X") + tkzmac.GetNextToken(); m_localMac[ i ] = readStringValue( str ); m_localGUIDtx.setAt( ( 9 + i ), m_localMac[ i ] ); m_localGUIDrx.setAt( ( 9 + i ), m_localMac[ i ] ); } } // start the workerthreads m_pthreadWorkTx = new CudpdrvTxTread(); if ( NULL != m_pthreadWorkTx ) { m_pthreadWorkTx->m_pobj = this; m_pthreadWorkTx->Create(); m_pthreadWorkTx->Run(); } else { rv = false; } wxSleep( 1 ); m_pthreadWorkRx = new CudpdrvRxTread(); if ( NULL != m_pthreadWorkRx ) { m_pthreadWorkRx->m_pobj = this; m_pthreadWorkRx->Create(); m_pthreadWorkRx->Run(); } else { rv = false; } return rv; }
bool CRawEthernet::open(const char *pUsername, const char *pPassword, const char *pHost, short port, const char *pPrefix, const char *pConfig) { bool rv = true; wxString wxstr = wxString::FromAscii(pConfig); m_username = wxString::FromAscii(pUsername); m_password = wxString::FromAscii(pPassword); m_host = wxString::FromAscii(pHost); m_port = port; m_prefix = wxString::FromAscii(pPrefix); // Parse the configuration string. It should // have the following form // path // wxStringTokenizer tkz(wxString::FromAscii(pConfig), _(";\n")); // Look for rawethernet interface in configuration string if (tkz.HasMoreTokens()) { // Interface m_interface = tkz.GetNextToken(); } // Local Mac wxString localMac; if (tkz.HasMoreTokens()) { localMac = tkz.GetNextToken(); localMac.MakeUpper(); wxStringTokenizer tkzmac(localMac, _(":\n")); for (int i = 0; i < 6; i++) { if (!tkzmac.HasMoreTokens()) break; wxString str = _("0X") + tkzmac.GetNextToken(); m_localMac[ i ] = vscp_readStringValue(str); m_localGUIDtx.setAt((9 + i), m_localMac[ i ]); m_localGUIDrx.setAt((9 + i), m_localMac[ i ]); } } // First log on to the host and get configuration // variables if ( VSCP_ERROR_SUCCESS != m_srv.doCmdOpen( m_host, m_username, m_password ) ) { syslog(LOG_ERR, "%s", (const char *) "Unable to connect to VSCP TCP/IP interface. Terminating!"); return false; } // Find the channel id uint32_t ChannelID; m_srv.doCmdGetChannelID(&ChannelID); // The server should hold configuration data for each sensor // we want to monitor. // // We look for // // _interface - The ethernet interface to use. Typically this // is “eth0, eth0, eth1... // // _localmac - The MAC address for our outgoing frames. // Typically on the form 00:26:55:CA:1F:DA // // _filter - Standard VSCP filter in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // _mask - Standard VSCP mask in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // wxString str; wxString strName = m_prefix + wxString::FromAscii("_interface"); m_srv.getVariableString(strName, &m_interface); // Local Mac if (tkz.HasMoreTokens()) { localMac = tkz.GetNextToken(); localMac.MakeUpper(); wxStringTokenizer tkzmac(localMac, _(":\n")); for (int i = 0; i < 6; i++) { if (!tkzmac.HasMoreTokens()) break; wxString str = _("0X") + tkzmac.GetNextToken(); m_localMac[ i ] = vscp_readStringValue(str); m_localGUIDtx.setAt((9 + i), m_localMac[ i ]); m_localGUIDrx.setAt((9 + i), m_localMac[ i ]); } } strName = m_prefix + wxString::FromAscii("_filter"); if (VSCP_ERROR_SUCCESS == m_srv.getVariableString(strName, &str)) { vscp_readFilterFromString(&m_vscpfilter, str); } strName = m_prefix + wxString::FromAscii("_mask"); if (VSCP_ERROR_SUCCESS == m_srv.getVariableString(strName, &str)) { vscp_readMaskFromString(&m_vscpfilter, str); } // start the read workerthread m_preadWorkThread = new CWrkReadThread(); if (NULL != m_preadWorkThread) { m_preadWorkThread->m_pObj = this; m_preadWorkThread->Create(); m_preadWorkThread->Run(); } else { rv = false; } // start the write workerthread m_pwriteWorkThread = new CWrkWriteThread(); if (NULL != m_pwriteWorkThread) { m_pwriteWorkThread->m_pObj = this; m_pwriteWorkThread->Create(); m_pwriteWorkThread->Run(); } else { rv = false; } // Close the channel m_srv.doCmdClose(); return rv; }