yy1717
2020-03-13 4c550a479530c4c1b2569b194dae2be6afb66088
更新地图
1个文件已修改
2个文件已添加
154 ■■■■■ 已修改文件
lib/src/main/cpp/driver_test.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/cpp/test_common/car_sensor.cpp 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/cpp/test_common/car_sensor.h 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
lib/src/main/cpp/test_common/car_sensor.cpp
New file
@@ -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;
}
lib/src/main/cpp/test_common/car_sensor.h
New file
@@ -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