mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-29 13:03:37 +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;
|
||||
/* Extra details (mainly interactive messages) */
|
||||
bool verbose;
|
||||
bool write_to_socket;
|
||||
};
|
||||
|
||||
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 */
|
||||
int main_list(struct fxlink_filter *filter, delay_t *delay,
|
||||
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 Wait indefinitely for a calculator to connect\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"
|
||||
"\n"
|
||||
"Mode-specific options:\n"
|
||||
|
@ -62,6 +63,10 @@ static const char *help_string =
|
|||
/* Global 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 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.verbose = false;
|
||||
|
||||
options.write_to_socket = false;
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
//---
|
||||
|
@ -108,6 +113,10 @@ int main(int argc, char **argv)
|
|||
case 'l':
|
||||
case 'b':
|
||||
case 's':
|
||||
options.write_to_socket = true;
|
||||
socket_in = argv[optind];
|
||||
socket_out = argv[optind+1];
|
||||
break;
|
||||
case 'i':
|
||||
case 't':
|
||||
case 'p':
|
||||
|
|
|
@ -39,10 +39,18 @@ static void handle_new_message(struct fxlink_device *fdev,
|
|||
}
|
||||
|
||||
if(fxlink_message_is_fxlink_text(msg)) {
|
||||
char const *str = msg->data;
|
||||
|
||||
char *str = msg->data;
|
||||
str[msg->size] = '\0';
|
||||
if(options.verbose)
|
||||
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);
|
||||
#if 0
|
||||
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];
|
||||
/* Current message */
|
||||
struct fxlink_transfer *tr = NULL;
|
||||
|
||||
FILE *fptr;
|
||||
char c[100];
|
||||
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();
|
||||
|
||||
int transferred = -1;
|
||||
|
@ -140,6 +160,8 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay,
|
|||
}
|
||||
if(transferred <= 0)
|
||||
continue;
|
||||
|
||||
|
||||
|
||||
/* Either start a new message or continue an unfinished one */
|
||||
if(tr == NULL)
|
||||
|
@ -156,7 +178,6 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay,
|
|||
tr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Warning for unfinished transfer */
|
||||
if(tr) {
|
||||
wlog("unfinished transfer interrupted by disconnection\n");
|
||||
|
|
Loading…
Reference in a new issue