mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2025-01-01 14:33:35 +01:00
Potter360 : add -s option to use socket
This commit is contained in:
parent
09e2cf5fda
commit
eeffbc46f2
3 changed files with 40 additions and 5 deletions
|
@ -16,10 +16,15 @@ struct fxlink_options {
|
||||||
FILE *log_file;
|
FILE *log_file;
|
||||||
/* Extra details (mainly interactive messages) */
|
/* Extra details (mainly interactive messages) */
|
||||||
bool verbose;
|
bool verbose;
|
||||||
|
bool write_to_socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct fxlink_options options;
|
extern struct fxlink_options options;
|
||||||
|
|
||||||
|
/* Input/output socket filename in case of -s option */
|
||||||
|
extern char* socket_in;
|
||||||
|
extern char* socket_out;
|
||||||
|
|
||||||
/* Main function for -l */
|
/* Main function for -l */
|
||||||
int main_list(struct fxlink_filter *filter, delay_t *delay,
|
int main_list(struct fxlink_filter *filter, delay_t *delay,
|
||||||
libusb_context *context);
|
libusb_context *context);
|
||||||
|
|
|
@ -41,6 +41,7 @@ static const char *help_string =
|
||||||
" -w <SECONDS> Wait this many seconds for a calculator to connect\n"
|
" -w <SECONDS> Wait this many seconds for a calculator to connect\n"
|
||||||
" -w Wait indefinitely for a calculator to connect\n"
|
" -w Wait indefinitely for a calculator to connect\n"
|
||||||
" -f <FILTER> Filter which calculators we connect to (see below)\n"
|
" -f <FILTER> Filter which calculators we connect to (see below)\n"
|
||||||
|
" -s <IN> <OUT> Send received data to IN file and send data in OUT file to calculator\n"
|
||||||
" --libusb-log=LEVEL libusb log level (NONE, ERROR, WARNING, INFO, DEBUG)\n"
|
" --libusb-log=LEVEL libusb log level (NONE, ERROR, WARNING, INFO, DEBUG)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Mode-specific options:\n"
|
"Mode-specific options:\n"
|
||||||
|
@ -62,6 +63,10 @@ static const char *help_string =
|
||||||
/* Global options */
|
/* Global options */
|
||||||
struct fxlink_options options;
|
struct fxlink_options options;
|
||||||
|
|
||||||
|
/* Input/output socket filenames for -s option */
|
||||||
|
char *socket_in;
|
||||||
|
char *socket_out;
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int rc=1, mode=0, error=0, option=0, loglevel=LIBUSB_LOG_LEVEL_WARNING;
|
int rc=1, mode=0, error=0, option=0, loglevel=LIBUSB_LOG_LEVEL_WARNING;
|
||||||
|
@ -72,7 +77,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
options.log_file = NULL;
|
options.log_file = NULL;
|
||||||
options.verbose = false;
|
options.verbose = false;
|
||||||
|
options.write_to_socket = false;
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
//---
|
//---
|
||||||
|
@ -108,6 +113,10 @@ int main(int argc, char **argv)
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'b':
|
case 'b':
|
||||||
case 's':
|
case 's':
|
||||||
|
options.write_to_socket = true;
|
||||||
|
socket_in = argv[optind];
|
||||||
|
socket_out = argv[optind+1];
|
||||||
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
case 't':
|
case 't':
|
||||||
case 'p':
|
case 'p':
|
||||||
|
|
|
@ -39,10 +39,18 @@ static void handle_new_message(struct fxlink_device *fdev,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fxlink_message_is_fxlink_text(msg)) {
|
if(fxlink_message_is_fxlink_text(msg)) {
|
||||||
char const *str = msg->data;
|
char *str = msg->data;
|
||||||
|
str[msg->size] = '\0';
|
||||||
if(options.verbose)
|
if(options.verbose)
|
||||||
printf("------------------\n");
|
printf("------------------\n");
|
||||||
|
if(options.write_to_socket)
|
||||||
|
{
|
||||||
|
FILE *fPtr;
|
||||||
|
fPtr = fopen(socket_in, "a");
|
||||||
|
fputs(str, fPtr);
|
||||||
|
fputs("\n\0",fPtr);
|
||||||
|
fclose(fPtr);
|
||||||
|
}
|
||||||
fwrite(str, 1, msg->size, stdout);
|
fwrite(str, 1, msg->size, stdout);
|
||||||
#if 0
|
#if 0
|
||||||
if(str[msg->size - 1] != '\n') {
|
if(str[msg->size - 1] != '\n') {
|
||||||
|
@ -120,8 +128,20 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay,
|
||||||
static uint8_t buffer[2048];
|
static uint8_t buffer[2048];
|
||||||
/* Current message */
|
/* Current message */
|
||||||
struct fxlink_transfer *tr = NULL;
|
struct fxlink_transfer *tr = NULL;
|
||||||
|
FILE *fptr;
|
||||||
|
char c[100];
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
||||||
|
if(options.write_to_socket)
|
||||||
|
{
|
||||||
|
if ((fptr = fopen(socket_out, "r"))) {
|
||||||
|
fscanf(fptr, "%[^\n]", c);
|
||||||
|
printf("%i",strlen(c));
|
||||||
|
fxlink_device_start_bulk_OUT(fdev,"fxlink", "text", &c, strlen(c), false);
|
||||||
|
remove(socket_out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fxlink_sdl2_handle_events();
|
fxlink_sdl2_handle_events();
|
||||||
|
|
||||||
int transferred = -1;
|
int transferred = -1;
|
||||||
|
@ -141,6 +161,8 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay,
|
||||||
if(transferred <= 0)
|
if(transferred <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Either start a new message or continue an unfinished one */
|
/* Either start a new message or continue an unfinished one */
|
||||||
if(tr == NULL)
|
if(tr == NULL)
|
||||||
tr = fxlink_transfer_make_IN(buffer, transferred);
|
tr = fxlink_transfer_make_IN(buffer, transferred);
|
||||||
|
@ -156,7 +178,6 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay,
|
||||||
tr = NULL;
|
tr = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Warning for unfinished transfer */
|
/* Warning for unfinished transfer */
|
||||||
if(tr) {
|
if(tr) {
|
||||||
wlog("unfinished transfer interrupted by disconnection\n");
|
wlog("unfinished transfer interrupted by disconnection\n");
|
||||||
|
|
Loading…
Reference in a new issue