kopia lustrzana https://github.com/projecthorus/radiosonde_auto_rx
				
				
				
			Merge pull request #133 from darksidelemm/testing
Update to latest dft_detect, fix log file and systemd restart issues.pull/134/head
						commit
						7644f68a63
					
				| 
						 | 
					@ -392,6 +392,7 @@ def main():
 | 
				
			||||||
    parser.add_argument("-t", "--timeout", type=int, default=0, help="Close auto_rx system after N minutes. Use 0 to run continuously.")
 | 
					    parser.add_argument("-t", "--timeout", type=int, default=0, help="Close auto_rx system after N minutes. Use 0 to run continuously.")
 | 
				
			||||||
    parser.add_argument("-v", "--verbose", help="Enable debug output.", action="store_true")
 | 
					    parser.add_argument("-v", "--verbose", help="Enable debug output.", action="store_true")
 | 
				
			||||||
    parser.add_argument("-e", "--ephemeris", type=str, default="None", help="Use a manually obtained ephemeris file when decoding RS92 Sondes.")
 | 
					    parser.add_argument("-e", "--ephemeris", type=str, default="None", help="Use a manually obtained ephemeris file when decoding RS92 Sondes.")
 | 
				
			||||||
 | 
					    parser.add_argument("--systemlog", action='store_true', default=False, help="Write a auto_rx system log-file to ./log/ (default=False)")
 | 
				
			||||||
    args = parser.parse_args()
 | 
					    args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Copy out timeout value, and convert to seconds,
 | 
					    # Copy out timeout value, and convert to seconds,
 | 
				
			||||||
