#ifdef WIN
#include "Windows.h"
#include "time.h"
+
+
#endif
#include <stdio.h>
#include <fstream>
#include <sstream>
+
#ifdef LINUX
#define RB "\e(0\x6a\e(B" // 188 Right Bottom corner
printf("Options:\n");
printf(" -i interactive mode\n");
printf(" select a device and get information about it\n");
+printf(" -s \"id as 64bit Hex\" try to skip select menu with this id \n");
+printf(" example: -s \"5D02160084D9A220\" \n");
printf(" -c read and print all continuous\n");
printf(" -p time in sec between readings\n");
printf(" -d [config file] put all Data in mysql Database descripted in config file\n");
printf(" [database]\n");
printf(" [prefix] -> a prefix of all tables \n\n");
printf(" -r Search every time for new Devices\n");
+printf(" -t [text_file] append comma separadet to text-file\n");
printf(" -f [hexfile] flash new\n");
printf(" -n [\"id as 64bit Hex\"] change id \n");
printf(" example: -n \"5D02160084D9A220\" \n");
printf(" -g get from server\n");
printf(" -w [1|2] show Warnings (1) or all information (2)\n");
printf(" -m memory functions\n");
+printf(" -x write direct 1-Wire\n");
int database=0;
mySensorDB *sdb=NULL;
#endif
+int textfile=0;
+std::string textfilename;
+
+
/*
snum_t getArgsnum(std::string flag) {
snum_t snum;
}
+int appendTextFile(std::string line) {
+ std::ofstream file;
+ file.open(textfilename, std::ios::out | std::ios::app);
+ if (file.fail()) {
+ owi->log->set(OWLOG_ERROR,"Can not open outputfile for text output");
+ return -1;
+ }
+
+
+ file << line << std::endl;
+ file.close();
+ return 0;
+}
+
void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int searchrom) {
int first=1;
+ char valbuf[100];
+ std::string tfl;
while (1) {
if (searchrom) {
owi->log->clear();
struct tm tm;
localtime_s(&tm,&t);
#endif
+
printf("%d-%02d-%02d %02d:%02d:%02d\t", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
+ if (textfile) {
+ snprintf(valbuf,100,"%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
+ tfl=valbuf;
+ }
+
+
for (owDevice* dev :*devices) {
for(int k=0;k<owi->maxrepeat;k++){
+ //std::vector<uint8_t> data;
+ //data.push_back(0xCC);
+ //data.push_back(0x44);
+ //owi->Reset();
+ //owi->Communicate(&data, 2, 0);
+=======
std::vector<uint8_t> data;
data.push_back(0xCC);
data.push_back(0x44);
owi->Reset();
owi->Communicate(&data, 2, 0);
+>>>>>>> origin/master
dev->convertAll();
if (owi->log->last()<OWLOG_ERROR) break;
owi->log->clear();
else
printf("%0.1f \t",dev->values[i]);
fflush(stdout);
+ if (textfile) {
+ snprintf(valbuf,100,",%0.4f",dev->values[i]);
+ tfl.append(valbuf);
+ }
}
}
}
}
printf("\n");
+ if (textfile) {
+ appendTextFile(tfl);
+ }
while (((int)time(NULL)) < (st + intervall)) {
#ifdef LINUX
sleep(1);
}
int selectDevice() {
+ std::string s;
owi->Find();
- int i=0;
+ int i = 0;
+ char *end;
+ unsigned long long l = 0;
+ if ((s = getArg("s")) != "") {
+ l = strtoull(s.c_str(), &end, 16);
+ for (owDevice* dev : owi->devices) {
+ i++;
+ snum_t snum = dev->getNum();
+ if (l == snum.num) return i;
+
+ }
+ printf("Number not found -> Select one or exit!\n");
+ }
+
+ i=0;
for (owDevice* dev :owi->devices) {
i++;
snum_t snum=dev->getNum();
database=1;
}
#endif
+<<<<<<< HEAD
+ if ((s=getArg("t")) !="") {
+ textfile=1;
+ printf("Write values to textfile %s\n",s.c_str());
+ textfilename=s;
+ }
+=======
+>>>>>>> origin/master
continuous(&(owi->devices),pause,1,reload);
} else
dev->Communicate(&cl,4,0);
} else
//------------------------------------------------------------------------------------------
+ // --------------------- Direct Write
+ //------------------------------------------------------------------------------------------
+
+ if ((s=getArg("x"))!="") {
+ std::vector<uint8_t> v;
+ int sp=0;
+ std::string ts="";
+ for ( std::string::iterator it = s.begin() ; it < s.end(); it++ ,sp++) {
+ if (isxdigit(*it)) {
+ char c=(*it);
+ ts.append(1,c);
+ if (ts.length()>=2) {
+ v.push_back(strtoul(ts.c_str(),NULL, 16));
+ ts="";
+ }
+ }
+ }
+ if (ts.length()!=0) {
+ v.push_back(strtoul(ts.c_str(),NULL, 16));
+ }
+ printf("Send ");
+ for (uint8_t val :v) printf("%02X ",val);
+ printf(" to selected Device\n");
+ int sel=selectDevice();
+ if (sel==0) exit(0);
+ sel-=1;
+ owDevice* dev=owi->devices[sel];
+ dev->Communicate(&v,v.size(),0);
+ for (uint8_t val :v) printf("%02X ",val);
+ printf("\n");
+ exit(0);
+
+
+ }
+
+ //------------------------------------------------------------------------------------------
+ // --------------------- Memory functions
+ //------------------------------------------------------------------------------------------
+
+=======
// --------------------- Memory functions
//------------------------------------------------------------------------------------------
+>>>>>>> origin/master
if ((s=getArg("m"))!="") {
int pnr=0;
std::vector<uint8_t> mem;
if (c=='x') br=1;
} else {
if ((c==',')|(c=='}')) {
+<<<<<<< HEAD
+ isnum.byte[i]=(uint8_t)strtoull(s, NULL, 16);
+=======
isnum.byte[i]=(uint8_t)strtol(s, NULL, 16);
+>>>>>>> origin/master
//printf("%x\n",strtol(s, NULL, 16));
i++;
br=0;
if (s=="1") {
snum.num+=256;
} else {
+<<<<<<< HEAD
+ unsigned long long l=strtoull(s.c_str(),NULL,16);
+=======
unsigned long long l=strtol(s.c_str(),NULL,16);
+>>>>>>> origin/master
if ((snum.num&0xFF)!=(l&0xFF)) {
printf("ERROR: Family of Device 0x%02X->0x%02X can not be changed\n",(int)(snum.num&0xFF),(int)(l&0xFF));
exit(1);