Translation update done using Pootle.
[gammu.git] / tests / sms-at-parse.c
blobe79218726ca7f3533912b194eec8b2ab23177c98
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|TXTDETAIL]\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 Priv->SMSTextDetails = FALSE;
82 } else if (argc == 3 && strcmp(argv[2], "TXTDETAIL") == 0) {
83 Priv->SMSMode = SMS_AT_TXT;
84 Priv->SMSTextDetails = TRUE;
85 } else {
86 Priv->SMSMode = SMS_AT_PDU;
89 /* Init message */
90 msg.Type = 0;
91 msg.Length = len;
92 msg.Buffer = buffer;
93 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
95 /* Pointer to store message */
96 s->Phone.Data.GetSMSMessage = &sms;
98 /* Parse it */
99 error = ATGEN_ReplyGetSMSMessage(&msg, s);
100 sms.SMS[0].Memory = MEM_SM;
102 #if 0
103 bkp.SMS[0] = &sms.SMS[0];
104 bkp.SMS[1] = NULL;
106 GSM_AddSMSBackupFile("/tmp/back", &bkp);
107 #endif
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");
125 return 0;
128 /* Editor configuration
129 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: