I solved the problem. The code should have been:

event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
len) {
    // ctp_data_header_t* in = (ctp_data_header_t*) payload; // Wrong:
payload is the CTP payload
ctp_data_header_t* in = (ctp_data_header_t*) msg->data; // msg is the AM
packet message, who's data begins with the CTP header.
ctp_data_header_t* out;
out = (ctp_data_header_t*) call SerialSend.getPayload(&uartbuf,
sizeof(ctp_data_header_t));
memcpy(out, in, sizeof(ctp_data_header_t));
uartlen = sizeof(ctp_data_header_t);
call SerialSend.send(0xffff, &uartbuf, uartlen);
return msg;
     }

This may help someone else who has this issue.

Regards,

Kevin

On Wed, Sep 12, 2012 at 3:39 PM, Omprakash Gnawali <[email protected]>wrote:

> Can you check if you are receiving the proper bytes corresponding to
> the message on the PC side using seriallisten or serialforwarder and
> sflisten? If you are receiving proper bytes, the problem is in your Java
> code. Otherwise, the problem might be on the mote side.
>
> - om_p
>
> On Sat, Sep 1, 2012 at 6:11 PM, kevin doran <[email protected]> wrote:
> > Hi,
> >
> > I have been struggling for days trying to tunnel a CTP header over serial
> > and receive the header in Java. I have just modified the
> > MultihopOscilloscope program. Here is my code:
> >
> > The base node of a CTP network receives packets and forwards them on
> serial
> > as follows:
> >
> > event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
> len)
> > {
> > ctp_data_header_t* in = (ctp_data_header_t*) payload;
> > ctp_data_header_t* out;
> > out = (ctp_data_header_t*) call SerialSend.getPayload(&uartbuf,
> > sizeof(ctp_data_header_t));
> > memcpy(out, in, sizeof(ctp_data_header_t));
> > uartlen = sizeof(ctp_data_header_t);
> > call SerialSend.send(0xffff, &uartbuf, uartlen);
> > return msg;
> > }
> >
> > The Java program running on the PC tries to capture the headers as
> follows:
> >
> > public class HeaderReceiver implements MessageListener {
> >
> > MoteIF mote;
> >
> > void run() {
> > mote = new MoteIF(PrintStreamMessenger.err);
> > mote.registerListener(new CtpDataHeader(), this);
> > }
> >
> > synchronized public void messageReceived(int dest_addr, Message msg) {
> > //never called.
> > }
> > }
> >
> > The CtpDataHeader class was created with MIG.
> >
> > Any thoughts on what I am doing wrong?
> >
> > Thanks a million,
> >
> > Kevin Doran
> >
> >
> > _______________________________________________
> > Tinyos-help mailing list
> > [email protected]
> > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to