eigerserver changes, need to include martins changes

This commit is contained in:
Dhanya Maliakal 2017-06-27 10:22:55 +02:00
parent 1ed4407c11
commit 5dd2f273fc
2 changed files with 59 additions and 10 deletions

View File

@ -102,13 +102,13 @@ int main(int argc, char* argv[]) {
// control options
serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL;
// input options
serial_conf.c_iflag = 0;//IGNPAR; (stuck because it was in ignore parity)
serial_conf.c_iflag = IGNPAR;
// output options
serial_conf.c_oflag = 0;
// line options
serial_conf.c_lflag = ICANON;
// flush input
if(tcflush(fd, TCIFLUSH) < 0){
if(tcflush(fd, TCIOFLUSH) < 0){
cprintf(RED,"Warning: error form tcflush %d\n", errno);
return 0;
}
@ -118,17 +118,39 @@ int main(int argc, char* argv[]) {
return 0;
}
if(tcsetattr(fd, TCSAFLUSH, &serial_conf) < 0){
cprintf(RED,"Warning: error form tcsetattr %d\n", errno);
return 0;
}
int ret = 0;
int n = 0;
int ival= 0;
char buffer[BUFFERSIZE];
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-2] = '\0';
buffer[BUFFERSIZE-1] = '\n';
cprintf(GREEN,"Ready...\n");
/*
int once = 1;
while(strcmp(buffer,"start")){
if(once){
once=0;
cprintf(MAGENTA,"in the loop, checking\n");
}
memset(buffer,0,BUFFERSIZE);
n = read(fd,buffer,BUFFERSIZE);
//#ifdef VERBOSE
cprintf(BLUE,"Received %d Bytes\n", n);
//#endif
cprintf(BLUE,"Got message: %s\n",buffer);
}
cprintf(GREEN,"started\n");
*/
while(ret != GOODBYE){
memset(buffer,0,BUFFERSIZE);
n = read(fd,buffer,BUFFERSIZE);
#ifdef VERBOSE
cprintf(BLUE,"Received %d Bytes\n", n);
@ -141,7 +163,9 @@ int main(int argc, char* argv[]) {
cprintf(RED,"Warning: cannot scan voltage value\n");
break;
}
// ok/ fail
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
if(i2c_write(ival)<0)
strcpy(buffer,"fail ");
else
@ -156,6 +180,8 @@ int main(int argc, char* argv[]) {
case 'g':
ival = i2c_read();
//ok/ fail
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
if(ival < 0)
strcpy(buffer,"fail ");
else
@ -165,6 +191,8 @@ int main(int argc, char* argv[]) {
cprintf(BLUE,"Sent %d Bytes\n", n);
#endif
//value
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
if(ival >= 0){
cprintf(GREEN,"%d\n",ival);
sprintf(buffer,"%d ",ival);
@ -180,7 +208,7 @@ int main(int argc, char* argv[]) {
ret = GOODBYE;
break;
default:
printf("Unknown Command. buffer:%s\n",buffer);
printf("Unknown Command. buffer:[%s]\n",buffer);
break;
}
}

View File

@ -240,13 +240,13 @@ int Feb_Control_OpenSerialCommunication(){
// control options
serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL;//57600 too high
// input options
serial_conf.c_iflag = 0;//IGNPAR; (stuck because it was in ignore parity)
serial_conf.c_iflag = IGNPAR;
// output options
serial_conf.c_oflag = 0;
// line options
serial_conf.c_lflag = ICANON;
// flush input
if(tcflush(Feb_Control_hv_fd, TCIFLUSH) < 0){
if(tcflush(Feb_Control_hv_fd, TCIOFLUSH) < 0){
cprintf(RED,"Warning: error form tcflush %d\n", errno);
return 0;
}
@ -255,7 +255,23 @@ int Feb_Control_OpenSerialCommunication(){
cprintf(RED,"Warning: error form tcsetattr %d\n", errno);
return 0;
}
if(tcsetattr(Feb_Control_hv_fd, TCSAFLUSH, &serial_conf) < 0){
cprintf(RED,"Warning: error form tcsetattr %d\n", errno);
return 0;
}
/*
//send start
char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE];
memset(buffer,0,SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1] = '\n';
strcpy(buffer,"start");
int n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
if (n < 0) {
cprintf(RED,"\nWarning: Error writing to i2c bus\n");
return 0;
}
*/
return 1;
}
@ -611,10 +627,9 @@ int Feb_Control_SendHighVoltage(int dacvalue){
char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE];
memset(buffer,0,SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0';
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n';
int n;
sprintf(buffer,"p%d ",dacvalue);
sprintf(buffer,"p%d",dacvalue);
n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
if (n < 0) {
cprintf(RED,"\nWarning: Error writing to i2c bus\n");
@ -624,6 +639,8 @@ int Feb_Control_SendHighVoltage(int dacvalue){
cprintf(BLUE,"Sent %d Bytes\n", n);
#endif
//ok/fail
memset(buffer,0,SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1] = '\n';
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
if (n < 0) {
cprintf(RED,"\nWarning: Error reading from i2c bus\n");
@ -694,10 +711,10 @@ int Feb_Control_ReceiveHighVoltage(unsigned int* value){
return 0;
}
char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE];
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0';
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n';
int n = 0;
//request
strcpy(buffer,"g ");
n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
if (n < 0) {
@ -709,6 +726,8 @@ int Feb_Control_ReceiveHighVoltage(unsigned int* value){
#endif
//ok/fail
memset(buffer,0,SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1] = '\n';
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
if (n < 0) {
cprintf(RED,"\nWarning: Error reading from i2c bus\n");
@ -722,6 +741,8 @@ int Feb_Control_ReceiveHighVoltage(unsigned int* value){
return 0;
}
memset(buffer,0,SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1] = '\n';
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
if (n < 0) {
cprintf(RED,"\nWarning: Error reading from i2c bus\n");