/*------------------------------- ----------------------------*/ void system_battery_detect() { static uint32_t detect_count = 0; uint8_t battery_level; // check every 2 minutes if(detect_count == 1) { battery_detect_start(); } if(battery_is_available() == true) { battery_level = get_battery_value(); battery_detect_stop(); set_battery_level(battery_level); xprintf(" level = %d \r\n", battery_level); if(get_battery_level() < 20) system_low_battery(); } if(detect_count > 1500000*120) { xprintf(" time on..\r\n"); detect_count = 0; } detect_count++; }
char* print_batt_cap() { char* full_cap_s = (char*)malloc(30); char full_cap_a[30]; int cap_i = get_battery_level(); // Get a usable time struct tm *current; time_t now; now = time(0); current = localtime(&now); sprintf(full_cap_a, "Battery Level: %i%% @ %02D:%02D", cap_i, current->tm_hour, current->tm_min); strcpy(full_cap_s, full_cap_a); return full_cap_s; }
static void try_to_change_state(dsme_state_t new_state) { dsme_log(LOG_INFO, PFIX"state change request: %s -> %s", state_name(current_state), state_name(new_state)); switch (new_state) { case DSME_STATE_SHUTDOWN: /* Runlevel 0 */ /* FALL THROUGH */ case DSME_STATE_REBOOT: /* Runlevel 6 */ change_state(new_state); start_delayed_shutdown_timer(SHUTDOWN_TIMER_TIMEOUT); break; case DSME_STATE_USER: /* Runlevel 5 */ /* FALL THROUGH */ case DSME_STATE_ACTDEAD: /* Runlevel 4 */ if (current_state == DSME_STATE_NOT_SET) { /* we have just booted up; simply change the state */ change_state(new_state); } else if (current_state == DSME_STATE_ACTDEAD) { /* We are in actdead and user state is wanted * We don't allow that to happen if battery level is too low */ if (get_battery_level() < DSME_MINIMUM_BATTERY_TO_USER ) { dsme_log(LOG_WARNING, PFIX"Battery level %d%% too low for %s state", get_battery_level(), state_name(new_state)); #ifdef DSME_VIBRA_FEEDBACK /* Indicate by vibra that boot is not possible */ dsme_play_vibra(low_battery_event_name); #endif /* We need to return initial ACT_DEAD shutdown_reqest * as it got cleared when USER state transfer was requested */ shutdown_requested = true; break; } /* Battery ok, lets do it */ user_switch_done = false; #ifndef DSME_SUPPORT_DIRECT_USER_ACTDEAD /* We don't support direct transfer from ACTDEAD to USER * but do it via reboot. */ dsme_log(LOG_DEBUG, PFIX"USER state requested, we do it via REBOOT"); change_state(DSME_STATE_REBOOT); start_delayed_shutdown_timer(SHUTDOWN_TIMER_TIMEOUT); #else if (actdead_switch_done) { /* actdead init done; runlevel change from actdead to user state */ if (start_delayed_user_timer(USER_TIMER_MIN_TIMEOUT)) { change_state(new_state); } } else { /* actdead init not done; wait longer to change from actdead to user state */ if (start_delayed_user_timer(USER_TIMER_MAX_TIMEOUT)) { change_state(new_state); } } #endif /* DSME_SUPPORT_DIRECT_USER_ACTDEAD */ } else if (current_state == DSME_STATE_USER) { actdead_switch_done = false; #ifndef DSME_SUPPORT_DIRECT_USER_ACTDEAD /* We don't support direct transfer from USER to ACTDEAD * but do it via shutdown. Usb cable will wakeup the device again * and then we will boot to ACTDEAD * Force SHUTDOWN */ if( need_to_use_reboot(new_state) ) { dsme_log(LOG_DEBUG, PFIX"ACTDEAD state requested, " "we do it via REBOOT"); change_state(DSME_STATE_REBOOT); } else { dsme_log(LOG_DEBUG, PFIX"ACTDEAD state requested, " "we do it via SHUTDOWN"); change_state(DSME_STATE_SHUTDOWN); } start_delayed_shutdown_timer(SHUTDOWN_TIMER_TIMEOUT); #else if (user_switch_done) { /* user init done; runlevel change from user to actdead state */ if (start_delayed_actdead_timer(ACTDEAD_TIMER_MIN_TIMEOUT)) { change_state(new_state); } } else { /* user init not done; wait longer to change from user to actdead state */ if (start_delayed_actdead_timer(ACTDEAD_TIMER_MAX_TIMEOUT)) { change_state(new_state); } } #endif /* DSME_SUPPORT_DIRECT_USER_ACTDEAD */ } break; case DSME_STATE_TEST: /* fall through */ case DSME_STATE_LOCAL: /* NOTE: test server is running */ if (current_state == DSME_STATE_NOT_SET) { change_state(new_state); } break; default: dsme_log(LOG_WARNING, PFIX"not possible to change to state %s (%d)", state_name(new_state), new_state); break; } }
//------------------------------------------------------------------------ // char * make_msg_k1(void) //------------------------------------------------------------------------ char * make_msg_k1(void) { char tmp_buf[50]; //char t_buf[15]; // 38 byte + '\0' // 0.........1.........2.........3.........4.........5.........6.........7.........8.........9......... // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 // |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| // K0S010yymmddhhmmLat---Longi----1234123Sensor--ws-wd-at--ap---hu-2at-2ap--sc--st--dcs-dc- // #H11,150310160005,-84,11.9,0000.0000,00000.0000,,,1.348E+01 debugstring( "-------------------------------\r\n"); // debugstring( " make msg K1\r\n"); // debugstring( "-------------------------------\r\n"); memset(s_msg,0,MSG_LENGTH); // Header strcpy(s_msg, "#J"); // strcat(s_msg, env.id); // strcat(s_msg, "env.id"); // date time rtc_isSecUpdate(); sprintf(tmp_buf,"11,%02d%02d%02d%02d%02d00,",rtc_time.year%100,rtc_time.mon,rtc_time.day,rtc_time.hour,rtc_time.min); strcat(s_msg, tmp_buf); // debugprintf("%s\r\n", s_msg); // CDMA RSSI sprintf(tmp_buf,"%d,",lblRSSI); strcat(s_msg, tmp_buf); // BAT sprintf(tmp_buf,"%.1f,", (float)(get_battery_level()/10.0f)); strcat(s_msg, tmp_buf); // debugprintf("%s \r\n", s_msg); // Position strcat(s_msg, "0000.0000,00000.0000,,,"); // debugprintf("%s \r\n", s_msg); if (is_dcs_valid()==1) { // sprintf(tmp_buf,"%.3f",get_dcs_speed()); // dcs.pitch == temperature sprintf(tmp_buf,"%.3E",get_dcs_speed()); // dcs.pitch == temperature strcat(s_msg, tmp_buf); // (-)150518 // strcat(s_msg, get_4050_temp()); // (+)150518 set_dcs_valid(0); init_dcs_data(); } // debugprintf("%s \r\n", s_msg); // PRINTVAR(strlen(s_msg)); sensor_status.w = DFLT_SENSOR; // sensor_status.w = 0xFFFFFFFF; // 5 5 5 5 5 5 5 5 // 0101 0101 0101 0101 0101 0101 0101 0101 // 0111 1101 0101 0101 0111 0111 0111 0101 // 7 D 5 5 7 7 7 5 // 7D557775 : DEFAULT VALUE // F7 77 55 D5 // (-)131017 --->>> if (is_q_full()) { q_pop(); } q_putData(); // <<<------ // (+)131017 ---->>> // fgMsgC_ready = 1; // { // int i; // for (i=0;i<MSG_LENGTH; i++) // { // s_msg_c[i] = s_msg[i]; // } // } // <<<------ //saveDeferredMsgFile(); debugstring(s_msg); // debugstring(s_msg_c); debugstring("\r\n"); debugprintf("q_put --> Q[%d]\r\n",is_q_dataNum()); strcat(s_msg, "\r\n"); if (sdc_read_detectPin()==SDC_INSERTED) { u32 fsz; //PRINTLINE; sdc_saveDataToFile(FN_SEND, s_msg, &fsz); //PRINTVAR(fsz); if (fsz > FSZ_MAX) { SensorBakSize.b.send = 1; } } return (s_msg); }