Gammu internals  1.38.0
pfunc.c
Go to the documentation of this file.
1 /* (c) 2002-2003 by Marcin Wiacek */
2 
3 #include <string.h>
4 #include <ctype.h>
5 
6 #include <gammu-ringtone.h>
7 
8 #include "../gsmstate.h"
9 #include "../misc/coding/coding.h"
10 #include "../misc/locales.h"
11 #include "../service/gsmring.h"
12 
13 /* These SMS layouts are used exactly as written in Nokia DCT3 phones.
14  * In AT module(s) we have to use some layouts to convert AT frame to format
15  * understod by SMS module. To share source the same layouts are used */
17  35 /* SMS Text */, 16 /* Phone number */,
18  0 /* SMSC Number */, 14 /* TPDCS */,
19  28 /* SendingDateTime */, 255 /* SMSCDateTime */,
20  255 /* TPStatus */, 15 /* TPUDL */,
21  255 /* TPVP */, 12 /* firstbyte */,
22  255 /* TPMR */, 13 /* TPPID */};
24  36 /* SMS Text */, 17 /* Phone number */,
25  0 /* SMSC Number */, 15 /* TPDCS */,
26  255 /* SendingDateTime */, 255 /* SMSCDateTime */,
27  255 /* TPStatus */, 16 /* TPUDL */,
28  29 /* TPVP */, 12 /* firstbyte */,
29  13 /* TPMR */, 14 /* TPPID */};
31  255 /* SMS Text */, 15 /* Phone number */,
32  0 /* SMSC Number */, 255 /* TPDCS */,
33  27 /* SendingDateTime */, 34 /* SMSCDateTime */,
34  14 /* TPStatus */, 255 /* TPUDL */,
35  255 /* TPVP */, 12 /* firstbyte */,
36  13 /* TPMR */, 255 /* TPPID?? */};
37 
39 {
40  folders->Number=2;
41  EncodeUnicode(folders->Folder[0].Name,_("Inbox"),strlen(_("Inbox")));
42  EncodeUnicode(folders->Folder[1].Name,_("Outbox"),strlen(_("Outbox")));
43  folders->Folder[0].InboxFolder = TRUE;
44  folders->Folder[1].InboxFolder = FALSE;
45  folders->Folder[0].OutboxFolder = FALSE;
46  folders->Folder[1].OutboxFolder = TRUE;
47  folders->Folder[0].Memory = MEM_SM;
48  folders->Folder[1].Memory = MEM_SM;
49  return ERR_NONE;
50 }
51 
53 {
55  smprintf(s, "Number version is \"%f\"\n", s->Phone.Data.VerNum);
56 }
57 
58 GSM_Error PHONE_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, gboolean clear)
59 {
60  GSM_Error error;
61 
62  if (SMS->SMSC.Location != 0) {
63  smprintf(s, "Getting SMSC from phone, location %d\n", SMS->SMSC.Location);
64  error = s->Phone.Functions->GetSMSC(s, &SMS->SMSC);
65  if (error != ERR_NONE) {
66  return ERR_GETTING_SMSC;
67  }
68  SMS->SMSC.Location = 0;
69  }
70  if (SMS->PDU == SMS_Deliver) {
71  if (SMS->SMSC.Number[0] == 0x00 && SMS->SMSC.Number[1] == 0x00) {
72  smprintf(s,"No SMSC in SMS Deliver\n");
73  return ERR_EMPTYSMSC;
74  }
75  }
76  return GSM_EncodeSMSFrame(GSM_GetDI(s), SMS, buffer, Layout, length, clear);
77 }
78 
80 {
81  GSM_Error error;
82 
83  if (s->Phone.Data.EnableIncomingCB==TRUE) {
84  error=s->Phone.Functions->SetIncomingCB(s,FALSE);
85  if (error!=ERR_NONE) return error;
86  }
87  if (s->Phone.Data.EnableIncomingSMS==TRUE) {
88  error=s->Phone.Functions->SetIncomingSMS(s,FALSE);
89  if (error!=ERR_NONE) return error;
90  }
91  return ERR_NONE;
92 }
93 
95 {
96  int duration, Hz;
97  GSM_Error error;
98 
99  Hz=GSM_RingNoteGetFrequency(note);
100 
101  error=s->Phone.Functions->PlayTone(s,Hz,5,first);
102  if (error!=ERR_NONE) return error;
103 
104  duration = GSM_RingNoteGetFullDuration(note);
105 
106  /* Is it correct ? Experimental values here */
107  switch (note.Style) {
108  case INVALIDStyle:
109  break;
110  case StaccatoStyle:
111  usleep(7500000);
112  error=s->Phone.Functions->PlayTone(s,0,0,FALSE);
113  if (error != ERR_NONE) return error;
114  usleep ((1400000000L/note.Tempo*duration)-(7500000));
115  break;
116  case ContinuousStyle:
117  usleep(1400000000L/note.Tempo*duration);
118  break;
119  case NaturalStyle:
120  usleep(1400000000L/note.Tempo*duration-50000);
121  error=s->Phone.Functions->PlayTone(s,0,0,FALSE);
122  if (error != ERR_NONE) return error;
123  usleep(50000);
124  break;
125  }
126  return ERR_NONE;
127 }
128 
130 {
131  GSM_Error error;
132 
133  error=s->Phone.Functions->PlayTone(s, 4000, 5,TRUE);
134  if (error!=ERR_NONE) return error;
135 
136  usleep(500000);
137 
138  return s->Phone.Functions->PlayTone(s,255*255,0,FALSE);
139 }
140 
141 GSM_Error PHONE_FindDataFile(GSM_StateMachine *s, GSM_File * File, const char *ExtraPath, const char *filename)
142 {
143  char *path;
144  GSM_Error error;
145 
146  EncodeUnicode(File->Name, filename, strlen(filename));
147 
148  path = malloc(MAX(strlen(GAMMU_DATA_PATH), ExtraPath == NULL ? 0 : strlen(ExtraPath)) + 50);
149  if (path == NULL) {
150  return ERR_MOREMEMORY;
151  }
152 
153  if (ExtraPath != NULL) {
154  sprintf(path, "%s/%s", ExtraPath, filename);
155  smprintf(s, "Trying to load from extra path: %s\n", path);
156 
157  error = GSM_ReadFile(path, File);
158  if (error == ERR_NONE) {
159  free(path);
160  return error;
161  }
162  }
163 
164  sprintf(path, "%s/%s", GAMMU_DATA_PATH, filename);
165  smprintf(s, "Trying to load from data path: %s\n", path);
166 
167  error = GSM_ReadFile(path, File);
168  free(path);
169 
170  return error;
171 }
172 
174 {
175  size_t Pos = 0;
176  int Handle = 0;
177  GSM_Error error = ERR_NONE;;
178 
179  while (error == ERR_NONE) {
180  error = GSM_SendFilePart(s, File, &Pos, &Handle);
181  }
182  if (error == ERR_EMPTY) {
183  return ERR_NONE;
184  }
185  return error;
186 }
187 
189 {
190  smprintf(s,"None answer\n");
191  return ERR_NONE;
192 }
193 
194 /* How should editor hadle tabs in this file? Add editor commands here.
195  * vim: noexpandtab sw=8 ts=8 sts=8:
196  */
GSM_SMSMessageType PDU
int GSM_RingNoteGetFrequency(GSM_RingNote Note)
Definition: gsmring.c:40
unsigned char Name[2 *(GSM_MAX_FILENAME_LENGTH+1)]
Definition: gammu-file.h:74
#define MAX(a, b)
Definition: gammu-misc.h:68
GSM_Error(* SetIncomingSMS)(GSM_StateMachine *s, gboolean enable)
Definition: gsmstate.h:975
GSM_Error GSM_SendFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
Definition: api.c:1778
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
gboolean EnableIncomingCB
Definition: gsmstate.h:667
GSM_Error
Definition: gammu-error.h:23
GSM_Error(* GetSMSC)(GSM_StateMachine *s, GSM_SMSC *smsc)
Definition: gsmstate.h:929
GSM_OneSMSFolder Folder[GSM_MAX_SMS_FOLDERS]
GSM_Error NoneReply(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
Definition: pfunc.c:188
GSM_SMSMessageLayout PHONE_SMSDeliver
Definition: pfunc.c:16
GSM_Error PHONE_Terminate(GSM_StateMachine *s)
Definition: pfunc.c:79
char Version[GSM_MAX_VERSION_LENGTH+1]
Definition: gsmstate.h:454
GSM_Error PHONE_RTTLPlayOneNote(GSM_StateMachine *s, GSM_RingNote note, gboolean first)
Definition: pfunc.c:94
void StringToDouble(char *text, double *d)
Definition: coding.c:1731
int gboolean
Definition: gammu-types.h:23
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:301
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
GSM_RingNoteStyle Style
GSM_Error PHONE_FindDataFile(GSM_StateMachine *s, GSM_File *File, const char *ExtraPath, const char *filename)
Definition: pfunc.c:141
unsigned char Name[(GSM_MAX_SMS_FOLDER_NAME_LEN+1) *2]
int GSM_RingNoteGetFullDuration(GSM_RingNote Note)
Definition: gsmring.c:76
GSM_MemoryType Memory
gboolean OutboxFolder
gboolean InboxFolder
GSM_Error PHONE_GetSMSFolders(GSM_StateMachine *s UNUSED, GSM_SMSFolders *folders)
Definition: pfunc.c:38
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
GSM_Error(* PlayTone)(GSM_StateMachine *s, int Herz, unsigned char Volume, gboolean start)
Definition: gsmstate.h:1075
GSM_SMSMessageLayout PHONE_SMSStatusReport
Definition: pfunc.c:30
GSM_Error GSM_ReadFile(const char *FileName, GSM_File *File)
Definition: gsmmisc.c:74
GSM_Error(* SetIncomingCB)(GSM_StateMachine *s, gboolean enable)
Definition: gsmstate.h:979
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Error GSM_EncodeSMSFrame(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, gboolean clear)
Definition: gsmsms.c:1008
double VerNum
Definition: gsmstate.h:462
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_SMSMessageLayout PHONE_SMSSubmit
Definition: pfunc.c:23
void GSM_CreateFirmwareNumber(GSM_StateMachine *s)
Definition: pfunc.c:52
#define _(x)
Definition: locales.h:21
#define GAMMU_DATA_PATH
Definition: gammu-config.h:380
GSM_Error PHONE_UploadFile(GSM_StateMachine *s, GSM_File *File)
Definition: pfunc.c:173
#define TRUE
Definition: gammu-types.h:28
gboolean EnableIncomingSMS
Definition: gsmstate.h:663
GSM_Error PHONE_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, gboolean clear)
Definition: pfunc.c:58
GSM_Error PHONE_Beep(GSM_StateMachine *s)
Definition: pfunc.c:129
#define UNUSED
Definition: gammu-misc.h:105
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261