Skip to content

Commit

Permalink
Embed instrument IP address in screenshot filename
Browse files Browse the repository at this point in the history
This helps identify screenshot files when capturing screenshots from
multiple instruments.

It also allows to simplify the APIs used by the screenshot plugins.
  • Loading branch information
lundmar committed Nov 10, 2017
1 parent 86cf35f commit 080681f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/include/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ void screenshot_list_plugins(void);
int screenshot(char *address, char *plugin_name, char *filename, int timeout);

// Screenshot helper function used by plugins to dump image file
void screenshot_file_dump(void *data, int length, char *filename, char *format);
void screenshot_file_dump(void *data, int length, char *format);

struct screenshot_plugin
{
const char *name;
const char *description;
const char *regex;
int (*screenshot)(char *address, char *filename, int timeout);
int (*screenshot)(char *address, int timeout);
};
4 changes: 2 additions & 2 deletions src/plugins/screenshot_keysight.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define IMAGE_SIZE_MAX 0x400000 // 4 MB

int keysight_screenshot(char *address, char *filename, int timeout)
int keysight_screenshot(char *address, int timeout)
{
char response[IMAGE_SIZE_MAX];
char *command, *image;
Expand Down Expand Up @@ -77,7 +77,7 @@ int keysight_screenshot(char *address, char *filename, int timeout)
length--;

// Dump remaining PNG image data to file
screenshot_file_dump(image, length, filename, "png");
screenshot_file_dump(image, length, "png");

// Disconnect
lxi_disconnect(device);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/screenshot_rigol-1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define IMAGE_SIZE_MAX 0x400000 // 4 MB

int rigol_1000_screenshot(char *address, char *filename, int timeout)
int rigol_1000_screenshot(char *address, int timeout)
{
char response[IMAGE_SIZE_MAX];
char *command, *image;
Expand Down Expand Up @@ -72,7 +72,7 @@ int rigol_1000_screenshot(char *address, char *filename, int timeout)
length -= n+2;

// Dump remaining PNG image data to file
screenshot_file_dump(image, length, filename, "png");
screenshot_file_dump(image, length, "png");

// Disconnect
lxi_disconnect(device);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/screenshot_rigol-2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define IMAGE_SIZE_MAX 0x400000 // 4 MB

int rigol_2000_screenshot(char *address, char *filename, int timeout)
int rigol_2000_screenshot(char *address, int timeout)
{
char response[IMAGE_SIZE_MAX];
char *command, *image;
Expand Down Expand Up @@ -75,7 +75,7 @@ int rigol_2000_screenshot(char *address, char *filename, int timeout)
length--;

// Dump remaining BMP image data to file
screenshot_file_dump(image, length, filename, "bmp");
screenshot_file_dump(image, length, "bmp");

// Disconnect
lxi_disconnect(device);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/screenshot_rohde-schwarz.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define IMAGE_SIZE_MAX 0x400000 // 4 MB

int rs_screenshot(char *address, char *filename, int timeout)
int rs_screenshot(char *address, int timeout)
{
char response[IMAGE_SIZE_MAX];
char *command, *image;
Expand Down Expand Up @@ -74,7 +74,7 @@ int rs_screenshot(char *address, char *filename, int timeout)
length -= n+5;

// Dump remaining PNG image data to file
screenshot_file_dump(image, length, filename, "png");
screenshot_file_dump(image, length, "png");

// Disconnect
lxi_disconnect(device);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/screenshot_tektronix.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define IMAGE_SIZE_MAX 0x400000 // 4 MB

int tektronix_screenshot(char *address, char *filename, int timeout)
int tektronix_screenshot(char *address, int timeout)
{
char response[IMAGE_SIZE_MAX];
char *command;
Expand Down Expand Up @@ -68,7 +68,7 @@ int tektronix_screenshot(char *address, char *filename, int timeout)
}

// Dump PNG image data to file
screenshot_file_dump(response, length, filename, "png");
screenshot_file_dump(response, length, "png");

// Disconnect
lxi_disconnect(device);
Expand Down
23 changes: 12 additions & 11 deletions src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <time.h>
#include <regex.h>
#include "screenshot.h"
#include "options.h"
#include <lxi.h>

#define PLUGIN_LIST_SIZE_MAX 50
Expand Down Expand Up @@ -111,31 +112,31 @@ char *date_time(void)
return date_time_string;
}

void screenshot_file_dump(void *data, int length, char *filename, char *format)
void screenshot_file_dump(void *data, int length, char *format)
{
char automatic_filename[80];
char automatic_filename[1000];
char *screenshot_filename;
FILE *fp;
FILE *fd;
int i = 0;

// Resolve screenshot filename
if (strlen(filename) == 0)
if (strlen(option.screenshot_filename) == 0)
{
sprintf(automatic_filename, "screenshot_%s.%s", date_time(), format);
sprintf(automatic_filename, "screenshot_%s_%s.%s", option.ip, date_time(), format);
screenshot_filename = automatic_filename;
}
else
screenshot_filename = filename;
screenshot_filename = option.screenshot_filename;

// Write screenshot file
fp = fopen(screenshot_filename, "w+");
if (fp == NULL)
fd = fopen(screenshot_filename, "w+");
if (fd == NULL)
{
printf("Error: Could not write screenshot file (%s)\n", strerror(errno));
exit(EXIT_FAILURE);
}
fwrite(data, 1, length, fp);
fclose(fp);
fwrite(data, 1, length, fd);
fclose(fd);

printf("Saved screenshot image to %s\n", screenshot_filename);
}
Expand Down Expand Up @@ -299,5 +300,5 @@ int screenshot(char *address, char *plugin_name, char *filename, int timeout)
}

// Call capture screenshot function
return plugin_list[i]->screenshot(address, filename, timeout);
return plugin_list[i]->screenshot(address, timeout);
}

0 comments on commit 080681f

Please sign in to comment.