Translation update done using Pootle.
[gammu.git] / tests / get-smsc-at.c
blobe0ac44bb1b43c865a202ba8f5890838f7069a440
1 /* Test for reading SMSC on AT driver */
3 #include <gammu.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
8 #include "common.h"
10 #include "../libgammu/protocol/protocol.h" /* Needed for GSM_Protocol_Message */
11 #include "../libgammu/gsmstate.h" /* Needed for state machine internals */
12 #include "../libgammu/gsmphones.h" /* Phone data */
14 #define BUFFER_SIZE 16384
16 extern GSM_Error ATGEN_ReplyGetSMSC(GSM_Protocol_Message *msg, GSM_StateMachine * s);
18 int main(int argc, char **argv)
20 GSM_Debug_Info *debug_info;
21 GSM_Phone_ATGENData *Priv;
22 GSM_Phone_Data *Data;
23 unsigned char buffer[BUFFER_SIZE];
24 FILE *f;
25 size_t len;
26 GSM_StateMachine *s;
27 GSM_Protocol_Message msg;
28 GSM_Error error;
29 GSM_SMSC SMSC;
31 /* Check parameters */
32 if (argc != 2) {
33 printf("Not enough parameters!\nUsage: get-smsc-at comm.dump\n");
34 return 1;
37 /* Open file */
38 f = fopen(argv[1], "r");
39 test_result(f != NULL);
41 /* Read data */
42 len = fread(buffer, 1, sizeof(buffer) - 1, f);
43 test_result(feof(f));
45 /* Zero terminate data */
46 buffer[len] = 0;
48 /* Close file */
49 fclose(f);
51 /* Configure state machine */
52 debug_info = GSM_GetGlobalDebug();
53 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
54 GSM_SetDebugLevel("textall", debug_info);
56 /* Allocates state machine */
57 s = GSM_AllocStateMachine();
58 test_result(s != NULL);
59 debug_info = GSM_GetDebug(s);
60 GSM_SetDebugGlobal(TRUE, debug_info);
61 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
62 GSM_SetDebugLevel("textall", debug_info);
64 /* Initialize AT engine */
65 Data = &s->Phone.Data;
66 Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
67 Priv = &s->Phone.Data.Priv.ATGEN;
68 Priv->ReplyState = AT_Reply_OK;
69 Priv->SMSMode = SMS_AT_PDU;
70 Priv->Charset = AT_CHARSET_UCS2;
72 /* Init message */
73 msg.Type = 0;
74 msg.Length = len;
75 msg.Buffer = buffer;
76 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
78 /* Pointer to store message */
79 s->Phone.Data.SMSC = &SMSC;
81 /* Parse it */
82 error = ATGEN_ReplyGetSMSC(&msg, s);
84 /* This is normally done by ATGEN_Terminate */
85 FreeLines(&Priv->Lines);
86 GetLineString(NULL, NULL, 0);
88 /* Free state machine */
89 GSM_FreeStateMachine(s);
91 printf("%s\n", GSM_ErrorString(error));
93 return (error == ERR_NONE) ? 0 : 1;
96 /* Editor configuration
97 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: