From 5cf430726849ec1d74b370baf4c73fc280cbdf50 Mon Sep 17 00:00:00 2001 From: Nicolas Bruguier Date: Tue, 17 Apr 2012 22:59:55 +0200 Subject: [PATCH] Cleanup open TI3410 --- lib/usb/ti-3410-stream.vala | 21 ++++++++++++++++----- lib/usb/usb-stream.vala | 12 ++++++++++++ src/modules/abbott/device.vala | 16 +--------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lib/usb/ti-3410-stream.vala b/lib/usb/ti-3410-stream.vala index 516afe9..9e25b02 100644 --- a/lib/usb/ti-3410-stream.vala +++ b/lib/usb/ti-3410-stream.vala @@ -22,6 +22,12 @@ namespace GlucoseBoard public class TI3410Stream : UsbStreamSerial { // types + public enum ConfigurationValue + { + BOOT = 0x01, + ACTIVE = 0x02 + } + private enum Commands { GET_VERSION = 0x01, @@ -76,6 +82,13 @@ namespace GlucoseBoard uint8 mode; } + public enum UARTType + { + RS232 = 0x00, + RS485_RECEIVER_DISABLED = 0x01, + RS485_RECEIVER_ENABLED = 0x02 + } + private enum UARTFlags { ENABLE_RTS_IN = 0x0001, @@ -197,6 +210,8 @@ namespace GlucoseBoard } } + Posix.usleep (100 * 1000); + // Reset device reset (); } @@ -295,7 +310,7 @@ namespace GlucoseBoard m_Config.flags = UARTFlags.ENABLE_MS_INTS | UARTFlags.ENABLE_AUTO_START_DMA; // use rs232 - m_Config.mode = 0; + m_Config.mode = UARTType.RS232; // set baud rate m_Config.baud_rate = (uint16)(14769230.77 / (inConfig.baud_rate * 16)); @@ -364,10 +379,6 @@ namespace GlucoseBoard // Configure serial communication set_config (); - // lock end point since open and start port - clear_halt_read_ep (); - clear_halt_write_ep (); - // Open port open_port (); diff --git a/lib/usb/usb-stream.vala b/lib/usb/usb-stream.vala index 517d1c1..f477ac9 100644 --- a/lib/usb/usb-stream.vala +++ b/lib/usb/usb-stream.vala @@ -29,6 +29,7 @@ namespace GlucoseBoard private uint m_Interface; private uint m_EndPointRead; private uint m_EndPointWrite; + private uint8 m_ConfigurationValue; private bool m_ReadEndPointAvailable; private LibUSB.TransferType m_ReadTransferType; private uint m_ReadMaxPacketSize; @@ -62,6 +63,16 @@ namespace GlucoseBoard } } + public uint8 configuration_value { + get { + return m_ConfigurationValue; + } + set { + if (m_Handle != null) + m_Handle.set_configuration (value); + } + } + // methods /** * Create new usb stream for inDevice @@ -86,6 +97,7 @@ namespace GlucoseBoard bool found_interface = false; m_ReadEndPointAvailable = false; m_WriteEndPointAvailable = false; + m_ConfigurationValue = config.bConfigurationValue; // Search interface for (int cpt = 0; cpt < config.bNumInterfaces; ++cpt) diff --git a/src/modules/abbott/device.vala b/src/modules/abbott/device.vala index 0aa5c06..4400b4f 100644 --- a/src/modules/abbott/device.vala +++ b/src/modules/abbott/device.vala @@ -85,7 +85,7 @@ namespace GlucoseBoard.Module.Abbott m_Stream = new TI3410Stream (this, m_UsbInterface, m_UsbEndPointRead, m_UsbEndPointWrite); // Read end point is not available load firmware - if (!m_Stream.read_ep_available) + if (m_Stream.configuration_value == TI3410Stream.ConfigurationValue.BOOT) { load_firmware (); } @@ -97,20 +97,6 @@ namespace GlucoseBoard.Module.Abbott // Open stream m_Stream.open (); - - // Send mem message - m_Stream.send (new Message (), 1000); - m_Stream.send (new Message.mem (), 1000); - - // Close stream - m_Stream.close (); - - // Open stream - m_Stream.open (); - - // Send xmem message - m_Stream.send (new Message (), 1000); - m_Stream.send (new Message.xmem (), 1000); } } catch (GLib.Error err)