Merge remote-tracking branch 'pootle/master'
[gammu.git] / tests / at-getmemory-reply.c
blob87fb93dc1575d6d4ccd5a9aed677077fe0b4b115
1 /* Test for parsing memory replies 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 "../helper/memory-display.h"
13 #include "common.h"
15 #define BUFFER_SIZE 16384
17 extern GSM_Error ATGEN_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 memory;
32 /* Check parameters */
33 if (argc != 2 && argc != 3) {
34 printf("Not enough parameters!\nUsage: at-getmemory-reply comm.dump [CHARSET]\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->Manufacturer = AT_Motorola;
75 Priv->SMSMode = SMS_AT_PDU;
76 if (argc == 3 && strcmp(argv[2], "PCCP437") == 0) {
77 Priv->Charset = AT_CHARSET_PCCP437;
78 } else if (argc == 3 && strcmp(argv[2], "UTF8") == 0) {
79 Priv->Charset = AT_CHARSET_UTF8;
80 } else if (argc == 3 && strcmp(argv[2], "HEX") == 0) {
81 Priv->Charset = AT_CHARSET_HEX;
82 } else {
83 Priv->Charset = AT_CHARSET_UCS2;
86 /* Init message */
87 msg.Type = 0;
88 msg.Length = len;
89 msg.Buffer = buffer;
90 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
92 s->Phone.Data.Memory = &memory;
94 /* Parse it */
95 error = ATGEN_ReplyGetMemory(&msg, s);
97 /* This is normally done by ATGEN_Terminate */
98 FreeLines(&Priv->Lines);
99 GetLineString(NULL, NULL, 0);
101 /* Free state machine */
102 GSM_FreeStateMachine(s);
104 gammu_test_result(error, "ATGEN_ReplyGetCNMIMode");
106 error = PrintMemoryEntry(&memory, NULL);
107 gammu_test_result(error, "PrintMemoryEntry");
109 return 0;
112 /* Editor configuration
113 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: