-//---------------------------------------------------------------------------
-// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//---------------------------------------------------------------------------
-//
-// tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API
-// for network functions.
-//
-// Version: 3.00
-//
-//
-
-#include "ownet.h"
-#include <windows.h>
-
-uchar StateBuffer[MAX_PORTNUM][5120];
-
-// external TMEX variables
-extern long SessionHandle[MAX_PORTNUM];
-extern short far pascal TMSearch(long session_handle, void *start_buffer,
- short ResetSearch, short PerformReset,
- short SrchCmd);
-extern short pascal TMFirst(long, void *);
-extern short pascal TMNext(long, void *);
-extern short pascal TMAccess(long, void *);
-extern short pascal TMStrongAccess(long, void *);
-extern short pascal TMStrongAlarmAccess(long, void *);
-extern short pascal TMOverAccess(long, void *);
-extern short pascal TMRom(long, void *, short *);
-extern short pascal TMFirstAlarm(long, void *);
-extern short pascal TMNextAlarm(long, void *);
-extern short pascal TMFamilySearchSetup(long, void *, short);
-extern short pascal TMSkipFamily(long, void *);
-extern short pascal TMAutoOverDrive(long, void *, short);
-
-
-//--------------------------------------------------------------------------
-// The 'owFirst' finds the first device on the 1-Wire Net This function
-// contains one parameter 'alarm_only'. When
-// 'alarm_only' is TRUE (1) the find alarm command 0xEC is
-// sent instead of the normal search command 0xF0.
-// Using the find alarm command 0xEC will limit the search to only
-// 1-Wire devices that are in an 'alarm' state.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
-// indicate the symbolic port number.
-// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not
-// perform reset before search.
-// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
-// sent instead of the normal search command 0xF0
-//
-// Returns: TRUE (1) : when a 1-Wire device was found and it's
-// Serial Number placed in the global SerialNum[portnum]
-// FALSE (0): There are no devices on the 1-Wire Net.
-//
-SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
-{
- return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1,
- (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
-}
-
-//--------------------------------------------------------------------------
-// The 'owNext' function does a general search. This function
-// continues from the previos search state. The search state
-// can be reset by using the 'owFirst' function.
-// This function contains one parameter 'alarm_only'.
-// When 'alarm_only' is TRUE (1) the find alarm command
-// 0xEC is sent instead of the normal search command 0xF0.
-// Using the find alarm command 0xEC will limit the search to only
-// 1-Wire devices that are in an 'alarm' state.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
-// indicate the symbolic port number.
-// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not
-// perform reset before search.
-// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
-// sent instead of the normal search command 0xF0
-//
-// Returns: TRUE (1) : when a 1-Wire device was found and it's
-// Serial Number placed in the global SerialNum[portnum]
-// FALSE (0): when no new device was found. Either the
-// last search was the last device or there
-// are no devices on the 1-Wire Net.
-//
-SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
-{
- return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0,
- (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
-}
-
-//--------------------------------------------------------------------------
-// The 'owSerialNum' function either reads or sets the SerialNum buffer
-// that is used in the search functions 'owFirst' and 'owNext'.
-// This function contains two parameters, 'serialnum_buf' is a pointer
-// to a buffer provided by the caller. 'serialnum_buf' should point to
-// an array of 8 unsigned chars. The second parameter is a flag called
-// 'do_read' that is TRUE (1) if the operation is to read and FALSE
-// (0) if the operation is to set the internal SerialNum buffer from
-// the data in the provided buffer.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
-// indicate the symbolic port number.
-// 'serialnum_buf' - buffer to that contains the serial number to set
-// when do_read = FALSE (0) and buffer to get the serial
-// number when do_read = TRUE (1).
-// 'do_read' - flag to indicate reading (1) or setting (0) the current
-// serial number.
-//
-void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read)
-{
- short ROM[8],i;
-
- // check if reading or writing
- if (do_read)
- {
- ROM[0] = 0;
- }
- else
- {
- for (i = 0; i < 8; i++)
- ROM[i] = serialnum_buf[i];
- }
-
- // call TMEX to read or set the current device
- TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM);
-
- // place in 'serialnum_buf'
- if (do_read)
- {
- for (i = 0; i < 8; i++)
- serialnum_buf[i] = (uchar)ROM[i];
- }
-}
-
-//--------------------------------------------------------------------------
-// Setup the search algorithm to find a certain family of devices
-// the next time a search function is called 'owNext'.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
-// OpenCOM to indicate the port number.
-// 'search_family' - family code type to set the search algorithm to find
-// next.
-//
-void owFamilySearchSetup(int portnum, SMALLINT search_family)
-{
- TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum],
- (short)search_family);
-}
-
-//--------------------------------------------------------------------------
-// Set the current search state to skip the current family code.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
-// indicate the symbolic port number.
-//
-void owSkipFamily(int portnum)
-{
- TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]);
-}
-
-//--------------------------------------------------------------------------
-// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial
-// Number command followed by the current SerialNum code. After this
-// function is complete the 1-Wire device is ready to accept device-specific
-// commands.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
-// indicate the symbolic port number.
-//
-// Returns: TRUE (1) : reset indicates present and device is ready
-// for commands.
-// FALSE (0): reset does not indicate presence or echos 'writes'
-// are not correct.
-//
-SMALLINT owAccess(int portnum)
-{
- return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
-}
-
-//----------------------------------------------------------------------
-// The function 'owVerify' verifies that the current device
-// is in contact with the 1-Wire Net.
-// Using the find alarm command 0xEC will verify that the device
-// is in contact with the 1-Wire Net and is in an 'alarm' state.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
-// indicate the symbolic port number.
-// 'alarm_only' - TRUE (1) the find alarm command 0xEC
-// is sent instead of the normal search
-// command 0xF0.
-//
-// Returns: TRUE (1) : when the 1-Wire device was verified
-// to be on the 1-Wire Net
-// with alarm_only == FALSE
-// or verified to be on the 1-Wire Net
-// AND in an alarm state when
-// alarm_only == TRUE.
-// FALSE (0): the 1-Wire device was not on the
-// 1-Wire Net or if alarm_only
-// == TRUE, the device may be on the
-// 1-Wire Net but in a non-alarm state.
-//
-SMALLINT owVerify(int portnum, SMALLINT alarm_only)
-{
- if (alarm_only)
- return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
- else
- return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
-}
-
-//----------------------------------------------------------------------
-// Perform a overdrive MATCH command to select the 1-Wire device with
-// the address in the ID data register.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
-// indicate the symbolic port number.
-//
-// Returns: TRUE: If the device is present on the 1-Wire Net and
-// can do overdrive then the device is selected.
-// FALSE: Device is not present or not capable of overdrive.
-//
-// *Note: This function could be converted to send DS2480
-// commands in one packet.
-//
-SMALLINT owOverdriveAccess(int portnum)
-{
- return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
-}
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//---------------------------------------------------------------------------\r
+//\r
+// tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API\r
+// for network functions.\r
+//\r
+// Version: 3.00\r
+//\r
+//\r
+\r
+#include "ownet.h"\r
+#include <windows.h>\r
+\r
+uchar StateBuffer[MAX_PORTNUM][5120];\r
+\r
+// external TMEX variables\r
+extern long SessionHandle[MAX_PORTNUM];\r
+extern short far pascal TMSearch(long session_handle, void *start_buffer, \r
+ short ResetSearch, short PerformReset, \r
+ short SrchCmd);\r
+extern short pascal TMFirst(long, void *);\r
+extern short pascal TMNext(long, void *);\r
+extern short pascal TMAccess(long, void *);\r
+extern short pascal TMStrongAccess(long, void *);\r
+extern short pascal TMStrongAlarmAccess(long, void *);\r
+extern short pascal TMOverAccess(long, void *);\r
+extern short pascal TMRom(long, void *, short *);\r
+extern short pascal TMFirstAlarm(long, void *);\r
+extern short pascal TMNextAlarm(long, void *);\r
+extern short pascal TMFamilySearchSetup(long, void *, short);\r
+extern short pascal TMSkipFamily(long, void *);\r
+extern short pascal TMAutoOverDrive(long, void *, short);\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owFirst' finds the first device on the 1-Wire Net This function\r
+// contains one parameter 'alarm_only'. When\r
+// 'alarm_only' is TRUE (1) the find alarm command 0xEC is\r
+// sent instead of the normal search command 0xF0.\r
+// Using the find alarm command 0xEC will limit the search to only\r
+// 1-Wire devices that are in an 'alarm' state.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not\r
+// perform reset before search.\r
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is\r
+// sent instead of the normal search command 0xF0\r
+//\r
+// Returns: TRUE (1) : when a 1-Wire device was found and it's\r
+// Serial Number placed in the global SerialNum[portnum]\r
+// FALSE (0): There are no devices on the 1-Wire Net.\r
+//\r
+SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only)\r
+{\r
+ return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1, \r
+ (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owNext' function does a general search. This function\r
+// continues from the previos search state. The search state\r
+// can be reset by using the 'owFirst' function.\r
+// This function contains one parameter 'alarm_only'.\r
+// When 'alarm_only' is TRUE (1) the find alarm command\r
+// 0xEC is sent instead of the normal search command 0xF0.\r
+// Using the find alarm command 0xEC will limit the search to only\r
+// 1-Wire devices that are in an 'alarm' state.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not\r
+// perform reset before search.\r
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is\r
+// sent instead of the normal search command 0xF0\r
+//\r
+// Returns: TRUE (1) : when a 1-Wire device was found and it's\r
+// Serial Number placed in the global SerialNum[portnum]\r
+// FALSE (0): when no new device was found. Either the\r
+// last search was the last device or there\r
+// are no devices on the 1-Wire Net.\r
+//\r
+SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only)\r
+{\r
+ return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0, \r
+ (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owSerialNum' function either reads or sets the SerialNum buffer\r
+// that is used in the search functions 'owFirst' and 'owNext'.\r
+// This function contains two parameters, 'serialnum_buf' is a pointer\r
+// to a buffer provided by the caller. 'serialnum_buf' should point to\r
+// an array of 8 unsigned chars. The second parameter is a flag called\r
+// 'do_read' that is TRUE (1) if the operation is to read and FALSE\r
+// (0) if the operation is to set the internal SerialNum buffer from\r
+// the data in the provided buffer.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'serialnum_buf' - buffer to that contains the serial number to set\r
+// when do_read = FALSE (0) and buffer to get the serial\r
+// number when do_read = TRUE (1).\r
+// 'do_read' - flag to indicate reading (1) or setting (0) the current\r
+// serial number.\r
+//\r
+void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read)\r
+{\r
+ short ROM[8],i;\r
+\r
+ // check if reading or writing\r
+ if (do_read)\r
+ {\r
+ ROM[0] = 0;\r
+ }\r
+ else\r
+ {\r
+ for (i = 0; i < 8; i++)\r
+ ROM[i] = serialnum_buf[i];\r
+ }\r
+\r
+ // call TMEX to read or set the current device\r
+ TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM);\r
+\r
+ // place in 'serialnum_buf'\r
+ if (do_read)\r
+ {\r
+ for (i = 0; i < 8; i++)\r
+ serialnum_buf[i] = (uchar)ROM[i];\r
+ }\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Setup the search algorithm to find a certain family of devices\r
+// the next time a search function is called 'owNext'.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+// 'search_family' - family code type to set the search algorithm to find\r
+// next.\r
+//\r
+void owFamilySearchSetup(int portnum, SMALLINT search_family)\r
+{\r
+ TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum], \r
+ (short)search_family);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Set the current search state to skip the current family code.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+//\r
+void owSkipFamily(int portnum)\r
+{\r
+ TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial\r
+// Number command followed by the current SerialNum code. After this\r
+// function is complete the 1-Wire device is ready to accept device-specific\r
+// commands.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+//\r
+// Returns: TRUE (1) : reset indicates present and device is ready\r
+// for commands.\r
+// FALSE (0): reset does not indicate presence or echos 'writes'\r
+// are not correct.\r
+//\r
+SMALLINT owAccess(int portnum)\r
+{\r
+ return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+}\r
+\r
+//----------------------------------------------------------------------\r
+// The function 'owVerify' verifies that the current device\r
+// is in contact with the 1-Wire Net.\r
+// Using the find alarm command 0xEC will verify that the device\r
+// is in contact with the 1-Wire Net and is in an 'alarm' state.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC\r
+// is sent instead of the normal search\r
+// command 0xF0.\r
+//\r
+// Returns: TRUE (1) : when the 1-Wire device was verified\r
+// to be on the 1-Wire Net\r
+// with alarm_only == FALSE\r
+// or verified to be on the 1-Wire Net\r
+// AND in an alarm state when\r
+// alarm_only == TRUE.\r
+// FALSE (0): the 1-Wire device was not on the\r
+// 1-Wire Net or if alarm_only\r
+// == TRUE, the device may be on the\r
+// 1-Wire Net but in a non-alarm state.\r
+//\r
+SMALLINT owVerify(int portnum, SMALLINT alarm_only)\r
+{\r
+ if (alarm_only)\r
+ return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+ else\r
+ return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+}\r
+\r
+//----------------------------------------------------------------------\r
+// Perform a overdrive MATCH command to select the 1-Wire device with\r
+// the address in the ID data register.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+//\r
+// Returns: TRUE: If the device is present on the 1-Wire Net and\r
+// can do overdrive then the device is selected.\r
+// FALSE: Device is not present or not capable of overdrive.\r
+//\r
+// *Note: This function could be converted to send DS2480\r
+// commands in one packet.\r
+//\r
+SMALLINT owOverdriveAccess(int portnum)\r
+{\r
+ return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+}\r