Skip to content

Commit 4ed337c

Browse files
committed
Add C/C++ ABI wrapper for NQC's rcxlib
1 parent c6aff03 commit 4ed337c

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

rcxlib/nqc_rcxlib.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

rcxlib/nqc_rcxlib.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* C/C++ ABI wrapper for NQC's rcxlib */
2+
3+
#if defined(__cplusplus)
4+
extern "C" {
5+
#endif
6+
7+
void *rcx_pipe_init();
8+
void rcx_pipe_close(void *);
9+
long rcx_pipe_read(void *, void *, long, long);
10+
long rcx_pipe_write(void *, const void *, long);
11+
long rcx_pipe_send(void *, void *, int, void *, int, int, int, int);
12+
13+
#if defined(__cplusplus)
14+
}
15+
#endif

0 commit comments

Comments
 (0)