diff --git a/utils/Makefile b/utils/Makefile index d73a8f7..2534b64 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -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) diff --git a/utils/vxi11_scdp.c b/utils/vxi11_scdp.c new file mode 100644 index 0000000..8b89f57 --- /dev/null +++ b/utils/vxi11_scdp.c @@ -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 steve.sharples@nottingham.ac.uk + */ + +#include +#include +#include +#include + +#include +#include +#include + +#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); +}