1 /* Test for parsing memory replies 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 */
11 #include "../helper/memory-display.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
;
24 unsigned char buffer
[BUFFER_SIZE
];
28 GSM_Protocol_Message msg
;
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");
39 f
= fopen(argv
[1], "r");
41 printf("Could not open %s\n", argv
[1]);
46 len
= fread(buffer
, 1, sizeof(buffer
) - 1, f
);
48 printf("Could not read whole file %s\n", argv
[1]);
52 /* Zero terminate data */
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
;
83 Priv
->Charset
= AT_CHARSET_UCS2
;
90 SplitLines(msg
.Buffer
, msg
.Length
, &Priv
->Lines
, "\x0D\x0A", 2, "\"", 1, TRUE
);
92 s
->Phone
.Data
.Memory
= &memory
;
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");
112 /* Editor configuration
113 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: