Translation update done using Pootle.
[gammu.git] / tests / samsung-get-memory.c
blob47502912f368f13bd54b1e7179738b5160b8fa0b
1 /* Test for reading memory on AT/Samsung 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/memory-display.h"
13 #include "common.h"
15 #define BUFFER_SIZE 16384
17 extern GSM_Error SAMSUNG_ReplyGetMemory(GSM_Protocol_Message *msg, GSM_StateMachine * s);
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_MemoryEntry Entry;
32 /* Check parameters */
33 if (argc != 2) {
34 printf("Not enough parameters!\nUsage: samsung-get-memory comm.dump\n");
35 return 1;
38 /* Open file */
39 f = fopen(argv[1], "r");
40 if (f == NULL) {
41 printf("Could not open %s\n", argv[1]);
42 return 1;
45 /* Read data */
46 len = fread(buffer, 1, sizeof(buffer) - 1, f);
47 if (!feof(f)) {
48 printf("Could not read whole file %s\n", argv[1]);
49 fclose(f);
50 return 1;
52 /* Zero terminate data */
53 buffer[len] = 0;
55 /* Close file */
56 fclose(f);
58 /* Configure state machine */
59 debug_info = GSM_GetGlobalDebug();
60 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
61 GSM_SetDebugLevel("textall", debug_info);
63 /* Allocates state machine */
64 s = GSM_AllocStateMachine();
65 test_result(s != NULL);
66 debug_info = GSM_GetDebug(s);
67 GSM_SetDebugGlobal(TRUE, debug_info);
69 /* Initialize AT engine */
70 Data = &s->Phone.Data;
71 Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
72 Priv = &s->Phone.Data.Priv.ATGEN;
73 Priv->ReplyState = AT_Reply_OK;
74 Priv->SMSMode = SMS_AT_PDU;
75 Priv->Charset = AT_CHARSET_UCS2;
76 s->Phone.Data.Memory = &Entry;
78 /* Init message */
79 msg.Type = 0;
80 msg.Length = len;
81 msg.Buffer = buffer;
82 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
84 /* Parse it */
85 error = SAMSUNG_ReplyGetMemory(&msg, s);
86 gammu_test_result(error, "SAMSUNG_ReplyGetMemory");
88 /* This is normally done by ATGEN_Terminate */
89 FreeLines(&Priv->Lines);
90 GetLineString(NULL, NULL, 0);
92 /* Print it */
93 error = PrintMemoryEntry(&Entry, s);
94 gammu_test_result(error, "PrintMemoryEntry");
96 /* Free state machine */
97 GSM_FreeStateMachine(s);
99 return 0;
102 /* Editor configuration
103 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: