mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-29 13:03:37 +01:00
Merge PR #8 into dev
This commit is contained in:
commit
cd9d669275
3 changed files with 88 additions and 8 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,41 @@ 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 {
|
||||||
|
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 {
|
||||||
|
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 +188,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,12 @@ 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"
|
||||||
|
" -q, --quiet Activate quiet mode, i.e. minimum verbosity and very\n"
|
||||||
|
" limited decorations (no extra messages).\n"
|
||||||
|
" -u, --unmount Force unmount disk at the end of operations, even if\n"
|
||||||
|
" not mounted here\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 +63,11 @@ 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;
|
||||||
|
bool forceunmount = false;
|
||||||
|
|
||||||
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 +79,7 @@ int main(int argc, char **argv)
|
||||||
//---
|
//---
|
||||||
|
|
||||||
enum { LIBUSB_LOG=1 };
|
enum { LIBUSB_LOG=1 };
|
||||||
|
enum { LOG_IN_FILE=2 };
|
||||||
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,10 +87,13 @@ 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 },
|
||||||
|
{ "quiet", no_argument, NULL, 'q' },
|
||||||
|
{ "fxlink-log", optional_argument, NULL, LOG_IN_FILE },
|
||||||
|
{ "unmount", no_argument, NULL, 'u' },
|
||||||
};
|
};
|
||||||
|
|
||||||
while(option >= 0 && option != '?')
|
while(option >= 0 && option != '?')
|
||||||
switch((option = getopt_long(argc, argv, "hlbsif:w::", longs, NULL)))
|
switch((option = getopt_long(argc, argv, "hlbsiquf:w::", longs, NULL)))
|
||||||
{
|
{
|
||||||
case 'h':
|
case 'h':
|
||||||
fprintf(stderr, help_string, argv[0]);
|
fprintf(stderr, help_string, argv[0]);
|
||||||
|
@ -101,6 +118,31 @@ 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 'q':
|
||||||
|
printf("Enabling quiet mode (i.e. minimum verbosity)\n");
|
||||||
|
silentmode = true;
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
printf("Force unmount the disk at the end.\n");
|
||||||
|
forceunmount = 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();
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
// UDisks2 utility functions
|
// UDisks2 utility functions
|
||||||
//---
|
//---
|
||||||
|
|
||||||
|
extern bool forceunmount;
|
||||||
|
|
||||||
int ud2_start(UDisksClient **udc_ptr, UDisksManager **udm_ptr)
|
int ud2_start(UDisksClient **udc_ptr, UDisksManager **udm_ptr)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -358,7 +360,7 @@ int main_send(filter_t *filter, delay_t *delay, char **files)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unmount the filesystem and eject the device if we mounted it */
|
/* Unmount the filesystem and eject the device if we mounted it */
|
||||||
if(mounted_here) {
|
if(mounted_here || forceunmount) {
|
||||||
GVariant *args = g_variant_new("a{sv}", NULL);
|
GVariant *args = g_variant_new("a{sv}", NULL);
|
||||||
udisks_filesystem_call_unmount_sync(fs, args, NULL, &error);
|
udisks_filesystem_call_unmount_sync(fs, args, NULL, &error);
|
||||||
if(error) err("while unmounting %s: %s", dev, error->message);
|
if(error) err("while unmounting %s: %s", dev, error->message);
|
||||||
|
|
Loading…
Reference in a new issue