author | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
commit | 50ab40e1e02ad7c65c17a78d08116a808b1257aa (patch) (unidiff) | |
tree | 0d1939e2297fa7bbd8e1f2030f154463854164c6 /gammu/emb/common/phone/at/sonyeric.c | |
parent | cf8616f64f20e5448d4ff644f7cc15750cf3f85f (diff) | |
download | kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.zip kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.gz kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.bz2 |
updated to latest gammu version
Diffstat (limited to 'gammu/emb/common/phone/at/sonyeric.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/phone/at/sonyeric.c | 141 |
1 files changed, 125 insertions, 16 deletions
diff --git a/gammu/emb/common/phone/at/sonyeric.c b/gammu/emb/common/phone/at/sonyeric.c index 4b2670a..8eeb39b 100644 --- a/gammu/emb/common/phone/at/sonyeric.c +++ b/gammu/emb/common/phone/at/sonyeric.c | |||
@@ -1,48 +1,46 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | 1 | /* (c) 2003 by Marcin Wiacek */ |
2 | 2 | ||
3 | #include "../../gsmstate.h" | 3 | #include "../../gsmstate.h" |
4 | 4 | ||
5 | #ifdef GSM_ENABLE_ATGEN | 5 | #ifdef GSM_ENABLE_ATGEN |
6 | 6 | ||
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <time.h> | 8 | #include <time.h> |
9 | #include <ctype.h> | 9 | #include <ctype.h> |
10 | 10 | ||
11 | #include "../../gsmcomon.h" | 11 | #include "../../gsmcomon.h" |
12 | #include "../../misc/coding/coding.h" | 12 | #include "../../misc/coding/coding.h" |
13 | 13 | ||
14 | extern GSM_Reply_Function ATGENReplyFunctions[]; | 14 | #include "atgen.h" |
15 | extern GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *s); | 15 | #include "sonyeric.h" |
16 | 16 | ||
17 | #ifdef GSM_ENABLE_OBEXGEN | 17 | #ifdef GSM_ENABLE_OBEXGEN |
18 | 18 | ||
19 | extern GSM_Reply_Function OBEXGENReplyFunctions[]; | 19 | #include "../obex/obexgen.h" |
20 | extern GSM_Error OBEXGEN_GetFilePart(GSM_StateMachine *s, GSM_File *File); | ||
21 | extern GSM_Error OBEXGEN_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos); | ||
22 | extern GSM_Error OBEXGEN_Disconnect(GSM_StateMachine *s); | ||
23 | 20 | ||
24 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 21 | extern GSM_Reply_FunctionOBEXGENReplyFunctions[]; |
22 | extern GSM_Reply_FunctionATGENReplyFunctions[]; | ||
25 | 23 | ||
26 | static GSM_Error SONYERIC_SetOBEXMode(GSM_StateMachine *s) | 24 | static GSM_Error SONYERIC_SetOBEXMode(GSM_StateMachine *s) |
27 | { | 25 | { |
28 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 26 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
29 | GSM_Error error; | 27 | GSM_Error error; |
30 | 28 | ||
31 | if (Priv->OBEX) return ERR_NONE; | 29 | if (Priv->OBEX) return ERR_NONE; |
32 | 30 | ||
33 | dbgprintf ("Changing to OBEX\n"); | 31 | dbgprintf ("Changing to OBEX\n"); |
34 | 32 | ||
35 | error=GSM_WaitFor (s, "AT*EOBEX\r", 9, 0x00, 4, ID_SetOBEX); | 33 | error=GSM_WaitFor (s, "AT*EOBEX\r", 9, 0x00, 4, ID_SetOBEX); |
36 | if (error != ERR_NONE) return error; | 34 | if (error != ERR_NONE) return error; |
37 | 35 | ||
38 | error = s->Protocol.Functions->Terminate(s); | 36 | error = s->Protocol.Functions->Terminate(s); |
39 | if (error != ERR_NONE) return error; | 37 | if (error != ERR_NONE) return error; |
40 | 38 | ||
41 | s->Protocol.Functions = &OBEXProtocol; | 39 | s->Protocol.Functions = &OBEXProtocol; |
42 | error = s->Protocol.Functions->Initialise(s); | 40 | error = s->Protocol.Functions->Initialise(s); |
43 | if (error != ERR_NONE) { | 41 | if (error != ERR_NONE) { |
44 | s->Protocol.Functions = &ATProtocol; | 42 | s->Protocol.Functions = &ATProtocol; |
45 | return error; | 43 | return error; |
46 | } | 44 | } |
47 | strcpy(s->CurrentConfig->Model,"seobex"); | 45 | strcpy(s->CurrentConfig->Model,"seobex"); |
48 | s->Phone.Data.Priv.OBEXGEN.Service = 0; | 46 | s->Phone.Data.Priv.OBEXGEN.Service = 0; |
@@ -105,190 +103,190 @@ static GSM_Error SONYERIC_SetFile(GSM_StateMachine *s, unsigned char *FileName, | |||
105 | GSM_File File; | 103 | GSM_File File; |
106 | int Pos = 0; | 104 | int Pos = 0; |
107 | 105 | ||
108 | error = SONYERIC_SetOBEXMode(s); | 106 | error = SONYERIC_SetOBEXMode(s); |
109 | if (error != ERR_NONE) return error; | 107 | if (error != ERR_NONE) return error; |
110 | 108 | ||
111 | strcpy(File.ID_FullName,FileName); | 109 | strcpy(File.ID_FullName,FileName); |
112 | EncodeUnicode(File.Name,FileName,strlen(FileName)); | 110 | EncodeUnicode(File.Name,FileName,strlen(FileName)); |
113 | File.Used = Length; | 111 | File.Used = Length; |
114 | File.Buffer = malloc(Length); | 112 | File.Buffer = malloc(Length); |
115 | memcpy(File.Buffer,Buffer,Length); | 113 | memcpy(File.Buffer,Buffer,Length); |
116 | 114 | ||
117 | error = ERR_NONE; | 115 | error = ERR_NONE; |
118 | while (error == ERR_NONE) error = OBEXGEN_AddFilePart(s,&File,&Pos); | 116 | while (error == ERR_NONE) error = OBEXGEN_AddFilePart(s,&File,&Pos); |
119 | free(File.Buffer); | 117 | free(File.Buffer); |
120 | if (error != ERR_EMPTY) return error; | 118 | if (error != ERR_EMPTY) return error; |
121 | 119 | ||
122 | return SONYERIC_SetATMode(s); | 120 | return SONYERIC_SetATMode(s); |
123 | } | 121 | } |
124 | 122 | ||
125 | #endif | 123 | #endif |
126 | 124 | ||
127 | GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) | 125 | GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) |
128 | { | 126 | { |
129 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 127 | #ifdef GSM_ENABLE_OBEXGEN |
130 | GSM_Error error; | 128 | GSM_Error error; |
131 | GSM_ToDoEntry ToDo; | 129 | GSM_ToDoEntry ToDo; |
132 | int Pos, num, Loc; | 130 | int Pos, num, Loc; |
133 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 131 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
134 | 132 | ||
135 | if (start) { | 133 | if (start) { |
136 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | 134 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); |
137 | if (error != ERR_NONE) return error; | 135 | if (error != ERR_NONE) return error; |
138 | 136 | ||
139 | Note->Location = 1; | 137 | Note->Location = 1; |
140 | } else { | 138 | } else { |
141 | Note->Location++; | 139 | Note->Location++; |
142 | } | 140 | } |
143 | smprintf(s, "Getting calendar note %i\n",Note->Location); | 141 | smprintf(s, "Getting calendar note %i\n",Note->Location); |
144 | 142 | ||
145 | Loc = Note->Location; | 143 | Loc = Note->Location; |
146 | Pos = 0; | 144 | Pos = 0; |
147 | num = 0; | 145 | num = 0; |
148 | while (1) { | 146 | while (1) { |
149 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, Note, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | 147 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, Note, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); |
150 | if (error == ERR_EMPTY) break; | 148 | if (error == ERR_EMPTY) break; |
151 | if (error != ERR_NONE) return error; | 149 | if (error != ERR_NONE) return error; |
152 | if (Note->EntriesNum != 0) { | 150 | if (Note->EntriesNum != 0) { |
153 | num++; | 151 | num++; |
154 | if (num == Loc) return ERR_NONE; | 152 | if (num == Loc) return ERR_NONE; |
155 | } | 153 | } |
156 | } | 154 | } |
157 | return ERR_EMPTY; | 155 | return ERR_EMPTY; |
158 | #else | 156 | #else |
159 | return ERR_SOURCENOTAVAILABLE; | 157 | return ERR_SOURCENOTAVAILABLE; |
160 | #endif | 158 | #endif |
161 | } | 159 | } |
162 | 160 | ||
163 | GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start) | 161 | GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start) |
164 | { | 162 | { |
165 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 163 | #ifdef GSM_ENABLE_OBEXGEN |
166 | GSM_Error error; | 164 | GSM_Error error; |
167 | GSM_CalendarEntryCalendar; | 165 | GSM_CalendarEntryCalendar; |
168 | int Pos, num, Loc; | 166 | int Pos, num, Loc; |
169 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 167 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
170 | 168 | ||
171 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | 169 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; |
172 | 170 | ||
173 | if (start) { | 171 | if (start) { |
174 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | 172 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); |
175 | if (error != ERR_NONE) return error; | 173 | if (error != ERR_NONE) return error; |
176 | 174 | ||
177 | ToDo->Location = 1; | 175 | ToDo->Location = 1; |
178 | } else { | 176 | } else { |
179 | ToDo->Location++; | 177 | ToDo->Location++; |
180 | } | 178 | } |
181 | smprintf(s,"Getting ToDo %i\n",ToDo->Location); | 179 | smprintf(s,"Getting ToDo %i\n",ToDo->Location); |
182 | 180 | ||
183 | Loc = ToDo->Location; | 181 | Loc = ToDo->Location; |
184 | Pos = 0; | 182 | Pos = 0; |
185 | num = 0; | 183 | num = 0; |
186 | while (1) { | 184 | while (1) { |
187 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | 185 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); |
188 | if (error == ERR_EMPTY) break; | 186 | if (error == ERR_EMPTY) break; |
189 | if (error != ERR_NONE) return error; | 187 | if (error != ERR_NONE) return error; |
190 | if (ToDo->EntriesNum != 0) { | 188 | if (ToDo->EntriesNum != 0) { |
191 | num++; | 189 | num++; |
192 | if (num == Loc) return ERR_NONE; | 190 | if (num == Loc) return ERR_NONE; |
193 | } | 191 | } |
194 | } | 192 | } |
195 | 193 | ||
196 | return ERR_EMPTY; | 194 | return ERR_EMPTY; |
197 | #else | 195 | #else |
198 | return ERR_SOURCENOTAVAILABLE; | 196 | return ERR_SOURCENOTAVAILABLE; |
199 | #endif | 197 | #endif |
200 | } | 198 | } |
201 | 199 | ||
202 | GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status) | 200 | GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status) |
203 | { | 201 | { |
204 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 202 | #ifdef GSM_ENABLE_OBEXGEN |
205 | GSM_Error error; | 203 | GSM_Error error; |
206 | GSM_ToDoEntry ToDo; | 204 | GSM_ToDoEntry ToDo; |
207 | GSM_CalendarEntry Calendar; | 205 | GSM_CalendarEntry Calendar; |
208 | int Pos; | 206 | int Pos; |
209 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 207 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
210 | 208 | ||
211 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | 209 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; |
212 | 210 | ||
213 | smprintf(s,"Getting ToDo status\n"); | 211 | smprintf(s,"Getting ToDo status\n"); |
214 | 212 | ||
215 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | 213 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); |
216 | if (error != ERR_NONE) return error; | 214 | if (error != ERR_NONE) return error; |
217 | 215 | ||
218 | status->Used = 0; | 216 | status->Used = 0; |
219 | Pos = 0; | 217 | Pos = 0; |
220 | while (1) { | 218 | while (1) { |
221 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | 219 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); |
222 | if (error == ERR_EMPTY) break; | 220 | if (error == ERR_EMPTY) break; |
223 | if (error != ERR_NONE) return error; | 221 | if (error != ERR_NONE) return error; |
224 | if (ToDo.EntriesNum != 0) status->Used++; | 222 | if (ToDo.EntriesNum != 0) status->Used++; |
225 | } | 223 | } |
226 | 224 | ||
227 | return ERR_NONE; | 225 | return ERR_NONE; |
228 | #else | 226 | #else |
229 | return ERR_SOURCENOTAVAILABLE; | 227 | return ERR_SOURCENOTAVAILABLE; |
230 | #endif | 228 | #endif |
231 | } | 229 | } |
232 | 230 | ||
233 | GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) | 231 | GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) |
234 | { | 232 | { |
235 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 233 | #ifdef GSM_ENABLE_OBEXGEN |
236 | unsigned char req[5000]; | 234 | unsigned char req[5000]; |
237 | int size=0; | 235 | int size=0; |
238 | 236 | ||
239 | smprintf(s,"Adding calendar note\n"); | 237 | smprintf(s,"Adding calendar note\n"); |
240 | 238 | ||
241 | GSM_EncodeVCALENDAR(req,&size,Note,true,SonyEricsson_VCalendar); | 239 | GSM_EncodeVCALENDAR(req,&size,Note,true,SonyEricsson_VCalendar); |
242 | 240 | ||
243 | return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); | 241 | return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); |
244 | #else | 242 | #else |
245 | return ERR_SOURCENOTAVAILABLE; | 243 | return ERR_SOURCENOTAVAILABLE; |
246 | #endif | 244 | #endif |
247 | } | 245 | } |
248 | 246 | ||
249 | GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) | 247 | GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) |
250 | { | 248 | { |
251 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 249 | #ifdef GSM_ENABLE_OBEXGEN |
252 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 250 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
253 | unsigned char req[5000]; | 251 | unsigned char req[5000]; |
254 | int size=0; | 252 | int size=0; |
255 | 253 | ||
256 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | 254 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; |
257 | 255 | ||
258 | smprintf(s,"Adding ToDo\n"); | 256 | smprintf(s,"Adding ToDo\n"); |
259 | 257 | ||
260 | GSM_EncodeVTODO(req,&size,ToDo,true,SonyEricsson_VToDo); | 258 | GSM_EncodeVTODO(req,&size,ToDo,true,SonyEricsson_VToDo); |
261 | 259 | ||
262 | return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); | 260 | return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); |
263 | #else | 261 | #else |
264 | return ERR_SOURCENOTAVAILABLE; | 262 | return ERR_SOURCENOTAVAILABLE; |
265 | #endif | 263 | #endif |
266 | } | 264 | } |
267 | 265 | ||
268 | GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s) | 266 | GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s) |
269 | { | 267 | { |
270 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 268 | #ifdef GSM_ENABLE_OBEXGEN |
271 | GSM_Error error; | 269 | GSM_Error error; |
272 | int Pos,Level = 0,Used; | 270 | int Pos,Level = 0,Used; |
273 | unsigned char *Buf; | 271 | unsigned char *Buf; |
274 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 272 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
275 | unsigned char Line[2000]; | 273 | unsigned char Line[2000]; |
276 | 274 | ||
277 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | 275 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; |
278 | 276 | ||
279 | smprintf(s,"Deleting all ToDo\n"); | 277 | smprintf(s,"Deleting all ToDo\n"); |
280 | 278 | ||
281 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | 279 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); |
282 | if (error != ERR_NONE) return error; | 280 | if (error != ERR_NONE) return error; |
283 | 281 | ||
284 | Pos = 0; | 282 | Pos = 0; |
285 | Buf = NULL; | 283 | Buf = NULL; |
286 | Used = 0; | 284 | Used = 0; |
287 | while (1) { | 285 | while (1) { |
288 | MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); | 286 | MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); |
289 | if (strlen(Line) == 0) break; | 287 | if (strlen(Line) == 0) break; |
290 | dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); | 288 | dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); |
291 | switch (Level) { | 289 | switch (Level) { |
292 | case 0: | 290 | case 0: |
293 | if (strstr(Line,"BEGIN:VTODO")) { | 291 | if (strstr(Line,"BEGIN:VTODO")) { |
294 | Level = 2; | 292 | Level = 2; |
@@ -298,49 +296,49 @@ GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s) | |||
298 | strcpy(Buf+Used,Line); | 296 | strcpy(Buf+Used,Line); |
299 | Used=Used+strlen(Line)+3; | 297 | Used=Used+strlen(Line)+3; |
300 | Buf[Used-3] = 13; | 298 | Buf[Used-3] = 13; |
301 | Buf[Used-2] = 10; | 299 | Buf[Used-2] = 10; |
302 | Buf[Used-1] = 0x00; | 300 | Buf[Used-1] = 0x00; |
303 | break; | 301 | break; |
304 | case 2: /* ToDo note */ | 302 | case 2: /* ToDo note */ |
305 | if (strstr(Line,"END:VTODO")) { | 303 | if (strstr(Line,"END:VTODO")) { |
306 | Level = 0; | 304 | Level = 0; |
307 | } | 305 | } |
308 | break; | 306 | break; |
309 | } | 307 | } |
310 | } | 308 | } |
311 | 309 | ||
312 | error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); | 310 | error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); |
313 | //if (Buf != NULL) free(Buf); | 311 | //if (Buf != NULL) free(Buf); |
314 | return error; | 312 | return error; |
315 | #else | 313 | #else |
316 | return ERR_SOURCENOTAVAILABLE; | 314 | return ERR_SOURCENOTAVAILABLE; |
317 | #endif | 315 | #endif |
318 | } | 316 | } |
319 | 317 | ||
320 | GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) | 318 | GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) |
321 | { | 319 | { |
322 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 320 | #ifdef GSM_ENABLE_OBEXGEN |
323 | GSM_Error error; | 321 | GSM_Error error; |
324 | int Pos,Level = 0,Loc=0,Used; | 322 | int Pos,Level = 0,Loc=0,Used; |
325 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 323 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
326 | unsigned char Line[2000]; | 324 | unsigned char Line[2000]; |
327 | unsigned char *Buf; | 325 | unsigned char *Buf; |
328 | 326 | ||
329 | smprintf(s, "Deleting calendar note %i\n",Note->Location); | 327 | smprintf(s, "Deleting calendar note %i\n",Note->Location); |
330 | 328 | ||
331 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | 329 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); |
332 | if (error != ERR_NONE) return error; | 330 | if (error != ERR_NONE) return error; |
333 | 331 | ||
334 | Pos = 0; | 332 | Pos = 0; |
335 | Buf = NULL; | 333 | Buf = NULL; |
336 | Used = 0; | 334 | Used = 0; |
337 | while (1) { | 335 | while (1) { |
338 | MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); | 336 | MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); |
339 | if (strlen(Line) == 0) break; | 337 | if (strlen(Line) == 0) break; |
340 | dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); | 338 | dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); |
341 | switch (Level) { | 339 | switch (Level) { |
342 | case 0: | 340 | case 0: |
343 | if (strstr(Line,"BEGIN:VEVENT")) { | 341 | if (strstr(Line,"BEGIN:VEVENT")) { |
344 | Loc++; | 342 | Loc++; |
345 | if (Loc == Note->Location) { | 343 | if (Loc == Note->Location) { |
346 | Level = 1; | 344 | Level = 1; |
@@ -353,59 +351,170 @@ GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) | |||
353 | Buf[Used-3] = 13; | 351 | Buf[Used-3] = 13; |
354 | Buf[Used-2] = 10; | 352 | Buf[Used-2] = 10; |
355 | Buf[Used-1] = 0x00; | 353 | Buf[Used-1] = 0x00; |
356 | break; | 354 | break; |
357 | case 1: /* Calendar note */ | 355 | case 1: /* Calendar note */ |
358 | if (strstr(Line,"END:VEVENT")) { | 356 | if (strstr(Line,"END:VEVENT")) { |
359 | Level = 0; | 357 | Level = 0; |
360 | } | 358 | } |
361 | break; | 359 | break; |
362 | } | 360 | } |
363 | } | 361 | } |
364 | 362 | ||
365 | DumpMessage(s->di.df, s->di.dl, Buf, Used); | 363 | DumpMessage(s->di.df, s->di.dl, Buf, Used); |
366 | 364 | ||
367 | error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); | 365 | error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); |
368 | if (Buf != NULL) free(Buf); | 366 | if (Buf != NULL) free(Buf); |
369 | return error; | 367 | return error; |
370 | #else | 368 | #else |
371 | return ERR_SOURCENOTAVAILABLE; | 369 | return ERR_SOURCENOTAVAILABLE; |
372 | #endif | 370 | #endif |
373 | } | 371 | } |
374 | 372 | ||
375 | GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status) | 373 | GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status) |
376 | { | 374 | { |
377 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | 375 | #ifdef GSM_ENABLE_OBEXGEN |
378 | GSM_Error error; | 376 | GSM_Error error; |
379 | GSM_ToDoEntry ToDo; | 377 | GSM_ToDoEntry ToDo; |
380 | GSM_CalendarEntry Calendar; | 378 | GSM_CalendarEntry Calendar; |
381 | int Pos; | 379 | int Pos; |
382 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | 380 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; |
383 | 381 | ||
384 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | 382 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; |
385 | 383 | ||
386 | smprintf(s, "Getting calendar status\n"); | 384 | smprintf(s, "Getting calendar status\n"); |
387 | 385 | ||
388 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | 386 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); |
389 | if (error != ERR_NONE) return error; | 387 | if (error != ERR_NONE) return error; |
390 | 388 | ||
391 | Status->Used = 0; | 389 | Status->Used = 0; |
392 | Pos = 0; | 390 | Pos = 0; |
393 | while (1) { | 391 | while (1) { |
394 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | 392 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); |
395 | if (error == ERR_EMPTY) break; | 393 | if (error == ERR_EMPTY) break; |
396 | if (error != ERR_NONE) return error; | 394 | if (error != ERR_NONE) return error; |
397 | if (Calendar.EntriesNum != 0) Status->Used++; | 395 | if (Calendar.EntriesNum != 0) Status->Used++; |
398 | } | 396 | } |
399 | 397 | ||
400 | return ERR_NONE; | 398 | return ERR_NONE; |
401 | #else | 399 | #else |
402 | return ERR_SOURCENOTAVAILABLE; | 400 | return ERR_SOURCENOTAVAILABLE; |
403 | #endif | 401 | #endif |
404 | } | 402 | } |
405 | 403 | ||
406 | #endif | 404 | GSM_Error ERICSSON_ReplyGetDateLocale(GSM_Protocol_Message msg, GSM_StateMachine *s) |
405 | { /*Author: Peter Ondraska, based on code by Marcin Wiacek and Michal Cihar | ||
406 | License: Whatever the current maintainer of gammulib chooses, as long as there | ||
407 | is an easy way to obtain the source under GPL, otherwise the author's parts | ||
408 | of this function are GPL 2.0. | ||
409 | */ | ||
410 | GSM_Locale*locale = s->Phone.Data.Locale; | ||
411 | char format; | ||
412 | |||
413 | switch (s->Phone.Data.Priv.ATGEN.ReplyState) { | ||
414 | case AT_Reply_OK: | ||
415 | smprintf(s, "Date settings received\n"); | ||
416 | format=atoi(msg.Buffer); | ||
417 | switch (format) { | ||
418 | case 0: locale->DateFormat = GSM_Date_OFF; | ||
419 | locale->DateSeparator = 0; | ||
420 | break; | ||
421 | case 1: locale->DateFormat = GSM_Date_DDMMMYY; | ||
422 | locale->DateSeparator = '-'; | ||
423 | break; | ||
424 | case 2: locale->DateFormat = GSM_Date_DDMMYY; | ||
425 | locale->DateSeparator = '-'; | ||
426 | break; | ||
427 | case 3: locale->DateFormat = GSM_Date_MMDDYY; | ||
428 | locale->DateSeparator = '/'; | ||
429 | break; | ||
430 | case 4: locale->DateFormat = GSM_Date_DDMMYY; | ||
431 | locale->DateSeparator = '/'; | ||
432 | break; | ||
433 | case 5: locale->DateFormat = GSM_Date_DDMMYY; | ||
434 | locale->DateSeparator = '.'; | ||
435 | break; | ||
436 | case 6: locale->DateFormat = GSM_Date_YYMMDD; | ||
437 | locale->DateSeparator = 0; | ||
438 | break; | ||
439 | case 7: locale->DateFormat = GSM_Date_YYMMDD; | ||
440 | locale->DateSeparator = '-'; | ||
441 | break; | ||
442 | default:return ERR_UNKNOWNRESPONSE; | ||
443 | } | ||
444 | default: | ||
445 | return ERR_NOTSUPPORTED; | ||
446 | } | ||
447 | } | ||
448 | |||
449 | GSM_Error ERICSSON_ReplyGetTimeLocale(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
450 | { /*Author: Peter Ondraska | ||
451 | License: Whatever the current maintainer of gammulib chooses, as long as there | ||
452 | is an easy way to obtain the source under GPL, otherwise the author's parts | ||
453 | of this function are GPL 2.0. | ||
454 | */ | ||
455 | char format; | ||
456 | |||
457 | switch (s->Phone.Data.Priv.ATGEN.ReplyState) { | ||
458 | case AT_Reply_OK: | ||
459 | smprintf(s, "Time settings received\n"); | ||
460 | format=atoi(msg.Buffer); | ||
461 | switch (format) { | ||
462 | case 1: | ||
463 | case 2: s->Phone.Data.Locale->AMPMTime=(format==2); | ||
464 | return ERR_NONE; | ||
465 | default:return ERR_UNKNOWNRESPONSE; | ||
466 | } | ||
467 | default: return ERR_NOTSUPPORTED; | ||
468 | } | ||
469 | } | ||
470 | |||
471 | GSM_Error ERICSSON_GetLocale(GSM_StateMachine *s, GSM_Locale *locale) | ||
472 | { | ||
473 | GSM_Error error; | ||
474 | |||
475 | s->Phone.Data.Locale = locale; | ||
476 | |||
477 | smprintf(s, "Getting date format\n"); | ||
478 | error=GSM_WaitFor (s, "AT+ESDF?\r", 9, 0x00, 3, ID_GetLocale); | ||
479 | if (error!=ERR_NONE) return error; | ||
480 | |||
481 | smprintf(s, "Getting time format\n"); | ||
482 | return GSM_WaitFor (s, "AT+ESTF?\r", 9, 0x00, 3, ID_GetLocale); | ||
483 | } | ||
484 | |||
485 | |||
486 | GSM_Error ERICSSON_SetLocale(GSM_StateMachine *s, GSM_Locale *locale) | ||
487 | { /*Author: Peter Ondraska | ||
488 | License: Whatever the current maintainer of gammulib chooses, as long as there | ||
489 | is an easy way to obtain the source under GPL, otherwise the author's parts | ||
490 | of this function are GPL 2.0. | ||
491 | */ | ||
492 | /* this is not yet supported by gammu.c */ | ||
493 | intformat=0; | ||
494 | charreq[12]; | ||
495 | |||
496 | if (locale->DateFormat==GSM_Date_OFF) { format=0; } else | ||
497 | if ((locale->DateFormat==GSM_Date_DDMMMYY)&&(locale->DateSeparator=='-')) { format=1; } else | ||
498 | if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='-')) { format=2; } else | ||
499 | if ((locale->DateFormat==GSM_Date_MMDDYY)&&(locale->DateSeparator=='/')) { format=3; } else | ||
500 | if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='/')) { format=4; } else | ||
501 | if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='.')) { format=5; } else | ||
502 | if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator==0)) { format=6; } else | ||
503 | if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator=='-')) { format=7; } | ||
504 | else { return ERR_NOTSUPPORTED; } /* ERR_WRONGINPUT */ | ||
505 | |||
506 | sprintf(req,"AT+ESDF=%i\r",format); | ||
507 | smprintf(s, "Setting date format\n"); | ||
508 | return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale); | ||
509 | |||
510 | if (locale->AMPMTime) { format=2; } else { format=1; } | ||
511 | sprintf(req,"AT+ESTF=%i\r",format); | ||
512 | smprintf(s, "Setting time format\n"); | ||
513 | return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale); | ||
514 | } | ||
515 | |||
407 | #endif | 516 | #endif |
408 | 517 | ||
409 | /* How should editor hadle tabs in this file? Add editor commands here. | 518 | /* How should editor hadle tabs in this file? Add editor commands here. |
410 | * vim: noexpandtab sw=8 ts=8 sts=8: | 519 | * vim: noexpandtab sw=8 ts=8 sts=8: |
411 | */ | 520 | */ |