Translation update done using Pootle.
[gammu.git] / tests / get-model-at.c
blob7053fc5f390aa41f4ce447750916b89c1fdb48e3
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_ReplyGetModel(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: get-model-at 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;
74 /* Init message */
75 msg.Type = 0;
76 msg.Length = len;
77 msg.Buffer = buffer;
78 SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
80 /* Parse it */
81 error = ATGEN_ReplyGetModel(&msg, s);
83 /* This is normally done by ATGEN_Terminate */
84 FreeLines(&Priv->Lines);
85 GetLineString(NULL, NULL, 0);
87 /* Free state machine */
88 GSM_FreeStateMachine(s);
90 gammu_test_result(error, "ATGEN_ReplyGetModel");
92 return 0;
95 /* Editor configuration
96 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: