Subject:
|
josx.rcxcomm and BrickOS LNP
|
Newsgroups:
|
lugnet.robotics.rcx.java
|
Date:
|
Mon, 15 Sep 2003 23:24:31 GMT
|
Viewed:
|
5459 times
|
| |
| |
Hi,
I'm currently working on a project in which I'm develping a task and memmory
monitor for the BrickOS operating system. I'm going to run a Java Applet on the
PC side and I'm using the josx.rcxcomm to obtain the necessary data from a
thread/task written in C on the BrickOS. Right now I'm just tring to send a
buffer of integers by running two simple programs on the PC and on the RCX. I'm
having trouble figuring out which protocol handler to use and which one will
best suit my needs. All I really need to do is send between 10 and 20 integers
from the RCX to the PC and I figured the best way to do it is to use the
RCXLNPAddrport which conforms with the LegOS Networking Protocol. It appears
that I can only read one byte at a time using the readShort() method from
DataInputStream. Would it be better to just use lower-level handlers and send
the data as bytes? Can anyone point me in the right direction on how I can best
achieve this? Here are the sample programs I'm using.
PC Code-------------------------------------------------------------------
import java.io.*;
import josx.rcxcomm.*;
public class LNPAddr {
public static void main(String[] args) {
try {
RCXLNPAddressingPort port = new RCXLNPAddressingPort((byte) 0x20,(byte) 0x00);
InputStream is = port.getInputStream();
OutputStream os = port.getOutputStream();
DataInputStream dis = new DataInputStream(is);
DataOutputStream dos = new DataOutputStream(os);
dos.writeByte(4);
dos.flush();
/*
byte [] buffer = new byte[4];
buffer[0] = 0;
buffer[1] = 0;
int numOfBytes = dis.read(buffer, 0, 4);
System.out.println(numOfBytes);
*/
short i = dis.readShort();
short j = dis.readShort();
System.out.println("recieved " + i);
System.out.println("recieved " + j);
}
catch (Exception e) {
System.out.println("Exception " + e.getMessage());
}
}
}
RCX Code----------------------------------------------------------------------
#include <sys/mm.h>
#include <sys/tm.h>
#include <stdlib.h>
#include <sys/critsec.h>
#include <string.h>
#include <config.h>
#include <conio.h>
#include <unistd.h>
#include <lnp.h>
#define MYPORT 0
#define DEST 0x20
extern size_t mm_start;
int got = 0;
unsigned int buf[2];
int in;
size_t *ptr=(size_t *)&mm_start;
void getdata(unsigned char *inbuf, char l, unsigned char src)
{
in = *inbuf;
got = 1;
}
wakeup_t WaitForData(wakeup_t data)
{
return got;
}
int main(int argc, char **argv) {
unsigned int val = &mm_start;
lnp_addressing_set_handler(MYPORT, &getdata);
while(1) {
// wait_event(WaitForData, 0);
buf[0] = (unsigned int)1900;
buf[1] = (unsigned int)500;
lnp_addressing_write(buf, 4, DEST, MYPORT);
// got = 0;
}
return 0;
}
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|