1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 import "data_stream.mojom" 6 7 module device.serial { 8 9 struct DeviceInfo { 10 string path; 11 uint16 vendor_id; 12 bool has_vendor_id = false; 13 uint16 product_id; 14 bool has_product_id = false; 15 string? display_name; 16 }; 17 18 enum SendError { 19 NONE, 20 DISCONNECTED, 21 PENDING, 22 TIMEOUT, 23 SYSTEM_ERROR, 24 }; 25 26 enum ReceiveError { 27 NONE, 28 DISCONNECTED, 29 TIMEOUT, 30 DEVICE_LOST, 31 SYSTEM_ERROR, 32 }; 33 34 enum DataBits { 35 NONE, 36 SEVEN, 37 EIGHT, 38 }; 39 40 enum ParityBit { 41 NONE, 42 NO, 43 ODD, 44 EVEN, 45 }; 46 47 enum StopBits { 48 NONE, 49 ONE, 50 TWO, 51 }; 52 53 struct ConnectionOptions { 54 uint32 bitrate = 0; 55 DataBits data_bits = NONE; 56 ParityBit parity_bit = NONE; 57 StopBits stop_bits = NONE; 58 bool cts_flow_control; 59 bool has_cts_flow_control = false; 60 }; 61 62 struct ConnectionInfo { 63 uint32 bitrate = 0; 64 DataBits data_bits = NONE; 65 ParityBit parity_bit = NONE; 66 StopBits stop_bits = NONE; 67 bool cts_flow_control; 68 }; 69 70 struct HostControlSignals { 71 bool dtr; 72 bool has_dtr = false; 73 bool rts; 74 bool has_rts = false; 75 }; 76 77 struct DeviceControlSignals { 78 bool dcd; 79 bool cts; 80 bool ri; 81 bool dsr; 82 }; 83 84 interface SerialService { 85 GetDevices() => (DeviceInfo[] devices); 86 87 // Creates a |Connection| to |path| with options specified by |options|, 88 // returning it via |connection|. Sending and receiving data over this 89 // connection is handled by |sink| and |source|, respectively. This will fail 90 // and |connection| will not be usable if |path| does not specify a valid 91 // serial device or there is an error connecting to or configuring the 92 // connection. 93 Connect(string path, 94 ConnectionOptions? options, 95 Connection& connection, 96 DataSink& sink, 97 DataSource& source); 98 }; 99 100 interface Connection { 101 GetInfo() => (ConnectionInfo? info); 102 SetOptions(ConnectionOptions options) => (bool success); 103 SetControlSignals(HostControlSignals signals) => (bool success); 104 GetControlSignals() => (DeviceControlSignals? signals); 105 Flush() => (bool success); 106 }; 107 108 } 109