From 4c550a479530c4c1b2569b194dae2be6afb66088 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期五, 13 三月 2020 16:22:01 +0800
Subject: [PATCH] 更新地图
---
lib/src/main/cpp/driver_test.cpp | 2
lib/src/main/cpp/test_common/car_sensor.h | 35 +++++++++++
lib/src/main/cpp/test_common/car_sensor.cpp | 117 +++++++++++++++++++++++++++++++++++++++
3 files changed, 153 insertions(+), 1 deletions(-)
diff --git a/lib/src/main/cpp/driver_test.cpp b/lib/src/main/cpp/driver_test.cpp
index 80ccb06..1429252 100644
--- a/lib/src/main/cpp/driver_test.cpp
+++ b/lib/src/main/cpp/driver_test.cpp
@@ -437,7 +437,7 @@
RtkBuffer[index].mm, RtkBuffer[index].ss, RtkBuffer[index].dss);
brief.qf = RtkBuffer[index].qf;
- brief.map_id = 867;//GetMapId(CurrExamMapIndex, MapList, MapNum);
+ brief.map_id = GetMapId(CurrExamMapIndex, MapList, MapNum);
brief.move = move;
brief.speed = speed * 3.6;
brief.heading = RtkBuffer[index].heading;
diff --git a/lib/src/main/cpp/test_common/car_sensor.cpp b/lib/src/main/cpp/test_common/car_sensor.cpp
new file mode 100644
index 0000000..73afdc4
--- /dev/null
+++ b/lib/src/main/cpp/test_common/car_sensor.cpp
@@ -0,0 +1,117 @@
+//
+// Created by fctom on 2020/2/13.
+//
+
+#include <pthread.h>
+#include "car_sensor.h"
+#include "../driver_test.h"
+#include "../defs.h"
+#include "../common/apptimer.h"
+#include "../jni_log.h"
+
+#define DEBUG(fmt, args...) LOGD("<car_sensor> <%s>: " fmt, __func__, ##args)
+
+#define MAX_SENSOR_NUM 32
+
+static uint16_t gpioStore = 0;
+static int engine_rpm = 0;
+
+static struct sensor_cfg {
+ int gpioId;
+ int funId;
+ int validLvl;
+ int currValue;
+} SensorConfig[MAX_SENSOR_NUM];
+static int SensorNum = 0;
+
+static pthread_mutex_t sonser_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void CarSensorInit(void)
+{
+ gpioStore = 0;
+ SensorNum = 0;
+ memset(SensorConfig, 0, sizeof(SensorConfig));
+
+ pthread_mutex_init(&sonser_mutex, NULL);
+}
+
+void SetSensorCfg(int (*sensor)[3], int sensorNum)
+{
+ DEBUG("鍔犲叆浼犳劅鍣ㄩ厤缃� sensorNum %d", sensorNum);
+
+ pthread_mutex_lock(&sonser_mutex);
+
+ SensorNum = sensorNum;
+ for (int i = 0; i < sensorNum; ++i) {
+ SensorConfig[i].gpioId = sensor[i][0];
+ SensorConfig[i].funId = sensor[i][1];
+ if (sensor[i][2] > 0) {
+ SensorConfig[i].validLvl = 1;
+ } else {
+ SensorConfig[i].validLvl = 0;
+ }
+ if (gpioStore & BV(SensorConfig[i].gpioId)) {
+ SensorConfig[i].currValue = 1;
+ } else {
+ SensorConfig[i].currValue = 0;
+ }
+ }
+
+ pthread_mutex_unlock(&sonser_mutex);
+}
+
+void UpdateSensor(uint16_t gpio, uint16_t speed, uint16_t engine)
+{
+ uint16_t chg = 0;
+
+ int reportSensor[MAX_SENSOR_NUM];
+ int reportValue[MAX_SENSOR_NUM];
+ int reportNum = 0;
+
+ pthread_mutex_lock(&sonser_mutex);
+
+ chg = gpioStore^gpio;
+ gpioStore = gpio;
+ engine_rpm = engine;
+
+ for (int i = 0; i < SensorNum; ++i) {
+ if (chg & BV(SensorConfig[i].gpioId)) {
+ if (gpio & BV(SensorConfig[i].gpioId)) {
+ SensorConfig[i].currValue = 1;
+ } else {
+ SensorConfig[i].currValue = 0;
+ }
+
+ reportSensor[reportNum] = SensorConfig[i].funId;
+ reportValue[reportNum] = (SensorConfig[i].validLvl == SensorConfig[i].currValue)?1:0;
+ reportNum++;
+ }
+ }
+
+ reportSensor[reportNum] = SENSOR_ENGINE_RPM;
+ reportValue[reportNum] = engine;
+ reportNum++;
+
+ pthread_mutex_unlock(&sonser_mutex);
+
+ SensorChanged(reportSensor, reportValue, reportNum);
+}
+
+int ReadSensor(uint16_t sensor_id)
+{
+ int ret = -1;
+
+ pthread_mutex_lock(&sonser_mutex);
+ for (int i = 0; i < SensorNum; ++i) {
+ if (sensor_id == SensorConfig[i].funId) {
+ ret = (SensorConfig[i].validLvl == SensorConfig[i].currValue)?1:0;
+ }
+ }
+
+ if (sensor_id == SENSOR_ENGINE_RPM) {
+ ret = engine_rpm;
+ }
+ pthread_mutex_unlock(&sonser_mutex);
+
+ return ret;
+}
diff --git a/lib/src/main/cpp/test_common/car_sensor.h b/lib/src/main/cpp/test_common/car_sensor.h
new file mode 100644
index 0000000..ef94afd
--- /dev/null
+++ b/lib/src/main/cpp/test_common/car_sensor.h
@@ -0,0 +1,35 @@
+//
+// Created by fctom on 2020/2/13.
+//
+
+#ifndef MYAPPLICATION2_COMM_TEST_H
+#define MYAPPLICATION2_COMM_TEST_H
+
+#include <cstdint>
+
+enum {
+ SENSOR_SEATBELT,
+ SENSOR_LEFT_TURN_SIGNAL,
+ SENSOR_RIGHT_TURN_SIGNAL,
+ SENSOR_HANDBREAK,
+ SENSOR_BREAK,
+ SENSOR_LIGHT,
+ SENSOR_FAR_LIGHT,
+ SENSOR_DOOR,
+ SENSOR_SHIFT_N,
+ SENSOR_SHIFT_1,
+ SENSOR_SHIFT_2,
+ SENSOR_SHIFT_3,
+ SENSOR_SHIFT_4,
+ SENSOR_SHIFT_5,
+ SENSOR_SHIFT_R,
+ SENSOR_ENGINE_START,
+ SENSOR_ENGINE_RPM
+};
+
+void CarSensorInit(void);
+int ReadSensor(uint16_t sensor_id);
+void UpdateSensor(uint16_t gpio, uint16_t speed, uint16_t engine);
+void SetSensorCfg(int (*sensor)[3], int sensorNum);
+
+#endif //MYAPPLICATION2_COMM_TEST_H
--
Gitblit v1.8.0