1 /* Test for parsing USSD reply 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 */
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
;
22 unsigned char buffer
[BUFFER_SIZE
];
26 GSM_Protocol_Message msg
;
29 /* Check parameters */
31 printf("Not enough parameters!\nUsage: at-ussd-reply comm.dump MODEL\n");
36 f
= fopen(argv
[1], "r");
38 printf("Could not open %s\n", argv
[1]);
43 len
= fread(buffer
, 1, sizeof(buffer
) - 1, f
);
45 printf("Could not read whole file %s\n", argv
[1]);
49 /* Zero terminate data */
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
;
80 SplitLines(msg
.Buffer
, msg
.Length
, &Priv
->Lines
, "\x0D\x0A", 2, "\"", 1, TRUE
);
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");
97 /* Editor configuration
98 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: