7 A Linux/Unix GUI for Nokia mobile phones.
8 Copyright (C) 1999 Pavel Janík ml., Hugh Blemings
9 & Ján Derfiòák <ja@mail.upjs.sk>.
11 Released under the terms of the GNU GPL, see file COPYING for more details.
14 Revision 1.1.1.4 2002/04/03 00:08:33 short
15 Found in "gnokii-working" directory, some November-patches version
17 Revision 1.19 2001/09/14 13:09:26 pkot
18 Xgnokii calendar updates
20 Revision 1.18 2001/06/20 21:27:36 pkot
21 IrDA patch (Martin Jancar)
23 Revision 1.17 2001/06/10 11:40:06 machek
24 xgnokii converted to new structure w.r.t. SMS messages.
26 Revision 1.16 2001/05/24 20:47:31 chris
27 More updating of 7110 code and some of xgnokii_lowlevel changed over.
29 Revision 1.15 2001/03/23 08:24:57 ja
30 New preview for 6210 in xgnokii's logos module.
32 Revision 1.14 2001/03/21 23:36:09 chris
33 Added the statemachine
34 This will break gnokii --identify and --monitor except for 6210/7110
36 Revision 1.13 2001/03/05 10:42:03 ja
37 Pavel Machek's vcard and finegrained indicators patch.
39 Revision 1.12 2001/02/02 08:09:57 ja
40 New dialogs for 6210/7110 in xgnokii. Fixed the smsd for new capabilty code.
42 Revision 1.11 2001/01/29 15:22:20 machek
43 Use integer as bitfield instead of struct of int:1.
45 Be able to read phonebook saved in gnokii format from xgnokii.
47 Revision 1.10 2001/01/17 02:54:56 chris
48 More 7110 work. Use with care! (eg it is not possible to delete phonebook entries)
49 I can now edit my phonebook in xgnokii but it is 'work in progress'.
51 Revision 1.9 2001/01/15 21:10:20 ja
52 Better status reporting in xgnokii, fixed phone capabilities detection in xgnokii.
62 #include "gsm-common.h"
64 #include "fbus-6110.h"
65 #include "fbus-3810.h"
66 #include "xgnokii_lowlevel.h"
68 #include "gsm-statemachine.h"
69 //#include "xgnokii_common.h"
72 PhoneMonitor phoneMonitor;
73 pthread_mutex_t memoryMutex;
74 pthread_cond_t memoryCond;
75 pthread_mutex_t calendarMutex;
76 pthread_cond_t calendarCond;
77 pthread_mutex_t smsMutex;
78 pthread_mutex_t sendSMSMutex;
79 pthread_cond_t sendSMSCond;
80 pthread_mutex_t saveSMSMutex;
81 pthread_cond_t saveSMSCond;
82 pthread_mutex_t callMutex;
83 pthread_mutex_t netMonMutex;
84 pthread_mutex_t speedDialMutex;
85 pthread_cond_t speedDialCond;
86 pthread_mutex_t callerGroupMutex;
87 pthread_cond_t callerGroupCond;
88 pthread_mutex_t smsCenterMutex;
89 pthread_cond_t smsCenterCond;
90 pthread_mutex_t alarmMutex;
91 pthread_cond_t alarmCond;
92 pthread_mutex_t getBitmapMutex;
93 pthread_cond_t getBitmapCond;
94 pthread_mutex_t setBitmapMutex;
95 pthread_cond_t setBitmapCond;
96 pthread_mutex_t getNetworkInfoMutex;
97 pthread_cond_t getNetworkInfoCond;
98 static pthread_mutex_t eventsMutex;
99 static GSList *ScheduledEvents = NULL;
101 /* This symbol must be export as it is (mis)used by xgnokii_logos.c
103 GSM_Statemachine xgnokii_statemachine;
106 inline void GUI_InsertEvent (PhoneEvent *event)
109 g_print ("Inserting Event: %d\n", event->event);
111 pthread_mutex_lock (&eventsMutex);
112 ScheduledEvents = g_slist_prepend (ScheduledEvents, event);
113 pthread_mutex_unlock (&eventsMutex);
117 inline static PhoneEvent *RemoveEvent (void)
120 PhoneEvent *event = NULL;
122 pthread_mutex_lock (&eventsMutex);
123 list = g_slist_last (ScheduledEvents);
126 event = (PhoneEvent *) list->data;
127 ScheduledEvents = g_slist_remove_link (ScheduledEvents, list);
128 g_slist_free_1 (list);
130 pthread_mutex_unlock (&eventsMutex);
136 static void InitModelInf (void)
143 GSM_DataClear(&data);
145 while ((error = SM_Functions(GOP_GetModel,&data,&xgnokii_statemachine)) != GE_NONE && i++ < 15)
148 if (error == GE_NONE)
150 g_free (phoneMonitor.phone.model);
151 phoneMonitor.phone.version = g_strdup (buf);
152 phoneMonitor.phone.model = GetModel (buf);
153 if (phoneMonitor.phone.model == NULL)
154 phoneMonitor.phone.model = g_strdup (_("unknown"));
156 phoneMonitor.supported = GetPhoneModel(buf)->flags;
161 while ((error = SM_Functions(GOP_GetRevision,&data,&xgnokii_statemachine)) != GE_NONE && i++ < 5)
164 if (error == GE_NONE)
166 g_free (phoneMonitor.phone.revision);
167 phoneMonitor.phone.revision = g_strdup (buf);
172 while ((error = SM_Functions(GOP_GetImei,&data,&xgnokii_statemachine)) != GE_NONE && i++ < 5)
175 if (error == GE_NONE)
177 g_free (phoneMonitor.phone.imei);
178 phoneMonitor.phone.imei = g_strdup (buf);
183 g_print ("Version: %s\n", phoneMonitor.phone.version);
184 g_print ("Model: %s\n", phoneMonitor.phone.model);
185 g_print ("IMEI: %s\n", phoneMonitor.phone.imei);
186 g_print ("Revision: %s\n", phoneMonitor.phone.revision);
191 static GSM_Error fbusinit(bool enable_monitoring)
194 GSM_Error error=GE_NOLINK;
195 GSM_ConnectionType connection=GCT_Serial;
197 if (!strcmp(xgnokiiConfig.connection, "infrared"))
198 connection = GCT_Infrared;
200 if (!strcmp(xgnokiiConfig.connection, "irda"))
201 connection = GCT_Irda;
203 /* Initialise the code for the GSM interface. */
205 if (error == GE_NOLINK)
206 error = GSM_Initialise (xgnokiiConfig.model, xgnokiiConfig.port,
207 xgnokiiConfig.initlength, connection, NULL /*RLP_DisplayF96Frame*/, &xgnokii_statemachine);
210 g_print ("fbusinit: error %d\n", error);
213 if (error != GE_NONE) {
214 g_print (_("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
215 /* FIXME: should popup some message... */
219 while (count++ < 40 && *GSM_LinkOK == false)
222 g_print("After usleep. GSM_LinkOK: %d\n", *GSM_LinkOK);
225 if (*GSM_LinkOK != true) {
234 void GUI_InitPhoneMonitor (void)
236 phoneMonitor.phone.model = g_strdup (_("unknown"));
237 phoneMonitor.phone.version = phoneMonitor.phone.model;
238 phoneMonitor.phone.revision = g_strdup (_("unknown"));
239 phoneMonitor.phone.imei = g_strdup (_("unknown"));
240 phoneMonitor.supported = 0;
241 phoneMonitor.rfLevel = phoneMonitor.batteryLevel = -1;
242 phoneMonitor.powerSource = GPS_BATTERY;
243 phoneMonitor.working = NULL;
244 phoneMonitor.alarm = FALSE;
245 phoneMonitor.sms.unRead = phoneMonitor.sms.used = phoneMonitor.sms.slots = 0;
246 phoneMonitor.sms.messages = NULL;
247 phoneMonitor.call.callInProgress = CS_Idle;
248 *phoneMonitor.call.callNum = '\0';
249 phoneMonitor.netmonitor.number = 0;
250 *phoneMonitor.netmonitor.screen = *phoneMonitor.netmonitor.screen3 =
251 *phoneMonitor.netmonitor.screen4 = *phoneMonitor.netmonitor.screen5 = '\0';
252 pthread_mutex_init (&memoryMutex, NULL);
253 pthread_cond_init (&memoryCond, NULL);
254 pthread_mutex_init (&calendarMutex, NULL);
255 pthread_cond_init (&calendarCond, NULL);
256 pthread_mutex_init (&smsMutex, NULL);
257 pthread_mutex_init (&sendSMSMutex, NULL);
258 pthread_cond_init (&sendSMSCond, NULL);
259 pthread_mutex_init (&saveSMSMutex, NULL);
260 pthread_cond_init (&saveSMSCond, NULL);
261 pthread_mutex_init (&callMutex, NULL);
262 pthread_mutex_init (&eventsMutex, NULL);
263 pthread_mutex_init (&callMutex, NULL);
264 pthread_mutex_init (&netMonMutex, NULL);
265 pthread_mutex_init (&speedDialMutex, NULL);
266 pthread_cond_init (&speedDialCond, NULL);
267 pthread_mutex_init (&callerGroupMutex, NULL);
268 pthread_cond_init (&callerGroupCond, NULL);
269 pthread_mutex_init (&smsCenterMutex, NULL);
270 pthread_cond_init (&smsCenterCond, NULL);
271 pthread_mutex_init (&getBitmapMutex, NULL);
272 pthread_cond_init (&getBitmapCond, NULL);
273 pthread_mutex_init (&setBitmapMutex, NULL);
274 pthread_cond_init (&setBitmapCond, NULL);
275 pthread_mutex_init (&getNetworkInfoMutex, NULL);
276 pthread_cond_init (&getNetworkInfoCond, NULL);
280 static inline void FreeElement (gpointer data, gpointer userData)
282 g_free ((GSM_SMSMessage *) data);
286 static inline void FreeArray (GSList **array)
290 g_slist_foreach (*array, FreeElement, NULL);
291 g_slist_free (*array);
297 static void RefreshSMS (const gint slots)
305 g_print ("RefreshSMS is running...\n");
308 pthread_mutex_lock (&smsMutex);
309 FreeArray (&(phoneMonitor.sms.messages));
310 phoneMonitor.sms.used = 0;
311 pthread_mutex_unlock (&smsMutex);
313 for (i=1; i<=slots; i++)
316 GSM_DataClear(&gdat);
317 msg = g_malloc (sizeof (GSM_SMSMessage));
318 msg->MemoryType = GMT_SM;
320 gdat.SMSMessage = msg;
322 if ((error = SM_Functions(GOP_GetSMS, &gdat, &xgnokii_statemachine)) == GE_NONE)
324 pthread_mutex_lock (&smsMutex);
325 phoneMonitor.sms.messages = g_slist_append (phoneMonitor.sms.messages, msg);
326 phoneMonitor.sms.used++;
327 if (msg->Type == GST_MT && msg->Status == GSS_NOTSENTREAD)
329 pthread_mutex_unlock (&smsMutex);
331 else if (error == GE_INVALIDSMSLOCATION) /* All positions are readed */
339 /* FIXME: Why is any delay here?
341 /* usleep (750000); */
343 /* Update it after the whole run as otherwise "Refreshing SMSes..."
344 * would collide with "Short Message received" message.
346 phoneMonitor.sms.unRead = unread;
350 static gint A_GetMemoryStatus (gpointer data)
353 D_MemoryStatus *ms = (D_MemoryStatus *) data;
356 error = ms->status = GE_UNKNOWN;
360 GSM_DataClear(&gdat);
361 pthread_mutex_lock (&memoryMutex);
362 gdat.MemoryStatus=&(ms->memoryStatus);
363 error = ms->status = SM_Functions(GOP_GetMemoryStatus,&gdat,&xgnokii_statemachine);
364 pthread_cond_signal (&memoryCond);
365 pthread_mutex_unlock (&memoryMutex);
372 static gint A_GetMemoryLocation (gpointer data)
375 D_MemoryLocation *ml = (D_MemoryLocation *) data;
378 error = ml->status = GE_UNKNOWN;
382 GSM_DataClear(&gdat);
383 pthread_mutex_lock (&memoryMutex);
384 gdat.PhonebookEntry=(ml->entry);
385 error = ml->status = SM_Functions(GOP_ReadPhonebook,&gdat,&xgnokii_statemachine);
386 pthread_cond_signal (&memoryCond);
387 pthread_mutex_unlock (&memoryMutex);
394 static gint A_GetMemoryLocationAll (gpointer data)
396 GSM_PhonebookEntry entry;
398 D_MemoryLocationAll *mla = (D_MemoryLocationAll *) data;
402 error = mla->status = GE_NONE;
403 entry.MemoryType = mla->type;
404 GSM_DataClear(&gdat);
405 gdat.PhonebookEntry=&entry;
407 pthread_mutex_lock (&memoryMutex);
408 for (i = mla->min; i <= mla->max; i++)
411 error = SM_Functions(GOP_ReadPhonebook,&gdat,&xgnokii_statemachine);
412 if (error != GE_NONE && error!=GE_INVALIDPHBOOKLOCATION)
416 while (error != GE_NONE)
418 g_print (_("%s: line %d: Can't get memory entry number %d from memory %d! %d\n"),
419 __FILE__, __LINE__, i, entry.MemoryType, error);
424 pthread_cond_signal (&memoryCond);
425 pthread_mutex_unlock (&memoryMutex);
429 error = SM_Functions(GOP_ReadPhonebook,&gdat,&xgnokii_statemachine);
434 /* If the phonebook location was invalid - just fill up the rest */
435 /* This works on a 7110 anyway...*/
437 if (error==GE_INVALIDPHBOOKLOCATION) {
441 for (i = mla->min; i <= mla->max; i++) {
442 error = mla->InsertEntry (&entry);
443 if (error != GE_NONE) break;
447 error = mla->InsertEntry (&entry);
448 if (error != GE_NONE)
452 pthread_cond_signal (&memoryCond);
453 pthread_mutex_unlock (&memoryMutex);
458 static gint A_WriteMemoryLocation (gpointer data)
461 D_MemoryLocation *ml = (D_MemoryLocation *) data;
464 error = ml->status = GE_UNKNOWN;
466 GSM_DataClear(&gdat);
467 gdat.PhonebookEntry=(ml->entry);
471 pthread_mutex_lock (&memoryMutex);
472 error = ml->status = SM_Functions(GOP_WritePhonebook,&gdat,&xgnokii_statemachine);
473 pthread_cond_signal (&memoryCond);
474 pthread_mutex_unlock (&memoryMutex);
481 static gint A_WriteMemoryLocationAll (gpointer data)
483 /* GSM_PhonebookEntry entry; */
485 D_MemoryLocationAll *mla = (D_MemoryLocationAll *) data;
488 error = mla->status = GE_NONE;
489 /* entry.MemoryType = mla->type;
491 pthread_mutex_lock (&memoryMutex);
492 for (i = mla->min; i <= mla->max; i++)
495 error = GSM->GetMemoryLocation (&entry);
496 if (error != GE_NONE)
500 while (error != GE_NONE)
502 g_print (_("%s: line %d: Can't get memory entry number %d from memory %d! %d\n"),
503 __FILE__, __LINE__, i, entry.MemoryType, error);
508 pthread_cond_signal (&memoryCond);
509 pthread_mutex_unlock (&memoryMutex);
513 error = GSM->GetMemoryLocation (&entry);
517 error = mla->InsertEntry (&entry);
518 if (error != GE_NONE)
522 pthread_cond_signal (&memoryCond);
523 pthread_mutex_unlock (&memoryMutex); */
528 static gint A_GetCalendarNote (gpointer data)
531 D_CalendarNote *cn = (D_CalendarNote *) data;
533 error = cn->status = GE_UNKNOWN;
537 pthread_mutex_lock (&calendarMutex);
538 error = cn->status = GSM->GetCalendarNote (cn->entry);
539 pthread_cond_signal (&calendarCond);
540 pthread_mutex_unlock (&calendarMutex);
547 static gint A_GetCalendarNoteAll (gpointer data)
549 GSM_CalendarNote entry;
550 D_CalendarNoteAll *cna = (D_CalendarNoteAll *) data;
554 pthread_mutex_lock (&calendarMutex);
557 entry.Location = i++;
559 if ((e = GSM->GetCalendarNote (&entry)) != GE_NONE)
562 if (cna->InsertEntry (&entry) != GE_NONE)
566 pthread_mutex_unlock (&calendarMutex);
568 if (e == GE_INVALIDCALNOTELOCATION)
575 static gint A_WriteCalendarNote (gpointer data)
578 D_CalendarNote *cn = (D_CalendarNote *) data;
580 error = cn->status = GE_UNKNOWN;
584 pthread_mutex_lock (&calendarMutex);
585 error = cn->status = GSM->WriteCalendarNote (cn->entry);
586 pthread_cond_signal (&calendarCond);
587 pthread_mutex_unlock (&calendarMutex);
594 static gint A_DeleteCalendarNote (gpointer data)
596 GSM_CalendarNote *note = (GSM_CalendarNote *) data;
597 GSM_Error error = GE_UNKNOWN;
601 error = GSM->DeleteCalendarNote (note);
608 static gint A_GetCallerGroup (gpointer data)
612 D_CallerGroup *cg = (D_CallerGroup *) data;
615 error = cg->status = GE_UNKNOWN;
619 bitmap.type = GSM_CallerLogo;
620 bitmap.number = cg->number;
622 pthread_mutex_lock (&callerGroupMutex);
623 GSM_DataClear(&gdat);
625 error = cg->status = SM_Functions(GOP_GetBitmap,&gdat,&xgnokii_statemachine);
626 strncpy (cg->text, bitmap.text, 256);
627 cg->text[255] = '\0';
628 pthread_cond_signal (&callerGroupCond);
629 pthread_mutex_unlock (&callerGroupMutex);
636 static gint A_SendCallerGroup (gpointer data)
639 D_CallerGroup *cg = (D_CallerGroup *) data;
645 bitmap.type = GSM_CallerLogo;
646 bitmap.number = cg->number;
647 if ((error = GSM->GetBitmap (&bitmap)) != GE_NONE)
652 strncpy (bitmap.text, cg->text, 256);
653 bitmap.text[255] = '\0';
655 return (GSM->SetBitmap (&bitmap));
659 static gint A_GetSMSCenter (gpointer data)
661 D_SMSCenter *c = (D_SMSCenter *) data;
664 error = c->status = GE_UNKNOWN;
667 pthread_mutex_lock (&smsCenterMutex);
668 error = c->status = GSM->GetSMSCenter (c->center);
669 pthread_cond_signal (&smsCenterCond);
670 pthread_mutex_unlock (&smsCenterMutex);
677 static gint A_SetSMSCenter (gpointer data)
679 D_SMSCenter *c = (D_SMSCenter *) data;
682 error = c->status = GE_UNKNOWN;
685 //pthread_mutex_lock (&smsCenterMutex);
686 error = c->status = GSM->SetSMSCenter (c->center);
688 //pthread_cond_signal (&smsCenterCond);
689 //pthread_mutex_unlock (&smsCenterMutex);
696 static gint A_SendSMSMessage (gpointer data)
698 D_SMSMessage *d = (D_SMSMessage *) data;
701 error = d->status = GE_UNKNOWN;
704 pthread_mutex_lock (&sendSMSMutex);
705 error = d->status = GSM->SendSMSMessage (d->sms);
706 pthread_cond_signal (&sendSMSCond);
707 pthread_mutex_unlock (&sendSMSMutex);
710 if (d->status == GE_SMSSENDOK)
717 static gint A_SaveSMSMessage (gpointer data)
719 D_SMSMessage *d = (D_SMSMessage *) data;
722 error = d->status = GE_UNKNOWN;
725 pthread_mutex_lock (&saveSMSMutex);
726 error = d->status = GSM->SaveSMSMessage (d->sms);
727 pthread_cond_signal (&saveSMSCond);
728 pthread_mutex_unlock (&saveSMSMutex);
735 static gint A_DeleteSMSMessage (gpointer data)
737 GSM_SMSMessage *sms = (GSM_SMSMessage *) data;
738 GSM_Error error = GE_UNKNOWN;
743 GSM_DataClear(&gdat);
744 gdat.SMSMessage = sms;
745 error = SM_Functions(GOP_DeleteSMS, &gdat, &xgnokii_statemachine);
753 static gint A_GetSpeedDial (gpointer data)
755 D_SpeedDial *d = (D_SpeedDial *) data;
758 error = d->status = GE_UNKNOWN;
762 pthread_mutex_lock (&speedDialMutex);
763 error = d->status = GSM->GetSpeedDial (&(d->entry));
764 pthread_cond_signal (&speedDialCond);
765 pthread_mutex_unlock (&speedDialMutex);
772 static gint A_SendSpeedDial (gpointer data)
774 D_SpeedDial *d = (D_SpeedDial *) data;
777 error = d->status = GE_UNKNOWN;
781 //pthread_mutex_lock (&speedDialMutex);
782 error = d->status = GSM->SetSpeedDial (&(d->entry));
784 //pthread_cond_signal (&speedDialCond);
785 //pthread_mutex_unlock (&speedDialMutex);
792 static gint A_SendDTMF (gpointer data)
794 gchar *buf = (gchar *) data;
795 GSM_Error error = GE_UNKNOWN;
799 error = GSM->SendDTMF (buf);
807 static gint A_NetMonOnOff (gpointer data)
810 gint mode = GPOINTER_TO_INT (data);
811 GSM_Error error = GE_UNKNOWN;
814 error = GSM->NetMonitor (0xf3, screen);
816 error = GSM->NetMonitor (0xf1, screen);
822 static gint A_NetMonitor (gpointer data)
824 gint number = GPOINTER_TO_INT (data);
827 phoneMonitor.netmonitor.number = 0;
829 phoneMonitor.netmonitor.number = number;
835 static gint A_DialVoice (gpointer data)
837 gchar *number = (gchar *) data;
838 GSM_Error error = GE_UNKNOWN;
842 error = GSM->DialVoice (number);
850 static gint A_GetAlarm (gpointer data)
852 D_Alarm *a = (D_Alarm *) data;
859 a->status = GE_UNKNOWN;
860 pthread_mutex_lock (&alarmMutex);
861 error = a->status = GSM->GetAlarm (0, &(a->time));
862 pthread_cond_signal (&alarmCond);
863 pthread_mutex_unlock (&alarmMutex);
870 static gint A_SetAlarm (gpointer data)
872 D_Alarm *a = (D_Alarm *) data;
875 error = a->status = GE_UNKNOWN;
879 error = a->status = GSM->SetAlarm (0, &(a->time));
887 static gint A_SendKeyStroke (gpointer data)
889 gchar *buf = (gchar *) data;
894 FB61_TX_SendMessage(0x07, 0x0c, buf);
902 static gint A_GetBitmap(gpointer data) {
904 D_Bitmap *d = (D_Bitmap *)data;
907 GSM_DataClear(&gdat);
908 pthread_mutex_lock(&getBitmapMutex);
909 gdat.Bitmap=d->bitmap;
910 error = d->status = SM_Functions(GOP_GetBitmap,&gdat,&xgnokii_statemachine);
911 pthread_cond_signal(&getBitmapCond);
912 pthread_mutex_unlock(&getBitmapMutex);
916 static gint A_SetBitmap(gpointer data) {
918 D_Bitmap *d = (D_Bitmap *)data;
922 GSM_DataClear(&gdat);
923 pthread_mutex_lock(&setBitmapMutex);
924 if (d->bitmap->type == GSM_CallerLogo) {
925 bitmap.type = d->bitmap->type;
926 bitmap.number = d->bitmap->number;
928 error = d->status = SM_Functions(GOP_GetBitmap,&gdat,&xgnokii_statemachine);
929 if (error == GE_NONE) {
930 strncpy(d->bitmap->text,bitmap.text,sizeof(bitmap.text));
931 d->bitmap->ringtone = bitmap.ringtone;
932 gdat.Bitmap=d->bitmap;
933 error = d->status = SM_Functions(GOP_SetBitmap,&gdat,&xgnokii_statemachine);
936 gdat.Bitmap=d->bitmap;
937 error = d->status = SM_Functions(GOP_SetBitmap,&gdat,&xgnokii_statemachine);
939 pthread_cond_signal(&setBitmapCond);
940 pthread_mutex_unlock(&setBitmapMutex);
944 static gint A_GetNetworkInfo(gpointer data) {
946 D_NetworkInfo *d = (D_NetworkInfo *)data;
949 GSM_DataClear(&gdat);
951 pthread_mutex_lock(&getNetworkInfoMutex);
952 gdat.NetworkInfo=d->info;
953 error = d->status = SM_Functions(GOP_GetNetworkInfo,&gdat,&xgnokii_statemachine);
954 pthread_cond_signal(&getNetworkInfoCond);
955 pthread_mutex_unlock(&getNetworkInfoMutex);
959 static gint A_Exit (gpointer data)
962 return (0); /* just to be proper */
966 gint (*DoAction[])(gpointer) = {
969 A_GetMemoryLocationAll,
970 A_WriteMemoryLocation,
971 A_WriteMemoryLocationAll,
973 A_GetCalendarNoteAll,
975 A_DeleteCalendarNote,
999 void *GUI_Connect (void *a)
1001 /* Define required unit types for RF and Battery level meters. */
1002 GSM_RFUnits rf_units = GRF_Percentage;
1003 GSM_BatteryUnits batt_units = GBU_Percentage;
1006 GSM_SMSStatus SMSStatus = {0, 0, 0};
1007 gchar number[INCALL_NUMBER_LENGTH];
1013 GSM_DataClear(&data);
1016 g_print ("Initializing connection...\n");
1019 phoneMonitor.working = _("Connecting...");
1020 while (fbusinit (true))
1024 g_print ("Phone connected. Starting monitoring...\n");
1029 data.RFLevel=&phoneMonitor.rfLevel;
1030 data.RFUnits=&rf_units;
1031 data.PowerSource=&phoneMonitor.powerSource;
1032 data.BatteryUnits=&batt_units;
1033 data.BatteryLevel=&phoneMonitor.batteryLevel;
1034 data.DateTime=&Alarm;
1035 data.SMSStatus=&SMSStatus;
1036 data.IncomingCallNr=number;
1040 phoneMonitor.working = NULL;
1042 /* FIXME - this loop goes mad on my 7110 - so I've put in a usleep */
1045 if (SM_Functions(GOP_GetRFLevel,&data,&xgnokii_statemachine) != GE_NONE)
1046 phoneMonitor.rfLevel = -1;
1048 if (rf_units == GRF_Arbitrary)
1049 phoneMonitor.rfLevel *= 25;
1051 if (SM_Functions(GOP_GetPowersource,&data,&xgnokii_statemachine) == GE_NONE
1052 && phoneMonitor.powerSource == GPS_ACDC)
1054 if (phoneMonitor.batteryLevel < 0 || phoneMonitor.batteryLevel > 100)
1055 phoneMonitor.batteryLevel = 100;
1058 if (SM_Functions(GOP_GetBatteryLevel,&data,&xgnokii_statemachine) != GE_NONE)
1059 phoneMonitor.batteryLevel = -1;
1060 if (batt_units == GBU_Arbitrary)
1061 phoneMonitor.batteryLevel *= 25;
1064 if (SM_Functions(GOP_GetAlarm,&data,&xgnokii_statemachine) == GE_NONE && Alarm.AlarmEnabled != 0)
1065 phoneMonitor.alarm = TRUE;
1067 phoneMonitor.alarm = FALSE;
1069 if (SM_Functions(GOP_GetSMSStatus,&data,&xgnokii_statemachine) == GE_NONE)
1071 /* Change of "UnRead" shouldn't be interesting - user may have read some of his
1072 * SMSes by the phone interface.
1074 if (phoneMonitor.sms.unRead != SMSStatus.UnRead ||
1075 phoneMonitor.sms.used != SMSStatus.Used ||
1076 phoneMonitor.sms.slots != SMSStatus.Slots) /* shouldn't change, just to be sure */
1078 /* We are primarily interested in SMSStatus.Slots so try to fix it up if it is broken
1080 if (SMSStatus.UnRead > SMSStatus.Used)
1081 SMSStatus.Used = SMSStatus.UnRead;
1082 if (SMSStatus.Used > SMSStatus.Slots)
1083 SMSStatus.Slots = SMSStatus.Used;
1084 phoneMonitor.sms.slots = SMSStatus.Slots; /* shouldn't change, just to be sure */
1085 /* phoneMonitor.sms.{unRead,used} will be updated by RefreshSMS()
1088 phoneMonitor.working = _("Refreshing SMSes...");
1089 RefreshSMS (SMSStatus.Slots);
1090 phoneMonitor.working = NULL;
1095 if (SM_Functions(GOP_GetIncomingCallNr,&data,&xgnokii_statemachine) == GE_NONE)
1098 g_print ("Call in progress: %s\n", phoneMonitor.call.callNum);
1101 GSM->GetDisplayStatus (&status);
1102 if (status & (1<<DS_Call_In_Progress))
1104 pthread_mutex_lock (&callMutex);
1105 phoneMonitor.call.callInProgress = CS_InProgress;
1106 pthread_mutex_unlock (&callMutex);
1110 pthread_mutex_lock (&callMutex);
1111 phoneMonitor.call.callInProgress = CS_Waiting;
1112 strncpy (phoneMonitor.call.callNum, number, INCALL_NUMBER_LENGTH);
1113 pthread_mutex_unlock (&callMutex);
1118 pthread_mutex_lock (&callMutex);
1119 phoneMonitor.call.callInProgress = CS_Idle;
1120 *phoneMonitor.call.callNum = '\0';
1121 pthread_mutex_unlock (&callMutex);
1124 pthread_mutex_lock (&netMonMutex);
1125 if (phoneMonitor.netmonitor.number)
1127 GSM->NetMonitor (phoneMonitor.netmonitor.number,
1128 phoneMonitor.netmonitor.screen);
1129 GSM->NetMonitor (3, phoneMonitor.netmonitor.screen3);
1130 GSM->NetMonitor (4, phoneMonitor.netmonitor.screen4);
1131 GSM->NetMonitor (5, phoneMonitor.netmonitor.screen5);
1135 *phoneMonitor.netmonitor.screen = *phoneMonitor.netmonitor.screen3 =
1136 *phoneMonitor.netmonitor.screen4 = *phoneMonitor.netmonitor.screen5 = '\0';
1138 pthread_mutex_unlock (&netMonMutex);
1140 while ((event = RemoveEvent ()) != NULL)
1143 g_print ("Processing Event: %d\n", event->event);
1145 phoneMonitor.working = _("Working...");
1146 if (event->event <= Event_Exit)
1147 if ((error = DoAction[event->event] (event->data)) != GE_NONE)
1148 g_print (_("Event %d failed with return code %d!\n"), event->event, error);