1 /* 2 OW -- One-Wire filesystem 3 version 0.4 7/2/2003 4 5 Function naming scheme: 6 OW -- Generic call to interaface 7 LI -- LINK commands 8 L1 -- 2480B commands 9 FS -- filesystem commands 10 UT -- utility functions 11 12 LICENSE (As of version 2.5p4 2-Oct-2006) 13 owlib: GPL v2 14 owfs, owhttpd, owftpd, owserver: GPL v2 15 owshell(owdir owread owwrite owpresent): GPL v2 16 owcapi (libowcapi): GPL v2 17 owperl: GPL v2 18 owtcl: LGPL v2 19 owphp: GPL v2 20 owpython: GPL v2 21 owsim.tcl: GPL v2 22 where GPL v2 is the "Gnu General License version 2" 23 and "LGPL v2" is the "Lesser Gnu General License version 2" 24 25 26 Written 2003 Paul H Alfille 27 */ 28 29 #ifndef OW_PARSEDNAME_H /* tedious wrapper */ 30 #define OW_PARSEDNAME_H 31 32 /* Define our understanding of integers, floats, ... */ 33 #include "ow_localtypes.h" 34 35 36 /* predeclare some structures */ 37 struct connection_in; 38 struct device; 39 struct filetype; 40 struct devloc ; 41 42 /* Maximum length of a file or directory name, and extension */ 43 #define OW_NAME_MAX (32) 44 #define OW_EXT_MAX (6) 45 #define OW_FULLNAME_MAX (OW_NAME_MAX+OW_EXT_MAX) 46 #define OW_DEFAULT_LENGTH (128) 47 48 /* Parsedname -- path converted into components */ 49 /* 50 Parsed name is the primary structure interpreting a 51 owfs systrem call. It is the interpretation of the owfs 52 file name, or the owhttpd URL. It contains everything 53 but the operation requested. The operation (read, write 54 or directory is in the extended URL or the actual callback 55 function requested). 56 */ 57 /* 58 Parsed name has several components: 59 sn is the serial number of the device 60 dev and ft are pointers to device and filetype 61 members corresponding to the element 62 ds2409_hubs and ds2409_depth interpret the route through 63 DS2409 branch controllers 64 filetype and extension correspond to property 65 (filetype) details 66 subdir points to in-device groupings 67 */ 68 69 #define NO_PARSEDNAME NULL 70 #define NO_PATH NULL 71 72 /* LocalControlFlags information (for remote control) */ 73 /* bit0: cacheenabled bit1: return bus-list */ 74 /* presencecheck */ 75 /* tempscale */ 76 /* device format */ 77 extern int32_t LocalControlFlags; 78 79 // flag to pn->selected_connection->branch.branch to force select from root dir 80 enum eBranch { 81 eBranch_bad = 0xFF, 82 eBranch_cleared = 0xFE, 83 eBranch_main = 0x00, 84 eBranch_aux = 0x01, 85 }; 86 87 struct ds2409_hubs { 88 BYTE sn[SERIAL_NUMBER_SIZE]; 89 BYTE branch; 90 }; 91 92 #define EXTENSION_BYTE -2 93 #define EXTENSION_ALL -1 94 #define EXTENSION_UNKNOWN -3 /* Sparse and not given yet */ 95 96 #define NO_FILETYPE NULL 97 #define NO_SUBDIR NULL 98 #define NO_DEVICE NULL 99 100 enum ePN_type { 101 ePN_root, 102 ePN_real, 103 ePN_statistics, 104 ePN_system, 105 ePN_settings, 106 ePN_structure, 107 ePN_interface, 108 ePN_max_type, 109 }; 110 111 extern char *ePN_name[]; // must match ePN_type 112 113 enum ePS_state { 114 ePS_normal = 0x0000, 115 ePS_uncached = 0x0001, 116 ePS_alarm = 0x0002, 117 ePS_text = 0x0004, 118 ePS_bus = 0x0008, 119 ePS_buslocal = 0x0010, 120 ePS_busanylocal = 0x0020, 121 ePS_busremote = 0x0040, 122 ePS_busveryremote = 0x0080, 123 ePS_reconnection = 0x0100, 124 ePS_unaliased = 0x0200, 125 ePS_json = 0x0400, 126 }; 127 128 struct parsedname { 129 char path[2*PATH_MAX+2]; // full device name 130 char path_to_server[PATH_MAX+2]; // path without first bus 131 char * device_name ; // for external name 132 struct connection_in *known_bus; // where this device is located 133 enum ePN_type type; // real? settings? ... 134 enum ePS_state state; // alarm? 135 BYTE sn[SERIAL_NUMBER_SIZE]; // 64-bit serial number 136 struct device *selected_device; // 1-wire device 137 struct filetype *selected_filetype; // device property 138 int extension; // numerical extension (for array values) or -1 139 char * sparse_name; // text extension for a sparse array value 140 struct filetype *subdir; // in-device grouping 141 int dirlength ; // Length of just directory part of path 142 UINT ds2409_depth; // DS2409 branching depth 143 struct ds2409_hubs *bp; // DS2409 branching route 144 struct connection_in *selected_connection; // which bus is assigned to this item 145 uint32_t control_flags; // more state info, packed for network transmission 146 struct devlock *lock; // pointer to a device-specific lock 147 int return_code ; // return (error) code 148 int detail_flag ; // matches a detail request 149 int tokens; // for anti-loop work 150 BYTE *tokenstring; // List of tokens from owservers passed 151 }; 152 153 /* ---- end Parsedname ----------------- */ 154 #define SHOULD_RETURN_BUS_LIST ( (UINT) 0x00000002 ) 155 #define PERSISTENT_MASK ( (UINT) 0x00000004 ) 156 #define PERSISTENT_BIT 2 157 #define ALIAS_REQUEST ( (UINT) 0x00000008 ) 158 #define SAFEMODE ( (UINT) 0x00000010 ) 159 #define UNCACHED ( (UINT) 0x00000020 ) 160 #define TRIM ( (UINT) 0x00000040 ) 161 #define OWNET ( (UINT) 0x00000100 ) 162 #define TEMPSCALE_MASK ( (UINT) 0x00030000 ) 163 #define TEMPSCALE_BIT 16 164 #define PRESSURESCALE_MASK ( (UINT) 0x001C0000 ) 165 #define PRESSURESCALE_BIT 18 166 #define DEVFORMAT_MASK ( (UINT) 0xFF000000 ) 167 #define DEVFORMAT_BIT 24 168 #define IsPersistent(ppn) ( ((ppn)->control_flags & PERSISTENT_MASK) ) 169 #define SetPersistent(ppn,b) UT_Setbit(((ppn)->control_flags),PERSISTENT_BIT,(b)) 170 #define TemperatureScale(ppn) ( (enum temp_type) (((ppn)->control_flags & TEMPSCALE_MASK) >> TEMPSCALE_BIT) ) 171 #define PressureScale(ppn) ( (enum pressure_type) (((ppn)->control_flags & PRESSURESCALE_MASK) >> PRESSURESCALE_BIT) ) 172 #define SGTemperatureScale(sg) ( (enum temp_type)(((sg) & TEMPSCALE_MASK) >> TEMPSCALE_BIT) ) 173 #define SGPressureScale(sg) ( (enum pressure_type)(((sg) & PRESSURESCALE_MASK) >> PRESSURESCALE_BIT) ) 174 #define DeviceFormat(ppn) ( (enum deviceformat) (((ppn)->control_flags & DEVFORMAT_MASK) >> DEVFORMAT_BIT) ) 175 176 #define IsDir( pn ) ( ((pn)->selected_device)==NO_DEVICE \ 177 || ((pn)->selected_filetype)==NO_FILETYPE \ 178 || ((pn)->selected_filetype)->format==ft_subdir \ 179 || ((pn)->selected_filetype)->format==ft_directory ) 180 #define NotUncachedDir(pn) ( (((pn)->state)&ePS_uncached) == 0 ) 181 #define IsUncachedDir(pn) ( ! NotUncachedDir(pn) ) 182 #define IsStructureDir(pn) ( ((pn)->type) == ePN_structure ) 183 #define IsInterfaceDir(pn) ( ((pn)->type) == ePN_interface ) 184 #define NotAlarmDir(pn) ( (((pn)->state)&ePS_alarm) == 0 ) 185 #define IsAlarmDir(pn) ( ! NotAlarmDir(pn) ) 186 #define NotRealDir(pn) ( ((pn)->type) != ePN_real ) 187 #define IsRealDir(pn) ( ((pn)->type) == ePN_real ) 188 189 #define NotReconnect(pn) ( (((pn)->state)&ePS_reconnection) == 0 ) 190 #define ClearReconnect(pn) do { ((pn)->state)&=~ePS_reconnection; } while(0) 191 #define SetReconnect(pn) do { ((pn)->state)|=ePS_reconnection; } while(0) 192 193 #define InSafeMode(pn) ( (((pn)->control_flags) & SAFEMODE ) != 0 ) 194 195 #define ShouldTrim(pn) ( (((pn)->control_flags) & TRIM ) != 0 ) 196 197 #define KnownBus(pn) ((((pn)->state) & ePS_bus) != 0 ) 198 #define UnsetKnownBus(pn) do { (pn)->state &= ~ePS_bus; \ 199 (pn)->known_bus=NULL; \ 200 (pn)->selected_connection=NO_CONNECTION; \ 201 } while(0) 202 203 #define ShouldReturnBusList(ppn) ( ((ppn)->control_flags & SHOULD_RETURN_BUS_LIST) ) 204 205 #define SpecifiedVeryRemoteBus(pn) ((((pn)->state) & ePS_busveryremote) != 0 ) 206 #define SpecifiedRemoteBus(pn) ((((pn)->state) & ePS_busremote) != 0 ) 207 #define SpecifiedLocalBus(pn) ((((pn)->state) & ePS_buslocal) != 0 ) 208 209 #define SpecifiedBus(pn) ( SpecifiedLocalBus(pn) || SpecifiedRemoteBus(pn) ) 210 211 #define RootNotBranch(pn) (((pn)->ds2409_depth)==0) 212 213 enum parse_enum { 214 parse_first, 215 parse_done, 216 parse_error, 217 parse_real, 218 parse_branch, 219 parse_nonreal, 220 parse_prop, 221 parse_subprop 222 }; 223 224 #endif /* OW_PARSEDNAME_H */ 225