brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #ifndef __VXWORKS__ |
| 2 | #include "aos/common/network/ReceiveSocket.h" |
| 3 | #include "aos/common/Configuration.h" |
| 4 | #endif |
Brian Silverman | a9cbe30 | 2013-03-12 18:41:44 -0700 | [diff] [blame^] | 5 | #include "aos/common/logging/logging.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 6 | |
| 7 | namespace aos { |
| 8 | |
| 9 | #ifdef __VXWORKS__ |
| 10 | template<class Values> SEM_ID SensorInput<Values>::lock_ = semBCreate(SEM_Q_PRIORITY, SEM_FULL); |
| 11 | template<class Values> std::vector<SensorInput<Values> *> SensorInput<Values>::running_; |
| 12 | #endif |
| 13 | template<class Values> void SensorInput<Values>::Run() { |
| 14 | #ifndef __VXWORKS__ |
| 15 | ReceiveSocket sock(NetworkPort::kSensors); |
| 16 | Values values; |
| 17 | while (true) { |
| 18 | if (sock.Recv(&values, sizeof(values)) == -1) { |
| 19 | LOG(WARNING, "socket receive failed\n"); |
| 20 | continue; |
| 21 | } |
| 22 | RunIteration(values); |
| 23 | } |
| 24 | #else |
| 25 | semTake(lock_, WAIT_FOREVER); |
| 26 | running_.push_back(this); |
| 27 | semGive(lock_); |
| 28 | #endif |
| 29 | } |
| 30 | |
| 31 | #ifdef __VXWORKS__ |
| 32 | template<class Values> void SensorInput<Values>::RunIterationAll(Values &vals) { |
| 33 | semTake(lock_, WAIT_FOREVER); |
| 34 | for (auto it = running_.begin(); it != running_.end(); ++it) { |
| 35 | (*it)->RunIteration(vals); |
| 36 | } |
| 37 | semGive(lock_); |
| 38 | } |
| 39 | #endif |
| 40 | |
| 41 | } // namespace aos |