1 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the
14 // * All advertising materials mentioning features or use of this
15 // software must display the following acknowledgement: This product
16 // includes software developed by tm3d.de and its contributors.
17 // * Neither the name of tm3d.de nor the names of its contributors may
18 // be used to endorse or promote products derived from this software
19 // without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __OWINTERFACES_H_
35 #define __OWINTERFACES_H_
37 #if defined(WIN) || defined(LINUX)
39 #if defined(_WINDOWS) || defined(__WINDOWS__) || defined(_WIN32) || defined(WIN32)
62 #include "owDeviceConfig.h"
64 #if defined(_WINDOWS) || defined(__WINDOWS__) || defined(_WIN32) || defined(WIN32)
65 #define USE_WINDOWS_TIME 1
67 //#include "win32/usb.h" // libusb header
69 #define USE_WINDOWS_TIME 0
84 #define OWLOG_WARNING 2
89 #define BLUE_B "\033[1;34m"
90 #define COLOR_E "\033[0m"
91 #define C2_B "\033[0;36m"
92 #define C3_B "\033[3;34m"
93 #define C4_B "\033[1;33m"
94 #define C5_B "\033[4;33m"
95 #define CLE_B "\033[1;31m"
96 #define CLW_B "\033[1;33m"
121 virtual int set(int llevel,const char *format, ...) {
125 va_start (arg, format);
127 done = vsprintf (s, format, arg);
130 done = vsprintf_s(s,300, format, arg);
136 if (level>=loglevel) {
137 if (loglevel==OWLOG_ERROR) printf(CLE_B "%s" COLOR_E "\n",s);
138 else if (loglevel==OWLOG_WARNING) printf(CLW_B "%s" COLOR_E "\n",s);
139 else printf("%s\n",s);
143 virtual void clear() {
147 if (lcount) return level; else return 0;
149 virtual void setLogLevel(int llevel ){
166 uint8_t docrc8(uint8_t value);
167 uint16_t docrc16(uint16_t cdata);
169 // global search state
170 unsigned char ROM_NO[8];
172 int LastFamilyDiscrepancy;
178 std::vector<snum_t> device_nums;
179 std::vector<owDevice*> devices;
196 int isDevicesChanged() {
197 int dc=devices_changed;
201 virtual void Clean();
203 virtual int InitAdapter(std::string s) {
204 uint8_t param=atoi(s.c_str());
205 return InitAdapter(param);
207 virtual void ReleaseAdapter() {}
208 virtual int InitAdapter(uint8_t)=0;
209 //Return 1 if Devices Present
210 virtual int Reset()=0;
211 virtual uint8_t sendrecivBit(uint8_t bit) =0;
215 virtual uint8_t sendrecivByte(uint8_t byte) {
218 for(int i=0;i<8;i++) {
220 rb|=sendrecivBit(b&1)<<7;
226 virtual int MatchRom(snum_t snum);
227 virtual int Communicate(std::vector<uint8_t> *data, int scount, int rcount);
231 uint8_t calcCRC8(std::vector<uint8_t> data);
232 uint16_t calcCRC16(std::vector<uint8_t> data);
233 int testCRC16(std::vector<uint8_t> data);
235 void resetFlasher(uint64_t id);
236 void resetID(uint64_t id);
237 int programmPage(uint64_t id,int pagenr, std::vector<uint8_t> page, int pagesize);
238 int flashHEXFile(std::string filename,snum_t dev,int resetid,int progress);
241 virtual int owFirst() {
243 LastDeviceFlag = FALSE;
244 LastFamilyDiscrepancy = 0;
247 virtual int owNext() {
250 virtual ~owInterface() {
259 #define OWDCS_DEFAULT 1
268 std::vector<int32_t> raw;
270 owDeviceConfig *config;
272 std::vector<double> values;
273 int lastfound; //0 found in last searchrom, 1 found in the searchrom befor, and so on
274 owDevice(owInterface *owi_,snum_t num);
275 //return 1 for real Config, return 0 for DefaultConig
277 virtual void setDefaultConfig();
278 //Information zum owDevice
279 std::vector<std::string> getFamilyInfo();
281 snum_t getNum() {return snum;}
283 int Communicate(std::vector<uint8_t> *data, int scount, int rcount);
284 int CommunicateShort(std::vector<uint8_t> *data, int scount, int rcount);
285 void changeID(snum_t nid);
287 virtual int convertAll() {return 1;}
288 virtual int readMemory(int page,int start, int count,std::vector<uint8_t> *data) {return 0;};
289 virtual int writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {return 0;};
290 virtual int getPageSize() {return 0;}
291 virtual ~owDevice() {}
294 class owDeviceDS18B20:public owDevice {
296 owDeviceDS18B20(owInterface *owi_,snum_t num):owDevice(owi_,num) { }
297 virtual void setDefaultConfig();
298 int readScratchpad(std::vector<uint8_t> *sp);
299 virtual int convertAll();
300 virtual int getPageSize() {return 8;}
304 class owDeviceDS2438:public owDevice {
306 owDeviceDS2438(owInterface *owi_,snum_t num):owDevice(owi_,num) {}
307 virtual void setDefaultConfig();
309 int setConfigByte(uint8_t cb);
310 int readScratchpad(std::vector<uint8_t> *sp, uint8_t page, int recall);
311 virtual int readMemory(int page,int start, int count,std::vector<uint8_t> *data);
312 virtual int writeMemory(int page,int start, int count,std::vector<uint8_t> *data);
313 virtual int convertAll();
314 virtual int getPageSize() {return 8;}
317 class owDeviceDS2450:public owDevice {
319 owDeviceDS2450(owInterface *owi_,snum_t num):owDevice(owi_,num) {}
321 virtual void setDefaultConfig();
322 virtual int convertAll();
323 void readMemory(uint8_t addr,std::vector<uint8_t> *sp);
324 void writeMemory(uint8_t addr,std::vector<uint8_t> *sp);
325 void convert(uint8_t mask, uint8_t preset);
326 virtual int getPageSize() {return 8;}
331 class owDeviceDS2423:public owDevice {
333 owDeviceDS2423(owInterface *owi_,snum_t num):owDevice(owi_,num) {}
335 virtual void setDefaultConfig();
336 virtual int convertAll();
337 uint32_t readCounter(uint8_t page);
338 virtual int readMemory(int page,int start, int count,std::vector<uint8_t> *data);
339 virtual int writeMemory(int page,int start, int count,std::vector<uint8_t> *data);
340 virtual int getPageSize() {return 32;}