Exemplo n.º 1
0
void main(void) {
    unsigned char cal_length, cal_dia;
    unsigned int length, dia, dia_offset, latest_l, latest_d;
    unsigned int tot_acc, mass_acc, timb_acc;
    unsigned int tot_num, mass_num, timb_num;
    unsigned int count1, count2, count3;
    OSCCON = 255;
    OSCTUNEbits.PLLEN = 1;

    TRISA = 0b00011111;
    PORTA = 0;
    ADCON1 = 0b00001101;
    TRISB = 0;
    PORTB = 0;
    TRISC = 0b00010000;
    PORTC = 0b00000000;
    TRISD = 0;
    PORTD = 0;
    TRISE = 0;
    PORTE = 0;

    init_display();
    init_counters();

    LED1 = 0;
    LED2 = 0;
    LED3 = 0;

    latest_l = 0;
    latest_d = 0;
    tot_acc = 0;
    tot_num = 0;
    timb_acc = 0;
    timb_num = 0;
    mass_acc = 0;
    mass_num = 0;

    cal_length = read_ad(0);
    cal_dia = read_ad(1);

    dia_offset = 2;
    
    while (1) {
        length = read_length(cal_length);
        dia = dia_offset + read_diameter(cal_dia);

        write_length(length);
        write_dia(dia);

        if (!CALIBRATE) {
            count1 = read_counter(1);
            count2 = read_counter(2);
            count3 = read_counter(3);
            cal_length = read_ad(0);
            cal_dia = read_ad(1);
            write_debug_info(cal_length, cal_dia, count1, count2, count3);
        }

        if (!RESET_DIA) {
            reset_dia();
        }
        
        if (!RESET_LENGTH) {
            delay(20000);
            delay(20000);
            if (!RESET_LENGTH) {
                LED1 = 1;
                if (length >= 100) {
                    tot_num = tot_num + 1;
                    tot_acc = tot_acc + length / 100;
                    latest_l = length;
                    latest_d = dia;
                    if (dia >= 15) {
                        timb_num = timb_num + 1;
                        timb_acc = timb_acc + length / 100;
                    } else {
                        mass_num = mass_num + 1;
                        mass_acc = mass_acc + length / 100;
                    }
                }
                reset_length();
                while (!RESET_LENGTH) {
                    write_length(0);
                    write_dia(0);
                    write_length(8);
                    write_dia(8);
                }
                write_stats(latest_l, latest_d, tot_num, tot_acc, timb_num, timb_acc, mass_num, mass_acc);
                LED1 = 0;
            }
        }
    }
}
Exemplo n.º 2
0
// safe test results to a log file if enabled
void
Responder::write_log_file()
{
    try
    {
        if(_opt.log_file){
            std::map<std::string, std::string> hw_info = get_hw_info();
            ofstream logs(_stats_log_filename.c_str());

            logs << boost::format("title=%s") % _opt.test_title << endl;
            logs << boost::format("device=%s") %  _usrp->get_mboard_name() << endl;
            logs << boost::format("device_args=%s") % _opt.device_args << endl;
            logs << boost::format("type=%s") %  hw_info["type"] << endl;
            if (hw_info.size() > 0)
            {
                logs << boost::format("usrp_addr=%s") %  hw_info["usrp_addr"] << endl;
                logs << boost::format("usrp_name=%s") %  hw_info["name"] << endl;
                logs << boost::format("serial=%s") %  hw_info["serial"] << endl;
                logs << boost::format("host_interface=%s") %  hw_info["interface"] << endl;
                logs << boost::format("host_addr=%s") %  hw_info["host_addr"] << endl;
                logs << boost::format("host_mac=%s") %  hw_info["mac"] << endl;
                logs << boost::format("host_vendor=%s (id=%s)") %  hw_info["vendor"] % hw_info["vendor_id"] << endl;
                logs << boost::format("host_device=%s (id=%s)") %  hw_info["device"] % hw_info["device_id"] << endl;
            }
            logs << boost::format("sample_rate=%f") % _opt.sample_rate << endl;
            logs << boost::format("samps_per_buff=%i") % _opt.samps_per_buff << endl;
            logs << boost::format("samps_per_packet=%i") % _samps_per_packet << endl;
            logs << boost::format("delay_min=%f") % _opt.delay_min << endl;
            logs << boost::format("delay_max=%f") % _opt.delay_max << endl;
            logs << boost::format("delay_step=%f") % _delay_step << endl;
            logs << boost::format("delay=%f") % _delay << endl;
            logs << boost::format("init_delay=%f") % _opt.init_delay << endl;
            logs << boost::format("response_duration=%f") % _opt.response_duration << endl;
            logs << boost::format("response_length=%ld") % _response_length << endl;
            logs << boost::format("timeout=%f") % _opt.timeout << endl;
            logs << boost::format("timeout_burst_count=%ld") % _timeout_burst_count << endl;
            logs << boost::format("timeout_eob_count=%f") % _timeout_eob_count << endl;
            logs << boost::format("allow_late_bursts=%s") % (_allow_late_bursts ? "yes" : "no") << endl;
            logs << boost::format("skip_eob=%s") % (_opt.skip_eob ? "yes" : "no") << endl;
            logs << boost::format("combine_eob=%s") % (_opt.combine_eob ? "yes" : "no") << endl;
            logs << boost::format("skip_send=%s") % (_opt.skip_send ? "yes" : "no") << endl;
            logs << boost::format("no_delay=%s") % (_no_delay ? "yes" : "no") << endl;
            logs << boost::format("simulate_frequency=%f") % _simulate_frequency << endl;
            logs << boost::format("simulate_duration=%ld") % _simulate_duration << endl;
            logs << boost::format("original_simulate_duration=%ld") % _original_simulate_duration << endl;
            logs << boost::format("realtime=%s") % (_opt.realtime ? "yes" : "no") << endl;
            logs << boost::format("rt_priority=%f") % _opt.rt_priority << endl;
            logs << boost::format("test_iterations=%ld") % _opt.test_iterations << endl;
            logs << boost::format("end_test_after_success_count=%i") % _opt.end_test_after_success_count << endl;
            logs << boost::format("skip_iterations=%i") % _opt.skip_iterations << endl;
            logs << boost::format("overruns=%i") % _overruns << endl;
            logs << boost::format("num_total_samps=%ld") % _num_total_samps << endl;
            logs << boost::format("return_code=%i\t(%s)") % _return_code % enum2str(_return_code) << endl;
            logs << endl;

            write_debug_info(logs);

            if(uhd_error_msgs.length() > 0)
            {
                logs << endl << "%% UHD ERROR MESSAGES %%" << endl;
                logs << uhd_error_msgs;
            }
        }
    }
    catch(...)
    {
        cerr << "Failed to write log file to: " << _stats_log_filename << endl;
    }
}