Skip to content

Commit c376b6a

Browse files
authored
Improve spirit agent
Improve spirit agent
2 parents eaecf75 + ba720c3 commit c376b6a

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

Spirit/Install.HC

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#define INS_DIR "~/Spirit"
1+
#define INS_DIR "::/Apps/Spirit"
22

33
if (!FileFind(INS_DIR,, FUF_JUST_DIRS))
44
DirMk(INS_DIR);
55

6+
Cd(__DIR__);
67
CopyTree("*", INS_DIR, FALSE);
78

89
"\n";

Spirit/Spirit.HC

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ Bool GrabPutS(U8 *str)
9797
#define CMD_EXECUTE "Exec"
9898
#define CMD_CLIP_SET "ClipSet"
9999
#define CMD_CLIP_GET "ClipGet"
100+
#define CMD_PING "Ping"
101+
102+
#define LINE_END "\r\n"
103+
#define RESP_UNKNOWN_CMD "Unknown command" LINE_END
104+
#define RESP_PONG "Pong" LINE_END
100105

101-
#define RESP_UNKNOWN_CMD "Unknown command\r\n"
102106
U8* SpiritDefaultHandler()
103107
{
104108
return MStrPrint(RESP_UNKNOWN_CMD);
@@ -156,11 +160,17 @@ U8*SpiritCmdClipGet()
156160
return clip;
157161
}
158162

159-
U8* (*handlers)()[4] = {
163+
U8* SpiritCmdPing()
164+
{
165+
return MStrPrint(RESP_PONG);
166+
}
167+
168+
U8* (*handlers)()[5] = {
160169
&SpiritCmdUserTask,
161170
&SpiritCmdExecute,
162171
&SpiritCmdClipSet,
163-
&SpiritCmdClipGet
172+
&SpiritCmdClipGet,
173+
&SpiritCmdPing
164174
};
165175

166176
U0 LoadCommands()
@@ -170,7 +180,9 @@ U0 LoadCommands()
170180
CMD_USER_TASK "\0"
171181
CMD_EXECUTE "\0"
172182
CMD_CLIP_SET "\0"
173-
CMD_CLIP_GET "\0");
183+
CMD_CLIP_GET "\0"
184+
CMD_PING "\0"
185+
);
174186
}
175187

176188
U0 WaitCommand(){
@@ -211,3 +223,4 @@ U0 StartUpSpirit()
211223
"Spirit guest agent"
212224
);
213225
}
226+
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ void usage(int exitCode, const char *errorMsg, ...)
2121
"Options:\n"
2222
" -h\t\t\tPrint usage message.\n"
2323
" -c\t\t\tSet connection information, format:\n"
24-
"\t\t\t<tcp:host:port>, example -p tcp:localhost:1234\n"
25-
"\t\t\t<unix:unix-socket.file>, example -p unix:/tmp/serial.socket\n"
24+
"\t\t\t<tcp:host:port>, example -c tcp:localhost:1234\n"
25+
"\t\t\t<unix:unix-socket.file>, example -c unix:/tmp/serial.socket\n"
2626
"Operations:\n"
2727
" user <command>\tSpawn a task and execute the command.\n"
2828
" exec <command>\tExecute the command silently and return the result.\n"
2929
" clip-get\t\tSet host system's clibpoard to the TempleOS clipboard content.\n"
3030
" clip-set\t\tSet TempleOS clipboard content to the host system's clipboard.\n"
31+
" ping\t\tPing Spirit agent.\n"
3132
,
3233
program_invocation_short_name);
3334

SpiritApi/C/src/spirit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ void spiritExec(struct SpiritConnection spirit, int argc, char **argv)
161161
spiritSendStr(spirit, "clipSet");
162162
spiritSendStr(spirit, argv[1]);
163163
} else {
164-
usage(EXIT_FAILURE, "Unknown operation `%s`.", op);
164+
spiritSendStr(spirit, op);
165+
for (int i = 2; i < argc; ++i) {
166+
spiritSendStr(spirit, argv[i]);
167+
}
165168
}
166169

167170
char *r = rs232RecvPackage(spirit.socket);

Supplemental.ISO.C

0 Bytes
Binary file not shown.

TOSC_Theme/Theme.HC

9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)