summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/protocol/symbian/mrouter.c
Unidiff
Diffstat (limited to 'gammu/emb/common/protocol/symbian/mrouter.c') (more/less context) (show whitespace changes)
-rw-r--r--gammu/emb/common/protocol/symbian/mrouter.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/gammu/emb/common/protocol/symbian/mrouter.c b/gammu/emb/common/protocol/symbian/mrouter.c
new file mode 100644
index 0000000..2ca7af1
--- a/dev/null
+++ b/gammu/emb/common/protocol/symbian/mrouter.c
@@ -0,0 +1,110 @@
1/* (c) 2003 by Marcin Wiacek */
2
3#include "../../gsmstate.h"
4
5#if defined(GSM_ENABLE_MROUTERBLUE)
6
7#include <stdio.h>
8#include <string.h>
9
10#include "../../gsmcomon.h"
11#include "mrouter.h"
12
13static GSM_Error MROUTER_WriteMessage (GSM_StateMachine *s, unsigned char *buffer,
14 int length, unsigned char type)
15{
16 unsigned char*out_buffer;
17 int current=0,sent;
18
19 out_buffer = (unsigned char *)malloc(length+1);
20
21 memcpy(out_buffer,buffer,length);
22 out_buffer[length]=0x7E;
23
24 GSM_DumpMessageLevel2(s, out_buffer, length, type);
25 GSM_DumpMessageLevel3(s, out_buffer, length, type);
26
27 /* Send it out... */
28 sent = s->Device.Functions->WriteDevice(s,out_buffer,length+1);
29
30 free(out_buffer);
31
32 if (sent!=current) return ERR_DEVICEWRITEERROR;
33 return ERR_NONE;
34}
35
36static GSM_Error MROUTER_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
37{
38 GSM_Phone_Functions *Phone= s->Phone.Functions;
39 GSM_Protocol_MROUTERData *d= &s->Protocol.Data.MROUTER;
40
41 switch (d->MsgRXState) {
42 case RX_Sync:
43 if (rx_char == 0x7E) {
44 d->MsgRXState = RX_GetMessage;
45 d->Msg.Count = 0;
46 d->Msg.Length = 0;
47 } else smprintf(s,"Sync error: %02x\n",rx_char);
48 break;
49 case RX_GetMessage:
50 if (rx_char == 0x7E) {
51 s->Phone.Data.RequestMsg= &d->Msg;
52 s->Phone.Data.DispatchError= Phone->DispatchMessage(s);
53 d->Msg.Count = 0;
54 d->Msg.Length = 0;
55 } else {
56 d->Msg.BufferUsed = d->Msg.Length+1;
57 d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed);
58
59 d->Msg.Buffer[d->Msg.Count] = rx_char;
60 d->Msg.Count++;
61 d->Msg.Length++;
62 }
63 break;
64 }
65
66 return ERR_NONE;
67}
68
69static GSM_Error MROUTER_Initialise(GSM_StateMachine *s)
70{
71 GSM_Protocol_MROUTERData *d = &s->Protocol.Data.MROUTER;
72GSM_Error error;
73
74 d->Msg.BufferUsed= 0;
75 d->Msg.Buffer = NULL;
76 d->Msg.Length = 0;
77
78 d->MsgRXState = RX_Sync;
79
80 //error=s->Device.Functions->DeviceSetDtrRts(s,false,false);
81 // if (error!=ERR_NONE) return error;
82
83 error=s->Device.Functions->DeviceSetSpeed(s,115200);
84 if (error!=ERR_NONE) return error;
85
86
87 //error=s->Device.Functions->DeviceSetSpeed(s,115200);
88 // if (error!=ERR_NONE) return error;
89
90 return ERR_NONE;
91}
92
93static GSM_Error MROUTER_Terminate(GSM_StateMachine *s)
94{
95 free(s->Protocol.Data.MROUTER.Msg.Buffer);
96 return ERR_NONE;
97}
98
99GSM_Protocol_Functions MROUTERProtocol = {
100 MROUTER_WriteMessage,
101 MROUTER_StateMachine,
102 MROUTER_Initialise,
103 MROUTER_Terminate
104};
105
106#endif
107
108/* How should editor hadle tabs in this file? Add editor commands here.
109 * vim: noexpandtab sw=8 ts=8 sts=8:
110 */