コード例 #1
0
ファイル: ow_com_open.c プロジェクト: GrandHsu/iicontrollibs
//open a port (serial or tcp)
GOOD_OR_BAD COM_open(struct connection_in *connection)
{
	struct port_in * pin ;
	struct connection_in * head_in ;
	
	if (connection == NO_CONNECTION) {
		LEVEL_DEBUG("Attempt to open a NULL serial device");
		return gbBAD;
	}

	pin = connection->pown ;
	head_in = pin->first ; // head of multigroup bus

	switch ( pin->state ) {
		case cs_deflowered:
			// Attempt to reopen a good connection?
			COM_close(head_in) ;
			break ;
		case cs_virgin:
			break ;
	}

	switch ( pin->type ) {
		case ct_telnet:
			if ( pin->dev.telnet.telnet_negotiated == completed_negotiation ) {
				 pin->dev.telnet.telnet_negotiated = needs_negotiation ;
			}
			pin->dev.telnet.telnet_supported = 0 ;
			return tcp_open( head_in ) ;		
		case ct_tcp:
			return tcp_open( head_in ) ;
		case ct_netlink:
#if OW_W1
			return w1_bind( connection ) ;
#endif /* OW_W1 */
		case ct_i2c:
		case ct_usb:
			LEVEL_DEBUG("Unimplemented");
			return gbBAD ;
		case ct_serial:
			return serial_open( head_in ) ;
		case ct_unknown:
		case ct_none:
		default:
			LEVEL_DEBUG("Unknown type.");
			return gbBAD ;
	}
}
コード例 #2
0
ファイル: ow_w1_monitor.c プロジェクト: M-o-a-T/owfs
/* Device-specific functions */
GOOD_OR_BAD W1_monitor_detect(struct port_in *pin)
{
	struct connection_in * in = pin->first ;
	struct timeval tvslack = { 1, 0 } ; // 1 second
	
	pin->file_descriptor = FILE_DESCRIPTOR_BAD;
	pin->type = ct_none ;
	in->iroutines.detect = W1_monitor_detect;
	in->Adapter = adapter_w1_monitor;	/* OWFS assigned value */
	in->iroutines.reset = NO_RESET_ROUTINE;
	in->iroutines.next_both = NO_NEXT_BOTH_ROUTINE;
	in->iroutines.PowerByte = NO_POWERBYTE_ROUTINE;
	in->iroutines.ProgramPulse = NO_PROGRAMPULSE_ROUTINE;
	in->iroutines.sendback_data = NO_SENDBACKDATA_ROUTINE;
	in->iroutines.sendback_bits = NO_SENDBACKBITS_ROUTINE;
	in->iroutines.select = NO_SELECT_ROUTINE;
	in->iroutines.select_and_sendback = NO_SELECTANDSENDBACK_ROUTINE;
	in->iroutines.set_config = NO_SET_CONFIG_ROUTINE;
	in->iroutines.get_config = NO_GET_CONFIG_ROUTINE;
	in->iroutines.reconnect = NO_RECONNECT_ROUTINE;
	in->iroutines.close = W1_monitor_close;
	in->iroutines.verify = NO_VERIFY_ROUTINE ;
	in->iroutines.flags = ADAP_FLAG_sham;
	in->adapter_name = "W1 monitor";
	pin->busmode = bus_w1_monitor ;
	
	RETURN_BAD_IF_BAD( w1_monitor_in_use(in) ) ;
	
	// Initial setup
	Inbound_Control.w1_monitor = in ; // essentially a global pointer to the w1_monitor entry
	_MUTEX_INIT(in->master.w1_monitor.seq_mutex);
	_MUTEX_INIT(in->master.w1_monitor.read_mutex);

	timernow( &(in->master.w1_monitor.last_read) );
	timeradd( &(in->master.w1_monitor.last_read), &tvslack, &(in->master.w1_monitor.last_read) );

	in->master.w1_monitor.seq = SEQ_INIT ;
	in->master.w1_monitor.pid = 0 ;
	
	w1_bind(in) ; // sets in->file_descriptor
	if ( FILE_DESCRIPTOR_NOT_VALID( in->pown->file_descriptor ) ) {
		ERROR_DEBUG("Netlink problem -- are you root?");
		Inbound_Control.w1_monitor = NO_CONNECTION ;
		return gbBAD ;
	}
	
	return W1_Browse() ; // creates thread that runs forever.
}