Доработка, исправление предупреждений.
This commit is contained in:
@@ -212,5 +212,12 @@
|
|||||||
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId=""/>
|
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
</scannerConfigBuildInfo>
|
</scannerConfigBuildInfo>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="refreshScope"/>
|
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||||
|
<configuration configurationName="Debug">
|
||||||
|
<resource resourceType="PROJECT" workspacePath="/STM32_CO2_NODE"/>
|
||||||
|
</configuration>
|
||||||
|
<configuration configurationName="Release">
|
||||||
|
<resource resourceType="PROJECT" workspacePath="/STM32_CO2_NODE"/>
|
||||||
|
</configuration>
|
||||||
|
</storageModule>
|
||||||
</cproject>
|
</cproject>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include "co2_can_protocol.hpp"
|
||||||
|
|
||||||
|
CANProtocol::CANProtocol(CAN_HandleTypeDef* hcan)
|
||||||
|
: can(hcan)
|
||||||
|
{
|
||||||
|
txHeader.StdId = 0x101;
|
||||||
|
txHeader.IDE = CAN_ID_STD;
|
||||||
|
txHeader.RTR = CAN_RTR_DATA;
|
||||||
|
txHeader.DLC = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CANProtocol::sendCO2(uint16_t ppm) {
|
||||||
|
data[0] = ppm >> 8;
|
||||||
|
data[1] = ppm & 0xFF;
|
||||||
|
|
||||||
|
uint32_t mailbox;
|
||||||
|
return HAL_CAN_AddTxMessage(can, &txHeader, data, &mailbox) == HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CANProtocol::receiveCO2(uint16_t &ppm) {
|
||||||
|
CAN_RxHeaderTypeDef rxHeader;
|
||||||
|
uint8_t rxData[8];
|
||||||
|
|
||||||
|
if (HAL_CAN_GetRxFifoFillLevel(can, CAN_RX_FIFO0) == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
HAL_CAN_GetRxMessage(can, CAN_RX_FIFO0, &rxHeader, rxData);
|
||||||
|
|
||||||
|
ppm = (rxData[0] << 8) | rxData[1];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
struct CO2Frame {
|
||||||
|
uint16_t ppm;
|
||||||
|
uint32_t timestamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CANProtocol {
|
||||||
|
public:
|
||||||
|
CANProtocol(CAN_HandleTypeDef* hcan);
|
||||||
|
|
||||||
|
bool sendCO2(uint16_t ppm);
|
||||||
|
bool receiveCO2(uint16_t &ppm);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CAN_HandleTypeDef* can;
|
||||||
|
|
||||||
|
CAN_TxHeaderTypeDef txHeader;
|
||||||
|
uint8_t data[8];
|
||||||
|
};
|
||||||
|
|||||||
4
STM32_CO2_NODE/FATFS/App/IPC/queues.cpp
Normal file
4
STM32_CO2_NODE/FATFS/App/IPC/queues.cpp
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include "queues.hpp"
|
||||||
|
|
||||||
|
QueueHandle_t g_sdQueue;
|
||||||
|
QueueHandle_t g_canQueue;
|
||||||
6
STM32_CO2_NODE/FATFS/App/IPC/queues.hpp
Normal file
6
STM32_CO2_NODE/FATFS/App/IPC/queues.hpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "queue.h"
|
||||||
|
|
||||||
|
extern QueueHandle_t g_sdQueue;
|
||||||
|
extern QueueHandle_t g_canQueue;
|
||||||
9
STM32_CO2_NODE/FATFS/App/Models/co2_data.hpp
Normal file
9
STM32_CO2_NODE/FATFS/App/Models/co2_data.hpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
struct CO2Data
|
||||||
|
{
|
||||||
|
uint32_t timestamp;
|
||||||
|
uint16_t ppm;
|
||||||
|
};
|
||||||
26
STM32_CO2_NODE/FATFS/App/Tasks/co2_task.cpp
Normal file
26
STM32_CO2_NODE/FATFS/App/Tasks/co2_task.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "co2_task.hpp"
|
||||||
|
#include "mhz19c.hpp"
|
||||||
|
#include "queues.hpp"
|
||||||
|
#include "co2_data.hpp"
|
||||||
|
|
||||||
|
extern MHZ19C sensor;
|
||||||
|
|
||||||
|
void CO2Task_Run() {
|
||||||
|
uint16_t ppm;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
sensor.requestCO2();
|
||||||
|
HAL_Delay(100);
|
||||||
|
|
||||||
|
if (sensor.readCO2(ppm)) {
|
||||||
|
CO2Data data;
|
||||||
|
data.ppm = ppm;
|
||||||
|
data.timestamp = HAL_GetTick();
|
||||||
|
|
||||||
|
xQueueSend(g_sdQueue, &data, 0);
|
||||||
|
xQueueSend(g_canQueue, &data, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
osDelay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
STM32_CO2_NODE/FATFS/App/Tasks/co2_task.hpp
Normal file
3
STM32_CO2_NODE/FATFS/App/Tasks/co2_task.hpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void CO2Task_RunOnce();
|
||||||
17
STM32_CO2_NODE/FATFS/App/Tasks/sd_task.cpp
Normal file
17
STM32_CO2_NODE/FATFS/App/Tasks/sd_task.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include "sd_task.hpp"
|
||||||
|
#include "sdcard.hpp"
|
||||||
|
#include "queues.hpp"
|
||||||
|
|
||||||
|
extern SDCardLogger sd;
|
||||||
|
|
||||||
|
void SDTask_Run() {
|
||||||
|
CO2Data data;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (xQueueReceive(g_sdQueue, &data, portMAX_DELAY)) {
|
||||||
|
char line[64];
|
||||||
|
sprintf(line, "CO2:%d t:%lu", data.ppm, data.timestamp);
|
||||||
|
sd.write(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
STM32_CO2_NODE/FATFS/App/Tasks/sd_task.hpp
Normal file
13
STM32_CO2_NODE/FATFS/App/Tasks/sd_task.hpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "fatfs.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class SDCardLogger {
|
||||||
|
public:
|
||||||
|
bool init();
|
||||||
|
bool write(const std::string &line);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FIL file;
|
||||||
|
FATFS fs;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user