Translation update done using Pootle.
[gammu.git] / tests / at-ussd-reply.c
blobd0b1cfaffe9b1e2e47030a885dbb795904316e6f
1 /* Test for parsing USSD reply 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 "common.h"
13 #define BUFFER_SIZE 16384
15 extern GSM_Error ATGEN_ReplyGetUSSD(GSM_Protocol_Message *msg, GSM_StateMachine * s);
17 int main(int argc, char **argv)
19 GSM_Debug_Info *debug_info;
20 GSM_Phone_ATGENData *Priv;
21 GSM_Phone_Data *Data;
22 unsigned char buffer[BUFFER_SIZE];
23 FILE *f;
24 size_t len;
25 GSM_StateMachine *s;
26 GSM_Protocol_Message msg;
27 GSM_Error error;
29 /* Check parameters */
30 if (argc != 3) {
31 printf("Not enough parameters!\nUsage: at-ussd-reply comm.dump MODEL\n");
32 return 1;
35 /* Open file */
36 f = fopen(argv[1], "r");
37 if (f == NULL) {
38 printf("Could not open %s\n", argv[1]);
39 return 1;
42 /* Read data */
43 len = fread(buffer, 1, sizeof(buffer) - 1, f);
44 if (!feof(f)) {
45 printf("Could not read whole file %s\n", argv[1]);
46 fclose(f);
47 return 1;
49 /* Zero terminate data */
50 buffer[len] = 0;
52 /* Close file */
53 fclose(f);
55 /* Configure state machine */
56 debug_info = GSM_GetGlobalDebug();
57 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
58 GSM_SetDebugLevel("textall", debug_info);
60 /* Allocates state machine */
61 s = GSM_AllocStateMachine();
62 test_result(s != NULL);
63 debug_info = GSM_GetDebug(s);
64 GSM_SetDebugGlobal(TRUE, debug_info);
66 /* Initialize AT engine */
67 Data = &s->Phone.Data;
68 Data->ModelInfo = GetModelData(NULL, NULL, argv[2], NULL);
69 Priv = &s->Phone.Data.Priv.ATGEN;
70 Priv->ReplyState = AT_Reply_OK;
71 Priv->SMSMode = SMS_AT_PDU;
72 Priv->Charset = AT_CHARSET_GSM;
73 s->User.IncomingUSSD = NULL;
74 s->Phone.Data.EnableIncomingUSSD = TRUE;
76 /* Init message */
77 msg.Type = 0;
78 msg.Length = len;
79 msg.Buffer = buffer;
80 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
82 /* Parse it */
83 error = ATGEN_ReplyGetUSSD(&msg, s);
85 /* This is normally done by ATGEN_Terminate */
86 FreeLines(&Priv->Lines);
87 GetLineString(NULL, NULL, 0);
89 /* Free state machine */
90 GSM_FreeStateMachine(s);
92 gammu_test_result(error, "ATGEN_ReplyGetCNMIMode");
94 return 0;
97 /* Editor configuration
98 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: