
not running
Diff: main.cpp
- Revision:
- 2:16b3bd337db2
- Parent:
- 1:19c3299ea83a
--- a/main.cpp Tue Dec 10 23:40:25 2019 +0000 +++ b/main.cpp Wed Dec 11 20:20:12 2019 +0000 @@ -14,6 +14,7 @@ #include <algorithm> #include <vector> +#include <queue> #include <string> #include <stdlib.h> @@ -62,34 +63,25 @@ Intersection intersection; // Initialize Communication - Communication* communication = Communication::getInstance(); - communication->send_message("Rahman/Sync/Send/1"); + + char buf1[30] = "Rahman/Position/2"; + char buf2[30] = "Rahman/Control/2"; + char buf3[50] = "Rahman/Sync/Receive/2"; + char buf4[50] = "Rahman/Sync/Send/2"; + Communication* c = Communication::getInstance(buf1, buf2, buf3, buf4); + // Initialize 5 AccCars and the Road - char buf1[50] = "Rahman/Sync/Receive/1"; - char buf2[50] = "Rahman/Sync/Send/1"; - Road road1(buf1, buf2); + + Road road1(c); intersection.road1 = &road1; road1.intersection = &intersection; - char buf11[30] = "Rahman/Position/1/1"; - char buf12[30] = "Rahman/Control/1/1"; - AccCar car11(1, &road1, 0x01, buf11, buf12); - char buf21[30] = "Rahman/Position/1/2"; - char buf22[30] = "Rahman/Control/1/2"; - AccCar car12(2, &road1, 0x02, buf21, buf22); - - char buf31[30] = "Rahman/Position/1/3"; - char buf32[30] = "Rahman/Control/1/3"; - AccCar car13(3, &road1, 0x04, buf31, buf32); - - char buf41[30] = "Rahman/Position/1/4"; - char buf42[30] = "Rahman/Control/1/4"; - AccCar car14(4, &road1, 0x08, buf41, buf42); - - char buf51[30] = "Rahman/Position/1/5"; - char buf52[30] = "Rahman/Control/1/5"; - AccCar car15(5, &road1, 0x10, buf51, buf52); + AccCar car11(1, &road1, 0x01, c); + AccCar car12(2, &road1, 0x02, c); + AccCar car13(3, &road1, 0x04, c); + AccCar car14(4, &road1, 0x08, c); + AccCar car15(5, &road1, 0x10, c); std::vector<AccCar*> q1; q1.push_back(&car15); @@ -106,8 +98,10 @@ stopwatch.start(); - communication->reset(); // start thread - + pc.printf("Dispatching communication thread.\r\n"); + + c->reset(); + int interval = MAX_SPEED - MIN_SPEED + 1; car11.reset(rand() % interval + MIN_SPEED); // set random speed [5, 15] car12.reset(rand() % interval + MIN_SPEED); @@ -115,6 +109,7 @@ car14.reset(rand() % interval + MIN_SPEED); car15.reset(rand() % interval + MIN_SPEED); +// c->reset(); stopwatch.reset(); int waitTime1 = 0; @@ -190,7 +185,7 @@ car13.stop(); car14.stop(); car15.stop(); - communication->stop(); + c->stop(); // ---------------------------------------------------------------------- // Timing statistics printout, do not modify