Update on June 6, 2012:

  To simplify things, one of the motes was changed to run ListenC.nc, as
follows:

#include "Listen.h"

module ListenC {
        uses interface Boot;
        uses interface Leds;
        uses interface Packet;
        uses interface AMSend;
        uses interface SplitControl as AMControl;
        uses interface Receive;
}

implementation {
        
        event void Boot.booted() {
                call AMControl.start();
        }
        
        event void AMControl.startDone(error_t err) {
                if (err == SUCCESS) {
                }else {
                        call AMControl.start();
                }
        }
        
        event void AMControl.stopDone(error_t err) {
        }
        
        event void AMSend.sendDone(message_t* msg, error_t error) {

        }
        
        event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
len) {
                if (len == sizeof(ListenMsg)) {
                        call Leds.led0Toggle();
                }
                return msg;
        }
}

Listen.h:

#ifndef LISTEN_H
#define LISTEN_H

enum {
        AM_LISTENMSG = 0x89,
};

typedef nx_struct ListenMsg {
        nx_uint16_t nodeid;
        nx_uint16_t counter;
} ListenMsg;

#endif

ListenAppC.nc:

#include "Listen.h"

configuration ListenAppC {
}

implementation {
        components MainC;
        components LedsC;
        components ListenC as App;
        components SerialActiveMessageC;
        components new SerialAMSenderC(AM_LISTENMSG);
        components new SerialAMReceiverC(AM_LISTENMSG);
        
        App.Boot -> MainC;
        App.Leds -> LedsC;
        App.Packet -> SerialAMSenderC;
        App.AMSend -> SerialAMSenderC;
        App.AMControl -> SerialActiveMessageC;
        App.Receive -> SerialAMReceiverC;
}

The red LED on the Tinynode running ListenC.nc does not flash.  We tried 
both straight through and null modem cable connections between the two
Tinynodes.  

  We know the SerialAMReceiver component works when receiving bytes
from a PC.  Does anyone have a clue as to why it does not work when
receiving
bytes from another Tinynode?

Luis


navarrojr89 wrote:
> 
> Hi:
> 
> We're trying to establish Tinynode to Tinynode serial communication.
> Both sending and receiving Tinynodes use the following BlinkToSerialC.nc
> and
> BlinkToSerialAppC.nc  code:
> 
> BlinkToSerial.h:
> 
> #ifndef BLINKTOSERIAL_H
> #define BLINKTOSERIAL_H
> 
> enum {
>     AM_BLINKTOSERIALMSG = 0x89,
>     TIMER_PERIOD_MILLI = 250
> };
> 
> typedef nx_struct BlinkToSerialMsg {
>     nx_uint16_t nodeid;
>     nx_uint16_t counter;
> } BlinkToSerialMsg;
> 
> #endif
> 
> BlinkToSerialC.nc:
> 
> #include <Timer.h>
> #include "BlinkToSerial.h"
> 
> module BlinkToSerialC {
>     uses interface Boot;
>     uses interface Leds;
>     uses interface Timer<TMilli> as Timer0;
>     uses interface Packet;
>     uses interface AMSend;
>     uses interface SplitControl as AMControl;
>     uses interface Receive;
> }
> 
> implementation {
>     bool busy = FALSE;
>     message_t pkt;
>     uint16_t counter = 0;
> 
>     event void Boot.booted() {
>         call AMControl.start();
>     }
> 
>     event void Timer0.fired() {
>         counter++;
>         if (!busy) {
>             BlinkToSerialMsg* btrpkt = (BlinkToSerialMsg*)(call
> Packet.getPayload(&pkt, sizeof (BlinkToSerialMsg)));
>             btrpkt -> nodeid = TOS_NODE_ID;
>             btrpkt -> counter = counter;
>             if (call AMSend.send(AM_BROADCAST_ADDR, &pkt,
> sizeof(BlinkToSerialMsg)) == SUCCESS) {
>                 busy = TRUE;
>             }
>         }
>     }
> 
>     event void AMControl.startDone(error_t err) {
>         if (err == SUCCESS) {
>             call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
>         }else {
>             call AMControl.start();
>         }
>     }
> 
>     event void AMControl.stopDone(error_t err) {
>     }
> 
>     event void AMSend.sendDone(message_t* msg, error_t error) {
>         if (&pkt == msg) {
>             busy = FALSE;
>             call Leds.led1Toggle();
>         }
>     }
> 
>     event message_t* Receive.receive(message_t* msg, void* payload,
> uint8_t
> len) {
>         if (len == sizeof(BlinkToSerialMsg)) {
>             BlinkToSerialMsg* btrpkt = (BlinkToSerialMsg*) payload;
>             call Leds.led0Toggle();
>         }
>         return msg;
>     }
> }
> 
> BlinkToSerialAppC.nc:
> 
> #include <Timer.h>
> #include "BlinkToSerial.h"
> 
> configuration BlinkToSerialAppC {
> }
> 
> implementation {
>     components MainC;
>     components LedsC;
>     components BlinkToSerialC as App;
>     components new TimerMilliC() as Timer0;
>     components SerialActiveMessageC;
>     components new SerialAMSenderC(AM_BLINKTOSERIALMSG);
>     components new SerialAMReceiverC(AM_BLINKTOSERIALMSG);
> 
>     App.Boot -> MainC;
>     App.Leds -> LedsC;
>     App.Timer0 -> Timer0;
>     App.Packet -> SerialAMSenderC;
>     App.AMSend -> SerialAMSenderC;
>     App.AMControl -> SerialActiveMessageC;
>     App.Receive -> SerialAMReceiverC;
> }
> 
> Makefile:
> 
> COMPONENT=BlinkToSerialAppC
> BUILD_EXTRA_DEPS=BlinkToSerialMsg.class
> 
> BlinkToSerialMsg.class: BlinkToSerialMsg.java
>     javac BlinkToSerialMsg.java
> 
> BlinkToSerialMsg.java:
>     mig java -target=null -java-classname=BlinkToSerialMsg BlinkToSerial.h
> BlinkToSerialMsg -o $@
> 
> include $(MAKERULES)
> 
> When we run this application, the green LED (led1) flashes every 250 ms on
> both Tinynodes, but the
> red LED (led0) never flashes.  Does anyone have a suggestion on how to
> make
> the Tinynode receive
> operation work?  If we change the above program to the BlinkToRadioC
> example, and communicate
> wirelessly, both send (green) and receive (red) LEDs flash as expected.
> 
>   Note that when one Tinynode is connected to a PC, and we run
> 
> java net.tinyos.tools.MsgReader -comm serial@/dev/ttyUSB0:tinynode
> BlinkToSerialMsg
> 
> the green LED flashes, and we see (e.g.)
> 
> 1337346452039: Message <BlinkToSerialMsg>
>   [nodeid=0x1]
>   [counter=0x46]
> 
> as in the TinyOS Tutorial 4
>   Mote-PC serial communication and SerialForwarder (pre-T2.1.1) running
> the
> MsgReader.java program
> This means the BlinkToSerialC.nc program is communicating with a PC. 
> Also,
> when we change the program
> on the PC to TestSerial (with a nodeid added to permit the Tinynode to
> send
> and receive serial data), and run
>    java TestSerial -comm serial@/dev/ttyUSB0:tinynode
> we see
>    Sending packet 30
>    Received packet sequence number 491
>    Received packet sequence number 492
>    Received packet sequence number 493
>    Received packet sequence number 494
>    Received packet sequence number 495
> The red LED also flashes on the Tinynode, indicating that the sent serial
> messages (e.g. packet 30 above)
> are received.  The green LED also flashes on the Tinynode.  The above
> "Received packet" messages indicate the messages sent by the Tinynode are
> received by the PC.  So,
> the Tinynode can receive packets from the PC.
> 
>   Does anyone have experience in mote-to-mote serial communication?  The
> reason we need this is we
> are trying to connect a serial device to a Tinynode (which must receive
> the
> data over the UART).  This
> received data will then be sent (wirelessly) to another Tinynode.
> 
> -- 
> Luis Alejandro Navarro Mollejas.
> Estudiante de la Universidad Simón Bolívar.
> 
> Correo Alternativo:   [email protected] <[email protected]>
> Teléfono:                 +584265579497
> 
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
> 

-- 
View this message in context: 
http://old.nabble.com/Mote-to-mote-serial-communication--tp33874679p33971798.html
Sent from the TinyOS - Help mailing list archive at Nabble.com.


_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to