公司代码
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.
 
 
 

109 lines
3.3 KiB

/*
* msp_DAM_Relay.c
*
* Created on: Nov 5, 2024
* Author: akeguo
*/
#include "msp_DAM_Relay.h"
#include "BHBF_ROBOT.h"
#include "bsp_MB_host.h"
//not modbus writcoil
uint8_t Dan1_open[8] = { 0xFE, 0x05, 0x00, 0x00, 0xFF, 0x00, 0x98, 0x35 };
uint8_t Dan1_close[8] = { 0xFE, 0x05, 0x00, 0x00, 0x00, 0x00, 0xD9, 0xC5 };
uint8_t Dan2_open[8] = { 0xFE, 0x05, 0x00, 0x01, 0xFF, 0x00, 0xC9, 0xF5 };
uint8_t Dan2_close[8] = { 0xFE, 0x05, 0x00, 0x01, 0x00, 0x00, 0x88, 0x05 };
uint8_t Dan3_open[8] = { 0xFE, 0x05, 0x00, 0x02, 0xFF, 0x00, 0x39, 0xF5 };
uint8_t Dan3_close[8] = { 0xFE, 0x05, 0x00, 0x02, 0x00, 0x00, 0x78, 0x05 };
uint8_t Dan4_open[8] = { 0xFE, 0x05, 0x00, 0x03, 0xFF, 0x00, 0x68, 0x35 };
uint8_t Dan4_close[8] = { 0xFE, 0x05, 0x00, 0x03, 0x00, 0x00, 0x29, 0xC5 };
int32_t *DMA_DO_Value_[4];//DAM模块
void decode_DAM(uint8_t *buffer, uint16_t length);
void DAM_0_Set();
void DAM_1_Set();
void DAM_2_Set();
void DAM_3_Set();
struct UARTHandler *DAM_Relay;
DispacherController *DAM_Relay_dispacherController;
void DAM_Relay_intialize(struct UARTHandler *Handler) {
//uartHandler_intialize(&Force_sensor,Handler,10);
DAM_Relay = Handler;
DAM_Relay->UART_Decode = decode_DAM;
DAM_Relay->Wait_time = 6; //等待10ms 最低不要低于4;
DAM_Relay_dispacherController = Handler->dispacherController;
DAM_Relay_dispacherController->DispacherCallTime = 200; //10 是100ms 难道这个2ms的定时器是10ms的?
LOG("DAM intialize");
//log_info("angle_encoder_intialize");
DAM_Relay_dispacherController->Add_Dispatcher_List(
DAM_Relay_dispacherController, DAM_0_Set);
DAM_Relay_dispacherController->Add_Dispatcher_List(
DAM_Relay_dispacherController, DAM_1_Set);
DAM_Relay_dispacherController->Add_Dispatcher_List(
DAM_Relay_dispacherController, DAM_2_Set);
DAM_Relay_dispacherController->Add_Dispatcher_List(
DAM_Relay_dispacherController, DAM_3_Set);
HardWareErrorController->Add_PCOMHardWare(HardWareErrorController, "DAM", 0,
DAM_Relay_ErrorBitFlag);
}
void DAM_0_Set() {
if (*DMA_DO_Value_[0] == 1) {
memcpy(&DAM_Relay->Tx_Buf, &Dan1_open, 8);
} else {
memcpy(&DAM_Relay->Tx_Buf, &Dan1_close, 8);
}
DAM_Relay->TxCount = 8;
DAM_Relay->UART_Tx(DAM_Relay); //send the data from the modbus command;
}
void DAM_1_Set() {
if (*DMA_DO_Value_[1] == 1) {
memcpy(&DAM_Relay->Tx_Buf, &Dan2_open, 8);
} else {
memcpy(&DAM_Relay->Tx_Buf, &Dan2_close, 8);
}
DAM_Relay->TxCount = 8;
DAM_Relay->UART_Tx(DAM_Relay); //send the data from the modbus command;
}
void DAM_2_Set() {
if (*DMA_DO_Value_[2] == 1) {
memcpy(&DAM_Relay->Tx_Buf, &Dan3_open, 8);
} else {
memcpy(&DAM_Relay->Tx_Buf, &Dan3_close, 8);
}
DAM_Relay->TxCount = 8;
DAM_Relay->UART_Tx(DAM_Relay); //send the data from the modbus command;
}
void DAM_3_Set() {
if (*DMA_DO_Value_[3] == 1) {
memcpy(&DAM_Relay->Tx_Buf, &Dan4_open, 8);
} else {
memcpy(&DAM_Relay->Tx_Buf, &Dan4_close, 8);
}
DAM_Relay->TxCount = 8;
DAM_Relay->UART_Tx(DAM_Relay); //send the data from the modbus command;
}
void decode_DAM(uint8_t *buffer, uint16_t length) {
/* CRC 校验 */
uint16_t crc_check = ((buffer[length - 1] << 8) | buffer[length - 2]);
/* CRC 校验正确 */
if (crc_check == MB_CRC16(buffer, length - 2)) {
HardWareErrorController->Set_PCOMHardWare(HardWareErrorController,
"DAM", 1);
} else {
}
}