diff --git a/rcxlib/nqc_rcxlib.cpp b/rcxlib/nqc_rcxlib.cpp new file mode 100644 index 0000000..fbf7878 --- /dev/null +++ b/rcxlib/nqc_rcxlib.cpp @@ -0,0 +1,60 @@ +/* C/C++ ABI wrapper for NQC's rcxlib */ + +#include + +#include "RCX_Pipe.h"; + +#ifdef USE_TRANSPORT +#include "RCX_Link.h" +#include "RCX_PipeTransport.h" +static RCX_PipeTransport *rcx_pipe_transport = 0; + +#define BUFFERSIZE 4096 +extern int __comm_debug; +#endif + +#include "nqc_rcxlib.h" + +void *rcx_pipe_init() +{ + RCX_Pipe *pipe = RCX_NewUSBTowerPipe(); +#ifdef USE_TRANSPORT + rcx_pipe_transport = new RCX_PipeTransport(pipe); + if (rcx_pipe_transport->Open((RCX_TargetType) 0, "short", (__comm_debug ? RCX_Link::kVerboseMode : 0)) != kRCX_OK) { + delete rcx_pipe_transport; + rcx_pipe_transport = 0; + exit(1); + } +#else + pipe->Open("short", RCX_Pipe::kNormalIrMode); + // pipe->SetMode(RCX_Pipe::kFastIrMode); +#endif + return (void *) pipe; +} + +void rcx_pipe_close(void *pipe) +{ + return ((RCX_Pipe *) pipe)->Close(); +} + +long rcx_pipe_read(void *pipe, void *ptr, long count, long timeout_ms) +{ + return ((RCX_Pipe *) pipe)->Read(ptr, count, timeout_ms); +} + +long rcx_pipe_write(void *pipe, const void *ptr, long count) +{ + return ((RCX_Pipe *) pipe)->Write(ptr, count); +} + +#ifdef USE_TRANSPORT +long rcx_pipe_send(void *pipe, void *send, int slen, void *recv, int rlen, + int timeout, int retries, int use_comp) +{ + long result = rcx_pipe_transport->Send((const UByte*) send, slen, (UByte*) recv, rlen, BUFFERSIZE, 1); + if (!RCX_ERROR(result)) + return rlen; + else + return result; +} +#endif diff --git a/rcxlib/nqc_rcxlib.h b/rcxlib/nqc_rcxlib.h new file mode 100644 index 0000000..1197e57 --- /dev/null +++ b/rcxlib/nqc_rcxlib.h @@ -0,0 +1,15 @@ +/* C/C++ ABI wrapper for NQC's rcxlib */ + +#if defined(__cplusplus) +extern "C" { +#endif + +void *rcx_pipe_init(); +void rcx_pipe_close(void *); +long rcx_pipe_read(void *, void *, long, long); +long rcx_pipe_write(void *, const void *, long); +long rcx_pipe_send(void *, void *, int, void *, int, int, int, int); + +#if defined(__cplusplus) +} +#endif