| 
						 | 
					@ -418,17 +419,28 @@ def main():
 | 
				
			||||||
    # Configure logging
 | 
					    # Configure logging
 | 
				
			||||||
    _log_suffix = datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S_system.log")
 | 
					    _log_suffix = datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S_system.log")
 | 
				
			||||||
    _log_path = os.path.join(logging_path, _log_suffix)
 | 
					    _log_path = os.path.join(logging_path, _log_suffix)
 | 
				
			||||||
    logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', filename=_log_path, level=logging_level)
 | 
					 | 
				
			||||||
    stdout_format = logging.Formatter('%(asctime)s %(levelname)s:%(message)s')
 | 
					 | 
				
			||||||
    stdout_handler = logging.StreamHandler(sys.stdout)
 | 
					 | 
				
			||||||
    stdout_handler.setFormatter(stdout_format)
 | 
					 | 
				
			||||||
    logging.getLogger().addHandler(stdout_handler)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if args.systemlog:
 | 
				
			||||||
 | 
					        # Only write out a logs to a system log file if we have been asked to.
 | 
				
			||||||
 | 
					        # Systemd will capture and logrotate our logs anyway, so writing to our own log file is less useful.
 | 
				
			||||||
 | 
					        logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', filename=_log_path, level=logging_level)
 | 
				
			||||||
 | 
					        logging.info("Opened new system log file: %s" % _log_path)
 | 
				
			||||||
 | 
					        # Also add a separate stdout logger.
 | 
				
			||||||
 | 
					        stdout_format = logging.Formatter('%(asctime)s %(levelname)s:%(message)s')
 | 
				
			||||||
 | 
					        stdout_handler = logging.StreamHandler(sys.stdout)
 | 
				
			||||||
 | 
					        stdout_handler.setFormatter(stdout_format)
 | 
				
			||||||
 | 
					        logging.getLogger().addHandler(stdout_handler)
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        # Otherwise, we only need the stdout logger, which if we don't specify a filename to logging.basicConfig,
 | 
				
			||||||
 | 
					        # is the default...
 | 
				
			||||||
 | 
					        logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', level=logging_level)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Add the web interface logging handler.
 | 
				
			||||||
    web_handler = WebHandler()
 | 
					    web_handler = WebHandler()
 | 
				
			||||||
    logging.getLogger().addHandler(web_handler)
 | 
					    logging.getLogger().addHandler(web_handler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Set the requests/socketio logger to only display critical log messages.
 | 
					    # Set the requests/socketio loggers (and related) to only display critical log messages.
 | 
				
			||||||
    logging.getLogger("requests").setLevel(logging.CRITICAL)
 | 
					    logging.getLogger("requests").setLevel(logging.CRITICAL)
 | 
				
			||||||
    logging.getLogger("urllib3").setLevel(logging.CRITICAL)
 | 
					    logging.getLogger("urllib3").setLevel(logging.CRITICAL)
 | 
				
			||||||
    logging.getLogger('werkzeug').setLevel(logging.ERROR)
 | 
					    logging.getLogger('werkzeug').setLevel(logging.ERROR)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ After=syslog.target
 | 
				
			||||||
[Service]
 | 
					[Service]
 | 
				
			||||||
ExecStart=/usr/bin/python /home/pi/radiosonde_auto_rx/auto_rx/auto_rx.py -t 0
 | 
					ExecStart=/usr/bin/python /home/pi/radiosonde_auto_rx/auto_rx/auto_rx.py -t 0
 | 
				
			||||||
Restart=always
 | 
					Restart=always
 | 
				
			||||||
RestartSec=3
 | 
					RestartSec=120
 | 
				
			||||||
WorkingDirectory=/home/pi/radiosonde_auto_rx/auto_rx/
 | 
					WorkingDirectory=/home/pi/radiosonde_auto_rx/auto_rx/
 | 
				
			||||||
User=pi
 | 
					User=pi
 | 
				
			||||||
SyslogIdentifier=auto_rx
 | 
					SyslogIdentifier=auto_rx
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,7 @@ static int option_verbose = 0,  // ausfuehrliche Anzeige
 | 
				
			||||||
           option_inv = 0,      // invertiert Signal
 | 
					           option_inv = 0,      // invertiert Signal
 | 
				
			||||||
           //option_dc = 0,
 | 
					           //option_dc = 0,
 | 
				
			||||||
           option_silent = 0,
 | 
					           option_silent = 0,
 | 
				
			||||||
 | 
					           option_cont = 0,
 | 
				
			||||||
           wavloaded = 0;
 | 
					           wavloaded = 0;
 | 
				
			||||||
static int wav_channel = 0;     // audio channel: left
 | 
					static int wav_channel = 0;     // audio channel: left
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -231,7 +232,7 @@ static float get_bufmu(int ofs) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int getCorrDFT(int abs, int K, unsigned int pos, float *maxv, unsigned int *maxvpos, rsheader_t *rshd) {
 | 
					static int getCorrDFT(int K, unsigned int pos, float *maxv, unsigned int *maxvpos, rsheader_t *rshd) {
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    int mp = -1;
 | 
					    int mp = -1;
 | 
				
			||||||
    float mx = 0.0;
 | 
					    float mx = 0.0;
 | 
				
			||||||
| 
						 | 
					@ -274,9 +275,6 @@ static int getCorrDFT(int abs, int K, unsigned int pos, float *maxv, unsigned in
 | 
				
			||||||
            mp = i;
 | 
					            mp = i;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (abs == 0) {
 | 
					 | 
				
			||||||
        // mx = 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (mp == rshd->L-1 || mp == K+rshd->L-1) return -4; // Randwert
 | 
					    if (mp == rshd->L-1 || mp == K+rshd->L-1) return -4; // Randwert
 | 
				
			||||||
    //  mp == t            mp == K+t
 | 
					    //  mp == t            mp == K+t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -703,6 +701,9 @@ int main(int argc, char **argv) {
 | 
				
			||||||
        else if ( (strcmp(*argv, "-s") == 0) || (strcmp(*argv, "--silent") == 0) ) {
 | 
					        else if ( (strcmp(*argv, "-s") == 0) || (strcmp(*argv, "--silent") == 0) ) {
 | 
				
			||||||
            option_silent = 1;
 | 
					            option_silent = 1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        else if ( (strcmp(*argv, "-c") == 0) || (strcmp(*argv, "--cnt") == 0) ) {
 | 
				
			||||||
 | 
					            option_cont = 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        else if ( (strcmp(*argv, "-t") == 0) || (strcmp(*argv, "--time") == 0) ) {
 | 
					        else if ( (strcmp(*argv, "-t") == 0) || (strcmp(*argv, "--time") == 0) ) {
 | 
				
			||||||
            ++argv;
 | 
					            ++argv;
 | 
				
			||||||
            if (*argv) tl = atof(*argv);
 | 
					            if (*argv) tl = atof(*argv);
 | 
				
			||||||
| 
						 | 
					@ -749,6 +750,8 @@ int main(int argc, char **argv) {
 | 
				
			||||||
        mv_pos[j] = 0;
 | 
					        mv_pos[j] = 0;
 | 
				
			||||||
        mp[j] = 0;
 | 
					        mp[j] = 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    j_max = 0;
 | 
				
			||||||
 | 
					    mv_max = 0.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    k = 0;
 | 
					    k = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -764,7 +767,7 @@ int main(int argc, char **argv) {
 | 
				
			||||||
                if ( strncmp(rs_hdr[j].type, "C34C50", 6) == 0 ) continue;
 | 
					                if ( strncmp(rs_hdr[j].type, "C34C50", 6) == 0 ) continue;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
                mv0_pos[j] = mv_pos[j];
 | 
					                mv0_pos[j] = mv_pos[j];
 | 
				
			||||||
                mp[j] = getCorrDFT(-1, K, 0, mv+j, mv_pos+j, rs_hdr+j);
 | 
					                mp[j] = getCorrDFT(K, 0, mv+j, mv_pos+j, rs_hdr+j);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            k = 0;
 | 
					            k = 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -847,7 +850,7 @@ int main(int argc, char **argv) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                    if (k >= K-4) {
 | 
					                                    if (k >= K-4) {
 | 
				
			||||||
                                        mv0_pos[j] = mv_pos[j];
 | 
					                                        mv0_pos[j] = mv_pos[j];
 | 
				
			||||||
                                        mp[j] = getCorrDFT(-1, K, 0, mv+j, mv_pos+j, rs_hdr+j);
 | 
					                                        mp[j] = getCorrDFT(K, 0, mv+j, mv_pos+j, rs_hdr+j);
 | 
				
			||||||
                                        k = 0;
 | 
					                                        k = 0;
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
                                    else {
 | 
					                                    else {
 | 
				
			||||||
| 
						 | 
					@ -873,14 +876,19 @@ int main(int argc, char **argv) {
 | 
				
			||||||
                                if (option_verbose) fprintf(stdout, "sample: %d\n", mv_pos[j]);
 | 
					                                if (option_verbose) fprintf(stdout, "sample: %d\n", mv_pos[j]);
 | 
				
			||||||
                                fprintf(stdout, "%s: %.4f\n", rs_hdr[j].type, mv[j]);
 | 
					                                fprintf(stdout, "%s: %.4f\n", rs_hdr[j].type, mv[j]);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            if ((j < 3) && mv[j] < 0) header_found = -1;
 | 
					                            // if ((j < 3) && mv[j] < 0) header_found = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            if ( fabs(mv_max) < fabs(mv[j]) ) { // j-weights?
 | 
				
			||||||
 | 
					                                mv_max = mv[j];
 | 
				
			||||||
 | 
					                                j_max = j;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (header_found) break;
 | 
					        if (header_found && !option_cont) break;
 | 
				
			||||||
        header_found = 0;
 | 
					        header_found = 0;
 | 
				
			||||||
        for (j = 0; j < Nrs; j++) mv[j] = 0.0;
 | 
					        for (j = 0; j < Nrs; j++) mv[j] = 0.0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -891,18 +899,12 @@ ende:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // return only best result
 | 
					    // return only best result
 | 
				
			||||||
    // latest: j
 | 
					    // latest: j
 | 
				
			||||||
    k = j;
 | 
					    if (mv_max) {
 | 
				
			||||||
    j_max = 0;
 | 
					        if (mv_max < 0 && j_max < 3) header_found = -1;
 | 
				
			||||||
    mv_max = 0.0;
 | 
					        else header_found = 1;
 | 
				
			||||||
    for (j = 0; j < Nrs; j++) {
 | 
					 | 
				
			||||||
        if ( fabs(mv_max) < fabs(mv[j]) ) {
 | 
					 | 
				
			||||||
            mv_max = mv[j];
 | 
					 | 
				
			||||||
            j_max = j;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    else header_found = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // rs_hdr[k].tn
 | 
					 | 
				
			||||||
    return (header_found * rs_hdr[j_max].tn);
 | 
					    return (header_found * rs_hdr[j_max].tn);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Ładowanie…
	
		Reference in New Issue