#include "owInterface.h"
+#ifdef LINUX
#include <unistd.h>
-
+#endif
+#ifdef WIN
+void usleep(int waitTime) {\r
+ __int64 time1 = 0, time2 = 0, freq = 0;\r
+\r
+ QueryPerformanceCounter((LARGE_INTEGER *)&time1);\r
+ QueryPerformanceFrequency((LARGE_INTEGER *)&freq);\r
+\r
+ do {\r
+ QueryPerformanceCounter((LARGE_INTEGER *)&time2);\r
+ } while ((time2 - time1) < waitTime);\r
+}
+#endif
owDevice::owDevice(owInterface *owi_,snum_t num) {
snum=num;
owi=owi_;
return 0;
}
+int owDeviceDS2438::readMemory(int page,int start, int count,std::vector<uint8_t> *data) {
+ if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0;
+ std::vector<uint8_t> cl;
+ cl.clear();
+ cl.push_back(0xB8); //recall
+ cl.push_back(page);
+ Communicate(&cl, 2, 0);
+ if (owi->log->last()>=OWLOG_ERROR) return -1;
+ cl.clear();
+ cl.push_back(0xBE);
+ cl.push_back(page);
+ Communicate(&cl, 2, 9);
+ if (owi->log->last()>=OWLOG_ERROR) return -1;
+ cl.erase(cl.begin());
+ cl.erase(cl.begin());
+ if (owi->calcCRC8(cl)!=0) {
+ owi->log->set(OWLOG_WARNING,"CRC ERROR reading DS2438 Scrachpad");
+ }
+ data->clear();
+ data->insert(data->begin(),cl.begin()+start,cl.begin()+start+count);
+ return count;
+}
+int owDeviceDS2438::writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {
+ if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0;
+ std::vector<uint8_t> sp;
+ if ((start>0)||(count<8)) {
+ readMemory(page,0,8,&sp);
+ }
+ std::vector<uint8_t> cl;
+ cl.push_back(0x4E);
+ cl.push_back(page);
+ int j=0;
+ for(int i=0;i<8;i++) {
+ if ((i<start)||(i>=start+count)) cl.push_back(sp[i]); else {cl.push_back((*data)[j]);j++;}
+ }
+ Communicate(&cl, 10,0);
+ if (owi->log->last()>=OWLOG_ERROR) return -1;
+ std::vector<uint8_t> cl1;
+ cl1.push_back(0xBE);
+ cl1.push_back(page);
+ Communicate(&cl1, 2, 9);
+ if (owi->log->last()>=OWLOG_ERROR) return -1;
+ cl1.erase(cl1.begin());
+ cl1.erase(cl1.begin());
+ if (owi->calcCRC8(cl1)!=0) {
+ owi->log->set(OWLOG_WARNING,"CRC ERROR rereading DS2438 Scrachpad");
+ }
+ for(int i=0;i<8;i++) {
+ if (cl1[i]!=cl[i+2]) {
+ owi->log->set(OWLOG_ERROR,"Reread not equal, nothing copied");
+ return 0;
+ }
+ }
+ cl.clear();
+ cl.push_back(0x48);
+ cl.push_back(page);
+ Communicate(&cl, 2, 0);
+ if (owi->log->last()>=OWLOG_ERROR) return -1;
+ return 1;
+}
+
+
+
int owDeviceDS2438::setConfigByte(uint8_t cb) {
std::vector<uint8_t> sp;
int k;