Matthew Goldsmith
/
cis441projMS2b
CIS441 Proj MS 2b
Revision 16:cb7cbf2cc23b, committed 2019-12-13
- Comitter:
- kchen7
- Date:
- Fri Dec 13 22:14:27 2019 +0000
- Parent:
- 15:1d611d264a1f
- Commit message:
- final version;
Changed in this revision
--- a/Communication.cpp Fri Dec 13 21:31:24 2019 +0000 +++ b/Communication.cpp Fri Dec 13 22:14:27 2019 +0000 @@ -81,7 +81,7 @@ //callback for update/control messages void Communication::update_message_arrived(MQTT::MessageData& md) { - printf("UPDATE MESSAGE ARRIVED"); + printf("UPDATE MESSAGE ARRIVED\r\n"); MQTT::Message &message = md.message; char* payload = (char*)message.payload; printf("%s\r\n", payload); @@ -90,7 +90,6 @@ if(payload[4] != 'x') { speed = speed * 10 + payload[4] - 48; } - Road::road_in_use(NULL)->update_car_speed(id, speed); }
--- a/Road.cpp Fri Dec 13 21:31:24 2019 +0000 +++ b/Road.cpp Fri Dec 13 22:14:27 2019 +0000 @@ -9,6 +9,7 @@ intersection_car = -1; next_release = 0; num_cars = 0; + wait_counter = 0; pending_car = new AccCar(num_cars, this, pow(2, num_cars)); pending_car->set_target_speed(rand() % 11 + 5); @@ -107,6 +108,15 @@ } } +void Road::update_wait_counter() { + for (int i = 0; i < num_cars; i++) { + if (cars[i]->position == 54) { + wait_counter++; + printf("Wait Counter: %d\r\n", wait_counter); + } + } +} + void Road::wait_for_sync() { done_flags.wait_all(0xF0); } \ No newline at end of file
--- a/Road.h Fri Dec 13 21:31:24 2019 +0000 +++ b/Road.h Fri Dec 13 22:14:27 2019 +0000 @@ -15,6 +15,7 @@ EventFlags done_flags; int active_cars; int intersection_car; + int wait_counter; static Road* road_in_use(Road* new_road); static int ready(int new_ready); @@ -24,6 +25,7 @@ void wait_for_car_update(); int check_exit_cars(int cars[]); void update_car_speed(int id, int speed); + void update_wait_counter(); void print_status(); void publish_car_info();
--- a/main.cpp Fri Dec 13 21:31:24 2019 +0000 +++ b/main.cpp Fri Dec 13 22:14:27 2019 +0000 @@ -62,17 +62,23 @@ printf("successful publish: car info\r\n"); Communication::publish_road_ready(); - Communication::yield(500); + Communication::yield(50); while(Road::ready(-1) == 0) { Communication::yield(50); } + road1.update_wait_counter(); printf("----------------------\r\n"); } while( road1.active_cars > 0x00); // ---------------------------------------------------------------------- // Timing statistics printout, do not modify + printf("Average Wait Time: %fs \r\n", road1.wait_counter / 5.0); printf("Average update cycle took: %fms \r\n", (totalUpdateTime*1.0)/(numberCycles*1.0)); totalUpdateTime = 0; numberCycles = 0; // ---------------------------------------------------------------------- + while (true) { + Communication::publish_road_ready(); + wait(0.1); + } }