From: Tobias Date: Mon, 8 Apr 2019 12:35:56 +0000 (+0200) Subject: remove compiler warnings of new compilerversion / X-Git-Url: http://git.smho.de/gw/?p=owTools.git;a=commitdiff_plain;h=f7b7cd722492679725b953a41717a3109c81813d remove compiler warnings of new compilerversion / add memory functions of DS2450 / add 0xCC by command line --- diff --git a/Makefile.am b/Makefile.am old mode 100755 new mode 100644 diff --git a/src/main.cpp b/src/main.cpp index c4e223d..51fd6c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,6 +129,7 @@ printf(" [database]\n"); printf(" [prefix] -> a prefix of all tables \n\n"); printf(" -r Search every time for new Devices\n"); printf(" -t [text_file] append comma separadet to text-file\n"); +printf(" -j Use 0xCC 0x44 to send convert temperature to all DS18B20 and DS2438\n"); printf(" -f [hexfile] flash new\n"); printf(" -n [\"id as 64bit Hex\"] change id \n"); printf(" example: -n \"5D02160084D9A220\" \n"); @@ -318,11 +319,13 @@ void continuous(std::vector *devices,int intervall,int headline,int s for (owDevice* dev :*devices) { for(int k=0;kmaxrepeat;k++){ - //std::vector data; - //data.push_back(0xCC); - //data.push_back(0x44); - //owi->Reset(); - //owi->Communicate(&data, 2, 0); + if (owCC_44_Temp>0) { + std::vector data; + data.push_back(0xCC); + data.push_back(0x44); + owi->Reset(); + owi->Communicate(&data, 2, 0); + } dev->convertAll(); if (owi->log->last()log->clear(); @@ -610,6 +613,10 @@ int main(int argc, char *argv[]) { interactive(owi); } else if (getArg("c")=="1") { + if (getArg("j")=="1") { + printf("Use 1-Wire command 0xCC 0x44 to send convert temperature to all DS18B20 and DS2438\n"); + owCC_44_Temp=1; + } int reload=(getArg("r")=="1"); owi->Find(); printf("\n"); @@ -829,8 +836,12 @@ int main(int argc, char *argv[]) { } else { unsigned long long l=strtoull(s.c_str(),NULL,16); if ((snum.num&0xFF)!=(l&0xFF)) { - printf("ERROR: Family of Device 0x%02X->0x%02X can not be changed\n",(int)(snum.num&0xFF),(int)(l&0xFF)); - exit(1); + printf("This command change family-fode of Device 0x%02X->0x%02X\n",(int)(snum.num&0xFF),(int)(l&0xFF)); + int resetid=questionYesNo("Are you sure?"); + if (resetid==0) { + printf("ERROR: Family of Device 0x%02X->0x%02X can not be changed\n",(int)(snum.num&0xFF),(int)(l&0xFF)); + exit(1); + } } snum.num=l; //printf("->%016llX\n",(unsigned long long)l); diff --git a/src/owCOMInterface.cpp b/src/owCOMInterface.cpp index 6b55e94..3bae680 100644 --- a/src/owCOMInterface.cpp +++ b/src/owCOMInterface.cpp @@ -331,7 +331,7 @@ int owCOMInterface::ReadCOM( int inlen, uint8_t *inbuf) FD_SET(fd,&filedescr); // set timeout to 10ms tval.tv_sec = 0; - tval.tv_usec = 20000; + tval.tv_usec = 20000; //TOOO CHECK!!!!!!!!!!!!!!!!!! // if byte available read or return bytes read if (select(fd+1,&filedescr,NULL,NULL,&tval) != 0) diff --git a/src/owDevice.cpp b/src/owDevice.cpp index 5d3e99a..2c1ee64 100644 --- a/src/owDevice.cpp +++ b/src/owDevice.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de +// Copyright (c) 2019, Tobias Mueller tm(at)tm3d.de // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -149,8 +149,8 @@ int owDevice::CommunicateShort(std::vector *data, int scount, int rcoun void owDevice::changeID(snum_t nid) { int i; if (nid.byte[0] != snum.byte[0]) { - owi->log->set(OWLOG_ERROR,"Family ID should not be changed, no correct ID"); - return; + owi->log->set(OWLOG_WARNING,"Family ID should not be changed, no correct ID"); + //return; } std::vector id; for(i=0;i<7;i++) id.push_back(nid.byte[i]); @@ -231,10 +231,11 @@ int owDeviceDS18B20::readScratchpad(std::vector *sp) { int owDeviceDS18B20::convertAll() { std::vector sp; - sp.push_back(0x44); - Communicate(&sp, 1, 0); ///######################################################## - usleep(750000); - + if (owCC_44_Temp==0) { + sp.push_back(0x44); + Communicate(&sp, 1, 0); ///######################################################## + usleep(750000); + } if (readScratchpad(&sp)) { int16_t tsht; tsht = sp[0] | ((int)sp[1] << 8); @@ -242,7 +243,7 @@ int owDeviceDS18B20::convertAll() { tsht |= 0xFFFFF0000; raw[0]=tsht; values[0]=config->calculateValue(0, raw); - return 1; + return 1; } return 0; } @@ -375,10 +376,12 @@ inline int16_t ow_fconvert(uint8_t b1, uint16_t b2) { int owDeviceDS2438::convertAll() { for(int k=0;kmaxrepeat;k++) { std::vector sp; - sp.push_back(0x44); - Communicate(&sp, 1, 0);///######################################################## - if (owi->log->last()>=OWLOG_ERROR) continue; - usleep(100000); + if (owCC_44_Temp==0) { + sp.push_back(0x44); + Communicate(&sp, 1, 0);///######################################################## + if (owi->log->last()>=OWLOG_ERROR) continue; + usleep(100000); + } if (setConfigByte(0x08)<=0) continue; for(int k=0;kmaxrepeat;k++) { sp.clear(); @@ -432,7 +435,7 @@ int owDeviceDS2450::convertAll() { return 0; } std::vector sp; - readMemory(0,&sp); + readMemory(0,0,8,&sp); if (owi->log->last()>=OWLOG_WARNING) { return 0; } @@ -447,7 +450,69 @@ int owDeviceDS2450::convertAll() { } -void owDeviceDS2450::readMemory(uint8_t addr,std::vector *sp) { +int owDeviceDS2450::readMemory(int page,int start, int count,std::vector *data) { + std::vector cl; + cl.push_back(0xAA); + cl.push_back(page*8+start); + cl.push_back(0x00); + Communicate(&cl,3,10-start); + if (owi->log->last()>=OWLOG_WARNING) { + return 0; + } + if (!owi->testCRC16(cl)) { + for (uint8_t v :cl) printf("%02X ",v); + printf("\n"); + owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Memory of DS2450"); + return 0; + } + data->clear(); + data->insert(data->begin(),cl.begin()+3,cl.end()-2); + return count; +} +int owDeviceDS2450::writeMemory(int page,int start, int count,std::vector *data) { + std::vector cl; + cl.push_back(0x55); + cl.push_back(page*8+start); + cl.push_back(0x00); + owi->MatchRom(snum); + if (owi->log->last()>=OWLOG_WARNING) { + return 0; + } + int i=0; + for(uint8_t b: (*data)) { + cl.push_back(b); + owi->Communicate(&cl,cl.size(),2); + if (owi->log->last()>=OWLOG_WARNING) { + return 0; + } + if (i>0) { + if (!owi->testCRC16(cl,i+page*8+start)) { + owi->log->set(OWLOG_ERROR,"CRC ERROR Writing Memory of DS2450"); + return 0; + } + } else { + if (!owi->testCRC16(cl)) { + owi->log->set(OWLOG_ERROR,"CRC ERROR Writing Memory of DS2450"); + return 0; + } + } + cl.clear(); + owi->Communicate(&cl, 0, 1); + if (owi->log->last()>=OWLOG_WARNING) { + return 0; + } + if (cl[0] != b) { + owi->log->set(OWLOG_ERROR,"ERROR Writing Memory of DS2450"); + return 0; + } + cl.clear(); + i++; + } + return count; +} + + +void owDeviceDS2450::readMemory_int(uint8_t addr,std::vector *sp) { std::vector cl; cl.push_back(0xAA); cl.push_back(addr); @@ -466,7 +531,7 @@ void owDeviceDS2450::readMemory(uint8_t addr,std::vector *sp) { sp->insert(sp->begin(),cl.begin()+3,cl.end()-2); } -void owDeviceDS2450::writeMemory(uint8_t addr,std::vector *sp) { +void owDeviceDS2450::writeMemory_int(uint8_t addr,std::vector *sp) { std::vector cl; cl.push_back(0x55); cl.push_back(addr); diff --git a/src/owInterface.cpp b/src/owInterface.cpp index b4d5d93..3da8460 100644 --- a/src/owInterface.cpp +++ b/src/owInterface.cpp @@ -38,6 +38,7 @@ #include #include "hexfile.h" +uint8_t owCC_44_Temp=0; #ifdef WIN void usleep(__int64 usec) @@ -118,6 +119,16 @@ uint16_t owInterface::calcCRC16(std::vector data) { int owInterface::testCRC16(std::vector data) { return calcCRC16(data)==0xB001; } + +int owInterface::testCRC16(std::vector data,uint16_t load) { + crc16=load; + for(uint8_t v:data) { + docrc16(v); + } + return crc16==0xB001; + +} + void owInterface::resetFlasher(uint64_t id) { // go back from Bootloader std::vector data; diff --git a/src/owInterface.h b/src/owInterface.h index 7e1edb0..0a568df 100644 --- a/src/owInterface.h +++ b/src/owInterface.h @@ -107,6 +107,8 @@ class owDeviceConfig; #endif +extern uint8_t owCC_44_Temp; + class owLog { int lcount; std::string logtext; @@ -231,6 +233,7 @@ public: uint8_t calcCRC8(std::vector data); uint16_t calcCRC16(std::vector data); int testCRC16(std::vector data); + int testCRC16(std::vector data,uint16_t load); void resetFlasher(uint64_t id); void resetID(uint64_t id); @@ -320,8 +323,10 @@ public: virtual void setDefaultConfig(); virtual int convertAll(); - void readMemory(uint8_t addr,std::vector *sp); - void writeMemory(uint8_t addr,std::vector *sp); + virtual int readMemory(int page,int start, int count,std::vector *data); + virtual int writeMemory(int page,int start, int count,std::vector *data); + void readMemory_int(uint8_t addr,std::vector *sp); + void writeMemory_int(uint8_t addr,std::vector *sp); void convert(uint8_t mask, uint8_t preset); virtual int getPageSize() {return 8;} diff --git a/src/owUSBInterface.cpp b/src/owUSBInterface.cpp index 0aa82d4..8768663 100644 --- a/src/owUSBInterface.cpp +++ b/src/owUSBInterface.cpp @@ -284,7 +284,7 @@ uint8_t owUSBInterface::sendrecivBit(uint8_t bit) { // success, read the result nBytes = 1; if (DS2490Read(hDevice, buf, &nBytes)) { - usleep(70); + usleep(200); return buf[0]; } else