t_HWindow call_LoadOutgoing(gu8 sim, const char *phone, t_CSessionID sid) { t_HWindow handle = NULL; if(prod_get_sim_count() == 0){ msgbox_show(NULL, _CSK(OK), 0, 0, "No SIM inserted!"); return NULL; } if(sim == 0xff || sim >= prod_get_sim_slots()){ int i; sim = 0xff; for(i = 0; i < prod_get_sim_slots(); i++){ if(prod_sim_status(i) == SIM_CARD_NORMAL){ sim = i; break; } } if(sim == 0xff){ msgbox_show(NULL, _CSK(OK), 0, 0, "No valid SIM cards!"); return NULL; } } if(phone && phone[0]){ int cid; cid = call_setup(sim, phone); g_printf("call(%s) id=%d", phone, cid); if(cid >= 0){ handle = wnd_create_by_resid(call_WndMsgHandler, cid, sid, brd_get(PACK_GUID_SELF), RESID_WIN_CALL); call_notifier(cid, CallNotificationCB, handle); wnd_show(handle); }else{ } } return handle; }
/*************************************************************************** Declaration : int main(void) Function : Main Loop ***************************************************************************/ int main(void) { init_mcu(); init_rf(); init_buffer(); init_protocol(); init_freq(); #ifdef TEST_TX_CW test_rf_transmitter(78); #endif #ifdef TEST_TX_MOD test_rf_modulator(81); #endif #ifdef TEST_RX test_rf_receiver(78); #endif /* Main Background loop */ call_state = CALL_IDLE; while(1) { /* Call States */ switch (call_state) { case CALL_IDLE: #ifdef DONGLE sleep(WDT_TIMEOUT_60MS,STANDBY_MODE); call_status = CALL_NO_ACTIVITY; #ifdef USB SET_VOLUME_DOWN; SET_VOLUME_UP; SET_MUTE_PLAY; SET_MUTE_REC; if(CALL_ACTIVITY_PIN) call_status = CALL_ACTIVITY; #else if(!CALL_SETUP_KEY) call_status = CALL_ACTIVITY; #endif if(call_status == CALL_ACTIVITY) call_state = CALL_SETUP; #endif #ifdef HEADSET sleep(WDT_TIMEOUT_1S,POWER_DOWN_MODE); call_state = CALL_SETUP; #endif break; case CALL_SETUP: #ifdef DONGLE LED_ON; call_status = call_setup(&setup_freq[0],N_FREQ_SETUP); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { init_buffer(); init_rf(); init_protocol(); init_codec(); start_codec(); #ifdef USB // Enable watchdog to handle USB Suspend Mode wdt_enable(WDT_TIMEOUT_15MS); #else start_timer1(0,FRAME_PERIOD, DIV1); #endif call_state = CALL_CONNECTED; } else call_state = CALL_IDLE; #endif #ifdef HEADSET LED_ON; call_status = call_detect(&setup_freq[0],N_FREQ_SETUP,N_REP_SETUP); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { init_buffer(); init_rf(); init_protocol(); init_codec(); call_status &= ~MASTER_SYNC; start_timer1(0,FRAME_PERIOD, DIV1); call_state = CALL_CONNECTED; } else call_state = CALL_IDLE; #endif break; case CALL_CONNECTED: #ifdef DONGLE while(1) { // USB Dongle clears watchdog handling USB Suspend Mode #ifdef USB wdt_reset(); #endif // Send and receive audio packet audio_transfer(); // Handle key code from HEADSET key_code = (signal_in[1] & 0x1F); if(key_code != 0) LED_ON; else LED_OFF; #ifdef USB if(key_code & VOLUME_DOWN) CLEAR_VOLUME_DOWN; else SET_VOLUME_DOWN; if(key_code & VOLUME_UP) CLEAR_VOLUME_UP; else SET_VOLUME_UP; if(key_code & MUTE_PLAY) CLEAR_MUTE_PLAY; else SET_MUTE_PLAY; if(key_code & MUTE_REC) CLEAR_MUTE_REC; else SET_MUTE_REC; #endif // Check if call is to be cleared #ifdef USB if(!CALL_ACTIVITY_PIN) { call_activity_timer += 1; if(call_activity_timer >= TIMEOUT_CALL_ACTIVITY) call_status = CALL_CLEAR; } else call_activity_timer = 0; #else if(!CALL_CLEAR_KEY) call_status = CALL_CLEAR; #endif // Call clearing by HEADSET or DONGLE if((key_code == CALL_CLEARING) || (call_status == CALL_CLEAR)) { signal_out[0] |= SIGNAL_CALL_CLEAR; call_timer += 1; if(call_timer >= TIMEOUT_CALL_CLEAR_MASTER) { call_state = CALL_IDLE; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); eeprom_write(freq[0],EEPROM_ADR_FREQ0); eeprom_write(freq[1],EEPROM_ADR_FREQ1); LED_OFF; #ifdef USB // Disable watchdog used to handle USB Suspend Mode wdt_disable(); #endif break; } } else signal_out[0] &= ~SIGNAL_CALL_CLEAR; // Call clearing due to Frame Loss if(frame_loss >= TIMEOUT_FRAME_LOSS) { #ifdef USB call_state = CALL_RECONNECT; init_rf(); init_protocol(); // Disable watchdog used to handle USB Suspend Mode wdt_disable(); #else call_state = CALL_RECONNECT; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); #endif break; } } #endif #ifdef HEADSET while(1) { if(call_status & MASTER_SYNC) { audio_transfer(); } else { call_status = get_sync(); if(call_status & MASTER_SYNC) start_codec(); else frame_loss += 10; } // Read and handle keys key_code = read_key(); signal_out[1] &= 0xE0; signal_out[1] |= key_code; // Call cleared by DONGLE if(signal_in[0] & SIGNAL_CALL_CLEAR) { call_timer += 1; if(call_timer >= TIMEOUT_CALL_CLEAR_SLAVE) { call_state = CALL_IDLE; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); break; } } else call_timer = 0; // Call clearing due to Frame Loss if(frame_loss >= TIMEOUT_FRAME_LOSS) { call_state = CALL_RECONNECT; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); break; } } #endif break; case CALL_RECONNECT: #ifdef DONGLE LED_ON; call_status = call_setup(&setup_freq[0],N_FREQ_SETUP); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { #ifdef USB init_rf(); init_protocol(); reset_codec(); call_state = CALL_CONNECTED; #else init_buffer(); init_rf(); init_protocol(); init_codec(); start_codec(); start_timer1(0,FRAME_PERIOD, DIV1); call_state = CALL_CONNECTED; #endif } else { stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); call_state = CALL_IDLE; } #endif #ifdef HEADSET LED_ON; call_status = call_detect(&setup_freq[0],N_FREQ_SETUP,N_REP_RECONNECT); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { init_buffer(); init_rf(); init_protocol(); init_codec(); call_status &= ~MASTER_SYNC; start_timer1(0,FRAME_PERIOD, DIV1); call_state = CALL_CONNECTED; } else call_state = CALL_IDLE; #endif break; default: break; } } }