Skip to content

Commit 1e75fad

Browse files
committed
Fixing merge conflicts.
2 parents cba5e29 + dd50743 commit 1e75fad

39 files changed

+1696
-312
lines changed

.cproject

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Bench/eRPC/InjectionControl}&quot;"/>
158158
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Bench/eRPC/TaskScheduler}&quot;"/>
159159
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Bench/eRPC/Diagnostics}&quot;"/>
160+
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Bench/eRPC/AdaptiveSensor}&quot;"/>
161+
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Bench/AdaptiveSensor/Inc}&quot;"/>
160162
</option>
161163
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1078652032" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
162164
<listOptionValue builtIn="false" value="DEBUG"/>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef ADAPTIVESENSOR_HPP_
2+
#define ADAPTIVESENSOR_HPP_
3+
4+
#include <cstdint>
5+
6+
#define ADAPT_SW_VER_STRLEN 9 // xxx.yyya
7+
#define ADAPT_HW_VER_STRLEN 8 // xxx.yyy
8+
#define ADAPT_ART_STRLEN 12 // 1-aabbcc-dd
9+
10+
/**
11+
* @brief Abstract base class for adaptive sensor
12+
*/
13+
class AdaptiveSensor {
14+
public:
15+
virtual ~AdaptiveSensor() = default;
16+
17+
virtual void init() = 0;
18+
19+
virtual int8_t boardReset() = 0;
20+
virtual int8_t hardReset() = 0;
21+
virtual int8_t softReset() = 0;
22+
23+
virtual int8_t getFlowMeasurement(int32_t *value) = 0;
24+
25+
virtual int8_t getSwVersion(char swVersion[ADAPT_SW_VER_STRLEN]) = 0;
26+
virtual int8_t getHwVersion(char hwVersion[ADAPT_HW_VER_STRLEN]) = 0;
27+
virtual int8_t getArticle(char article[ADAPT_ART_STRLEN]) = 0;
28+
};
29+
30+
#endif /* ADAPTIVESENSOR_HPP_ */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef ADAPTIVESENSORCONTROL_H
2+
#define ADAPTIVESENSORCONTROL_H
3+
4+
#include "AdaptiveSensor.hpp"
5+
#include "AdaptiveSensorHw.hpp"
6+
#include "AdaptiveSensorSim.hpp"
7+
8+
#include <memory>
9+
10+
class AdaptiveSensorControl
11+
{
12+
public:
13+
AdaptiveSensorControl();
14+
void init();
15+
void serviceTask();
16+
17+
AdaptiveSensor *getSensor() { return m_sensor; };
18+
19+
private:
20+
std::unique_ptr<AdaptiveSensorSim> m_sensorSim;
21+
std::unique_ptr<AdaptiveSensorHw> m_sensorHw;
22+
AdaptiveSensor *m_sensor;
23+
};
24+
#endif //ADAPTIVESENSORCONTROL_H
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#ifndef ADAPTIVESENSORHW_HPP_
2+
#define ADAPTIVESENSORHW_HPP_
3+
4+
#include "AdaptiveSensor.hpp"
5+
#include "GpioDriver.hpp"
6+
7+
#include <vector>
8+
9+
#include "usart.h"
10+
11+
#define ADAPT_ADDRESS 1
12+
13+
#define ADAPT_CMD_GET_SW_VERSION 1
14+
#define ADAPT_CMD_GET_HW_VERSION 2
15+
#define ADAPT_CMD_GET_ARTICLE 10
16+
#define ADAPT_CMD_BOARD_RESET 11
17+
#define ADAPT_CMD_HARD_RESET 12
18+
#define ADAPT_CMD_SOFT_RESET 13
19+
#define ADAPT_CMD_GET_FLOW_MEAS 16
20+
21+
// pre-computed CRC8 crcs for the commands
22+
#define ADAPT_CRC_GET_SW_VERSION 0xB2
23+
#define ADAPT_CRC_GET_HW_VERSION 0x9F
24+
#define ADAPT_CRC_GET_ARTICLE 0xA8
25+
#define ADAPT_CRC_BOARD_RESET 0x5C
26+
#define ADAPT_CRC_HARD_RESET 0xF2
27+
#define ADAPT_CRC_SOFT_RESET 0x06
28+
#define ADAPT_CRC_GET_FLOW_MEAS 0x28
29+
30+
// timeout in milliseconds when expecting a response from adaptive sensor
31+
#define ADAPT_TIMEOUT 100
32+
33+
// structs are packed differently in gcc vs MSVC.
34+
// MSVC could be used to compile this for unit tests.
35+
#ifdef __GNUC__
36+
#define PACKED __attribute__((packed))
37+
#else
38+
#define PACKED
39+
#pragma pack(push, 1)
40+
#endif
41+
42+
struct adapt_comm_cmd {
43+
uint8_t address; // 0x01
44+
uint8_t cmd; // per above
45+
uint8_t len; // 0
46+
uint8_t crc; // crc8
47+
} PACKED;
48+
49+
#ifdef _MSC_VER
50+
#pragma pack(pop)
51+
#endif
52+
53+
/**
54+
* @brief Hardware implementation of the AdaptiveSensor using STM32 HAL.
55+
*/
56+
class AdaptiveSensorHw : public AdaptiveSensor
57+
{
58+
public:
59+
/**
60+
* @brief Constructor for AdaptiveSensorHw.
61+
* @param uart Pointer to the uart.
62+
* @param dePort GPIO port for RS485 drive enable.
63+
* @param dePin GPIO pin for RS485 drive enable.
64+
*
65+
* Because the schematic used the wrong pin for UART_DE, the DE pin needs to
66+
* handled manually instead of by the hal uart driver. Brkjing DE high to send
67+
* data and low to receive response.
68+
*/
69+
AdaptiveSensorHw(UART_HandleTypeDef* uart, GPIO_TypeDef* dePort, uint16_t dePin);
70+
71+
/**
72+
* @brief Initialize the hardware adaptive sensor
73+
*/
74+
void init() override;
75+
76+
/**
77+
* @brief Do a reset of the adaptive sensor board. Probably want this one
78+
* @return 0 on success, <0 on communication error, >0 on error returned from sensor
79+
*/
80+
int8_t boardReset() override;
81+
82+
/**
83+
* @brief Do a hard reset of the sensor.
84+
* @return 0 on success, <0 on communication error, >0 on error returned from sensor
85+
*/
86+
int8_t hardReset() override;
87+
88+
/**
89+
* @brief Do a soft reset of the sensor.
90+
* @return 0 on success, <0 on communication error, >0 on error returned from sensor
91+
*/
92+
int8_t softReset() override;
93+
94+
/**
95+
* @brief Get the current flow getFlowMeasurement
96+
* @param[out] value Measured flow value in mSlm^2 (milli-standard-liters per minute)
97+
* Divide by 1000 to get slpm
98+
* @return 0 on success, <0 on communication error, >0 on error returned from sensor
99+
*/
100+
int8_t getFlowMeasurement(int32_t *value) override;
101+
102+
/**
103+
* @brief Get the software version of the adaptive sensor
104+
* @param[out] swVersion max 9 bytes xxx.yyyc (ex: "10.32a"
105+
* @return 0 on success, <0 on communication error, >0 on error returned from sensor
106+
*/
107+
int8_t getSwVersion(char swVersion[ADAPT_SW_VER_STRLEN]) override;
108+
109+
/**
110+
* @brief Get the hardware version of the adaptive sensor
111+
* @param[out] swVersion max 9 bytes xxx.yyyc (ex: "10.32a"
112+
* @return 0 on success, <0 on communication error, >0 on error returned from sensor
113+
*/
114+
int8_t getHwVersion(char hwVersion[ADAPT_HW_VER_STRLEN]) override;
115+
116+
/**
117+
* @brief Get the "Sensirion article id" of the adaptive sensor for example 1-101053-01
118+
* @param[out] article max 12 bytes
119+
* @return 0 on success, <0 on communication error, >0 on error returned from sensor
120+
*/
121+
int8_t getArticle(char article[ADAPT_ART_STRLEN]) override;
122+
123+
private:
124+
UART_HandleTypeDef* m_uart;
125+
GpioDriver m_driveEnable;
126+
127+
int8_t sendCmd(const struct adapt_comm_cmd& cmd);
128+
int8_t getResponse(uint8_t cmd, uint8_t *response, size_t sz);
129+
bool verifyCrc(const std::vector<uint8_t>& msg);
130+
};
131+
132+
extern void adaptiveSensorUartCallback(UART_HandleTypeDef *huart);
133+
134+
#endif /* ADAPTIVESENSORHW_HPP_ */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef ADAPTIVESENSORSIM_HPP_
2+
#define ADAPTIVESENSORSIM_HPP_
3+
4+
#include "AdaptiveSensor.hpp"
5+
6+
/**
7+
* @brief Simulation implementation of the AdaptiveSensor for testing.
8+
*/
9+
class AdaptiveSensorSim : public AdaptiveSensor
10+
{
11+
public:
12+
/**
13+
* @brief Initialize the simulated heater.
14+
*/
15+
void init() override;
16+
17+
int8_t boardReset() override;
18+
int8_t hardReset() override;
19+
int8_t softReset() override;
20+
21+
int8_t getFlowMeasurement(int32_t *value) override;
22+
23+
int8_t getSwVersion(char swVersion[ADAPT_SW_VER_STRLEN]) override;
24+
int8_t getHwVersion(char hwVersion[ADAPT_HW_VER_STRLEN]) override;
25+
int8_t getArticle(char article[ADAPT_ART_STRLEN]) override;
26+
27+
private:
28+
29+
};
30+
31+
#endif /* ADAPTIVESENSORSIM_HPP_ */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "main.h"
2+
3+
#include "AdaptiveSensorControl.hpp"
4+
5+
AdaptiveSensorControl::AdaptiveSensorControl()
6+
{
7+
m_sensorSim = std::make_unique<AdaptiveSensorSim>();
8+
m_sensorHw = std::make_unique<AdaptiveSensorHw>(ADS_UART, ADS_RE_GPIO_Port, ADS_RE_Pin);
9+
}
10+
11+
void AdaptiveSensorControl::init()
12+
{
13+
#ifdef ERCPSIM
14+
m_sensor = m_sensorSim.get();
15+
#else
16+
m_sensor = m_sensorHw.get();
17+
#endif
18+
m_sensor->init();
19+
}
20+
21+
void AdaptiveSensorControl::serviceTask()
22+
{
23+
// Since adaptive sensor can be hotplugged, maybe check here to see if it's attached
24+
}

0 commit comments

Comments
 (0)