|
|
#include "kernelModuleModemManager.h"
#include "../../components/base/basicFunctionality.h"
#define LOG( X ) kernelModule::m_pLog->Log( "MOD_MODEM", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\ sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ }#else
#define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, X )
#endif
kernelModuleModemManager::kernelModuleModemManager( uint32_t moduleID ): kernelModule( moduleID, KERNEL_MODULE_MODEM_MANAGER ) /*, basicThread() */{ if( checkCmdExists("mmcli") > 0 ){ LOG("ModemManager Present!"); } else { LOG_ERROR("No ModemManager installed in the System!"); };};
kernelModuleModemManager::~kernelModuleModemManager(){ //if ( m_vUserData.size() ) {
//for ( VECTOR_MDM_USER_DATA::iterator idx = m_vUserData.begin(); idx < m_vUserData.end(); idx++ ) {
// if ( !(*idx)->finished ) pthread_join( (*idx)->handler, NULL);
//};
//};
};
bool kernelModuleModemManager::reloadSettings(){ LOG("Reload"); //Reload Phonebook
return true;};
bool kernelModuleModemManager::startService(){ LOG("Start Service"); //Load PhoneBook
setWM( MDM_IDLE_WM ); return moduleActive = init();};
bool kernelModuleModemManager::stopService( bool force ){ LOG("Stop Service"); setWM( MDM_IDLE_WM ); return moduleActive = !uninit();};
void kernelModuleModemManager::m_fThreadProc( void ){ uint32_t nCurrentPhoneBookId = 0; uint32_t nCurrentCallId = 0; uint64_t lNextWindowAction = 0; m_bThreadStatus == TH_WORKING; while ( m_bThreadStatus < TH_ENDED ) { uint8_t bCWM = getWM(); switch ( bCWM ) { case MDM_IDLE_WM:{ break; }; case MDM_INIT_CALL_WM:{ if ( nCurrentPhoneBookId < m_vPhoneBook.size() ) { DBC_MODEM_PHONEBOOK_RECORD *tRECORD = m_vPhoneBook.at( nCurrentPhoneBookId ); if ( tRECORD ) { if( tRECORD->mode == 2 ){ LOG("Start Call"); nCurrentCallId = startCall( tRECORD->number ); lNextWindowAction = getMilliseconds() + m_sMMData.call_hangup_wait * 1000; // Need to wait till calling
setWM( MDM_MODEM_IS_BUSY_WM ); } else { LOG("Start SMS"); nCurrentCallId = 0; sendSMS( tRECORD->number, tRECORD->custom_msg ); //No need to wait SMS
setWM( MDM_FETCH_NEXT_WM ); }; } else { LOG_ERROR("No Phone Book Record!"); sessionStarted = false; setWM( MDM_IDLE_WM ); }; } else { LOG_ERROR("Phone Book is Empty!"); sessionStarted = false; setWM( MDM_IDLE_WM ); }; break; }; case MDM_MODEM_IS_BUSY_WM:{ if ( lNextWindowAction < getMilliseconds() ){ LOG("Hangup Call"); hangupCall( nCurrentCallId ); setWM( MDM_FETCH_NEXT_WM ); }; break; }; case MDM_FETCH_NEXT_WM:{ if ( nCurrentPhoneBookId < m_vPhoneBook.size() ) { nCurrentPhoneBookId++; setWM( MDM_INIT_CALL_WM ); } else { nCurrentPhoneBookId = 0; lNextWindowAction = getMilliseconds() + m_sMMData.time_window; setWM( MDM_WAIT_WINDOW_WM ); }; break; }; case MDM_WAIT_WINDOW_WM:{ if ( lNextWindowAction < getMilliseconds() ){ sessionStarted = false; setWM( MDM_IDLE_WM ); }; break; }; }; SLEEP(DEFAULT_THREAD_SLEEP_TIME); };};
bool kernelModuleModemManager::dispatchEvent( EVENT_CONTAINER *Evt ){ if ( moduleActive ) { if( Evt == NULL ) return false; if( Evt->m_eClass == EVT_CLASS_SYSTEM ){ if( Evt->m_eType == EVT_LRF_START_SESSION ){ //sessionStarted = true;
//setWM( MDM_INIT_CALL_WM );
}; if ( Evt->m_eType == EVT_LRF_END_SESSION_TO || Evt->m_eType == EVT_LRF_END_SESSION_MA ) { }; }; switch( Evt->m_eType ) { case EVT_TARGET_1D: case EVT_TARGET_3D_WHITE: case EVT_TARGET_3D_BLACK: case EVT_TARGET_2D_WHITE: case EVT_TARGET_2D_BLACK:{ sessionStarted = true; setWM( MDM_INIT_CALL_WM ); break; }; case EVT_LRF_END_SESSION_TO: case EVT_LRF_END_SESSION_MA:{ sessionStarted = false; break; }; }; }; return true;};
bool kernelModuleModemManager::validate(){ if ( moduleActive ) { // Get current WAN IP Address
//
//LOG("Validate");
}; return true;};
#define TLOG_ERROR( X ) DATA->parent->m_pLog->Log( "MOD_MODEM_T", DATA->parent, _LOG_ERROR, X )
void *kernelModuleModemManager::callProc( void *ptr ){ MDM_CALL_DATA *DATA = (MDM_CALL_DATA *)ptr; if ( DATA ) { char CMD[128]; uint32_t callID = 0; sprintf( CMD, "mmcli -m %d --voice-create-call='number=%s'", DATA->modem_id, DATA->target );/*
Successfully created new call: /org/freedesktop/ModemManager1/Call/2 */ FILE *fd = popen( CMD, "r"); if ( fd ) {
pclose( fd ); }; if ( callID ) { // Wait X seconds then hang call
SLEEP( DATA->parent->m_sMMData.call_hangup_wait * 1000 ); sprintf( CMD, "mmcli -m %d --close-call %d", DATA->modem_id, callID ); fd = popen( CMD, "r"); if ( fd ) {
pclose( fd ); } else { TLOG_ERROR("Cannot Execute Call Hang Command!"); }; } else TLOG_ERROR("Call is not registered at Modem!"); }; pthread_exit( NULL ); return NULL;};
void *kernelModuleModemManager::smsProc( void *ptr ){ MDM_SMS_DATA *DATA = (MDM_SMS_DATA *)ptr; if ( DATA ) {
}; pthread_exit( NULL ); return NULL;};
uint32_t kernelModuleModemManager::startCall( CSTR number ){ MDM_CALL_DATA *DATA = ( MDM_CALL_DATA *) malloc( sizeof( MDM_CALL_DATA )); if( DATA ) { memset( DATA, 0 , sizeof( MDM_CALL_DATA )); DATA->parent = this; //strncpy( DATA->target, m_sMMData.call_target, 64 );
int RetVal = pthread_create( &DATA->handler, NULL, callProc, ( void * ) DATA ); if( RetVal == -1 ) { LOG_ERROR("Cannot start Call Procedure."); free( DATA ); return 0; }; //Push Data into vector
m_vUserData.push_back( (MDM_USER_DATA*) DATA ); } else { LOG_ERROR("Cannot allocate Call data."); }; return 0;};
void kernelModuleModemManager::sendSMS( CSTR number, CSTR text ){
};
void kernelModuleModemManager::hangupCall( uint32_t call_id ){
};
#undef LOG
#undef LOG_ERROR
|