X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fplatforms%2Ftmirws%2Fsensors%2FAeroVaneReadP.nc;h=71d04b08b661655ad28bf04526220f6f99d51cfb;hb=69fc4c14eb331474d8c6654eebcf4147b7780ec8;hp=319614ace68334b4094af5ab7367cc3234c94751;hpb=0914119d47f1b35118297a00caa91a88122ccd46;p=tinyos-2.x.git diff --git a/tos/platforms/tmirws/sensors/AeroVaneReadP.nc b/tos/platforms/tmirws/sensors/AeroVaneReadP.nc index 319614ac..71d04b08 100644 --- a/tos/platforms/tmirws/sensors/AeroVaneReadP.nc +++ b/tos/platforms/tmirws/sensors/AeroVaneReadP.nc @@ -39,14 +39,11 @@ generic module AeroVaneReadP(uint16_t period) { provides interface Notify; uses { -#if 0 - interface Alarm; -#else interface Timer; -#endif interface Read; interface StdControl as AnemometerControl; - interface AsyncGet as Count; + interface Get as Revolutions; + interface Average; interface State; } } @@ -58,17 +55,13 @@ implementation { PHYS_PER_READ = 4, /* # of physical reads per reading */ }; - uint16_t m_count; - int m_vane; - int m_sum; + uint8_t m_count; + uint16_t m_speed; - task void readVane(); - - void init() + inline void init() { m_count = 0; - m_vane = 0; - m_sum = 0; + call Average.reset(); } command error_t Notify.enable() @@ -78,82 +71,49 @@ implementation { init(); call AnemometerControl.start(); - /* FIXME: First alarm should be synced to top of the next second. How? */ -#if 0 - call Alarm.start(call Alarm.getNow() + period); -#else + /* FIXME: How to get first Timer.fired() synced with top of hour? */ call Timer.startPeriodic(period); -#endif return SUCCESS; } command error_t Notify.disable() { call State.toIdle(); -#if 0 - call Alarm.stop(); -#else call Timer.stop(); -#endif call AnemometerControl.stop(); return SUCCESS; } -#if 0 - async event void Alarm.fired() -#else event void Timer.fired() -#endif { - //call Alarm.start(call Alarm.getAlarm() + period); - post readVane(); - } + if (++m_count == PHYS_PER_READ) { + /* Get anemometer revolutions for the period */ + m_speed = call Revolutions.get(); + } - task void readVane() - { - //call Alarm.start(call Alarm.getAlarm() + period); - if (!(call State.isIdle())) + if (!(call State.isIdle())) { + /* Avoid notifying if the user has disabled */ call Read.read(); - } - - int distance(int angle1, int angle2) - { - int d = angle2 - angle1; - - if (d <= -180) - d += 360; - else if (d > 180) - d -= 360; - return d; + } } event void Read.readDone(error_t error, uint16_t result) { - int newVane; - - if (error != SUCCESS) - return; - - newVane = m_vane + distance(m_vane, result); - m_sum += result; - m_vane = newVane; - if (++m_count == PHYS_PER_READ) { - norace aerovector_t vector; - - /* Get speed average */ - atomic vector.speed = (call Count.get() * 2.25) / (period * 4 / 1024) + - 0.5; - - /* Complete direction average */ - vector.dir = m_sum / PHYS_PER_READ; - while (vector.dir < 0) - vector.dir += 360; - vector.dir %= 360; - init(); - - /* Inform the consumer of the vector */ - if (!(call State.isIdle())) + if (error == SUCCESS) + call Average.submit(result); + + if (m_count == PHYS_PER_READ) { + if (call State.isIdle()) { + /* Avoid notifying if the user has disabled */ + init(); + } else { + aerovector_t vector; + + vector.dir = call Average.average(); + vector.speed = m_speed; + init(); signal Notify.notify(vector); + } } } }