Skip to content

Commit

Permalink
Enhance logging
Browse files Browse the repository at this point in the history
  • Loading branch information
blemasle authored and asalamon74 committed Feb 13, 2021
1 parent bdba056 commit 5f32c9e
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cli: $(CLI_TARGET)
gui: $(GUI_TARGET)

MANS = pktriggercord-cli.1 pktriggercord.1
SRCOBJNAMES = pslr pslr_enum pslr_scsi pslr_lens pslr_model pktriggercord-servermode
SRCOBJNAMES = pslr pslr_enum pslr_scsi pslr_log pslr_lens pslr_model pktriggercord-servermode
OBJS = $(SRCOBJNAMES:=.o) $(JSONDIR)/js0n.o
WIN_DLLS_DIR=win_dlls
SOURCE_PACKAGE_FILES = Makefile Changelog COPYING INSTALL BUGS $(MANS) pentax_scsi_protocol.md pentax.rules samsung.rules $(SRCOBJNAMES:=.h) $(SRCOBJNAMES:=.c) pslr_scsi_linux.c pslr_scsi_win.c pslr_scsi_openbsd.c exiftool_pentax_lens.txt pktriggercord.c pktriggercord-cli.c pktriggercord.ui pentax_settings.json $(SPECFILE) android_scsi_sg.h rad10/ src/
Expand Down
1 change: 1 addition & 0 deletions android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := pktriggercord-cli
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../src/external/js0n/
LOCAL_SRC_FILES := ../../src/external/js0n/js0n.c \
../../pslr_log.c \
../../pslr_enum.c \
../../pslr_lens.c \
../../pslr_model.c \
Expand Down
93 changes: 40 additions & 53 deletions pktriggercord-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@

#include "pslr.h"
#include "pktriggercord-servermode.h"
#include "pslr_log.h"

#ifdef WIN32
#define FILE_ACCESS O_WRONLY | O_CREAT | O_TRUNC | O_BINARY
#else
#define FILE_ACCESS O_WRONLY | O_CREAT | O_TRUNC
#endif

bool debug = false;
bool warnings = false;

const char *shortopts = "m:q:a:r:d:t:o:i:F:fghvsSw";

pslr_settings settings;
Expand Down Expand Up @@ -270,24 +268,13 @@ int open_file(char* output_file, int frameNo, user_file_format_t ufft) {
snprintf(fileName, 256, "%.*s-%04d.%s", prefix_length, output_file, frameNo, ufft.extension);
ofd = open(fileName, FILE_ACCESS, 0664);
if (ofd == -1) {
fprintf(stderr, "Could not open %s\n", output_file);
pslr_write_log(PSLR_ERROR, "Could not open %s\n", output_file);
return -1;
}
}
return ofd;
}

void warning_message( const char* message, ... ) {
if ( warnings ) {
// Write to stderr
//
va_list argp;
va_start(argp, message);
vfprintf( stderr, message, argp );
va_end(argp);
}
}

void process_wbadj( const char* argv0, const char chr, uint32_t adj, uint32_t *wbadj_mg, uint32_t *wbadj_ba ) {
if ( chr == 'M' ) {
*wbadj_mg = 7 - adj;
Expand All @@ -298,7 +285,7 @@ void process_wbadj( const char* argv0, const char chr, uint32_t adj, uint32_t *w
} else if ( chr == 'A' ) {
*wbadj_ba = 7 + adj;
} else {
warning_message("%s: Invalid white_balance_adjustment\n", argv0);
pslr_write_log(PSLR_WARNING, "%s: Invalid white_balance_adjustment\n", argv0);
}
}

Expand Down Expand Up @@ -346,15 +333,15 @@ void bulb_new(pslr_handle_t camhandle, pslr_rational_t shutter_speed) {
} else if (pslr_has_setting_by_name(camhandle, "astrotracer")) {
pslr_set_setting_by_name(camhandle, "astrotracer", 1);
} else {
fprintf(stderr, "New bulb mode is not supported for this camera model\n");
pslr_write_log(PSLR_ERROR, "New bulb mode is not supported for this camera model\n");
}
int bulb_sec = (int)(shutter_speed.nom / shutter_speed.denom);
if (pslr_has_setting_by_name(camhandle, "bulb_timer_sec")) {
pslr_set_setting_by_name(camhandle, "bulb_timer_sec", bulb_sec);
} else if (pslr_has_setting_by_name(camhandle, "astrotracer_timer_sec")) {
pslr_set_setting_by_name(camhandle, "astrotracer_timer_sec", bulb_sec);
} else {
fprintf(stderr, "New bulb mode is not supported for this camera model\n");
pslr_write_log(PSLR_ERROR, "New bulb mode is not supported for this camera model\n");
}
pslr_shutter(camhandle);
}
Expand Down Expand Up @@ -445,19 +432,19 @@ int main(int argc, char **argv) {
usage(argv[0]);
exit(-1);
case 'w':
warnings = true;
pslr_set_verbosity(PSLR_WARNING);
break;
case 17:
warnings = false;
pslr_set_verbosity(PSLR_ERROR);
break;
case 4:
debug = true;
pslr_set_verbosity(PSLR_DEBUG);
DPRINT( "Debug messaging is now enabled.\n" );
break;
}
}

if (debug) {
if (PSLR_DEBUG_ENABLED) {
DPRINT("command line:\n%s\n", command_line(argc, argv));
}

Expand Down Expand Up @@ -486,7 +473,7 @@ int main(int argc, char **argv) {
} else if (!strcmp(optarg, "JPEG") || !strcmp(optarg, "JPG")) {
uff = USER_FILE_FORMAT_JPEG;
} else {
warning_message("%s: Invalid file format.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid file format.\n", argv[0]);
}
break;

Expand Down Expand Up @@ -526,7 +513,7 @@ int main(int argc, char **argv) {
} else if (!strcmp(optarg, "X")) {
EM = PSLR_EXPOSURE_MODE_X;
} else {
warning_message("%s: Invalid exposure mode.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid exposure mode.\n", argv[0]);
}
break;

Expand All @@ -537,36 +524,36 @@ int main(int argc, char **argv) {
case 7:
color_space = pslr_get_color_space( optarg );
if ( color_space == (pslr_color_space_t)(-1) ) {
warning_message("%s: Invalid color space\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid color space\n", argv[0]);
}
break;

case 8:
af_mode = pslr_get_af_mode( optarg );
if ( af_mode == (pslr_af_mode_t)(-1) || af_mode == (pslr_af_mode_t)(0) ) {
// 0: changing MF does not work
warning_message("%s: Invalid af mode\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid af mode\n", argv[0]);
}
break;

case 9:
ae_metering = pslr_get_ae_metering( optarg );
if ( ae_metering == (pslr_ae_metering_t)(-1) ) {
warning_message("%s: Invalid ae metering\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid ae metering\n", argv[0]);
}
break;

case 10:
flash_mode = pslr_get_flash_mode( optarg );
if ( flash_mode == (pslr_flash_mode_t)(-1) ) {
warning_message("%s: Invalid flash_mode\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid flash_mode\n", argv[0]);
}
break;

case 11:
drive_mode = pslr_get_drive_mode( optarg );
if ( drive_mode == (pslr_drive_mode_t)(-1) ) {
warning_message("%s: Invalid drive_mode\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid drive_mode\n", argv[0]);
}
break;

Expand All @@ -577,22 +564,22 @@ int main(int argc, char **argv) {
if (af_point_selected != 0) {
af_point_sel = PSLR_AF_POINT_SEL_SELECT;
} else {
warning_message("%s: Invalid select af point: %s\n", argv[0], optarg);
pslr_write_log(PSLR_WARNING, "%s: Invalid select af point: %s\n", argv[0], optarg);
}
}
break;

case 13:
jpeg_image_tone = pslr_get_jpeg_image_tone( optarg );
if ( jpeg_image_tone == -1 ) {
warning_message("%s: Invalid jpeg_image_tone\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg_image_tone\n", argv[0]);
}
break;

case 14:
white_balance_mode = pslr_get_white_balance_mode( optarg );
if ( white_balance_mode == (pslr_white_balance_mode_t)(-1) ) {
warning_message("%s: Invalid white_balance_mode\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid white_balance_mode\n", argv[0]);
}
break;

Expand All @@ -606,7 +593,7 @@ int main(int argc, char **argv) {
process_wbadj( argv[0], c2, adj2, &white_balance_adjustment_mg, &white_balance_adjustment_ba );
}
} else {
warning_message("%s: Invalid white_balance_adjustment\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid white_balance_adjustment\n", argv[0]);
}
break;

Expand All @@ -629,21 +616,21 @@ int main(int argc, char **argv) {
case 'q':
quality = atoi(optarg);
if (!quality) {
warning_message("%s: Invalid jpeg quality\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg quality\n", argv[0]);
}
break;

case 'a':
aperture = parse_aperture(optarg);
if (aperture.nom == 0) {
warning_message( "%s: Invalid aperture value.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid aperture value.\n", argv[0]);
}
break;

case 't':
shutter_speed = parse_shutter_speed(optarg);
if (shutter_speed.nom == 0) {
warning_message("%s: Invalid shutter speed value: %s\n", argv[0], optarg);
pslr_write_log(PSLR_WARNING, "%s: Invalid shutter speed value: %s\n", argv[0], optarg);
}
break;

Expand All @@ -666,15 +653,15 @@ int main(int argc, char **argv) {
case 'F':
frames = atoi(optarg);
if (frames > 9999) {
warning_message("%s: Invalid frame number.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid frame number.\n", argv[0]);
frames = 9999;
}
break;

case 'd':
delay = atoi(optarg);
if (!delay) {
warning_message("%s: Invalid delay value\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid delay value\n", argv[0]);
}
break;

Expand All @@ -685,7 +672,7 @@ int main(int argc, char **argv) {
iso = atoi(optarg);
}
if (iso==0 && auto_iso_min==0) {
warning_message("%s: Invalid iso value\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid iso value\n", argv[0]);
exit(-1);
}
break;
Expand Down Expand Up @@ -753,7 +740,7 @@ int main(int argc, char **argv) {
mult = 1024;
break;
default:
warning_message("%s: Invalid dump memory size: %s\n", argv[0], optarg);
pslr_write_log(PSLR_WARNING, "%s: Invalid dump memory size: %s\n", argv[0], optarg);

}
dump_memory_size *= mult;
Expand All @@ -771,13 +758,13 @@ int main(int argc, char **argv) {
servermode_socket(servermode_timeout);
exit(0);
#else
fprintf(stderr, "Servermode is not supported in Windows\n");
pslr_write_log(PSLR_ERROR, "Servermode is not supported in Windows\n");
exit(-1);
#endif
}

if (!output_file && !output_file_stdout && frames > 0) {
fprintf(stderr, "Should specify output filename (use '-o -' if you really want to output to stdout)\n");
pslr_write_log(PSLR_ERROR, "Should specify output filename (use '-o -' if you really want to output to stdout)\n");
exit(-1);
}

Expand All @@ -802,7 +789,7 @@ int main(int argc, char **argv) {
if ( dump_memory_size > 0 ) {
int dfd = open(DUMP_FILE_NAME, FILE_ACCESS, 0664);
if (dfd == -1) {
fprintf(stderr, "Could not open %s\n", DUMP_FILE_NAME);
pslr_write_log(PSLR_ERROR, "Could not open %s\n", DUMP_FILE_NAME);
return -1;
} else {
printf("Dumping system memory to %s\n", DUMP_FILE_NAME);
Expand Down Expand Up @@ -847,7 +834,7 @@ int main(int argc, char **argv) {

if ( jpeg_image_tone != -1 ) {
if ( jpeg_image_tone > pslr_get_model_max_supported_image_tone(camhandle) ) {
warning_message("%s: Invalid jpeg image tone setting.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg image tone setting.\n", argv[0]);
}
pslr_set_jpeg_image_tone( camhandle, jpeg_image_tone );
}
Expand Down Expand Up @@ -885,7 +872,7 @@ int main(int argc, char **argv) {

if (quality>-1) {
if ( quality > pslr_get_model_max_jpeg_stars(camhandle) ) {
warning_message("%s: Invalid jpeg quality setting.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg quality setting.\n", argv[0]);
}
pslr_set_jpeg_stars(camhandle, quality);
}
Expand Down Expand Up @@ -918,33 +905,33 @@ int main(int argc, char **argv) {
}

if (EM != PSLR_EXPOSURE_MODE_MAX && status.exposure_mode != EM) {
warning_message( "%s: Cannot set %s mode; set the mode dial to %s or USER\n", argv[0], MODESTRING, MODESTRING);
pslr_write_log(PSLR_WARNING, "%s: Cannot set %s mode; set the mode dial to %s or USER\n", argv[0], MODESTRING, MODESTRING);
}

if (shutter_speed.nom) {
DPRINT("shutter_speed.nom=%d\n", shutter_speed.nom);
DPRINT("shutter_speed.denom=%d\n", shutter_speed.denom);

if (shutter_speed.nom <= 0 || (shutter_speed.nom > 30 && status.exposure_mode != PSLR_GUI_EXPOSURE_MODE_B ) || shutter_speed.denom <= 0 || shutter_speed.denom > pslr_get_model_fastest_shutter_speed(camhandle)) {
warning_message("%s: Invalid shutter speed value.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Invalid shutter speed value.\n", argv[0]);
}

pslr_set_shutter(camhandle, shutter_speed);
} else if ( status.exposure_mode == PSLR_GUI_EXPOSURE_MODE_B ) {
warning_message("%s: Shutter speed not specified in Bulb mode. Using 30s.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Shutter speed not specified in Bulb mode. Using 30s.\n", argv[0]);
shutter_speed.nom = 30;
shutter_speed.denom = 1;
}

if (aperture.nom) {
if ((aperture.nom * status.lens_max_aperture.denom) > (aperture.denom * status.lens_max_aperture.nom)) {
warning_message("%s: Warning, selected aperture is smaller than this lens minimum aperture.\n", argv[0]);
warning_message("%s: Setting aperture to f:%d\n", argv[0], status.lens_max_aperture.nom / status.lens_max_aperture.denom);
pslr_write_log(PSLR_WARNING, "%s: Warning, selected aperture is smaller than this lens minimum aperture.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Setting aperture to f:%d\n", argv[0], status.lens_max_aperture.nom / status.lens_max_aperture.denom);
}

if ((aperture.nom * status.lens_min_aperture.denom) < (aperture.denom * status.lens_min_aperture.nom)) {
warning_message( "%s: Warning, selected aperture is wider than this lens maximum aperture.\n", argv[0]);
warning_message( "%s: Setting aperture to f:%.1f\n", argv[0], (float) status.lens_min_aperture.nom / (float) status.lens_min_aperture.denom);
pslr_write_log(PSLR_WARNING, "%s: Warning, selected aperture is wider than this lens maximum aperture.\n", argv[0]);
pslr_write_log(PSLR_WARNING, "%s: Setting aperture to f:%.1f\n", argv[0], (float) status.lens_min_aperture.nom / (float) status.lens_min_aperture.denom);
}


Expand Down Expand Up @@ -972,7 +959,7 @@ int main(int argc, char **argv) {
exit(0);
}

if (read_firmware_version || debug) {
if (read_firmware_version || PSLR_DEBUG_ENABLED) {
char firmware[16];
pslr_get_dspinfo( camhandle, firmware );
if (!read_firmware_version) {
Expand Down
Loading

0 comments on commit 5f32c9e

Please sign in to comment.