Пример #1
0
extern "C" int CanalGetStatistics( long handle, PCANALSTATISTICS pCanalStatistics  )
{
	VscpTcpIf *pvscpif =  theApp.getDriverObject( handle );
        if ( NULL == pvscpif ) return CANAL_ERROR_MEMORY;

	return ( pvscpif->doCmdStatistics( pCanalStatistics ) ? CANAL_ERROR_SUCCESS : CANAL_ERROR_SUB_DRIVER );
}
Пример #2
0
extern "C" int CanalSetBaudrate( long handle, unsigned long baudrate )
{
	VscpTcpIf *pvscpif =  theApp.getDriverObject( handle );
        if ( NULL == pvscpif ) return CANAL_ERROR_MEMORY;

	return ( pvscpif->doCmdSetBaudrate( baudrate ) ? CANAL_ERROR_SUCCESS : CANAL_ERROR_SUB_DRIVER );
}
Пример #3
0
extern "C" int CanalSend( long handle, PCANALMSG pCanalMsg  )
{
	VscpTcpIf *pvscpif =  theApp.getDriverObject( handle );
	if ( NULL == pvscpif ) return CANAL_ERROR_MEMORY;

	return ( pvscpif->doCmdSendLevel1( pCanalMsg )? CANAL_ERROR_SUCCESS : CANAL_ERROR_SUB_DRIVER );
}
Пример #4
0
extern "C" int CanalDataAvailable( long handle  )
{
	int rv = 0;

	VscpTcpIf *pvscpif =  theApp.getDriverObject( handle );
        if ( NULL == pvscpif ) return CANAL_ERROR_MEMORY;

	return ( pvscpif->doCmdDataAvailable() ? CANAL_ERROR_SUCCESS : CANAL_ERROR_SUB_DRIVER );
}
Пример #5
0
extern "C" long CanalOpen( const char *pDevice, unsigned long flags )
{
	long h = CANAL_ERROR_SUB_DRIVER;
	unsigned long filter=0, mask=0;
	bool bFilter=false, bMask=false;
	wxString str;
	wxString strDevice( pDevice, wxConvUTF8);
	wxStringTokenizer tkz(strDevice, _(";") );

	// Get possible filter	
	if ( str = tkz.GetNextToken() ) {
		if ( 0 != str.Length() ) {
			if ( str.ToULong( &filter ) ) {
				bFilter = true;
			}
		}
	}

	// Get possible mask
	if ( str = tkz.GetNextToken() ) {
		if ( 0 != str.Length() ) {
			if ( str.ToULong( &mask ) ) {
				bMask = true;
			}
		}
	}
	
	
	VscpTcpIf *pvscpif = new VscpTcpIf();
	if ( NULL != pvscpif ) {

		if ( pvscpif->doCmdOpen( strDevice, flags ) ){

			if ( !( h = theApp.addDriverObject( pvscpif ) ) ) {
				delete pvscpif;
			}
			else {
				
				if ( bFilter ) {
					pvscpif->doCmdFilter( filter );	
				}

				if ( bMask ) {
					pvscpif->doCmdMask( mask );
				}
			}

		}
		else {
			delete pvscpif;
		}

	}
 
	return h;
}
Пример #6
0
extern "C" unsigned long CanalGetLevel( long handle )
{
	unsigned long level;

	VscpTcpIf *pvscpif =  theApp.getDriverObject( handle );
	if ( NULL == pvscpif ) return CANAL_ERROR_MEMORY;

	level = pvscpif->doCmdGetLevel();
	return level;
}
Пример #7
0
extern "C" int CanalClose( long handle )
{
	int rv = 0;

	VscpTcpIf *pvscpif =  theApp.getDriverObject( handle );
	if ( NULL == pvscpif ) return CANAL_ERROR_MEMORY;
	pvscpif->doCmdClose();
	theApp.removeDriverObject( handle );
	rv = CANAL_ERROR_SUCCESS;
	return rv;
}
Пример #8
0
void *TXWorkerThread::Entry()
{
  eventOutQueue::compatibility_iterator node;
  vscpEvent *pEvent;

  // Must be a valid control object pointer
    if ( NULL == m_pCtrlObject ) return NULL;

    wxCommandEvent eventConnectionLost( wxVSCP_CTRL_LOST_EVENT, m_pCtrlObject->m_windowID );
  
  /// TCP/IP Control
  VscpTcpIf tcpifControl;
  


  
  // Connect to the server with the control interface
  if ( !tcpifControl.doCmdOpen( m_pCtrlObject->m_ifVSCP.m_strHost,
                                m_pCtrlObject->m_ifVSCP.m_port,
                                m_pCtrlObject->m_ifVSCP.m_strUser,
                                m_pCtrlObject->m_ifVSCP.m_strPassword ) ) {
    //::wxGetApp().logMsg ( _("VSCP TX thread - Unable to connect to server."), DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_errorControl = VSCP_SESSION_ERROR_UNABLE_TO_CONNECT;
        wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );
    return NULL;
  }
  
  // Get channel ID
  tcpifControl.doCmdGetChannelID( &m_pCtrlObject->m_txChannelID );
  
    while ( !TestDestroy() && !m_pCtrlObject->m_bQuit )
    {
    if ( wxSEMA_TIMEOUT == m_pCtrlObject->m_semOutQue.WaitTimeout( 500 ) ) continue;
    m_pCtrlObject->m_mutexOutQueue.Lock();
    node = m_pCtrlObject->m_outQueue.GetFirst();
    pEvent = node->GetData();
    tcpifControl.doCmdSend( pEvent );
    m_pCtrlObject->m_outQueue.DeleteNode( node );
    deleteVSCPevent( pEvent );
    m_pCtrlObject->m_mutexOutQueue.Unlock();
    } // while
  
  // Close the interface
  tcpifControl.doCmdClose();

    wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );

    return NULL;

}
Пример #9
0
CVSCPL1App::~CVSCPL1App()
{
	LOCK_MUTEX( m_objMutex );
	
	for ( int i = 0; i<VSCP_LEVEL1_INTERFACE_MAX_OPEN; i++ ) {
		
		if ( NULL == m_pvscpifArray[ i ] ) {
			
			VscpTcpIf *pvscpif =  getDriverObject( i );
			if ( NULL != pvscpif ) { 
				pvscpif->doCmdClose();	
				delete m_pvscpifArray[ i ];
				m_pvscpifArray[ i ] = NULL; 
			}
		}
	}

	UNLOCK_MUTEX( m_objMutex );	
	pthread_mutex_destroy( &m_objMutex );
}
Пример #10
0
void *RXWorkerThread::Entry()
{
  int rv;
  VscpTcpIf tcpifReceive;
  wxCommandEvent eventReceive( wxVSCP_IN_EVENT, m_pCtrlObject->m_windowID );
    wxCommandEvent eventConnectionLost( wxVSCP_RCV_LOST_EVENT, m_pCtrlObject->m_windowID );
  
  // Must be a valid control object pointer
    if ( NULL == m_pCtrlObject ) return NULL;
  
  // Connect to the server with the control interface
  if ( !tcpifReceive.doCmdOpen( m_pCtrlObject->m_ifVSCP.m_strHost,
                            m_pCtrlObject->m_ifVSCP.m_port,
                            m_pCtrlObject->m_ifVSCP.m_strUser,
                            m_pCtrlObject->m_ifVSCP.m_strPassword ) ) {
    //::wxGetApp().logMsg ( _("VSCP Receive thread - Unable to connect to server."), DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_errorReceive = VSCP_SESSION_ERROR_UNABLE_TO_CONNECT;
        wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );
    return NULL;
  }
  
  // Find the channel id
  tcpifReceive.doCmdGetChannelID( &m_pCtrlObject->m_rxChannelID );

  // Start Receive Loop
    tcpifReceive.doCmdEnterReceiveLoop();

  vscpEvent event;
    while ( !TestDestroy() && !m_pCtrlObject->m_bQuit )
    {

    if ( CANAL_ERROR_SUCCESS == 
            ( rv = tcpifReceive.doCmdBlockReceive( &event, 1000 ) ) ) {

      if ( NULL != m_pCtrlObject->m_pWnd ) {

        vscpEvent *pEvent = new vscpEvent;
        if ( NULL != pEvent ) {

          copyVSCPEvent( pEvent, &event );

          eventReceive.SetClientData( pEvent );
          wxPostEvent( m_pCtrlObject->m_pWnd, eventReceive );
        
        }

      } // Session window exist

    }
    else {
      if ( CANAL_ERROR_COMMUNICATION == rv ) m_pCtrlObject->m_bQuit = true;
    }

    } // while

  // Close the interface
  tcpifReceive.doCmdClose();

    wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );

    return NULL;

}