not running

Dependencies:   TextLCD MQTT

Revision:
0:3b4906b8a747
Child:
2:16b3bd337db2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Road.cpp	Tue Dec 10 22:29:09 2019 +0000
@@ -0,0 +1,57 @@
+#include "Road.h"
+
+Serial pc_road(USBTX, USBRX);
+
+Road::Road(char* t1, char* t2) {
+    active_cars = 0x00;
+    topic_send = t1; // road publish, controller receive
+    topic_receive = t2; // road receive, controller publish
+    comm = Communication::getInstance();
+    comm->subscribe_to_topic_sync(topic_receive); // for receiving sync messages
+    n = 0;
+}
+
+void Road::add_car(Car* car) {
+    // this->car1 = car;
+
+    active_cars = active_cars | car->flag;
+}
+
+void Road::add_acc_car(AccCar* car, int id) {
+    active_cars = active_cars | car->flag;
+
+    switch(id) {
+      case 1: {
+        this->car1 = car;
+        break;
+      }
+      case 2: {
+        this->car2 = car;
+        break;
+      }
+      case 3: {
+        this->car3 = car;
+        break;
+      }
+      case 4: {
+        this->car4 = car;
+        break;
+      }
+      case 5: {
+        this->car5 = car;
+        break;
+      }
+    }
+}
+
+void Road::let_cars_update() {
+    go_flags.set(active_cars);
+}
+
+void Road::wait_for_car_update() {
+    done_flags.wait_all(active_cars);
+    n = n + 1;
+    comm->publish_road(topic_send, n);
+    Communication::sync_flags.wait_all(0x01);
+    n = Communication::sync;
+}