--- /dev/null
+//---------------------------------------------------------------------------\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
+int owInUse = 0;\r
+\r
+// external TMEX variables\r
+extern long SessionHandle[MAX_PORTNUM];\r
+extern "C" short far pascal TMSearch(long session_handle, void *start_buffer,\r
+ short ResetSearch, short PerformReset, \r
+ short SrchCmd);\r
+extern "C" short pascal TMFirst(long, void *);\r
+extern "C" short pascal TMNext(long, void *);\r
+extern "C" short pascal TMAccess(long, void *);\r
+extern "C" short pascal TMStrongAccess(long, void *);\r
+extern "C" short pascal TMStrongAlarmAccess(long, void *);\r
+extern "C" short pascal TMOverAccess(long, void *);\r
+extern "C" short pascal TMRom(long, void *, short *);\r
+extern "C" short pascal TMFirstAlarm(long, void *);\r
+extern "C" short pascal TMNextAlarm(long, void *);\r
+extern "C" short pascal TMFamilySearchSetup(long, void *, short);\r
+extern "C" short pascal TMSkipFamily(long, void *);\r
+extern "C" 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