Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve spirit agent #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Spirit/Install.HC
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#define INS_DIR "~/Spirit"
#define INS_DIR "::/Apps/Spirit"

if (!FileFind(INS_DIR,, FUF_JUST_DIRS))
DirMk(INS_DIR);

Cd(__DIR__);
CopyTree("*", INS_DIR, FALSE);

"\n";
Expand Down
21 changes: 17 additions & 4 deletions Spirit/Spirit.HC
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ Bool GrabPutS(U8 *str)
#define CMD_EXECUTE "Exec"
#define CMD_CLIP_SET "ClipSet"
#define CMD_CLIP_GET "ClipGet"
#define CMD_PING "Ping"

#define LINE_END "\r\n"
#define RESP_UNKNOWN_CMD "Unknown command" LINE_END
#define RESP_PONG "Pong" LINE_END

#define RESP_UNKNOWN_CMD "Unknown command\r\n"
U8* SpiritDefaultHandler()
{
return MStrPrint(RESP_UNKNOWN_CMD);
Expand Down Expand Up @@ -156,11 +160,17 @@ U8*SpiritCmdClipGet()
return clip;
}

U8* (*handlers)()[4] = {
U8* SpiritCmdPing()
{
return MStrPrint(RESP_PONG);
}

U8* (*handlers)()[5] = {
&SpiritCmdUserTask,
&SpiritCmdExecute,
&SpiritCmdClipSet,
&SpiritCmdClipGet
&SpiritCmdClipGet,
&SpiritCmdPing
};

U0 LoadCommands()
Expand All @@ -170,7 +180,9 @@ U0 LoadCommands()
CMD_USER_TASK "\0"
CMD_EXECUTE "\0"
CMD_CLIP_SET "\0"
CMD_CLIP_GET "\0");
CMD_CLIP_GET "\0"
CMD_PING "\0"
);
}

U0 WaitCommand(){
Expand Down Expand Up @@ -211,3 +223,4 @@ U0 StartUpSpirit()
"Spirit guest agent"
);
}

5 changes: 3 additions & 2 deletions SpiritApi/C/src/app.c → SpiritApi/C/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ void usage(int exitCode, const char *errorMsg, ...)
"Options:\n"
" -h\t\t\tPrint usage message.\n"
" -c\t\t\tSet connection information, format:\n"
"\t\t\t<tcp:host:port>, example -p tcp:localhost:1234\n"
"\t\t\t<unix:unix-socket.file>, example -p unix:/tmp/serial.socket\n"
"\t\t\t<tcp:host:port>, example -c tcp:localhost:1234\n"
"\t\t\t<unix:unix-socket.file>, example -c unix:/tmp/serial.socket\n"
"Operations:\n"
" user <command>\tSpawn a task and execute the command.\n"
" exec <command>\tExecute the command silently and return the result.\n"
" clip-get\t\tSet host system's clibpoard to the TempleOS clipboard content.\n"
" clip-set\t\tSet TempleOS clipboard content to the host system's clipboard.\n"
" ping\t\tPing Spirit agent.\n"
,
program_invocation_short_name);

Expand Down
5 changes: 4 additions & 1 deletion SpiritApi/C/src/spirit.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ void spiritExec(struct SpiritConnection spirit, int argc, char **argv)
spiritSendStr(spirit, "clipSet");
spiritSendStr(spirit, argv[1]);
} else {
usage(EXIT_FAILURE, "Unknown operation `%s`.", op);
spiritSendStr(spirit, op);
for (int i = 2; i < argc; ++i) {
spiritSendStr(spirit, argv[i]);
}
}

char *r = rs232RecvPackage(spirit.socket);
Expand Down
Binary file modified Supplemental.ISO.C
Binary file not shown.
Binary file modified TOSC_Theme/Theme.HC
Binary file not shown.