X-Git-Url: http://git.smho.de/gw/?p=owTools.git;a=blobdiff_plain;f=src%2FowDevice.cpp;h=2c1ee64c5fbf9e39977a2a1cad6294a3a92b1033;hp=5d3e99a02509572d5034b51c9c4f3bee30e050aa;hb=f7b7cd722492679725b953a41717a3109c81813d;hpb=8b3ce8126a8bbc16822e939bc46f513e1c52b3d3 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);