This commit was manufactured by cvs2svn to create branch 'decode'.
[gnokii.git] / mgnetd / mg_demo_client / mg_demo_client.c
1 /*
2    Demo/test prg for MYGNOKII net_api 
3         Ralf Thelen 20.01.2002
4         */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include "mg_net_api.h"
10
11 /* usage */
12 void usage(void)
13 {
14     fprintf(stderr, "\n\nUsage:  mg_demo_client <server> <passwd> <command> <option 1, option 2>\n"
15 "   where \n"
16 " <server> is hostname or ip-address with running 'gnokii --server'\n"
17 " <passwd> is the password for the running gnokii server\n"
18 " <command> is a number between 0 and 5 (see below)\n"
19 " <option 1> is command specific (see below)\n\n\n"
20
21 "   mg_demo_client <server> <passwd> 1\n"
22 "command = 1(MG_EXIT) -> let server die\n\n"
23
24 "   mg_demo_client <server> <passwd> 2\n"
25 "command = 2    (MG_VERSION) -> ask for server version of mg_net_api\n\n"
26
27 "   mg_demo_client <server> <passwd> 3\n"
28 "command = 3    (MG_IDENTIFY) -> get identify-string from phone\n\n"
29
30 "   mg_demo_client <server> <passwd> 4 < SM | ME> \n"
31 "command = 4    (MG_MEMORYSTATUS) -> get memory status from phone\n\n"
32
33 "   mg_demo_client <server> <passwd> 5 < SM | ME> <location-nr> \n"
34 "command = 5    (MG_GET_MEMORY_LOCATION) -> get phonebookentry at location from phone \n\n"
35
36 "   mg_demo_client <server> <passwd> 6 < SM | ME> <location-nr> <name> <number>\n"
37 "command = 6    (MG_WRITE_PHONEBOOK_LOCATION) -> write phonebookentry to location at phone\n\n"
38
39 "   mg_demo_client <server> <passwd> 7 < SM | ME> <location-nr>\n"
40 "command = 7    (MG_DELETE_PHONEBOOK_LOCATION) -> delete phonebookentry at location at phone\n\n"
41
42 "   mg_demo_client <server> <passwd> 8 <destination> <message>\n"
43 "command = 8    (MG_SEND_SMS) -> send sms 'message to destionation\n\n");
44
45     exit(1);
46 }
47
48
49 int main(argc, argv)
50 int argc;
51 char *argv[];
52 {
53         int user_cmd;
54         int ret;
55         MG_rq_version version;
56         MG_rq_identify ident;
57         MG_rq_memorystatus status;
58         MG_rq_phonebook_location ph;
59         MG_rq_send_sms sms;
60
61
62         if (argc < 3) {
63                 usage();
64         }
65         if ( mg_init(argv[1], argv[2])  < 0 )
66           {
67                 printf("init failed\n");
68                 exit(1);
69                 }
70
71         user_cmd = atoi(argv[3]);
72         switch(user_cmd)
73         {
74          case MG_EXIT:
75                 if (argc != 4) usage();
76                 if ( (ret = mg_exit()) < 0)
77                   printf("exit failed (%d)\n",ret);
78                 else
79                   printf("server is exiting\n");
80                 break;
81          case MG_VERSION:
82                 if (argc != 4) usage();
83                 if ( (ret = mg_version(&version)) < 0)
84                   printf("version failed (%d)\n",ret);
85                 else
86                 {
87                   printf("Version is %d.%d\n",version.major, version.minor);
88                 }
89                 break;
90          case MG_IDENTIFY:
91                 if (argc != 4) usage();
92                 if ( (ret = mg_identify(&ident)) < 0)
93                   printf("identify failed(%d)\n",ret);
94                 else
95                 {
96                   printf("IMEI: %s, Model: %s, Revision: %s\n",ident.imei, ident.model, ident.rev);
97                 }
98                 break;
99          case MG_MEMORYSTATUS:
100                 if (argc != 5) usage();
101                 strcpy(status.memtype,argv[4]);
102                 if ( (ret = mg_memorystatus(&status)) < 0)
103                   printf("status failed(%d)\n",ret);
104                 else
105                 {
106                   printf("Status for %s: %d Free, %d Used\n",status.memtype,status.free,status.used);
107                 }
108                 break;
109          case MG_GET_MEMORY_LOCATION:
110                 if (argc != 6) usage();
111                 strcpy(ph.memtype,argv[4]);
112                 ph.location = atoi(argv[5]);
113                 if ( (ret = mg_get_memory_location(&ph)) < 0)
114                   printf("get memory location failed(%d)\n",ret);
115                 else
116                 {
117                   printf("Location Nr: %d:\n",ph.location);
118                   printf("Name: %s\nGroup: %s\nnr_general: %s\nnr_mobile: %s\nnr_work: %s\nnr_fax: %s\nnr_home: %s\nnote: %s\npostal: %s\nemail: %s\n",
119                                 ph.name,
120                                 ph.group,
121                                 ph.nr_general,
122                                 ph.nr_mobile,
123                                 ph.nr_work,
124                                 ph.nr_fax,
125                                 ph.nr_home,
126                                 ph.note,
127                                 ph.postal,
128                                 ph.email);
129                 }
130                 break;
131          case MG_WRITE_PHONEBOOK_LOCATION:
132                 if (argc != 8) usage();
133                 ph.group[0] = ph.nr_mobile[0] = ph.nr_work[0] = '\0';
134                 ph.nr_fax[0] = ph.nr_home[0] = ph.note[0] = ph.postal[0] = ph.email[0] = '\0';
135                 strcpy(ph.memtype,argv[4]);
136                 ph.location = atoi(argv[5]);
137                 strcpy(ph.name,argv[6]);
138                 strcpy(ph.nr_general,argv[7]);
139                 if ( (ret = mg_write_phonebook_location(&ph)) < 0)
140                   printf("Write Location Nr: %d %s %s FAILED(%d)\n",ph.location,ph.name,ph.nr_general,ret);
141                 else
142                 {
143                   printf("Write Location Nr: %d %s %s succeded\n",ph.location,ph.name,ph.nr_general);
144                 }
145                 break;
146          case MG_DELETE_PHONEBOOK_LOCATION:
147                 if (argc != 6) usage();
148                 strcpy(ph.memtype,argv[4]);
149                 ph.location = atoi(argv[5]);
150                 if ( (ret = mg_delete_phonebook_location(&ph)) < 0)
151                   printf("Delete Location Nr: %d failed (%d)\n",ph.location,ret);
152                 else
153                 {
154                   printf("Delete Location Nr: %d succeded\n",ph.location);
155                 }
156                 break;
157          case MG_SEND_SMS:
158                 if (argc != 6) usage();
159                 strcpy(sms.destination,argv[4]);
160                 strcpy(sms.message,argv[5]);
161                 /* defaults */
162                 sms.SMSCNumber[0] = '\0';                   /* SMSC number */
163                 sms.SMSCenterIndex = 0;                          /* SMSC number index in phone memory */
164                 sms.SMSValidity= 0;                               /* validity of sms */
165                 sms.enablevoice=FALSE;                               /* SMS enables voice indicator */
166                 sms.disablevoice=FALSE;                              /* SMS disables voice indicator */
167                 sms.enableemail=FALSE;                               /* SMS enables email indicator */
168                 sms.disableemail=FALSE;                              /* SMS disables email indicator */
169                 sms.enablefax=FALSE;                                 /* SMS enables fax indicator */
170                 sms.disablefax=FALSE;                                /* SMS disables fax indicator */
171                 sms.unicode=FALSE;                                   /* SMS coding type */
172                 sms.delivery=FALSE;
173                 if ( (ret = mg_send_sms(&sms)) < 0)
174                   printf("send sms failed \n(%d)",ret);
175                 else
176                 {
177                   printf("send sms succeded \n");
178                 }
179                 break;
180          default:
181                 printf("unknown command\n");
182                 usage();
183         }
184
185 return(0);
186 }