You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

50 lines
1.2 KiB

#pragma once
#include "cmsis_os.h"
#include "stm32basic/stm32basic.hpp"
#include "stm32basic/zqueue.hpp"
namespace iflytop {
using namespace std;
typedef struct {
uint32_t extid;
uint8_t rxpacket[8];
int32_t rkpacketlen;
} zcanrx_t;
class ZCAN1 {
zmutex m_lock = {"ZCAN1"};
ZThread canListener;
ZQueue<zcanrx_t> rxQueue;
function<void(zcanrx_t *rx)> onZcanRx;
bool inited = false;
bool txNoError = false;
public:
ZCAN1() {}
static ZCAN1 *ins() {
static ZCAN1 instance;
return &instance;
}
void zcaninit();
bool txMsg(const uint32_t extid, const uint8_t txdata[], uint32_t txdatalen, int32_t overtime);
bool txMsgNoError(const uint32_t extid, const uint8_t txdata[], uint32_t txdatalen, int32_t overtime);
bool getRxMsg(zcanrx_t *rx);
void regOnCanMessage(function<void(zcanrx_t *rx)> onmessage);
public:
void STM32_HAL_onCAN_RxFifo0MsgPending(CAN_HandleTypeDef *can);
void STM32_HAL_onCAN_Error(CAN_HandleTypeDef *can);
private:
HAL_StatusTypeDef initializeFilter();
HAL_StatusTypeDef activateRxIT();
bool _txMsg(const uint32_t extid, const uint8_t txdata[], uint32_t txdatalen, int32_t overtime);
};
} // namespace iflytop