/* * system.c */ #include #include //#include #include "task.h" #include "system.h" #include "process.h" #include "server.h" FILE *fp; nonv_t non_volatile; void systm(void) { nonv_t *n = &non_volatile; pid_t_ *p = &pid; static int state =0; printf ("system \n"); /* debug, data handling for comm/file i/o goes here */ printf("last cmd %s",last_cmd); if(n->changed) { update_non_volatiles(n); } } void update_non_volatiles(nonv_t *n) { pid_t_ *p = &pid; n->prop = p->kp; n->integ = p->ki; n->deriv = p->kd; n->limit_max = p->y_max; n->limit_min = p->y_min; n->changed = 0; } int save_non_volatiles(nonv_t *n) { if(n->lock == 1) { return -1; } n->lock = 1; if((fp = fopen("params.txt","w"))==NULL) { printf("open parameter file failed \n"); exit(1); } fprintf(fp,"!kp%f \n",n->prop); fprintf(fp,"!ki%f \n",n->integ); fprintf(fp,"!kd%f \n",n->deriv); fprintf(fp,"!lx%f \n",n->limit_max); fprintf(fp,"!ln%f \n",n->limit_min); /* don't forget to flush */ fflush(fp); close(fp); n->lock = 0; printf("save params \n"); return 0; } int get_non_volatile (nonv_t *n) { int i; char inbuf[16]; n->lock = 1; if((fp = fopen("params.txt","r"))==NULL) { printf("open parameter file failed \n"); exit(1); } while(i=!feof(fp)) { fscanf(fp,"%s",inbuf); //FIXME handle returned int, error fprintf(stdout,"cmd %s \n",inbuf); fflush(fp); fflush(stdout); if(i=!feof(fp)) { if(strlen(inbuf)>3) { (void)parse_cmd(inbuf); } } } update_non_volatiles(n); close(fp); n->lock = 0; return 0; } #if 0 int main () { } #endif