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.5 2002/04/03 01:44:15 short
15 Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
17 Revision 1.1.1.4 2002/04/03 00:08:33 short
18 Found in "gnokii-working" directory, some November-patches version
20 Revision 1.19 2001/09/14 13:09:26 pkot
21 Xgnokii calendar updates
23 Revision 1.18 2001/06/20 21:27:36 pkot
24 IrDA patch (Martin Jancar)
26 Revision 1.17 2001/06/10 11:40:06 machek
27 xgnokii converted to new structure w.r.t. SMS messages.
29 Revision 1.16 2001/05/24 20:47:31 chris
30 More updating of 7110 code and some of xgnokii_lowlevel changed over.
32 Revision 1.15 2001/03/23 08:24:57 ja
33 New preview for 6210 in xgnokii's logos module.
35 Revision 1.14 2001/03/21 23:36:09 chris
36 Added the statemachine
37 This will break gnokii --identify and --monitor except for 6210/7110
39 Revision 1.13 2001/03/05 10:42:03 ja
40 Pavel Machek's vcard and finegrained indicators patch.
42 Revision 1.12 2001/02/02 08:09:57 ja
43 New dialogs for 6210/7110 in xgnokii. Fixed the smsd for new capabilty code.
45 Revision 1.11 2001/01/29 15:22:20 machek
46 Use integer as bitfield instead of struct of int:1.
48 Be able to read phonebook saved in gnokii format from xgnokii.
50 Revision 1.10 2001/01/17 02:54:56 chris
51 More 7110 work. Use with care! (eg it is not possible to delete phonebook entries)
52 I can now edit my phonebook in xgnokii but it is 'work in progress'.
54 Revision 1.9 2001/01/15 21:10:20 ja
55 Better status reporting in xgnokii, fixed phone capabilities detection in xgnokii.
65 #include "gsm-common.h"
67 #include "fbus-6110.h"
68 #include "fbus-3810.h"
69 #include "xgnokii_lowlevel.h"
71 #include "gsm-statemachine.h"
72 //#include "xgnokii_common.h"
75 PhoneMonitor phoneMonitor;
76 pthread_mutex_t memoryMutex;
77 pthread_cond_t memoryCond;
78 pthread_mutex_t calendarMutex;
79 pthread_cond_t calendarCond;
80 pthread_mutex_t smsMutex;
81 pthread_mutex_t sendSMSMutex;
82 pthread_cond_t sendSMSCond;
83 pthread_mutex_t saveSMSMutex;
84 pthread_cond_t saveSMSCond;
85 pthread_mutex_t callMutex;
86 pthread_mutex_t netMonMutex;
87 pthread_mutex_t speedDialMutex;
88 pthread_cond_t speedDialCond;
89 pthread_mutex_t callerGroupMutex;
90 pthread_cond_t callerGroupCond;
91 pthread_mutex_t smsCenterMutex;
92 pthread_cond_t smsCenterCond;
93 pthread_mutex_t alarmMutex;
94 pthread_cond_t alarmCond;
95 pthread_mutex_t getBitmapMutex;
96 pthread_cond_t getBitmapCond;
97 pthread_mutex_t setBitmapMutex;
98 pthread_cond_t setBitmapCond;
99 pthread_mutex_t getNetworkInfoMutex;
100 pthread_cond_t getNetworkInfoCond;
101 static pthread_mutex_t eventsMutex;
102 static GSList *ScheduledEvents = NULL;
104 /* This symbol must be export as it is (mis)used by xgnokii_logos.c
106 GSM_Statemachine xgnokii_statemachine;
109 inline void GUI_InsertEvent (PhoneEvent *event)
112 g_print ("Inserting Event: %d\n", event->event);
114 pthread_mutex_lock (&eventsMutex);
115 ScheduledEvents = g_slist_prepend (ScheduledEvents, event);
116 pthread_mutex_unlock (&eventsMutex);
120 inline static PhoneEvent *RemoveEvent (void)
123 PhoneEvent *event = NULL;
125 pthread_mutex_lock (&eventsMutex);
126 list = g_slist_last (ScheduledEvents);
129 event = (PhoneEvent *) list->data;
130 ScheduledEvents = g_slist_remove_link (ScheduledEvents, list);
131 g_slist_free_1 (list);
133 pthread_mutex_unlock (&eventsMutex);
139 static void InitModelInf (void)
146 GSM_DataClear(&data);
148 while ((error = SM_Functions(GOP_GetModel,&data,&xgnokii_statemachine)) != GE_NONE && i++ < 15)
151 if (error == GE_NONE)
153 g_free (phoneMonitor.phone.model);
154 phoneMonitor.phone.version = g_strdup (buf);
155 phoneMonitor.phone.model = GetModel (buf);
156 if (phoneMonitor.phone.model == NULL)
157 phoneMonitor.phone.model = g_strdup (_("unknown"));
159 phoneMonitor.supported = GetPhoneModel(buf)->flags;
164 while ((error = SM_Functions(GOP_GetRevision,&data,&xgnokii_statemachine)) != GE_NONE && i++ < 5)
167 if (error == GE_NONE)
169 g_free (phoneMonitor.phone.revision);
170 phoneMonitor.phone.revision = g_strdup (buf);
175 while ((error = SM_Functions(GOP_GetImei,&data,&xgnokii_statemachine)) != GE_NONE && i++ < 5)
178 if (error == GE_NONE)
180 g_free (phoneMonitor.phone.imei);
181 phoneMonitor.phone.imei = g_strdup (buf);
186 g_print ("Version: %s\n", phoneMonitor.phone.version);
187 g_print ("Model: %s\n", phoneMonitor.phone.model);
188 g_print ("IMEI: %s\n", phoneMonitor.phone.imei);
189 g_print ("Revision: %s\n", phoneMonitor.phone.revision);
194 static GSM_Error fbusinit(bool enable_monitoring)
197 GSM_Error error=GE_NOLINK;
198 GSM_ConnectionType connection=GCT_Serial;
200 if (!strcmp(xgnokiiConfig.connection, "infrared"))
201 connection = GCT_Infrared;
203 if (!strcmp(xgnokiiConfig.connection, "irda"))
204 connection = GCT_Irda;
206 if (!strcmp(xgnokiiConfig.connection, "tcp"))
207 connection = GCT_TCP;
209 /* Initialise the code for the GSM interface. */
211 if (error == GE_NOLINK)
212 error = GSM_Initialise (xgnokiiConfig.model, xgnokiiConfig.port,
213 xgnokiiConfig.initlength, connection, NULL /*RLP_DisplayF96Frame*/, &xgnokii_statemachine);
216 g_print ("fbusinit: error %d\n", error);
219 if (error != GE_NONE) {
220 g_print (_("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
221 /* FIXME: should popup some message... */
225 while (count++ < 40 && *GSM_LinkOK == false)
228 g_print("After usleep. GSM_LinkOK: %d\n", *GSM_LinkOK);
231 if (*GSM_LinkOK != true) {
240 void GUI_InitPhoneMonitor (void)
242 phoneMonitor.phone.model = g_strdup (_("unknown"));
243 phoneMonitor.phone.version = phoneMonitor.phone.model;
244 phoneMonitor.phone.revision = g_strdup (_("unknown"));
245 phoneMonitor.phone.imei = g_strdup (_("unknown"));
246 phoneMonitor.supported = 0;
247 phoneMonitor.rfLevel = phoneMonitor.batteryLevel = -1;
248 phoneMonitor.powerSource = GPS_BATTERY;
249 phoneMonitor.working = NULL;
250 phoneMonitor.alarm = FALSE;
251 phoneMonitor.sms.unRead = phoneMonitor.sms.used = phoneMonitor.sms.slots = 0;
252 phoneMonitor.sms.messages = NULL;
253 phoneMonitor.call.callInProgress = CS_Idle;
254 *phoneMonitor.call.callNum = '\0';
255 phoneMonitor.netmonitor.number = 0;
256 *phoneMonitor.netmonitor.screen = *phoneMonitor.netmonitor.screen3 =
257 *phoneMonitor.netmonitor.screen4 = *phoneMonitor.netmonitor.screen5 = '\0';
258 pthread_mutex_init (&memoryMutex, NULL);
259 pthread_cond_init (&memoryCond, NULL);
260 pthread_mutex_init (&calendarMutex, NULL);
261 pthread_cond_init (&calendarCond, NULL);
262 pthread_mutex_init (&smsMutex, NULL);
263 pthread_mutex_init (&sendSMSMutex, NULL);
264 pthread_cond_init (&sendSMSCond, NULL);
265 pthread_mutex_init (&saveSMSMutex, NULL);
266 pthread_cond_init (&saveSMSCond, NULL);
267 pthread_mutex_init (&callMutex, NULL);
268 pthread_mutex_init (&eventsMutex, NULL);
269 pthread_mutex_init (&callMutex, NULL);
270 pthread_mutex_init (&netMonMutex, NULL);
271 pthread_mutex_init (&speedDialMutex, NULL);
272 pthread_cond_init (&speedDialCond, NULL);
273 pthread_mutex_init (&callerGroupMutex, NULL);
274 pthread_cond_init (&callerGroupCond, NULL);
275 pthread_mutex_init (&smsCenterMutex, NULL);
276 pthread_cond_init (&smsCenterCond, NULL);
277 pthread_mutex_init (&getBitmapMutex, NULL);
278 pthread_cond_init (&getBitmapCond, NULL);
279 pthread_mutex_init (&setBitmapMutex, NULL);
280 pthread_cond_init (&setBitmapCond, NULL);
281 pthread_mutex_init (&getNetworkInfoMutex, NULL);
282 pthread_cond_init (&getNetworkInfoCond, NULL);
286 static inline void FreeElement (gpointer data, gpointer userData)
288 g_free ((GSM_SMSMessage *) data);
292 static inline void FreeArray (GSList **array)
296 g_slist_foreach (*array, FreeElement, NULL);
297 g_slist_free (*array);
303 static void RefreshSMS (const gint slots)
311 g_print ("RefreshSMS is running...\n");
314 pthread_mutex_lock (&smsMutex);
315 FreeArray (&(phoneMonitor.sms.messages));
316 phoneMonitor.sms.used = 0;
317 pthread_mutex_unlock (&smsMutex);
319 for (i=1; i<=slots; i++)
322 GSM_DataClear(&gdat);
323 msg = g_malloc (sizeof (GSM_SMSMessage));
324 msg->MemoryType = GMT_SM;
326 gdat.SMSMessage = msg;
328 if ((error = SM_Functions(GOP_GetSMS, &gdat, &xgnokii_statemachine)) == GE_NONE)
330 pthread_mutex_lock (&smsMutex);
331 phoneMonitor.sms.messages = g_slist_append (phoneMonitor.sms.messages, msg);
332 phoneMonitor.sms.used++;
333 if (msg->Type == GST_MT && msg->Status == GSS_NOTSENTREAD)
335 pthread_mutex_unlock (&smsMutex);
337 else if (error == GE_INVALIDSMSLOCATION) /* All positions are readed */
345 /* FIXME: Why is any delay here?
347 /* usleep (750000); */
349 /* Update it after the whole run as otherwise "Refreshing SMSes..."
350 * would collide with "Short Message received" message.
352 phoneMonitor.sms.unRead = unread;
356 static gint A_GetMemoryStatus (gpointer data)
359 D_MemoryStatus *ms = (D_MemoryStatus *) data;
362 error = ms->status = GE_UNKNOWN;
366 GSM_DataClear(&gdat);
367 pthread_mutex_lock (&memoryMutex);
368 gdat.MemoryStatus=&(ms->memoryStatus);
369 error = ms->status = SM_Functions(GOP_GetMemoryStatus,&gdat,&xgnokii_statemachine);
370 pthread_cond_signal (&memoryCond);
371 pthread_mutex_unlock (&memoryMutex);
378 static gint A_GetMemoryLocation (gpointer data)
381 D_MemoryLocation *ml = (D_MemoryLocation *) data;
384 error = ml->status = GE_UNKNOWN;
388 GSM_DataClear(&gdat);
389 pthread_mutex_lock (&memoryMutex);
390 gdat.PhonebookEntry=(ml->entry);
391 error = ml->status = SM_Functions(GOP_ReadPhonebook,&gdat,&xgnokii_statemachine);
392 pthread_cond_signal (&memoryCond);
393 pthread_mutex_unlock (&memoryMutex);
400 static gint A_GetMemoryLocationAll (gpointer data)
402 GSM_PhonebookEntry entry;
404 D_MemoryLocationAll *mla = (D_MemoryLocationAll *) data;
408 error = mla->status = GE_NONE;
409 entry.MemoryType = mla->type;
410 GSM_DataClear(&gdat);
411 gdat.PhonebookEntry=&entry;
413 pthread_mutex_lock (&memoryMutex);
414 for (i = mla->min; i <= mla->max; i++)
417 error = SM_Functions(GOP_ReadPhonebook,&gdat,&xgnokii_statemachine);
418 if (error != GE_NONE && error!=GE_INVALIDPHBOOKLOCATION)
422 while (error != GE_NONE)
424 g_print (_("%s: line %d: Can't get memory entry number %d from memory %d! %d\n"),
425 __FILE__, __LINE__, i, entry.MemoryType, error);
430 pthread_cond_signal (&memoryCond);
431 pthread_mutex_unlock (&memoryMutex);
435 error = SM_Functions(GOP_ReadPhonebook,&gdat,&xgnokii_statemachine);
440 /* If the phonebook location was invalid - just fill up the rest */
441 /* This works on a 7110 anyway...*/
443 if (error==GE_INVALIDPHBOOKLOCATION) {
447 for (i = mla->min; i <= mla->max; i++) {
448 error = mla->InsertEntry (&entry);
449 if (error != GE_NONE) break;
453 error = mla->InsertEntry (&entry);
454 if (error != GE_NONE)
458 pthread_cond_signal (&memoryCond);
459 pthread_mutex_unlock (&memoryMutex);
464 static gint A_WriteMemoryLocation (gpointer data)
467 D_MemoryLocation *ml = (D_MemoryLocation *) data;
470 error = ml->status = GE_UNKNOWN;
472 GSM_DataClear(&gdat);
473 gdat.PhonebookEntry=(ml->entry);
477 pthread_mutex_lock (&memoryMutex);
478 error = ml->status = SM_Functions(GOP_WritePhonebook,&gdat,&xgnokii_statemachine);
479 pthread_cond_signal (&memoryCond);
480 pthread_mutex_unlock (&memoryMutex);
487 static gint A_WriteMemoryLocationAll (gpointer data)
489 /* GSM_PhonebookEntry entry; */
491 D_MemoryLocationAll *mla = (D_MemoryLocationAll *) data;
494 error = mla->status = GE_NONE;
495 /* entry.MemoryType = mla->type;
497 pthread_mutex_lock (&memoryMutex);
498 for (i = mla->min; i <= mla->max; i++)
501 error = GSM->GetMemoryLocation (&entry);
502 if (error != GE_NONE)
506 while (error != GE_NONE)
508 g_print (_("%s: line %d: Can't get memory entry number %d from memory %d! %d\n"),
509 __FILE__, __LINE__, i, entry.MemoryType, error);
514 pthread_cond_signal (&memoryCond);
515 pthread_mutex_unlock (&memoryMutex);
519 error = GSM->GetMemoryLocation (&entry);
523 error = mla->InsertEntry (&entry);
524 if (error != GE_NONE)
528 pthread_cond_signal (&memoryCond);
529 pthread_mutex_unlock (&memoryMutex); */
534 static gint A_GetCalendarNote (gpointer data)
537 D_CalendarNote *cn = (D_CalendarNote *) data;
539 error = cn->status = GE_UNKNOWN;
543 pthread_mutex_lock (&calendarMutex);
544 error = cn->status = GSM->GetCalendarNote (cn->entry);
545 pthread_cond_signal (&calendarCond);
546 pthread_mutex_unlock (&calendarMutex);
553 static gint A_GetCalendarNoteAll (gpointer data)
555 GSM_CalendarNote entry;
556 D_CalendarNoteAll *cna = (D_CalendarNoteAll *) data;
560 pthread_mutex_lock (&calendarMutex);
563 entry.Location = i++;
565 if ((e = GSM->GetCalendarNote (&entry)) != GE_NONE)
568 if (cna->InsertEntry (&entry) != GE_NONE)
572 pthread_mutex_unlock (&calendarMutex);
574 if (e == GE_INVALIDCALNOTELOCATION)
581 static gint A_WriteCalendarNote (gpointer data)
584 D_CalendarNote *cn = (D_CalendarNote *) data;
586 error = cn->status = GE_UNKNOWN;
590 pthread_mutex_lock (&calendarMutex);
591 error = cn->status = GSM->WriteCalendarNote (cn->entry);
592 pthread_cond_signal (&calendarCond);
593 pthread_mutex_unlock (&calendarMutex);
600 static gint A_DeleteCalendarNote (gpointer data)
602 GSM_CalendarNote *note = (GSM_CalendarNote *) data;
603 GSM_Error error = GE_UNKNOWN;
607 error = GSM->DeleteCalendarNote (note);
614 static gint A_GetCallerGroup (gpointer data)
618 D_CallerGroup *cg = (D_CallerGroup *) data;
621 error = cg->status = GE_UNKNOWN;
625 bitmap.type = GSM_CallerLogo;
626 bitmap.number = cg->number;
628 pthread_mutex_lock (&callerGroupMutex);
629 GSM_DataClear(&gdat);
631 error = cg->status = SM_Functions(GOP_GetBitmap,&gdat,&xgnokii_statemachine);
632 strncpy (cg->text, bitmap.text, 256);
633 cg->text[255] = '\0';
634 pthread_cond_signal (&callerGroupCond);
635 pthread_mutex_unlock (&callerGroupMutex);
642 static gint A_SendCallerGroup (gpointer data)
645 D_CallerGroup *cg = (D_CallerGroup *) data;
651 bitmap.type = GSM_CallerLogo;
652 bitmap.number = cg->number;
653 if ((error = GSM->GetBitmap (&bitmap)) != GE_NONE)
658 strncpy (bitmap.text, cg->text, 256);
659 bitmap.text[255] = '\0';
661 return (GSM->SetBitmap (&bitmap));
665 static gint A_GetSMSCenter (gpointer data)
667 D_SMSCenter *c = (D_SMSCenter *) data;
670 error = c->status = GE_UNKNOWN;
673 pthread_mutex_lock (&smsCenterMutex);
674 error = c->status = GSM->GetSMSCenter (c->center);
675 pthread_cond_signal (&smsCenterCond);
676 pthread_mutex_unlock (&smsCenterMutex);
683 static gint A_SetSMSCenter (gpointer data)
685 D_SMSCenter *c = (D_SMSCenter *) data;
688 error = c->status = GE_UNKNOWN;
691 //pthread_mutex_lock (&smsCenterMutex);
692 error = c->status = GSM->SetSMSCenter (c->center);
694 //pthread_cond_signal (&smsCenterCond);
695 //pthread_mutex_unlock (&smsCenterMutex);
702 static gint A_SendSMSMessage (gpointer data)
704 D_SMSMessage *d = (D_SMSMessage *) data;
707 error = d->status = GE_UNKNOWN;
710 pthread_mutex_lock (&sendSMSMutex);
711 error = d->status = GSM->SendSMSMessage (d->sms);
712 pthread_cond_signal (&sendSMSCond);
713 pthread_mutex_unlock (&sendSMSMutex);
716 if (d->status == GE_SMSSENDOK)
723 static gint A_SaveSMSMessage (gpointer data)
725 D_SMSMessage *d = (D_SMSMessage *) data;
728 error = d->status = GE_UNKNOWN;
731 pthread_mutex_lock (&saveSMSMutex);
732 error = d->status = GSM->SaveSMSMessage (d->sms);
733 pthread_cond_signal (&saveSMSCond);
734 pthread_mutex_unlock (&saveSMSMutex);
741 static gint A_DeleteSMSMessage (gpointer data)
743 GSM_SMSMessage *sms = (GSM_SMSMessage *) data;
744 GSM_Error error = GE_UNKNOWN;
749 GSM_DataClear(&gdat);
750 gdat.SMSMessage = sms;
751 error = SM_Functions(GOP_DeleteSMS, &gdat, &xgnokii_statemachine);
759 static gint A_GetSpeedDial (gpointer data)
761 D_SpeedDial *d = (D_SpeedDial *) data;
764 error = d->status = GE_UNKNOWN;
768 pthread_mutex_lock (&speedDialMutex);
769 error = d->status = GSM->GetSpeedDial (&(d->entry));
770 pthread_cond_signal (&speedDialCond);
771 pthread_mutex_unlock (&speedDialMutex);
778 static gint A_SendSpeedDial (gpointer data)
780 D_SpeedDial *d = (D_SpeedDial *) data;
783 error = d->status = GE_UNKNOWN;
787 //pthread_mutex_lock (&speedDialMutex);
788 error = d->status = GSM->SetSpeedDial (&(d->entry));
790 //pthread_cond_signal (&speedDialCond);
791 //pthread_mutex_unlock (&speedDialMutex);
798 static gint A_SendDTMF (gpointer data)
800 gchar *buf = (gchar *) data;
801 GSM_Error error = GE_UNKNOWN;
805 error = GSM->SendDTMF (buf);
813 static gint A_NetMonOnOff (gpointer data)
816 gint mode = GPOINTER_TO_INT (data);
817 GSM_Error error = GE_UNKNOWN;
820 error = GSM->NetMonitor (0xf3, screen);
822 error = GSM->NetMonitor (0xf1, screen);
828 static gint A_NetMonitor (gpointer data)
830 gint number = GPOINTER_TO_INT (data);
833 phoneMonitor.netmonitor.number = 0;
835 phoneMonitor.netmonitor.number = number;
841 static gint A_DialVoice (gpointer data)
843 gchar *number = (gchar *) data;
844 GSM_Error error = GE_UNKNOWN;
848 error = GSM->DialVoice (number);
856 static gint A_GetAlarm (gpointer data)
858 D_Alarm *a = (D_Alarm *) data;
865 a->status = GE_UNKNOWN;
866 pthread_mutex_lock (&alarmMutex);
867 error = a->status = GSM->GetAlarm (0, &(a->time));
868 pthread_cond_signal (&alarmCond);
869 pthread_mutex_unlock (&alarmMutex);
876 static gint A_SetAlarm (gpointer data)
878 D_Alarm *a = (D_Alarm *) data;
881 error = a->status = GE_UNKNOWN;
885 error = a->status = GSM->SetAlarm (0, &(a->time));
893 static gint A_SendKeyStroke (gpointer data)
895 gchar *buf = (gchar *) data;
900 FB61_TX_SendMessage(0x07, 0x0c, buf);
908 static gint A_GetBitmap(gpointer data) {
910 D_Bitmap *d = (D_Bitmap *)data;
913 GSM_DataClear(&gdat);
914 pthread_mutex_lock(&getBitmapMutex);
915 gdat.Bitmap=d->bitmap;
916 error = d->status = SM_Functions(GOP_GetBitmap,&gdat,&xgnokii_statemachine);
917 pthread_cond_signal(&getBitmapCond);
918 pthread_mutex_unlock(&getBitmapMutex);
922 static gint A_SetBitmap(gpointer data) {
924 D_Bitmap *d = (D_Bitmap *)data;
928 GSM_DataClear(&gdat);
929 pthread_mutex_lock(&setBitmapMutex);
930 if (d->bitmap->type == GSM_CallerLogo) {
931 bitmap.type = d->bitmap->type;
932 bitmap.number = d->bitmap->number;
934 error = d->status = SM_Functions(GOP_GetBitmap,&gdat,&xgnokii_statemachine);
935 if (error == GE_NONE) {
936 strncpy(d->bitmap->text,bitmap.text,sizeof(bitmap.text));
937 d->bitmap->ringtone = bitmap.ringtone;
938 gdat.Bitmap=d->bitmap;
939 error = d->status = SM_Functions(GOP_SetBitmap,&gdat,&xgnokii_statemachine);
942 gdat.Bitmap=d->bitmap;
943 error = d->status = SM_Functions(GOP_SetBitmap,&gdat,&xgnokii_statemachine);
945 pthread_cond_signal(&setBitmapCond);
946 pthread_mutex_unlock(&setBitmapMutex);
950 static gint A_GetNetworkInfo(gpointer data) {
952 D_NetworkInfo *d = (D_NetworkInfo *)data;
955 GSM_DataClear(&gdat);
957 pthread_mutex_lock(&getNetworkInfoMutex);
958 gdat.NetworkInfo=d->info;
959 error = d->status = SM_Functions(GOP_GetNetworkInfo,&gdat,&xgnokii_statemachine);
960 pthread_cond_signal(&getNetworkInfoCond);
961 pthread_mutex_unlock(&getNetworkInfoMutex);
965 static gint A_Exit (gpointer data)
968 return (0); /* just to be proper */
972 gint (*DoAction[])(gpointer) = {
975 A_GetMemoryLocationAll,
976 A_WriteMemoryLocation,
977 A_WriteMemoryLocationAll,
979 A_GetCalendarNoteAll,
981 A_DeleteCalendarNote,
1005 void *GUI_Connect (void *a)
1007 /* Define required unit types for RF and Battery level meters. */
1008 GSM_RFUnits rf_units = GRF_Percentage;
1009 GSM_BatteryUnits batt_units = GBU_Percentage;
1012 GSM_SMSStatus SMSStatus = {0, 0, 0};
1013 gchar number[INCALL_NUMBER_LENGTH];
1019 GSM_DataClear(&data);
1022 g_print ("Initializing connection...\n");
1025 phoneMonitor.working = _("Connecting...");
1026 while (fbusinit (true))
1030 g_print ("Phone connected. Starting monitoring...\n");
1035 data.RFLevel=&phoneMonitor.rfLevel;
1036 data.RFUnits=&rf_units;
1037 data.PowerSource=&phoneMonitor.powerSource;
1038 data.BatteryUnits=&batt_units;
1039 data.BatteryLevel=&phoneMonitor.batteryLevel;
1040 data.DateTime=&Alarm;
1041 data.SMSStatus=&SMSStatus;
1042 data.IncomingCallNr=number;
1046 phoneMonitor.working = NULL;
1048 /* FIXME - this loop goes mad on my 7110 - so I've put in a usleep */
1051 if (SM_Functions(GOP_GetRFLevel,&data,&xgnokii_statemachine) != GE_NONE)
1052 phoneMonitor.rfLevel = -1;
1054 if (rf_units == GRF_Arbitrary)
1055 phoneMonitor.rfLevel *= 25;
1057 if (SM_Functions(GOP_GetPowersource,&data,&xgnokii_statemachine) == GE_NONE
1058 && phoneMonitor.powerSource == GPS_ACDC)
1060 if (phoneMonitor.batteryLevel < 0 || phoneMonitor.batteryLevel > 100)
1061 phoneMonitor.batteryLevel = 100;
1064 if (SM_Functions(GOP_GetBatteryLevel,&data,&xgnokii_statemachine) != GE_NONE)
1065 phoneMonitor.batteryLevel = -1;
1066 if (batt_units == GBU_Arbitrary)
1067 phoneMonitor.batteryLevel *= 25;
1070 if (SM_Functions(GOP_GetAlarm,&data,&xgnokii_statemachine) == GE_NONE && Alarm.AlarmEnabled != 0)
1071 phoneMonitor.alarm = TRUE;
1073 phoneMonitor.alarm = FALSE;
1075 if (SM_Functions(GOP_GetSMSStatus,&data,&xgnokii_statemachine) == GE_NONE)
1077 /* Change of "UnRead" shouldn't be interesting - user may have read some of his
1078 * SMSes by the phone interface.
1080 if (phoneMonitor.sms.unRead != SMSStatus.UnRead ||
1081 phoneMonitor.sms.used != SMSStatus.Used ||
1082 phoneMonitor.sms.slots != SMSStatus.Slots) /* shouldn't change, just to be sure */
1084 /* We are primarily interested in SMSStatus.Slots so try to fix it up if it is broken
1086 if (SMSStatus.UnRead > SMSStatus.Used)
1087 SMSStatus.Used = SMSStatus.UnRead;
1088 if (SMSStatus.Used > SMSStatus.Slots)
1089 SMSStatus.Slots = SMSStatus.Used;
1090 phoneMonitor.sms.slots = SMSStatus.Slots; /* shouldn't change, just to be sure */
1091 /* phoneMonitor.sms.{unRead,used} will be updated by RefreshSMS()
1094 phoneMonitor.working = _("Refreshing SMSes...");
1095 RefreshSMS (SMSStatus.Slots);
1096 phoneMonitor.working = NULL;
1101 if (SM_Functions(GOP_GetIncomingCallNr,&data,&xgnokii_statemachine) == GE_NONE)
1104 g_print ("Call in progress: %s\n", phoneMonitor.call.callNum);
1107 GSM->GetDisplayStatus (&status);
1108 if (status & (1<<DS_Call_In_Progress))
1110 pthread_mutex_lock (&callMutex);
1111 phoneMonitor.call.callInProgress = CS_InProgress;
1112 pthread_mutex_unlock (&callMutex);
1116 pthread_mutex_lock (&callMutex);
1117 phoneMonitor.call.callInProgress = CS_Waiting;
1118 strncpy (phoneMonitor.call.callNum, number, INCALL_NUMBER_LENGTH);
1119 pthread_mutex_unlock (&callMutex);
1124 pthread_mutex_lock (&callMutex);
1125 phoneMonitor.call.callInProgress = CS_Idle;
1126 *phoneMonitor.call.callNum = '\0';
1127 pthread_mutex_unlock (&callMutex);
1130 pthread_mutex_lock (&netMonMutex);
1131 if (phoneMonitor.netmonitor.number)
1133 GSM->NetMonitor (phoneMonitor.netmonitor.number,
1134 phoneMonitor.netmonitor.screen);
1135 GSM->NetMonitor (3, phoneMonitor.netmonitor.screen3);
1136 GSM->NetMonitor (4, phoneMonitor.netmonitor.screen4);
1137 GSM->NetMonitor (5, phoneMonitor.netmonitor.screen5);
1141 *phoneMonitor.netmonitor.screen = *phoneMonitor.netmonitor.screen3 =
1142 *phoneMonitor.netmonitor.screen4 = *phoneMonitor.netmonitor.screen5 = '\0';
1144 pthread_mutex_unlock (&netMonMutex);
1146 while ((event = RemoveEvent ()) != NULL)
1149 g_print ("Processing Event: %d\n", event->event);
1151 phoneMonitor.working = _("Working...");
1152 if (event->event <= Event_Exit)
1153 if ((error = DoAction[event->event] (event->data)) != GE_NONE)
1154 g_print (_("Event %d failed with return code %d!\n"), event->event, error);