static GOOD_OR_BAD LINK_detect_net(struct connection_in * in) { struct port_in * pin = in->pown ; /* Set up low-level routines */ LINKE_setroutines(in); pin->timeout.tv_sec = 0 ; pin->timeout.tv_usec = 300000 ; /* Open the tcp port */ RETURN_BAD_IF_BAD( COM_open(in) ) ; LEVEL_DEBUG("Slurp in initial bytes"); // LINK_slurp( in ) ; UT_delay(1000) ; // based on http://morpheus.wcf.net/phpbb2/viewtopic.php?t=89&sid=3ab680415917a0ebb1ef020bdc6903ad LINK_slurp( in ) ; // LINK_flush(in); pin->dev.telnet.telnet_negotiated = needs_negotiation ; RETURN_GOOD_IF_GOOD( LINK_version(in) ) ; // second try -- send a break and line settings LEVEL_DEBUG("Second try -- send BREAK"); COM_flush(in) ; COM_break(in); telnet_change(in); // LINK_slurp( in ) ; RETURN_GOOD_IF_GOOD( LINK_version(in) ) ; LEVEL_DEFAULT("LINK detection error"); COM_close(in) ; return gbBAD; }
/* Called on head of multibus group */ SIZE_OR_ERROR COM_read_with_timeout( BYTE * data, size_t length, struct connection_in *connection) { struct port_in * pin ; if ( length == 0 ) { return 0 ; } if ( connection == NO_CONNECTION || data == NULL ) { // bad parameters return -EIO ; } pin = connection->pown ; // unlike write or open, a closed connection isn't automatically opened. // the reason is that reopening won't have the data waiting. We really need // to restart the transaction from the "write" portion if ( FILE_DESCRIPTOR_NOT_VALID( pin->file_descriptor ) ) { return -EBADF ; } else { size_t actual_size ; ZERO_OR_ERROR zoe = tcp_read( pin->file_descriptor, data, length, &(pin->timeout), &actual_size ) ; if ( zoe == -EBADF ) { COM_close(connection) ; return zoe ; } else { return actual_size ; } } }
static GOOD_OR_BAD LINK_detect_serial(struct connection_in * in) { struct port_in * pin = in->pown ; /* Set up low-level routines */ LINK_setroutines(in); pin->timeout.tv_sec = Globals.timeout_serial ; pin->timeout.tv_usec = 0 ; /* Open the com port */ RETURN_BAD_IF_BAD(COM_open(in)) ; //COM_break( in ) ; LEVEL_DEBUG("Slurp in initial bytes"); LINK_slurp( in ) ; UT_delay(100) ; // based on http://morpheus.wcf.net/phpbb2/viewtopic.php?t=89&sid=3ab680415917a0ebb1ef020bdc6903ad LINK_slurp( in ) ; RETURN_GOOD_IF_GOOD( LINK_version(in) ) ; LEVEL_DEFAULT("LINK detection error"); serial_powercycle(in) ; LEVEL_DEBUG("Slurp in initial bytes"); LINK_slurp( in ) ; UT_delay(100) ; // based on http://morpheus.wcf.net/phpbb2/viewtopic.php?t=89&sid=3ab680415917a0ebb1ef020bdc6903ad LINK_slurp( in ) ; RETURN_GOOD_IF_GOOD( LINK_version(in) ) ; LEVEL_DEFAULT("LINK detection error"); COM_close(in) ; return gbBAD; }
// setting for serial port already made static GOOD_OR_BAD DS2480_detect_serial(struct connection_in *in) { in->pown->state = cs_virgin ; if ( BAD(DS2480_initialize_repeatedly(in)) ) { LEVEL_DEBUG("Could not initilize the DS9097U even after several tries") ; COM_close(in) ; return gbBAD ; } DS2480_adapter(in) ; return gbGOOD ; }
/* Called on head of multibus group */ static SIZE_OR_ERROR COM_read_get_size( BYTE * data, size_t length, struct connection_in *connection ) { size_t actual_size ; struct port_in * pin = connection->pown ; // tcp_read seems to work with serial and network ZERO_OR_ERROR zoe = tcp_read( pin->file_descriptor, data, length, &(pin->timeout), &actual_size ) ; if ( zoe < 0 ) { COM_close(connection) ; return zoe ; } else { return actual_size ; } }
//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 ; } }
/* Try to see if there is a DS2482 device on the specified i2c bus */ static GOOD_OR_BAD DS2482_detect_single(int lowindex, int highindex, char * i2c_device, struct port_in *pin) { int test_address[8] = { 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, }; // the last 4 are -800 only int i2c_index; FILE_DESCRIPTOR_OR_ERROR file_descriptor; struct connection_in * in = pin->first ; /* Sanity check */ if ( lowindex < 0 ) { LEVEL_DEBUG("Bad lower bound"); return gbBAD ; } if ( highindex >= (int) (sizeof(test_address)/sizeof(int)) ) { LEVEL_DEBUG("Bad upper bound"); return gbBAD ; } /* open the i2c port */ file_descriptor = open(i2c_device, O_RDWR); if ( FILE_DESCRIPTOR_NOT_VALID(file_descriptor) ) { ERROR_CONNECT("Could not open i2c device %s", i2c_device); return gbBAD; } /* Set up low-level routines */ DS2482_setroutines(in); for (i2c_index = lowindex; i2c_index <= highindex; ++i2c_index) { int trial_address = test_address[i2c_index] ; /* set the candidate address */ if (ioctl(file_descriptor, I2C_SLAVE, trial_address) < 0) { ERROR_CONNECT("Cound not set trial i2c address to %.2X", trial_address); } else { BYTE c; LEVEL_CONNECT("Found an i2c device at %s address %.2X", i2c_device, trial_address); /* Provisional setup as a DS2482-100 ( 1 channel ) */ in->pown->file_descriptor = file_descriptor; pin->state = cs_deflowered; pin->type = ct_i2c ; in->master.i2c.i2c_address = trial_address; in->master.i2c.i2c_index = i2c_index; in->master.i2c.index = 0; in->master.i2c.channels = 1; in->master.i2c.current = 0; in->master.i2c.head = in; in->adapter_name = "DS2482-100"; in->master.i2c.configreg = 0x00 ; // default configuration setting desired if ( Globals.i2c_APU ) { in->master.i2c.configreg |= DS2482_REG_CFG_APU ; } if ( Globals.i2c_PPM ) { in->master.i2c.configreg |= DS2482_REG_CFG_PPM ; } in->Adapter = adapter_DS2482_100; /* write the RESET code */ if (i2c_smbus_write_byte(file_descriptor, DS2482_CMD_RESET) // reset || BAD(DS2482_readstatus(&c, file_descriptor, DS2482_Chip_reset_usec)) // pause .5 usec then read status || (c != (DS2482_REG_STS_LL | DS2482_REG_STS_RST)) // make sure status is properly set ) { LEVEL_CONNECT("i2c device at %s address %.2X cannot be reset. Not a DS2482.", i2c_device, trial_address); continue; } LEVEL_CONNECT("i2c device at %s address %.2X appears to be DS2482-x00", i2c_device, trial_address); in->master.i2c.configchip = 0x00; // default configuration register after RESET // Note, only the lower nibble of the device config stored // Create name SAFEFREE( DEVICENAME(in) ) ; DEVICENAME(in) = owmalloc( strlen(i2c_device) + 10 ) ; if ( DEVICENAME(in) ) { UCLIBCLOCK; snprintf(DEVICENAME(in), strlen(i2c_device) + 10, "%s:%.2X", i2c_device, trial_address); UCLIBCUNLOCK; } /* Now see if DS2482-100 or DS2482-800 */ return HeadChannel(in); } } /* fell though, no device found */ COM_close( in ) ; return gbBAD; }