1 /* 2 OW -- One-Wire filesystem 3 version 0.4 7/2/2003 4 5 Written 2003 Paul H Alfille 6 Fuse code based on "fusexmp" {GPL} by Miklos Szeredi, mszeredi@inf.bme.hu 7 Serial code based on "xt" {GPL} by David Querbach, www.realtime.bc.ca 8 in turn based on "miniterm" by Sven Goldt, goldt@math.tu.berlin.de 9 GPL license 10 This program is free software; you can redistribute it and/or 11 modify it under the terms of the GNU General Public License 12 as published by the Free Software Foundation; either version 2 13 of the License, or (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 21 */ 22 23 #ifndef OW_MASTER_H /* tedious wrapper */ 24 #define OW_MASTER_H 25 26 /* included in ow_connection.h as the bus-master specific portion of the connection_in structure */ 27 28 struct master_server { 29 char *type; // for zeroconf 30 char *domain; // for zeroconf 31 char *name; // zeroconf name 32 int no_dirall; // flag that server doesn't support DIRALL 33 } ; 34 35 struct master_serial { 36 enum ds2480b_mode { ds2480b_data_mode, ds2480b_command_mode, } mode ; 37 int reverse_polarity ; 38 }; 39 40 struct master_fake { 41 int index; 42 _FLOAT templow; 43 _FLOAT temphigh; 44 45 // For adapters that maintain dir-at-once (or dirgulp): 46 struct dirblob main; /* main directory */ 47 struct dirblob alarm; /* alarm directory */ 48 }; 49 50 // DS2490R (usb) hub 51 struct master_usb { 52 #if OW_USB 53 libusb_device * lusb_dev ; 54 libusb_device_handle * lusb_handle ; 55 int bus_number; 56 int address; 57 int datasampleoffset; 58 int writeonelowtime; 59 int pulldownslewrate; 60 int timeout; 61 #endif /* OW_USB */ 62 int specific_usb_address ; // only a specific address requested? 63 64 /* "Name" of the device, like "8146572300000051" 65 * This is set to the first DS1420 id found on the 1-wire adapter which 66 * exists on the DS9490 adapters. If user only have a DS2490 chip, there 67 * are no such DS1420 device available. It's used to find the 1-wire adapter 68 * if it's disconnected and later reconnected again. 69 */ 70 BYTE ds1420_address[SERIAL_NUMBER_SIZE]; 71 }; 72 73 // DS2482 (i2c) hub -- 800 has 8 channels 74 struct master_i2c { 75 int channels; 76 int index; 77 int i2c_address; 78 enum ds248x_type { ds2482_unknown, ds2482_100, ds2482_800, ds2483, } type ; 79 int i2c_index ; 80 BYTE configreg; 81 BYTE configchip; 82 /* only one per chip, the bus entries for the other 7 channels point to the first one */ 83 int current; 84 struct connection_in *head; 85 }; 86 87 // HobbyBoards Master Hub 88 // Single char channel (1,2,3,4,W -- ignore A) 89 struct master_masterhub { 90 // Need to lock directory for "next" command" 91 int channels; 92 char channel_char; 93 }; 94 95 // Embedded Data Systems HA7 hub 96 struct master_ha7 { 97 ASCII lock[10]; 98 int locked; 99 int found; 100 }; 101 102 struct master_enet { 103 int version; 104 }; 105 106 struct master_ds1wm { 107 off_t base ; 108 off_t page_start ; 109 off_t page_offset ; 110 void * mm ; // mmap 111 int longline ; 112 int byte_mode ; 113 long int frequency ; 114 int presence_mask ; 115 size_t mm_size ; 116 uint8_t channels_count; // for k1wm 117 uint8_t active_channel; // for k1wm 118 }; 119 120 enum e_link_t_mode { e_link_t_unknown, e_link_t_extra, e_link_t_none } ; 121 122 struct master_link { 123 enum e_link_t_mode tmode ; // extra ',' before tF0 command 124 enum e_link_t_mode qmode ; //extra '?' after b command 125 #if OW_FTDI 126 struct ftdi_context *ftdic; 127 #endif 128 }; 129 130 // Embedded Data Systems HA5 hub 131 struct master_ha5 { 132 int checksum ; /* flag to use checksum byte in communication */ 133 char channel ; 134 struct connection_in *head; 135 }; 136 137 struct master_pbm { 138 char channel; 139 unsigned int version; 140 unsigned int serial_number; 141 struct connection_in *head; 142 }; 143 144 // W1 (kernel) "device" 145 struct master_w1 { 146 #if OW_W1 147 // bus master name kept in name 148 SEQ_OR_ERROR seq ; 149 int id ; // equivalent to the number part of w1_bus_master23 150 FILE_DESCRIPTOR_OR_ERROR netlink_pipe[2] ; 151 enum enum_w1_slave_order { w1_slave_order_unknown, w1_slave_order_forward, w1_slave_order_reversed } w1_slave_order ; 152 #endif /* OW_W1 */ 153 }; 154 155 // Search for W1 (kernel) devices 156 struct master_w1_monitor { 157 #if OW_W1 158 // netlink fd kept in file_descriptor 159 SEQ_OR_ERROR seq ; // seq number to netlink 160 pid_t pid ; 161 struct timeval last_read ; 162 163 pthread_mutex_t seq_mutex; // mutex for w1 sequence number */ 164 pthread_mutex_t read_mutex; // mutex for w1 netlink read time 165 #endif /* OW_W1 */ 166 }; 167 168 // Search for USB (DS9490R) devices 169 struct master_usb_monitor { 170 FILE_DESCRIPTOR_OR_ERROR shutdown_pipe[2] ; 171 int usb_scan_interval ; 172 173 }; 174 175 struct master_enet_monitor { 176 FILE_DESCRIPTOR_OR_ERROR shutdown_pipe[2] ; 177 int enet_scan_interval ; 178 179 }; 180 181 // Search for HobbyBoards MasterHub (network) devices 182 struct master_masterhub_monitor { 183 FILE_DESCRIPTOR_OR_ERROR shutdown_pipe[2] ; 184 int mh_scan_interval ; 185 186 }; 187 188 struct master_browse { 189 #if OW_ZERO 190 DNSServiceRef bonjour_browse; 191 #endif /* OW_ZERO */ 192 193 #if OW_AVAHI 194 AvahiClient *client ; 195 AvahiServiceBrowser * browser ; 196 AvahiThreadedPoll *poll ; 197 198 #if __HAS_IPV6__ 199 char host[INET6_ADDRSTRLEN+1] ; 200 #else 201 char host[INET_ADDRSTRLEN+1] ; 202 #endif 203 char service[10] ; 204 #endif /* OW_AVAHI */ 205 }; 206 207 union master_union { 208 struct master_serial serial; 209 struct master_link link; 210 struct master_server server ; 211 struct master_usb usb; 212 struct master_usb_monitor usb_monitor ; 213 struct master_i2c i2c; 214 struct master_fake fake; 215 struct master_fake tester; 216 struct master_fake mock; 217 struct master_enet enet; 218 struct master_enet_monitor enet_monitor ; 219 struct master_ha5 ha5; 220 struct master_ha7 ha7; 221 struct master_pbm pbm; 222 struct master_w1 w1; 223 struct master_masterhub masterhub; 224 struct master_masterhub_monitor masterhub_monitor ; 225 struct master_w1_monitor w1_monitor ; 226 struct master_browse browse; 227 struct master_ds1wm ds1wm ; 228 }; 229 230 231 #endif /* OW_MASTER_H */ 232