Added option not to use configured logging in SMSD inject and monitor (bug #1539).
[gammu.git] / tests / sms-at-parse.c
blobb1b8d69786b15a2fe52f88e7fd83c988c10a02eb
1 /* Test for decoding SMS on AT driver */
3 #include <gammu.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
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"
13 #include "common.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;
23 GSM_Phone_Data *Data;
24 unsigned char buffer[BUFFER_SIZE];
25 FILE *f;
26 size_t len;
27 GSM_StateMachine *s;
28 GSM_Protocol_Message msg;
29 GSM_Error error;
30 GSM_MultiSMSMessage sms;
31 #if 0
32 GSM_SMS_Backup bkp;
33 #endif
35 /* Check parameters */
36 if (argc != 2 && argc != 3) {
37 printf("Not enough parameters!\nUsage: sms-at-parse comm.dump [PDU|TXT]\n");
38 return 1;
41 /* Open file */
42 f = fopen(argv[1], "r");
43 if (f == NULL) {
44 printf("Could not open %s\n", argv[1]);
45 return 1;
48 /* Read data */
49 len = fread(buffer, 1, sizeof(buffer) - 1, f);
50 if (!feof(f)) {
51 printf("Could not read whole file %s\n", argv[1]);
52 fclose(f);
53 return 1;
55 /* Zero terminate data */
56 buffer[len] = 0;
58 /* Close file */
59 fclose(f);
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 } else {
82 Priv->SMSMode = SMS_AT_PDU;
85 /* Init message */
86 msg.Type = 0;
87 msg.Length = len;
88 msg.Buffer = buffer;
89 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
91 /* Pointer to store message */
92 s->Phone.Data.GetSMSMessage = &sms;
94 /* Parse it */
95 error = ATGEN_ReplyGetSMSMessage(&msg, s);
96 sms.SMS[0].Memory = MEM_SM;
98 #if 0
99 bkp.SMS[0] = &sms.SMS[0];
100 bkp.SMS[1] = NULL;
102 GSM_AddSMSBackupFile("/tmp/back", &bkp);
103 #endif
105 /* Display message */
106 if (error == ERR_NONE) {
107 DisplayMultiSMSInfo(&sms, FALSE, TRUE, NULL, NULL);
108 DisplayMultiSMSInfo(&sms, TRUE, TRUE, NULL, NULL);
109 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);
112 /* This is normally done by ATGEN_Terminate */
113 FreeLines(&Priv->Lines);
114 GetLineString(NULL, NULL, 0);
116 /* Free state machine */
117 GSM_FreeStateMachine(s);
119 gammu_test_result(error, "ATGEN_ReplyGetSMSMessage");
121 return 0;
124 /* Editor configuration
125 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: