Hi,
I finally implemented the queues and they work fine.
Just one question, do you think it is a good idea?
Eric, you suggested there may be another easier way but I did not
grasp it. I had a look at SerialAMSender but I did not understand very
much, :-(
This is the code just in case somebody faces the same problem.
// Define messages...
typedef struct OutputResultMsg {
float result [2];
int8_t meas[NUM_ANCHORS];
uint16_t numAvailableMeas[NUM_ANCHORS];
uint16_t numComputedMeas;
bool ready2Compute;
} OutputResultMsg;
// Declare queues of those messages
interface Queue <MeasurementMsg> as QueueMeas;
interface Queue <ControlANSMsg> as QueueANS;
interface Queue <OutputResultMsg> as QueueResult;
// Set serial pointers at the beginning of the implementation
event void SerialSplitControl.startDone(error_t error){
if (error == SUCCESS) {
busySerialTx = FALSE;
pointerSerialMeasSend = (MeasurementMsg *) call
SerialMeasSend.getPayload(&pktSerialMeas, (uint8_t) NULL);
pointerSerialControlANS = (ControlANSMsg *) call
SerialControlANSSend.getPayload(&pktSerialControlANS, (uint8_t) NULL);
pointerSerialResult = (OutputResultMsg *) call
SerialOutputResultSend.getPayload(&pktSerialResult, (uint8_t) NULL);
call Leds.set(0);
}
else {
call SerialSplitControl.start();
call Leds.set(ERROR_LEDS_INIT);
}
}
// Whenever you want to asynchronously send, you'd better enqueue
post putQueueMeas (); // instead of "post serialSendMeas()"
// Define tasks for appending to each queue and sending through serial port
task void putQueueMeas () {
call QueueMeas.enqueue (*pointerSerialMeasSend);
post serialSend ();
}
task void putQueueANS () {
call QueueANS.enqueue (*pointerSerialControlANS);
post serialSend ();
}
task void putQueueResult () {
call QueueResult.enqueue (*pointerSerialResult);
post serialSend ();
}
task void serialSend () {
if (!busySerialTx) {
if (call QueueMeas.size() > 0 ) {
*pointerSerialMeasSend = call QueueMeas.head();
if (call SerialMeasSend.send(AM_BROADCAST_ADDR,
&pktSerialMeas,
sizeMeas) == SUCCESS)
busySerialTx = TRUE;
} else if (call QueueANS.size() > 0 ) {
*pointerSerialControlANS = call QueueANS.head();
if (call
SerialControlANSSend.send(AM_BROADCAST_ADDR,
&pktSerialControlANS, sizeANS) == SUCCESS)
busySerialTx = TRUE;
} else if (call QueueResult.size() > 0 ) {
*pointerSerialResult = call QueueResult.head();
if (call
SerialOutputResultSend.send(AM_BROADCAST_ADDR,
&pktSerialResult, sizeResult) == SUCCESS)
busySerialTx = TRUE;
}
}
}
// Signal that serial buffer is free and continue with pending jobs
event void SerialControlANSSend.sendDone(message_t *msg, error_t error){
if ( error == SUCCESS )
call QueueANS.dequeue();
busySerialTx = FALSE;
post serialSend();
}
event void SerialMeasSend.sendDone(message_t *msg, error_t error){
if ( error == SUCCESS )
call QueueMeas.dequeue();
busySerialTx = FALSE;
post serialSend();
}
event void SerialOutputResultSend.sendDone(message_t *msg, error_t
error){
if ( error == SUCCESS )
call QueueResult.dequeue();
busySerialTx = FALSE;
post serialSend ();
}
Thanks!!!
Sergio
On Mon, Jan 3, 2011 at 9:07 PM, Eric Decker <[email protected]> wrote:
>
>
> On Mon, Jan 3, 2011 at 11:45 AM, Sergio Valcarcel <[email protected]>
> wrote:
>>
>> Dear Eric,
>>
>> Thanks so much for your fast respond! :-)
>>
>> I basically want to be able to asynchronously send messages to the
>> serial port. Those messages come from different AM channels (e.g.
>> measurements, computation results and control answers).
>
> Right. Sounds like what you want is a virtualization of the Serial AM port.
>
>>
>> However, what I understand from Phil's mail is that many instances of
>> AMSend will just simply try to write in the same buffer.
>
> That is correct and why you need to virtualize it. Once virtualized then
> each client has their own virtual interface to SerialAM and its AMSend
> interface.
>
>>
>> So if the
>> buffer has not been released (signaled via AMSend.sendDone) it will
>> result in error = FAIL.
>> Is that right?
>
> Correct.
>
>>
>> I think I could use one queue per kind of message and assign them a
>> priority as the order to empty them.
>> What do you think?
>
> You could do this. But it is a lot of bother. I'd suggest starting by
> looking
> at code that uses SerialAMSender.
> eric
>
>>
>> Thanks!
>> Sergio
>>
>> On Mon, Jan 3, 2011 at 7:34 PM, Eric Decker <[email protected]> wrote:
>> >
>> >
>> > On Mon, Jan 3, 2011 at 7:49 AM, Sergio Valcarcel <[email protected]>
>> > wrote:
>> >>
>> >> Happy New Year!!!!
>> >>
>> >> Please, regarding the discussion in:
>> >>
>> >>
>> >> http://www.mail-archive.com/[email protected]/msg10654.html
>> >>
>> >> I do not see how to use the queue when using different kind of
>> >> messages. In this case I think that different instances of AMSend
>> >> suits better.
>> >>
>> >> Should I have to use as many queues as kinds of message?
>> >
>> > Depends on what behaviour you want and what the queuing behaviour of
>> > message
>> > generation looks like.
>> > Starting off with just one instance of each message should be fine.
>> > The
>> > queueing happens
>> > at a simple level at the AMSender.
>> >
>> >>
>> >> Thanks!
>> >> Sergio
>> >> _______________________________________________
>> >> Tinyos-help mailing list
>> >> [email protected]
>> >>
>> >> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>> >
>> >
>> >
>> > --
>> > Eric B. Decker
>> > Senior (over 50 :-) Researcher
>> >
>> >
>> >
>
>
>
> --
> Eric B. Decker
> Senior (over 50 :-) Researcher
>
>
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help