|
| 1 | +/* C/C++ ABI wrapper for NQC's rcxlib */ |
| 2 | + |
| 3 | +#include <stdlib.h> |
| 4 | + |
| 5 | +#include "RCX_Pipe.h"; |
| 6 | + |
| 7 | +#ifdef USE_TRANSPORT |
| 8 | +#include "RCX_Link.h" |
| 9 | +#include "RCX_PipeTransport.h" |
| 10 | +static RCX_PipeTransport *rcx_pipe_transport = 0; |
| 11 | + |
| 12 | +#define BUFFERSIZE 4096 |
| 13 | +extern int __comm_debug; |
| 14 | +#endif |
| 15 | + |
| 16 | +#include "nqc_rcxlib.h" |
| 17 | + |
| 18 | +void *rcx_pipe_init() |
| 19 | +{ |
| 20 | + RCX_Pipe *pipe = RCX_NewUSBTowerPipe(); |
| 21 | +#ifdef USE_TRANSPORT |
| 22 | + rcx_pipe_transport = new RCX_PipeTransport(pipe); |
| 23 | + if (rcx_pipe_transport->Open((RCX_TargetType) 0, "short", (__comm_debug ? RCX_Link::kVerboseMode : 0)) != kRCX_OK) { |
| 24 | + delete rcx_pipe_transport; |
| 25 | + rcx_pipe_transport = 0; |
| 26 | + exit(1); |
| 27 | + } |
| 28 | +#else |
| 29 | + pipe->Open("short", RCX_Pipe::kNormalIrMode); |
| 30 | + // pipe->SetMode(RCX_Pipe::kFastIrMode); |
| 31 | +#endif |
| 32 | + return (void *) pipe; |
| 33 | +} |
| 34 | + |
| 35 | +void rcx_pipe_close(void *pipe) |
| 36 | +{ |
| 37 | + return ((RCX_Pipe *) pipe)->Close(); |
| 38 | +} |
| 39 | + |
| 40 | +long rcx_pipe_read(void *pipe, void *ptr, long count, long timeout_ms) |
| 41 | +{ |
| 42 | + return ((RCX_Pipe *) pipe)->Read(ptr, count, timeout_ms); |
| 43 | +} |
| 44 | + |
| 45 | +long rcx_pipe_write(void *pipe, const void *ptr, long count) |
| 46 | +{ |
| 47 | + return ((RCX_Pipe *) pipe)->Write(ptr, count); |
| 48 | +} |
| 49 | + |
| 50 | +#ifdef USE_TRANSPORT |
| 51 | +long rcx_pipe_send(void *pipe, void *send, int slen, void *recv, int rlen, |
| 52 | + int timeout, int retries, int use_comp) |
| 53 | +{ |
| 54 | + long result = rcx_pipe_transport->Send((const UByte*) send, slen, (UByte*) recv, rlen, BUFFERSIZE, 1); |
| 55 | + if (!RCX_ERROR(result)) |
| 56 | + return rlen; |
| 57 | + else |
| 58 | + return result; |
| 59 | +} |
| 60 | +#endif |
0 commit comments