diff options
-rw-r--r-- | libvxi11client/Makefile | 5 | ||||
-rw-r--r-- | libvxi11client/client.c | 104 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.c | 148 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.h | 49 | ||||
-rw-r--r-- | vxi11_server.c | 91 |
5 files changed, 293 insertions, 104 deletions
diff --git a/libvxi11client/Makefile b/libvxi11client/Makefile index 2e3f129..9b82fac 100644 --- a/libvxi11client/Makefile +++ b/libvxi11client/Makefile @@ -19,3 +19,8 @@ vxi11_xdr.o: vxi11_xdr.c clean: -rm *.o client + -rm -rf VXI11-Client + +perl: + -rm -rf VXI11-Client + h2xs -M vxi11 -x -n VXI11::Client libvxi11client.h diff --git a/libvxi11client/client.c b/libvxi11client/client.c index fe023c7..d75ddd5 100644 --- a/libvxi11client/client.c +++ b/libvxi11client/client.c @@ -1,22 +1,94 @@ #include "vxi11.h" #include <stdio.h> +#define IDENTIFY "*IDN?" + +static char* geterrorstring(int errorcode) { + switch (errorcode) { + case 0: + return "no response from server"; + default: + return "unknown error code"; + } +} + int main() { printf("VXI-11 test client\n"); - CLIENT* clnt; - vxi11_open("192.168.2.250"); - vxi11_write(); - vxi11_read(); - vxi11_trigger(); - vxi11_clear(); - vxi11_abort(); - vxi11_lock(); - vxi11_unlock(); - vxi11_remote(); - vxi11_local(); - vxi11_readstatusbyte(); - vxi11_create_intr_chan(); - vxi11_destroy_intr_chan(); - vxi11_docmd(); - vxi11_close(); + + int err = 0; + + if (vxi11_open("192.168.2.250")) { + + // write some bytes + int byteswritten = vxi11_write(IDENTIFY, sizeof(IDENTIFY)); + if (byteswritten >= 0) + printf("Wrote %d bytes\n", byteswritten); + else + printf("Error writing data\n"); + + // read some bytes + int bytesread = vxi11_read(); + if (bytesread >= 0) + printf("Read %d bytes\n", bytesread); + else + printf("Error reading data\n"); + + // trigger + if (vxi11_trigger()) + printf("triggered\n"); + + // clear + if (vxi11_clear()) + printf("cleared\n"); + + // abort + if ((err = vxi11_abort())) + printf("aborted\n"); + else + printf("abort failed; %s\n", geterrorstring(err)); + + // lock + if (vxi11_lock()) + printf("locked\n"); + + // unlock + if (vxi11_unlock()) + printf("unlocked\n"); + + // remote + if (vxi11_remote()) + printf("remote'd\n"); + + // local + if (vxi11_local()) + printf("local'd\n"); + + // read the status byte + int statusbyte = vxi11_readstatusbyte(); + if (statusbyte >= 0) + printf("Status byte is 0x%02x\n", statusbyte); + else + printf("Error reading status byte\n"); + + // create interrupt channel + vxi11_create_intr_chan(); + + // destroy interrupt channel + if ((err = vxi11_destroy_intr_chan())) + printf("destroyed interrupt channel\n"); + else + printf("Error destroying interrupt channel; %s\n", geterrorstring(err)); + + // docmd + if ((err = vxi11_docmd(0x00))) + printf("did command, should fail!\n"); + else + printf("Error calling docmd; %\n", geterrorstring(err)); + + // close + vxi11_close(); + } + else { + exit(1); + } } diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c index 41ad046..20fa0fa 100644 --- a/libvxi11client/libvxi11client.c +++ b/libvxi11client/libvxi11client.c @@ -5,10 +5,10 @@ static CLIENT* clnt = NULL; static Device_Link link; -void vxi11_open(char* address, char* device) { +int vxi11_open(char* address, char* device) { clnt = clnt_create(address, DEVICE_CORE, DEVICE_CORE_VERSION, "tcp"); if (clnt == NULL) { - printf("error creating client\n"); + return 0; } else { Create_LinkParms link_parms; @@ -18,34 +18,52 @@ void vxi11_open(char* address, char* device) { link_parms.device = device; Create_LinkResp* linkresp = create_link_1(&link_parms, clnt); - link = linkresp->lid; + if (linkresp != NULL && linkresp->error == 0) { + link = linkresp->lid; + return 1; + } + else if (linkresp == NULL) + return 0; + else + return -(linkresp->error); } } -void vxi11_readstatusbyte() { +int vxi11_readstatusbyte() { if (clnt == NULL) return; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; Device_ReadStbResp* resp = device_readstb_1(¶ms, clnt); + + if (resp != NULL && resp->error == 0) + return resp->stb; + else if (resp == NULL) + return 0; + else + return -1; } -void vxi11_write() { +int vxi11_write(char* data, unsigned int len) { if (clnt == NULL) { return; } - char* IDENTIFY = "*IDN?"; - Device_WriteParms params = { .lid = link, .io_timeout = VXI11_DEFAULT_TIMEOUT, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .flags = 0x0 }; - params.data.data_len = sizeof(IDENTIFY); - params.data.data_val = IDENTIFY; + params.data.data_len = len; + params.data.data_val = data; Device_WriteResp* resp = device_write_1(¶ms, clnt); + if (resp != NULL && resp->error == 0) + return resp->size; + else if (resp == NULL) + return 0; + else + return -1; } -void vxi11_read() { +int vxi11_read() { if (clnt == NULL) { return; } @@ -54,89 +72,155 @@ void vxi11_read() { VXI11_DEFAULT_TIMEOUT, .flags = 0x0, .termChar = 0x0 }; Device_ReadResp* resp = device_read_1(¶ms, clnt); + if (resp != NULL && resp->error == 0) + return resp->data.data_len; + else if (resp == NULL) + return 0; + else + return -1; } -void vxi11_docmd() { +int vxi11_docmd(unsigned long cmd) { if (clnt == NULL) return; Device_DocmdParms params = { .lid = link, .flags = 0x0, .io_timeout = VXI11_DEFAULT_TIMEOUT, .lock_timeout = - VXI11_DEFAULT_TIMEOUT, .cmd = 0, .network_order = 0, .datasize = 0 }; + VXI11_DEFAULT_TIMEOUT, .cmd = cmd, .network_order = 0, .datasize = 0 }; params.data_in.data_in_len = 0; params.data_in.data_in_val = NULL; Device_DocmdResp* resp = device_docmd_1(¶ms, clnt); + if (resp != NULL && resp->error == 0) + return 1; + else if (resp == NULL) + return 0; + else + return -(resp->error); } -void vxi11_trigger() { +int vxi11_trigger() { if (clnt == NULL) return; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; - device_trigger_1(¶ms, clnt); + Device_Error* error = device_trigger_1(¶ms, clnt); + + if (error->error == 0) + return 1; + else + return -1; } -void vxi11_clear() { +int vxi11_clear() { if (clnt == NULL) return; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; - device_clear_1(¶ms, clnt); + Device_Error* error = device_clear_1(¶ms, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_remote() { +int vxi11_remote() { if (clnt == NULL) return; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; - device_remote_1(¶ms, clnt); + Device_Error* error = device_remote_1(¶ms, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_local() { +int vxi11_local() { if (clnt == NULL) return; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; - device_local_1(¶ms, clnt); + Device_Error* error = device_local_1(¶ms, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_lock() { +int vxi11_lock() { if (clnt == NULL) return; Device_LockParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT }; - device_lock_1(¶ms, clnt); + Device_Error* error = device_lock_1(¶ms, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_unlock() { +int vxi11_unlock() { if (clnt == NULL) return; - device_unlock_1(&link, clnt); + Device_Error* error = device_unlock_1(&link, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_create_intr_chan() { +int vxi11_create_intr_chan() { if (clnt == NULL) return; Device_RemoteFunc remotefunc = { .hostAddr = 0x0, .hostPort = 0x0, .progNum = 0x0, .progVers = 0x0, .progFamily = DEVICE_TCP }; - create_intr_chan_1(&remotefunc, clnt); + Device_Error* error = create_intr_chan_1(&remotefunc, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_destroy_intr_chan() { +int vxi11_destroy_intr_chan() { if (clnt == NULL) return; - destroy_intr_chan_1(NULL, clnt); + Device_Error* error = destroy_intr_chan_1(NULL, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_abort() { +int vxi11_abort() { if (clnt == NULL) return; - device_abort_1(&link, clnt); + Device_Error* error = device_abort_1(&link, clnt); + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -void vxi11_close() { - destroy_link_1(&link, clnt); +int vxi11_close() { + Device_Error* error = destroy_link_1(&link, clnt); clnt_destroy(clnt); clnt = NULL; + return 1; } diff --git a/libvxi11client/libvxi11client.h b/libvxi11client/libvxi11client.h index 4b2f781..b65e711 100644 --- a/libvxi11client/libvxi11client.h +++ b/libvxi11client/libvxi11client.h @@ -1,17 +1,36 @@ #include "vxi11.h" -void vxi11_open(char* address, char* device); -void vxi11_abort(); -void vxi11_trigger(); -void vxi11_clear(); -void vxi11_write(); -void vxi11_read(); -void vxi11_lock(); -void vxi11_unlock(); -void vxi11_local(); -void vxi11_readstatusbyte(); -void vxi11_remote(); -void vxi11_create_intr_chan(); -void vxi11_destroy_intr_chan(); -void vxi11_docmd(); -void vxi11_close(); +#define ERR_SYNTAXERROR -1 +#define ERR_DEVICENOTACCESSIBLE -3 +#define ERR_INVALIDLINKINDENTIFIER -4 +#define ERR_PARAMETERERROR -5 +#define ERR_CHANNELNOTESTABLISHED -6 +#define ERR_OPERATIONNOTSUPPORTED -8 +#define ERR_OUTOFRESOURCES -9 +#define ERR_DEVICELOCKEDBYANOTHERLINK -11 +#define ERR_NOLOCKHELDBYTHISLINK -12 +#define ERR_IOTIMEOUT -15 +#define ERR_IOERROR -17 +#define ERR_INVALIDADDRESS -21 +#define ERR_ABORT -23 +#define ERR_CHANNELALREADYESTABLISHED -29 + +#define FLAG_TERMCHRSET (1 << 7) +#define FLAG_END (1 << 3) +#define FLAG_WAITLOCK 1 + +int vxi11_open(char* address, char* device); +int vxi11_abort(); +int vxi11_trigger(); +int vxi11_clear(); +int vxi11_write(); +int vxi11_read(); +int vxi11_lock(); +int vxi11_unlock(); +int vxi11_local(); +int vxi11_readstatusbyte(); +int vxi11_remote(); +int vxi11_create_intr_chan(); +int vxi11_destroy_intr_chan(); +int vxi11_docmd(unsigned long cmd); +int vxi11_close(); diff --git a/vxi11_server.c b/vxi11_server.c index cebff63..84a80d5 100644 --- a/vxi11_server.c +++ b/vxi11_server.c @@ -6,6 +6,52 @@ #include "vxi11.h" #include "stdio.h" +#include "globals.h" +#include <stdbool.h> + +#define ERR_SYNTAXERROR 1 +#define ERR_DEVICENOTACCESSIBLE 3 +#define ERR_INVALIDLINKINDENTIFIER 4 +#define ERR_PARAMETERERROR 5 +#define ERR_CHANNELNOTESTABLISHED 6 +#define ERR_OPERATIONNOTSUPPORTED 8 +#define ERR_OUTOFRESOURCES 9 +#define ERR_DEVICELOCKEDBYANOTHERLINK 11 +#define ERR_NOLOCKHELDBYTHISLINK 12 +#define ERR_IOTIMEOUT 15 +#define ERR_IOERROR 17 +#define ERR_INVALIDADDRESS 21 +#define ERR_ABORT 23 +#define ERR_CHANNELALREADYESTABLISHED 29 + +static bool isLocked() { + return globals.VxiLocks.locked_network_server != NO_SERVER_LOCKED; +} + +static bool haveLock(int lid) { + return globals.VxiLocks.locked_network_server == lid; +} + +static void waitForLock(long timeout) { + +} + +static bool lock(int lid) { + if (globals.VxiLocks.locked_network_server = NO_SERVER_LOCKED) + return false; + globals.VxiLocks.locked_network_server = lid; +} + +static bool unlock(int lid) { + if (globals.VxiLocks.locked_network_server = NO_SERVER_LOCKED) + return false; + else if (globals.VxiLocks.locked_network_server != lid) + return false; + else { + globals.VxiLocks.locked_network_server = NO_SERVER_LOCKED; + return true; + } +} Device_Error * device_abort_1_svc(Device_Link *argp, struct svc_req *rqstp) { @@ -23,10 +69,7 @@ Create_LinkResp * create_link_1_svc(Create_LinkParms *argp, struct svc_req *rqstp) { printf("create_link_1_svc()\n"); static Create_LinkResp result; - - /* - * insert server code here - */ + globals.Remote.vxi_connections++; result.error = 0; return &result; } @@ -35,7 +78,6 @@ Device_WriteResp * device_write_1_svc(Device_WriteParms *argp, struct svc_req *rqstp) { printf("device_write_1_svc()\n"); static Device_WriteResp result; - printf("%s\n", argp->data.data_val); /* @@ -68,11 +110,6 @@ Device_ReadStbResp * device_readstb_1_svc(Device_GenericParms *argp, struct svc_req *rqstp) { printf("device_readstb_1_svc()\n"); static Device_ReadStbResp result; - - /* - * insert server code here - */ - result.error = 0; result.stb = 0; return &result; @@ -132,11 +169,9 @@ device_local_1_svc(Device_GenericParms *argp, struct svc_req *rqstp) { Device_Error * device_lock_1_svc(Device_LockParms *argp, struct svc_req *rqstp) { printf("device_lock_1_svc()\n"); + static Device_Error result; - /* - * insert server code here - */ result.error = 0; return &result; } @@ -156,11 +191,6 @@ Device_Error * device_enable_srq_1_svc(Device_EnableSrqParms *argp, struct svc_req *rqstp) { printf("device_enable_srq_1_svc()\n"); static Device_Error result; - - /* - * insert server code here - */ - return &result; } @@ -168,11 +198,7 @@ Device_DocmdResp * device_docmd_1_svc(Device_DocmdParms *argp, struct svc_req *rqstp) { printf("device_docmd_1_svc()\n"); static Device_DocmdResp result; - - /* - * insert server code here - */ - result.error = 0; + result.error = ERR_OPERATIONNOTSUPPORTED; return &result; } @@ -180,11 +206,7 @@ Device_Error * destroy_link_1_svc(Device_Link *argp, struct svc_req *rqstp) { printf("destroy_link_1_svc()\n"); static Device_Error result; - - /* - * insert server code here - */ - + globals.Remote.vxi_connections--; return &result; } @@ -192,10 +214,6 @@ Device_Error * create_intr_chan_1_svc(Device_RemoteFunc *argp, struct svc_req *rqstp) { printf("create_intr_chan_1_svc()\n"); static Device_Error result; - - /* - * insert server code here - */ result.error = 0; return &result; } @@ -204,10 +222,6 @@ Device_Error * destroy_intr_chan_1_svc(void *argp, struct svc_req *rqstp) { printf("destroy_intr_chan_1_svc()\n"); static Device_Error result; - - /* - * insert server code here - */ result.error = 0; return &result; } @@ -216,10 +230,5 @@ void * device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) { printf("device_intr_srq_1_svc()\n"); static char * result; - - /* - * insert server code here - */ - return (void *) &result; } |