Translation update done using Pootle.
[gammu.git] / tests / at-get-smsmemories.c
blob37f22e16b3df5f5f67cbaf343d1902f963c26141
1 /* Test for reading model 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_ReplyGetSMSMemories(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 != 2) {
31 printf("Not enough parameters!\nUsage: at-cnmi-reply comm.dump\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, "unknown", 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_UCS2;
73 Priv->Manufacturer = AT_Samsung;
75 /* Init message */
76 msg.Type = 0;
77 msg.Length = len;
78 msg.Buffer = buffer;
79 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
81 /* Parse it */
82 error = ATGEN_ReplyGetSMSMemories(&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 gammu_test_result(error, "ATGEN_ReplyGetSMSMemories");
93 return 0;
96 /* Editor configuration
97 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: