/* Check if a given word can end the sentence */ bool is_valid_end(char *word) { State state_info = get_state_info(current_state); int j = -1; while(state_info.transitions[++j].word != NULL) if (state_info.transitions[j].identifier == S_END) return true; return false; }
/* Check for a valid transition from one argument (i.e. word) to the next */ bool is_valid_transition(char *word) { State state_info = get_state_info(current_state); int j = -1; while(state_info.transitions[++j].word != NULL) { // Check for everything else if (strcmp(state_info.transitions[j].word, word) == 0) { current_state = state_info.transitions[j].identifier; return true; } } return false; }
void disp_signal() { InfoState infoState; const char *IMAGE_POINT[] = { IMAGE_0, IMAGE_1, IMAGE_2, IMAGE_3, IMAGE_4, IMAGE_5, IMAGE_6, IMAGE_7, IMAGE_8, IMAGE_9 }; uint8 signal; if(!get_state_info(&infoState)){ post_trace("get state false"); }else{post_trace("get state ok");} signal = get_signal(&infoState); power_screen(true); show_picture(7, 10, IMAGE_POINT[(signal/ 10) % 10]); show_picture(33, 10, IMAGE_POINT[signal % 10]); }
bool process_sentence(int sentence_number) { /* Process each word in sentence */ current_position = sentences[sentence_number][0]; // start State state_info; while (current_position <= sentences[sentence_number][1]) { state_info = get_state_info(current_state); if (state_info.process_state != NULL && !state_info.process_state(sentences[sentence_number][1])) return false; if (current_state != S_END && !is_valid_transition(words[current_position])) return false; current_position++; } // Set position to end current_position = sentences[sentence_number][1]; if (current_state != S_END && is_valid_end(words[current_position])) { state_info = get_state_info(current_state); if (!prepend_to_definition(" ")) return false; if (!prepend_to_definition(state_info.print_name)) return false; current_state = S_END; } if (current_state != S_END) return false; current_state = S_START; return true; }
/* Process basic data type */ bool process_basic(int sentence_end) { if (is_valid_variable(words[current_position])) { State state_info = get_state_info(current_state); if (!append_to_definition(state_info.print_name)) return false; if (!append_to_definition(" ")) return false; if (!append_to_definition(words[current_position])) return false; if (current_position == sentence_end) current_state = S_END; if ((current_position+1) < sentence_end) current_position++; } return true; }
void component_key_alarm() { const uint8 DATA_SIZE = sizeof(HMC5883L_data) + sizeof(RTC_Clock) + sizeof(MMA8451_data); char szTrace[piece_size]; HMC5883L_data data_5883; RTC_Clock clock; Sensor data_8451; uint8 nIndex = 0; uint32 nVotage = 0; LED_Light(led_blue, true); sprintf(szTrace, "key = alarm, led = blue"); post_trace(szTrace); for(nIndex = 0; nIndex < 60; ++nIndex) { HMC5883L_ReadXYZ(&data_5883); sprintf(szTrace, "hmc5883 x = %d, y = %d, z = %d", data_5883.x, data_5883.y, data_5883.z); post_trace(szTrace); clock = GetTime(); sprintf(szTrace, "sd2058: 20%02d:%02d:%02d %02d:%02d:%02d", clock.year, clock.month, clock.day, clock.hour, clock.minute, clock.second); post_trace(szTrace); if((MMA845x_readbyte(MMA845x_STATUS_00) & 0x08) != 0) { //三个轴数据更新 MMA845x_readData(&data_8451); if(data_8451.x == -1 && data_8451.y == -1 && data_8451.z == -1) { post_trace("MMA8451: read error data"); } else { sprintf(szTrace, "MMA8451: x = %d, y = %d, z = %d", data_8451.x, data_8451.y, data_8451.z); post_trace(szTrace); } } else { post_trace("MMA8451: read error"); } nVotage = ADC_Read(); sprintf(szTrace, "votage = %d", nVotage); post_trace(szTrace); } memcpy(szTrace, &data_5883, sizeof(HMC5883L_data)); memcpy(szTrace + sizeof(HMC5883L_data), &clock, sizeof(RTC_Clock)); memcpy(szTrace + sizeof(HMC5883L_data) + sizeof(RTC_Clock), &data_8451, sizeof(MMA8451_data)); write_file("temp", szTrace, DATA_SIZE); post_trace("save sensor data in file named \"temp\" in tf card"); { InfoBase base_info = { 0 }; InfoState state_info = { 0 }; if(get_base_info(&base_info)) { sprintf(szTrace, "base info, sid = %s, imei = %s", base_info.sid, base_info.imei); post_trace(szTrace); } if(get_state_info(&state_info)) { sprintf(szTrace, "state info, charging: %s, quantity: %d, sim card: %s, signal: %d, lac: %s, cell: %s, lng: %s, lat: %s", (is_charging(&state_info) ? "yes" : "no"), get_quantity(&state_info), (is_sim_card_exist(&state_info) ? (is_sim_card_valid(&state_info) ? "normal" : "error") : "lost"), get_signal(&state_info), state_info.lac, state_info.cell, state_info.lng, state_info.lat); post_trace(szTrace); } } post_trace("alarm completed"); LED_Light(led_blue, false); }