copied everything over from 2012 and removed all of the actual robot code except the drivetrain stuff


git-svn-id: https://robotics.mvla.net/svn/frc971/2013/trunk/src@4078 f308d9b7-e957-4cde-b6ac-9a88185e7312
diff --git a/aos/common/input/SensorInput-tmpl.h b/aos/common/input/SensorInput-tmpl.h
new file mode 100644
index 0000000..e92a923
--- /dev/null
+++ b/aos/common/input/SensorInput-tmpl.h
@@ -0,0 +1,41 @@
+#include "aos/common/input/SensorInput.h"
+#ifndef __VXWORKS__
+#include "aos/common/network/ReceiveSocket.h"
+#include "aos/common/Configuration.h"
+#endif
+
+namespace aos {
+
+#ifdef __VXWORKS__
+template<class Values> SEM_ID SensorInput<Values>::lock_ = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
+template<class Values> std::vector<SensorInput<Values> *> SensorInput<Values>::running_;
+#endif
+template<class Values> void SensorInput<Values>::Run() {
+#ifndef __VXWORKS__
+	ReceiveSocket sock(NetworkPort::kSensors);
+  Values values;
+	while (true) {
+		if (sock.Recv(&values, sizeof(values)) == -1) {
+      LOG(WARNING, "socket receive failed\n");
+      continue;
+    }
+    RunIteration(values);
+	}
+#else
+  semTake(lock_, WAIT_FOREVER);
+  running_.push_back(this);
+  semGive(lock_);
+#endif
+}
+
+#ifdef __VXWORKS__
+template<class Values> void SensorInput<Values>::RunIterationAll(Values &vals) {
+  semTake(lock_, WAIT_FOREVER);
+  for (auto it = running_.begin(); it != running_.end(); ++it) {
+    (*it)->RunIteration(vals);
+  }
+  semGive(lock_);
+}
+#endif
+
+} // namespace aos
diff --git a/aos/common/input/SensorInput.h b/aos/common/input/SensorInput.h
new file mode 100644
index 0000000..7f8eaa7
--- /dev/null
+++ b/aos/common/input/SensorInput.h
@@ -0,0 +1,36 @@
+#ifndef AOS_INPUT_SENSOR_INPUT_H_
+#define AOS_INPUT_SENSOR_INPUT_H_
+
+#include "aos/aos_core.h"
+#ifdef __VXWORKS__
+#include <vector>
+#include <semLib.h>
+#endif
+
+namespace aos {
+
+// Class for implementing code that takes information from a sensor struct and
+// places it into queues. Subclasses should be compiled for both the atom and
+// the crio to support crio control loops.
+template<class Values> class SensorInput {
+ protected:
+  virtual void RunIteration(Values &values) = 0;
+ public:
+  // Enters an infinite loop that reads values and calls RunIteration.
+  void Run();
+
+#ifdef __VXWORKS__
+  // Calls RunIteration on all instances with values.
+  static void RunIterationAll(Values &values);
+ private:
+  static SEM_ID lock_;
+  static std::vector<SensorInput *> running_;
+#endif
+};
+
+} // namespace aos
+
+#include "SensorInput-tmpl.h"
+
+#endif
+