replaced old logger

This commit is contained in:
Erik Frojdh
2020-03-11 12:40:12 +01:00
parent 4aeb8bf62e
commit 0de0d82a1a
79 changed files with 3635 additions and 3814 deletions

View File

@ -25,13 +25,13 @@ int i2c_open(const char* file,unsigned int addr){
//device file
int fd = open( file, O_RDWR );
if (fd < 0) {
FILE_LOG(logERROR, ("Warning: Unable to open file %s\n",file));
LOG(logERROR, ("Warning: Unable to open file %s\n",file));
return -1;
}
//device address
if( ioctl( fd, I2C_SLAVE, addr&0x7F ) < 0 ) {
FILE_LOG(logERROR, ("Warning: Unable to set slave address:0x%x \n",addr));
LOG(logERROR, ("Warning: Unable to set slave address:0x%x \n",addr));
return -2;
}
return fd;
@ -45,17 +45,17 @@ int i2c_read(){
unsigned char buf = reg;
if (write(fd, &buf, 1)!= 1){
FILE_LOG(logERROR, ("Warning: Unable to write read request to register %d\n", reg));
LOG(logERROR, ("Warning: Unable to write read request to register %d\n", reg));
return -1;
}
//read and update value (but old value read out)
if(read(fd, &buf, 1) != 1){
FILE_LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
return -2;
}
//read again to read the updated value
if(read(fd, &buf, 1) != 1){
FILE_LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
return -2;
}
close(fd);
@ -76,7 +76,7 @@ int i2c_write(unsigned int value){
buf[0] = reg;
buf[1] = val;
if (write(fd, buf, 2) != 2) {
FILE_LOG(logERROR, ("Warning: Unable to write %d to register %d\n",val, reg));
LOG(logERROR, ("Warning: Unable to write %d to register %d\n",val, reg));
return -1;
}
@ -92,10 +92,10 @@ int main(int argc, char* argv[]) {
int fd = open(PORTNAME, O_RDWR | O_NOCTTY | O_SYNC);
if(fd < 0){
FILE_LOG(logERROR, ("Warning: Unable to open port %s\n", PORTNAME));
LOG(logERROR, ("Warning: Unable to open port %s\n", PORTNAME));
return -1;
}
FILE_LOG(logINFO, ("opened port at %s\n",PORTNAME));
LOG(logINFO, ("opened port at %s\n",PORTNAME));
struct termios serial_conf;
// reset structure
@ -110,17 +110,17 @@ int main(int argc, char* argv[]) {
serial_conf.c_lflag = ICANON;
// flush input
if(tcflush(fd, TCIOFLUSH) < 0){
FILE_LOG(logERROR, ("Warning: error form tcflush %d\n", errno));
LOG(logERROR, ("Warning: error form tcflush %d\n", errno));
return 0;
}
// set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete
if(tcsetattr(fd, TCSANOW, &serial_conf) < 0){
FILE_LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
return 0;
}
if(tcsetattr(fd, TCSAFLUSH, &serial_conf) < 0){
FILE_LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
return 0;
}
@ -130,25 +130,25 @@ int main(int argc, char* argv[]) {
char buffer[BUFFERSIZE];
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
FILE_LOG(logINFO, ("Ready...\n"));
LOG(logINFO, ("Ready...\n"));
while(ret != GOODBYE){
memset(buffer,0,BUFFERSIZE);
n = read(fd,buffer,BUFFERSIZE);
FILE_LOG(logDEBUG1, ("Received %d Bytes\n", n));
FILE_LOG(logINFO, ("Got message: '%s'\n",buffer));
LOG(logDEBUG1, ("Received %d Bytes\n", n));
LOG(logINFO, ("Got message: '%s'\n",buffer));
switch(buffer[0]){
case '\0':
FILE_LOG(logINFO, ("Got Start (Detector restart)\n"));
LOG(logINFO, ("Got Start (Detector restart)\n"));
break;
case 's':
FILE_LOG(logINFO, ("Got Start \n"));
LOG(logINFO, ("Got Start \n"));
break;
case 'p':
if (!sscanf(&buffer[1],"%d",&ival)){
FILE_LOG(logERROR, ("Warning: cannot scan voltage value\n"));
LOG(logERROR, ("Warning: cannot scan voltage value\n"));
break;
}
// ok/ fail
@ -158,9 +158,9 @@ int main(int argc, char* argv[]) {
strcpy(buffer,"fail ");
else
strcpy(buffer,"success ");
FILE_LOG(logINFO, ("Sending: '%s'\n",buffer));
LOG(logINFO, ("Sending: '%s'\n",buffer));
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logDEBUG1, ("Sent %d Bytes\n", n));
LOG(logDEBUG1, ("Sent %d Bytes\n", n));
break;
case 'g':
@ -173,17 +173,17 @@ int main(int argc, char* argv[]) {
else
strcpy(buffer,"success ");
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logINFO, ("Sending: '%s'\n",buffer));
FILE_LOG(logDEBUG1, ("Sent %d Bytes\n", n));
LOG(logINFO, ("Sending: '%s'\n",buffer));
LOG(logDEBUG1, ("Sent %d Bytes\n", n));
//value
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
if(ival >= 0){
FILE_LOG(logINFO, ("Sending: '%d'\n",ival));
LOG(logINFO, ("Sending: '%d'\n",ival));
sprintf(buffer,"%d ",ival);
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logINFO, ("Sent %d Bytes\n", n));
}else FILE_LOG(logERROR, ("%s\n",buffer));
LOG(logINFO, ("Sent %d Bytes\n", n));
}else LOG(logERROR, ("%s\n",buffer));
break;
case 'e':
@ -191,7 +191,7 @@ int main(int argc, char* argv[]) {
ret = GOODBYE;
break;
default:
FILE_LOG(logERROR, ("Unknown Command. buffer:'%s'\n",buffer));
LOG(logERROR, ("Unknown Command. buffer:'%s'\n",buffer));
break;
}
}