| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
s |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#include "../biosig.h" |
| 42 |
|
| 43 |
#include <errno.h> |
| 44 |
#include <math.h> |
| 45 |
#include <inttypes.h> |
| 46 |
#include <stdio.h> |
| 47 |
#include <stdlib.h> |
| 48 |
#include <string.h> |
| 49 |
#include <time.h> |
| 50 |
#include <sys/time.h> |
| 51 |
|
| 52 |
#include <termios.h> |
| 53 |
#include <unistd.h> |
| 54 |
#include <fcntl.h> |
| 55 |
#include <sys/signal.h> |
| 56 |
#include <sys/types.h> |
| 57 |
|
| 58 |
|
| 59 |
#define LENBUF 300 |
| 60 |
#define BAUDRATE B9600 |
| 61 |
#define MODEMDEVICE "/dev/ttyUSB0" |
| 62 |
#define _POSIX_SOURCE 1 //POSIX compliant source |
| 63 |
#define FALSE 0 |
| 64 |
#define TRUE 1 |
| 65 |
|
| 66 |
|
| 67 |
int wait_flag=TRUE; |
| 68 |
|
| 69 |
char buf[LENBUF+1] __attribute__ ((deprecated)); |
| 70 |
uint8_t idata[LENBUF]; |
| 71 |
uint8_t odata[LENBUF]; |
| 72 |
char manufacturer[1000]; |
| 73 |
|
| 74 |
int fd; |
| 75 |
FILE *fid=NULL; |
| 76 |
FILE *fid2=NULL; |
| 77 |
|
| 78 |
HDRTYPE *hdr = NULL; |
| 79 |
struct termios oldtio, newtio; |
| 80 |
|
| 81 |
void stop() { |
| 82 |
|
| 83 |
if (fd>2) { |
| 84 |
tcsetattr(fd, TCSANOW, &oldtio); |
| 85 |
close(fd); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
if (hdr) destructHDR(hdr); |
| 90 |
|
| 91 |
|
| 92 |
if (fid2) fclose(fid2); |
| 93 |
} |
| 94 |
|
| 95 |
const void *outPtr = odata+3; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
#if defined(__LITTLE_ENDIAN) |
| 107 |
uint16_t crc16_a001(uint8_t data[], size_t n) |
| 108 |
{ |
| 109 |
uint8_t flag; |
| 110 |
size_t i,j; |
| 111 |
union { |
| 112 |
uint16_t u16; |
| 113 |
uint8_t u8[2]; |
| 114 |
} crc; |
| 115 |
|
| 116 |
crc.u16 = 0xffff; |
| 117 |
for (i=0; i<n; i++) { |
| 118 |
crc.u8[0] = crc.u8[0]^data[i]; |
| 119 |
for (j=0; j<8; j++) { |
| 120 |
flag = crc.u8[0] & 0x01; |
| 121 |
crc.u16 = crc.u16 >> 1; |
| 122 |
if (flag) crc.u16 = crc.u16^0xa001; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
*(uint16_t*)(data+n) = crc.u16; |
| 128 |
return (uint16_t)crc.u16; |
| 129 |
} |
| 130 |
|
| 131 |
int read_register(uint8_t slave, uint8_t cmd, uint16_t reg) { |
| 132 |
|
| 133 |
idata[0] = slave; |
| 134 |
idata[1] = 3; |
| 135 |
*(uint16_t*)(idata+2) = bswap_16((uint16_t)reg); |
| 136 |
*(uint16_t*)(idata+4) = bswap_16(0x0004); |
| 137 |
crc16_a001(idata,6); |
| 138 |
tcflush(fd, TCIOFLUSH); |
| 139 |
int c = write(fd,idata,8); |
| 140 |
if (VERBOSE_LEVEL>8) fprintf(stdout,"\n======= SENT %i bytes\n",c); |
| 141 |
usleep(100000); |
| 142 |
c = read(fd,odata,16); |
| 143 |
if (VERBOSE_LEVEL>8) fprintf(stdout,"\n======= RECEIVED %i bytes\n",c); |
| 144 |
if (c<9 || odata[0] != slave) return (-1); |
| 145 |
|
| 146 |
if (VERBOSE_LEVEL==6) |
| 147 |
fprintf(stdout,"\n======= REG:0x%04x RECEIVED %2i bytes U16[2]: 0x%08x %08x %08x %08x F:%10g %10g<%s> ",\ |
| 148 |
reg,c,beu32p(odata),beu32p(odata+4),beu32p(odata+8),beu32p(odata+12), \ |
| 149 |
(double)bef32p(odata+3), (double)bef32p(odata+7), (char*)(odata+3)); |
| 150 |
|
| 151 |
uint16_t crc=bswap_16(crc16_a001(odata,c-2)); |
| 152 |
if (VERBOSE_LEVEL>8) |
| 153 |
fprintf(stdout,"crc 0x%04x 0x%04x",bswap_16(crc),beu16p(odata+c-2)); |
| 154 |
usleep(10000); |
| 155 |
|
| 156 |
if (crc!=beu16p(odata+c-2)) return -1; |
| 157 |
|
| 158 |
return 0; |
| 159 |
} |
| 160 |
#else |
| 161 |
#error CRC16 function not defined for big endian platform |
| 162 |
#endif |
| 163 |
|
| 164 |
|
| 165 |
int main(int argc, char *argv[]) { |
| 166 |
|
| 167 |
char *devicename = "/dev/ttyUSB0"; |
| 168 |
const char *outFile = NULL; |
| 169 |
|
| 170 |
|
| 171 |
const char *debugFile = NULL; |
| 172 |
char debugfile[40] = "flowmonDD.log.txt"; |
| 173 |
|
| 174 |
|
| 175 |
struct timeval tv; |
| 176 |
struct timezone tz; |
| 177 |
struct tm T; |
| 178 |
uint32_t oldDay=0, newDay; |
| 179 |
gdf_time gdfTime; |
| 180 |
char flag_GZIP = 0; |
| 181 |
|
| 182 |
char logfile[48] = "flowmonYYYYMMDD.log.gdf"; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
const char help[]= |
| 192 |
"FLOWMON2 reads data of the flow sensor through the serial terminal and stores it into a data file for archiving.\n" |
| 193 |
" The current measurement values are also written into the file /var/www/flowsensor.html.\n" |
| 194 |
" This software supports the device 'Flow Meter GSM-D3KA-BN00 (BHT Rotary Gas Meter) from Vögtlin Instruments'.\n\n" |
| 195 |
"Usage: flowmon -d devicename [-o outfile] [-D debugfile] [-V#]\n" |
| 196 |
" devicename: default value is /dev/ttyS0\n" |
| 197 |
" outfile: logs the recorded data\n" |
| 198 |
" If no outfile is provided, the data will be logged into daily files named flowmon<$date>.log.gdf \n" |
| 199 |
" debugfile: logs the data in ascii text\n" |
| 200 |
" If no outfile is provided, the data will be logged into daily files named flowmon<$day-of-month>.log.txt \n" |
| 201 |
" -V# verbose level #=0 is no messages, #=9 is highest level(debugging) messages\n" |
| 202 |
" -h, --help: display this help text\n" |
| 203 |
" -z save outfile in gzipped format\n" |
| 204 |
" \n\n" |
| 205 |
; |
| 206 |
if (argc<2) { |
| 207 |
fprintf(stdout,"%s",help); |
| 208 |
return(0); |
| 209 |
} |
| 210 |
|
| 211 |
gettimeofday(&tv, &tz); |
| 212 |
gdfTime = t_time2gdf_time(tv.tv_sec + ldexp(tv.tv_usec*1e-6/(24*3600.0),32) ); |
| 213 |
gdf_time2tm_time_r(gdfTime, &T); |
| 214 |
newDay = T.tm_mday; |
| 215 |
sprintf(debugfile,"flowmon%02d.log.txt",T.tm_mday); |
| 216 |
|
| 217 |
|
| 218 |
int k = 0; |
| 219 |
while (k<argc) { |
| 220 |
|
| 221 |
if (VERBOSE_LEVEL>3) fprintf(stdout,"%i/%i\t%s\n",k,argc,argv[k]); |
| 222 |
|
| 223 |
if (0) { |
| 224 |
} |
| 225 |
else if (!strcmp(argv[k],"-d")) { |
| 226 |
devicename = argv[++k]; |
| 227 |
} |
| 228 |
else if (!strcmp(argv[k],"-h") || !strcmp(argv[k],"--help") ) { |
| 229 |
fprintf(stdout,"%s",help); |
| 230 |
return 0; |
| 231 |
} |
| 232 |
else if (!strcmp(argv[k],"-o")) { |
| 233 |
k++; |
| 234 |
outFile = argv[k]; |
| 235 |
} |
| 236 |
else if (!strcmp(argv[k],"-D")) { |
| 237 |
k++; |
| 238 |
debugFile = argv[k]; |
| 239 |
} |
| 240 |
else if (!strncmp(argv[k],"-V",2)) { |
| 241 |
char c = argv[k][2]; |
| 242 |
#ifndef VERBOSE_LEVEL |
| 243 |
if ('0'<=c && c<='9') |
| 244 |
VERBOSE_LEVEL = c-'0'; |
| 245 |
#endif |
| 246 |
} |
| 247 |
else if (!strcmp(argv[k],"-z")) { |
| 248 |
flag_GZIP = 1; |
| 249 |
} |
| 250 |
k++; |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
atexit(&stop); |
| 261 |
|
| 262 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %d): err %d\n",__FILE__,__LINE__,errno); |
| 263 |
|
| 264 |
|
| 265 |
fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK); |
| 266 |
if (fd < 0) { |
| 267 |
perror(devicename); |
| 268 |
exit(EXIT_FAILURE); |
| 269 |
} |
| 270 |
tcgetattr(fd,&oldtio); |
| 271 |
|
| 272 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %d): fd=%d\n",__FILE__,__LINE__,fd); |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD | CSTOPB; |
| 277 |
newtio.c_iflag = IGNPAR; |
| 278 |
newtio.c_oflag = 0; |
| 279 |
newtio.c_lflag = 0; |
| 280 |
newtio.c_cc[VMIN] = 1; |
| 281 |
newtio.c_cc[VTIME]= 0; |
| 282 |
tcflush(fd, TCIOFLUSH); |
| 283 |
tcsetattr(fd,TCSANOW,&newtio); |
| 284 |
|
| 285 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %d): err %d\n",__FILE__,__LINE__,errno); |
| 286 |
if (errno) { |
| 287 |
fprintf(stderr,"%s (line %d) %d %s\n", __FILE__, __LINE__, errno, strerror(errno)); |
| 288 |
stop(); |
| 289 |
return(errno); |
| 290 |
} |
| 291 |
|
| 292 |
#if 1 |
| 293 |
fid2 = fopen(debugFile,"a"); |
| 294 |
|
| 295 |
{ |
| 296 |
hdr = constructHDR(4 ,0); |
| 297 |
hdr->SampleRate = 1; |
| 298 |
hdr->SPR = 1; |
| 299 |
hdr->NRec = -1; |
| 300 |
hdr->EVENT.N = 0; |
| 301 |
hdr->FILE.COMPRESSION = 0; |
| 302 |
|
| 303 |
{ |
| 304 |
|
| 305 |
CHANNEL_TYPE *hc = hdr->CHANNEL + 0; |
| 306 |
hc->LeadIdCode = 0; |
| 307 |
strcpy(hc->Label,"time "); |
| 308 |
hc->GDFTYP = 8; |
| 309 |
hc->SPR = hdr->SPR; |
| 310 |
|
| 311 |
hc->PhysMax = ldexp(1,32); |
| 312 |
hc->PhysMin = 0; |
| 313 |
hc->DigMax = ldexp(1,64); |
| 314 |
hc->DigMin = 0; |
| 315 |
hc->PhysDimCode = PhysDimCode("d"); |
| 316 |
hdr->AS.bpb += GDFTYP_BITS[hc->GDFTYP]>>3; |
| 317 |
} |
| 318 |
|
| 319 |
{ |
| 320 |
|
| 321 |
CHANNEL_TYPE *hc = hdr->CHANNEL + 1; |
| 322 |
hc->LeadIdCode = 0; |
| 323 |
strcpy(hc->Label,"total volume "); |
| 324 |
hc->GDFTYP = 6; |
| 325 |
hc->GDFTYP = 16; |
| 326 |
hc->SPR = hdr->SPR; |
| 327 |
hc->PhysMax = ldexp(1,32); |
| 328 |
hc->PhysMin = -hc->PhysMax; |
| 329 |
hc->DigMax = hc->PhysMax; |
| 330 |
hc->DigMin = hc->PhysMin; |
| 331 |
hdr->AS.bpb += GDFTYP_BITS[hc->GDFTYP]>>3; |
| 332 |
|
| 333 |
read_register(247, 3, 0x6384) ; |
| 334 |
|
| 335 |
if (!strcmp((char*)(outPtr+4),"ln")) |
| 336 |
hc->PhysDimCode = PhysDimCode("l"); |
| 337 |
else |
| 338 |
hc->PhysDimCode = 0; |
| 339 |
} |
| 340 |
|
| 341 |
{ |
| 342 |
|
| 343 |
CHANNEL_TYPE *hc = hdr->CHANNEL + 2; |
| 344 |
hc->LeadIdCode = 0; |
| 345 |
strcpy(hc->Label,"flow "); |
| 346 |
hc->GDFTYP = 3; |
| 347 |
hc->GDFTYP = 16; |
| 348 |
hc->SPR = hdr->SPR; |
| 349 |
hdr->AS.bpb += GDFTYP_BITS[hc->GDFTYP]>>3; |
| 350 |
|
| 351 |
read_register(247, 3, 0x6020) ; |
| 352 |
hc->PhysMax = bef32p(outPtr); |
| 353 |
hc->PhysMin = -hc->PhysMax; |
| 354 |
hc->DigMax = hc->PhysMax; |
| 355 |
hc->DigMin = hc->PhysMin; |
| 356 |
read_register(247, 3, 0x6022) ; |
| 357 |
strncpy(hc->Transducer,(char*)(outPtr+1),MAX_LENGTH_TRANSDUCER); |
| 358 |
read_register(247, 3, 0x6042) ; |
| 359 |
strncpy(hc->Transducer,(char*)(outPtr),MAX_LENGTH_LABEL); |
| 360 |
|
| 361 |
read_register(247, 3, 0x6046) ; |
| 362 |
if (!strcmp((char*)outPtr,"ln/h")) { |
| 363 |
|
| 364 |
hc->PhysDimCode = 3104; |
| 365 |
} |
| 366 |
else |
| 367 |
hc->PhysDimCode = 0; |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
read_register(247, 3, 0x6120) ; |
| 372 |
|
| 373 |
|
| 374 |
} |
| 375 |
|
| 376 |
{ |
| 377 |
|
| 378 |
CHANNEL_TYPE *hc = hdr->CHANNEL + 3; |
| 379 |
hc->LeadIdCode = 0; |
| 380 |
strcpy(hc->Label,"Temperature"); |
| 381 |
hc->GDFTYP = 16; |
| 382 |
hc->SPR = hdr->SPR; |
| 383 |
hc->PhysMax = 500; |
| 384 |
hc->PhysMin = -500; |
| 385 |
hc->DigMax = 500; |
| 386 |
hc->DigMin = -500; |
| 387 |
hc->PhysDimCode = 6048; |
| 388 |
hdr->AS.bpb += GDFTYP_BITS[hc->GDFTYP]>>3; |
| 389 |
} |
| 390 |
|
| 391 |
if (hdr->NS > 4) { |
| 392 |
|
| 393 |
CHANNEL_TYPE *hc = hdr->CHANNEL + 4; |
| 394 |
hc->LeadIdCode = 0; |
| 395 |
strcpy(hc->Label,"typ of gas"); |
| 396 |
hc->GDFTYP = 2; |
| 397 |
hc->SPR = hdr->SPR; |
| 398 |
hc->PhysMax = 255; |
| 399 |
hc->PhysMin = 0; |
| 400 |
hc->DigMax = 255; |
| 401 |
hc->DigMin = 0; |
| 402 |
hc->PhysDimCode = 0; |
| 403 |
hdr->AS.bpb += GDFTYP_BITS[hc->GDFTYP]>>3; |
| 404 |
} |
| 405 |
for (k=0; k<hdr->NS; k++) { |
| 406 |
CHANNEL_TYPE *hc = hdr->CHANNEL + k; |
| 407 |
hc->LeadIdCode = 0; |
| 408 |
hc->SPR = 1; |
| 409 |
} |
| 410 |
|
| 411 |
hdr->AS.rawdata = (uint8_t*)realloc(hdr->AS.rawdata,hdr->AS.bpb); |
| 412 |
|
| 413 |
hdr->ID.Manufacturer.Name = "Voegtlin"; |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
read_register(247, 3, 0x0023) ; 1 |
| 420 |
hdr->ID.Manufacturer.Model = (char*)manufacturer; |
| 421 |
strcpy(manufacturer,"FlowMeter "); |
| 422 |
strcat(manufacturer, outPtr); |
| 423 |
read_register(247, 3, 0x1004) ; 2 |
| 424 |
strcat(manufacturer, outPtr); |
| 425 |
|
| 426 |
read_register(247, 3, 0x0020); |
| 427 |
uint16_t HardWareVersion = beu16p(outPtr); |
| 428 |
|
| 429 |
uint16_t SoftWareVersion = beu16p(outPtr+2); |
| 430 |
hdr->ID.Manufacturer.Version = manufacturer+strlen(manufacturer)+1; |
| 431 |
sprintf((char*)(hdr->ID.Manufacturer.Version),"Hardware: %d.%d.%d Software: %d.%d.%d", \ |
| 432 |
HardWareVersion>>8, \ |
| 433 |
(HardWareVersion & 0xF0)>>4, \ |
| 434 |
HardWareVersion & 0x0F, \ |
| 435 |
SoftWareVersion>>8, \ |
| 436 |
(SoftWareVersion & 0xF0)>>4, \ |
| 437 |
SoftWareVersion & 0x0F \ |
| 438 |
); |
| 439 |
|
| 440 |
read_register(247, 3, 0x001e) ; |
| 441 |
hdr->ID.Manufacturer.SerialNumber = hdr->ID.Manufacturer.Version+strlen(hdr->ID.Manufacturer.Version)+1; |
| 442 |
sprintf((char*)(hdr->ID.Manufacturer.SerialNumber),"%d",beu32p(outPtr)); |
| 443 |
|
| 444 |
hdr->FLAG.UCAL = 1; |
| 445 |
hdr->TYPE = GDF; |
| 446 |
hdr->VERSION = 2.0; |
| 447 |
if (outFile) hdr->FileName = strdup(outFile); |
| 448 |
} |
| 449 |
#endif |
| 450 |
|
| 451 |
read_register(247, 3, 0x0000) ; |
| 452 |
read_register(247, 3, 0x0002) ; |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
read_register(247, 3, 0x000c) ; |
| 457 |
read_register(247, 3, 0x000d) ; |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
read_register(247, 3, 0x0013) ; |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
read_register(247, 3, 0x0004) ; |
| 469 |
read_register(247, 3, 0x6380) ; |
| 470 |
r |
| 471 |
read_register(247, 3, 0x6384) ; |
| 472 |
|
| 473 |
|
| 474 |
if (outFile) { |
| 475 |
|
| 476 |
hdr->FILE.COMPRESSION = flag_GZIP; |
| 477 |
hdr = sopen(outFile, "a", hdr); |
| 478 |
if (VERBOSE_LEVEL>7) hdr2ascii(hdr,stdout,4); |
| 479 |
|
| 480 |
if (serror2(hdr)) { |
| 481 |
destructHDR(hdr); |
| 482 |
return(EXIT_FAILURE); |
| 483 |
} |
| 484 |
|
| 485 |
if (hdr->FILE.OPEN < 2) { |
| 486 |
destructHDR(hdr); |
| 487 |
hdr = NULL; |
| 488 |
fprintf(stderr,"Could not open output file %s\n", outFile); |
| 489 |
exit(-1); |
| 490 |
} |
| 491 |
|
| 492 |
hdr->AS.rawdata = (uint8_t*)realloc(hdr->AS.rawdata,hdr->AS.bpb); |
| 493 |
if (hdr->NRec < 0) hdr->NRec = 0; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
fid = fdopen(fd, "r+"); |
| 503 |
|
| 504 |
while (1) { |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
if (read_register(247, 3, 0x0004)) continue; |
| 510 |
float TotalVolume = bef32p(outPtr); |
| 511 |
|
| 512 |
if (read_register(247, 3, 0x0000)) continue; |
| 513 |
|
| 514 |
float Flow = bef32p(outPtr); |
| 515 |
float Temperature = bef32p(outPtr+4); |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
gettimeofday(&tv, &tz); |
| 524 |
gdfTime = t_time2gdf_time(tv.tv_sec) + ldexp(tv.tv_usec*1e-6/(24*3600.0),32); |
| 525 |
gdf_time2tm_time_r(gdfTime, &T); |
| 526 |
newDay = T.tm_mday; |
| 527 |
if ( (newDay != oldDay) && !outFile) { |
| 528 |
|
| 529 |
|
| 530 |
sclose(hdr); |
| 531 |
hdr->NRec = -1; |
| 532 |
sprintf(logfile,"flowmon%04d%02d%02d.log.gdf",T.tm_year+1900,T.tm_mon+1,T.tm_mday); |
| 533 |
hdr->FILE.COMPRESSION = flag_GZIP; |
| 534 |
hdr = sopen(logfile, "a", hdr); |
| 535 |
|
| 536 |
if (serror2(hdr)) { |
| 537 |
destructHDR(hdr); |
| 538 |
return(EXIT_FAILURE); |
| 539 |
} |
| 540 |
|
| 541 |
if (!hdr->FILE.OPEN) { |
| 542 |
destructHDR(hdr); |
| 543 |
hdr = NULL; |
| 544 |
fprintf(stderr,"Could not open output file %s\n", logfile); |
| 545 |
} |
| 546 |
|
| 547 |
hdr->AS.rawdata = (uint8_t*)realloc(hdr->AS.rawdata,hdr->AS.bpb); |
| 548 |
if (hdr->NRec<0) hdr->NRec = 0; |
| 549 |
} |
| 550 |
|
| 551 |
if ( (newDay != oldDay) && !debugFile) { |
| 552 |
|
| 553 |
if (fid2) fclose(fid2); |
| 554 |
sprintf(debugfile,"flowmon%02d.log.txt",T.tm_mday); |
| 555 |
fid2 = fopen(debugfile,"a"); |
| 556 |
} |
| 557 |
|
| 558 |
if (newDay != oldDay) { |
| 559 |
oldDay = newDay; |
| 560 |
}; |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
memcpy(hdr->AS.rawdata+hdr->CHANNEL[0].bi,&gdfTime,8); |
| 568 |
*(float*)(hdr->AS.rawdata+hdr->CHANNEL[1].bi)=TotalVolume; |
| 569 |
*(float*)(hdr->AS.rawdata+hdr->CHANNEL[2].bi)=Flow; |
| 570 |
*(float*)(hdr->AS.rawdata+hdr->CHANNEL[3].bi)=Temperature; |
| 571 |
|
| 572 |
if (hdr) { |
| 573 |
|
| 574 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"FLOWMON 230 %i, %i, %i\n", (int)hdr->NRec, hdr->AS.bpb, hdr->FILE.OPEN); |
| 575 |
if (VERBOSE_LEVEL>8) fprintf(stdout,"FLOWMON 240 %g, %g, %g\n", TotalVolume,Flow,Temperature); |
| 576 |
|
| 577 |
hdr->NRec += ifwrite(hdr->AS.rawdata, hdr->AS.bpb, 1, hdr); |
| 578 |
ifflush(hdr); |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
char buf[100]; |
| 584 |
strfgdftime(buf,100,"%Y-%m-%d %H:%M:%S UTC",gdfTime); |
| 585 |
FILE *fid3 = fopen("/var/www/flowsensor.html","w"); |
| 586 |
if (fid3 != NULL) { |
| 587 |
fprintf(fid3,"<html><body><h1>Carbogen FlowSensor</h1><br><pre>Time:\t\t%s\n",buf); |
| 588 |
fprintf(fid3,"Manufacturer:\t%s \nModel:\t\t%s\nSerialNo:\t%s\nVersion:\t%s\n",hdr->ID.Manufacturer.Name, hdr->ID.Manufacturer.Model,hdr->ID.Manufacturer.SerialNumber,hdr->ID.Manufacturer.Version); |
| 589 |
fprintf(fid3,"Total Volume:\t%10.3f l_n\n",TotalVolume); |
| 590 |
|
| 591 |
|
| 592 |
fprintf(fid3,"Flow:\t\t %10.4f l_n/h\n",Flow); |
| 593 |
fprintf(fid3,"Temperature:\t%6.3f C\n</pre><META HTTP-EQUIV=\"refresh\" CONTENT=\"1\"></body></html>",Temperature); |
| 594 |
fclose(fid3); |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
} |
| 599 |
stop(); |
| 600 |
|
| 601 |
return(0); |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|