From: Tobias Date: Fri, 29 Dec 2017 22:06:11 +0000 (+0100) Subject: Config Change.... 0xCC for temp measurement DS2438/DS18B20 X-Git-Url: https://git.smho.de/?a=commitdiff_plain;h=17ea6dc449cad650a4c783446ab048c12e44c666;p=owTools.git Config Change.... 0xCC for temp measurement DS2438/DS18B20 --- diff --git a/src/main.cpp b/src/main.cpp index 1d9e64f..de17078 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -285,10 +285,10 @@ 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); + data.push_back(0xCC); + data.push_back(0x44); + owi->Reset(); + owi->Communicate(&data, 2, 0); dev->convertAll(); if (owi->log->last()log->clear(); diff --git a/src/owDevice.cpp b/src/owDevice.cpp index e710102..60a8e99 100755 --- a/src/owDevice.cpp +++ b/src/owDevice.cpp @@ -231,8 +231,8 @@ int owDeviceDS18B20::readScratchpad(std::vector *sp) { int owDeviceDS18B20::convertAll() { std::vector sp; - sp.push_back(0x44); - Communicate(&sp, 1, 0); + //sp.push_back(0x44); + //communicate(&sp, 1, 0); ///######################################################## usleep(750000); if (readScratchpad(&sp)) { @@ -375,8 +375,8 @@ 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); + //sp.push_back(0x44); + //Communicate(&sp, 1, 0);///######################################################## if (owi->log->last()>=OWLOG_ERROR) continue; usleep(100000); if (setConfigByte(0x08)<=0) continue; @@ -457,6 +457,8 @@ void owDeviceDS2450::readMemory(uint8_t addr,std::vector *sp) { return; } 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; } @@ -503,6 +505,8 @@ void owDeviceDS2450::convert(uint8_t mask, uint8_t preset) { cl.push_back(preset); Communicate(&cl, 3, 2); if (!owi->testCRC16(cl)) { + for (uint8_t v :cl) printf("%02X ",v); + printf("\n"); owi->log->set(OWLOG_ERROR,"CRC ERROR Convert Command of DS2450"); return; } diff --git a/src/owDeviceConfig.cpp b/src/owDeviceConfig.cpp index 66bc9df..33f9769 100644 --- a/src/owDeviceConfig.cpp +++ b/src/owDeviceConfig.cpp @@ -279,7 +279,8 @@ double owDeviceConfig::calculateValueFromNumber(int code, int vn, std::vector data) { return calcCRC16(data)==0xB001; } -void owInterface::resetFlasher() { // go back from Bootloader +void owInterface::resetFlasher(uint64_t id) { // go back from Bootloader std::vector data; data.push_back(0x89); Wait_Free(); snum_t snum; - snum.num=0xfa55aa55aa55aaa3; + snum.num=id; MatchRom(snum); if (log->last()==OWLOG_ERROR) {Free(); return;} Communicate(&data, 1, 0); @@ -134,21 +134,21 @@ void owInterface::resetFlasher() { // go back from Bootloader usleep(50); } -void owInterface::resetID() { +void owInterface::resetID(uint64_t id) { std::vector data; data.push_back(0x8B); Wait_Free(); snum_t snum; - snum.num=0xfa55aa55aa55aaa3; + snum.num=id; MatchRom(snum); if (log->last()==OWLOG_ERROR) {Free(); return;} Communicate(&data, 1, 0); Free(); } -int owInterface::programmPage(int pagenr, std::vector page, int pagesize) { +int owInterface::programmPage(uint64_t id,int pagenr, std::vector page, int pagesize) { snum_t snum; - snum.num=0xfa55aa55aa55aaa3; + snum.num=id; // printf("programm page %i",pagenr); @@ -249,11 +249,7 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr 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; @@ -283,6 +279,10 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr found=1; break; } + if (dev->getNum().num==0x8A57AA57AA57AAA3) { + found=2; + break; + } } if (found==0) log->set(OWLOG_WARNING,"Bootloader not found"); r--; @@ -291,16 +291,43 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr log->set(OWLOG_ERROR,"Can not start Bootloader on this device %llX",dev.num); return -4; } + + unsigned int blcount=0; + + int blsize=64; + uint64_t id=0; + + if (found==1) { + log->set(OWLOG_INFO,"Bootloader on ATtiny84A found. Pagesize = 64 bytes"); + blsize=64; + blcount=hf->getBlockCount(64); + id=0xfa55aa55aa55aaa3; + if (blcount>118) { + log->set(OWLOG_ERROR,"Code to big, max 7552 Byte allowed (118 Pages). Code has %i pages!",blcount); + return -5; + } + } + if (found==2) { + log->set(OWLOG_INFO,"Bootloader on ATmega328PB found. Pagesize = 128 bytes"); + blsize=128; + blcount=hf->getBlockCount(128); + id=0x8A57AA57AA57AAA3; + if (blcount>248) { + log->set(OWLOG_ERROR,"Code to big, max 31744 Byte allowed (248 Pages). Code has %i pages!",blcount); + return -5; + } + + } 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 blk = hf->getBlock(i*64, 64); + std::vector blk = hf->getBlock(i*blsize, blsize); int errc = maxrepeat*5; while (errc != 0) { log->clear(); - if (programmPage(i, blk, 64) >= 0) { + if (programmPage(id,i, blk,blsize) >= 0) { if (progress) {printf("#");fflush(stdout);} break; } @@ -322,14 +349,14 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr } else { if (resetid) { log->set(OWLOG_INFO,"Set 1-Wire ID to ID in hexfile...",blcount); - resetID(); + resetID(id); #ifdef LINUX sleep(3); #endif #ifdef WIN Sleep(3000); #endif - resetID(); + resetID( id); #ifdef LINUX sleep(3); #endif @@ -342,14 +369,14 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr log->set(OWLOG_INFO,"Back from bootloader to normal device...",blcount); - resetFlasher(); + resetFlasher(id); #ifdef LINUX sleep(1); #endif #ifdef WIN Sleep(1000); #endif - resetFlasher(); + resetFlasher(id); #ifdef LINUX sleep(3); #endif