2
* pilot-debugsh.c: Simple debugging console
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12
* Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
#include <sys/types.h>
31
#include <netinet/in.h>
33
#include "pi-source.h"
35
#include "pi-syspkt.h"
36
#include "pi-header.h"
39
#ifdef HAVE_SYS_SELECT_H
40
#include <sys/select.h>
43
/* Declare prototypes */
44
void read_user(int sd);
45
void read_pilot(int sd);
50
void read_user(int sd)
53
int l = read(fileno(stdin), line, 256);
58
if (strcmp(line, "apps") == 0) {
59
sys_RemoteEvent(sd, 1, 5, 170, 0, 0, 0, 0); /* Set the pen down */
60
sys_RemoteEvent(sd, 0, 5, 170, 0, 0, 0, 0); /* And then lift it up */
61
} else if (strcmp(line, "menu") == 0) {
62
sys_RemoteEvent(sd, 1, 5, 200, 0, 0, 0, 0); /* Set the pen down */
63
sys_RemoteEvent(sd, 0, 5, 200, 0, 0, 0, 0); /* And then lift it up */
64
} else if (strcmp(line, "reboot") == 0) {
65
RPC(sd, 1, 0xA08C, 2, RPC_End);
66
} else if (strcmp(line, "coldboot") == 0) {
67
RPC(sd, 1, 0xA08B, 2, RPC_Long(0), RPC_Long(0),
68
RPC_Long(0), RPC_Long(0), RPC_End);
69
} else if (strcmp(line, "numdb") == 0) {
70
printf("Number of databases on card 0: %d\n",
71
RPC(sd, 1, 0xA043, 0, RPC_Short(0), RPC_End)
73
} else if (strcmp(line, "dbinfo") == 0) {
74
long creator, type, appInfo, sortInfo, modnum, backdate,
75
moddate, crdate, version, attr;
79
RPC(sd, 1, 0xA044, 0, RPC_Short(0), RPC_Short(0),
82
RPC(sd, 1, 0xA046, 0, RPC_Short(0), RPC_Long(id_),
84
RPC_ShortRef(attr), RPC_ShortRef(version),
85
RPC_LongRef(crdate), RPC_LongRef(moddate),
86
RPC_LongRef(backdate), RPC_LongRef(modnum),
87
RPC_LongRef(appInfo), RPC_LongRef(sortInfo),
88
RPC_LongRef(type), RPC_LongRef(creator), RPC_End);
90
printf("The name of db 0 (LocalID %x) is %s\n", id_, name);
92
} else if (strcmp(line, "quit") == 0) {
96
("unknown command '%s' (try 'apps', 'menu', 'coldboot', 'reboot', 'dbinfo', or 'quit')\n",
108
void read_pilot(int sd)
110
pi_buffer_t *buf = pi_buffer_new (4096);
111
int l = pi_read(sd, buf, 4096);
113
printf("From Palm %d:", l);
117
pi_dumpdata(buf->data, l);
119
if (buf->data[2] == 0) { /* SysPkt command */
120
if (buf->data[0] == 1) { /* Console */
121
if (buf->data[4] == 0x7f) { /* Message from Palm */
124
for (i = 6; i < l; i++)
125
if (buf->data[i] == '\r')
127
printf("%s", buf->data + 6);
132
pi_buffer_free (buf);
146
int main(int argc, char *argv[])
154
fprintf(stderr, " Usage: %s %s\n\n", argv[0], TTYPrompt);
158
sd = pi_socket(PI_AF_PILOT, PI_SOCK_STREAM, PI_PF_SYS);
160
fprintf(stderr, "Unable to create socket\n");
164
if (pi_connect(sd, argv[1]) < 0) {
165
fprintf(stderr, "Unable to connect\n");
169
/* Now we can read and write packets: to get the Palm to send a
170
packet, write a ".2" shortcut, which starts the debugging mode.
171
(Make sure to reset your Palm after finishing this example!) */
175
FD_SET(fileno(stdin), &r);
178
if (fileno(stdin) > max)
188
if (select(max + 1, &rin, 0, 0, 0) >= 0) {
189
if (FD_ISSET(fileno(stdin), &rin)) {
191
} else if (FD_ISSET(sd, &rin)) {
199
printf("\n Exiting...\n");
205
/* vi: set ts=8 sw=4 sts=4 noexpandtab: cin */
206
/* Local Variables: */
207
/* indent-tabs-mode: t */
208
/* c-basic-offset: 8 */