-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C/C++ ABI wrapper for NQC's rcxlib
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* C/C++ ABI wrapper for NQC's rcxlib */ | ||
|
||
#include <stdlib.h> | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |