X-Git-Url: http://git.smho.de/gw/?a=blobdiff_plain;f=src%2FowDevice.cpp;h=d5683c1696aa6d0eb7d42e56e57519e08de73d9b;hb=HEAD;hp=5d3e99a02509572d5034b51c9c4f3bee30e050aa;hpb=8b3ce8126a8bbc16822e939bc46f513e1c52b3d3;p=owTools.git diff --git a/src/owDevice.cpp b/src/owDevice.cpp index 5d3e99a..d5683c1 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,11 +243,18 @@ int owDeviceDS18B20::convertAll() { tsht |= 0xFFFFF0000; raw[0]=tsht; values[0]=config->calculateValue(0, raw); - return 1; + return 1; } return 0; } +int owDeviceDS18B20::readMemory(int page,int start, int count,std::vector *data) { + std::vector d; + readScratchpad(&d); + data->insert(data->begin(),d.begin()+start,d.end()); + return 8; +} + void owDeviceDS2438::setDefaultConfig() { config->setConfig({1,6, 6,8, 4,7, 6,17, 0,2,3,12,4,0,0,0,0,0,0,0,0,0,0,0}); @@ -375,10 +383,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 +442,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 +457,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 +538,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); @@ -604,5 +676,130 @@ int owDeviceDS2423::writeMemory(int page,int start, int count,std::vectorsetConfig({0,13, 0,13, 0,13, 0,13, 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}); + configstate=OWDCS_DEFAULT; +} +int owDeviceDS2408::convertAll() { + std::vector da; + /*da.push_back(0x11); + da.push_back(0x22); + da.push_back(0x34); + writeMemory(0,0x8b,3,&da); + readMemory(0,0x88,10,&da); + printf("\n____________________________\n"); + readChannelAccess(80,&da); + owi->log->clear(); + da.clear(); + da.push_back(0x11); + da.push_back(0x12); + da.push_back(0x31); + da.push_back(0x14); + da.push_back(0x55); + da.push_back(0x63); + da.push_back(0x70); + owi->log->clear(); + + writeChannelAccess(7,&da);*/ + return 1; +} +int owDeviceDS2408::readMemory(int page,int start, int count,std::vector *data) { + std::vector cl; + cl.push_back(0xF0); + cl.push_back(start&0xFF); + cl.push_back(start>>8); + if (start>=0x90) { + owi->log->set(OWLOG_WARNING,"DS2408 reading Register. Address value to hight"); + return 0; + } + count=0x90-start; + + Communicate(&cl, 3,count+2 ); + for (uint8_t v :cl) printf("%02X ",v);;printf("\n"); + if (!owi->testCRC16(cl)) { + owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Register of DS2408"); + return 0; + } + data->clear(); + data->insert(data->begin(),cl.begin()+3+start,cl.begin()+start+3+count); + return count; + +} + +int owDeviceDS2408::writeMemory(int page,int start, int count,std::vector *data) { + std::vector cl; + cl.push_back(0xCC); + cl.push_back(start&0xFF); + cl.push_back(start>>8); + if ((start<0x8b)&&(start>0x8b)) { + owi->log->set(OWLOG_WARNING,"DS2408 writing Register. Address value not match 0x8B 0x8C 0x8D"); + return 0; + } + if ((142-start) *data) { + std::vector cl; + cl.push_back(0xF5); + Communicate(&cl, 1,34 ); + int read=0; + for (uint8_t v :cl) printf("%02X ",v);;printf("\n"); + if (!owi->testCRC16(cl)) { + owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Register of DS2408"); + return 0; + } + read=32; + data->clear(); + data->insert(data->begin(),cl.begin()+1,cl.begin()+33); + + while (readCommunicate(&cl,0,34); + for (uint8_t v :cl) printf("%02X ",v);;printf("\n"); + if (!owi->testCRC16(cl)) { + owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Register of DS2408"); + return read; + } + data->insert(data->begin()+read,cl.begin(),cl.begin()+32); + read+=32; + + } + + + return read; +} +int owDeviceDS2408::writeChannelAccess(int count, std::vector *data) { + std::vector cl; + cl.push_back(0x5A); + Communicate(&cl, 1,0 ); + for(int i=0;iCommunicate(&cl,2,2); + for (uint8_t v :cl) printf("%02X ",v);;printf("\n"); + } + return count; +} +int owDeviceDS2408::resetActivityLatches() { + return 1; +} + + + +