2 Demo/test prg for MYGNOKII net_api
9 #include "mg_net_api.h"
14 fprintf(stderr, "\n\nUsage: mg_demo_client <server> <passwd> <command> <option 1, option 2>\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"
21 " mg_demo_client <server> <passwd> 1\n"
22 "command = 1(MG_EXIT) -> let server die\n\n"
24 " mg_demo_client <server> <passwd> 2\n"
25 "command = 2 (MG_VERSION) -> ask for server version of mg_net_api\n\n"
27 " mg_demo_client <server> <passwd> 3\n"
28 "command = 3 (MG_IDENTIFY) -> get identify-string from phone\n\n"
30 " mg_demo_client <server> <passwd> 4 < SM | ME> \n"
31 "command = 4 (MG_MEMORYSTATUS) -> get memory status from phone\n\n"
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"
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"
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"
42 " mg_demo_client <server> <passwd> 8 <destination> <message>\n"
43 "command = 8 (MG_SEND_SMS) -> send sms 'message to destionation\n\n");
55 MG_rq_version version;
57 MG_rq_memorystatus status;
58 MG_rq_phonebook_location ph;
65 if ( mg_init(argv[1], argv[2]) < 0 )
67 printf("init failed\n");
71 user_cmd = atoi(argv[3]);
75 if (argc != 4) usage();
76 if ( (ret = mg_exit()) < 0)
77 printf("exit failed (%d)\n",ret);
79 printf("server is exiting\n");
82 if (argc != 4) usage();
83 if ( (ret = mg_version(&version)) < 0)
84 printf("version failed (%d)\n",ret);
87 printf("Version is %d.%d\n",version.major, version.minor);
91 if (argc != 4) usage();
92 if ( (ret = mg_identify(&ident)) < 0)
93 printf("identify failed(%d)\n",ret);
96 printf("IMEI: %s, Model: %s, Revision: %s\n",ident.imei, ident.model, ident.rev);
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);
106 printf("Status for %s: %d Free, %d Used\n",status.memtype,status.free,status.used);
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);
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",
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);
143 printf("Write Location Nr: %d %s %s succeded\n",ph.location,ph.name,ph.nr_general);
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);
154 printf("Delete Location Nr: %d succeded\n",ph.location);
158 if (argc != 6) usage();
159 strcpy(sms.destination,argv[4]);
160 strcpy(sms.message,argv[5]);
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 */
173 if ( (ret = mg_send_sms(&sms)) < 0)
174 printf("send sms failed \n(%d)",ret);
177 printf("send sms succeded \n");
181 printf("unknown command\n");