1 //---------------------------------------------------------------------------
\r
2 // Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
\r
4 // Permission is hereby granted, free of charge, to any person obtaining a
\r
5 // copy of this software and associated documentation files (the "Software"),
\r
6 // to deal in the Software without restriction, including without limitation
\r
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
8 // and/or sell copies of the Software, and to permit persons to whom the
\r
9 // Software is furnished to do so, subject to the following conditions:
\r
11 // The above copyright notice and this permission notice shall be included
\r
12 // in all copies or substantial portions of the Software.
\r
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
\r
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
\r
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
\r
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
\r
20 // OTHER DEALINGS IN THE SOFTWARE.
\r
22 // Except as contained in this notice, the name of Dallas Semiconductor
\r
23 // shall not be used except as stated in the Dallas Semiconductor
\r
25 //---------------------------------------------------------------------------
\r
27 // tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API
\r
28 // for network functions.
\r
35 #include <windows.h>
\r
37 uchar StateBuffer[MAX_PORTNUM][5120];
\r
41 // external TMEX variables
\r
42 extern long SessionHandle[MAX_PORTNUM];
\r
43 extern "C" short far pascal TMSearch(long session_handle, void *start_buffer,
\r
44 short ResetSearch, short PerformReset,
\r
46 extern "C" short pascal TMFirst(long, void *);
\r
47 extern "C" short pascal TMNext(long, void *);
\r
48 extern "C" short pascal TMAccess(long, void *);
\r
49 extern "C" short pascal TMStrongAccess(long, void *);
\r
50 extern "C" short pascal TMStrongAlarmAccess(long, void *);
\r
51 extern "C" short pascal TMOverAccess(long, void *);
\r
52 extern "C" short pascal TMRom(long, void *, short *);
\r
53 extern "C" short pascal TMFirstAlarm(long, void *);
\r
54 extern "C" short pascal TMNextAlarm(long, void *);
\r
55 extern "C" short pascal TMFamilySearchSetup(long, void *, short);
\r
56 extern "C" short pascal TMSkipFamily(long, void *);
\r
57 extern "C" short pascal TMAutoOverDrive(long, void *, short);
\r
60 //--------------------------------------------------------------------------
\r
61 // The 'owFirst' finds the first device on the 1-Wire Net This function
\r
62 // contains one parameter 'alarm_only'. When
\r
63 // 'alarm_only' is TRUE (1) the find alarm command 0xEC is
\r
64 // sent instead of the normal search command 0xF0.
\r
65 // Using the find alarm command 0xEC will limit the search to only
\r
66 // 1-Wire devices that are in an 'alarm' state.
\r
68 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
69 // indicate the symbolic port number.
\r
70 // 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not
\r
71 // perform reset before search.
\r
72 // 'alarm_only' - TRUE (1) the find alarm command 0xEC is
\r
73 // sent instead of the normal search command 0xF0
\r
75 // Returns: TRUE (1) : when a 1-Wire device was found and it's
\r
76 // Serial Number placed in the global SerialNum[portnum]
\r
77 // FALSE (0): There are no devices on the 1-Wire Net.
\r
79 SMALLINT owFirst_(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
\r
81 return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1,
\r
82 (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
\r
85 //--------------------------------------------------------------------------
\r
86 // The 'owNext' function does a general search. This function
\r
87 // continues from the previos search state. The search state
\r
88 // can be reset by using the 'owFirst' function.
\r
89 // This function contains one parameter 'alarm_only'.
\r
90 // When 'alarm_only' is TRUE (1) the find alarm command
\r
91 // 0xEC is sent instead of the normal search command 0xF0.
\r
92 // Using the find alarm command 0xEC will limit the search to only
\r
93 // 1-Wire devices that are in an 'alarm' state.
\r
95 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
96 // indicate the symbolic port number.
\r
97 // 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not
\r
98 // perform reset before search.
\r
99 // 'alarm_only' - TRUE (1) the find alarm command 0xEC is
\r
100 // sent instead of the normal search command 0xF0
\r
102 // Returns: TRUE (1) : when a 1-Wire device was found and it's
\r
103 // Serial Number placed in the global SerialNum[portnum]
\r
104 // FALSE (0): when no new device was found. Either the
\r
105 // last search was the last device or there
\r
106 // are no devices on the 1-Wire Net.
\r
108 SMALLINT owNext_(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
\r
110 return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0,
\r
111 (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
\r
114 //--------------------------------------------------------------------------
\r
115 // The 'owSerialNum' function either reads or sets the SerialNum buffer
\r
116 // that is used in the search functions 'owFirst' and 'owNext'.
\r
117 // This function contains two parameters, 'serialnum_buf' is a pointer
\r
118 // to a buffer provided by the caller. 'serialnum_buf' should point to
\r
119 // an array of 8 unsigned chars. The second parameter is a flag called
\r
120 // 'do_read' that is TRUE (1) if the operation is to read and FALSE
\r
121 // (0) if the operation is to set the internal SerialNum buffer from
\r
122 // the data in the provided buffer.
\r
124 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
125 // indicate the symbolic port number.
\r
126 // 'serialnum_buf' - buffer to that contains the serial number to set
\r
127 // when do_read = FALSE (0) and buffer to get the serial
\r
128 // number when do_read = TRUE (1).
\r
129 // 'do_read' - flag to indicate reading (1) or setting (0) the current
\r
132 void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read)
\r
136 // check if reading or writing
\r
143 for (i = 0; i < 8; i++)
\r
144 ROM[i] = serialnum_buf[i];
\r
147 // call TMEX to read or set the current device
\r
148 TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM);
\r
150 // place in 'serialnum_buf'
\r
153 for (i = 0; i < 8; i++)
\r
154 serialnum_buf[i] = (uchar)ROM[i];
\r
158 //--------------------------------------------------------------------------
\r
159 // Setup the search algorithm to find a certain family of devices
\r
160 // the next time a search function is called 'owNext'.
\r
162 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
\r
163 // OpenCOM to indicate the port number.
\r
164 // 'search_family' - family code type to set the search algorithm to find
\r
167 void owFamilySearchSetup(int portnum, SMALLINT search_family)
\r
169 TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum],
\r
170 (short)search_family);
\r
173 //--------------------------------------------------------------------------
\r
174 // Set the current search state to skip the current family code.
\r
176 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
177 // indicate the symbolic port number.
\r
179 void owSkipFamily(int portnum)
\r
181 TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]);
\r
184 //--------------------------------------------------------------------------
\r
185 // The 'owAccess' function resets the 1-Wire and sends a MATCH Serial
\r
186 // Number command followed by the current SerialNum code. After this
\r
187 // function is complete the 1-Wire device is ready to accept device-specific
\r
190 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
191 // indicate the symbolic port number.
\r
193 // Returns: TRUE (1) : reset indicates present and device is ready
\r
195 // FALSE (0): reset does not indicate presence or echos 'writes'
\r
196 // are not correct.
\r
198 SMALLINT owAccess(int portnum)
\r
200 return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
\r
203 //----------------------------------------------------------------------
\r
204 // The function 'owVerify' verifies that the current device
\r
205 // is in contact with the 1-Wire Net.
\r
206 // Using the find alarm command 0xEC will verify that the device
\r
207 // is in contact with the 1-Wire Net and is in an 'alarm' state.
\r
209 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
210 // indicate the symbolic port number.
\r
211 // 'alarm_only' - TRUE (1) the find alarm command 0xEC
\r
212 // is sent instead of the normal search
\r
215 // Returns: TRUE (1) : when the 1-Wire device was verified
\r
216 // to be on the 1-Wire Net
\r
217 // with alarm_only == FALSE
\r
218 // or verified to be on the 1-Wire Net
\r
219 // AND in an alarm state when
\r
220 // alarm_only == TRUE.
\r
221 // FALSE (0): the 1-Wire device was not on the
\r
222 // 1-Wire Net or if alarm_only
\r
223 // == TRUE, the device may be on the
\r
224 // 1-Wire Net but in a non-alarm state.
\r
226 SMALLINT owVerify(int portnum, SMALLINT alarm_only)
\r
229 return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
\r
231 return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
\r
234 //----------------------------------------------------------------------
\r
235 // Perform a overdrive MATCH command to select the 1-Wire device with
\r
236 // the address in the ID data register.
\r
238 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
\r
239 // indicate the symbolic port number.
\r
241 // Returns: TRUE: If the device is present on the 1-Wire Net and
\r
242 // can do overdrive then the device is selected.
\r
243 // FALSE: Device is not present or not capable of overdrive.
\r
245 // *Note: This function could be converted to send DS2480
\r
246 // commands in one packet.
\r
248 SMALLINT owOverdriveAccess(int portnum)
\r
250 return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
\r