int parsecf(char *buf) { double gust, avg, chill, hum_out; double avg_dir, gust_dir; if (!sumcheck(buf, SIZECF)) { errlog(9, "Checksum failure for CF block."); return (-1); } gust = ((xDtoint(buf[2]) * 100) + DDtoint(buf[1])) / 10; gust_dir = (Dxtoint(buf[2])) + (DDtoint(buf[3]) * 10); avg = ((xDtoint(buf[5]) * 100) + DDtoint(buf[4])) / 10; avg_dir = (Dxtoint(buf[5])) + (DDtoint(buf[6]) * 10); chill = DDtoint(buf[16]); if (buf[21] & 0x20) { chill = -1.0 * chill; } #if 0 pthread_mutex_lock(¤t_obs_lock); if (((chill - current_obs.temp_out) > 0.5) && (avg > 0 || gust > 0)) { chill = -1.0 * chill; } pthread_mutex_unlock(¤t_obs_lock); #endif correct(chill, current_cal.chill_mul, current_cal.chill_offs); correct(gust, current_cal.gust_spd_mul, current_cal.gust_spd_offs); correct(gust_dir, current_cal.gust_dir_mul, current_cal.gust_dir_offs); correct(avg_dir, current_cal.wavg_dir_mul, current_cal.wavg_dir_offs); gust_dir = (gust_dir < 0) ? 360 + ((int) gust_dir % 360) : (int) gust_dir % 360; correct(avg, current_cal.wavg_spd_mul, current_cal.wavg_spd_offs); avg_dir = (avg_dir < 0) ? 360 + ((int) avg_dir % 360) : (int) avg_dir % 360; update(current_obs.gust, gust, GUST); update(current_obs.wavg, avg, WAVG); update(current_obs.gust_dir, gust_dir, GUSTDIR); update(current_obs.wavg_dir, avg_dir, WAVGDIR); update(current_obs.chill, chill, WCHILL); errlog2(9, "Wind gust %g m/s, direction: %g", gust, gust_dir); errlog2(9, "Wind avg %g m/s, direction: %g", avg, avg_dir); errlog1(9, "Wind chill %g C", chill); }
int parsebf(char *buf) { double rainrate, raintot; if (!sumcheck(buf, SIZEBF)) { errlog(8, "Checksum failure for BF block."); return (-1); } rainrate = (xDtoint(buf[2]) * 100) + DDtoint(buf[1]); raintot = (xDtoint(buf[6]) * 100) + DDtoint(buf[5]); correct(rainrate, current_cal.rain_rate_mul, current_cal.rain_rate_offs); correct(raintot, current_cal.rain_tot_mul, current_cal.rain_tot_offs); pthread_mutex_lock(¤t_obs_lock); if (raintot < current_obs.rain_tot) { current_obs.rtot_offset += current_obs.rain_tot; } pthread_mutex_unlock(¤t_obs_lock); update(current_obs.rain_rate, rainrate, RAINRATE); update(current_obs.rain_tot, raintot, RAINTOT); errlog2(9, "Rain rate %g mm/hr, Rain tot %g mm", rainrate, raintot); }
int parseaf(char *buf) { double baro, dewpt_in, dewpt_out; if (!sumcheck(buf, SIZEAF)) { errlog(8, "Checksum failure for AF block."); return (-1); } baro = DDtoint(buf[3]) + (DDtoint(buf[4]) * 100.0) + (xDtoint(buf[5]) * 10000.0); baro /= 10; dewpt_in = DDtoint(buf[7]); dewpt_out = DDtoint(buf[18]); correct(dewpt_in, current_cal.dp_in_mul, current_cal.dp_in_offs); correct(dewpt_out, current_cal.dp_out_mul, current_cal.dp_out_offs); correct(baro, current_cal.barometer_mul, current_cal.barometer_offs); update(current_obs.dp_in, dewpt_in, DEWIN); update(current_obs.dp_out, dewpt_out, DEWOUT); update(current_obs.barometer, baro, BARO); errlog1(9, "Barometer: %g mb", baro); errlog2(9, "Indoor dewpoint: %gC, Outdoor dewpoint: %gC", dewpt_in, dewpt_out); }
int parse9f(char *buf) { double temp_in, temp_out; if (!sumcheck(buf, SIZE9F)) { errlog(8, "Checksum failure for 9F block."); return (-1); } temp_in = ((xDtoint(buf[2] & 0x07) * 100) + (DDtoint(buf[1]))) / 10; if (buf[2] & 0x08) { temp_in = -1.0 * temp_in; } temp_out = ((xDtoint(buf[17] & 0x07) * 100) + (DDtoint(buf[16]))) / 10; if (buf[17] & 0x08) { temp_out = -1.0 * temp_out; } if ((temp_out < -50.0) || (temp_in < -50.0)) return; /*Bad data*/ correct(temp_in, current_cal.temp_in_mul, current_cal.temp_in_offs); correct(temp_out, current_cal.temp_out_mul, current_cal.temp_out_offs); update(current_obs.temp_in, temp_in, TEMPIN); update(current_obs.temp_out, temp_out, TEMPOUT); errlog2(9, "Indoor temp: %gC, Outdoor temp: %gC", temp_in, temp_out); }
int parse8f(char *buf) { int hour, min, sec, day, mon; double hum_in, hum_out; if (!sumcheck(buf, SIZE8F)) { errlog(8, "Checksum failure for 8F block."); return (-1); } sec = DDtoint(buf[1]); min = DDtoint(buf[2]); hour = DDtoint(buf[3]); mon = xDtoint(buf[5]); day = DDtoint(buf[4]); hum_in = DDtoint(buf[8]); hum_out = DDtoint(buf[20]); current_obs.sec = sec; current_obs.min = min; current_obs.hour = hour; current_obs.month = mon; current_obs.day = day; correct(hum_in, current_cal.rh_in_mul, current_cal.rh_in_offs); correct(hum_out, current_cal.rh_out_mul, current_cal.rh_out_offs); update(current_obs.rh_in, hum_in, HUMIN); update(current_obs.rh_out, hum_out, HUMOUT); errlog5(9, "%s %d %.2d:%.2d:%.2d", month[mon], day, hour, min, sec); errlog2(9, "Indoor hum: %g%%, Outdoor hum: %g%%", hum_in, hum_out); }
void test_read(cbuf * thebuf) { double shouldwe; int got, thislen; buf_t destbuf[BSIZE]; FILE *fptr; fptr = stdout; shouldwe = rnum(1); if (shouldwe > 0.10) return; /* only test 10% of the time */ thislen = (int)rnum(BSIZE); got = read_cbuf(thebuf, destbuf, thislen); errlog2(5,"test_read asked: %d got: %d\n",thislen, got); do_write(destbuf, got); }
void sup_log_undefobj(mcmcxdef *mctx, errcxdef *ec, int err, char *nm, int nmlen, objnum objn) { uchar *p; size_t len; /* * if the object has any superclasses defined, what must have * happened is that we encountered an error in the course of * defining the object; the object is partially defined, hence it * won't show up in our records of defined objects, yet it really * shouldn't count as an undefined object; simply suppress the * message in this case */ if (objget1sc(mctx, objn) != MCMONINV) return; /* get the object - it contains the location where it was defined */ p = mcmlck(mctx, (mcmon)objn); /* skip the object header */ p += OBJDEFSIZ; /* get the length of the name */ len = strlen((char *)p); #ifdef OS_ERRLINE len += strlen((char *)p + len + 1); #endif /* log the error */ errlog2(ec, err, ERRTSTR, errstr(ec, nm, nmlen), ERRTSTR, errstr(ec, (char *)p, len)); /* done with the object */ mcmunlck(mctx, (mcmon)objn); }
main(int argc, char **argv) { pthread_attr_t sched_attr; int maxprio, minprio; int go = 1; struct sched_param fifo_param; struct sigaction ignoreChildDeath = {NULL, 0, (SA_NOCLDSTOP | SA_RESTART), NULL}; struct sigaction hupAction = {hupcatch, 0, SA_RESTART, NULL}; struct sigaction termAction = {termcatch, 0, SA_RESTART, NULL}; myName=argv[0]; ch_flag = 0; terminate = 0; fprintf(stderr,"%s daemon start.\n", myName); pthread_attr_init(&sched_attr); pthread_attr_setinheritsched(&sched_attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&sched_attr, /*SCHED_RR */ SCHED_FIFO); maxprio = sched_get_priority_max(SCHED_FIFO); minprio = sched_get_priority_min(SCHED_FIFO); sigaction(SIGCHLD, &ignoreChildDeath, NULL); /*zombie protection */ sigaction(SIGHUP, &hupAction, NULL); sigaction(SIGTERM, &termAction, NULL); if (terminate == TERM_TERM) { go = 0; } else { go = 1; } while (go) { /*The main restart loop */ terminate = 0; /*read config file here */ cfg_read(CONFIG_FILE, "", ""); /* do command line option processing, they override config file opts */ do_opts(argc, argv); if (!foreground) { daemon(); } wxin = serial_open(opts.ttydev); last_write_time = time(NULL); if (wxin > 0) { sane_defaults(); init_db(); if (setupio(wxin) < 0) { errlog(9, "setupio bailed."); } iobuf = make_cbuf(BSIZE); pthread_mutex_init(¤t_obs_lock, pthread_mutexattr_default); pthread_mutex_init(¤t_cal_lock, pthread_mutexattr_default); pthread_mutex_init(&terminate_lock, pthread_mutexattr_default); pthread_mutex_init(&cond_update_lock, pthread_mutexattr_default); pthread_cond_init(&cond_update, pthread_condattr_default); #if USE_CBUF /* fifo_param.sched_priority = (minprio + maxprio) / 2; pthread_attr_setschedparam(&sched_attr, &fifo_param);*/ pthread_create(&reader, /*pthread_attr_default */ NULL, (pthread_startroutine_t) serial_reader, (pthread_addr_t) iobuf); pthread_create(&parser, NULL /*&sched_attr*/, (pthread_startroutine_t) parse_input, (pthread_addr_t) iobuf); #if SCREENOUT pthread_create(&writer, NULL /*&sched_attr*/, (pthread_startroutine_t) screen_writer, (pthread_addr_t) NULL); #else /* Make a db writer thread */ pthread_create(&writer, NULL /*&sched_attr*/, (pthread_startroutine_t) db_writer, (pthread_addr_t) NULL); #endif pthread_join(reader, NULL); pthread_join(parser, NULL); pthread_join(writer, NULL); #else parse_input(iobuf); #endif release_cbuf(iobuf); serial_close(opts.ttydev); if (terminate == TERM_TERM) { errlog1(1, "%s: TERMINATE.", argv[0]); go = 0; } if (terminate == TERM_RESTART) { errlog1(1, "%s: RESTART.", argv[0]); go = 1; } #if SCREENOUT #else db_getout(dbconn); #endif } else { go = 0; errlog2(1, "%s: cannot open serial port: %s", argv[0], opts.ttydev); } } errlog1(1,"%s daemon shutdown.", myName); exit(0); }