X-Git-Url: http://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=xgnokii%2Fxgnokii_lowlevel.c;fp=xgnokii%2Fxgnokii_lowlevel.c;h=78a9ba4fbb67aba7c60b8baca2e5df8bc28d32eb;hp=a606d73d94aae8c897dbb2ab04567ee1219ac0df;hb=a2dfc99dc499ea8600bf5178f8122125d7d7d557;hpb=1fdb423c0a2e33c1282bec25de66d9f40d56999b diff --git a/xgnokii/xgnokii_lowlevel.c b/xgnokii/xgnokii_lowlevel.c index a606d73..78a9ba4 100644 --- a/xgnokii/xgnokii_lowlevel.c +++ b/xgnokii/xgnokii_lowlevel.c @@ -1,12 +1,8 @@ /* - $Id$ - X G N O K I I A Linux/Unix GUI for Nokia mobile phones. - Copyright (C) 1999 Pavel Janík ml., Hugh Blemings - & Ján Derfiòák . Released under the terms of the GNU GPL, see file COPYING for more details. @@ -16,15 +12,10 @@ #include #include #include -#include "misc.h" -#include "gsm-common.h" #include "gsm-api.h" -//#include "6110.h" -//#include "fbus-3810.h" #include "xgnokii_lowlevel.h" #include "xgnokii.h" -#include "gsm-statemachine.h" -//#include "xgnokii_common.h" +#include "xgnokii_common.h" pthread_t monitor_th; PhoneMonitor phoneMonitor; @@ -54,13 +45,13 @@ pthread_cond_t getNetworkInfoCond; static pthread_mutex_t eventsMutex; static GSList *ScheduledEvents = NULL; -static GSM_Statemachine statemachine; -/* FIXME - don't really know what should own the statemachine in */ -/* the xgnokii scheme of things - Chris */ - inline void GUI_InsertEvent (PhoneEvent *event) { + while (phoneMonitor.working) { + usleep(1); + } + # ifdef XDEBUG g_print ("Inserting Event: %d\n", event->event); # endif @@ -94,27 +85,21 @@ static void InitModelInf (void) gchar buf[64]; GSM_Error error; register gint i = 0; - GSM_Data data; - GSM_DataClear(&data); - data.Model=buf; - while ((error = SM_Functions(GOP_GetModel,&data,&statemachine)) != GE_NONE && i++ < 15) + while ((error = GSM->GetModel(buf)) != GE_NONE && i++ < 15) sleep(1); if (error == GE_NONE) { g_free (phoneMonitor.phone.model); phoneMonitor.phone.version = g_strdup (buf); - phoneMonitor.phone.model = GetModel (buf); + phoneMonitor.phone.model = GetModelName (buf); if (phoneMonitor.phone.model == NULL) phoneMonitor.phone.model = g_strdup (_("unknown")); - - phoneMonitor.supported = GetPhoneModel(buf)->flags; } i = 0; - data.Revision=buf; - while ((error = SM_Functions(GOP_GetRevision,&data,&statemachine)) != GE_NONE && i++ < 5) + while ((error = GSM->GetRevision (buf)) != GE_NONE && i++ < 5) sleep(1); if (error == GE_NONE) @@ -124,8 +109,7 @@ static void InitModelInf (void) } i = 0; - data.Imei=buf; - while ((error = SM_Functions(GOP_GetImei,&data,&statemachine)) != GE_NONE && i++ < 5) + while ((error = GSM->GetIMEI (buf)) != GE_NONE && i++ < 5) sleep(1); if (error == GE_NONE) @@ -143,24 +127,23 @@ static void InitModelInf (void) #endif } - static GSM_Error fbusinit(bool enable_monitoring) { int count=0; static GSM_Error error=GE_NOLINK; - GSM_ConnectionType connection=GCT_Serial; - - if (!strcmp(xgnokiiConfig.connection, "infrared")) - connection = GCT_Infrared; - if (!strcmp(xgnokiiConfig.connection, "irda")) - connection = GCT_Irda; +#ifndef WIN32 + if (strcmp(GetMygnokiiVersion(),VERSION)!=0) + fprintf(stderr,_("WARNING: version of installed libmygnokii.so (%s) is different to version of xgnokii (%s)\n"),GetMygnokiiVersion(),VERSION); +#endif /* Initialise the code for the GSM interface. */ - if (error == GE_NOLINK) error = GSM_Initialise (xgnokiiConfig.model, xgnokiiConfig.port, - xgnokiiConfig.initlength, connection, RLP_DisplayF96Frame, &statemachine); + xgnokiiConfig.initlength, + GetConnectionTypeFromString(xgnokiiConfig.connection), + RLP_DisplayF96Frame, + xgnokiiConfig.synchronizetime); #ifdef XDEBUG g_print ("fbusinit: error %d\n", error); @@ -191,12 +174,11 @@ void GUI_InitPhoneMonitor (void) phoneMonitor.phone.version = phoneMonitor.phone.model; phoneMonitor.phone.revision = g_strdup (_("unknown")); phoneMonitor.phone.imei = g_strdup (_("unknown")); - phoneMonitor.supported = 0; phoneMonitor.rfLevel = phoneMonitor.batteryLevel = -1; phoneMonitor.powerSource = GPS_BATTERY; - phoneMonitor.working = NULL; + phoneMonitor.working = FALSE; phoneMonitor.alarm = FALSE; - phoneMonitor.sms.unRead = phoneMonitor.sms.number = 0; + phoneMonitor.sms.unRead = phoneMonitor.sms.number = phoneMonitor.sms.number2 = 0; phoneMonitor.sms.messages = NULL; phoneMonitor.call.callInProgress = CS_Idle; *phoneMonitor.call.callNum = '\0'; @@ -246,7 +228,7 @@ static inline void FreeArray (GSList **array) } -static void RefreshSMS (const gint number) +void RefreshSMS (const gint number) { GSM_Error error; GSM_SMSMessage *msg; @@ -259,36 +241,49 @@ static void RefreshSMS (const gint number) pthread_mutex_lock (&smsMutex); FreeArray (&(phoneMonitor.sms.messages)); phoneMonitor.sms.number = 0; + phoneMonitor.sms.number2 = 0; pthread_mutex_unlock (&smsMutex); - i = 0; + i = 1; while (1) { - GSM_Data gdat; - GSM_DataClear(&gdat); msg = g_malloc (sizeof (GSM_SMSMessage)); msg->MemoryType = GMT_SM; - msg->Number = ++i; - gdat.SMSMessage = msg; - - if ((error = SM_Functions(GOP_GetSMS, &gdat, &statemachine)) == GE_NONE) - { - pthread_mutex_lock (&smsMutex); - phoneMonitor.sms.messages = g_slist_append (phoneMonitor.sms.messages, msg); - phoneMonitor.sms.number++; - pthread_mutex_unlock (&smsMutex); - if (phoneMonitor.sms.number == number) - return; - } - else if (error == GE_INVALIDSMSLOCATION) /* All positions are readed */ - { - g_free (msg); - break; + msg->Location = i; +#ifdef XDEBUG + fprintf(stdout, _("test: %d %i %i %i\n"),msg->Location,phoneMonitor.sms.number,phoneMonitor.sms.number2,number); +#endif + pthread_mutex_lock (&smsMutex); + if( GetModelFeature(FN_SMS)==F_SMS71 ) msg->Location = 0; /* read next sms for 6210/7110 */ + error = GSM->GetSMSMessage (msg); + pthread_mutex_unlock (&smsMutex); + switch (error) { + case GE_NONE: + pthread_mutex_lock (&smsMutex); +#ifdef XDEBUG + fprintf(stdout, _("Refresh SMS: g_slist_append: sms message")); + fprintf(stdout, _(" Location: %d"),msg->Location); + fprintf(stdout, _(" folder: %d"),msg->folder); + if ( msg-> SMSData) fprintf(stdout, _(" SMSData true\n")); + else fprintf(stdout, _(" SMSData false\n")); +#endif + /* RTH: unread sms from folder 0 to INBOX */ + phoneMonitor.sms.messages = g_slist_append (phoneMonitor.sms.messages, msg); + phoneMonitor.sms.number++; + phoneMonitor.sms.number2++; + pthread_mutex_unlock (&smsMutex); + if (phoneMonitor.sms.number2 == number) return; + break; + case GE_SMSTOOLONG: /* Picture Image in 7110 comp phone */ + g_free (msg); + phoneMonitor.sms.number2++; + if (phoneMonitor.sms.number2 == number) return; + break; + default: + g_free (msg); + break; } - else - g_free (msg); - - usleep (750000); + i++; } } @@ -297,16 +292,13 @@ static gint A_GetMemoryStatus (gpointer data) { GSM_Error error; D_MemoryStatus *ms = (D_MemoryStatus *) data; - GSM_Data gdat; error = ms->status = GE_UNKNOWN; if (ms) { - GSM_DataClear(&gdat); pthread_mutex_lock (&memoryMutex); - gdat.MemoryStatus=&(ms->memoryStatus); - error = ms->status = SM_Functions(GOP_GetMemoryStatus,&gdat,&statemachine); + error = ms->status = GSM->GetMemoryStatus (&(ms->memoryStatus)); pthread_cond_signal (&memoryCond); pthread_mutex_unlock (&memoryMutex); } @@ -319,16 +311,13 @@ static gint A_GetMemoryLocation (gpointer data) { GSM_Error error; D_MemoryLocation *ml = (D_MemoryLocation *) data; - GSM_Data gdat; error = ml->status = GE_UNKNOWN; if (ml) { - GSM_DataClear(&gdat); pthread_mutex_lock (&memoryMutex); - gdat.PhonebookEntry=(ml->entry); - error = ml->status = SM_Functions(GOP_ReadPhonebook,&gdat,&statemachine); + error = ml->status = GSM->GetMemoryLocation (ml->entry); pthread_cond_signal (&memoryCond); pthread_mutex_unlock (&memoryMutex); } @@ -343,51 +332,46 @@ static gint A_GetMemoryLocationAll (gpointer data) GSM_Error error; D_MemoryLocationAll *mla = (D_MemoryLocationAll *) data; register gint i; - GSM_Data gdat; + gint readed=0; error = mla->status = GE_NONE; entry.MemoryType = mla->type; - GSM_DataClear(&gdat); - gdat.PhonebookEntry=&entry; pthread_mutex_lock (&memoryMutex); for (i = mla->min; i <= mla->max; i++) { entry.Location = i; - error = SM_Functions(GOP_ReadPhonebook,&gdat,&statemachine); - if (error != GE_NONE && error!=GE_INVALIDPHBOOKLOCATION) - { - gint err_count = 0; - - while (error != GE_NONE) + if (readedused) { + error = GSM->GetMemoryLocation (&entry); + if (error != GE_NONE) { - g_print (_("%s: line %d: Can't get memory entry number %d from memory %d! %d\n"), - __FILE__, __LINE__, i, entry.MemoryType, error); - if (err_count++ > 3) + gint err_count = 0; + + while (error != GE_NONE && + error != GE_INVALIDPHBOOKLOCATION && error != GE_UNKNOWN) //n7110.c { - mla->ReadFailed (i); - mla->status = error; - pthread_cond_signal (&memoryCond); - pthread_mutex_unlock (&memoryMutex); - return (error); + g_print (_("%s: line %d: Can't get memory entry number %d from memory %d! %d\n"), + __FILE__, __LINE__, i, entry.MemoryType, error); + if (err_count++ > 3) + { + mla->ReadFailed (i); + mla->status = error; + pthread_cond_signal (&memoryCond); + pthread_mutex_unlock (&memoryMutex); + return (error); + } + + error = GSM->GetMemoryLocation (&entry); + sleep (2); } - - error = SM_Functions(GOP_ReadPhonebook,&gdat,&statemachine); - sleep (2); } - } + + if (strcmp(entry.Number, "\0") || strcmp(entry.Name, "\0")) + readed++; - /* If the phonebook location was invalid - just fill up the rest */ - /* This works on a 7110 anyway...*/ - - if (error==GE_INVALIDPHBOOKLOCATION) { - entry.Empty=true; - entry.Name[0]=0; - entry.Number[0]=0; - for (i = mla->min; i <= mla->max; i++) { - error = mla->InsertEntry (&entry); - if (error != GE_NONE) break; - } + } else { + entry.Number[0]='\0'; + entry.Name[0]='\0'; } error = mla->InsertEntry (&entry); @@ -405,17 +389,13 @@ static gint A_WriteMemoryLocation (gpointer data) { GSM_Error error; D_MemoryLocation *ml = (D_MemoryLocation *) data; - GSM_Data gdat; error = ml->status = GE_UNKNOWN; - GSM_DataClear(&gdat); - gdat.PhonebookEntry=(ml->entry); - if (ml) { pthread_mutex_lock (&memoryMutex); - error = ml->status = SM_Functions(GOP_WritePhonebook,&gdat,&statemachine); + error = ml->status = GSM->WritePhonebookLocation (ml->entry); pthread_cond_signal (&memoryCond); pthread_mutex_unlock (&memoryMutex); } @@ -517,7 +497,6 @@ static gint A_GetCalendarNoteAll (gpointer data) return (e); } - static gint A_WriteCalendarNote (gpointer data) { GSM_Error error; @@ -556,7 +535,6 @@ static gint A_GetCallerGroup (gpointer data) GSM_Bitmap bitmap; GSM_Error error; D_CallerGroup *cg = (D_CallerGroup *) data; - GSM_Data gdat; error = cg->status = GE_UNKNOWN; @@ -566,9 +544,7 @@ static gint A_GetCallerGroup (gpointer data) bitmap.number = cg->number; pthread_mutex_lock (&callerGroupMutex); - GSM_DataClear(&gdat); - gdat.Bitmap=&bitmap; - error = cg->status = SM_Functions(GOP_GetBitmap,&gdat,&statemachine); + error = cg->status = GSM->GetBitmap (&bitmap); strncpy (cg->text, bitmap.text, 256); cg->text[255] = '\0'; pthread_cond_signal (&callerGroupCond); @@ -648,7 +624,7 @@ static gint A_SendSMSMessage (gpointer data) if (d) { pthread_mutex_lock (&sendSMSMutex); - error = d->status = GSM->SendSMSMessage (d->sms, 0); + error = d->status = GSM->SendSMSMessage (d->sms); pthread_cond_signal (&sendSMSCond); pthread_mutex_unlock (&sendSMSMutex); } @@ -667,10 +643,7 @@ static gint A_DeleteSMSMessage (gpointer data) if (sms) { - GSM_Data gdat; - GSM_DataClear(&gdat); - gdat.SMSMessage = sms; - error = SM_Functions(GOP_DeleteSMS, &gdat, &statemachine); + error = GSM->DeleteSMSMessage(sms); g_free (sms); } @@ -780,11 +753,10 @@ static gint A_GetAlarm (gpointer data) D_Alarm *a = (D_Alarm *) data; GSM_Error error; - error = GE_UNKNOWN; + error = a->status = GE_UNKNOWN; if (a) { - a->status = GE_UNKNOWN; pthread_mutex_lock (&alarmMutex); error = a->status = GSM->GetAlarm (0, &(a->time)); pthread_cond_signal (&alarmCond); @@ -814,14 +786,13 @@ static gint A_SetAlarm (gpointer data) static gint A_SendKeyStroke (gpointer data) { - /* gchar *buf = (gchar *) data;*/ + gchar *buf = (gchar *) data; - /* This is wrong. FIX IT */ - /* if (buf) + if (buf) { - FB61_TX_SendMessage(0x07, 0x0c, buf); + GSM->PressKey(buf[1], buf[0]); g_free (buf); - }*/ + } return (0); } @@ -829,12 +800,9 @@ static gint A_SendKeyStroke (gpointer data) static gint A_GetBitmap(gpointer data) { GSM_Error error; D_Bitmap *d = (D_Bitmap *)data; - GSM_Data gdat; - GSM_DataClear(&gdat); pthread_mutex_lock(&getBitmapMutex); - gdat.Bitmap=d->bitmap; - error = d->status = SM_Functions(GOP_GetBitmap,&gdat,&statemachine); + error = d->status = GSM->GetBitmap(d->bitmap); pthread_cond_signal(&getBitmapCond); pthread_mutex_unlock(&getBitmapMutex); return error; @@ -844,24 +812,19 @@ static gint A_SetBitmap(gpointer data) { GSM_Error error; D_Bitmap *d = (D_Bitmap *)data; GSM_Bitmap bitmap; - GSM_Data gdat; - GSM_DataClear(&gdat); pthread_mutex_lock(&setBitmapMutex); if (d->bitmap->type == GSM_CallerLogo) { bitmap.type = d->bitmap->type; bitmap.number = d->bitmap->number; - gdat.Bitmap=&bitmap; - error = d->status = SM_Functions(GOP_GetBitmap,&gdat,&statemachine); + error = d->status = GSM->GetBitmap(&bitmap); if (error == GE_NONE) { strncpy(d->bitmap->text,bitmap.text,sizeof(bitmap.text)); d->bitmap->ringtone = bitmap.ringtone; - gdat.Bitmap=d->bitmap; - error = d->status = SM_Functions(GOP_SetBitmap,&gdat,&statemachine); + error = d->status = GSM->SetBitmap(d->bitmap); } } else { - gdat.Bitmap=d->bitmap; - error = d->status = SM_Functions(GOP_SetBitmap,&gdat,&statemachine); + error = d->status = GSM->SetBitmap(d->bitmap); } pthread_cond_signal(&setBitmapCond); pthread_mutex_unlock(&setBitmapMutex); @@ -871,13 +834,9 @@ static gint A_SetBitmap(gpointer data) { static gint A_GetNetworkInfo(gpointer data) { GSM_Error error; D_NetworkInfo *d = (D_NetworkInfo *)data; - GSM_Data gdat; - - GSM_DataClear(&gdat); pthread_mutex_lock(&getNetworkInfoMutex); - gdat.NetworkInfo=d->info; - error = d->status = SM_Functions(GOP_GetNetworkInfo,&gdat,&statemachine); + error = d->status = GSM->GetNetworkInfo(d->info); pthread_cond_signal(&getNetworkInfoCond); pthread_mutex_unlock(&getNetworkInfoMutex); return error; @@ -921,22 +880,18 @@ gint (*DoAction[])(gpointer) = { A_Exit }; - void *GUI_Connect (void *a) { /* Define required unit types for RF and Battery level meters. */ - GSM_RFUnits rf_units = GRF_Percentage; - GSM_BatteryUnits batt_units = GBU_Percentage; + GSM_RFUnits rf_units = GRF_Arbitrary; + GSM_BatteryUnits batt_units = GBU_Arbitrary; GSM_DateTime Alarm; - GSM_SMSMemoryStatus SMSStatus = {0, 0}; gchar number[INCALL_NUMBER_LENGTH]; - PhoneEvent *event; + PhoneEvent *event=NULL; GSM_Error error; gint status; - GSM_Data data; - GSM_DataClear(&data); # ifdef XDEBUG g_print ("Initializing connection...\n"); @@ -950,104 +905,86 @@ void *GUI_Connect (void *a) g_print ("Phone connected. Starting monitoring...\n"); # endif - sleep(1); - - data.RFLevel=&phoneMonitor.rfLevel; - data.RFUnits=&rf_units; - data.PowerSource=&phoneMonitor.powerSource; - data.BatteryUnits=&batt_units; - data.BatteryLevel=&phoneMonitor.batteryLevel; - data.DateTime=&Alarm; - data.SMSStatus=&SMSStatus; - data.IncomingCallNr=number; - while (1) { - phoneMonitor.working = NULL; - - /* FIXME - this loop goes mad on my 7110 - so I've put in a usleep */ - usleep(50000); - - if (SM_Functions(GOP_GetRFLevel,&data,&statemachine) != GE_NONE) - phoneMonitor.rfLevel = -1; + if (event != NULL) { + phoneMonitor.working = _("Working..."); + } else { + phoneMonitor.working = NULL; - if (rf_units == GRF_Arbitrary) - phoneMonitor.rfLevel *= 25; + if (GSM->GetRFLevel (&rf_units, &phoneMonitor.rfLevel) != GE_NONE) + phoneMonitor.rfLevel = -1; - if (SM_Functions(GOP_GetPowersource,&data,&statemachine) == GE_NONE - && phoneMonitor.powerSource == GPS_ACDC) - phoneMonitor.batteryLevel = ((gint) phoneMonitor.batteryLevel + 25) % 125; - else - { - if (SM_Functions(GOP_GetBatteryLevel,&data,&statemachine) != GE_NONE) - phoneMonitor.batteryLevel = -1; - if (batt_units == GBU_Arbitrary) - phoneMonitor.batteryLevel *= 25; - } + if (rf_units == GRF_Arbitrary) + phoneMonitor.rfLevel *= 25; - if (SM_Functions(GOP_GetAlarm,&data,&statemachine) == GE_NONE && Alarm.AlarmEnabled != 0) - phoneMonitor.alarm = TRUE; - else - phoneMonitor.alarm = FALSE; - - if (SM_Functions(GOP_GetSMSStatus,&data,&statemachine) == GE_NONE) - { - if (phoneMonitor.sms.unRead != SMSStatus.Unread || - phoneMonitor.sms.number != SMSStatus.Number) + if (GSM->GetPowerSource (&phoneMonitor.powerSource) == GE_NONE + && phoneMonitor.powerSource == GPS_ACDC) + phoneMonitor.batteryLevel = ((gint) phoneMonitor.batteryLevel + 25) % 125; + else { - phoneMonitor.working = _("Refreshing SMSes..."); - RefreshSMS (SMSStatus.Number); - phoneMonitor.working = NULL; + if (GSM->GetBatteryLevel (&batt_units, &phoneMonitor.batteryLevel) != GE_NONE) + phoneMonitor.batteryLevel = -1; + if (batt_units == GBU_Arbitrary) + phoneMonitor.batteryLevel *= 25; } - phoneMonitor.sms.unRead = SMSStatus.Unread; - } + if (GSM->GetAlarm (0, &Alarm) == GE_NONE && Alarm.IsSet != 0) + phoneMonitor.alarm = TRUE; + else + phoneMonitor.alarm = FALSE; - if (SM_Functions(GOP_GetIncomingCallNr,&data,&statemachine) == GE_NONE) - { + if (GSM->GetIncomingCallNr (number) == GE_NONE) + { # ifdef XDEBUG - g_print ("Call in progress: %s\n", phoneMonitor.call.callNum); + g_print ("Call in progress: %s\n", phoneMonitor.call.callNum); # endif - GSM->GetDisplayStatus (&status); - if (status & (1<GetDisplayStatus (&status)==GE_NONE) { + if (status & (1<NetMonitor (phoneMonitor.netmonitor.number, - phoneMonitor.netmonitor.screen); - GSM->NetMonitor (3, phoneMonitor.netmonitor.screen3); - GSM->NetMonitor (4, phoneMonitor.netmonitor.screen4); - GSM->NetMonitor (5, phoneMonitor.netmonitor.screen5); - } - else - { - *phoneMonitor.netmonitor.screen = *phoneMonitor.netmonitor.screen3 = - *phoneMonitor.netmonitor.screen4 = *phoneMonitor.netmonitor.screen5 = '\0'; + pthread_mutex_lock (&netMonMutex); + if (phoneMonitor.netmonitor.number) + { + GSM->NetMonitor (phoneMonitor.netmonitor.number, + phoneMonitor.netmonitor.screen); + GSM->NetMonitor (3, phoneMonitor.netmonitor.screen3); + GSM->NetMonitor (4, phoneMonitor.netmonitor.screen4); + GSM->NetMonitor (5, phoneMonitor.netmonitor.screen5); + } + else + { + *phoneMonitor.netmonitor.screen = *phoneMonitor.netmonitor.screen3 = + *phoneMonitor.netmonitor.screen4 = *phoneMonitor.netmonitor.screen5 = '\0'; + } + pthread_mutex_unlock (&netMonMutex); } - pthread_mutex_unlock (&netMonMutex); - while ((event = RemoveEvent ()) != NULL) { # ifdef XDEBUG