// // Created by YY on 2020/8/11. // #include "odo_graph.h" #include "../test_items2/road_exam.h" #include "../common/apptimer.h" #include "../utils/xconvert.h" static double odoGraph; static struct RtkTime odoTimer; static double odoPrevSpeed; static int odoCnt; void ResetOdo(void) { odoCnt = 0; odoGraph = 0; } double ReadOdo(void) { return odoGraph; } void UpdataOdo(double speed, int moveDirect, const struct RtkTime *rtkTime) { // 行驶距离,不包含倒车 if (odoCnt == 0 && moveDirect == 1) { odoPrevSpeed = speed; odoCnt = 1; odoTimer = *rtkTime; } else if (odoCnt == 1) { if (moveDirect == 1) { uint32_t tm = TimeGetDiff(rtkTime, &odoTimer); if (tm >= D_SEC(1)) { odoGraph += ((double) tm) * (odoPrevSpeed + speed) / 2.0 / 1000.0; odoTimer = *rtkTime; odoPrevSpeed = speed; } } else { odoCnt = 0; } } }