*/
#include <RF230Packet.h>
+#include <TimeSyncMessage.h>
module RF230PacketP
{
interface PacketField<uint8_t> as PacketTransmitPower;
interface PacketField<uint8_t> as PacketRSSI;
interface PacketField<uint16_t> as PacketSleepInterval;
+ interface PacketField<uint8_t> as PacketTimeSyncOffset;
- interface PacketTimeStamp<TRF230, uint16_t>;
- interface PacketLastTouch;
-
- async event void lastTouch(message_t* msg);
+ interface PacketTimeStamp<TRF230, uint32_t> as PacketTimeStampRadio;
+ interface PacketTimeStamp<TMilli, uint32_t> as PacketTimeStampMilli;
}
uses
{
interface IEEE154Packet;
+
+ interface LocalTime<TRF230> as LocalTimeRadio;
+ interface LocalTime<TMilli> as LocalTimeMilli;
}
}
{
call IEEE154Packet.createDataFrame(msg);
-#ifdef IEEE154_6LOWPAN
- call IEEE154Packet.set6LowPan(msg, TINYOS_6LOWPAN_NETWORK_ID);
-#endif
-
getMeta(msg)->flags = RF230PACKET_CLEAR_METADATA;
}
call IEEE154Packet.setLength(msg, len + PACKET_LENGTH_INCREASE);
}
- // TODO: make Packet.payloadLength async
inline command uint8_t Packet.payloadLength(message_t* msg)
{
return call IEEE154Packet.getLength(msg) - PACKET_LENGTH_INCREASE;
}
- // TODO: make Packet.maxPayloadLength async
inline command uint8_t Packet.maxPayloadLength()
{
return TOSH_DATA_LENGTH;
getMeta(msg)->lqi = value;
}
-/*----------------- PacketTimeStamp -----------------*/
+/*----------------- PacketTimeStampRadio -----------------*/
- async command bool PacketTimeStamp.isSet(message_t* msg)
+ async command bool PacketTimeStampRadio.isValid(message_t* msg)
{
return getMeta(msg)->flags & RF230PACKET_TIMESTAMP;
}
- async command uint16_t PacketTimeStamp.get(message_t* msg)
+ async command uint32_t PacketTimeStampRadio.timestamp(message_t* msg)
{
return getMeta(msg)->timestamp;
}
- async command void PacketTimeStamp.clear(message_t* msg)
+ async command void PacketTimeStampRadio.clear(message_t* msg)
{
getMeta(msg)->flags &= ~RF230PACKET_TIMESTAMP;
}
- async command void PacketTimeStamp.set(message_t* msg, uint16_t value)
+ async command void PacketTimeStampRadio.set(message_t* msg, uint32_t value)
{
getMeta(msg)->flags |= RF230PACKET_TIMESTAMP;
getMeta(msg)->timestamp = value;
}
+/*----------------- PacketTimeStampMilli -----------------*/
+
+ async command bool PacketTimeStampMilli.isValid(message_t* msg)
+ {
+ return call PacketTimeStampRadio.isValid(msg);
+ }
+
+ async command uint32_t PacketTimeStampMilli.timestamp(message_t* msg)
+ {
+ int32_t offset = call PacketTimeStampRadio.timestamp(msg) - call LocalTimeRadio.get();
+
+ // TODO: Make the shift constant configurable
+ return (offset >> 10) + call LocalTimeMilli.get();
+ }
+
+ async command void PacketTimeStampMilli.clear(message_t* msg)
+ {
+ call PacketTimeStampRadio.clear(msg);
+ }
+
+ async command void PacketTimeStampMilli.set(message_t* msg, uint32_t value)
+ {
+ // TODO: Make the shift constant configurable
+ int32_t offset = (value - call LocalTimeMilli.get()) << 10;
+
+ call PacketTimeStampRadio.set(msg, offset + call LocalTimeRadio.get());
+ }
+
/*----------------- PacketTransmitPower -----------------*/
async command bool PacketTransmitPower.isSet(message_t* msg)
getMeta(msg)->power = value;
}
-/*----------------- Global fields -----------------*/
-
- norace uint8_t flags;
- enum
- {
- FLAG_SLEEPINT = 0x01,
- };
-
- // TODO: Move sleepInterval into the metadata
- norace uint16_t sleepInterval;
-
-/*----------------- PacketSleepInterval -----------------*/
+/*----------------- PacketTimeSyncOffset -----------------*/
- async command bool PacketSleepInterval.isSet(message_t* msg)
+ async command bool PacketTimeSyncOffset.isSet(message_t* msg)
{
- return flags & FLAG_SLEEPINT;
+ return getMeta(msg)->flags & RF230PACKET_TIMESYNC;
}
- async command uint16_t PacketSleepInterval.get(message_t* msg)
+ async command uint8_t PacketTimeSyncOffset.get(message_t* msg)
{
- return sleepInterval;
+ return call IEEE154Packet.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_absolute_t);
}
- async command void PacketSleepInterval.clear(message_t* msg)
+ async command void PacketTimeSyncOffset.clear(message_t* msg)
{
- flags &= ~FLAG_SLEEPINT;
+ getMeta(msg)->flags &= ~RF230PACKET_TIMESYNC;
}
- async command void PacketSleepInterval.set(message_t* msg, uint16_t value)
+ async command void PacketTimeSyncOffset.set(message_t* msg, uint8_t value)
{
- flags |= FLAG_SLEEPINT;
- sleepInterval = value;
+ // the value is ignored, the offset always points to the timesync footer at the end of the payload
+ getMeta(msg)->flags |= RF230PACKET_TIMESYNC;
}
-/*----------------- PacketLastTouch -----------------*/
-
- async command void PacketLastTouch.request(message_t* msg)
- {
- getMeta(msg)->flags |= RF230PACKET_LAST_TOUCH;
- }
+/*----------------- PacketSleepInterval -----------------*/
- async command void PacketLastTouch.cancel(message_t* msg)
+ async command bool PacketSleepInterval.isSet(message_t* msg)
{
- getMeta(msg)->flags &= ~RF230PACKET_LAST_TOUCH;
+ return getMeta(msg)->flags & RF230PACKET_LPL_SLEEPINT;
}
- async command bool PacketLastTouch.isPending(message_t* msg)
+ async command uint16_t PacketSleepInterval.get(message_t* msg)
{
- return getMeta(msg)->flags & RF230PACKET_LAST_TOUCH;
+#ifdef LOW_POWER_LISTENING
+ return getMeta(msg)->lpl_sleepint;
+#else
+ return 0;
+#endif
}
- async event void lastTouch(message_t* msg)
+ async command void PacketSleepInterval.clear(message_t* msg)
{
- if( getMeta(msg)->flags & RF230PACKET_LAST_TOUCH )
- signal PacketLastTouch.touch(msg);
+ getMeta(msg)->flags &= ~RF230PACKET_LPL_SLEEPINT;
}
- default async event void PacketLastTouch.touch(message_t* msg)
+ async command void PacketSleepInterval.set(message_t* msg, uint16_t value)
{
+ getMeta(msg)->flags |= RF230PACKET_LPL_SLEEPINT;
+
+#ifdef LOW_POWER_LISTENING
+ getMeta(msg)->lpl_sleepint = value;
+#endif
}
}