Ejemplo n.º 1
0
void gps_tweaks_shutdown_hook()
{
    if (gps_powersave_tweak)
    {
        /* GPS internal? we should restore at next boot */
        /* any other value? do not restore */
        config_flag_file_setting_save(get_gps_flag_file(), gps_state == GPS_INTERNAL);

        /* internal GPS enabled? turn it off to save battery power */
        if (gps_state == GPS_INTERNAL)
        {
            gps_disable();
        }
    }
}
Ejemplo n.º 2
0
static void schedule(enum sys_message msg)
{

    // battery related
    if (rtca_time.sys > adc_check_next) {
        adc_read();

        adc_check_next = rtca_time.sys + adc_check_interval;

        if ((stat.v_raw > 400) && (stat.v_raw < 550)) {
            if (CHARGING_STOPPED) {
                if (stat.should_charge) {
                    CHARGE_DISABLE;
                    stat.should_charge = false;
                    adc_check_next = rtca_time.sys + 300;
                } else {
                    if (stat.v_bat < 390) {
                        CHARGE_ENABLE;
                        stat.should_charge = true;
                        charge_start = rtca_time.sys;
                    }
                }
            } else {
                if (rtca_time.sys > charge_start + 36000) {
                    CHARGE_DISABLE;
                    stat.should_charge = false;
                    adc_check_next = rtca_time.sys + 3600;
                }
            }
        } else {
            CHARGE_DISABLE;
            stat.should_charge = false;
        }
    }

    // GPS related
    if (rtca_time.sys > gps_trigger_next) {

        switch (gps_next_state) {
            case MAIN_GPS_IDLE:
                if (s.gps_loop_interval > s.gps_warmup_interval + 30) {
                    // when gps has OFF intervals
                    gps_disable();
                    gps_trigger_next = rtca_time.sys + s.gps_loop_interval - s.gps_warmup_interval - 2;
                }
                gps_next_state = MAIN_GPS_START;
            break;
    
            case MAIN_GPS_START:
                gps_next_state = MAIN_GPS_INIT;
                gps_enable();
            break;

            case MAIN_GPS_INIT:
                if (s.gps_loop_interval > s.gps_warmup_interval + 30) {
                    // gps had a power off interval
                    gps_trigger_next = rtca_time.sys + s.gps_warmup_interval - s.gps_invalidate_interval - 3;
                    uart0_tx_str((char *)gps_init, 51);
                } else {
                    // gps was on all the time
                    gps_trigger_next = rtca_time.sys + s.gps_loop_interval - s.gps_invalidate_interval - 3;
                    if (rtca_time.sys > gps_reinit_next) {
                        gps_reinit_next = rtca_time.sys + gps_reinit_interval;
                        uart0_tx_str((char *)gps_init, 51);
                    }
                }
                gps_next_state = MAIN_GPS_PDOP_RST;
                // zero out all the old data
                memset(&mc_f, 0, sizeof(mc_f));
            break;
    
            case MAIN_GPS_PDOP_RST:
                gps_trigger_next = rtca_time.sys + s.gps_invalidate_interval - 1;
                gps_next_state = MAIN_GPS_STORE;
                mc_f.pdop = 9999;
            break;
    
            case MAIN_GPS_STORE:
                if (mc_f.fix) {
                    // save all info to f-ram
                    store_pkt();
                }
                gps_next_state = MAIN_GPS_IDLE;
            break;
        }
    }

    // GPRS related
    // force the HTTP POST from time to time
    if (rtca_time.sys > gprs_tx_next) {
        if (gprs_tx_trig & TG_NOW_MOVING) {
            gprs_tx_next = rtca_time.sys + s.gprs_moving_tx_interval;
        } else {
            gprs_tx_next = rtca_time.sys + s.gprs_static_tx_interval;
        }
        sim900.flags |= TX_FIX_RDY;
    }

    if (sim900.flags & BLACKOUT) {
       if (rtca_time.sys > gprs_blackout_lift) {
           sim900.flags &= ~BLACKOUT;
       }
    }

    if (((rtca_time.sys > gprs_trigger_next) || (sim900.flags & TX_FIX_RDY)) && 
            !(sim900.flags & TASK_IN_PROGRESS)) {

        // time to act
        adc_read();
        gprs_trigger_next = rtca_time.sys + s.gprs_loop_interval;

        if (stat.v_bat > 350) {
#ifndef DEBUG_GPS
            // if battery voltage is below ~3.4v
            // the sim will most likely lock up while trying to TX
            if (!(sim900.flags & BLACKOUT)) {
                sim900_exec_default_task();
            }
#endif
        }
    }
}