1 /* Test for decoding SMS on AT driver */
7 #include "../libgammu/protocol/protocol.h" /* Needed for GSM_Protocol_Message */
8 #include "../libgammu/gsmstate.h" /* Needed for state machine internals */
9 #include "../libgammu/gsmphones.h" /* Phone data */
11 #include "../helper/message-display.h"
15 extern GSM_Error
ATGEN_ReplyGetSMSMessage(GSM_Protocol_Message
*msg
, GSM_StateMachine
* s
);
17 #define BUFFER_SIZE 16384
19 int main(int argc
, char **argv
)
21 GSM_Debug_Info
*debug_info
;
22 GSM_Phone_ATGENData
*Priv
;
24 unsigned char buffer
[BUFFER_SIZE
];
28 GSM_Protocol_Message msg
;
30 GSM_MultiSMSMessage sms
;
35 /* Check parameters */
36 if (argc
!= 2 && argc
!= 3) {
37 printf("Not enough parameters!\nUsage: sms-at-parse comm.dump [PDU|TXT|TXTDETAIL]\n");
42 f
= fopen(argv
[1], "r");
44 printf("Could not open %s\n", argv
[1]);
49 len
= fread(buffer
, 1, sizeof(buffer
) - 1, f
);
51 printf("Could not read whole file %s\n", argv
[1]);
55 /* Zero terminate data */
61 /* Configure state machine */
62 debug_info
= GSM_GetGlobalDebug();
63 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
64 GSM_SetDebugLevel("textall", debug_info
);
66 /* Allocates state machine */
67 s
= GSM_AllocStateMachine();
68 test_result(s
!= NULL
);
70 debug_info
= GSM_GetDebug(s
);
71 GSM_SetDebugGlobal(TRUE
, debug_info
);
73 /* Initialize AT engine */
74 Data
= &s
->Phone
.Data
;
75 Data
->ModelInfo
= GetModelData(NULL
, NULL
, "unknown", NULL
);
76 Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
77 Priv
->ReplyState
= AT_Reply_OK
;
78 Priv
->Charset
= AT_CHARSET_GSM
;
79 if (argc
== 3 && strcmp(argv
[2], "TXT") == 0) {
80 Priv
->SMSMode
= SMS_AT_TXT
;
81 Priv
->SMSTextDetails
= FALSE
;
82 } else if (argc
== 3 && strcmp(argv
[2], "TXTDETAIL") == 0) {
83 Priv
->SMSMode
= SMS_AT_TXT
;
84 Priv
->SMSTextDetails
= TRUE
;
86 Priv
->SMSMode
= SMS_AT_PDU
;
93 SplitLines(msg
.Buffer
, msg
.Length
, &Priv
->Lines
, "\x0D\x0A", 2, "\"", 1, TRUE
);
95 /* Pointer to store message */
96 s
->Phone
.Data
.GetSMSMessage
= &sms
;
99 error
= ATGEN_ReplyGetSMSMessage(&msg
, s
);
100 sms
.SMS
[0].Memory
= MEM_SM
;
103 bkp
.SMS
[0] = &sms
.SMS
[0];
106 GSM_AddSMSBackupFile("/tmp/back", &bkp
);
109 /* Display message */
110 if (error
== ERR_NONE
) {
111 DisplayMultiSMSInfo(&sms
, FALSE
, TRUE
, NULL
, NULL
);
112 DisplayMultiSMSInfo(&sms
, TRUE
, TRUE
, NULL
, NULL
);
113 printf("Parts: %d, count: %d, ID16: %d, ID8: %d\n", sms
.SMS
[0].UDH
.AllParts
, sms
.Number
, sms
.SMS
[0].UDH
.ID16bit
, sms
.SMS
[0].UDH
.ID8bit
);
116 /* This is normally done by ATGEN_Terminate */
117 FreeLines(&Priv
->Lines
);
118 GetLineString(NULL
, NULL
, 0);
120 /* Free state machine */
121 GSM_FreeStateMachine(s
);
123 gammu_test_result(error
, "ATGEN_ReplyGetSMSMessage");
128 /* Editor configuration
129 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: