Merge lp:~kumy/frogd/1.1 into lp:frogd

Proposed by Mathieu Alorent
Status: Merged
Approved by: Mathieu Alorent
Approved revision: 2
Merged at revision: 2
Proposed branch: lp:~kumy/frogd/1.1
Merge into: lp:frogd
Diff against target: 1514 lines
To merge this branch: bzr merge lp:~kumy/frogd/1.1
Reviewer Review Type Date Requested Status
Mathieu Alorent Approve
Review via email: mp+86889@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mathieu Alorent (kumy) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2009-04-23 14:20:18 +0000
3+++ README 2011-12-26 10:35:27 +0000
4@@ -1,14 +1,14 @@
5 FROGD version 1.0
6 -----------------
7
8-Ce programme permet de faire l'interface avec les capteurs de temperatures, pression et humidite
9+Ce programme permet de faire l'interface avec les capteurs de temperatures, pression et humidite
10 vendus sur http://www.froggyhome.com
11
12 Il est disponible sur http://www.redge.net/frogd/
13
14 DOC
15 ---
16-La documentation est sous forme de fichiers HTML et se trouve dans le repertoire
17+La documentation est sous forme de fichiers HTML et se trouve dans le repertoire
18 ./doc. Ouvrir le fichier index.html avec un navigateur web.
19
20 voila,
21
22=== modified file 'contrib/cgi/frog-cgi.pl'
23--- contrib/cgi/frog-cgi.pl 2009-04-23 14:20:18 +0000
24+++ contrib/cgi/frog-cgi.pl 2011-12-26 10:35:27 +0000
25@@ -1,6 +1,6 @@
26 #!/usr/bin/perl
27 # configuration :
28-$logfile = "/usr/local/frogd/data/frogd.log";
29+$logfile = "/var/log/frogd.log";
30
31
32 # do not change anything after this line ...
33
34=== modified file 'contrib/console/frog.pl'
35--- contrib/console/frog.pl 2009-04-23 14:20:18 +0000
36+++ contrib/console/frog.pl 2011-12-26 10:35:27 +0000
37@@ -1,6 +1,6 @@
38 #!/usr/bin/perl
39 # configuration:
40-$logfile = "/usr/local/frogd/data/frogd.log";
41+$logfile = "/var/log/frogd.log";
42
43 # programme
44 open(FILE, $logfile);
45
46=== modified file 'contrib/frogd-image/btux-frogd.pl'
47--- contrib/frogd-image/btux-frogd.pl 2009-04-23 14:20:18 +0000
48+++ contrib/frogd-image/btux-frogd.pl 2011-12-26 10:35:27 +0000
49@@ -6,7 +6,7 @@
50 # configuration :
51 # fichier contenant les donnees
52 # data file
53-
54my $froglog = '/usr/local/frogd/data/frogd.log';
55+
56my $froglog = '/var/log/frogd.log';
57
58 # the template image
59 # le modele pour l image
60
61=== modified file 'contrib/frogd-image/f-image.pl'
62--- contrib/frogd-image/f-image.pl 2009-04-23 14:20:18 +0000
63+++ contrib/frogd-image/f-image.pl 2011-12-26 10:35:27 +0000
64@@ -4,7 +4,7 @@
65
66 # configuration
67:
68 # fichier contenant les donnees
69-my $froglog = '/usr/local/frogd/data/frogd.log';
70+my $froglog = '/var/log/frogd.log';
71
72 # the template image
73 # le modele pour l image
74
75=== modified file 'contrib/rrdtool/rrd-update.pl'
76--- contrib/rrdtool/rrd-update.pl 2009-04-23 14:20:18 +0000
77+++ contrib/rrdtool/rrd-update.pl 2011-12-26 10:35:27 +0000
78@@ -2,7 +2,7 @@
79 # configuration
80 # ficher de log de frogd
81 # frogd logfile
82-$logfile = "/usr/local/frogd/data/frogd.log";
83+$logfile = "/var/log/frogd.log";
84
85 # fichier rrd
86 # rrd file
87
88=== modified file 'contrib/rrdtool/rrd-update.sh'
89--- contrib/rrdtool/rrd-update.sh 2009-04-23 14:20:18 +0000
90+++ contrib/rrdtool/rrd-update.sh 2011-12-26 10:35:27 +0000
91@@ -2,7 +2,7 @@
92 # configuration
93 # ficher de log de frogd
94 # frogd logfile
95-logfile="/usr/local/frogd/data/frogd.log";
96+logfile="/var/log/frogd.log";
97
98 # fichier rrd
99 # rrd file
100
101=== modified file 'src/frogd.c'
102--- src/frogd.c 2009-04-23 14:20:18 +0000
103+++ src/frogd.c 2011-12-26 10:35:27 +0000
104@@ -1,20 +1,20 @@
105 /***********************************************************************
106-frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
107-
108-Copyright (C) 2001 (Regis Barbier)
109-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
110-les termes de la Licence Publique Générale GNU publiée par la Free Software
111-Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
112-
113-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
114-GARANTIE, ni explicite ni implicite, y compris les garanties de
115-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
116-Licence Publique Générale GNU pour plus de détails.
117-
118-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
119-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
120-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
121-*************************************************************************/
122+ frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
123+
124+ Copyright (C) 2001 (Regis Barbier)
125+ Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
126+ les termes de la Licence Publique Générale GNU publiée par la Free Software
127+ Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
128+
129+ Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
130+ GARANTIE, ni explicite ni implicite, y compris les garanties de
131+ commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
132+ Licence Publique Générale GNU pour plus de détails.
133+
134+ Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
135+ temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
136+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
137+ *************************************************************************/
138
139
140 #include "frogd.h"
141@@ -25,23 +25,59 @@
142 #include "frogd_mysql.h"
143 #endif
144
145-SensorType sensortype[] =
146+SensorType sensortype[] =
147 {
148- {SENSOR_PRES_TEMP, "Pression-Temperature"},
149- {SENSOR_HR, "hygrometrie"},
150+ {SENSOR_PRES_TEMP, "Pression-Temperature"},
151+ {SENSOR_HR, "hygrometrie"},
152 };
153
154 int nbsensortype = 4;
155+int wannaleave = FALSE;
156+
157+//---------------------------------------------------------------
158+// handle signals
159+//---------------------------------------------------------------
160+void leave(int sig) {
161+ wannaleave = 1;
162+}
163
164 //---------------------------------------------------------------
165 // become a daemon
166 //---------------------------------------------------------------
167-int daemonize(void) {
168+int daemonize(Frog* frog) {
169+ int pid;
170+ int devnull;
171+ FILE *fd;
172+
173+ if (chdir("/")) perror("Can't chdir to /");
174 if (fork()!=0) {
175 exit(0);
176 }
177+
178+ pid = getpid();
179+ if ((fd = fopen(frog->pidfile, "w")) == NULL) {
180+ perror("Can't write pidfile");
181+ exit(2);
182+ }
183+ fprintf(fd, "%d", pid);
184+ fclose(fd);
185+ if (frog->isroot)
186+ if (chown(frog->pidfile, frog->userid, -1))
187+ perror("Can't chown pidfile");
188+ if (frog->isroot)
189+ if (chown(frog->logfile, frog->userid, -1))
190+ perror("Can't chown logfile");
191+ devnull = open("/dev/null", O_RDWR);
192+ dup2(devnull, 0);
193+ dup2(devnull, 1);
194+ dup2(devnull, 2);
195+ close(devnull);
196+
197 setsid();
198- return 1;
199+ if (setgid(frog->groupid)) perror("gid err");
200+ setuid(frog->userid);
201+
202+ return 1;
203 }
204
205 //---------------------------------------------------------------
206@@ -59,11 +95,14 @@
207
208 time(&t);
209 date = localtime(&t);
210-
211- fprintf( file, "%d/%d/%d:%d/%d:%.1f:%.1f:%.1f\n", date->tm_mday, date->tm_mon+1, date->tm_year+1900, date->tm_hour, date->tm_min, frog->lasttemp, frog->lastpress, frog->lasthum);
212-
213+
214+ if (frog->logmultiline)
215+ fprintf( file, "%.1f\n%.1f\n%.1f\n", frog->lasttemp, frog->lastpress, frog->lasthum);
216+ else
217+ fprintf( file, "%d/%d/%d:%d/%d:%.1f:%.1f:%.1f\n", date->tm_mday, date->tm_mon+1, date->tm_year+1900, date->tm_hour, date->tm_min, frog->lasttemp, frog->lastpress, frog->lasthum);
218+
219 fclose(file);
220- return 1;
221+ return 1;
222 }
223
224 //---------------------------------------------------------------
225@@ -75,71 +114,89 @@
226
227 time(&t);
228 date = localtime(&t);
229-
230+
231 printf("On est %d/%d/%d:%dh%d:\n", date->tm_mday, date->tm_mon+1, date->tm_year+1900, date->tm_hour, date->tm_min);
232-
233+
234 printf("**** L'humidite est : %.1f\n", frog->lasthum);
235 printf("**** La temperature est : %.1f\n", frog->lasttemp);
236- printf("**** La pression est : %.1f\n", frog->lastpress);
237- printf("---------------------------\n");
238-
239- return 1;
240-}
241+ printf("**** La pression est : %.1f\n", frog->lastpress);
242+ printf("---------------------------\n");
243+
244+ return 1;
245+}
246+
247+//---------------------------------------------------------------
248+// log Zero to logfile
249+//---------------------------------------------------------------
250+void LogZero(Frog *frog) {
251+ frog->lasttemp = frog->lastpress = frog->lasthum = 0;
252+ if (frog->log) LogLastResult(frog);
253+}
254+
255+
256 //---------------------------------------------------------------
257 // Initialise the frog structure with the defaults values
258 // read config file
259 //---------------------------------------------------------------
260 int InitFrog(Frog* frog) {
261+ memset(frog, 0, sizeof(Frog));
262 frog->debug = FROG_DEBUG;
263 frog->verbose = FROG_VERBOSE;
264- frog->baud = FROG_SPEED;
265+ frog->baud = FROG_SPEED;
266 frog->stopbit = FROG_STOPBIT;
267 frog->altitude = FROG_ALTITUDE;
268 frog->period = FROG_PERIOD;
269 frog->log = FROG_LOG;
270- frog->daemon = FROG_DAEMON;
271- frog->nbretry = FROG_NB_RETRY;
272- strcpy(frog->device, FROG_DEVICE);
273- strcpy(frog->logfile, FROG_LOGFILE);
274- strcpy(frog->logtype, FROG_LOGTYPE);
275- return 1;
276+ frog->daemon = FROG_DAEMON;
277+ frog->nbretry = FROG_NB_RETRY;
278+ frog->userid = geteuid();
279+ frog->groupid = getegid();
280+ frog->isroot = !getuid();
281+ frog->logmultiline = FROG_LOG_MULTILINE;
282+ strncpy(frog->device, FROG_DEVICE, sizeof(frog->device)-1);
283+ strncpy(frog->logfile, FROG_LOGFILE, sizeof(frog->logfile)-1);
284+ strncpy(frog->logtype, FROG_LOGTYPE, sizeof(frog->logtype)-1);
285+ strncpy(frog->pidfile, FROG_PIDFILE, sizeof(frog->pidfile)-1);
286+ return 1;
287 }
288
289 //---------------------------------------------------------------
290-// Print the version and all the data about the frog
291+// Print the version and all the data about the frog
292 //---------------------------------------------------------------
293 int PrintIdentification(Frog* frog) {
294 int i, j, k;
295
296 printf("Copyright Regis Barbier frog@redge.net\n");
297- printf("For more informations please visit : http://www.froggyhome.com\n");
298+ printf("For more informations please visit : http://www.froggyhome.com\n");
299 printf("Frogd version : %s\n", FROG_PROG_VERSION);
300 printf("Frogd device : %s\n", frog->device);
301 printf("Frogd altitude : %d\n", frog->altitude);
302- printf("sample period : %d\n", frog->period);
303+ printf("sample period : %d\n", frog->period);
304 printf("Firmware Version of frog : %d\n", frog->firmware);
305 printf("Serial Number : %d\n", frog->serialnumber);
306- printf("Number of sensors : %d\n", frog->nbsensor);
307+ printf("Number of sensors : %d\n", frog->nbsensor);
308+ printf("Frogd userid : %d\n", frog->userid);
309+ printf("Frogd is running as root? : %d\n", frog->isroot);
310 for( i=0; i<frog->nbsensor; i++) {
311 printf("*sensor number %d\n",i);
312 printf(" sensor type : %x", frog->sensor[i].identification);
313
314-//we try to determine the type of sensor
315+ //we try to determine the type of sensor
316 for (k=0; k<nbsensortype; k++) {
317- if ( sensortype[k].identification == (frog->sensor[i].identification & SENSOR_IDENTIFICATION_MASK) )
318+ if ( sensortype[k].identification == (frog->sensor[i].identification & SENSOR_IDENTIFICATION_MASK) )
319 printf (" (%s) \n", sensortype[k].name ) ;
320 }
321 printf(" sensor physical mes : %x\n", frog->sensor[i].phymesurementsize);
322 printf(" sensor data size : %x\n", frog->sensor[i].datasize);
323 printf(" sensor data : ");
324
325-// Now we print the raw data for the sensor
326+ // Now we print the raw data for the sensor
327 for(j=0; j<frog->sensor[i].datasize; j++) {
328 printf("%.2x ", frog->sensor[i].data[j]);
329 }
330 printf("\n");
331 }
332- return 1;
333+ return 1;
334 }
335
336 //---------------------------------------------------------------
337@@ -148,9 +205,41 @@
338 char parse_cmdline(int argc,char *argv[], Frog* frog) {
339 int errflg=0;
340 int c;
341+ char username[25];
342+ char groupname[25];
343+ struct passwd* pwnam;
344+ struct group* grnam;
345
346- while ((c = getopt(argc, argv, "fdvlp:L:D:a:r:")) != EOF) {
347+ while ((c = getopt(argc, argv, "fdvcmlp:L:D:a:r:u:i:g:")) != EOF) {
348 switch (c) {
349+ case 'u':
350+ // todo if -u is user ne pas alerter
351+ if (!frog->isroot) {
352+ printf("You're not root, cannot change user\n");
353+ exit (2); // exit 2 ou autre ?
354+ }
355+ if (optarg != NULL) {
356+ strncpy(username, optarg, sizeof(username)-1);
357+ username[sizeof(username)-1] = '\0';
358+ pwnam = getpwnam(username);
359+ frog->userid = pwnam->pw_uid;
360+ }
361+ break;
362+
363+ case 'g':
364+ // todo if -u is user ne pas alerter
365+ if (!frog->isroot) {
366+ printf("You're not root, cannot change group\n");
367+ exit (2); // exit 2 ou autre ?
368+ }
369+ if (optarg != NULL) {
370+ strncpy(groupname, optarg, sizeof(groupname)-1);
371+ groupname[sizeof(groupname)-1] = '\0';
372+ grnam = getgrnam(groupname);
373+ frog->groupid = grnam->gr_gid;
374+ }
375+ break;
376+
377 case 'f':
378 frog->daemon=FALSE;
379 break;
380@@ -158,76 +247,97 @@
381 case 'd':
382 frog->debug=TRUE;
383 break;
384-
385+
386 case 'v':
387 frog->verbose=TRUE ;
388 break;
389-
390+
391 case 'l':
392 frog->log = TRUE;
393 break;
394
395+ case 'm':
396+ frog->logmultiline = TRUE;
397+ break;
398+
399 case 'p':
400 frog->period = atoi(optarg);
401 if (frog->period < FROG_MIN_PERIOD)
402- break;
403+ break;
404
405 case 'r':
406 frog->nbretry = atoi(optarg);
407 break;
408
409+ case 'i':
410+ if (optarg != NULL) {
411+ strncpy(frog->pidfile,optarg, sizeof(frog->pidfile)-1);
412+ frog->pidfile[sizeof(frog->pidfile)-1] = '\0';
413+ }
414+ break;
415+
416 case 'L':
417 frog->log = TRUE;
418- if (optarg != NULL) {
419- strcpy(frog->logfile,optarg);
420- }
421- break;
422-
423- case 'h':
424- strcpy(frog->logtype,"a");
425- break;
426-
427+ if (optarg != NULL) {
428+ strncpy(frog->logfile,optarg, sizeof(frog->logfile)-1);
429+ frog->logfile[sizeof(frog->logfile)-1] = '\0';
430+ }
431+ break;
432+
433+ case 'c':
434+ strncpy(frog->logtype,"a", 2);
435+ break;
436+
437 case 'D':
438- strcpy(frog->device,optarg);
439- break;
440-
441+ strncpy(frog->device,optarg, sizeof(frog->device)-1);
442+ frog->device[sizeof(frog->device)-1] = '\0';
443+ break;
444+
445 case 'a':
446 frog->altitude = atoi(optarg);
447- break;
448+ break;
449
450 case 'H':
451- strcpy(frog->mysqlhost,optarg);
452- frog->logmysql = TRUE ;
453- break;
454+ strncpy(frog->mysqlhost,optarg, sizeof(frog->mysqlhost)-1);
455+ frog->mysqlhost[sizeof(frog->mysqlhost)-1] = '\0';
456+ frog->logmysql = TRUE ;
457+ break;
458
459 case 'U':
460- strcpy(frog->mysqluser,optarg);
461- break;
462+ strncpy(frog->mysqluser,optarg, sizeof(frog->mysqluser)-1);
463+ frog->mysqluser[sizeof(frog->mysqluser)-1] = '\0';
464+ break;
465
466 case 'P':
467- strcpy(frog->mysqlpassword,optarg);
468- break;
469+ strncpy(frog->mysqlpassword,optarg, sizeof(frog->mysqlpassword)-1);
470+ frog->mysqlpassword[sizeof(frog->mysqlpassword)-1] = '\0';
471+ break;
472
473 case 'B':
474- strcpy(frog->mysqldb,optarg);
475- break;
476+ strncpy(frog->mysqldb,optarg, sizeof(frog->mysqldb)-1);
477+ frog->mysqldb[sizeof(frog->mysqldb)-1] = '\0';
478+ break;
479
480 case '?':
481 errflg++;
482- break;
483-
484+ break;
485+
486 }
487- if (errflg) {
488- printf( "utilisation: frog [-v] [-d] [-l] [-f] [-h]\n[-a altitude] [-L fichier] [-D /dev/ttySx] [-p periode] [-r fois]\n
489+ if (errflg) {
490+ printf( "utilisation: frog [-v] [-d] [-l] [-f] [-h] [-c] [-m] [-u user] [-g group]\n"
491+ " [-a altitude] [-p periode] [-r fois]\n"
492+ " [-D device=" FROG_DEVICE "]\n"
493+ " [-L logfile=" FROG_LOGFILE "]\n"
494+ " [-i pidfile=" FROG_PIDFILE "]\n"
495 #ifdef HAVE_MYSQL
496-[-H mysql hote] [-B mysql base] [-U mysql user] [-P mysql password]\n
497+ " [-H mysql_host] [-B mysql_database] [-U mysql_user] [-P mysql_password]\n"
498 #endif
499-");
500- exit (2);
501- }
502- }
503-
504- return 1;
505+ );
506+ exit (2);
507+ }
508+ }
509+
510+ return 1;
511 }
512
513 //---------------------------------------------------------------
514@@ -238,35 +348,39 @@
515 Frog* frog;
516 int error=FALSE;
517 int nberror=0;
518- frog=&frog1;
519-
520+ frog=&frog1;
521+
522+ (void) signal(SIGTERM,leave);
523+
524 InitFrog(frog);
525 parse_cmdline(argc,argv, frog);
526- if (frog->daemon) daemonize();
527+ LogZero(frog);
528
529 if (OpenPort(frog)<0) {
530- printf("can't open serial port: %s\n",frog->device);
531- exit(1);
532+ printf("can't open serial port: %s\n",frog->device);
533+ exit(1);
534 }
535-
536+
537 if (ConfigurePort(frog)<0) {
538- printf("can't configure serial port: %s\n",frog->device);
539- exit(1);
540- }
541+ printf("can't configure serial port: %s\n",frog->device);
542+ exit(1);
543+ }
544
545 #ifdef HAVE_MYSQL
546 if (ConnectDBFrog(frog)<0) {
547- printf("host |%s|:\n",frog->mysqlhost);
548- printf("user |%s|:\n",frog->mysqluser);
549- printf("db |%s|:\n",frog->mysqldb);
550- printf("can't connect to |%s| mysql database\n",frog->mysqlhost);
551- exit(1);
552+ printf("host |%s|:\n",frog->mysqlhost);
553+ printf("user |%s|:\n",frog->mysqluser);
554+ printf("db |%s|:\n",frog->mysqldb);
555+ printf("can't connect to |%s| mysql database\n",frog->mysqlhost);
556+ exit(1);
557 }else{
558- if (frog->debug) printf("connected to host %s base %s user %s\n",frog->mysqlhost,frog->mysqldb, frog->mysqluser);
559+ if (frog->debug) printf("connected to host %s base %s user %s\n",frog->mysqlhost,frog->mysqldb, frog->mysqluser);
560 }
561 #endif
562
563- while (frog->nbretry != nberror) {
564+ if (frog->daemon) daemonize(frog);
565+
566+ while (!wannaleave && frog->nbretry != nberror) {
567 ResetFrog(frog);
568 error=FALSE;
569 if (GetIdentification(frog) < 0) {
570@@ -274,7 +388,7 @@
571 if (frog->nbretry) nberror++;
572 }
573 if ((frog->verbose) && !error) PrintIdentification(frog);
574- while (error==FALSE) {
575+ while (!wannaleave && error==FALSE) {
576 sleep(frog->period);
577 if (CalcValue(frog)<0) {
578 error=TRUE;
579@@ -284,21 +398,19 @@
580 if ((frog->verbose) && !error) PrintLastResult(frog);
581
582 #ifdef HAVE_MYSQL
583- if (frog->logmysql) {
584- ConnectDBFrog(frog);
585- InsertDBFrog(frog);
586- CloseDBFrog();
587- }
588-#endif
589+ if (frog->logmysql) {
590+ ConnectDBFrog(frog);
591+ InsertDBFrog(frog);
592+ CloseDBFrog();
593+ }
594+#endif
595
596- }
597+ }
598 }
599
600- ClosePort(frog);
601- if (close(frog->fd)== -1) perror("close");
602+ LogZero(frog);
603+ ClosePort(frog);
604+ if (close(frog->fd)== -1) perror("close");
605+ if (frog->daemon) unlink(frog->pidfile);
606 return(0);
607 }
608-
609-
610-
611-
612
613=== modified file 'src/frogd.h'
614--- src/frogd.h 2009-04-23 14:20:18 +0000
615+++ src/frogd.h 2011-12-26 10:35:27 +0000
616@@ -1,35 +1,39 @@
617 /***********************************************************************
618-frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
619-
620-Copyright (C) 2001 (Regis Barbier)
621-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
622-les termes de la Licence Publique Générale GNU publiée par la Free Software
623-Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
624-
625-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
626-GARANTIE, ni explicite ni implicite, y compris les garanties de
627-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
628-Licence Publique Générale GNU pour plus de détails.
629-
630-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
631-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
632-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
633-*************************************************************************/
634+ frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
635+
636+ Copyright (C) 2001 (Regis Barbier)
637+ Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
638+ les termes de la Licence Publique Générale GNU publiée par la Free Software
639+ Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
640+
641+ Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
642+ GARANTIE, ni explicite ni implicite, y compris les garanties de
643+ commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
644+ Licence Publique Générale GNU pour plus de détails.
645+
646+ Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
647+ temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
648+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
649+ *************************************************************************/
650
651 #ifndef FROG_H
652 #define FROG_H
653-
654+
655 #include <sys/termios.h>
656 #include <fcntl.h>
657 #include <unistd.h>
658 #include <stdio.h>
659-#include <sys/ioctl.h>
660+#include <sys/ioctl.h>
661 #include <string.h>
662 #include <time.h>
663 #include <stdlib.h>
664 #include <math.h>
665 #include <sys/file.h>
666 #include "../config.h"
667+#include <pwd.h>
668+#include <grp.h>
669+#include <signal.h>
670+#include <errno.h>
671
672 #define TRUE 1
673 #define FALSE 0
674@@ -43,17 +47,19 @@
675 #define FROG_MAX_CHECKSUM_SIZE 5
676 #define FROG_DEVICE "/dev/ttyS0"
677 #define FROG_LOG FALSE
678+#define FROG_LOG_MULTILINE FALSE
679 #define FROG_LOGFILE "/var/log/frogd.log"
680+#define FROG_PIDFILE "/var/run/frogd.pid"
681 #define FROG_ALTITUDE 0
682 #define FROG_MIN_PERIOD 70
683 #define FROG_PERIOD 70
684 #define FROG_DEBUG FALSE
685 #define FROG_VERBOSE FALSE
686-#define FROG_DAEMON TRUE
687+#define FROG_DAEMON TRUE
688 #define FROG_READ_DELAY 10
689 #define FROG_NB_RETRY -1
690 #define FROG_LOGTYPE "w"
691-
692+
693 #define MAX_SENSOR_DATA 200
694 #define MAX_SENSOR_NUMBER 3
695
696@@ -69,21 +75,21 @@
697 #define BEGIN_FRAME 'G'
698 #define END_FRAME 'Z'
699
700-typedef struct {
701+typedef struct {
702 unsigned char identification;
703 char name[SENSOR_MAX_NAME_SIZE];
704 } SensorType;
705
706-typedef struct {
707+typedef struct {
708 unsigned int identification;
709 unsigned int phymesurementsize;
710 unsigned int datasize;
711 unsigned char data[MAX_SENSOR_DATA];
712 } Sensor;
713
714-
715-typedef struct {
716-// config
717+
718+typedef struct {
719+ // config
720 int debug;
721 int verbose;
722 int baud;
723@@ -92,34 +98,39 @@
724 int period;
725 char device[100];
726 int log;
727+ int logmultiline;
728 char logfile[100];
729 int daemon;
730+ char pidfile[100];
731 int nbretry;
732+ int userid;
733+ int groupid;
734+ int isroot;
735 char logtype[100];
736-// identification
737+ // identification
738 unsigned int firmware;
739 unsigned int partnumber;
740 unsigned int serialnumber;
741- unsigned int nbsensor;
742-// data
743+ unsigned int nbsensor;
744+ // data
745 int fd;
746 Sensor sensor[MAX_SENSOR_NUMBER];
747 float lasttemp;
748- float lastpress;
749+ float lastpress;
750 float lasthum;
751- // mysql
752- char mysqlhost[MYSQL_MAX_CHAR_DB];
753- char mysqldb[MYSQL_MAX_CHAR_DB];
754- char mysqluser[MYSQL_MAX_CHAR_DB];
755- char mysqlpassword[MYSQL_MAX_CHAR_DB];
756- char mysqlquery[MYSQL_MAX_CHAR_QUERY];
757- int logmysql;
758+ // mysql
759+ char mysqlhost[MYSQL_MAX_CHAR_DB];
760+ char mysqldb[MYSQL_MAX_CHAR_DB];
761+ char mysqluser[MYSQL_MAX_CHAR_DB];
762+ char mysqlpassword[MYSQL_MAX_CHAR_DB];
763+ char mysqlquery[MYSQL_MAX_CHAR_QUERY];
764+ int logmysql;
765 } Frog;
766
767 //---------------------------------------------------------------
768 // become a daemon
769 //---------------------------------------------------------------
770-int daemonize(void);
771+int daemonize(Frog* frog);
772
773 //---------------------------------------------------------------
774 // log the last value generated
775@@ -138,7 +149,7 @@
776 int InitFrog(Frog* frog);
777
778 //---------------------------------------------------------------
779-// Print the version and all the data about the frog
780+// Print the version and all the data about the frog
781 //---------------------------------------------------------------
782 int PrintIdentification(Frog* frog);
783
784@@ -147,4 +158,9 @@
785 //---------------------------------------------------------------
786 char parse_cmdline(int argc,char *argv[], Frog* frog);
787
788+//---------------------------------------------------------------
789+// log Zero to filelog
790+//---------------------------------------------------------------
791+void LogZero(Frog *frog);
792+
793 #endif
794
795=== modified file 'src/frogd_calc.c'
796--- src/frogd_calc.c 2009-04-23 14:20:18 +0000
797+++ src/frogd_calc.c 2011-12-26 10:35:27 +0000
798@@ -1,20 +1,20 @@
799 /***********************************************************************
800-frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
801-
802-Copyright (C) 2001 (Regis Barbier)
803-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
804-les termes de la Licence Publique Générale GNU publiée par la Free Software
805-Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
806-
807-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
808-GARANTIE, ni explicite ni implicite, y compris les garanties de
809-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
810-Licence Publique Générale GNU pour plus de détails.
811-
812-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
813-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
814-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
815-*************************************************************************/
816+ frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
817+
818+ Copyright (C) 2001 (Regis Barbier)
819+ Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
820+ les termes de la Licence Publique Générale GNU publiée par la Free Software
821+ Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
822+
823+ Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
824+ GARANTIE, ni explicite ni implicite, y compris les garanties de
825+ commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
826+ Licence Publique Générale GNU pour plus de détails.
827+
828+ Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
829+ temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
830+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
831+ *************************************************************************/
832
833 #include "frogd.h"
834 #include "frogd_calc.h"
835@@ -32,12 +32,12 @@
836 float fUTI,fDT,fTemp;
837 float fOFF,fSENS,fX,fPress;
838 int w;
839-
840- Word1=Word2=Word3=Word4=0;
841- C1=C2=C3=C4=C5=C6=0;
842-
843+
844+ Word1=Word2=Word3=Word4=0;
845+ C1=C2=C3=C4=C5=C6=0;
846+
847 Decode(reponse, tempo, frog->sensor[sensornumber].phymesurementsize*2+2);
848-
849+
850 Word1=frog->sensor[sensornumber].data[1];
851 Word1<<=8;
852 Word1|=frog->sensor[sensornumber].data[2];
853@@ -53,15 +53,15 @@
854
855 C1=Word1 & 0xFFFE;
856 C1>>=1;
857-
858+
859 C2=Word3 & 0x003F;
860 C2<<=6;
861 w=Word4 & 0x003F;
862 C2|=w;
863-
864+
865 C3=Word4 & 0xFFC0;
866 C3>>=6;
867-
868+
869 C4=Word3 & 0xFFC0;
870 C4>>=6;
871
872@@ -72,7 +72,7 @@
873 C5|=w;
874
875 C6=Word2 & 0x003F;
876-
877+
878 D1=tempo[1];
879 D1<<=8;
880 D1|=tempo[2];
881@@ -80,7 +80,7 @@
882 D2=tempo[3];
883 D2<<=8;
884 D2|=tempo[4];
885-
886+
887 if (frog->debug) {
888 printf("word1 : %.4X\n",Word1);
889 printf("word2 : %.4X\n",Word2);
890@@ -94,26 +94,26 @@
891 printf("word1 : %.2X\n",C6);
892 printf("D1 : %.2X\n",D1);
893 printf("D2 : %.2X\n",D2);
894- }
895-
896-/* if (D2==0) {
897- bErr=TRUE;
898- return (float)0.0;
899- }*/
900-
901+ }
902+
903+ /* if (D2==0) {
904+ bErr=TRUE;
905+ return (float)0.0;
906+ }*/
907+
908 fUTI=8*(float)C5+20224;
909 if ((float)D2>=fUTI) {
910 fDT=D2-fUTI;
911 fTemp=(200+fDT*(C6+50)/1024)/10;
912 } else {
913 fDT=(D2-fUTI)-( ((D2-fUTI)/128)*((D2-fUTI)/128) )/4;
914- fTemp=(200+fDT*(C6+50)/1024+fDT/256)/10;
915+ fTemp=(200+fDT*(C6+50)/1024+fDT/256)/10;
916 }
917
918-/* if ((D1==0) && (D2==0)) {
919- bErr=TRUE;
920- return (float)0.0;
921- }*/
922+ /* if ((D1==0) && (D2==0)) {
923+ bErr=TRUE;
924+ return (float)0.0;
925+ }*/
926
927 fUTI=8*(float)C5+20224;
928
929@@ -123,11 +123,11 @@
930 fPress=fX*10/32+2500;
931 fPress=fPress/10;
932 fPress=fPress*(float)pow(10,(float) frog->altitude/19434);
933-
934+
935 frog->lasttemp = fTemp;
936- frog->lastpress = fPress;
937+ frog->lastpress = fPress;
938
939- return 1;
940+ return 1;
941 }
942
943 //---------------------------------------------------------------
944@@ -140,13 +140,13 @@
945 unsigned short int Mesure;
946 float fImped, fHum;
947 float fa,fb,fc,fd,fT2,fT3;
948- float fA1,fA2,fA3,fA4,fB1,fB2,fB3,fB4,fC1,fC2,fC3,fC4,fD1,fD2,fD3,fD4;
949-
950+ float fA1,fA2,fA3,fA4,fB1,fB2,fB3,fB4,fC1,fC2,fC3,fC4,fD1,fD2,fD3,fD4;
951+
952 float fTemp;
953
954 if (frog->debug) printf("we are in CalcHr and temperature is %f\n",frog->lasttemp);
955 fTemp = frog->lasttemp;
956-
957+
958 Decode(reponse, tempo, frog->sensor[sensornumber].phymesurementsize*2+2);
959
960 NbBits=frog->sensor[sensornumber].data[1];
961@@ -168,14 +168,14 @@
962 printf("Rp : %.3X\n",Rp);
963 }
964
965-/*
966- if (pData[0]==0xFF)
967- { bErr=TRUE;
968- return (float)0.0;
969- }
970- else bErr=FALSE;
971-*/
972-
973+ /*
974+ if (pData[0]==0xFF)
975+ { bErr=TRUE;
976+ return (float)0.0;
977+ }
978+ else bErr=FALSE;
979+ */
980+
981 Mesure=tempo[1];
982 Mesure<<=8;
983 Mesure|=tempo[2];
984@@ -204,9 +204,9 @@
985
986 if (fHum>(float)100.0) fHum=(float)100.0;
987 if (fHum<(float)0.0) fHum=(float)0.0;
988-
989- frog->lasthum = fHum;
990-
991+
992+ frog->lasthum = fHum;
993+
994 return 1;
995 }
996
997@@ -216,23 +216,23 @@
998 int CalcValue(Frog* frog) {
999 unsigned char tab[255];
1000 unsigned char* reponse;
1001- int nbread;
1002+ int nbread;
1003 char* command="01"; // command 01 => ask le last values
1004 int i;
1005
1006 if (frog->debug) printf("We are in CalcValue\n");
1007-
1008+
1009 reponse = tab;
1010 if ( (nbread = AskFrog(command, frog, reponse)) < 0) {
1011- printf("Askfrog not successfull \n");
1012+ printf("Askfrog not successfull - CalcValue\n");
1013 return -1;
1014 }
1015-
1016- reponse+=1; // strip leading G
1017-
1018+
1019+ reponse+=1; // strip leading G
1020+
1021 if (frog->debug) {
1022 for (i=0; i<nbread/2; i++) {
1023- printf("offset %d - values %c%c \n",i*2,reponse[i*2], reponse[i*2+1]);
1024+ printf("offset %d - values %c%c \n",i*2,reponse[i*2], reponse[i*2+1]);
1025 }
1026 printf("frame size : %d octet\n", nbread );
1027 }
1028@@ -244,12 +244,12 @@
1029 case SENSOR_PRES_TEMP:
1030 CalcPresTemp(frog, i, reponse);
1031 break;
1032-
1033+
1034 case SENSOR_HR:
1035 CalcHr(frog, i, reponse);
1036- break;
1037+ break;
1038 }
1039 reponse += frog->sensor[i].phymesurementsize*2 + 2; // go to the next sensor
1040- }
1041+ }
1042 return 1;
1043 }
1044
1045=== modified file 'src/frogd_calc.h'
1046--- src/frogd_calc.h 2009-04-23 14:20:18 +0000
1047+++ src/frogd_calc.h 2011-12-26 10:35:27 +0000
1048@@ -1,20 +1,20 @@
1049 /***********************************************************************
1050-frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1051-
1052-Copyright (C) 2001 (Regis Barbier)
1053-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1054-les termes de la Licence Publique Générale GNU publiée par la Free Software
1055-Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1056-
1057-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1058-GARANTIE, ni explicite ni implicite, y compris les garanties de
1059-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1060-Licence Publique Générale GNU pour plus de détails.
1061-
1062-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1063-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1064-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1065-*************************************************************************/
1066+ frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1067+
1068+ Copyright (C) 2001 (Regis Barbier)
1069+ Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1070+ les termes de la Licence Publique Générale GNU publiée par la Free Software
1071+ Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1072+
1073+ Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1074+ GARANTIE, ni explicite ni implicite, y compris les garanties de
1075+ commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1076+ Licence Publique Générale GNU pour plus de détails.
1077+
1078+ Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1079+ temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1080+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1081+ *************************************************************************/
1082
1083 #ifndef FROG_CALC_H
1084 #define FROG_CALC_H
1085
1086=== modified file 'src/frogd_comm.c'
1087--- src/frogd_comm.c 2009-04-23 14:20:18 +0000
1088+++ src/frogd_comm.c 2011-12-26 10:35:27 +0000
1089@@ -1,20 +1,20 @@
1090 /***********************************************************************
1091-frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1092-
1093-Copyright (C) 2001 (Regis Barbier)
1094-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1095-les termes de la Licence Publique Générale GNU publiée par la Free Software
1096-Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1097-
1098-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1099-GARANTIE, ni explicite ni implicite, y compris les garanties de
1100-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1101-Licence Publique Générale GNU pour plus de détails.
1102-
1103-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1104-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1105-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1106-*************************************************************************/
1107+ frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1108+
1109+ Copyright (C) 2001 (Regis Barbier)
1110+ Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1111+ les termes de la Licence Publique Générale GNU publiée par la Free Software
1112+ Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1113+
1114+ Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1115+ GARANTIE, ni explicite ni implicite, y compris les garanties de
1116+ commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1117+ Licence Publique Générale GNU pour plus de détails.
1118+
1119+ Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1120+ temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1121+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1122+ *************************************************************************/
1123
1124 #include "frogd.h"
1125 #include "frogd_comm.h"
1126@@ -26,15 +26,15 @@
1127 unsigned char tempo[FROG_MAX_FRAME_SIZE];
1128 unsigned char check;
1129 int i;
1130-
1131+
1132 Decode(input+1, tempo, framesize-1);
1133-
1134+
1135 check='G';
1136 for (i=0; i<(framesize-1)/2; i++) {
1137 check=check^tempo[i];
1138 }
1139-
1140- sprintf( checksum, "%.2X", check);
1141+
1142+ sprintf( checksum, "%.2X", check);
1143 if (frog->debug) printf("Checksum is %s, framesize is %d\n", checksum, framesize);
1144 return 1;
1145
1146@@ -49,13 +49,13 @@
1147
1148 for(i=0; i<(size/2) ;i++) {
1149 sscanf( input+(i*2), "%2x", &a);
1150- *(output+i) = a;
1151-// write(1, input+(i*2), 2);
1152-// printf("dec - %.2X \n",*(output+i) );
1153+ *(output+i) = a;
1154+ // write(1, input+(i*2), 2);
1155+ // printf("dec - %.2X \n",*(output+i) );
1156 }
1157 return 1;
1158 }
1159-
1160+
1161 //---------------------------------------------------------------
1162 // Open the serial port put the file descriptor in frog->fd
1163 //---------------------------------------------------------------
1164@@ -69,7 +69,7 @@
1165 printf ("device is not a tty device\n");
1166 close(frog->fd);
1167 return -1;
1168- }
1169+ }
1170
1171 flock(frog->fd, LOCK_EX );
1172 if (frog->debug) printf("Serial port Opened\n");
1173@@ -95,7 +95,7 @@
1174 int ConfigurePort (Frog* frog) {
1175 struct termios attr;
1176
1177- bzero(&attr, sizeof(attr));
1178+ bzero(&attr, sizeof(attr));
1179 attr.c_cflag |= (CS8 | CLOCAL | CREAD);
1180 if (frog->stopbit == 2) {
1181 attr.c_cflag |= CSTOPB;
1182@@ -103,7 +103,7 @@
1183 attr.c_iflag = BRKINT | INPCK;
1184 attr.c_oflag = 0;
1185 attr.c_lflag = 0;
1186-
1187+
1188 attr.c_cc[VTIME] = FROG_READ_DELAY;
1189 attr.c_cc[VMIN] = 0;
1190
1191@@ -114,25 +114,25 @@
1192 if (cfsetospeed(&attr, frog->baud)== -1) {
1193 perror("Can't set the serial port output speed");
1194 return -1;
1195- }
1196+ }
1197
1198- if (tcsetattr(frog->fd,TCSANOW,&attr)== -1) {
1199+ if (tcsetattr(frog->fd,TCSANOW,&attr)== -1) {
1200 perror("Can't set the serial port configuration");
1201 return -1;
1202 }
1203-
1204+
1205 if (frog->debug) printf("Setattr (ConfigurePort) done\n");
1206 return(1);
1207 }
1208
1209 //---------------------------------------------------------------
1210-// Reset the frog by switching it OFF and ON
1211+// Reset the frog by switching it OFF and ON
1212 //---------------------------------------------------------------
1213 int ResetFrog(Frog* frog) {
1214 int status;
1215- if (ioctl(frog->fd, TIOCMGET, &status) == -1 )
1216+ if (ioctl(frog->fd, TIOCMGET, &status) == -1 )
1217 perror("Can't get the serial port modem line status");
1218-
1219+
1220 status |= TIOCM_DTR;
1221 status &= ~TIOCM_RTS;
1222 if (ioctl(frog->fd, TIOCMSET, &status) == -1 ) {
1223@@ -140,7 +140,7 @@
1224 return -1;
1225 }
1226 sleep(FROG_RESET_DELAY);
1227-
1228+
1229 status &= ~TIOCM_DTR ;
1230 status |= TIOCM_RTS ;
1231
1232@@ -148,10 +148,10 @@
1233 perror("Can't set the serial port modem line status");
1234 return -1;
1235 }
1236-
1237+
1238 sleep(FROG_RESET_DELAY);
1239 tcflush(frog->fd,TCIOFLUSH );
1240-
1241+
1242 if (frog->debug) printf("Frog reset done\n");
1243 return(1);
1244 }
1245@@ -165,17 +165,17 @@
1246 int gotend=FALSE;
1247 int i;
1248
1249- sprintf(frame, "G%s", command);
1250+ sprintf(frame, "G%s", command);
1251 CalcCheckSum(frog, frame, strlen(frame), checksum);
1252 sprintf(frame, "G%s%sZ", command, checksum);
1253-
1254+
1255 if (write(frog->fd, frame , strlen(frame) ) != strlen(frame)) {
1256- printf ("Can't write to the serial port");
1257+ printf ("Can't write to the serial port\n");
1258 return -1;
1259 }
1260
1261 if (frog->debug) printf("frame sent : %s\n", frame);
1262-
1263+
1264 i = 0;
1265 while (!gotend) {
1266 if (read(frog->fd, response+i, 1) <=0) {
1267@@ -203,24 +203,24 @@
1268 int GetIdentification(Frog* frog) {
1269 unsigned char tab[255];
1270 unsigned char* reponse;
1271- int nbread;
1272+ int nbread;
1273 char* com="00"; // command "00" => get frog identification
1274 int i;
1275 int offset;
1276-
1277+
1278 if (frog->debug) printf("We are in GetIdentification\n");
1279 reponse = tab;
1280-
1281+
1282 if ( (nbread = AskFrog(com, frog, reponse)) < 0) {
1283- printf("Askfrog not successfull \n");
1284+ printf("Askfrog not successfull - GetIdentification\n");
1285 return -1;
1286 }
1287-
1288+
1289 reponse++; // strip leading G
1290
1291 if (frog->debug) {
1292 for (i=0; i<nbread/2; i++) {
1293- printf("offset %d - value %c%c \n", i*2, reponse[i*2], reponse[i*2+1]);
1294+ printf("offset %d - value %c%c \n", i*2, reponse[i*2], reponse[i*2+1]);
1295 }
1296 printf("frame size : %d octet\n", nbread );
1297 }
1298@@ -229,7 +229,7 @@
1299 sscanf(reponse+4, "%2x", &(frog->partnumber));
1300 sscanf(reponse+6, "%8x", &(frog->serialnumber));
1301 sscanf(reponse+14, "%2x", &(frog->nbsensor));
1302-
1303+
1304 offset = 16;
1305 for (i=0; i<frog->nbsensor; i++) {
1306 sscanf(reponse+ offset , "%2x", &(frog->sensor[i].identification));
1307@@ -238,17 +238,6 @@
1308 Decode( reponse+ offset + 6, (unsigned char*) &(frog->sensor[i].data), frog->sensor[i].datasize*2 );
1309 offset += 6 + frog->sensor[i].datasize*2;
1310 }
1311-
1312+
1313 return 1;
1314 }
1315-
1316-
1317-
1318-
1319-
1320-
1321-
1322-
1323-
1324-
1325-
1326
1327=== modified file 'src/frogd_comm.h'
1328--- src/frogd_comm.h 2009-04-23 14:20:18 +0000
1329+++ src/frogd_comm.h 2011-12-26 10:35:27 +0000
1330@@ -2,17 +2,17 @@
1331 frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1332
1333 Copyright (C) 2001 (Regis Barbier)
1334-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1335-les termes de la Licence Publique Générale GNU publiée par la Free Software
1336+Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1337+les termes de la Licence Publique Générale GNU publiée par la Free Software
1338 Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1339
1340-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1341-GARANTIE, ni explicite ni implicite, y compris les garanties de
1342-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1343+Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1344+GARANTIE, ni explicite ni implicite, y compris les garanties de
1345+commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1346 Licence Publique Générale GNU pour plus de détails.
1347
1348-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1349-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1350+Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1351+temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1352 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1353 *************************************************************************/
1354
1355@@ -47,7 +47,7 @@
1356 int ConfigurePort(Frog* frog);
1357
1358 //---------------------------------------------------------------
1359-// Reset the frog by switching it OFF and ON
1360+// Reset the frog by switching it OFF and ON
1361 //---------------------------------------------------------------
1362 int ResetFrog(Frog* frog) ;
1363
1364
1365=== modified file 'src/frogd_mysql.c'
1366--- src/frogd_mysql.c 2009-04-23 14:20:18 +0000
1367+++ src/frogd_mysql.c 2011-12-26 10:35:27 +0000
1368@@ -1,54 +1,54 @@
1369 /***********************************************************************
1370-frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1371-
1372-Copyright (C) 2001 (Regis Barbier)
1373-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1374-les termes de la Licence Publique Générale GNU publiée par la Free Software
1375-Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1376-
1377-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1378-GARANTIE, ni explicite ni implicite, y compris les garanties de
1379-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1380-Licence Publique Générale GNU pour plus de détails.
1381-
1382-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1383-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1384-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1385-*************************************************************************/
1386+ frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1387+
1388+ Copyright (C) 2001 (Regis Barbier)
1389+ Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1390+ les termes de la Licence Publique Générale GNU publiée par la Free Software
1391+ Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1392+
1393+ Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1394+ GARANTIE, ni explicite ni implicite, y compris les garanties de
1395+ commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1396+ Licence Publique Générale GNU pour plus de détails.
1397+
1398+ Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1399+ temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1400+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1401+ *************************************************************************/
1402
1403 #include "frogd.h"
1404 #include "frogd_mysql.h"
1405 #include "mysql.h"
1406 MYSQL mysql;
1407 //---------------------------------------------------------------
1408-// Open a connexion with MySQL.
1409+// Open a connexion with MySQL.
1410 //---------------------------------------------------------------
1411 int ConnectDBFrog(Frog* frog) {
1412- mysql_init(&mysql);
1413- if (!mysql_real_connect(&mysql,frog->mysqlhost,frog->mysqluser,frog->mysqlpassword,frog->mysqldb, 0, NULL, 0))
1414- return -1;
1415- return 1;
1416+ mysql_init(&mysql);
1417+ if (!mysql_real_connect(&mysql,frog->mysqlhost,frog->mysqluser,frog->mysqlpassword,frog->mysqldb, 0, NULL, 0))
1418+ return -1;
1419+ return 1;
1420 }
1421
1422 //---------------------------------------------------------------
1423-// Insert the frog values into the DB
1424+// Insert the frog values into the DB
1425 //---------------------------------------------------------------
1426 int InsertDBFrog(Frog* frog) {
1427- struct tm* date;
1428- time_t t;
1429- time(&t);
1430- date = localtime(&t);
1431-
1432- sprintf(frog->mysqlquery,"INSERT INTO froggyhome (frog_date,frog_temp,frog_hum,frog_press) values (\"%d-%d-%d %d:%d:%d\", \"%.1f\", \"%.1f\", \"%.1f\")",date->tm_year+1900,date->tm_mon+1,date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec,frog->lasttemp,frog->lasthum,frog->lastpress);
1433-
1434- if (mysql_query(&mysql, frog->mysqlquery))
1435- return 1;
1436- else return -1;
1437+ struct tm* date;
1438+ time_t t;
1439+ time(&t);
1440+ date = localtime(&t);
1441+
1442+ sprintf(frog->mysqlquery,"INSERT INTO froggyhome (frog_date,frog_temp,frog_hum,frog_press) values (\"%d-%d-%d %d:%d:%d\", \"%.1f\", \"%.1f\", \"%.1f\")",date->tm_year+1900,date->tm_mon+1,date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec,frog->lasttemp,frog->lasthum,frog->lastpress);
1443+
1444+ if (mysql_query(&mysql, frog->mysqlquery))
1445+ return 1;
1446+ else return -1;
1447 }
1448
1449 //---------------------------------------------------------------
1450-// Close the frog database
1451+// Close the frog database
1452 //---------------------------------------------------------------
1453 int CloseDBFrog() {
1454- mysql_close(&mysql);
1455+ mysql_close(&mysql);
1456 }
1457
1458=== modified file 'src/frogd_mysql.h'
1459--- src/frogd_mysql.h 2009-04-23 14:20:18 +0000
1460+++ src/frogd_mysql.h 2011-12-26 10:35:27 +0000
1461@@ -1,20 +1,20 @@
1462 /***********************************************************************
1463-frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1464-
1465-Copyright (C) 2001 (Regis Barbier)
1466-Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1467-les termes de la Licence Publique Générale GNU publiée par la Free Software
1468-Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1469-
1470-Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1471-GARANTIE, ni explicite ni implicite, y compris les garanties de
1472-commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1473-Licence Publique Générale GNU pour plus de détails.
1474-
1475-Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1476-temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1477-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1478-*************************************************************************/
1479+ frogd, daemon pour l'utilisation des capteurs meteo de http://www.froggyhome.com
1480+
1481+ Copyright (C) 2001 (Regis Barbier)
1482+ Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon
1483+ les termes de la Licence Publique Générale GNU publiée par la Free Software
1484+ Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
1485+
1486+ Ce programme est distribué car potentiellement utile, mais SANS AUCUNE
1487+ GARANTIE, ni explicite ni implicite, y compris les garanties de
1488+ commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la
1489+ Licence Publique Générale GNU pour plus de détails.
1490+
1491+ Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même
1492+ temps que ce programme. Si ce n'est pas le cas, écrivez à la Free Software
1493+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
1494+ *************************************************************************/
1495
1496 #ifndef FROG_MYSQL_H
1497 #define FROG_MYSQL_H
1498@@ -23,17 +23,17 @@
1499 #include "mysql.h"
1500
1501 //---------------------------------------------------------------
1502-// Connect to the mysql Host
1503+// Connect to the mysql Host
1504 //---------------------------------------------------------------
1505 int ConnectDBFrog(Frog* frog);
1506
1507 //---------------------------------------------------------------
1508-// Insert the frog values into the DB
1509+// Insert the frog values into the DB
1510 //---------------------------------------------------------------
1511 int InsertDBFrog(Frog* frog);
1512
1513 //---------------------------------------------------------------
1514-// Close the frog database
1515+// Close the frog database
1516 //---------------------------------------------------------------
1517 int CloseDBFrog();
1518

Subscribers

People subscribed via source and target branches

to all changes: