Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scdp #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ include ../config.mk

CFLAGS:=${CFLAGS} -I../library

all : vxi11_cmd vxi11_send
all : vxi11_cmd vxi11_send vxi11_scdp

vxi11_scdp: vxi11_scdp.o ../library/libvxi11.so.${SOVERSION}
$(CC) -o $@ $^ $(LDFLAGS)

vxi11_cmd: vxi11_cmd.o ../library/libvxi11.so.${SOVERSION}
$(CC) -o $@ $^ $(LDFLAGS)
Expand Down
103 changes: 103 additions & 0 deletions utils/vxi11_scdp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* vxi11_scdp.c
* Copyright (C) 2006 Steve D. Sharples
* Copyright (C) 2020 Harald Barth
*
* A simple interactive utility that allows you to send commands and queries to
* a device enabled with the VXI11 RPC ethernet protocol. Uses the files
* generated by rpcgen vxi11.x, and the vxi11_user.h user libraries.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The author's email address is [email protected]
*/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "vxi11_user.h"
/* support max 2MB sized BMPs */
#define BUF_LEN 800000

#ifdef WIN32
#define strncasecmp(a, b, c) stricmp(a, b)
#endif

int main(int argc, char *argv[])
{

int err = 0;
char *device_ip;
char *device_name = "unknown";
char *filename;
char buf[BUF_LEN];
int ret;
long bytes_returned;
VXI11_CLINK *clink;

if (argc < 2) {
printf("usage: %s your.inst.ip.addr filename\n", argv[0]);
exit(1);
}

device_ip = argv[1];
if (argc > 2) {
filename = argv[2];
}
if (argc > 3) {
exit(255);
}

if(vxi11_open_device(&clink, device_ip, device_name)){
printf("Error: could not open device %s, quitting\n",
device_ip);
exit(2);
}

memset(buf, 0, BUF_LEN); // initialize buffer

if (vxi11_send(clink, "SCDP", 4) < 0) {
printf("*** [ VXI11 send failed ] ***\n");
exit(255);
}
bytes_returned = vxi11_receive(clink, buf, BUF_LEN);
if (bytes_returned > 0) {
int f;
printf("%ld bytes received ", bytes_returned);
f = open(filename, O_CREAT|O_TRUNC|O_RDWR, 0644);
if (bytes_returned == write(f, buf, bytes_returned) && (err = close(f)) == 0)
printf("and saved in %s", filename);
else {
if (!err)
err = 1;
printf("and save error to file %s", filename);
}
printf("\n");
} else if (bytes_returned == -15) {
err = 15;
printf("*** [ NOTHING RECEIVED ] ***\n");
} else {
err = 128;
printf("*** [ unknown error ] ***\n");
}

ret = vxi11_close_device(clink, device_ip);
exit (err);
}