Emanuel Kuflik
/
smat_controller
541 smart traffic controller
Diff: AccCar.cpp
- Revision:
- 5:e0d8e5e922f1
- Parent:
- 2:f10d6fecb345
- Child:
- 6:6cb13ac483e0
diff -r 64c6fc70ddb7 -r e0d8e5e922f1 AccCar.cpp --- a/AccCar.cpp Fri Dec 06 20:34:52 2019 +0000 +++ b/AccCar.cpp Tue Dec 10 23:39:25 2019 +0000 @@ -9,7 +9,8 @@ #define MONITOR_DIST 17 #define SAFETY_GAP 2 -#define DEBUG_ACC +//#define DEBUG_ACC +#define ACC_TAG "[ACC] " // speed for a legal stop #define STOPPED_SPEED 0 @@ -40,7 +41,7 @@ msg->car_id = this->car_id; msg->road_id = this->road->get_road_id(); msg->counter = this->road->get_road_clock(); - msg->state = this->state; + //msg->state = this->state; } // if a null pointer is sent this means no car is in front and it is the lead car. @@ -96,7 +97,22 @@ ThisThread::sleep_for(TICK); road->go_flags.wait_all(flag); cycles++; +// if(cycles > 1) +// { + // get_control message may need to malloc the message or something +// control_msg_t* c_msg = this->singleton->get_control_msg(this->car_id); + + // + // do something with the control message +// assert(c_msg->car_id == car_id ); +// speed = c_msg->speed; +// delete c_msg; +// } + position = position + speed; + + + if( (cycles % 5) == 0) { get_new_target_speed(); @@ -119,20 +135,34 @@ assert(state == NORMAL_STATE); } -#ifdef DEBUG_ACC - printf("sending position to server\r\n"); -#endif +//#ifdef DEBUG_ACC +// printf(ACC_TAG "sending position to server DELIM"); +//#endif +//#ifdef DEBUG_ACC +// printf(ACC_TAG "car %d done DELIM",car_id); +//#endif + // make a message make_position_msg(msg); // stuff a message in the queue this->singleton->add_to_position_queue(msg); +#ifndef PUBLISH_ONLY // // get_control message may need to malloc the message or something control_msg_t* c_msg = this->singleton->get_control_msg(this->car_id); + // + // do something with the control message + assert(c_msg->car_id == car_id ); + speed = c_msg->speed; + + // + // delete the control message + delete c_msg; +#endif // set flag for completion of cycle road->done_flags.set(this->flag); } @@ -161,6 +191,7 @@ if (thread != NULL) { thread->terminate(); } + delete thread; delete msg; }