mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-29 13:03:37 +01:00
added --silent-mode and --fxlink-log options
This commit is contained in:
parent
c517447a02
commit
89ca11678c
2 changed files with 83 additions and 6 deletions
|
@ -20,6 +20,11 @@
|
||||||
static int last_message_was_video = 0;
|
static int last_message_was_video = 0;
|
||||||
static int video_frame_count = 0;
|
static int video_frame_count = 0;
|
||||||
|
|
||||||
|
/* external global variables coming from user arguments*/
|
||||||
|
extern bool silentmode;
|
||||||
|
extern bool loginfile;
|
||||||
|
extern char *userlogfilename;
|
||||||
|
|
||||||
static char *output_file(char const *path,char const *type,char const *suffix)
|
static char *output_file(char const *path,char const *type,char const *suffix)
|
||||||
{
|
{
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
|
@ -62,7 +67,7 @@ static bool message_new(message_t *msg, usb_fxlink_header_t const *h)
|
||||||
last_message_was_video = 0;
|
last_message_was_video = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "New message (v%d.%d): application '%.16s', type '%.16s', "
|
if (!silentmode) fprintf(stderr, "New message (v%d.%d): application '%.16s', type '%.16s', "
|
||||||
"size %d bytes", version_major, version_minor, h->application,
|
"size %d bytes", version_major, version_minor, h->application,
|
||||||
h->type, h->size);
|
h->type, h->size);
|
||||||
|
|
||||||
|
@ -103,10 +108,47 @@ static void message_finish(message_t *msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strncmp(msg->header.type, "text", 16)) {
|
if(!strncmp(msg->header.type, "text", 16)) {
|
||||||
|
|
||||||
|
/* I choose the option of maintening a console ouptut even if log in file is set */
|
||||||
|
/* this can be removed by uncommenting the following line */
|
||||||
|
|
||||||
|
//if (!loginfile)
|
||||||
|
{
|
||||||
|
if (!silentmode)
|
||||||
|
{
|
||||||
printf("------------------\n");
|
printf("------------------\n");
|
||||||
fwrite(msg->output, 1, msg->header.size, stdout);
|
fwrite(msg->output, 1, msg->header.size, stdout);
|
||||||
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
|
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
|
||||||
printf("------------------\n");
|
printf("------------------\n");
|
||||||
|
}
|
||||||
|
else if (silentmode)
|
||||||
|
{
|
||||||
|
fwrite(msg->output, 1, msg->header.size, stdout);
|
||||||
|
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (loginfile)
|
||||||
|
{
|
||||||
|
FILE *fp = fopen( userlogfilename, "a" );
|
||||||
|
if(!fp) {
|
||||||
|
err("could not save to '%s': %m", userlogfilename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!silentmode)
|
||||||
|
{
|
||||||
|
fprintf(fp, "------------------\n");
|
||||||
|
fwrite(msg->output, 1, msg->header.size, fp);
|
||||||
|
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
|
||||||
|
fprintf(fp, "------------------\n");
|
||||||
|
}
|
||||||
|
else if (silentmode)
|
||||||
|
{
|
||||||
|
fwrite(msg->output, 1, msg->header.size, fp);
|
||||||
|
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
|
||||||
|
}
|
||||||
|
fclose( fp );
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +194,7 @@ static void message_output(message_t *msg, void *buffer, int size)
|
||||||
if(msg->size_read >= msg->header.size) {
|
if(msg->size_read >= msg->header.size) {
|
||||||
bool is_video = !strncmp(msg->header.application, "fxlink", 16) &&
|
bool is_video = !strncmp(msg->header.application, "fxlink", 16) &&
|
||||||
!strncmp(msg->header.type, "video", 16);
|
!strncmp(msg->header.type, "video", 16);
|
||||||
if(!is_video)
|
if(!is_video && !silentmode)
|
||||||
fprintf(stderr, "Successfully read %d bytes\n", msg->size_read);
|
fprintf(stderr, "Successfully read %d bytes\n", msg->size_read);
|
||||||
message_finish(msg);
|
message_finish(msg);
|
||||||
msg->valid = false;
|
msg->valid = false;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
int main_test(libusb_device *device, libusb_context *context);
|
int main_test(libusb_device *device, libusb_context *context);
|
||||||
|
|
||||||
|
@ -36,6 +38,10 @@ static const char *help_string =
|
||||||
" connect. If DELAY is unspecified, wait indefinitely.\n"
|
" connect. If DELAY is unspecified, wait indefinitely.\n"
|
||||||
" -f FILTER Filter which calculators can be detected and used\n"
|
" -f FILTER Filter which calculators can be detected and used\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"
|
||||||
|
" --fxlink-log=file Log text data into a logfile called file. If file is\n"
|
||||||
|
" missing, a generic filename will be created.\n"
|
||||||
|
" --silent-mode Will turn output to the minimum value, without\n"
|
||||||
|
" decorations (no extra messages).\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Device filters:\n"
|
"Device filters:\n"
|
||||||
" A device filter is a comma-separated list of properties that a device has\n"
|
" A device filter is a comma-separated list of properties that a device has\n"
|
||||||
|
@ -55,6 +61,10 @@ static const char *help_string =
|
||||||
" serial_number=ID Matches this specific serial number. Requires write\n"
|
" serial_number=ID Matches this specific serial number. Requires write\n"
|
||||||
" access to the device in libusb. [libusb, udisks2]\n";
|
" access to the device in libusb. [libusb, udisks2]\n";
|
||||||
|
|
||||||
|
bool silentmode = false;
|
||||||
|
bool loginfile = false;
|
||||||
|
char *userlogfilename = NULL;
|
||||||
|
|
||||||
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_ERROR;
|
int rc=1, mode=0, error=0, option=0, loglevel=LIBUSB_LOG_LEVEL_ERROR;
|
||||||
|
@ -66,6 +76,8 @@ int main(int argc, char **argv)
|
||||||
//---
|
//---
|
||||||
|
|
||||||
enum { LIBUSB_LOG=1 };
|
enum { LIBUSB_LOG=1 };
|
||||||
|
enum { SILENT_MODE=2 };
|
||||||
|
enum { LOG_IN_FILE=3 };
|
||||||
const struct option longs[] = {
|
const struct option longs[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "list", no_argument, NULL, 'l' },
|
{ "list", no_argument, NULL, 'l' },
|
||||||
|
@ -73,6 +85,8 @@ int main(int argc, char **argv)
|
||||||
{ "send", no_argument, NULL, 's' },
|
{ "send", no_argument, NULL, 's' },
|
||||||
{ "interactive", no_argument, NULL, 'i' },
|
{ "interactive", no_argument, NULL, 'i' },
|
||||||
{ "libusb-log", required_argument, NULL, LIBUSB_LOG },
|
{ "libusb-log", required_argument, NULL, LIBUSB_LOG },
|
||||||
|
{ "silent-mode", no_argument, NULL, SILENT_MODE },
|
||||||
|
{ "fxlink-log", optional_argument, NULL, LOG_IN_FILE },
|
||||||
};
|
};
|
||||||
|
|
||||||
while(option >= 0 && option != '?')
|
while(option >= 0 && option != '?')
|
||||||
|
@ -101,6 +115,27 @@ int main(int argc, char **argv)
|
||||||
else fprintf(stderr, "warning: ignoring log level '%s'; should be "
|
else fprintf(stderr, "warning: ignoring log level '%s'; should be "
|
||||||
"NONE, ERROR, WARNING, INFO or DEBUG\n", optarg);
|
"NONE, ERROR, WARNING, INFO or DEBUG\n", optarg);
|
||||||
break;
|
break;
|
||||||
|
case SILENT_MODE:
|
||||||
|
printf("Enabling Silent (i.e. minimum verbosity) Mode\n");
|
||||||
|
silentmode = true;
|
||||||
|
break;
|
||||||
|
case LOG_IN_FILE:
|
||||||
|
printf("Enabling Log in File Mode\n");
|
||||||
|
loginfile = true;
|
||||||
|
if (optarg)
|
||||||
|
{
|
||||||
|
asprintf( &userlogfilename, "%s", optarg );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time_t time_raw;
|
||||||
|
struct tm time_bd;
|
||||||
|
time(&time_raw);
|
||||||
|
localtime_r(&time_raw, &time_bd);
|
||||||
|
asprintf( &userlogfilename, "./fxlink-logfile-%04d.%02d.%02d-%02dh%02d.log", time_bd.tm_year + 1900, time_bd.tm_mon + 1, time_bd.tm_mday, time_bd.tm_hour, time_bd.tm_min );
|
||||||
|
}
|
||||||
|
printf("Log File will be : %s \n", userlogfilename );
|
||||||
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
if(!optarg) {
|
if(!optarg) {
|
||||||
delay = delay_infinite();
|
delay = delay_infinite();
|
||||||
|
|
Loading…
Reference in a new issue