#define TC "\e(0\x77\e(B" // 203 Top Cross
#define VL "\e(0\x78\e(B" // 186 Vertical Line
#define SP " " // space string
+#define BLUE_B "\033[1;34m"
+#define COLOR_E "\033[0m"
+#define C2_B "\033[0;36m"
+#define C3_B "\033[3;34m"
+#define C4_B "\033[1;33m"
+#define C5_B "\033[4;33m"
#endif
#ifdef WIN
#define RB " "// 188 Right Bottom corner
#define TC " "// 203 Top Cross
#define VL " "// 186 Vertical Line
#define SP " " // space string
+#define BLUE_B ""
+#define C2_B ""
+#define C3_B ""
+#define C4_B ""
+#define COLOR_E ""
+#define C5_B ""
+
+
#endif
void printhelp() {
printf(" -n change id \n");
printf(" -g get from server\n");
printf(" -w [1|2] show Warnings (1) or all Infos (2)\n");
+printf(" -m memory functions\n");
if (dev->configstate!=OWDCS_NONE) {
for (size_t i=0;i<4;i++) {
if (dev->config->getPropertyID((uint8_t)i)!=0)
- printf("\033[1;34m%02X.%02X%02X\033[0m\t",dev->getNum().byte[7],dev->getNum().byte[1],dev->getNum().byte[0]);
+ printf(BLUE_B "%02X.%02X%02X" COLOR_E "\t",dev->getNum().byte[7],dev->getNum().byte[1],dev->getNum().byte[0]);
}
}
}
if (dev->configstate!=OWDCS_NONE) {
for (size_t i=0;i<4;i++) {
if (dev->config->getPropertyID((uint8_t)i)!=0)
- printf("\033[0;36m%s\033[0m\t",dev->config->getQuantity((uint8_t)i).substr(0,7).c_str());
+ printf(C2_B "%s" COLOR_E "\t",dev->config->getQuantity((uint8_t)i).substr(0,7).c_str());
}
}
}
if (dev->config->getPropertyID((uint8_t)i)!=0) {
size_t l=utf8_length(dev->config->getUnit((uint8_t)i));
std::string ls=" ";
- printf("\033[3;34m[%s]%s\033[0m\t",dev->config->getUnit((uint8_t)i).c_str(),ls.substr(0,5-l).c_str());
+ printf(C3_B "[%s]%s" COLOR_E "\t",dev->config->getUnit((uint8_t)i).c_str(),ls.substr(0,5-l).c_str());
}
}
}
for(int i=0;i<70;i++) printf(HL);printf("\n");
printf("Selected Device: ");
snum_t snum=d->getNum();
- printf("\033[1;34m%016llX\033[0m",(unsigned long long)snum.num);
+ printf(BLUE_B "%016llX" COLOR_E,(unsigned long long)snum.num);
printf(" \n");
printf("Chip Info: ");
std::vector<std::string> info=d->getFamilyInfo();
printf("\n");
d->convertAll();
for (size_t i=0;i<d->values.size();i++) {
- printf("\033[1;33m%0.4f %s\033[0m ",d->values[i],d->config->getUnit((uint8_t)i).c_str());
+ printf(C4_B "%0.4f %s" COLOR_E,d->values[i],d->config->getUnit((uint8_t)i).c_str());
}
printf("\n");
for(int i=0;i<70;i++) printf(HL);printf("\n");
i++;
snum_t snum=dev->getNum();
printf("%i) ",i);
- printf("\033[1;34m%016llX\033[0m",(unsigned long long)snum.num);
+ printf(BLUE_B "%016llX" COLOR_E,(unsigned long long)snum.num);
printf(" ");
for (int j=0;j<4;j++) printf("%s ",dev->config->getQuantity(j).c_str());
dnr=atoi(inp.c_str());
if (dnr<=0) return 0;
if (dnr<=i) break;
- printf("\033[4;33mSelect a number between 0 and %i\033[0m\n",i);
+ printf(C5_B "Select a number between 0 and %i" COLOR_E "\n",i);
}
return dnr;
}
else
if (adapter.find("COM") != std::string::npos) {
- printf("USB \n");
owi = new owTMEXWIN();
int port = atoi(adapter.substr(adapter.find("COM") + 3).c_str());
printf("Open Adapter on COM%i\n", port);
owi->Find();
for (owDevice* dev :owi->devices) {
snum_t snum=dev->getNum();
- printf("\033[1;34m%016llX\033[0m",(unsigned long long)snum.num);
+ printf(BLUE_B "%016llX" COLOR_E,(unsigned long long)snum.num);
printf("\n");
}
cl.push_back(0x1F);
dev->Communicate(&cl,4,0);
} else
+ //------------------------------------------------------------------------------------------
+ // --------------------- Memory functions
+ //------------------------------------------------------------------------------------------
+ if ((s=getArg("m"))!="") {
+ int pnr=0;
+ std::vector<uint8_t> mem;
+ if(s.find("read")!=std::string::npos) {
+ size_t cla=s.find_first_of("(",0);
+ size_t page=s.find_first_of("p=",cla);
+ size_t epage=s.find_first_of(";",page);
+ if (epage==std::string::npos) epage=s.find_first_of(")",page);
+ std::string pn=s.substr(page+2,epage-page-2);
+ printf("%s Read Memory Page %s of Device:\n",s.c_str(),pn.c_str());
+ pnr=atoi(pn.c_str());
+
+ } else
+ if(s.find("write")!=std::string::npos) {
+ size_t cla=s.find("(",0);
+ size_t page=s.find("p=",cla);
+ size_t epage=s.find(";",page);
+ if (epage==std::string::npos) epage=s.find_first_of(")",page);
+ std::string pn=s.substr(page+2,epage-page-2);
+ size_t data=s.find("d=",cla);
+ size_t edata=s.find(";",data);
+ if (edata==std::string::npos) edata=s.find(")",data);
+ std::string pd=s.substr(data+2,edata-data-2);
+ std::istringstream pdss(pd);
+ //std::cout << pd <<std::endl;
+ while (!pdss.eof()) {
+ int v;
+ pdss>>std::hex>>v;
+ mem.push_back(v);
+ }
+ printf("Write ");
+ for(uint8_t v :mem) printf("%02X ",v);
+ printf("to Memory Page %s of Device:\n",pn.c_str());
+ pnr=atoi(pn.c_str());
+
+ } else exit(1);
+ int sel=selectDevice();
+ if (sel==0) exit(0);
+ sel-=1;
+ //snum_t snum=owi->devices[sel]->getNum();
+ owDevice* dev=owi->devices[sel];
+ if(s.find("read")!=std::string::npos) {
+ int r=dev->readMemory(pnr,0,8,&mem);
+ for(int i=0;i<r;i++) printf("%02X ",mem[i]);
+ printf("\n");
+ exit(0);
+ } else
+ if(s.find("write")!=std::string::npos) {
+ int r=dev->writeMemory(pnr,0,8,&mem);
+ r=dev->readMemory(pnr,0,8,&mem);
+ for(int i=0;i<r;i++) printf("%02X ",mem[i]);
+ printf("\n");
+ exit(0);
+ }
+ }
if ((s=getArg("n"))!="") {
printf("Change id of selected Device\n");
int sel=selectDevice();
printf("New ID: ");
- printf("\033[1;34m%016llX\033[0m",(unsigned long long)snum.num);
+ printf(BLUE_B "%016llX" COLOR_E,(unsigned long long)snum.num);
printf("\n");
owi->Find();
for (owDevice* dev :owi->devices) {
snum_t snum=dev->getNum();
- printf("\033[1;34m%016llX\033[0m",(unsigned long long)snum.num);
+ printf(BLUE_B "%016llX" COLOR_E,(unsigned long long)snum.num);
printf("\n");
}
for (owDevice* dev :owi->devices) {
printf("_______________________________________________________________________\n");
snum_t snum=dev->getNum();
- printf("\033[1;34m%016llX\033[0m ",(unsigned long long)snum.num);
+ printf(BLUE_B "%016llX " COLOR_E,(unsigned long long)snum.num);
switch (dev->configstate) {
case OWDCS_16:printf("old Configcode from www.tm3d.de");break;
case OWDCS_24:printf("Configcode from www.tm3d.de");break;
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;
#define OWLOG_WARNING 2
#define OWLOG_ERROR 3
+#ifdef LINUX
+
+#define BLUE_B "\033[1;34m"
+#define COLOR_E "\033[0m"
+#define C2_B "\033[0;36m"
+#define C3_B "\033[3;34m"
+#define C4_B "\033[1;33m"
+#define C5_B "\033[4;33m"
+#define CLE_B "\033[1;31m"
+#define CLW_B "\033[1;33m"
+#endif
+#ifdef WIN
+#define BLUE_B ""
+#define C2_B ""
+#define C3_B ""
+#define C4_B ""
+#define COLOR_E ""
+#define C5_B ""
+#define CLE_B ""
+#define CLW_B ""
+
+#endif
+
class owLog {
int lcount;
std::string logtext;
level=llevel;
lcount++;
if (level>=loglevel) {
- if (loglevel==OWLOG_ERROR) printf("\033[1;31m%s\033[0m\n",s);
- else if (loglevel==OWLOG_WARNING) printf("\033[1;33m%s\033[0m\n",s);
+ if (loglevel==OWLOG_ERROR) printf(CLE_B "%s" COLOR_E "\n",s);
+ else if (loglevel==OWLOG_WARNING) printf(CLW_B "%s" COLOR_E "\n",s);
else printf("%s\n",s);
}
return done;
void changeID(snum_t nid);
void runFlasher();
virtual int convertAll() {return 1;}
+ virtual int readMemory(int page,int start, int count,std::vector<uint8_t> *data) {return 0;};
+ virtual int writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {return 0;};
virtual ~owDevice() {}
};
int setConfigByte(uint8_t cb);
int readScratchpad(std::vector<uint8_t> *sp, uint8_t page, int recall);
-
+ virtual int readMemory(int page,int start, int count,std::vector<uint8_t> *data);
+ virtual int writeMemory(int page,int start, int count,std::vector<uint8_t> *data);
virtual int convertAll();
} ;