blob: 667d2e8c4555e7afb7ade6a81c6016c35f0a7764 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#ifndef __VXWORKS__
2#include "aos/common/network/ReceiveSocket.h"
3#include "aos/common/Configuration.h"
4#endif
Brian Silvermana9cbe302013-03-12 18:41:44 -07005#include "aos/common/logging/logging.h"
brians343bc112013-02-10 01:53:46 +00006
7namespace aos {
8
9#ifdef __VXWORKS__
10template<class Values> SEM_ID SensorInput<Values>::lock_ = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
11template<class Values> std::vector<SensorInput<Values> *> SensorInput<Values>::running_;
12#endif
13template<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__
32template<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