Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
avr-pager
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yids
avr-pager
Commits
875a5b1f
Commit
875a5b1f
authored
Nov 18, 2016
by
yids
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added pager-cli
parent
3a4c8ebd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
0 deletions
+116
-0
base-tx/pager-cli.c
base-tx/pager-cli.c
+94
-0
base-tx/pager-cli.h
base-tx/pager-cli.h
+22
-0
No files found.
base-tx/pager-cli.c
0 → 100644
View file @
875a5b1f
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "../libs/pagerlib/pagerlib.h"
#include "pager-cli.h"
struct
pl_ctx
*
ctx
;
int
list_pubkeys
()
{
pl_print_public_keylist
(
ctx
);
return
0
;
}
int
send_message
()
{
char
*
addr
;
char
*
msg
;
list_pubkeys
();
addr
=
readline
(
"Enter receiver address: "
);
if
(
pl_set_receiver_by_address
(
ctx
,
atoi
(
addr
))
==
0
)
printf
(
"setting receiver to %s
\n
"
,
addr
);
else
{
printf
(
"public key not found :(
\n
"
);
return
0
;
}
msg
=
readline
(
"Type your message:
\n
"
);
memcpy
(
ctx
->
msg
->
msg
,
msg
,
MSG_SIZE
);
switch
(
pl_send_message
(
ctx
))
{
// send msg
case
0
:
printf
(
"SEND: OK!
\n
"
);
break
;
case
-
1
:
printf
(
"SEND: -1
\n
"
);
break
;
case
-
2
:
printf
(
"SEND: -2
\n
"
);
break
;
case
-
3
:
printf
(
"SEND: -3
\n
"
);
break
;
default:
printf
(
"SEND: unknown error
\n
"
);
break
;
}
pl_send_message_fifo
(
ctx
,
"/tmp/pager"
);
return
0
;
}
int
help
()
{
for
(
int
i
=
0
;
i
<
(
sizeof
(
commands
)
/
sizeof
(
COMMAND
))
;
i
++
)
{
printf
(
"%s : %s
\n
"
,
commands
[
i
].
name
,
commands
[
i
].
doc
);
}
}
int
quit
()
{
printf
(
"Quitting...
\n
"
);
return
0
;
}
int
main
()
{
ctx
=
pl_init
();
pl_load_keypair
(
ctx
,
"tx"
);
pl_load_public_keys_from_folder
(
ctx
,
"pubkeys"
);
char
*
input
;
for
(;;)
{
input
=
readline
(
"pager-cli: "
);
for
(
int
i
=
0
;
i
<
(
sizeof
(
commands
)
/
sizeof
(
COMMAND
))
;
i
++
)
{
if
(
strncmp
(
commands
[
i
].
name
,
input
,
20
)
==
0
)
{
((
*
(
commands
[
i
].
func
))
(
input
));
break
;
}
//printf("%s: command not found\n",input);
//break;
}
}
return
0
;
}
base-tx/pager-cli.h
0 → 100644
View file @
875a5b1f
int
list_pubkeys
();
int
send_message
();
int
help
();
int
quit
();
/* structure for the commands */
typedef
struct
{
char
*
name
;
/* User printable name of the function. */
rl_icpfunc_t
*
func
;
/* Function to call to do the job. */
char
*
doc
;
/* Documentation for this function. */
}
COMMAND
;
static
COMMAND
commands
[]
=
{
{
"listPublicKeys"
,
list_pubkeys
,
"Shows a list of the loaded public keys"
},
{
"sendMessage"
,
send_message
,
"Sends a message"
},
{
"help"
,
help
,
"Shows help"
},
{
"quit"
,
quit
,
"Exits pager-cli"
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment