if (line[0]==':') {
//ss << std::hex << line.substr(1,2);
//ss >> bc;
- uint8_t bc=std::stoul( line.substr(1,2), nullptr, 16);
+ uint8_t bc=(uint8_t)std::stoul( line.substr(1,2), nullptr, 16);
uint32_t fw=std::stoul(line.substr(3,4),nullptr, 16);
- uint8_t ty=std::stoul(line.substr(7,2),nullptr,16);
+ uint8_t ty=(uint8_t)std::stoul(line.substr(7,2),nullptr,16);
uint32_t chsm = bc + (fw >> 8) + (fw & 0xFF) + ty;
for (int i = 0; i < bc; i++) {
int p = 9 + i * 2;
- uint8_t b = std::stoul(line.substr(p, 2),nullptr, 16);
+ uint8_t b = (uint8_t)std::stoul(line.substr(p, 2),nullptr, 16);
chsm = chsm + b;
prog.push_back(b);
}
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include "owTools.h"
+#ifdef LINUX
#include <mysql.h>
#include "mySensorDB.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
#include <sys/mman.h>
-#include <fcntl.h> /* For O_RDWR */
#include <unistd.h>
#include <pthread.h>
#include <sched.h>
+#endif
+
+#ifdef WIN
+#include "Windows.h"
+#include "time.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <fcntl.h> /* For O_RDWR */
#include <memory.h>
-#include "owTools.h"
#include "hexfile.h"
#include <iostream>
#include <algorithm>
#include <fstream>
#include <sstream>
-
+#ifdef LINUX
#define RB "\e(0\x6a\e(B" // 188 Right Bottom corner
#define RT "\e(0\x6b\e(B" // 187 Right Top corner
#define TC "\e(0\x77\e(B" // 203 Top Cross
#define VL "\e(0\x78\e(B" // 186 Vertical Line
#define SP " " // space string
-
+#endif
+#ifdef WIN
+#define RB " "// 188 Right Bottom corner
+#define RT " "// 187 Right Top corner
+#define LT " "// 201 Left Top cornet
+#define LB " "// 200 Left Bottom corner
+#define MC " " // 206 Midle Cross
+#define HL " "// 205 Horizontal Line
+#define LC " "// 204 Left Cross
+#define RC " "// 185 Right Cross
+#define BC " "// 202 Bottom Cross
+#define TC " "// 203 Top Cross
+#define VL " "// 186 Vertical Line
+#define SP " " // space string
+#endif
void printhelp() {
printf("owTools - Programm for reading und controlling 1-Wire Devices from www.tm3d.de\n\n");
return atoi(getArg(flag).c_str());
}
-
+#ifdef LINUX
int database=0;
mySensorDB *sdb=NULL;
-
-
+#endif
+/*
snum_t getArgsnum(std::string flag) {
snum_t snum;
snum.num=0;
return snum;
}
-
+*/
int findCPU(std::string cpu) {
std::ifstream fileInput;
std::string line;
for (owDevice* dev :*devices) {
if (dev->configstate!=OWDCS_NONE) {
for (size_t i=0;i<4;i++) {
- if (dev->config->getPropertyID(i)!=0)
+ if (dev->config->getPropertyID((uint8_t)i)!=0)
printf("\033[1;34m%02X.%02X%02X\033[0m\t",dev->getNum().byte[7],dev->getNum().byte[1],dev->getNum().byte[0]);
}
}
for (owDevice* dev :*devices) {
if (dev->configstate!=OWDCS_NONE) {
for (size_t i=0;i<4;i++) {
- if (dev->config->getPropertyID(i)!=0)
- printf("\033[0;36m%s\033[0m\t",dev->config->getQuantity(i).substr(0,7).c_str());
+ if (dev->config->getPropertyID((uint8_t)i)!=0)
+ printf("\033[0;36m%s\033[0m\t",dev->config->getQuantity((uint8_t)i).substr(0,7).c_str());
}
}
}
for (owDevice* dev :*devices) {
if (dev->configstate!=OWDCS_NONE) {
for (size_t i=0;i<4;i++) {
- if (dev->config->getPropertyID(i)!=0) {
- size_t l=utf8_length(dev->config->getUnit(i));
+ if (dev->config->getPropertyID((uint8_t)i)!=0) {
+ size_t l=utf8_length(dev->config->getUnit((uint8_t)i));
std::string ls=" ";
- printf("\033[3;34m[%s]%s\033[0m\t",dev->config->getUnit(i).c_str(),ls.substr(0,5-l).c_str());
+ printf("\033[3;34m[%s]%s\033[0m\t",dev->config->getUnit((uint8_t)i).c_str(),ls.substr(0,5-l).c_str());
}
}
}
}
printf("\n");
-
+#ifdef LINUX
if (database) {
//owi->log->setLogLevel(0);
for (owDevice* dev : *devices) {
sdb->createDeviceTable(dev);
}
}
+#endif
}
}
time_t t=time(NULL);
int st=(int)t;
+#ifdef LINUX
struct tm tm = *localtime(&t);
+#endif
+#ifdef WIN
+ struct tm tm;
+ localtime_s(&tm,&t);
+#endif
printf("%d-%02d-%02d %02d:%02d:%02d\t", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
for (owDevice* dev :*devices) {
for(int k=0;k<owi->maxrepeat;k++){
if (owi->log->last()<OWLOG_ERROR) {
if (dev->configstate!=OWDCS_NONE) {
for (size_t i=0;i<4;i++) {
- if (dev->config->getPropertyID(i)!=0) {
+ if (dev->config->getPropertyID((int8_t)i)!=0) {
if (dev->values[i]<=-10)
printf("%0.2f \t",dev->values[i]);
else if (dev->values[i]<0)
}
}
}
+#ifdef LINUX
if (database) {
sdb->insertValues(dev);
}
+#endif
} else {
owi->log->setLogLevel(OWLOG_INFO);
owi->log->set(OWLOG_ERROR,"Too many errors, mybee conection is dead.");
}
printf("\n");
- while (((int)time(NULL))<(st+intervall)) sleep(1);
+ while (((int)time(NULL)) < (st + intervall)) {
+#ifdef LINUX
+ sleep(1);
+#endif
+#ifdef WIN
+ Sleep(1000);
+#endif
+ }
}
}
printf("Values info: ");
int tm3d=d->readConfig();
for (size_t i=0;i<4;i++) {
- printf("%s in %s",d->config->getQuantity(i).c_str(),d->config->getUnit(i).c_str());
+ printf("%s in %s",d->config->getQuantity((uint8_t)i).c_str(),d->config->getUnit((uint8_t)i).c_str());
if (i<4) printf("; ");
}
if (tm3d) printf(" (tm3d.de)"); else printf(" (default)");
printf("\n");
d->convertAll();
for (size_t i=0;i<d->values.size();i++) {
- printf("\033[1;33m%0.4f %s\033[0m ",d->values[i],d->config->getUnit(i).c_str());
+ printf("\033[1;33m%0.4f %s\033[0m ",d->values[i],d->config->getUnit((uint8_t)i).c_str());
}
printf("\n");
for(int i=0;i<70;i++) printf(HL);printf("\n");
std::transform(adapter.begin(), adapter.end(),adapter.begin(), ::toupper);
std::string s;
-
+#ifdef LINUX
if(adapter.find("COM")!=std::string::npos) {
owi=new owCOMInterface();
int port=atoi(adapter.substr(adapter.find("COM")+3).c_str());
printf("Open /dev/ttyS%i\n",port);
owi->InitAdapter(port);
} else
- if(adapter.find("ARDUINO")!=std::string::npos) {
- owi=new owARDUINOInterface();
- int port=atoi(adapter.substr(adapter.find("ARDUINO")+7).c_str());
- printf("Open /dev/ttyS%i\n",port);
- owi->InitAdapter(port);
- } else
if(adapter.find("USB")!=std::string::npos) {
owi=new owUSBInterface();
int port=atoi(adapter.substr(adapter.find("USB")+3).c_str());
} else {
printf("\033[1;31mGPIO works with Raspberry PI only \033[0m\n");
}
- }
- if (owi==NULL) {
+ } else
+#endif
+ if (adapter.find("ARDUINO") != std::string::npos) {
+ owi = new owARDUINOInterface();
+ int port = atoi(adapter.substr(adapter.find("ARDUINO") + 7).c_str());
+ printf("Open /dev/ttyS%i\n", port);
+ owi->InitAdapter(port);
+ }
+
+#ifdef WIN
+ else
+ if (adapter.find("USB") != std::string::npos) {
+ printf("USB \n");
+ owi = new owTMEXWIN();
+ int port = atoi(adapter.substr(adapter.find("USB") + 3).c_str());
+ printf("Open the %i. USB Adapter\n", port);
+ int err;
+ char cs[20];
+ sprintf_s(cs, 20, "{%i,6}", port);
+ if ((err = owi->InitAdapter(cs))==0) {
+ printf("ERROR Init USB Adapter\n");
+ exit(0);
+ }
+ }
+ else
+ if (adapter.find("COM") != std::string::npos) {
+ printf("USB \n");
+ owi = new owTMEXWIN();
+ int port = atoi(adapter.substr(adapter.find("COM") + 3).c_str());
+ printf("Open Adapter on COM%i\n", port);
+ int err;
+ char cs[20];
+ sprintf_s(cs, 20, "{%i,5}", port);
+ if ((err = owi->InitAdapter(cs))==0) {
+ printf("ERROR Init Serial Adapter\n");
+ exit(0);
+ }
+ }
+#endif
+ if (owi == NULL) {
printf("No 1-Wiremaster found\n");
return 0;
}
-
setLogMode();
if ((s=getArg("p")) !="") {
pause=atoi(s.c_str());
} else pause=30;
+#ifdef LINUX
if ((s=getArg("d")) !="") {
reload=1;
printf("Use Database\n");
exit(1);
}
database=1;
- }
+ }
+#endif
continuous(&(owi->devices),pause,1,reload);
if ((getArg("g"))=="1") {
printf("get ID from Server\n");
char s[255];
+#ifdef LINUX
sprintf(s,"wget -q http://www.tm3d.de/shop99/owid.php?fam=%02X -O id.txt",snum.byte[0]);
+#endif
+#ifdef WIN
+ sprintf_s(s, "wget -q http://www.tm3d.de/shop99/owid.php?fam=%02X -O id.txt", snum.byte[0]);
+#endif
int err;
if ((err=system(s))==0) {
printf("OK!\n");
if (c=='x') br=1;
} else {
if ((c==',')|(c=='}')) {
- isnum.byte[i]=strtol(s, NULL, 16);
+ isnum.byte[i]=(uint8_t)strtol(s, NULL, 16);
//printf("%x\n",strtol(s, NULL, 16));
i++;
br=0;
colm.push_back("");
} else {
char hs[50];
+#ifdef LINUX
sprintf(hs,"%0.3f",dev->values[i]);
+#endif
+#ifdef WIN
+ sprintf_s(hs, "%0.3f", dev->values[i]);
+#endif
colm.push_back(hs);
}
if (max<utf8_length(colm[3])) max=utf8_length(colm[3]);
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the
-// distribution.
-// * All advertising materials mentioning features or use of this
-// software must display the following acknowledgement: This product
-// includes software developed by tm3d.de and its contributors.
-// * Neither the name of tm3d.de nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/select.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <time.h>
-#include <termios.h>
-#include <errno.h>
-#include <sys/time.h>
-#include "owARDUINOInterface.h"
-
-#define MODE_DATA 0xE1
-#define MODE_COMMAND 0xE3
-
-// Baud rate bits
-#define PARMSET_9600 0x00
-#define PARMSET_19200 0x02
-#define PARMSET_57600 0x04
-#define PARMSET_115200 0x06
-
-
-
-#define COM_IDENTIFER 1
-#define COM_RESET 2
-#define COM_SEARCH_INIT 3
-#define COM_SEARCH_NEXT 4
-#define COM_BLOCK 5
-#define COM_SBYTE 6
-#define COM_RBYTE 7
-#define COM_SBIT 8
-#define COM_RBIT 9
-
-//---------------------------------------------------------------------------
-// Description:
-// flush the rx and tx buffers
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
-// OpenCOM to indicate the port number.
-//
-void owARDUINOInterface::FlushCOM() {
- tcflush(fd, TCIOFLUSH);
-}
-
-
-int owARDUINOInterface::OpenCOM(uint8_t comnr) {
- struct termios t; // see man termios - declared as above
- int rc;
- //int fd;
- char port_zstr[100];
- if (com_init) return fd;
-
- sprintf(port_zstr,"/dev/ttyUSB%i",comnr);
-
- fd = open(port_zstr, O_RDWR|O_NONBLOCK| O_NOCTTY );
- if (fd<0)
- {
- log->set(OWLOG_ERROR,"ERROR open Com %s return %i",port_zstr,fd);
- return fd;
- }
- rc = tcgetattr (fd, &t);
- if (rc < 0)
- {
- int tmp;
- tmp = errno;
- close(fd);
- errno = tmp;
- log->set(OWLOG_ERROR,"OWERROR_SYSTEM_RESOURCE_INIT_FAILED %s",port_zstr);
- return rc; // changed (2.00), used to return rc;
- }
-
- cfsetospeed(&t, B9600);
- cfsetispeed (&t, B9600);
-
- // Get terminal parameters. (2.00) removed raw
- tcgetattr(fd,&t);
- // Save original settings.
- origterm = t;
-
- t.c_cflag &= ~PARENB; // Make 8n1
- t.c_cflag &= ~CSTOPB;
- t.c_cflag &= ~CSIZE;
- t.c_cflag |= CS8;
-
- t.c_cflag &= ~CRTSCTS; // no flow control
- t.c_cc[VMIN] = 1; // read doesn't block
- t.c_cc[VTIME] = 5; // 0.5 seconds read timeout
- t.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
- t.c_cflag &= ~CRTSCTS; // no flow control
- t.c_iflag &= ~(IXON | IXOFF | IXANY);// turn off s/w flow ctrl
-/* Make raw */
- cfmakeraw(&t);
- tcflush(fd,TCIOFLUSH);
-
- rc = tcsetattr(fd, TCSAFLUSH, &t);
-
- if (rc < 0)
- {
- int tmp;
- tmp = errno;
- close(fd);
- errno = tmp;
- log->set(OWLOG_ERROR,"OWERROR_SYSTEM_RESOURCE_INIT_FAILED %s",port_zstr);
- return rc; // changed (2.00), used to return rc;
- }
- com_init=1;
- return fd; // changed (2.00), used to return fd;
-}
-
-
-//---------------------------------------------------------------------------
-// Closes the connection to the port.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
-// OpenCOM to indicate the port number.
-//
-void owARDUINOInterface::CloseCOM()
-{
- // restore tty settings
- tcsetattr(fd, TCSAFLUSH, &origterm);
- FlushCOM();
- close(fd);
- com_init=0;
-
-}
-
-
-//--------------------------------------------------------------------------
-// Write an array of bytes to the COM port, verify that it was
-// sent out. Assume that baud rate has been set.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number provided will
-// be used to indicate the port number desired when calling
-// all other functions in this library.
-// Returns 1 for success and 0 for failure
-//
-int owARDUINOInterface::WriteCOM( int outlen, uint8_t *outbuf)
-{
- long count = outlen;
- int i=0;
- for (int k=0;k<outlen;k++) {
- i+= write(fd, outbuf+k, 1);
-// sleep(1);
- }
-
- tcdrain(fd);
- return (i == count);
-}
-
-
-//--------------------------------------------------------------------------
-// Read an array of bytes to the COM port, verify that it was
-// sent out. Assume that baud rate has been set.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
-// OpenCOM to indicate the port number.
-// 'outlen' - number of bytes to write to COM port
-// 'outbuf' - pointer ot an array of bytes to write
-//
-// Returns: TRUE(1) - success
-// FALSE(0) - failure
-//
-int owARDUINOInterface::ReadCOM( int inlen, uint8_t *inbuf)
-{
- fd_set filedescr;
- struct timeval tval;
- int cnt;
-
- // loop to wait until each byte is available and read it
- for (cnt = 0; cnt < inlen; cnt++)
- {
- // set a descriptor to wait for a character available
- FD_ZERO(&filedescr);
- FD_SET(fd,&filedescr);
- // set timeout to 10ms
- tval.tv_sec = 10;
- tval.tv_usec = 10000;
-
- // if byte available read or return bytes read
- if (select(fd+1,&filedescr,NULL,NULL,&tval) != 0)
- {
- if (read(fd,&inbuf[cnt],1) != 1) {
- log->set(OWLOG_ERROR,"Read Error on Serial");
-
- return cnt;
- }
- }
- else {
- log->set(OWLOG_ERROR,"Read Error on Serial (select)");
- return cnt;
- }
- }
-
-
- // success, so return desired length
- return inlen;
-}
-
-
-
-
-//--------------------------------------------------------------------------
-// Description:
-// Send a break on the com port for at least 2 ms
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
-// OpenCOM to indicate the port number.
-//
-void owARDUINOInterface::BreakCOM()
-{
- int duration = 0; // see man termios break may be
- tcsendbreak(fd, duration); // too long
-}
-
-
-//--------------------------------------------------------------------------
-// Set the baud rate on the com port.
-//
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
-// OpenCOM to indicate the port number.
-// 'new_baud' - new baud rate defined as
-// PARMSET_9600 0x00
-// PARMSET_19200 0x02
-// PARMSET_57600 0x04
-// PARMSET_115200 0x06
-//
-void owARDUINOInterface::SetBaudCOM( uint8_t new_baud)
-{
- struct termios t;
- int rc;
- speed_t baud;
-
- // read the attribute structure
- rc = tcgetattr(fd, &t);
- if (rc < 0)
- {
- close(fd);
- log->set(OWLOG_ERROR,"Error on Serial (set Boudrate)");
-
- return;
- }
-
- // convert parameter to linux baud rate
- switch(new_baud)
- {
- case PARMSET_9600:
- baud = B9600;
- break;
- case PARMSET_19200:
- baud = B19200;
- break;
- case PARMSET_57600:
- baud = B57600;
- break;
- case PARMSET_115200:
- baud = B115200;
- break;
- default:
- baud = B9600;
- break;
- }
-
- // set baud in structure
- cfsetospeed(&t, baud);
- cfsetispeed(&t, baud);
-
- // change baud on port
- rc = tcsetattr(fd, TCSAFLUSH, &t);
- if (rc < 0) {
- log->set(OWLOG_ERROR,"Error on Serial (set Boudrate)");
-
- close(fd);
- }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-int owARDUINOInterface::InitAdapter(uint8_t nr) {
- // attempt to open the communications port
- if ((fd = OpenCOM(nr)) < 0)
- {
- log->set(OWLOG_ERROR,"OWERROR_OPENCOM_FAILED");
- return -1;
- }
- sleep(2);
- uint8_t readbuffer[20],sendpacket[20];
- uint8_t sendlen=0;
- sendpacket[sendlen++]=0x01;
- sendpacket[sendlen++]=0x00;
- sendpacket[sendlen++]=0x03;
- if (WriteCOM(sendlen,sendpacket)) {
- if ((sendlen=ReadCOM(3,readbuffer)) == 3) {
-
- // printf("%02X %02X %02X\n",readbuffer[0],readbuffer[1],readbuffer[2] );
-
-
-
- } else {
- //printf("%i\n",sendlen);
- log->set(OWLOG_ERROR,"OWERROR_READCOM_FAILED");
- }
- } else log->set(OWLOG_ERROR,"OWERROR_WRITECOM_FAILED");
-
- com_init=1;
-
-
- return 1;
-}
-
-
-int owARDUINOInterface::owFirst() {
- uint8_t readbuffer[20],sendpacket[20];
- uint8_t sendlen=0;
- sendpacket[sendlen++]=0x03;
- sendpacket[sendlen++]=0x00;
- sendpacket[sendlen++]=0x08;
- if (WriteCOM(sendlen,sendpacket)) {
- if ((sendlen=ReadCOM(8,readbuffer)) == 8) {
- if (readbuffer[0]!=0) {
- for (int i=0;i<8;i++) ROM_NO[i]=readbuffer[i];
- return 1;
- }
- }
- }
- return 0;
-
-}
-int owARDUINOInterface::owNext() {
- uint8_t readbuffer[20],sendpacket[20];
- uint8_t sendlen=0;
- sendpacket[sendlen++]=0x04;
- sendpacket[sendlen++]=0x00;
- sendpacket[sendlen++]=0x08;
- if (WriteCOM(sendlen,sendpacket)) {
- if ((sendlen=ReadCOM(8,readbuffer)) == 8) {
- if (readbuffer[0]!=0) {
- for (int i=0;i<8;i++) ROM_NO[i]=readbuffer[i];
- return 1;
- }
- }
- }
- return 0;
-
-}
-
-
-void owARDUINOInterface::ReleaseAdapter() {
- CloseCOM();
-}
-
-
-int owARDUINOInterface::Reset() {
- uint8_t readbuffer[5],sendpacket[5];
- uint8_t sendlen=0;
- /* size_t l;
-
- if ((l=read(fd,readbuffer,5))>0) {
- printf("in buf %i bytes %02X %02X %02X %02X %02X\n",l,readbuffer[0],readbuffer[1],readbuffer[2],readbuffer[3],readbuffer[4]);
- }*/
- sendlen=0;
- sendpacket[sendlen++]=0x02;
- sendpacket[sendlen++]=0x00;
- sendpacket[sendlen++]=0x01;
- if (WriteCOM(sendlen,sendpacket)) {
- if ((sendlen=ReadCOM(1,readbuffer)) == 1) {
- // printf("Reset %i\n",readbuffer[0]);
- if (readbuffer[0]) return 1;
-
- }
- }
-
- return 0;
-}
-
-
-uint8_t owARDUINOInterface::sendrecivByte(uint8_t byte) {
-
- uint8_t readbuffer[5],sendpacket[5];
- uint8_t sendlen=0;
-/* size_t l;
- if ((l=read(fd,readbuffer,5))>0) {
- printf("in buf %i bytes %02X %02X %02X %02X %02X\n",l,readbuffer[0],readbuffer[1],readbuffer[2],readbuffer[3],readbuffer[4]);
- }*/
- if (byte!=0xFF) {
- sendlen=0;
- sendpacket[sendlen++]=COM_SBYTE;
- sendpacket[sendlen++]=0x01;
- sendpacket[sendlen++]=0x01;
- sendpacket[sendlen++]=byte;
- if (WriteCOM(sendlen,sendpacket)) {
- if ((sendlen=ReadCOM(1,readbuffer)) == 1) {
- // printf("Send %02X %02X \n",byte,readbuffer[0]);
-
- return byte;
- }
- }
- } else {
- sendlen=0;
- sendpacket[sendlen++]=COM_RBYTE;
- sendpacket[sendlen++]=0x00;
- sendpacket[sendlen++]=0x01;
- if (WriteCOM(sendlen,sendpacket)) {
- if ((sendlen=ReadCOM(1,readbuffer)) == 1) {
- // printf("Recive %02X\n",readbuffer[0]);
- return readbuffer[0];
- }
- }
-
- }
-
- return 0;
-}
-uint8_t owARDUINOInterface::sendrecivBit(uint8_t bit) {
- return 0;
-}
-
-int owARDUINOInterface::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {
- int i=0;
- data->resize(scount);
- uint8_t readbuffer[128],sendpacket[128+3];
- uint8_t sendlen=0;
- sendpacket[sendlen++]=COM_BLOCK;
- sendpacket[sendlen++]=scount;
- sendpacket[sendlen++]=rcount;
- for(uint8_t v:*data) {
- sendpacket[sendlen++]=v;
- (*data)[i]=v;i++;
- }
- if (WriteCOM(sendlen,sendpacket)) {
- if ((sendlen=ReadCOM(rcount,readbuffer)) == rcount) {
- for(i=0;i<rcount;i++) {
- //printf("%02X ",readbuffer[i]);
- data->push_back(readbuffer[i]);
- }
- //printf("\n");
- }
- }
-
-
- return 0;
-}
-
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+// * Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+// * Redistributions in binary form must reproduce the above copyright\r
+// notice, this list of conditions and the following disclaimer in the\r
+// documentation and/or other materials provided with the\r
+// distribution.\r
+// * All advertising materials mentioning features or use of this\r
+// software must display the following acknowledgement: This product\r
+// includes software developed by tm3d.de and its contributors.\r
+// * Neither the name of tm3d.de nor the names of its contributors may\r
+// be used to endorse or promote products derived from this software\r
+// without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#ifdef LINUX\r
+#include <unistd.h>\r
+#include <sys/select.h>\r
+#include <sys/ioctl.h>\r
+#include <termios.h>\r
+#include <sys/time.h>\r
+#endif\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <fcntl.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include "owARDUINOInterface.h"\r
+\r
+\r
+#define COM_IDENTIFER 1\r
+#define COM_RESET 2\r
+#define COM_SEARCH_INIT 3\r
+#define COM_SEARCH_NEXT 4\r
+#define COM_BLOCK 5\r
+#define COM_SBYTE 6\r
+#define COM_RBYTE 7\r
+#define COM_SBIT 8\r
+#define COM_RBIT 9\r
+\r
+//---------------------------------------------------------------------------\r
+// Description:\r
+// flush the rx and tx buffers\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+//\r
+void owARDUINOInterface::FlushCOM() {\r
+#ifdef LINUX\r
+ tcflush(fd, TCIOFLUSH);\r
+#endif \r
+#ifdef WIN\r
+ PurgeComm(fd, PURGE_TXABORT | PURGE_RXABORT |\r
+ PURGE_TXCLEAR | PURGE_RXCLEAR);\r
+#endif\r
+}\r
+\r
+#ifdef LINUX\r
+int \r
+#endif\r
+#ifdef WIN\r
+HANDLE \r
+#endif\r
+owARDUINOInterface::OpenCOM(uint8_t comnr)\r
+{\r
+ char port_zstr[100];\r
+#ifdef LINUX\r
+ struct termios t; // see man termios - declared as above\r
+ int rc;\r
+ //int fd;\r
+ \r
+ if (com_init) return fd;\r
+\r
+ sprintf(port_zstr,"/dev/ttyUSB%i",comnr);\r
+\r
+ fd = open(port_zstr, O_RDWR|O_NONBLOCK| O_NOCTTY );\r
+ if (fd<0)\r
+ {\r
+ log->set(OWLOG_ERROR,"ERROR open Com %s return %i",port_zstr,fd);\r
+ return fd;\r
+ }\r
+ rc = tcgetattr (fd, &t);\r
+ if (rc < 0)\r
+ {\r
+ int tmp;\r
+ tmp = errno;\r
+ close(fd);\r
+ errno = tmp;\r
+ log->set(OWLOG_ERROR,"OWERROR_SYSTEM_RESOURCE_INIT_FAILED %s",port_zstr);\r
+ return rc; // changed (2.00), used to return rc;\r
+ }\r
+\r
+ cfsetospeed(&t, B9600);\r
+ cfsetispeed (&t, B9600);\r
+\r
+ // Get terminal parameters. (2.00) removed raw\r
+ tcgetattr(fd,&t);\r
+ // Save original settings.\r
+ origterm = t;\r
+\r
+ t.c_cflag &= ~PARENB; // Make 8n1\r
+ t.c_cflag &= ~CSTOPB;\r
+ t.c_cflag &= ~CSIZE;\r
+ t.c_cflag |= CS8;\r
+\r
+ t.c_cflag &= ~CRTSCTS; // no flow control\r
+ t.c_cc[VMIN] = 1; // read doesn't block\r
+ t.c_cc[VTIME] = 5; // 0.5 seconds read timeout\r
+ t.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines\r
+ t.c_cflag &= ~CRTSCTS; // no flow control\r
+ t.c_iflag &= ~(IXON | IXOFF | IXANY);// turn off s/w flow ctrl\r
+/* Make raw */\r
+ cfmakeraw(&t);\r
+ tcflush(fd,TCIOFLUSH);\r
+\r
+ rc = tcsetattr(fd, TCSAFLUSH, &t);\r
+ \r
+ if (rc < 0)\r
+ {\r
+ int tmp;\r
+ tmp = errno;\r
+ close(fd);\r
+ errno = tmp;\r
+ log->set(OWLOG_ERROR,"OWERROR_SYSTEM_RESOURCE_INIT_FAILED %s",port_zstr);\r
+ return rc; // changed (2.00), used to return rc;\r
+ }\r
+ com_init=1;\r
+ return fd; // changed (2.00), used to return fd;\r
+#endif\r
+#ifdef WIN\r
+ short fRetVal;\r
+ COMMTIMEOUTS CommTimeOuts;\r
+ DCB dcb;\r
+ int comnr1 = comnr;\r
+ sprintf_s(port_zstr,100, "COM%d", comnr1);\r
+ if (fd <= 0) {\r
+ if ((fd = CreateFileA(port_zstr, GENERIC_READ | GENERIC_WRITE,\r
+ 0,\r
+ NULL, // no security attrs\r
+ OPEN_EXISTING,\r
+ FILE_FLAG_OVERLAPPED, // overlapped I/O\r
+ NULL)) == (HANDLE)-1) {\r
+ fd = 0;\r
+ log->set(OWLOG_ERROR, "ERROR open Com %s return %i", port_zstr, fd);\r
+ return (FALSE);\r
+ } else {\r
+ // get any early notifications\r
+ SetCommMask(fd, EV_RXCHAR | EV_TXEMPTY | EV_ERR | EV_BREAK);\r
+ SetupComm(fd, 2048, 2048);\r
+ // purge any information in the buffer\r
+ PurgeComm(fd, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);\r
+ // set up for overlapped non-blocking I/O\r
+ CommTimeOuts.ReadIntervalTimeout = 0;\r
+ CommTimeOuts.ReadTotalTimeoutMultiplier = 20;\r
+ CommTimeOuts.ReadTotalTimeoutConstant = 40;\r
+ CommTimeOuts.WriteTotalTimeoutMultiplier = 20;\r
+ CommTimeOuts.WriteTotalTimeoutConstant = 40;\r
+ SetCommTimeouts(fd, &CommTimeOuts);\r
+ // setup the com port\r
+ GetCommState(fd, &dcb);\r
+ dcb.BaudRate = CBR_9600; // current baud rate\r
+ dcb.fBinary = TRUE; // binary mode, no EOF check\r
+ dcb.fParity = FALSE; // enable parity checking\r
+ dcb.fOutxCtsFlow = FALSE; // CTS output flow control\r
+ dcb.fOutxDsrFlow = FALSE; // DSR output flow control\r
+ dcb.fDtrControl = FALSE; // DTR flow control type\r
+ dcb.fDsrSensitivity = FALSE; // DSR sensitivity\r
+ dcb.fTXContinueOnXoff = FALSE; // XOFF continues Tx\r
+ dcb.fOutX = FALSE; // XON/XOFF out flow control\r
+ dcb.fInX = FALSE; // XON/XOFF in flow control\r
+ dcb.fErrorChar = FALSE; // enable error replacement\r
+ dcb.fNull = FALSE; // enable null stripping\r
+ dcb.fRtsControl = FALSE; // RTS flow control\r
+ dcb.fAbortOnError = FALSE; // abort reads/writes on error\r
+ dcb.XonLim = 0; // transmit XON threshold\r
+ dcb.XoffLim = 0; // transmit XOFF threshold\r
+ dcb.ByteSize = 8; // number of bits/byte, 4-8\r
+ dcb.Parity = NOPARITY; // 0-4=no,odd,even,mark,space\r
+ dcb.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2\r
+ dcb.XonChar = 0; // Tx and Rx XON character\r
+ dcb.XoffChar = 0; // Tx and Rx XOFF character\r
+ dcb.ErrorChar = 0; // error replacement character\r
+ dcb.EofChar = 0; // end of input character\r
+ dcb.EvtChar = 0; // received event character\r
+ fRetVal = SetCommState(fd, &dcb);\r
+\r
+ }\r
+ // check if successfull\r
+ if (!fRetVal) {\r
+ CloseHandle(fd);\r
+ fd = 0;\r
+ log->set(OWLOG_ERROR, "OWERROR_SYSTEM_RESOURCE_INIT_FAILED %s", port_zstr);\r
+ }\r
+ return (fd);\r
+ }\r
+ return 0;\r
+#endif\r
+}\r
+\r
+\r
+//---------------------------------------------------------------------------\r
+// Closes the connection to the port.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+//\r
+void owARDUINOInterface::CloseCOM()\r
+{\r
+#ifdef LINUX\r
+ // restore tty settings\r
+ tcsetattr(fd, TCSAFLUSH, &origterm);\r
+ FlushCOM();\r
+ close(fd);\r
+#endif\r
+#ifdef WIN\r
+ // disable event notification and wait for thread\r
+ // to halt\r
+ SetCommMask(fd, 0);\r
+\r
+ PurgeComm(fd, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);\r
+ CloseHandle(fd);\r
+ fd = 0;\r
+#endif\r
+ com_init = 0;\r
+\r
+}\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// Write an array of bytes to the COM port, verify that it was\r
+// sent out. Assume that baud rate has been set.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number provided will\r
+// be used to indicate the port number desired when calling\r
+// all other functions in this library.\r
+// Returns 1 for success and 0 for failure\r
+//\r
+int owARDUINOInterface::WriteCOM( int outlen, uint8_t *outbuf) {\r
+#ifdef LINUX\r
+ long count = outlen;\r
+ int i=0;\r
+ for (int k=0;k<outlen;k++) {\r
+ i+= write(fd, outbuf+k, 1);\r
+// sleep(1);\r
+ }\r
+\r
+ tcdrain(fd);\r
+ return (i == count);\r
+#endif\r
+#ifdef WIN\r
+ BOOL fWriteStat;\r
+ DWORD dwBytesWritten = 0;\r
+ DWORD ler = 0, to;\r
+ OVERLAPPED osWrite = { 0 };\r
+ // calculate a timeout\r
+ to = 20 * outlen + 60;\r
+ // write the byte\r
+ osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);\r
+ ResetEvent(osWrite.hEvent);\r
+ fWriteStat = WriteFile(fd, (LPSTR)&outbuf[0], outlen, &dwBytesWritten, &osWrite);\r
+ // check for an error\r
+ // Sleep(100);\r
+ if (!fWriteStat)\r
+ ler = GetLastError();\r
+ // if not done writting then wait\r
+ if (!fWriteStat && ler == ERROR_IO_PENDING) {\r
+ // log->set(OWLOG_ERROR, "SERIAL_ERROR_IO_PENDING");\r
+ WaitForSingleObject(osWrite.hEvent, to);\r
+ // verify all is written correctly\r
+\r
+ fWriteStat = GetOverlappedResult(fd, &osWrite, &dwBytesWritten, FALSE);\r
+ }\r
+ // check results of write\r
+ if (!fWriteStat || (dwBytesWritten != (DWORD)outlen))\r
+ return 0;\r
+ else\r
+ return 1;\r
+#endif\r
+}\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// Read an array of bytes to the COM port, verify that it was\r
+// sent out. Assume that baud rate has been set.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+// 'outlen' - number of bytes to write to COM port\r
+// 'outbuf' - pointer ot an array of bytes to write\r
+//\r
+// Returns: TRUE(1) - success\r
+// FALSE(0) - failure\r
+//\r
+int owARDUINOInterface::ReadCOM( int inlen, uint8_t *inbuf)\r
+{\r
+#ifdef LINUX\r
+ fd_set filedescr;\r
+ struct timeval tval;\r
+ int cnt;\r
+\r
+ // loop to wait until each byte is available and read it\r
+ for (cnt = 0; cnt < inlen; cnt++)\r
+ {\r
+ // set a descriptor to wait for a character available\r
+ FD_ZERO(&filedescr);\r
+ FD_SET(fd,&filedescr);\r
+ // set timeout to 10ms\r
+ tval.tv_sec = 10;\r
+ tval.tv_usec = 10000;\r
+\r
+ // if byte available read or return bytes read\r
+ if (select(fd+1,&filedescr,NULL,NULL,&tval) != 0)\r
+ {\r
+ if (read(fd,&inbuf[cnt],1) != 1) {\r
+ log->set(OWLOG_ERROR,"Read Error on Serial");\r
+\r
+ return cnt;\r
+ }\r
+ }\r
+ else {\r
+ log->set(OWLOG_ERROR,"Read Error on Serial (select)");\r
+ return cnt;\r
+ }\r
+ }\r
+\r
+ \r
+ // success, so return desired length\r
+ return inlen;\r
+#endif\r
+#ifdef WIN\r
+ DWORD dwLength = 0;\r
+ BOOL fReadStat;\r
+ DWORD ler = 0, to;\r
+ OVERLAPPED osReader = { 0 };\r
+ // calculate a timeout\r
+ to = 20 * inlen + 60;\r
+ // read\r
+ osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);\r
+ ResetEvent(osReader.hEvent);\r
+ fReadStat = ReadFile(fd, (LPSTR)&inbuf[0], inlen, &dwLength, &osReader);\r
+ //Sleep(100);\r
+ // check for an error\r
+ if (!fReadStat) {\r
+ ler = GetLastError();\r
+ // log->set(OWLOG_ERROR, "Read Error on Serial");\r
+ }\r
+ // if not done writing then wait\r
+ int e = 0;\r
+ while (!fReadStat && ler == ERROR_IO_PENDING) {\r
+ // wait until everything is read\r
+ // log->set(OWLOG_ERROR, "Read Error on Serial");\r
+ // printf("try Read %i\n", e); e++;\r
+ WaitForSingleObject(osReader.hEvent, to);\r
+ // verify all is read correctly\r
+ fReadStat = GetOverlappedResult(fd, &osReader, &dwLength, FALSE);\r
+ //printf("%i %i\n", dwLength, inlen);\r
+ if (dwLength == inlen) break;\r
+ if (e == 3) break;\r
+ printf("repeat\n");\r
+\r
+ }\r
+ // check results\r
+ if (fReadStat)\r
+ return dwLength;\r
+ else\r
+ return 0;\r
+#endif\r
+}\r
+\r
+\r
+/*\r
+\r
+//--------------------------------------------------------------------------\r
+// Description:\r
+// Send a break on the com port for at least 2 ms\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+//\r
+void owARDUINOInterface::BreakCOM()\r
+{\r
+ int duration = 0; // see man termios break may be\r
+ tcsendbreak(fd, duration); // too long\r
+}\r
+\r
+*/\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+int owARDUINOInterface::InitAdapter(uint8_t nr) {\r
+ // attempt to open the communications port\r
+ if ((fd = OpenCOM(nr)) < 0)\r
+ {\r
+ log->set(OWLOG_ERROR,"OWERROR_OPENCOM_FAILED");\r
+ return -1;\r
+ }\r
+#ifdef WIN\r
+ Sleep(2000);\r
+#endif\r
+#ifdef LINUX\r
+ sleep(2);\r
+#endif\r
+ uint8_t readbuffer[20],sendpacket[20];\r
+ uint8_t sendlen=0;\r
+ sendpacket[sendlen++]=0x01;\r
+ sendpacket[sendlen++]=0x00;\r
+ sendpacket[sendlen++]=0x03;\r
+ if (WriteCOM(sendlen,sendpacket)) {\r
+ if ((sendlen=ReadCOM(3,readbuffer)) == 3) {\r
+ // printf("%02X %02X %02X\n",readbuffer[0],readbuffer[1],readbuffer[2] );\r
+ } else {\r
+ log->set(OWLOG_ERROR,"OWERROR_READCOM_FAILED");\r
+ }\r
+ } else log->set(OWLOG_ERROR,"OWERROR_WRITECOM_FAILED"); \r
+ com_init=1;\r
+ return 1; \r
+}\r
+\r
+\r
+int owARDUINOInterface::owFirst() {\r
+ uint8_t readbuffer[20],sendpacket[20];\r
+ uint8_t sendlen=0;\r
+ sendpacket[sendlen++]=0x03;\r
+ sendpacket[sendlen++]=0x00; \r
+ sendpacket[sendlen++]=0x08;\r
+ if (WriteCOM(sendlen,sendpacket)) {\r
+ if ((sendlen=ReadCOM(8,readbuffer)) == 8) {\r
+ if (readbuffer[0]!=0) {\r
+ for (int i=0;i<8;i++) ROM_NO[i]=readbuffer[i];\r
+ return 1;\r
+ }\r
+ }\r
+ }\r
+ return 0;\r
+\r
+}\r
+int owARDUINOInterface::owNext() {\r
+ uint8_t readbuffer[20],sendpacket[20];\r
+ uint8_t sendlen=0;\r
+ sendpacket[sendlen++]=0x04;\r
+ sendpacket[sendlen++]=0x00; \r
+ sendpacket[sendlen++]=0x08;\r
+ if (WriteCOM(sendlen,sendpacket)) {\r
+ if ((sendlen=ReadCOM(8,readbuffer)) == 8) {\r
+ if (readbuffer[0]!=0) {\r
+ for (int i=0;i<8;i++) ROM_NO[i]=readbuffer[i];\r
+ return 1;\r
+ }\r
+ }\r
+ }\r
+ return 0;\r
+\r
+}\r
+\r
+\r
+void owARDUINOInterface::ReleaseAdapter() {\r
+ CloseCOM();\r
+}\r
+\r
+\r
+int owARDUINOInterface::Reset() {\r
+ uint8_t readbuffer[5],sendpacket[5];\r
+ uint8_t sendlen=0;\r
+ sendlen=0;\r
+ sendpacket[sendlen++]=0x02;\r
+ sendpacket[sendlen++]=0x00;\r
+ sendpacket[sendlen++]=0x01;\r
+ if (WriteCOM(sendlen,sendpacket)) {\r
+ if ((sendlen=ReadCOM(1,readbuffer)) == 1) {\r
+ if (readbuffer[0]) return 1;\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+uint8_t owARDUINOInterface::sendrecivByte(uint8_t byte) {\r
+ \r
+ uint8_t readbuffer[5],sendpacket[5];\r
+ uint8_t sendlen=0;\r
+ if (byte!=0xFF) {\r
+ sendlen=0;\r
+ sendpacket[sendlen++]=COM_SBYTE;\r
+ sendpacket[sendlen++]=0x01;\r
+ sendpacket[sendlen++]=0x01;\r
+ sendpacket[sendlen++]=byte;\r
+ if (WriteCOM(sendlen,sendpacket)) {\r
+ if ((sendlen=ReadCOM(1,readbuffer)) == 1) {\r
+ return byte;\r
+ }\r
+ }\r
+ } else {\r
+ sendlen=0;\r
+ sendpacket[sendlen++]=COM_RBYTE;\r
+ sendpacket[sendlen++]=0x00;\r
+ sendpacket[sendlen++]=0x01;\r
+ if (WriteCOM(sendlen,sendpacket)) {\r
+ if ((sendlen=ReadCOM(1,readbuffer)) == 1) {\r
+ return readbuffer[0];\r
+ }\r
+ }\r
+ \r
+ }\r
+\r
+ return 0; \r
+}\r
+uint8_t owARDUINOInterface::sendrecivBit(uint8_t bit) {\r
+ return 0;\r
+}\r
+\r
+int owARDUINOInterface::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {\r
+ int i=0;\r
+ data->resize(scount);\r
+ uint8_t readbuffer[128],sendpacket[128+3];\r
+ uint8_t sendlen=0;\r
+ sendpacket[sendlen++]=COM_BLOCK;\r
+ sendpacket[sendlen++]=scount;\r
+ sendpacket[sendlen++]=rcount;\r
+ for(uint8_t v:*data) {\r
+ sendpacket[sendlen++]=v;\r
+ (*data)[i]=v;i++;\r
+ }\r
+\r
+ if (WriteCOM(sendlen,sendpacket)) {\r
+ if ((sendlen=ReadCOM(rcount,readbuffer)) == rcount) {\r
+ for(i=0;i<rcount;i++) {\r
+ data->push_back(readbuffer[i]);\r
+ }\r
+ } else {\r
+ for (i = 0; i<rcount; i++) \r
+ data->push_back(0xFF);\r
+ }\r
+ }\r
+ return 0;\r
+}\r
+ \r
class owARDUINOInterface:public owInterface{
protected:
+#ifdef LINUX
int fd;
+#endif
+#ifdef WIN
+ HANDLE fd;
+#endif
int com_init;
public:
owARDUINOInterface():owInterface() {
uint8_t UMode; // current DS2480B command or data mode state
uint8_t USpeed; // current DS2480B 1-Wire Net communication speed
uint8_t UVersion; // current DS2480B version
+#ifdef LINUX
struct termios origterm;
-
-
+#endif
+#ifdef LINUX
int OpenCOM(uint8_t comnr);
+#endif
+#ifdef WIN
+ HANDLE OpenCOM(uint8_t comnr);
+#endif
+
void CloseCOM();
void FlushCOM();
int WriteCOM(int outlen, uint8_t *outbuf);
int ReadCOM(int inlen, uint8_t *inbuf);
- void BreakCOM();
- void SetBaudCOM(uint8_t new_baud);
+// void BreakCOM();
+
};
#include "owInterface.h"
+#ifdef LINUX
#include <unistd.h>
-
+#endif
+#ifdef WIN
+void usleep(int waitTime) {\r
+ __int64 time1 = 0, time2 = 0, freq = 0;\r
+\r
+ QueryPerformanceCounter((LARGE_INTEGER *)&time1);\r
+ QueryPerformanceFrequency((LARGE_INTEGER *)&freq);\r
+\r
+ do {\r
+ QueryPerformanceCounter((LARGE_INTEGER *)&time2);\r
+ } while ((time2 - time1) < waitTime);\r
+}
+#endif
owDevice::owDevice(owInterface *owi_,snum_t num) {
snum=num;
owi=owi_;
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the
-// distribution.
-// * All advertising materials mentioning features or use of this
-// software must display the following acknowledgement: This product
-// includes software developed by tm3d.de and its contributors.
-// * Neither the name of tm3d.de nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#include "owInterface.h"
-#include <unistd.h>
-#include <math.h>
-#include "hexfile.h"
-
-static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
-static unsigned char owi_dscrc_table[] = {
- 0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
- 157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220,
- 35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98,
- 190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
- 70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7,
- 219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154,
- 101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36,
- 248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185,
- 140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
- 17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
- 175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
- 50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
- 202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139,
- 87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
- 233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
- 116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};
-
-
-uint8_t owInterface::docrc8(uint8_t value) {
- // See Application Note 27
-
- // TEST BUILD
- crc8 = owi_dscrc_table[crc8 ^ value];
- return crc8;
-}
-
-uint16_t owInterface::docrc16(uint16_t cdata) {
- cdata = (cdata ^ (crc16 & 0xff)) & 0xff;
- crc16 >>= 8;
-
- if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])
- crc16 ^= 0xc001;
-
- cdata <<= 6;
- crc16 ^= cdata;
- cdata <<= 1;
- crc16 ^= cdata;
-
- return crc16;
-
-
-}
-
-uint8_t owInterface::calcCRC8(std::vector<uint8_t> data) {
- crc8 = 0;
- for(uint8_t v: data)
- docrc8(v);
- return crc8; //0 bei erfolg oder crc wenn crc nicht babei
-}
-
-uint16_t owInterface::calcCRC16(std::vector<uint8_t> data) {
- crc16=0;
- for(uint8_t v:data) {
- docrc16(v);
- }
- return crc16;
-}
-
-int owInterface::testCRC16(std::vector<uint8_t> data) {
- return calcCRC16(data)==0xB001;
-}
-
-void owInterface::resetFlasher() { // go back from Bootloader
- std::vector<uint8_t> data;
- data.push_back(0x89);
- Wait_Free();
- snum_t snum;
- snum.num=0xfa55aa55aa55aaa3;
- MatchRom(snum);
- if (log->last()==OWLOG_ERROR) {Free(); return;}
- Communicate(&data, 1, 0);
-
- Free();
- if (log->last()==OWLOG_ERROR) return;
- usleep(50);
-}
-
-void owInterface::resetID() {
- std::vector<uint8_t> data;
- data.push_back(0x8B);
- Wait_Free();
- snum_t snum;
- snum.num=0xfa55aa55aa55aaa3;
- MatchRom(snum);
- if (log->last()==OWLOG_ERROR) {Free(); return;}
- Communicate(&data, 1, 0);
- Free();
-}
-
-int owInterface::programmPage(int pagenr, std::vector<uint8_t> page, int pagesize) {
- snum_t snum;
- snum.num=0xfa55aa55aa55aaa3;
-// printf("programm page %i",pagenr);
-
-
- int diff = pagesize - page.size();
- if (diff>0) {
- for (int i = 0; i < (diff); i++) page.push_back(0xFF);
- }
- std::vector<uint8_t> cl;
- std::vector<uint8_t> clb; //backup
- cl.push_back(0x0F); //code for Flashing
- cl.push_back((pagenr*pagesize) & 0xFF); //adress in byte
- cl.push_back((pagenr*pagesize) >> 8);
- cl.insert(cl.end(),page.begin(),page.end()); //page
- clb=cl; //make backup
- Wait_Free();
- MatchRom(snum);
- if (log->last()==OWLOG_ERROR) {Free();return -3;}
- Communicate(&cl, 3+pagesize, 0); //send (resive page)
- Free();
- if (log->last()==OWLOG_ERROR) return -3;
- int err=0;
- for(int k=0;k<maxrepeat;k++) { //repeat for readback error
- cl.clear();
- cl.push_back(0xAA); //code for readback scratchpad
- Wait_Free();
- MatchRom(snum);
- if (log->last()==OWLOG_ERROR) {Free();return -3;}
- Communicate(&cl, 1, 2+pagesize); // read back scratchpad
- Free();
- if (log->last()==OWLOG_ERROR) return -3;
- err=0;
- for (int i = 0; i < pagesize+2; i++) {
- if (clb[i + 1] != cl[i + 1]) { //test
- usleep(50000);
- err=1;
- break;
- }
- }
- if (err==0) break;
- }
- if (err==1) {
- usleep(50000);
- return -1; //error in scratchpad
- }
- cl.clear();
- cl.push_back(0x55);//Programm
- Wait_Free();
- MatchRom(snum);
- if (log->last()==OWLOG_ERROR) {Free();return -3;}
- Communicate(&cl, 1, 0);
- Free();
- if (log->last()==OWLOG_ERROR) return -3;
- usleep(50000);
- cl.clear();
- cl.push_back(0xB8);//recal programm memory to scratchpad
- cl.push_back((pagenr*pagesize) & 0xFF);
- cl.push_back((pagenr*pagesize) >> 8);
- Wait_Free();
- MatchRom(snum);
- if (log->last()==OWLOG_ERROR) {Free();return -3;}
- Communicate(&cl, 3, 0); //Copy programm memory to scratch
- Free();
- if (log->last()==OWLOG_ERROR) return -3;
- usleep(50000);
-
- for(int k=0;k<maxrepeat;k++) { //repead for reading scratch error
- cl.clear();
- cl.push_back(0xAA);
- Wait_Free();
- MatchRom(snum);
- if (log->last()==OWLOG_ERROR) {Free();return -3;}
- Communicate(&cl, 1, 2 + pagesize); //Reread scratch
- Free();
- if (log->last()==OWLOG_ERROR) return -3;
- err=0;
- for (int i = 0; i < pagesize + 2; i++) {
- if (cl[i + 1] != clb[i + 1]) {
- usleep(50000);
- err=1;
- break;
- }
- }
- if (err==0) break;
- }
- if (err==1) {
- usleep(50000);
- return -2;
- }
-
-
- return 0;
-}
-
-
-int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int progress) {
- log->set(OWLOG_INFO,"Open Hex-File: %s",filename.c_str());
- hexFile *hf=new hexFile(filename);
- if (hf->lastError==1) {log->set(OWLOG_ERROR,"CRC Error in HEX-File %s",filename.c_str());return -1;}
- if (hf->lastError==2) {log->set(OWLOG_ERROR,"Error interpreting HEX-File %s",filename.c_str());return -2;}
- if (hf->lastError==3) {log->set(OWLOG_ERROR,"File could not be opened: %s",filename.c_str());return -3;}
- unsigned int blcount=hf->getBlockCount(64);
- if (blcount>118) {
- log->set(OWLOG_ERROR,"Code to big, max 7552 Byte allowed (118 Pages). Code has %i pages!",blcount);
- return -5;
- }
- log->set(OWLOG_INFO,"Try to start Bootloader on device %llX",dev.num);
- int r=maxrepeat+1;
- int found;
- do {
- log->clear();
- std::vector<uint8_t> data;
- MatchRom(dev);
- data.push_back(0x88);
- Communicate(&data, 1, 0);
- MatchRom(dev);
- Communicate(&data, 1, 0);
- MatchRom(dev);
- Communicate(&data, 1, 0);
- sleep(3);
- log->set(OWLOG_INFO,"Search for Bootloader...");
- log->setLogLevel(OWLOG_WARNING);
- Find();
- log->setLogLevel(OWLOG_INFO);
- found=0;
- for (owDevice* dev :devices) {
- if (dev->getNum().num==0xfa55aa55aa55aaa3) {
- found=1;
- break;
- }
- }
- if (found==0) log->set(OWLOG_WARNING,"Bootloader not found");
- r--;
- } while ((found==0)&&(r>0));
- if (r==0) {
- log->set(OWLOG_ERROR,"Can not start Bootloader on this device %llX",dev.num);
- return -4;
- }
- log->set(OWLOG_INFO,"Start Programm %i Pages",blcount);
- int rp=0;
- int er=0;
- unsigned int i =0;
- for ( i= 0; i < blcount; i++) {
- std::vector<uint8_t> blk = hf->getBlock(i*64, 64);
- int errc = maxrepeat*5;
- while (errc != 0) {
- log->clear();
- if (programmPage(i, blk, 64) >= 0) {
- if (progress) {printf("#");fflush(stdout);}
- break;
- }
-
- errc -= 1;
- rp++;
- if (progress) {printf("\033[1;31m#\033[0m");fflush(stdout);} //printf("\033[1;33m%s\033[0m\n",s);
-
- }
- if (errc == 0) { er++; break; }
- }
- if (progress) printf("\n");
- if (er != 0) {
- log->set(OWLOG_ERROR,"ERROR Writing Program Memory!!!");
- if (i==0) {
- log->set(OWLOG_ERROR,"If Fuse SELFPRGEN enabled?");
- } else
- log->set(OWLOG_ERROR,"Maybe 1-Wire Connection is verry bad!");
- } else {
- if (resetid) {
- log->set(OWLOG_INFO,"Set 1-Wire ID to ID in hexfile...",blcount);
- resetID();
- sleep(3);
- resetID();
- sleep(3);
- }
- }
-
- log->set(OWLOG_INFO,"Back from bootloader to normal device...",blcount);
-
-
- resetFlasher();
- sleep(1);
- resetFlasher();
- sleep(3);
-
- Find();
-
- return 1;
-
-}
-
-
-int owInterface::owSearch() {
- int id_bit_number;
- int last_zero, rom_byte_number, search_result;
- int id_bit, cmp_id_bit;
- unsigned char rom_byte_mask, search_direction;
-
- // initialize for search
- id_bit_number = 1;
- last_zero = 0;
- rom_byte_number = 0;
- rom_byte_mask = 1;
- search_result = 0;
- crc8 = 0;
-
- // if the last call was not the last one
- if (!LastDeviceFlag) {
- // 1-Wire reset
- Wait_Free();
- if (!Reset()) {
- // reset the search
- LastDiscrepancy = 0;
- LastDeviceFlag = FALSE;
- LastFamilyDiscrepancy = 0;
- Free();
- return FALSE;
- }
- if (log->last()==OWLOG_ERROR) return -3;
- // issue the search command
- sendrecivByte(0xF0);
- if (log->last()==OWLOG_ERROR) return -3;
-
- // loop to do the search
- do {
- // read a bit and its complement
- id_bit = sendrecivBit(1);
- cmp_id_bit = sendrecivBit(1);
- // check for no devices on 1-wire
- if ((id_bit == 1) && (cmp_id_bit == 1))
- break;
- else {
- // all devices coupled have 0 or 1
- if (id_bit != cmp_id_bit)
- search_direction = id_bit; // bit write value for search
- else {
- // if this discrepancy if before the Last Discrepancy
- // on a previous next then pick the same as last time
- if (id_bit_number < LastDiscrepancy)
- search_direction = ((ROM_NO[rom_byte_number] & rom_byte_mask) > 0);
- else
- // if equal to last pick 1, if not then pick 0
- search_direction = (id_bit_number == LastDiscrepancy);
-
- // if 0 was picked then record its position in LastZero
- if (search_direction == 0) {
- last_zero = id_bit_number;
- // check for Last discrepancy in family
- if (last_zero < 9)
- LastFamilyDiscrepancy = last_zero;
- }
- }
- // set or clear the bit in the ROM byte rom_byte_number
- // with mask rom_byte_mask
- if (search_direction == 1)
- ROM_NO[rom_byte_number] |= rom_byte_mask;
- else
- ROM_NO[rom_byte_number] &= ~rom_byte_mask;
- // serial number search direction write bit
- sendrecivBit(search_direction);
- //usleep(50);
-
- // increment the byte counter id_bit_number
- // and shift the mask rom_byte_mask
- id_bit_number++;
- rom_byte_mask <<= 1;
-
- // if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask
- if (rom_byte_mask == 0) {
- docrc8(ROM_NO[rom_byte_number]); // accumulate the CRC
- rom_byte_number++;
- rom_byte_mask = 1;
- }
- }
- }
- while(rom_byte_number < 8); // loop until through all ROM bytes 0-7
- // if the search was successful then
- if (!((id_bit_number < 65) || (crc8 != 0))) {
- // search successful so set LastDiscrepancy,LastDeviceFlag,search_result
- LastDiscrepancy = last_zero;
- // check for last device
- if (LastDiscrepancy == 0)
- LastDeviceFlag = TRUE;
- search_result = TRUE;
- } else {
- log->set(OWLOG_WARNING,"CRC Error on Search Rom");
- }
- }
-
- // if no device found then reset counters so next 'search' will be like a first
- if (!search_result || !ROM_NO[0]) {
- LastDiscrepancy = 0;
- LastDeviceFlag = FALSE;
- LastFamilyDiscrepancy = 0;
- search_result = FALSE;
- }
- Free();
- return search_result;
-
-
-}
-void owInterface::Clean() {
- for (owDevice* dev :devices) {
- delete dev;
- }
- devices.clear();
- device_nums.clear();
- devices_changed=1;
-}
-
-int owInterface::Find() {
- int rslt,i,cnt=0;
- std::vector<snum_t> found;
- for (int k=0;k<maxrepeat;k++) {
- cnt=0;
- log->clear();
- found.clear();
- rslt = owFirst();
- if (log->last()>=OWLOG_WARNING) continue;
- while (rslt){
- snum_t snum;
- // print device found
- for (i = 7; i >= 0; i--)
- snum.byte[i]=ROM_NO[i];
- //printf("%02X", ROM_NO[i]);
- //printf(" %d\n",++cnt);
- found.push_back(snum);
- cnt++;
- log->clear();
- rslt = owNext();
- if (log->last()>=OWLOG_WARNING) {rslt=-1;break;}
- }
- if (rslt==0) break;
-
- }
- if (log->last()>=OWLOG_WARNING) {
- log->set(OWLOG_ERROR,"To much Errors while search rom");
- //Alles so lassen wie es ist?
- return 0;
- }
- for(snum_t snum:found) {
- int snum_found=0;
- //Device schon forhanden?
- for(snum_t d : device_nums) {
- if (snum.num==d.num) {snum_found=1;break;}
- }
- //nein, dann anlegen.
- if (!snum_found) {
- log->set(OWLOG_INFO,"new dev %llx\n",snum.num);
- devices_changed=1;
- device_nums.push_back(snum);
- owDevice *d=NULL;
-
- switch (snum.byte[0]) {
- case 0x28:d=new owDeviceDS18B20(this,snum);break;
- case 0x26:d=new owDeviceDS2438(this,snum);break;
- case 0x20:d=new owDeviceDS2450(this,snum);break;
- case 0x1D:d=new owDeviceDS2423(this,snum);break;
- default:d=new owDevice(this,snum);
- }
- devices.push_back(d);
- if (d!=NULL) {d->readConfig();}
- }
- }
- //Pruefe nach nicht mehr vorhandenen devices
- int dpos=0;
- for(snum_t d:device_nums) {
- int snum_found=0;
- for(snum_t fd:found) {
- if (fd.num==d.num) {snum_found=1;break;}
- }
- //Device nicht gefunden, vieleicht nur Fehler?
- if (!snum_found) {
- devices[dpos]->lastfound++;
- log->set(OWLOG_INFO,"%llx not found %i times \n",device_nums[dpos].num,devices[dpos]->lastfound);
-
- if (devices[dpos]->lastfound>2) {
-
- log->set(OWLOG_INFO,"del device %llx (pos %i)\n",device_nums[dpos].num,dpos);
-
- devices_changed=1;
- delete devices[dpos];
- device_nums.erase(device_nums.begin()+dpos);
- devices.erase(devices.begin()+dpos);
- //printf("new length %i\n",devices.size());
- dpos--;
- }
-
- } else {
- devices[dpos]->lastfound=0;
- }
- dpos++;
-
- }
- return cnt;
-}
-
-int owInterface::MatchRom(snum_t snum) {
- Reset();
- sendrecivByte(0x55);
- usleep(20);
- for(int i=0;i<8;i++) {
- sendrecivByte(snum.byte[i]);
- usleep(20);
- }
- if (log->last()>OWLOG_WARNING) return 0;
- return 1;
-}
-int owInterface::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {
- int i=0;
- data->resize(scount);
- for(uint8_t v:*data) {
- (*data)[i]=sendrecivByte(v);i++;
- usleep(20);
- }
- for(i=0;i<rcount;i++) {
- data->push_back(sendrecivByte(0xFF));
- usleep(20);
-
- }
- return 0;
-}
-
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+// * Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+// * Redistributions in binary form must reproduce the above copyright\r
+// notice, this list of conditions and the following disclaimer in the\r
+// documentation and/or other materials provided with the\r
+// distribution.\r
+// * All advertising materials mentioning features or use of this\r
+// software must display the following acknowledgement: This product\r
+// includes software developed by tm3d.de and its contributors.\r
+// * Neither the name of tm3d.de nor the names of its contributors may\r
+// be used to endorse or promote products derived from this software\r
+// without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+\r
+#include "owInterface.h"\r
+#ifdef LINUX\r
+#include <unistd.h>\r
+#endif\r
+#include <math.h>\r
+#include "hexfile.h"\r
+\r
+\r
+#ifdef WIN\r
+void usleep(__int64 usec)\r
+{\r
+ HANDLE timer;\r
+ LARGE_INTEGER ft;\r
+\r
+ ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time\r
+\r
+ timer = CreateWaitableTimer(NULL, TRUE, NULL);\r
+ SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);\r
+ WaitForSingleObject(timer, INFINITE);\r
+ CloseHandle(timer);\r
+}\r
+#endif\r
+\r
+\r
+static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };\r
+static unsigned char owi_dscrc_table[] = {\r
+ 0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,\r
+ 157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220,\r
+ 35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98,\r
+ 190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,\r
+ 70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7,\r
+ 219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154,\r
+ 101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36,\r
+ 248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185,\r
+ 140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,\r
+ 17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,\r
+ 175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,\r
+ 50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,\r
+ 202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139,\r
+ 87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,\r
+ 233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,\r
+ 116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};\r
+\r
+ \r
+uint8_t owInterface::docrc8(uint8_t value) {\r
+ // See Application Note 27\r
+ \r
+ // TEST BUILD\r
+ crc8 = owi_dscrc_table[crc8 ^ value];\r
+ return crc8;\r
+}\r
+ \r
+uint16_t owInterface::docrc16(uint16_t cdata) {\r
+ cdata = (cdata ^ (crc16 & 0xff)) & 0xff;\r
+ crc16 >>= 8;\r
+\r
+ if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])\r
+ crc16 ^= 0xc001;\r
+\r
+ cdata <<= 6;\r
+ crc16 ^= cdata;\r
+ cdata <<= 1;\r
+ crc16 ^= cdata;\r
+\r
+ return crc16;\r
+ \r
+ \r
+}\r
+\r
+uint8_t owInterface::calcCRC8(std::vector<uint8_t> data) {\r
+ crc8 = 0;\r
+ for(uint8_t v: data) \r
+ docrc8(v);\r
+ return crc8; //0 bei erfolg oder crc wenn crc nicht babei\r
+}\r
+\r
+uint16_t owInterface::calcCRC16(std::vector<uint8_t> data) {\r
+ crc16=0;\r
+ for(uint8_t v:data) {\r
+ docrc16(v);\r
+ }\r
+ return crc16;\r
+}\r
+\r
+int owInterface::testCRC16(std::vector<uint8_t> data) {\r
+ return calcCRC16(data)==0xB001;\r
+}\r
+ \r
+void owInterface::resetFlasher() { // go back from Bootloader\r
+ std::vector<uint8_t> data;\r
+ data.push_back(0x89);\r
+ Wait_Free();\r
+ snum_t snum;\r
+ snum.num=0xfa55aa55aa55aaa3;\r
+ MatchRom(snum);\r
+ if (log->last()==OWLOG_ERROR) {Free(); return;}\r
+ Communicate(&data, 1, 0);\r
+ \r
+ Free();\r
+ if (log->last()==OWLOG_ERROR) return;\r
+ usleep(50); \r
+}\r
+\r
+void owInterface::resetID() {\r
+ std::vector<uint8_t> data;\r
+ data.push_back(0x8B);\r
+ Wait_Free();\r
+ snum_t snum;\r
+ snum.num=0xfa55aa55aa55aaa3;\r
+ MatchRom(snum);\r
+ if (log->last()==OWLOG_ERROR) {Free(); return;}\r
+ Communicate(&data, 1, 0);\r
+ Free();\r
+}\r
+\r
+int owInterface::programmPage(int pagenr, std::vector<uint8_t> page, int pagesize) {\r
+ snum_t snum;\r
+ snum.num=0xfa55aa55aa55aaa3;\r
+// printf("programm page %i",pagenr);\r
+ \r
+ \r
+ int diff = pagesize - page.size();\r
+ if (diff>0) {\r
+ for (int i = 0; i < (diff); i++) page.push_back(0xFF);\r
+ }\r
+ std::vector<uint8_t> cl;\r
+ std::vector<uint8_t> clb; //backup \r
+ cl.push_back(0x0F); //code for Flashing\r
+ cl.push_back((pagenr*pagesize) & 0xFF); //adress in byte\r
+ cl.push_back((pagenr*pagesize) >> 8);\r
+ cl.insert(cl.end(),page.begin(),page.end()); //page\r
+ clb=cl; //make backup\r
+ Wait_Free();\r
+ MatchRom(snum); \r
+ if (log->last()==OWLOG_ERROR) {Free();return -3;}\r
+ Communicate(&cl, 3+pagesize, 0); //send (resive page)\r
+ Free();\r
+ if (log->last()==OWLOG_ERROR) return -3;\r
+ int err=0;\r
+ for(int k=0;k<maxrepeat;k++) { //repeat for readback error \r
+ cl.clear();\r
+ cl.push_back(0xAA); //code for readback scratchpad\r
+ Wait_Free();\r
+ MatchRom(snum);\r
+ if (log->last()==OWLOG_ERROR) {Free();return -3;}\r
+ Communicate(&cl, 1, 2+pagesize); // read back scratchpad\r
+ Free();\r
+ if (log->last()==OWLOG_ERROR) return -3;\r
+ err=0;\r
+ for (int i = 0; i < pagesize+2; i++) {\r
+ if (clb[i + 1] != cl[i + 1]) { //test\r
+ usleep(50000);\r
+ err=1;\r
+ break;\r
+ }\r
+ }\r
+ if (err==0) break;\r
+ }\r
+ if (err==1) {\r
+ usleep(50000);\r
+ return -1; //error in scratchpad\r
+ }\r
+ cl.clear();\r
+ cl.push_back(0x55);//Programm\r
+ Wait_Free();\r
+ MatchRom(snum);\r
+ if (log->last()==OWLOG_ERROR) {Free();return -3;}\r
+ Communicate(&cl, 1, 0);\r
+ Free();\r
+ if (log->last()==OWLOG_ERROR) return -3;\r
+ usleep(50000);\r
+ cl.clear();\r
+ cl.push_back(0xB8);//recal programm memory to scratchpad\r
+ cl.push_back((pagenr*pagesize) & 0xFF);\r
+ cl.push_back((pagenr*pagesize) >> 8);\r
+ Wait_Free();\r
+ MatchRom(snum);\r
+ if (log->last()==OWLOG_ERROR) {Free();return -3;}\r
+ Communicate(&cl, 3, 0); //Copy programm memory to scratch\r
+ Free();\r
+ if (log->last()==OWLOG_ERROR) return -3;\r
+ usleep(50000);\r
+ \r
+ for(int k=0;k<maxrepeat;k++) { //repead for reading scratch error\r
+ cl.clear();\r
+ cl.push_back(0xAA);\r
+ Wait_Free();\r
+ MatchRom(snum);\r
+ if (log->last()==OWLOG_ERROR) {Free();return -3;}\r
+ Communicate(&cl, 1, 2 + pagesize); //Reread scratch\r
+ Free();\r
+ if (log->last()==OWLOG_ERROR) return -3;\r
+ err=0;\r
+ for (int i = 0; i < pagesize + 2; i++) {\r
+ if (cl[i + 1] != clb[i + 1]) {\r
+ usleep(50000);\r
+ err=1;\r
+ break;\r
+ }\r
+ }\r
+ if (err==0) break;\r
+ }\r
+ if (err==1) {\r
+ usleep(50000);\r
+ return -2;\r
+ }\r
+\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int progress) {\r
+ log->set(OWLOG_INFO,"Open Hex-File: %s",filename.c_str());\r
+ hexFile *hf=new hexFile(filename);\r
+ if (hf->lastError==1) {log->set(OWLOG_ERROR,"CRC Error in HEX-File %s",filename.c_str());return -1;}\r
+ if (hf->lastError==2) {log->set(OWLOG_ERROR,"Error interpreting HEX-File %s",filename.c_str());return -2;}\r
+ if (hf->lastError==3) {log->set(OWLOG_ERROR,"File could not be opened: %s",filename.c_str());return -3;}\r
+ unsigned int blcount=hf->getBlockCount(64);\r
+ if (blcount>118) {\r
+ log->set(OWLOG_ERROR,"Code to big, max 7552 Byte allowed (118 Pages). Code has %i pages!",blcount);\r
+ return -5;\r
+ }\r
+ log->set(OWLOG_INFO,"Try to start Bootloader on device %llX",dev.num);\r
+ int r=maxrepeat+1;\r
+ int found;\r
+ do {\r
+ log->clear();\r
+ std::vector<uint8_t> data;\r
+ MatchRom(dev);\r
+ data.push_back(0x88);\r
+ Communicate(&data, 1, 0);\r
+ MatchRom(dev);\r
+ Communicate(&data, 1, 0);\r
+ MatchRom(dev);\r
+ Communicate(&data, 1, 0);\r
+#ifdef LINUX\r
+ sleep(3);\r
+#endif\r
+#ifdef WIN\r
+ Sleep(3000);\r
+#endif\r
+ log->set(OWLOG_INFO,"Search for Bootloader...");\r
+ log->setLogLevel(OWLOG_WARNING);\r
+ Find();\r
+ log->setLogLevel(OWLOG_INFO);\r
+ found=0;\r
+ for (owDevice* dev :devices) {\r
+ if (dev->getNum().num==0xfa55aa55aa55aaa3) {\r
+ found=1;\r
+ break;\r
+ } \r
+ }\r
+ if (found==0) log->set(OWLOG_WARNING,"Bootloader not found");\r
+ r--;\r
+ } while ((found==0)&&(r>0));\r
+ if (r==0) {\r
+ log->set(OWLOG_ERROR,"Can not start Bootloader on this device %llX",dev.num);\r
+ return -4;\r
+ }\r
+ log->set(OWLOG_INFO,"Start Programm %i Pages",blcount);\r
+ int rp=0;\r
+ int er=0;\r
+ unsigned int i =0;\r
+ for ( i= 0; i < blcount; i++) {\r
+ std::vector<uint8_t> blk = hf->getBlock(i*64, 64);\r
+ int errc = maxrepeat*5;\r
+ while (errc != 0) {\r
+ log->clear();\r
+ if (programmPage(i, blk, 64) >= 0) {\r
+ if (progress) {printf("#");fflush(stdout);} \r
+ break;\r
+ }\r
+ \r
+ errc -= 1;\r
+ rp++;\r
+ if (progress) {printf("\033[1;31m#\033[0m");fflush(stdout);} //printf("\033[1;33m%s\033[0m\n",s);\r
+ \r
+ }\r
+ if (errc == 0) { er++; break; }\r
+ }\r
+ if (progress) printf("\n");\r
+ if (er != 0) {\r
+ log->set(OWLOG_ERROR,"ERROR Writing Program Memory!!!");\r
+ if (i==0) {\r
+ log->set(OWLOG_ERROR,"If Fuse SELFPRGEN enabled?");\r
+ } else\r
+ log->set(OWLOG_ERROR,"Maybe 1-Wire Connection is verry bad!");\r
+ } else {\r
+ if (resetid) {\r
+ log->set(OWLOG_INFO,"Set 1-Wire ID to ID in hexfile...",blcount); \r
+ resetID();\r
+#ifdef LINUX\r
+ sleep(3);\r
+#endif\r
+#ifdef WIN\r
+ Sleep(3000);\r
+#endif\r
+ resetID(); \r
+#ifdef LINUX\r
+ sleep(3);\r
+#endif\r
+#ifdef WIN\r
+ Sleep(3000);\r
+#endif\r
+ }\r
+ } \r
+ \r
+ log->set(OWLOG_INFO,"Back from bootloader to normal device...",blcount); \r
+ \r
+ \r
+ resetFlasher();\r
+#ifdef LINUX\r
+ sleep(1); \r
+#endif\r
+#ifdef WIN\r
+ Sleep(1000);\r
+#endif\r
+ resetFlasher();\r
+#ifdef LINUX\r
+ sleep(3);\r
+#endif\r
+#ifdef WIN\r
+ Sleep(3000);\r
+#endif\r
+\r
+ Find();\r
+ \r
+ return 1;\r
+ \r
+}\r
+\r
+\r
+int owInterface::owSearch() {\r
+ int id_bit_number;\r
+ int last_zero, rom_byte_number, search_result;\r
+ int id_bit, cmp_id_bit;\r
+ unsigned char rom_byte_mask, search_direction;\r
+\r
+ // initialize for search\r
+ id_bit_number = 1;\r
+ last_zero = 0;\r
+ rom_byte_number = 0;\r
+ rom_byte_mask = 1;\r
+ search_result = 0;\r
+ crc8 = 0;\r
+\r
+ // if the last call was not the last one\r
+ if (!LastDeviceFlag) {\r
+ // 1-Wire reset\r
+ Wait_Free();\r
+ if (!Reset()) {\r
+ // reset the search\r
+ LastDiscrepancy = 0;\r
+ LastDeviceFlag = FALSE;\r
+ LastFamilyDiscrepancy = 0;\r
+ Free();\r
+ return FALSE;\r
+ }\r
+ if (log->last()==OWLOG_ERROR) return -3;\r
+ // issue the search command \r
+ sendrecivByte(0xF0); \r
+ if (log->last()==OWLOG_ERROR) return -3;\r
+\r
+ // loop to do the search\r
+ do {\r
+ // read a bit and its complement\r
+ id_bit = sendrecivBit(1);\r
+ cmp_id_bit = sendrecivBit(1);\r
+ // check for no devices on 1-wire\r
+ if ((id_bit == 1) && (cmp_id_bit == 1))\r
+ break;\r
+ else {\r
+ // all devices coupled have 0 or 1\r
+ if (id_bit != cmp_id_bit)\r
+ search_direction = id_bit; // bit write value for search\r
+ else {\r
+ // if this discrepancy if before the Last Discrepancy\r
+ // on a previous next then pick the same as last time\r
+ if (id_bit_number < LastDiscrepancy)\r
+ search_direction = ((ROM_NO[rom_byte_number] & rom_byte_mask) > 0);\r
+ else\r
+ // if equal to last pick 1, if not then pick 0\r
+ search_direction = (id_bit_number == LastDiscrepancy);\r
+\r
+ // if 0 was picked then record its position in LastZero\r
+ if (search_direction == 0) {\r
+ last_zero = id_bit_number;\r
+ // check for Last discrepancy in family\r
+ if (last_zero < 9)\r
+ LastFamilyDiscrepancy = last_zero;\r
+ }\r
+ }\r
+ // set or clear the bit in the ROM byte rom_byte_number\r
+ // with mask rom_byte_mask\r
+ if (search_direction == 1)\r
+ ROM_NO[rom_byte_number] |= rom_byte_mask;\r
+ else\r
+ ROM_NO[rom_byte_number] &= ~rom_byte_mask;\r
+ // serial number search direction write bit\r
+ sendrecivBit(search_direction);\r
+ //usleep(50);\r
+\r
+ // increment the byte counter id_bit_number\r
+ // and shift the mask rom_byte_mask\r
+ id_bit_number++;\r
+ rom_byte_mask <<= 1;\r
+\r
+ // if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask\r
+ if (rom_byte_mask == 0) {\r
+ docrc8(ROM_NO[rom_byte_number]); // accumulate the CRC\r
+ rom_byte_number++;\r
+ rom_byte_mask = 1;\r
+ }\r
+ }\r
+ }\r
+ while(rom_byte_number < 8); // loop until through all ROM bytes 0-7\r
+ // if the search was successful then\r
+ if (!((id_bit_number < 65) || (crc8 != 0))) {\r
+ // search successful so set LastDiscrepancy,LastDeviceFlag,search_result\r
+ LastDiscrepancy = last_zero;\r
+ // check for last device\r
+ if (LastDiscrepancy == 0)\r
+ LastDeviceFlag = TRUE;\r
+ search_result = TRUE;\r
+ } else {\r
+ log->set(OWLOG_WARNING,"CRC Error on Search Rom");\r
+ }\r
+ }\r
+\r
+ // if no device found then reset counters so next 'search' will be like a first\r
+ if (!search_result || !ROM_NO[0]) {\r
+ LastDiscrepancy = 0;\r
+ LastDeviceFlag = FALSE;\r
+ LastFamilyDiscrepancy = 0;\r
+ search_result = FALSE;\r
+ }\r
+ Free();\r
+ return search_result;\r
+ \r
+\r
+}\r
+void owInterface::Clean() {\r
+ for (owDevice* dev :devices) {\r
+ delete dev;\r
+ }\r
+ devices.clear();\r
+ device_nums.clear();\r
+ devices_changed=1;\r
+}\r
+\r
+int owInterface::Find() {\r
+ int rslt,i,cnt=0;\r
+ std::vector<snum_t> found;\r
+ for (int k=0;k<maxrepeat;k++) {\r
+ cnt=0;\r
+ log->clear();\r
+ found.clear();\r
+ rslt = owFirst();\r
+ if (log->last()>=OWLOG_WARNING) continue;\r
+ while (rslt){\r
+ snum_t snum;\r
+ // print device found\r
+ for (i = 7; i >= 0; i--)\r
+ snum.byte[i]=ROM_NO[i];\r
+ //printf("%02X", ROM_NO[i]);\r
+ //printf(" %d\n",++cnt);\r
+ found.push_back(snum);\r
+ cnt++;\r
+ log->clear();\r
+ rslt = owNext();\r
+ if (log->last()>=OWLOG_WARNING) {rslt=-1;break;}\r
+ }\r
+ if (rslt==0) break;\r
+ \r
+ }\r
+ if (log->last()>=OWLOG_WARNING) { \r
+ log->set(OWLOG_ERROR,"To much Errors while search rom"); \r
+ //Alles so lassen wie es ist? \r
+ return 0;\r
+ }\r
+ for(snum_t snum:found) {\r
+ int snum_found=0;\r
+ //Device schon forhanden?\r
+ for(snum_t d : device_nums) {\r
+ if (snum.num==d.num) {snum_found=1;break;}\r
+ }\r
+ //nein, dann anlegen.\r
+ if (!snum_found) {\r
+ log->set(OWLOG_INFO,"new dev %llx\n",snum.num);\r
+ devices_changed=1;\r
+ device_nums.push_back(snum);\r
+ owDevice *d=NULL;\r
+ \r
+ switch (snum.byte[0]) {\r
+ case 0x28:d=new owDeviceDS18B20(this,snum);break;\r
+ case 0x26:d=new owDeviceDS2438(this,snum);break;\r
+ case 0x20:d=new owDeviceDS2450(this,snum);break;\r
+ case 0x1D:d=new owDeviceDS2423(this,snum);break;\r
+ default:d=new owDevice(this,snum);\r
+ }\r
+ devices.push_back(d);\r
+ if (d!=NULL) {d->readConfig();}\r
+ }\r
+ }\r
+ //Pruefe nach nicht mehr vorhandenen devices\r
+ int dpos=0;\r
+ for(snum_t d:device_nums) {\r
+ int snum_found=0;\r
+ for(snum_t fd:found) {\r
+ if (fd.num==d.num) {snum_found=1;break;}\r
+ }\r
+ //Device nicht gefunden, vieleicht nur Fehler?\r
+ if (!snum_found) {\r
+ devices[dpos]->lastfound++;\r
+ log->set(OWLOG_INFO,"%llx not found %i times \n",device_nums[dpos].num,devices[dpos]->lastfound); \r
+ \r
+ if (devices[dpos]->lastfound>2) {\r
+\r
+ log->set(OWLOG_INFO,"del device %llx (pos %i)\n",device_nums[dpos].num,dpos);\r
+ \r
+ devices_changed=1;\r
+ delete devices[dpos];\r
+ device_nums.erase(device_nums.begin()+dpos);\r
+ devices.erase(devices.begin()+dpos); \r
+ //printf("new length %i\n",devices.size());\r
+ dpos--;\r
+ } \r
+\r
+ } else {\r
+ devices[dpos]->lastfound=0;\r
+ }\r
+ dpos++;\r
+ \r
+ } \r
+ return cnt; \r
+}\r
+\r
+int owInterface::MatchRom(snum_t snum) {\r
+ Reset();\r
+/* sendrecivByte(0x55);\r
+ usleep(20);\r
+ for(int i=0;i<8;i++) {\r
+ sendrecivByte(snum.byte[i]); \r
+ usleep(20);\r
+ }\r
+ if (log->last()>OWLOG_WARNING) return 0;*/\r
+ std::vector<uint8_t> cl;\r
+ cl.push_back(0x55); //code for Flashing\r
+ for (int i = 0; i<8; i++) {\r
+ cl.push_back(snum.byte[i]);\r
+ }\r
+ Communicate(&cl, 9, 0);\r
+\r
+ return 1;\r
+}\r
+int owInterface::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {\r
+ int i=0;\r
+ data->resize(scount);\r
+ for(uint8_t v:*data) {\r
+ (*data)[i]=sendrecivByte(v);i++;\r
+ usleep(20);\r
+ }\r
+ for(i=0;i<rcount;i++) {\r
+ data->push_back(sendrecivByte(0xFF));\r
+ usleep(20);\r
+ \r
+ }\r
+ return 0;\r
+}\r
+\r
#ifndef __OWINTERFACES_H_
#define __OWINTERFACES_H_
+#if defined(WIN) || defined(LINUX)
+#else
+#if defined(_WINDOWS) || defined(__WINDOWS__) || defined(_WIN32) || defined(WIN32)
+#define WIN
+#else
+#define LINUX
+#endif
+#endif
+
+
#include <vector>
#include <stdint.h>
#include <string>
+#ifdef LINUX
#include <termios.h>
+#endif
#include <stdarg.h>
+#ifdef WIN
+#include <Windows.h>
+
+#endif
class owDevice;
class owDeviceConfig;
#if defined(_WINDOWS) || defined(__WINDOWS__) || defined(_WIN32) || defined(WIN32)
#define USE_WINDOWS_TIME 1
#include <windows.h>
- #include "win32/usb.h" // libusb header
+ //#include "win32/usb.h" // libusb header
#else
#define USE_WINDOWS_TIME 0
#include <time.h>
va_list arg;
int done;
va_start (arg, format);
+#ifdef LINUX
done = vsprintf (s, format, arg);
+#endif
+#ifdef WIN
+ done = vsprintf_s(s,300, format, arg);
+#endif
va_end (arg);
logtext=s;
level=llevel;
--- /dev/null
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+// * Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+// * Redistributions in binary form must reproduce the above copyright\r
+// notice, this list of conditions and the following disclaimer in the\r
+// documentation and/or other materials provided with the\r
+// distribution.\r
+// * All advertising materials mentioning features or use of this\r
+// software must display the following acknowledgement: This product\r
+// includes software developed by tm3d.de and its contributors.\r
+// * Neither the name of tm3d.de nor the names of its contributors may\r
+// be used to endorse or promote products derived from this software\r
+// without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#pragma once\r
+\r
+ \r
+#include <ownet.h>\r
+\r
+#include <atlstr.h>\r
+\r
+#include <stdio.h>\r
+#include "owTMEXWIN.h"\r
+\r
+\r
+int owTMEXWIN::InitAdapter(std::string s) {\r
+ // resu = owi.InitAdapter("{1,6}");\r
+\r
+ // int resu = owi.InitAdapter("{4,5}");\r
+ char hs[100];\r
+ sprintf_s(hs, 100, "%s", s.c_str());\r
+ portnum = owAcquireEx(hs);\r
+ if (portnum > -1) {\r
+ owSpeed(portnum, 2);\r
+ return 1;\r
+ }\r
+ return 0; \r
+}\r
+\r
+\r
+int owTMEXWIN::owFirst() {\r
+ uchar SNum[8];\r
+ int res=owFirst_(portnum, TRUE, FALSE);\r
+ if (res) {\r
+ owSerialNum(portnum, &SNum[0], TRUE);\r
+ for (int i = 0; i<8; i++) ROM_NO[i] = SNum[i];\r
+ }\r
+ return res;\r
+\r
+}\r
+int owTMEXWIN::owNext() {\r
+ uchar SNum[8];\r
+ int res = owNext_(portnum, TRUE, FALSE);\r
+ if (res) {\r
+ owSerialNum(portnum, &SNum[0], TRUE);\r
+ for (int i = 0; i<8; i++) ROM_NO[i] = SNum[i];\r
+ }\r
+ return res;\r
+\r
+}\r
+\r
+\r
+void owTMEXWIN::ReleaseAdapter() {\r
+ owRelease(portnum);\r
+}\r
+\r
+\r
+int owTMEXWIN::Reset() {\r
+ return owTouchReset(portnum);\r
+}\r
+\r
+int owTMEXWIN::MatchRom(snum_t snum) {\r
+ owSerialNum(portnum, snum.byte, FALSE);\r
+ return owAccess(portnum);\r
+}\r
+uint8_t owTMEXWIN::sendrecivByte(uint8_t byte) {\r
+ return owTouchByte(portnum, byte);\r
+ \r
+}\r
+uint8_t owTMEXWIN::sendrecivBit(uint8_t bit) {\r
+ return owTouchBit(portnum, bit);\r
+ \r
+}\r
+\r
+int owTMEXWIN::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {\r
+ int i = 0;\r
+ uint8_t buf[400];\r
+ data->resize(scount);\r
+ for (uint8_t v : *data) {\r
+ buf[i++] = v;\r
+ }\r
+ for (int j = 0; j < rcount; j++) {\r
+ buf[i++] = 0xFF;\r
+ }\r
+ int ret = owBlock(portnum, FALSE, buf, scount + rcount);\r
+ if (ret) {\r
+ for (int j = 0; j < rcount; j++) {\r
+ data->push_back(buf[scount + j]);\r
+ }\r
+ }\r
+ return ret;\r
+\r
+}\r
+ \r
--- /dev/null
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the
+// distribution.
+// * All advertising materials mentioning features or use of this
+// software must display the following acknowledgement: This product
+// includes software developed by tm3d.de and its contributors.
+// * Neither the name of tm3d.de nor the names of its contributors may
+// be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#ifndef __OWTMEXWIN_H_
+#define __OWTMEXWIN_H_
+
+#include "owInterface.h"
+
+class owTMEXWIN :public owInterface {
+protected:
+ int portnum;
+ int com_init;
+public:
+ owTMEXWIN():owInterface() {
+ portnum=-1;
+ com_init=0;
+ }
+ virtual int InitAdapter(std::string s);
+ virtual int InitAdapter(uint8_t) { return 0; };
+ virtual int Reset();
+ virtual uint8_t sendrecivBit(uint8_t bit);
+ virtual uint8_t sendrecivByte(uint8_t byte);
+ virtual void ReleaseAdapter();
+ virtual int MatchRom(snum_t snum);
+ virtual int owFirst();
+ virtual int owNext();
+ virtual int Communicate(std::vector<uint8_t> *data, int scount, int rcount);
+
+
+
+};
+
+#endif
#ifndef __OWTOOLS_H_
#define __OWTOOLS_H_
+#if defined(_WINDOWS) || defined(__WINDOWS__) || defined(_WIN32) || defined(WIN32)
+#define WIN
+#else
+#define LINUX
+#endif
+
+
+
#include "owInterface.h"
+#include "owARDUINOInterface.h"
+#ifdef WIN
+#include "owTMEXWIN.h"
+#endif
+
+#ifdef LINUX
#include "owUSBInterface.h"
#include "owCOMInterface.h"
#include "owPiGPioInterface.h"
-#include "owARDUINOInterface.h"
+#endif
#endif
--- /dev/null
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2000 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
+// crcutil.c - Keeps track of the CRC for 16 and 8 bit operations\r
+// version 2.00\r
+\r
+// Include files\r
+#include "ownet.h"\r
+\r
+// Local global variables\r
+ushort utilcrc16[MAX_PORTNUM];\r
+uchar utilcrc8[MAX_PORTNUM];\r
+static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };\r
+static uchar dscrc_table[] = {\r
+ 0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,\r
+ 157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220,\r
+ 35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98,\r
+ 190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,\r
+ 70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7,\r
+ 219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154,\r
+ 101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36,\r
+ 248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185,\r
+ 140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,\r
+ 17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,\r
+ 175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,\r
+ 50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,\r
+ 202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139,\r
+ 87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,\r
+ 233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,\r
+ 116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};\r
+\r
+//--------------------------------------------------------------------------\r
+// Reset crc16 to the value passed in\r
+//\r
+// 'reset' - data to set crc16 to.\r
+//\r
+void setcrc16(int portnum, ushort reset)\r
+{\r
+ utilcrc16[portnum&0x0FF] = reset;\r
+ return;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Reset crc8 to the value passed in\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'reset' - data to set crc8 to\r
+//\r
+void setcrc8(int portnum, uchar reset)\r
+{\r
+ utilcrc8[portnum&0x0FF] = reset;\r
+ return;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Calculate a new CRC16 from the input data short. Return the current\r
+// CRC16 and also update the global variable CRC16.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'data' - data to perform a CRC16 on\r
+//\r
+// Returns: the current CRC16\r
+//\r
+ushort docrc16(int portnum, ushort cdata)\r
+{\r
+ cdata = (cdata ^ (utilcrc16[portnum&0x0FF] & 0xff)) & 0xff;\r
+ utilcrc16[portnum&0x0FF] >>= 8;\r
+\r
+ if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])\r
+ utilcrc16[portnum&0x0FF] ^= 0xc001;\r
+\r
+ cdata <<= 6;\r
+ utilcrc16[portnum&0x0FF] ^= cdata;\r
+ cdata <<= 1;\r
+ utilcrc16[portnum&0x0FF] ^= cdata;\r
+\r
+ return utilcrc16[portnum&0x0FF];\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global\r
+// variable utilcrc8 and the argument.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'x' - data byte to calculate the 8 bit crc from\r
+//\r
+// Returns: the updated utilcrc8.\r
+//\r
+uchar docrc8(int portnum, uchar x)\r
+{\r
+ utilcrc8[portnum&0x0FF] = dscrc_table[utilcrc8[portnum&0x0FF] ^ x];\r
+ return utilcrc8[portnum&0x0FF];\r
+}\r
--- /dev/null
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Visual Studio 14\r
+VisualStudioVersion = 14.0.25123.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "owTools", "owTools.vcxproj", "{7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}"\r
+EndProject\r
+Global\r
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+ Debug|x64 = Debug|x64\r
+ Debug|x86 = Debug|x86\r
+ Release|x64 = Release|x64\r
+ Release|x86 = Release|x86\r
+ EndGlobalSection\r
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Debug|x64.ActiveCfg = Debug|x64\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Debug|x64.Build.0 = Debug|x64\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Debug|x86.ActiveCfg = Debug|Win32\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Debug|x86.Build.0 = Debug|Win32\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Release|x64.ActiveCfg = Release|x64\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Release|x64.Build.0 = Release|x64\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Release|x86.ActiveCfg = Release|Win32\r
+ {7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}.Release|x86.Build.0 = Release|Win32\r
+ EndGlobalSection\r
+ GlobalSection(SolutionProperties) = preSolution\r
+ HideSolutionNode = FALSE\r
+ EndGlobalSection\r
+EndGlobal\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+ <ItemGroup Label="ProjectConfigurations">\r
+ <ProjectConfiguration Include="Debug|Win32">\r
+ <Configuration>Debug</Configuration>\r
+ <Platform>Win32</Platform>\r
+ </ProjectConfiguration>\r
+ <ProjectConfiguration Include="Release|Win32">\r
+ <Configuration>Release</Configuration>\r
+ <Platform>Win32</Platform>\r
+ </ProjectConfiguration>\r
+ <ProjectConfiguration Include="Debug|x64">\r
+ <Configuration>Debug</Configuration>\r
+ <Platform>x64</Platform>\r
+ </ProjectConfiguration>\r
+ <ProjectConfiguration Include="Release|x64">\r
+ <Configuration>Release</Configuration>\r
+ <Platform>x64</Platform>\r
+ </ProjectConfiguration>\r
+ </ItemGroup>\r
+ <PropertyGroup Label="Globals">\r
+ <ProjectGuid>{7BC76CAE-ECA9-4C9B-9DE0-3F8449F815B4}</ProjectGuid>\r
+ <Keyword>Win32Proj</Keyword>\r
+ <RootNamespace>owTools</RootNamespace>\r
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>\r
+ </PropertyGroup>\r
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+ <ConfigurationType>Application</ConfigurationType>\r
+ <UseDebugLibraries>true</UseDebugLibraries>\r
+ <PlatformToolset>v140</PlatformToolset>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+ <ConfigurationType>Application</ConfigurationType>\r
+ <UseDebugLibraries>false</UseDebugLibraries>\r
+ <PlatformToolset>v140</PlatformToolset>\r
+ <WholeProgramOptimization>true</WholeProgramOptimization>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+ <ConfigurationType>Application</ConfigurationType>\r
+ <UseDebugLibraries>true</UseDebugLibraries>\r
+ <PlatformToolset>v140</PlatformToolset>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+ <ConfigurationType>Application</ConfigurationType>\r
+ <UseDebugLibraries>false</UseDebugLibraries>\r
+ <PlatformToolset>v140</PlatformToolset>\r
+ <WholeProgramOptimization>true</WholeProgramOptimization>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ </PropertyGroup>\r
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+ <ImportGroup Label="ExtensionSettings">\r
+ </ImportGroup>\r
+ <ImportGroup Label="Shared">\r
+ </ImportGroup>\r
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <PropertyGroup Label="UserMacros" />\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+ <LinkIncremental>true</LinkIncremental>\r
+ <IgnoreImportLibrary>true</IgnoreImportLibrary>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+ <LinkIncremental>true</LinkIncremental>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+ <LinkIncremental>false</LinkIncremental>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+ <LinkIncremental>false</LinkIncremental>\r
+ </PropertyGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+ <ClCompile>\r
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <Optimization>Disabled</Optimization>\r
+ <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <SDLCheck>true</SDLCheck>\r
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+ <AdditionalIncludeDirectories>.\windows\owTools;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+ </ClCompile>\r
+ <Link>\r
+ <SubSystem>Console</SubSystem>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ </Link>\r
+ </ItemDefinitionGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+ <ClCompile>\r
+ <PrecompiledHeader>Use</PrecompiledHeader>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <Optimization>Disabled</Optimization>\r
+ <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <SDLCheck>true</SDLCheck>\r
+ </ClCompile>\r
+ <Link>\r
+ <SubSystem>Console</SubSystem>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ </Link>\r
+ </ItemDefinitionGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+ <ClCompile>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>\r
+ <Optimization>MaxSpeed</Optimization>\r
+ <FunctionLevelLinking>true</FunctionLevelLinking>\r
+ <IntrinsicFunctions>true</IntrinsicFunctions>\r
+ <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <SDLCheck>true</SDLCheck>\r
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+ <AdditionalIncludeDirectories>.\windows\owTools;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+ </ClCompile>\r
+ <Link>\r
+ <SubSystem>Console</SubSystem>\r
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+ <OptimizeReferences>true</OptimizeReferences>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ </Link>\r
+ </ItemDefinitionGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+ <ClCompile>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <PrecompiledHeader>Use</PrecompiledHeader>\r
+ <Optimization>MaxSpeed</Optimization>\r
+ <FunctionLevelLinking>true</FunctionLevelLinking>\r
+ <IntrinsicFunctions>true</IntrinsicFunctions>\r
+ <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <SDLCheck>true</SDLCheck>\r
+ </ClCompile>\r
+ <Link>\r
+ <SubSystem>Console</SubSystem>\r
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+ <OptimizeReferences>true</OptimizeReferences>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ </Link>\r
+ </ItemDefinitionGroup>\r
+ <ItemGroup>\r
+ <Text Include="ReadMe.txt" />\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <ClInclude Include="..\..\src\hexfile.h" />\r
+ <ClInclude Include="..\..\src\owARDUINOInterface.h" />\r
+ <ClInclude Include="..\..\src\owDeviceConfig.h" />\r
+ <ClInclude Include="..\..\src\owInterface.h" />\r
+ <ClInclude Include="..\..\src\owTMEXWIN.h" />\r
+ <ClInclude Include="..\..\src\owTools.h" />\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <ClCompile Include="..\..\src\hexfile.cpp" />\r
+ <ClCompile Include="..\..\src\main.cpp" />\r
+ <ClCompile Include="..\..\src\owARDUINOInterface.cpp" />\r
+ <ClCompile Include="..\..\src\owDevice.cpp" />\r
+ <ClCompile Include="..\..\src\owDeviceConfig.cpp" />\r
+ <ClCompile Include="..\..\src\owInterface.cpp" />\r
+ <ClCompile Include="..\..\src\owTMEXWIN.cpp" />\r
+ <ClCompile Include="crcutil.cpp" />\r
+ <ClCompile Include="owerr.cpp" />\r
+ <ClCompile Include="tmexlnk.cpp" />\r
+ <ClCompile Include="tmexnet.cpp" />\r
+ <ClCompile Include="tmexses.cpp" />\r
+ <ClCompile Include="tmextran.cpp" />\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <Library Include="ibfs32.lib" />\r
+ </ItemGroup>\r
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+ <ImportGroup Label="ExtensionTargets">\r
+ </ImportGroup>\r
+</Project>
\ No newline at end of file
--- /dev/null
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2000 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
+// owerr.c - Library functions for error handling with 1-Wire library\r
+//\r
+// Version: 1.00\r
+//\r
+\r
+#include <string.h>\r
+#ifndef _WIN32_WCE\r
+#include <stdio.h>\r
+#endif\r
+#ifdef _WIN64\r
+#include <stdio.h>\r
+#endif\r
+#include "ownet.h"\r
+\r
+#ifndef SIZE_OWERROR_STACK\r
+ #ifdef SMALL_MEMORY_TARGET\r
+ //for small memory, only hole 1 error\r
+ #define SIZE_OWERROR_STACK 1\r
+ #else\r
+ #define SIZE_OWERROR_STACK 10\r
+ #endif\r
+#endif\r
+\r
+//---------------------------------------------------------------------------\r
+// Variables\r
+//---------------------------------------------------------------------------\r
+\r
+// Error Struct for holding error information.\r
+// In DEBUG, this will also hold the line number and filename.\r
+typedef struct\r
+{\r
+ int owErrorNum;\r
+#ifdef DEBUG\r
+ int lineno;\r
+ char *filename;\r
+#endif\r
+} owErrorStruct;\r
+\r
+// Ring-buffer used for stack.\r
+// In case of overflow, deepest error is over-written.\r
+static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];\r
+\r
+// Stack pointer to top-most error.\r
+static int owErrorPointer = 0;\r
+\r
+\r
+//---------------------------------------------------------------------------\r
+// Functions Definitions\r
+//---------------------------------------------------------------------------\r
+int owGetErrorNum(void);\r
+void owClearError(void);\r
+int owHasErrors(void);\r
+#ifdef DEBUG\r
+ void owRaiseError(int,int,char*);\r
+#else\r
+ void owRaiseError(int);\r
+#endif\r
+#ifndef SMALL_MEMORY_TARGET\r
+ void owPrintErrorMsg(FILE *);\r
+ void owPrintErrorMsgStd();\r
+ char *owGetErrorMsg(int);\r
+#endif\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owGetErroNum' returns the error code of the top-most error on the\r
+// error stack. NOTE: This function has the side effect of popping the\r
+// current error off the stack. All successive calls to 'owGetErrorNum'\r
+// will further clear the error stack.\r
+//\r
+// For list of error codes, see 'ownet.h'\r
+//\r
+// Returns: int : The error code of the top-most error on the stack\r
+//\r
+int owGetErrorNum(void)\r
+{\r
+ int i = owErrorStack[ owErrorPointer ].owErrorNum;\r
+ owErrorStack[ owErrorPointer ].owErrorNum = 0;\r
+ if(!owErrorPointer)\r
+ owErrorPointer = SIZE_OWERROR_STACK - 1;\r
+ else\r
+ owErrorPointer = (owErrorPointer - 1);\r
+ return i;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owClearError' clears all the errors.\r
+//\r
+void owClearError(void)\r
+{\r
+ owErrorStack[ owErrorPointer ].owErrorNum = 0;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owHasErrors' is a boolean test function which tests whether or not\r
+// a valid error is waiting on the stack.\r
+//\r
+// Returns: TRUE (1) : When there are errors on the stack.\r
+// FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET.\r
+//\r
+int owHasErrors(void)\r
+{\r
+ if(owErrorStack[ owErrorPointer ].owErrorNum)\r
+ return 1; //TRUE\r
+ else\r
+ return 0; //FALSE\r
+}\r
+\r
+#ifdef DEBUG\r
+ //--------------------------------------------------------------------------\r
+ // The 'owRaiseError' is the method for raising an error onto the error\r
+ // stack.\r
+ //\r
+ // Arguments: int err - the error code you wish to raise.\r
+ // int lineno - DEBUG only - the line number where it was raised\r
+ // char* filename - DEBUG only - the file name where it occured.\r
+ //\r
+ void owRaiseError(int err, int lineno, char* filename)\r
+ {\r
+ owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;\r
+ owErrorStack[ owErrorPointer ].owErrorNum = err;\r
+ owErrorStack[ owErrorPointer ].lineno = lineno;\r
+ owErrorStack[ owErrorPointer ].filename = filename;\r
+ }\r
+#else\r
+ //--------------------------------------------------------------------------\r
+ // The 'owRaiseError' is the method for raising an error onto the error\r
+ // stack.\r
+ //\r
+ // Arguments: int err - the error code you wish to raise.\r
+ //\r
+ void owRaiseError(int err)\r
+ {\r
+ owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;\r
+ owErrorStack[ owErrorPointer ].owErrorNum = err;\r
+ }\r
+#endif\r
+\r
+\r
+// SMALL_MEMORY_TARGET - embedded microcontrollers, where these\r
+// messaging functions might not make any sense.\r
+#ifndef SMALL_MEMORY_TARGET\r
+ //Array of meaningful error messages to associate with codes.\r
+ //Not used on targets with low memory (i.e. PIC).\r
+ static char *owErrorMsg[125] =\r
+ {\r
+ /*000*/ "No Error Was Set",\r
+ /*001*/ "No Devices found on 1-Wire Network",\r
+ /*002*/ "1-Wire Net Reset Failed",\r
+ /*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire",\r
+ /*004*/ "Access Failed: Could not select device",\r
+ /*005*/ "DS2480B Adapter Not Detected",\r
+ /*006*/ "DS2480B: Wrong Baud",\r
+ /*007*/ "DS2480B: Bad Response",\r
+ /*008*/ "Open COM Failed",\r
+ /*009*/ "Write COM Failed",\r
+ /*010*/ "Read COM Failed",\r
+ /*011*/ "Data Block Too Large",\r
+ /*012*/ "Block Transfer failed",\r
+ /*013*/ "Program Pulse Failed",\r
+ /*014*/ "Program Byte Failed",\r
+ /*015*/ "Write Byte Failed",\r
+ /*016*/ "Read Byte Failed",\r
+ /*017*/ "Write Verify Failed",\r
+ /*018*/ "Read Verify Failed",\r
+ /*019*/ "Write Scratchpad Failed",\r
+ /*020*/ "Copy Scratchpad Failed",\r
+ /*021*/ "Incorrect CRC Length",\r
+ /*022*/ "CRC Failed",\r
+ /*023*/ "Failed to acquire a necessary system resource",\r
+ /*024*/ "Failed to initialize system resource",\r
+ /*025*/ "Data too long to fit on specified device.",\r
+ /*026*/ "Read exceeds memory bank end.",\r
+ /*027*/ "Write exceeds memory bank end.",\r
+ /*028*/ "Device select failed",\r
+ /*029*/ "Read Scratch Pad verify failed.",\r
+ /*030*/ "Copy scratchpad complete not found",\r
+ /*031*/ "Erase scratchpad complete not found",\r
+ /*032*/ "Address read back from scrachpad was incorrect",\r
+ /*033*/ "Read page with extra-info not supported by this memory bank",\r
+ /*034*/ "Read page packet with extra-info not supported by this memory bank",\r
+ /*035*/ "Length of packet requested exceeds page size",\r
+ /*036*/ "Invalid length in packet",\r
+ /*037*/ "Program pulse required but not available",\r
+ /*038*/ "Trying to access a read-only memory bank",\r
+ /*039*/ "Current bank is not general purpose memory",\r
+ /*040*/ "Read back from write compare is incorrect, page may be locked",\r
+ /*041*/ "Invalid page number for this memory bank",\r
+ /*042*/ "Read page with CRC not supported by this memory bank",\r
+ /*043*/ "Read page with CRC and extra-info not supported by this memory bank",\r
+ /*044*/ "Read back from write incorrect, could not lock page",\r
+ /*045*/ "Read back from write incorrect, could not lock redirect byte",\r
+ /*046*/ "The read of the status was not completed.",\r
+ /*047*/ "Page redirection not supported by this memory bank",\r
+ /*048*/ "Lock Page redirection not supported by this memory bank",\r
+ /*049*/ "Read back byte on EPROM programming did not match.",\r
+ /*050*/ "Can not write to a page that is locked.",\r
+ /*051*/ "Can not lock a redirected page that has already been locked.",\r
+ /*052*/ "Trying to redirect a locked redirected page.",\r
+ /*053*/ "Trying to lock a page that is already locked.",\r
+ /*054*/ "Trying to write to a memory bank that is write protected.",\r
+ /*055*/ "Error due to not matching MAC.",\r
+ /*056*/ "Memory Bank is write protected.",\r
+ /*057*/ "Secret is write protected, can not Load First Secret.",\r
+ /*058*/ "Error in Reading Scratchpad after Computing Next Secret.",\r
+ /*059*/ "Load Error from Loading First Secret.",\r
+ /*060*/ "Power delivery required but not available",\r
+ /*061*/ "Not a valid file name.",\r
+ /*062*/ "Unable to Create a Directory in this part.",\r
+ /*063*/ "That file already exists.",\r
+ /*064*/ "The directory is not empty.",\r
+ /*065*/ "The wrong type of part for this operation.",\r
+ /*066*/ "The max len for this file is too small.",\r
+ /*067*/ "This is not a write once bank.",\r
+ /*068*/ "The file can not be found.",\r
+ /*069*/ "There is not enough space available.",\r
+ /*070*/ "There is not a page to match that bit in the bitmap.",\r
+ /*071*/ "There are no jobs for EPROM parts.",\r
+ /*072*/ "Function not supported to modify attributes.",\r
+ /*073*/ "Handle is not in use.",\r
+ /*074*/ "Tring to read a write only file.",\r
+ /*075*/ "There is no handle available for use.",\r
+ /*076*/ "The directory provided is an invalid directory.",\r
+ /*077*/ "Handle does not exist.",\r
+ /*078*/ "Serial Number did not match with current job.",\r
+ /*079*/ "Can not program EPROM because a non-EPROM part on the network.",\r
+ /*080*/ "Write protect redirection byte is set.",\r
+ /*081*/ "There is an inappropriate directory length.",\r
+ /*082*/ "The file has already been terminated.",\r
+ /*083*/ "Failed to read memory page of iButton part.",\r
+ /*084*/ "Failed to match scratchpad of iButton part.",\r
+ /*085*/ "Failed to erase scratchpad of iButton part.",\r
+ /*086*/ "Failed to read scratchpad of iButton part.",\r
+ /*087*/ "Failed to execute SHA function on SHA iButton.",\r
+ /*088*/ "SHA iButton did not return a status completion byte.",\r
+ /*089*/ "Write data page failed.",\r
+ /*090*/ "Copy secret into secret memory pages failed.",\r
+ /*091*/ "Bind unique secret to iButton failed.",\r
+ /*092*/ "Could not install secret into user token.",\r
+ /*093*/ "Transaction Incomplete: signature did not match.",\r
+ /*094*/ "Transaction Incomplete: could not sign service data.",\r
+ /*095*/ "User token did not provide a valid authentication response.",\r
+ /*096*/ "Failed to answer a challenge on the user token.",\r
+ /*097*/ "Failed to create a challenge on the coprocessor.",\r
+ /*098*/ "Transaction Incomplete: service data was not valid.",\r
+ /*099*/ "Transaction Incomplete: service data was not updated.",\r
+ /*100*/ "Unrecoverable, catastrophic service failure occured.",\r
+ /*101*/ "Load First Secret from scratchpad data failed.",\r
+ /*102*/ "Failed to match signature of user's service data.",\r
+ /*103*/ "Subkey out of range for the DS1991.",\r
+ /*104*/ "Block ID out of range for the DS1991",\r
+ /*105*/ "Password is enabled",\r
+ /*106*/ "Password is invalid",\r
+ /*107*/ "This memory bank has no read only password",\r
+ /*108*/ "This memory bank has no read/write password",\r
+ /*109*/ "1-Wire is shorted",\r
+ /*110*/ "Error communicating with 1-Wire adapter",\r
+ /*111*/ "CopyScratchpad failed: Ending Offset must go to end of page",\r
+ /*112*/ "WriteScratchpad failed: Ending Offset must go to end of page",\r
+ /*113*/ "Mission can not be stopped while one is not in progress",\r
+ /*114*/ "Error stopping the mission",\r
+ /*115*/ "Port number is outside (0,MAX_PORTNUM) interval",\r
+ /*116*/ "Level of the 1-Wire was not changed",\r
+ /*117*/ "Both the Read Only and Read Write Passwords must be set",\r
+ /*118*/ "Failure to change latch state."\r
+ /*119*/ "Could not open usb port through libusb",\r
+ /*120*/ "Libusb DS2490 port already opened",\r
+ /*121*/ "Failed to set libusb configuration",\r
+ /*122*/ "Failed to claim libusb interface",\r
+ /*123*/ "Failed to set libusb altinterface",\r
+ /*124*/ "No adapter found at this port number"\r
+ };\r
+\r
+ char *owGetErrorMsg(int err)\r
+ {\r
+ return owErrorMsg[err];\r
+ }\r
+\r
+#ifndef __C51__\r
+ //--------------------------------------------------------------------------\r
+ // The 'owPrintErrorMsg' is the method for printing an error from the stack.\r
+ // The destination for the print is specified by the argument, fileno, which\r
+ // can be stderr, stdout, or a log file. In non-debug mode, the output is\r
+ // of the form:\r
+ // Error num: Error msg\r
+ //\r
+ // In debug-mode, the output is of the form:\r
+ // Error num: filename line#: Error msg\r
+ //\r
+ // NOTE: This function has the side-effect of popping the error off the stack.\r
+ //\r
+ // Arguments: FILE*: the destination for printing.\r
+ //\r
+ void owPrintErrorMsg(FILE *filenum)\r
+ {\r
+ #ifdef DEBUG\r
+ int l = owErrorStack[ owErrorPointer ].lineno;\r
+ char *f = owErrorStack[ owErrorPointer ].filename;\r
+ int err = owGetErrorNum();\r
+ fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);\r
+ #else\r
+ int err = owGetErrorNum();\r
+ fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]);\r
+ #endif\r
+ }\r
+#endif //__C51__\r
+\r
+ // Same as above, except uses default printf output\r
+ void owPrintErrorMsgStd()\r
+ {\r
+ #ifdef DEBUG\r
+ int l = owErrorStack[ owErrorPointer ].lineno;\r
+ char *f = owErrorStack[ owErrorPointer ].filename;\r
+ int err = owGetErrorNum();\r
+ printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);\r
+ #else\r
+ int err = owGetErrorNum();\r
+ printf("Error %d: %s\r\n",err,owErrorMsg[err]);\r
+ #endif\r
+ }\r
+#endif\r
+\r
--- /dev/null
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2000 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
+// ownet.h - Include file for 1-Wire Net library\r
+//\r
+// Version: 2.10\r
+//\r
+// History: 1.02 -> 1.03 Make sure uchar is not defined twice.\r
+// 1.03 -> 2.00 Changed 'MLan' to 'ow'.\r
+// 2.00 -> 2.01 Added error handling. Added circular-include check.\r
+// 2.01 -> 2.10 Added raw memory error handling and SMALLINT\r
+// 2.10 -> 3.00 Added memory bank functionality\r
+// Added file I/O operations\r
+//\r
+\r
+#ifndef OWNET_H\r
+#define OWNET_H\r
+\r
+//--------------------------------------------------------------//\r
+// Common Includes to ownet applications\r
+//--------------------------------------------------------------//\r
+#include <stdlib.h>\r
+#include <stdint.h>\r
+\r
+\r
+//--------------------------------------------------------------//\r
+// Target Specific Information\r
+//--------------------------------------------------------------//\r
+//--------------------------------------------------------------//\r
+// Handhelds (PalmOS, WinCE)\r
+//--------------------------------------------------------------//\r
+#ifdef __MC68K__\r
+ //MC68K is the type of processor in the PILOT\r
+ //Metrowerk's CodeWarrior defines this symbol\r
+ #include <string.h>\r
+ #ifndef strcmp\r
+ #include <StringMgr.h>\r
+ #define strcmp StrCompare\r
+ #endif\r
+ #include <file_struc.h>\r
+#endif\r
+\r
+#ifdef _WIN32_WCE\r
+ //All of our projects had this flag defined by default (_WIN32_WCE),\r
+ //but I'm not 100% positive that this is _the_ definitive\r
+ //flag to use to identify a WinCE system.\r
+ #include "WinCElnk.h"\r
+ #ifndef FILE\r
+ #define FILE int\r
+ extern int sprintf(char *buffer, char *format,...);\r
+ extern void fprintf(FILE *fp, char *format,...);\r
+ extern void printf(char *format,...);\r
+ #endif\r
+#endif\r
+\r
+#if !defined(_WIN32_WCE) && !defined(__MC68K__)\r
+ #include <stdio.h>\r
+#endif\r
+\r
+#ifdef __C51__\r
+ #define FILE int\r
+ #define exit(c) return\r
+ typedef unsigned int ushort;\r
+ typedef unsigned long ulong;\r
+ #define SMALLINT uchar\r
+#endif\r
+\r
+#ifdef __ICCMAXQ__\r
+ #define FILE int\r
+ #define stdout 0\r
+ #define stdin 1\r
+ #define stderr 2\r
+ typedef unsigned int ushort;\r
+ typedef unsigned long ulong;\r
+ #define SMALLINT short\r
+ #define main micro_main\r
+ #define real_main main\r
+ #define SMALL_MEMORY_TARGET\r
+#endif\r
+\r
+\r
+//--------------------------------------------------------------//\r
+// Typedefs\r
+//--------------------------------------------------------------//\r
+#ifndef SMALLINT\r
+ //\r
+ // purpose of smallint is for compile-time changing of formal\r
+ // parameters and return values of functions. For each target\r
+ // machine, an integer is alleged to represent the most "simple"\r
+ // number representable by that architecture. This should, in\r
+ // most cases, produce optimal code for that particular arch.\r
+ // BUT... The majority of compilers designed for embedded\r
+ // processors actually keep an int at 16 bits, although the\r
+ // architecture might only be comfortable with 8 bits.\r
+ // The default size of smallint will be the same as that of\r
+ // an integer, but this allows for easy overriding of that size.\r
+ //\r
+ // NOTE:\r
+ // In all cases where a smallint is used, it is assumed that\r
+ // decreasing the size of this integer to something as low as\r
+ // a single byte _will_not_ change the functionality of the\r
+ // application. e.g. a loop counter that will iterate through\r
+ // several kilobytes of data should not be SMALLINT. The most\r
+ // common place you'll see smallint is for boolean return types.\r
+ //\r
+ #define SMALLINT int\r
+#endif\r
+\r
+// setting max baud\r
+#ifdef _WINDOWS\r
+ // 0x02 = PARAMSET_19200\r
+#define MAX_BAUD 0x02\r
+#else\r
+ // 0x06 = PARMSET_115200\r
+#define MAX_BAUD 0x06\r
+#endif\r
+\r
+#ifndef OW_UCHAR\r
+ #define OW_UCHAR\r
+ typedef unsigned char uchar;\r
+ #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__))\r
+ typedef unsigned long ulong;\r
+ //ushort already defined in sys/types.h\r
+ #include <sys/types.h>\r
+ #else\r
+ #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS) || defined(_WINDOWS) || defined(__MINGW32__)\r
+ typedef unsigned short ushort;\r
+ typedef unsigned long ulong;\r
+ #endif\r
+ #endif\r
+ #ifdef __sun__\r
+ #include <sys/types.h>\r
+ #endif\r
+ #ifdef SDCC\r
+ //intent of ushort is 2 bytes unsigned.\r
+ //for ds390 in sdcc, an int, not a short,\r
+ //is 2 bytes.\r
+ typedef unsigned int ushort;\r
+ #endif\r
+#endif\r
+\r
+// general defines\r
+#define WRITE_FUNCTION 1\r
+#define READ_FUNCTION 0\r
+\r
+// error codes\r
+// todo: investigate these and replace with new Error Handling library\r
+#define READ_ERROR -1\r
+#define INVALID_DIR -2\r
+#define NO_FILE -3\r
+#define WRITE_ERROR -4\r
+#define WRONG_TYPE -5\r
+#define FILE_TOO_BIG -6\r
+\r
+// Misc\r
+#define FALSE 0\r
+#define TRUE 1\r
+\r
+#ifndef MAX_PORTNUM\r
+ #define MAX_PORTNUM 16\r
+#endif\r
+\r
+// mode bit flags\r
+#define MODE_NORMAL 0x00\r
+#define MODE_OVERDRIVE 0x01\r
+#define MODE_STRONG5 0x02\r
+#define MODE_PROGRAM 0x04\r
+#define MODE_BREAK 0x08\r
+\r
+// Output flags\r
+#define LV_ALWAYS 2\r
+#define LV_OPTIONAL 1\r
+#define LV_VERBOSE 0\r
+\r
+//--------------------------------------------------------------//\r
+// Error handling\r
+//--------------------------------------------------------------//\r
+extern int owGetErrorNum(void);\r
+extern int owHasErrors(void);\r
+\r
+//Clears the stack.\r
+#define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum();\r
+\r
+#ifdef DEBUG\r
+ //Raises an exception with extra debug info\r
+ #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__)\r
+ extern void owRaiseError(int,int,char*);\r
+ #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);}\r
+#else\r
+ //Raises an exception with just the error code\r
+ #define OWERROR(err) owRaiseError(err)\r
+ extern void owRaiseError(int);\r
+ #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);}\r
+#endif\r
+\r
+#ifdef SMALL_MEMORY_TARGET\r
+ #define OWERROR_DUMP(fileno) /*no-op*/;\r
+#else\r
+ //Prints the stack out to the given file.\r
+ #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno);\r
+ extern void owPrintErrorMsg(FILE *);\r
+ extern void owPrintErrorMsgStd();\r
+ extern char *owGetErrorMsg(int);\r
+#endif\r
+\r
+#define OWERROR_NO_ERROR_SET 0\r
+#define OWERROR_NO_DEVICES_ON_NET 1\r
+#define OWERROR_RESET_FAILED 2\r
+#define OWERROR_SEARCH_ERROR 3\r
+#define OWERROR_ACCESS_FAILED 4\r
+#define OWERROR_DS2480_NOT_DETECTED 5\r
+#define OWERROR_DS2480_WRONG_BAUD 6\r
+#define OWERROR_DS2480_BAD_RESPONSE 7\r
+#define OWERROR_OPENCOM_FAILED 8\r
+#define OWERROR_WRITECOM_FAILED 9\r
+#define OWERROR_READCOM_FAILED 10\r
+#define OWERROR_BLOCK_TOO_BIG 11\r
+#define OWERROR_BLOCK_FAILED 12\r
+#define OWERROR_PROGRAM_PULSE_FAILED 13\r
+#define OWERROR_PROGRAM_BYTE_FAILED 14\r
+#define OWERROR_WRITE_BYTE_FAILED 15\r
+#define OWERROR_READ_BYTE_FAILED 16\r
+#define OWERROR_WRITE_VERIFY_FAILED 17\r
+#define OWERROR_READ_VERIFY_FAILED 18\r
+#define OWERROR_WRITE_SCRATCHPAD_FAILED 19\r
+#define OWERROR_COPY_SCRATCHPAD_FAILED 20\r
+#define OWERROR_INCORRECT_CRC_LENGTH 21\r
+#define OWERROR_CRC_FAILED 22\r
+#define OWERROR_GET_SYSTEM_RESOURCE_FAILED 23\r
+#define OWERROR_SYSTEM_RESOURCE_INIT_FAILED 24\r
+#define OWERROR_DATA_TOO_LONG 25\r
+#define OWERROR_READ_OUT_OF_RANGE 26\r
+#define OWERROR_WRITE_OUT_OF_RANGE 27\r
+#define OWERROR_DEVICE_SELECT_FAIL 28\r
+#define OWERROR_READ_SCRATCHPAD_VERIFY 29\r
+#define OWERROR_COPY_SCRATCHPAD_NOT_FOUND 30\r
+#define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND 31\r
+#define OWERROR_ADDRESS_READ_BACK_FAILED 32\r
+#define OWERROR_EXTRA_INFO_NOT_SUPPORTED 33\r
+#define OWERROR_PG_PACKET_WITHOUT_EXTRA 34\r
+#define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE 35\r
+#define OWERROR_INVALID_PACKET_LENGTH 36\r
+#define OWERROR_NO_PROGRAM_PULSE 37\r
+#define OWERROR_READ_ONLY 38\r
+#define OWERROR_NOT_GENERAL_PURPOSE 39\r
+#define OWERROR_READ_BACK_INCORRECT 40\r
+#define OWERROR_INVALID_PAGE_NUMBER 41\r
+#define OWERROR_CRC_NOT_SUPPORTED 42\r
+#define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED 43\r
+#define OWERROR_READ_BACK_NOT_VALID 44\r
+#define OWERROR_COULD_NOT_LOCK_REDIRECT 45\r
+#define OWERROR_READ_STATUS_NOT_COMPLETE 46\r
+#define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED 47\r
+#define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED 48\r
+#define OWERROR_READBACK_EPROM_FAILED 49\r
+#define OWERROR_PAGE_LOCKED 50\r
+#define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN 51\r
+#define OWERROR_REDIRECTED_PAGE 52\r
+#define OWERROR_PAGE_ALREADY_LOCKED 53\r
+#define OWERROR_WRITE_PROTECTED 54\r
+#define OWERROR_NONMATCHING_MAC 55\r
+#define OWERROR_WRITE_PROTECT 56\r
+#define OWERROR_WRITE_PROTECT_SECRET 57\r
+#define OWERROR_COMPUTE_NEXT_SECRET 58\r
+#define OWERROR_LOAD_FIRST_SECRET 59\r
+#define OWERROR_POWER_NOT_AVAILABLE 60\r
+#define OWERROR_XBAD_FILENAME 61\r
+#define OWERROR_XUNABLE_TO_CREATE_DIR 62\r
+#define OWERROR_REPEAT_FILE 63\r
+#define OWERROR_DIRECTORY_NOT_EMPTY 64\r
+#define OWERROR_WRONG_TYPE 65\r
+#define OWERROR_BUFFER_TOO_SMALL 66\r
+#define OWERROR_NOT_WRITE_ONCE 67\r
+#define OWERROR_FILE_NOT_FOUND 68\r
+#define OWERROR_OUT_OF_SPACE 69\r
+#define OWERROR_TOO_LARGE_BITNUM 70\r
+#define OWERROR_NO_PROGRAM_JOB 71\r
+#define OWERROR_FUNC_NOT_SUP 72\r
+#define OWERROR_HANDLE_NOT_USED 73\r
+#define OWERROR_FILE_WRITE_ONLY 74\r
+#define OWERROR_HANDLE_NOT_AVAIL 75\r
+#define OWERROR_INVALID_DIRECTORY 76\r
+#define OWERROR_HANDLE_NOT_EXIST 77\r
+#define OWERROR_NONMATCHING_SNUM 78\r
+#define OWERROR_NON_PROGRAM_PARTS 79\r
+#define OWERROR_PROGRAM_WRITE_PROTECT 80\r
+#define OWERROR_FILE_READ_ERR 81\r
+#define OWERROR_ADDFILE_TERMINATED 82\r
+#define OWERROR_READ_MEMORY_PAGE_FAILED 83\r
+#define OWERROR_MATCH_SCRATCHPAD_FAILED 84\r
+#define OWERROR_ERASE_SCRATCHPAD_FAILED 85\r
+#define OWERROR_READ_SCRATCHPAD_FAILED 86\r
+#define OWERROR_SHA_FUNCTION_FAILED 87\r
+#define OWERROR_NO_COMPLETION_BYTE 88\r
+#define OWERROR_WRITE_DATA_PAGE_FAILED 89\r
+#define OWERROR_COPY_SECRET_FAILED 90\r
+#define OWERROR_BIND_SECRET_FAILED 91\r
+#define OWERROR_INSTALL_SECRET_FAILED 92\r
+#define OWERROR_VERIFY_SIG_FAILED 93\r
+#define OWERROR_SIGN_SERVICE_DATA_FAILED 94\r
+#define OWERROR_VERIFY_AUTH_RESPONSE_FAILED 95\r
+#define OWERROR_ANSWER_CHALLENGE_FAILED 96\r
+#define OWERROR_CREATE_CHALLENGE_FAILED 97\r
+#define OWERROR_BAD_SERVICE_DATA 98\r
+#define OWERROR_SERVICE_DATA_NOT_UPDATED 99\r
+#define OWERROR_CATASTROPHIC_SERVICE_FAILURE 100\r
+#define OWERROR_LOAD_FIRST_SECRET_FAILED 101\r
+#define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED 102\r
+#define OWERROR_KEY_OUT_OF_RANGE 103\r
+#define OWERROR_BLOCK_ID_OUT_OF_RANGE 104\r
+#define OWERROR_PASSWORDS_ENABLED 105\r
+#define OWERROR_PASSWORD_INVALID 106\r
+#define OWERROR_NO_READ_ONLY_PASSWORD 107\r
+#define OWERROR_NO_READ_WRITE_PASSWORD 108\r
+#define OWERROR_OW_SHORTED 109\r
+#define OWERROR_ADAPTER_ERROR 110\r
+#define OWERROR_EOP_COPY_SCRATCHPAD_FAILED 111\r
+#define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED 112\r
+#define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY 113\r
+#define OWERROR_HYGRO_STOP_MISSION_ERROR 114\r
+#define OWERROR_PORTNUM_ERROR 115\r
+#define OWERROR_LEVEL_FAILED 116\r
+#define OWERROR_PASSWORD_NOT_SET 117\r
+#define OWERROR_LATCH_NOT_SET 118\r
+#define OWERROR_LIBUSB_OPEN_FAILED 119\r
+#define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED 120\r
+#define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR 121\r
+#define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR 122\r
+#define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR 123\r
+#define OWERROR_LIBUSB_NO_ADAPTER_FOUND 124\r
+ \r
+\r
+ // One Wire functions defined in ownetu.c\r
+ SMALLINT owFirst_(int portnum, SMALLINT do_reset, SMALLINT alarm_only);\r
+ SMALLINT owNext_(int portnum, SMALLINT do_reset, SMALLINT alarm_only);\r
+ void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read);\r
+ void owFamilySearchSetup(int portnum, SMALLINT search_family);\r
+ void owSkipFamily(int portnum);\r
+ SMALLINT owAccess(int portnum);\r
+ SMALLINT owVerify(int portnum, SMALLINT alarm_only);\r
+ SMALLINT owOverdriveAccess(int portnum);\r
+\r
+\r
+ // external One Wire functions defined in owsesu.c\r
+ SMALLINT owAcquire(int portnum, char *port_zstr);\r
+ int owAcquireEx(char *port_zstr);\r
+ void owRelease(int portnum);\r
+\r
+ // external One Wire functions defined in findtype.c\r
+ // SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int);\r
+\r
+ // external One Wire functions from link layer owllu.c\r
+ SMALLINT owTouchReset(int portnum);\r
+ SMALLINT owTouchBit(int portnum, SMALLINT sendbit);\r
+ SMALLINT owTouchByte(int portnum, SMALLINT sendbyte);\r
+ SMALLINT owWriteByte(int portnum, SMALLINT sendbyte);\r
+ SMALLINT owReadByte(int portnum);\r
+ SMALLINT owSpeed(int portnum, SMALLINT new_speed);\r
+ SMALLINT owLevel(int portnum, SMALLINT new_level);\r
+ SMALLINT owProgramPulse(int portnum);\r
+ SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte);\r
+ SMALLINT owReadBytePower(int portnum);\r
+ SMALLINT owHasPowerDelivery(int portnum);\r
+ SMALLINT owHasProgramPulse(int portnum);\r
+ SMALLINT owHasOverDrive(int portnum);\r
+ SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse);\r
+ // external One Wire global from owllu.c\r
+ extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE;\r
+\r
+ // external One Wire functions from transaction layer in owtrnu.c\r
+ SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len);\r
+ SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf);\r
+ SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf,\r
+ SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type);\r
+ SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,\r
+ SMALLINT crc_type, SMALLINT do_access);\r
+\r
+ // link functions\r
+ void msDelay(int len);\r
+ long msGettick(void);\r
+\r
+ // ioutil.c functions prototypes\r
+ int EnterString(char *msg, char *buf, int min, int max);\r
+ int EnterNum(char *msg, int numchars, long *value, long min, long max);\r
+ int EnterHex(char *msg, int numchars, ulong *value);\r
+ int ToHex(char ch);\r
+ int getkeystroke(void);\r
+ int key_abort(void);\r
+ void ExitProg(char *msg, int exit_code);\r
+ int getData(uchar *write_buff, int max_len, SMALLINT gethex);\r
+ void PrintHex(uchar* buffer, int cnt);\r
+ void PrintChars(uchar* buffer, int cnt);\r
+ void PrintSerialNum(uchar* buffer);\r
+\r
+ // external functions defined in crcutil.c\r
+ void setcrc16(int portnum, ushort reset);\r
+ ushort docrc16(int portnum, ushort cdata);\r
+ void setcrc8(int portnum, uchar reset);\r
+ uchar docrc8(int portnum, uchar x);\r
+\r
+ extern int owInUse;\r
+\r
+#endif //OWNET_H\r
--- /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
+// TMEXLnk.C - Link module to call on TMEX low-level functions to\r
+// excersize the general 1-Wire Net functions.\r
+// (Requires TMEX 3.11 or newer)\r
+//\r
+// Version: 3.00\r
+//\r
+// History: 1.00 -> 1.01 Return values in owLevel corrected.\r
+// Added function msDelay.\r
+// 1.02 -> 1.03 Add msGettick, always return owLevel success\r
+// to hide adapters (DS9097E) that do not have\r
+// power delivery capabilities.\r
+// 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for\r
+// multiple ports.\r
+// 2.10 -> 3.00 Added owReadBitPower and owWriteBytePower\r
+\r
+#include "ownet.h"\r
+#include <windows.h>\r
+\r
+// external TMEX variables\r
+extern long SessionHandle[MAX_PORTNUM];\r
+extern uchar StateBuffer[MAX_PORTNUM][5120];\r
+extern "C" short far pascal TMTouchByte(long, short);\r
+extern "C" short far pascal TMTouchReset(long);\r
+extern "C" short far pascal TMTouchBit(long, short);\r
+extern "C" short far pascal TMProgramPulse(long);\r
+extern "C" short far pascal TMOneWireCom(long, short, short);\r
+extern "C" short far pascal TMOneWireLevel(long, short, short, short);\r
+\r
+// globals\r
+SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE = FALSE; // for compatibility purposes\r
+\r
+//--------------------------------------------------------------------------\r
+// Reset all of the devices on the 1-Wire Net and return the result.\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): presense pulse(s) detected, device(s) reset\r
+// FALSE(0): no presense pulses detected\r
+//\r
+SMALLINT owTouchReset(int portnum)\r
+{\r
+ int result;\r
+\r
+ // Assume valid Session\r
+ result = TMTouchReset(SessionHandle[portnum]);\r
+\r
+ // success if the normal or alarm presence\r
+ if ((result == 1) || (result == 2))\r
+ return TRUE;\r
+ else\r
+ return FALSE;\r
+}\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 1 bit of communication to the 1-Wire Net and return the\r
+// result 1 bit read from the 1-Wire Net. The parameter 'sendbit'\r
+// least significant bit is used and the least significant bit\r
+// of the result is the return bit.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'sendbit' - the least significant bit is the bit to send\r
+//\r
+// Returns: 0: 0 bit read from sendbit\r
+// 1: 1 bit read from sendbit\r
+//\r
+SMALLINT owTouchBit(int portnum, SMALLINT sendbit)\r
+{\r
+ // Assume valid Session\r
+ return TMTouchBit(SessionHandle[portnum],(short)sendbit);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of communication to the 1-Wire Net and verify that the\r
+// 8 bits read from the 1-Wire Net is the same (write operation).\r
+// The parameter 'sendbyte' least significant 8 bits are used.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'sendbyte' - 8 bits to send (least significant byte)\r
+//\r
+// Returns: TRUE: bytes written and echo was the same\r
+// FALSE: echo was not the same\r
+//\r
+SMALLINT owTouchByte(int portnum, SMALLINT sendbyte)\r
+{\r
+ // Assume valid Session\r
+ return TMTouchByte(SessionHandle[portnum],(short)sendbyte);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of communication to the MicroLAN and verify that the\r
+// 8 bits read from the MicroLAN is the same (write operation).\r
+// The parameter 'sendbyte' least significant 8 bits are used.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'sendbyte' - 8 bits to send (least significant byte)\r
+//\r
+// Returns: TRUE: bytes written and echo was the same\r
+// FALSE: echo was not the same\r
+//\r
+SMALLINT owWriteByte(int portnum, SMALLINT sendbyte)\r
+{\r
+ return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of read communication to the 1-Wire Net and and return the\r
+// result 8 bits read from the 1-Wire Net.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+//\r
+// Returns: TRUE: 8 bytes read from 1-Wire Net\r
+// FALSE: the 8 bytes were not read\r
+//\r
+SMALLINT owReadByte(int portnum)\r
+{\r
+ return owTouchByte(portnum,0xFF);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Set the 1-Wire Net communucation speed.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'new_speed' - new speed defined as\r
+// MODE_NORMAL 0x00\r
+// MODE_OVERDRIVE 0x01\r
+//\r
+// Returns: current 1-Wire Net speed\r
+//\r
+SMALLINT owSpeed(int portnum, SMALLINT new_speed)\r
+{\r
+ return TMOneWireCom(SessionHandle[portnum],0,(short)new_speed);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Set the 1-Wire Net line level. The values for new_level are\r
+// as follows:\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'new_level' - new level defined as\r
+// MODE_NORMAL 0x00\r
+// MODE_STRONG5 0x02\r
+// MODE_PROGRAM 0x04\r
+// MODE_BREAK 0x08 (not supported)\r
+//\r
+// Returns: current 1-Wire Net level\r
+//\r
+SMALLINT owLevel(int portnum, SMALLINT new_level)\r
+{\r
+ int rslt;\r
+ int docheck = FALSE;\r
+\r
+ // check for DS2480 bug\r
+ if (((SessionHandle[portnum] & 0x0F0) == 0x050) &&\r
+ (TMOneWireLevel(SessionHandle[portnum],1,0,0) == 1))\r
+ docheck = TRUE;\r
+\r
+ switch (new_level)\r
+ {\r
+ case MODE_NORMAL:\r
+ rslt = TMOneWireLevel(SessionHandle[portnum],0,0,0);\r
+ // test code for DS2480 bug\r
+ if (docheck)\r
+ TMTouchBit(SessionHandle[portnum],1);\r
+ break;\r
+ case MODE_STRONG5:\r
+ rslt = TMOneWireLevel(SessionHandle[portnum],0,1,0);\r
+ break;\r
+ case MODE_PROGRAM:\r
+ rslt = TMOneWireLevel(SessionHandle[portnum],0,3,0);\r
+ break;\r
+ case MODE_BREAK:\r
+ rslt = TMOneWireLevel(SessionHandle[portnum],0,2,0);\r
+ break;\r
+ default:\r
+ rslt = 0;\r
+ }\r
+\r
+ // Assume TMEX can do it so always return NewLevel\r
+ return new_level;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure creates a fixed 480 microseconds 12 volt pulse\r
+// on the 1-Wire Net for programming EPROM iButtons.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+//\r
+// Returns: TRUE successful\r
+// FALSE program voltage not available\r
+//\r
+SMALLINT owProgramPulse(int portnum)\r
+{\r
+ return TMProgramPulse(SessionHandle[portnum]);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Description:\r
+// Delay for at least 'len' ms\r
+//\r
+void msDelay(int len)\r
+{\r
+ Sleep(len);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Get the current millisecond tick count. Does not have to represent\r
+// an actual time, it just needs to be an incrementing timer.\r
+//\r
+long msGettick(void)\r
+{\r
+ return GetTickCount();\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of communication to the 1-Wire Net and verify that the\r
+// 8 bits read from the 1-Wire Net is the same (write operation). \r
+// The parameter 'sendbyte' least significant 8 bits are used. After the\r
+// 8 bits are sent change the level of the 1-Wire net.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+// 'sendbyte' - 8 bits to send (least significant byte)\r
+//\r
+// Returns: TRUE: bytes written and echo was the same\r
+// FALSE: echo was not the same \r
+//\r
+SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte)\r
+{\r
+ // prime for power delivery after byte\r
+ TMOneWireLevel(SessionHandle[portnum],0,1,2);\r
+\r
+ // send the byte and start strong pullup\r
+ if(TMTouchByte(SessionHandle[portnum],(short)sendbyte) != sendbyte)\r
+ {\r
+ TMOneWireLevel(SessionHandle[portnum],0,0,0);\r
+ return FALSE;\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Read 8 bits of communication to the 1-Wire Net and verify that the\r
+// 8 bits read from the 1-Wire Net is the same (write operation). \r
+// The parameter 'sendbyte' least significant 8 bits are used. After the\r
+// 8 bits are read change the level of the 1-Wire net.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+// 'sendbyte' - 8 bits to send (least significant byte)\r
+//\r
+// Returns: TRUE: bytes written and echo was the same\r
+// FALSE: echo was not the same \r
+//\r
+SMALLINT owReadBytePower(int portnum)\r
+{\r
+ SMALLINT sendbyte = 0xFF;\r
+\r
+ // prime for power delivery after byte\r
+ TMOneWireLevel(SessionHandle[portnum],0,1,2);\r
+\r
+ // send the byte and start strong pullup\r
+ return TMTouchByte(SessionHandle[portnum],(short)sendbyte);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 1 bit of communication to the 1-Wire Net and verify that the\r
+// response matches the 'applyPowerResponse' bit and apply power delivery\r
+// to the 1-Wire net. Note that some implementations may apply the power\r
+// first and then turn it off if the response is incorrect.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+// 'applyPowerResponse' - 1 bit response to check, if correct then start\r
+// power delivery \r
+//\r
+// Returns: TRUE: bit written and response correct, strong pullup now on\r
+// FALSE: response incorrect\r
+//\r
+SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse)\r
+{\r
+ // prime for power delivery after bit\r
+ TMOneWireLevel(SessionHandle[portnum],0,1,1);\r
+\r
+ // send the byte and start strong pullup\r
+ if(TMTouchBit(SessionHandle[portnum],0x01) != applyPowerResponse)\r
+ {\r
+ TMOneWireLevel(SessionHandle[portnum],0,0,0);\r
+ return FALSE;\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure indicates wether the adapter can deliver power.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+//\r
+// Returns: TRUE because all userial adapters have over drive. \r
+//\r
+SMALLINT owHasPowerDelivery(int portnum)\r
+{\r
+ return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure indicates wether the adapter can deliver power.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+//\r
+// Returns: TRUE because all userial adapters have over drive. \r
+//\r
+SMALLINT owHasOverDrive(int portnum)\r
+{\r
+ return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure creates a fixed 480 microseconds 12 volt pulse \r
+// on the 1-Wire Net for programming EPROM iButtons.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to\r
+// OpenCOM to indicate the port number.\r
+//\r
+// Returns: TRUE program volatage available\r
+// FALSE program voltage not available \r
+SMALLINT owHasProgramPulse(int portnum)\r
+{\r
+ return TMProgramPulse(SessionHandle[portnum]);\r
+}
\ No newline at end of file
--- /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
--- /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
+// owsestmx.c - Acquire and release a Session on the 1-Wire Net using TMEX.\r
+// (Requires TMEX 3.11 or newer)\r
+//\r
+// Version: 2.01\r
+//\r
+// History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for\r
+// multiple ports.\r
+// 2.00 -> 2.01 Added support for owError library.\r
+//\r
+\r
+#include <stdio.h>\r
+#include <windows.h>\r
+#include "ownet.h"\r
+\r
+// external function prototypes\r
+extern "C" long far pascal TMExtendedStartSession(short, short, void far *);\r
+extern "C" short far pascal TMEndSession(long);\r
+extern "C" short far pascal TMClose(long);\r
+extern "C" short far pascal TMSetup(long);\r
+extern "C" short far pascal TMReadDefaultPort(short far *, short far *);\r
+extern "C" short far pascal TMOneWireCom(\r
+ long session_handle, // session handle for the desired 1-Wire network\r
+ short Operation,// Read (1) or Set (0) the communication rate\r
+ short TimeMode // communication rate number\r
+ );\r
+short PortNum=1,PortType=2;\r
+long SessionHandle[MAX_PORTNUM];\r
+SMALLINT handle_init = FALSE;\r
+\r
+//---------------------------------------------------------------------------\r
+// Attempt to acquire a 1-Wire net using a com port and a DS2480 based\r
+// adapter.\r
+//\r
+// 'port_zstr' - zero terminated port name. For this platform\r
+// use format {port number, port type}.\r
+//\r
+// Returns: port number and -1 if not successful in setting up the port.\r
+//\r
+int owAcquireEx(char *port_zstr)\r
+{\r
+ int portnum;\r
+ int string_counter, counter, i, lenmax;\r
+ char portnum_str[15];\r
+ char porttype_str[15];\r
+ void *tmex_options = NULL;\r
+\r
+ if(!handle_init)\r
+ {\r
+ for(i=0; i<MAX_PORTNUM; i++)\r
+ SessionHandle[i] = 0;\r
+ handle_init = TRUE;\r
+ }\r
+\r
+ // check to find first available handle slot\r
+ for(portnum = 0; portnum<MAX_PORTNUM; portnum++)\r
+ {\r
+ if(!SessionHandle[portnum])\r
+ break;\r
+ }\r
+ OWASSERT( portnum<MAX_PORTNUM, OWERROR_PORTNUM_ERROR, -1 );\r
+\r
+ // convert the string in port_zstr to be the port number and port type\r
+ if(port_zstr)\r
+ {\r
+ lenmax = strlen(port_zstr);\r
+ if (lenmax > 12)\r
+ lenmax = 12;\r
+ string_counter = 1;\r
+ counter = 0;\r
+ do\r
+ {\r
+ portnum_str[counter] = port_zstr[string_counter];\r
+\r
+ counter++;\r
+ string_counter++;\r
+ }\r
+ while((port_zstr[string_counter] != ',') && (string_counter <= lenmax));\r
+\r
+ portnum_str[counter] = '\0';\r
+\r
+ string_counter++;\r
+ counter = 0;\r
+\r
+ do\r
+ {\r
+ porttype_str[counter] = port_zstr[string_counter];\r
+\r
+ counter++;\r
+ string_counter++;\r
+ }\r
+ while((port_zstr[string_counter] != '}') && (string_counter <= lenmax));\r
+\r
+ porttype_str[counter] = '\0';\r
+\r
+ PortNum = atoi(portnum_str);\r
+ PortType = atoi(porttype_str);\r
+ }\r
+\r
+ // open a session\r
+ SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,tmex_options);\r
+\r
+ // check the session handle\r
+ if (SessionHandle[portnum] <= 0)\r
+ {\r
+ OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);\r
+ SessionHandle[portnum] = 0;\r
+ return -1;\r
+ }\r
+\r
+ // setup the port\r
+ if (TMSetup(SessionHandle[portnum]) != 1)\r
+ {\r
+ TMClose(SessionHandle[portnum]);\r
+ TMEndSession(SessionHandle[portnum]);\r
+ OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);\r
+ SessionHandle[portnum] = 0;\r
+ return -1;\r
+ }\r
+ \r
+ return portnum;\r
+}\r
+\r
+//---------------------------------------------------------------------------\r
+// Attempt to acquire a 1-Wire net using a com port and a DS2480 based\r
+// adapter.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'port_zstr' - zero terminated port name. For this platform\r
+// use format COMX where X is the port number.\r
+//\r
+// Returns: TRUE - success, COM port opened\r
+//\r
+SMALLINT owAcquire(int portnum, char *port_zstr)\r
+{\r
+ int i;\r
+\r
+ if(!handle_init)\r
+ {\r
+ for(i=0; i<MAX_PORTNUM; i++)\r
+ SessionHandle[i] = 0;\r
+ handle_init = TRUE;\r
+ }\r
+\r
+ OWASSERT( portnum<MAX_PORTNUM && portnum>=0 && !SessionHandle[portnum],\r
+ OWERROR_PORTNUM_ERROR, FALSE );\r
+\r
+ // read the default PortNum and PortType\r
+ TMReadDefaultPort(&PortNum,&PortType);\r
+\r
+ // convert the string in port_zstr to be the port number\r
+ PortNum = atoi(port_zstr);\r
+\r
+ // open a session\r
+ SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,NULL);\r
+\r
+ // check the session handle\r
+ if (SessionHandle[portnum] <= 0)\r
+ {\r
+ OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);\r
+ SessionHandle[portnum] = 0;\r
+ return FALSE;\r
+ }\r
+\r
+ // setup the port\r
+ if (TMSetup(SessionHandle[portnum]) != 1)\r
+ {\r
+ TMClose(SessionHandle[portnum]);\r
+ TMEndSession(SessionHandle[portnum]);\r
+ OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);\r
+ SessionHandle[portnum] = 0;\r
+ return FALSE;\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+//---------------------------------------------------------------------------\r
+// Release the previously acquired a 1-Wire net.\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+//\r
+void owRelease(int portnum)\r
+{\r
+ TMClose(SessionHandle[portnum]);\r
+ TMEndSession(SessionHandle[portnum]);\r
+ SessionHandle[portnum] = 0;\r
+}\r
+\r
--- /dev/null
+//---------------------------------------------------------------------------\r
+// Copyright (C) 1999 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 transport functions.\r
+//\r
+// Version: 3.00\r
+//\r
+\r
+#include "ownet.h"\r
+#include <windows.h>\r
+\r
+// external TMEX variables\r
+extern long SessionHandle[MAX_PORTNUM];\r
+extern "C" short far pascal TMBlockIO(long, uchar *, short);\r
+extern "C" short far pascal TMBlockStream(long, uchar *, short);\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owBlock' transfers a block of data to and from the\r
+// 1-Wire Net with an optional reset at the begining of communication.\r
+// The result is returned in the same buffer.\r
+//\r
+// 'do_reset' - cause a owTouchReset to occure at the begining of\r
+// communication TRUE(1) or not FALSE(0)\r
+// 'tran_buf' - pointer to a block of unsigned\r
+// chars of length 'TranferLength' that will be sent\r
+// to the 1-Wire Net\r
+// 'tran_len' - length in bytes to transfer\r
+// Supported devices: all\r
+//\r
+// Returns: TRUE (1) : The optional reset returned a valid\r
+// presence (do_reset == TRUE) or there\r
+// was no reset required.\r
+// FALSE (0): The reset did not return a valid prsence\r
+// (do_reset == TRUE).\r
+//\r
+// The maximum tran_len is 64\r
+//\r
+SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len)\r
+{\r
+ short rslt;\r
+\r
+ // check for a block too big\r
+ if (tran_len > 192)\r
+ {\r
+ OWERROR(OWERROR_BLOCK_TOO_BIG);\r
+ return FALSE;\r
+ }\r
+\r
+ // check if need to do a owTouchReset first\r
+ if (do_reset)\r
+ rslt = TMBlockIO(SessionHandle[portnum], tran_buf, (short)tran_len);\r
+ else\r
+ rslt = TMBlockStream(SessionHandle[portnum], tran_buf, (short)tran_len);\r
+\r
+ return (rslt == tran_len);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Write a byte to an EPROM 1-Wire device.\r
+//\r
+// Supported devices: crc_type=0(CRC8)\r
+// DS1982\r
+// crc_type=1(CRC16)\r
+// DS1985, DS1986, DS2407\r
+//\r
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
+// indicate the symbolic port number.\r
+// 'write_byte' - byte to program\r
+// 'addr' - address of byte to program\r
+// 'write_cmd' - command used to write (0x0F reg mem, 0x55 status)\r
+// 'crc_type' - CRC used (0 CRC8, 1 CRC16)\r
+// 'do_access' - Flag to access device for each byte\r
+// (0 skip access, 1 do the access)\r
+// WARNING, only use do_access=0 if programing the NEXT\r
+// byte immediatly after the previous byte.\r
+//\r
+// Returns: >=0 success, this is the resulting byte from the program\r
+// effort\r
+// -1 error, device not connected or program pulse voltage\r
+// not available\r
+//\r
+SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,\r
+ SMALLINT crc_type, SMALLINT do_access)\r
+{\r
+ ushort lastcrc16;\r
+ uchar lastcrc8;\r
+\r
+ // optionally access the device\r
+ if (do_access)\r
+ {\r
+ if (!owAccess(portnum))\r
+ {\r
+ OWERROR(OWERROR_ACCESS_FAILED);\r
+ return -1;\r
+ }\r
+\r
+ // send the write command\r
+ if (!owWriteByte(portnum,write_cmd))\r
+ {\r
+ OWERROR(OWERROR_WRITE_BYTE_FAILED);\r
+ return -1;\r
+ }\r
+\r
+ // send the address\r
+ if (!owWriteByte(portnum,addr & 0xFF) || !owWriteByte(portnum,addr >> 8))\r
+ {\r
+ OWERROR(OWERROR_WRITE_BYTE_FAILED);\r
+ return -1;\r
+ }\r
+ }\r
+\r
+ // send the data to write\r
+ if (!owWriteByte(portnum,write_byte))\r
+ {\r
+ OWERROR(OWERROR_WRITE_BYTE_FAILED);\r
+ return -1;\r
+ }\r
+\r
+ // read the CRC\r
+ if (crc_type == 0)\r
+ {\r
+ // calculate CRC8\r
+ if (do_access)\r
+ {\r
+ setcrc8(portnum,0);\r
+ docrc8(portnum,(uchar)write_cmd);\r
+ docrc8(portnum,(uchar)(addr & 0xFF));\r
+ docrc8(portnum,(uchar)(addr >> 8));\r
+ }\r
+ else\r
+ setcrc8(portnum,(uchar)(addr & 0xFF));\r
+\r
+ docrc8(portnum,(uchar)write_byte);\r
+ // read and calculate the read crc\r
+ lastcrc8 = docrc8(portnum,(uchar)owReadByte(portnum));\r
+ // crc should now be 0x00\r
+ if (lastcrc8 != 0)\r
+ {\r
+ OWERROR(OWERROR_CRC_FAILED);\r
+ return -1;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ // CRC16\r
+ if (do_access)\r
+ {\r
+ setcrc16(portnum,0);\r
+ docrc16(portnum,(ushort)write_cmd);\r
+ docrc16(portnum,(ushort)(addr & 0xFF));\r
+ docrc16(portnum,(ushort)(addr >> 8));\r
+ }\r
+ else\r
+ setcrc16(portnum,(ushort)addr);\r
+ docrc16(portnum,(ushort)write_byte);\r
+ // read and calculate the read crc\r
+ docrc16(portnum,(ushort)owReadByte(portnum));\r
+ lastcrc16 = docrc16(portnum,(ushort)owReadByte(portnum));\r
+ // crc should now be 0xB001\r
+ if (lastcrc16 != 0xB001)\r
+ return -1;\r
+ }\r
+\r
+ // send the program pulse\r
+ if (!owProgramPulse(portnum))\r
+ {\r
+ OWERROR(OWERROR_PROGRAM_PULSE_FAILED);\r
+ return -1;\r
+ }\r
+\r
+ // read back and return the resulting byte\r
+ return owReadByte(portnum);\r
+}\r
+\r
+\r