From c2aa474e128b4c133786759819463e30d93359a6 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期三, 17 六月 2020 13:36:46 +0800 Subject: [PATCH] time --- test/test_right_walk3 | 0 test/test_right_walk3.c | 5 ++++- algorithm/IndirectAlg.c | 44 +++++++++++++++++++++++++++----------------- test/test_right_walk | 0 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/algorithm/IndirectAlg.c b/algorithm/IndirectAlg.c index 45d95d8..0ad09fd 100644 --- a/algorithm/IndirectAlg.c +++ b/algorithm/IndirectAlg.c @@ -41,13 +41,16 @@ IndirectAlg::IndirectAlg(const initializer_list<Point> & points, const time_t & _keepTime, const Vector2 & _direction): keepTime(_keepTime), direction(_direction), mterminate(false) { - std::vector<Edge> edges; - initializer_list<Point>::iterator iter; - for(iter = points.begin(); iter < points.end(); iter++ ) { - edges.push_back({*iter, *(iter +1)}); + if (points.size() > 0) { + std::vector<Edge> edges; + initializer_list<Point>::iterator iter; + for(iter = points.begin(); iter < points.end(); iter++ ) { + edges.push_back({*iter, *(iter +1)}); + } + edges.push_back({*(points.end()), *(points.begin())}); + frame = Figure(edges); } - edges.push_back({*(points.end()), *(points.begin())}); - frame = Figure(edges); + mthread = std::thread(std::bind(&IndirectAlg::threadRoutine, this)); @@ -76,14 +79,16 @@ map<string, Status *>::iterator iter; Status *status = nullptr; while (!mterminate.load()) { - // err_msg(0, "===========thread==========run" ); - std::this_thread::sleep_for(std::chrono::seconds(this->keepTime)); + std::this_thread::sleep_for(std::chrono::seconds(this->keepTime * 2)); //sleep(this->keepTime); for(iter = statusMap.begin(); iter != statusMap.end(); iter++) { - //cout<<iter->first<<' '<<iter->second<<endl; + status = iter->second; if (status != nullptr) { - if(time_t(0) - status->lastTime > this->keepTime) { + // cout<< "iter " << iter->first <<' '<< iter->second << status->lastTime << endl; + // printf("%ld, %ld, %ld\n", time(NULL), status->lastTime, (time(0) - status->lastTime)); + if((time(NULL) - status->lastTime) > this->keepTime) { + std::cout << status->id << "鑴辩鐩戞帶鍖�, remove from map\n"; delete status; statusMap.erase(iter); } @@ -136,16 +141,20 @@ return false; } - - status->lastTime = record.timestamp; - Vector2 currentDirection = getVecor2(status -> lastCoordinate, record.coordinate); + if(difftime(record.timestamp, status->lastTime) >= this->keepTime) { +//printf("update lastCoordinate curtime=%ld, lastTime=%ld, diff=%f\n", record.timestamp, status->lastTime, difftime(record.timestamp, status->lastTime)); + status->lastTime = record.timestamp; + status->lastCoordinate = record.coordinate; + } + if (currentDirection.x == 0 && currentDirection.y == 0) { //娌″姩 printRecord(3, record); return false; } - status -> lastCoordinate = record.coordinate; + + //status -> lastCoordinate = record.coordinate; //閫嗚鍒ゆ柇 cos灏忎簬0鍗充袱涓悜閲忕殑澶硅澶т簬90搴�,琛ㄧず閫嗚浜� if(frame.contains(record.coordinate) && getVector2Angle(direction, currentDirection) <= 0) { if(status->firstInvalTime ==0) { @@ -159,7 +168,7 @@ status->lastInvalTime = record.timestamp; //printf("%鍚庣画鍙戠敓閫嗚鐨勬椂闂�=%ld\n", status->lastInvalTime); //閫嗚鏃堕棿瓒呰繃keeptime - if (status->lastInvalTime - status-> firstInvalTime >= keepTime) { + if (difftime(status->lastInvalTime, status->firstInvalTime) >= keepTime) { status->firstValTime = status->lastValTime = 0; printRecord(5, record); return true; @@ -170,12 +179,13 @@ } else { if(status->firstValTime ==0) { + //璁板綍绗竴娆℃纭璧版椂闂� status->firstValTime = status->lastValTime = record.timestamp; printRecord(7, record); } else { status->lastValTime = record.timestamp; - //閫嗚鏃堕棿瓒呰繃keeptime - if (status->lastValTime - status-> firstValTime >= keepTime) { + //姝g‘琛岃蛋鏃堕棿瓒呰繃keeptime + if (difftime(status->lastValTime, status->firstValTime) >= keepTime) { status->firstInvalTime = status->lastInvalTime = 0; printRecord(8, record); } diff --git a/test/test_right_walk b/test/test_right_walk index 95f4046..bf4aa5a 100755 --- a/test/test_right_walk +++ b/test/test_right_walk Binary files differ diff --git a/test/test_right_walk3 b/test/test_right_walk3 index d18ac4b..9f0a3eb 100755 --- a/test/test_right_walk3 +++ b/test/test_right_walk3 Binary files differ diff --git a/test/test_right_walk3.c b/test/test_right_walk3.c index 343f8f4..31ca7ff 100644 --- a/test/test_right_walk3.c +++ b/test/test_right_walk3.c @@ -105,8 +105,9 @@ char *targetPointXstr; char *targetPointYstr; //{"x":148,"y":45},{"x":148,"y":539},{"x":769,"y":539},{"x":769,"y":45} + //{148, 45}, {148, 539}, {769, 539}, {769, 45} Record record; - IndirectAlg indirectAlg((std::initializer_list<Point>){{148, 45}, {148, 539}, {769, 539}, {769, 45} }, 2, {621, 0}); + IndirectAlg indirectAlg((std::initializer_list<Point>){}, 3, {621, 0}); // const char *delim = " "; while(fin.getline(line, 1024)) { @@ -151,10 +152,12 @@ // printf("key = %s, value=%s\n", key, value); } fin.close(); + sleep(30); } int main() { test3(); + } -- Gitblit v1.8.0