Gammu internals  1.38.0
nfuncold.c
Go to the documentation of this file.
1 /* (c) 2003 by Marcin Wiacek */
2 
3 #include <string.h> /* memcpy only */
4 #include <stdio.h>
5 #include <ctype.h>
6 #include <time.h>
7 
8 #include "../../misc/coding/coding.h"
9 #include "../../gsmstate.h"
10 #include "../../service/gsmcal.h"
11 #include "../pfunc.h"
12 #include "nfunc.h"
13 
14 #ifdef DEBUG
15 static void N71_65_GetCalendarAlarm(GSM_StateMachine *s, unsigned char *buffer, GSM_CalendarEntry *entry, int DT, GSM_Phone_Data *Data)
16 {
17  unsigned long diff;
18 
19  if (buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0xff && buffer[3] == 0xff) {
20  smprintf(s, "No alarm\n");
21  } else {
22  memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[DT].Date,sizeof(GSM_DateTime));
23 
24  diff = ((unsigned int)buffer[0]) << 24;
25  diff += ((unsigned int)buffer[1]) << 16;
26  diff += ((unsigned int)buffer[2]) << 8;
27  diff += buffer[3];
28  smprintf(s, " Difference : %li seconds\n", diff);
29 
30  switch (entry->Type) {
31  case GSM_CAL_MEETING:
32  GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
33  break;
34  case GSM_CAL_MEMO:
36  GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
37  break;
38  }
39  case GSM_CAL_CALL:
41  GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
42  break;
43  }
44  default:
45  GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 1);
46  }
47  smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n",
48  entry->Entries[entry->EntriesNum].Date.Day, entry->Entries[entry->EntriesNum].Date.Month,
49  entry->Entries[entry->EntriesNum].Date.Year, entry->Entries[entry->EntriesNum].Date.Hour,
50  entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second);
51 
53  if (entry->Type == GSM_CAL_BIRTHDAY) {
54  if (buffer[14]!=0x00) entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
55  smprintf(s, "Alarm type : Silent\n");
56  }
57 
58  entry->EntriesNum++;
59  }
60 }
61 
62 /* method 2 */
63 GSM_Error N71_65_ReplyGetNextCalendar2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
64 {
65  GSM_DateTime Date;
66  GSM_CalendarEntry *entry = s->Phone.Data.Cal;
67  GSM_Phone_Data *Data = &s->Phone.Data;
68  int i;
69  unsigned long diff;
70 
71  smprintf(s, "Calendar note received method 2\n");
72 
73  if (msg->Length < 10) return ERR_EMPTY;
74 
75  entry->Location = msg->Buffer[4]*256 + msg->Buffer[5];
76  smprintf(s, "Location: %i\n",entry->Location);
77 
78  /* Not birthday */
79  if (msg->Buffer[21] != 0x04) {
80  Date.Year = 2030; Date.Month = 01; Date.Day = 01;
81  Date.Hour = 00; Date.Minute = 00; Date.Second = 00;
82  } else {
83  Date.Year = 2029; Date.Month = 12; Date.Day = 31;
84  Date.Hour = 22; Date.Minute = 59; Date.Second = 58;
85  }
86  diff = ((unsigned int)msg->Buffer[12]) << 24;
87  diff += ((unsigned int)msg->Buffer[13]) << 16;
88  diff += ((unsigned int)msg->Buffer[14]) << 8;
89  diff += msg->Buffer[15];
90  smprintf(s, " Difference : %li seconds\n", diff);
91  GetTimeDifference(diff, &Date, TRUE, 1);
92  Date.Year += 20;
94 
95  smprintf(s, "Note type %02x: ",msg->Buffer[21]);
96  switch (msg->Buffer[21]) {
97  case 0x01:
98  case 0x08:
99  if (msg->Buffer[21] == 0x01) {
100  smprintf(s, "Meeting or Reminder\n");
101  entry->Type = GSM_CAL_MEETING;
102  } else {
103  smprintf(s, "Memo\n");
104  Data->Cal->Type = GSM_CAL_MEMO;
105  }
106 
107  memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
108  entry->EntriesNum++;
109 
110  N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
111  GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);
112 
113  memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30, msg->Buffer[28]*2);
114  entry->Entries[entry->EntriesNum].Text[msg->Buffer[28]*2] = 0;
115  entry->Entries[entry->EntriesNum].Text[msg->Buffer[28]*2+1] = 0;
116  entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
117  break;
118  case 0x02:
119  smprintf(s, "Call\n");
120  entry->Type = GSM_CAL_CALL;
121 
122  memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
123  entry->EntriesNum++;
124 
125  N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
126  GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);
127 
128  i = msg->Buffer[28] * 2;
129  if (i!=0) {
130  memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30, i);
131  entry->Entries[entry->EntriesNum].Text[i] = 0;
132  entry->Entries[entry->EntriesNum].Text[i+1] = 0;
133  entry->Entries[entry->EntriesNum].EntryType = CAL_PHONE;
134  smprintf(s, "Phone : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
135  entry->EntriesNum++;
136  }
137 
138  memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30+i, msg->Buffer[29]*2);
139  entry->Entries[entry->EntriesNum].Text[msg->Buffer[29]*2] = 0;
140  entry->Entries[entry->EntriesNum].Text[msg->Buffer[29]*2+1] = 0;
141  entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
142  break;
143  case 0x04:
144  smprintf(s, "Birthday\n");
145  Data->Cal->Type = GSM_CAL_BIRTHDAY;
146 
147  /* Year was set earlier */
148  entry->Entries[0].Date.Month = Date.Month;
149  entry->Entries[0].Date.Day = Date.Day;
150  entry->Entries[0].Date.Hour = 23;
151  entry->Entries[0].Date.Minute = 59;
152  entry->Entries[0].Date.Second = 58;
153  entry->EntriesNum++;
154 
155  N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
156  GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);
157 
158  /* Birthday year */
159  entry->Entries[0].Date.Year = msg->Buffer[28]*256 + msg->Buffer[29];
160  if (msg->Buffer[28] == 0xff && msg->Buffer[29] == 0xff) entry->Entries[0].Date.Year = 0;
161  smprintf(s, "Birthday date: %02i-%02i-%04i\n",
162  entry->Entries[0].Date.Day,entry->Entries[0].Date.Month,
163  entry->Entries[0].Date.Year);
164 
165  memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+32, msg->Buffer[31]*2);
166  entry->Entries[entry->EntriesNum].Text[msg->Buffer[31]*2] = 0;
167  entry->Entries[entry->EntriesNum].Text[msg->Buffer[31]*2+1] = 0;
168  entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
169  break;
170  default:
171  smprintf(s, "ERROR: unknown %i\n",msg->Buffer[6]);
172  return ERR_UNKNOWNRESPONSE;
173  }
174  smprintf(s, "Text : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
175  entry->EntriesNum++;
176  return ERR_NONE;
177 }
178 
179 /* method 2 */
180 /* Note: in known phones texts of notes cut to 50 chars */
181 GSM_Error N71_65_GetNextCalendar2(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, int *LastCalendarYear, int *LastCalendarPos)
182 {
183  GSM_Error error;
184  GSM_DateTime date_time;
185  unsigned char req[] = {N6110_FRAME_HEADER, 0x3e,
186  0xFF, 0xFE}; /* Location */
187 
188  if (start) {
189  /* We have to get current year. It's NOT written in frame for
190  * Birthday
191  */
192  error=s->Phone.Functions->GetDateTime(s,&date_time);
193  switch (error) {
194  case ERR_EMPTY:
195  case ERR_NOTIMPLEMENTED:
196  GSM_GetCurrentDateTime(&date_time);
197  break;
198  case ERR_NONE:
199  break;
200  default:
201  return error;
202  }
203  *LastCalendarYear = date_time.Year;
204 
205  /* First location at all */
206  req[4] = 0xFF;
207  req[5] = 0xFE;
208  } else {
209  req[4] = *LastCalendarPos / 256;
210  req[5] = *LastCalendarPos % 256;
211  }
212  Note->EntriesNum = 0;
213  Note->Entries[0].Date.Year = *LastCalendarYear;
214 
215  s->Phone.Data.Cal = Note;
216  smprintf(s, "Getting calendar note method 2\n");
217  error=GSM_WaitFor (s, req, 6, 0x13, 4, ID_GetCalendarNote);
218  *LastCalendarPos = Note->Location;
219  return error;
220 }
221 
222 #endif
223 
224 /* How should editor hadle tabs in this file? Add editor commands here.
225  * vim: noexpandtab sw=8 ts=8 sts=8:
226  */
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
void GetTimeDifference(unsigned long diff, GSM_DateTime *DT, gboolean Plus, int multi)
Definition: misc.c:247
#define N6110_FRAME_HEADER
Definition: ncommon.h:8
GSM_Error
Definition: gammu-error.h:23
GSM_Debug_Info di
Definition: gsmstate.h:1412
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
void GSM_GetCalendarRecurranceRepeat(GSM_Debug_Info *di, unsigned char *rec, unsigned char *endday, GSM_CalendarEntry *entry)
Definition: gsmcal.c:137
int gboolean
Definition: gammu-types.h:23
GSM_CalendarNoteType Type
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
GSM_Error GSM_WaitFor(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout, GSM_Phone_RequestID request)
Definition: gsmstate.c:1029
GSM_CalendarType EntryType
GSM_Error(* GetDateTime)(GSM_StateMachine *s, GSM_DateTime *date_time)
Definition: gsmstate.h:814
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_SubCalendarEntry Entries[GSM_CALENDAR_ENTRIES]
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
Definition: misc.c:184
gboolean GSM_IsPhoneFeatureAvailable(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1026
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
#define TRUE
Definition: gammu-types.h:28
unsigned char * Buffer
Definition: protocol.h:22
unsigned char Text[(GSM_MAX_CALENDAR_TEXT_LENGTH+1) *2]
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261
GSM_CalendarEntry * Cal
Definition: gsmstate.h:549