添加文件1和文件2
This commit is contained in:
144
PTZ/Core/Src/CToC.c
Normal file
144
PTZ/Core/Src/CToC.c
Normal file
@@ -0,0 +1,144 @@
|
||||
#include "main.h"
|
||||
#include "CToC.h"
|
||||
#include "can.h"
|
||||
#include "dma.h"
|
||||
#include "gpio.h"
|
||||
#include "Remote.h"
|
||||
#include "RefereeSystem.h"
|
||||
#include "Parameter.h"
|
||||
|
||||
|
||||
static CAN_TxHeaderTypeDef TxMessage;
|
||||
static uint8_t TxMessage_Data[8];
|
||||
uint8_t CToC_MasterSendData(void)
|
||||
{
|
||||
|
||||
uint32_t send_mail_box;
|
||||
TxMessage.StdId=CToC_SlaveID1;
|
||||
TxMessage.IDE = CAN_ID_STD;
|
||||
TxMessage.RTR = CAN_RTR_DATA;
|
||||
TxMessage.DLC=0x08;
|
||||
if((PC_Go==0 && PC_Back==0 && PC_Left==0 && PC_Right==0 && PC_Spin==0 && PC_Pitch==0) && RefereeSystem_Status==0)//?????
|
||||
{
|
||||
TxMessage_Data[0]=(uint8_t)((uint16_t)Remote_RxData.Remote_R_RL>>8);//????????
|
||||
TxMessage_Data[1]=(uint8_t)((uint16_t)Remote_RxData.Remote_R_RL & 0x00FF);//????????
|
||||
TxMessage_Data[2]=(uint8_t)((uint16_t)Remote_RxData.Remote_R_UD>>8);//????????
|
||||
TxMessage_Data[3]=(uint8_t)((uint16_t)Remote_RxData.Remote_R_UD & 0x00FF);//????????
|
||||
TxMessage_Data[4]=(uint8_t)(Remote_RxData.Remote_L_RL>>8);//????????
|
||||
TxMessage_Data[5]=(uint8_t)(Remote_RxData.Remote_L_RL & 0x00FF);//????????
|
||||
TxMessage_Data[6]=(uint8_t)(Remote_RxData.Remote_L_UD>>8);//????????
|
||||
TxMessage_Data[7]=(uint8_t)(Remote_RxData.Remote_L_UD & 0x00FF);//????????
|
||||
}
|
||||
else//????
|
||||
{
|
||||
TxMessage_Data[0]=(uint8_t)((1024+(PC_Right-PC_Left)*660)>>8);//??AD,????????(???)
|
||||
TxMessage_Data[1]=(uint8_t)((1024+(PC_Right-PC_Left)*660) & 0x00FF);//??AD,????????(???)
|
||||
TxMessage_Data[2]=(uint8_t)((1024+(PC_Go-PC_Back)*660)>>8);//??WS,????????(???)
|
||||
TxMessage_Data[3]=(uint8_t)((1024+(PC_Go-PC_Back)*660) & 0x00FF);//??WS,????????(???)
|
||||
TxMessage_Data[4]=(uint8_t)((uint16_t)(1024+PC_Spin*PC_Mouse_RLSensitivity)>>8);//????,????????(???)
|
||||
TxMessage_Data[5]=(uint8_t)((uint16_t)(1024+PC_Spin*PC_Mouse_RLSensitivity) & 0x00FF);//????,????????(???)
|
||||
TxMessage_Data[6]=(uint8_t)((uint16_t)(1024+PC_Pitch*PC_Mouse_DUSensitivity)>>8);//????,????????(???)
|
||||
TxMessage_Data[7]=(uint8_t)((uint16_t)(1024+PC_Pitch*PC_Mouse_DUSensitivity) & 0x00FF);//????,????????(???)
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(&hcan2, &TxMessage,TxMessage_Data, &send_mail_box);
|
||||
if (status != HAL_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t i = 0;
|
||||
while ((HAL_CAN_IsTxMessagePending(&hcan2, send_mail_box)) && (i < 0xFFF)) {
|
||||
i++;
|
||||
}
|
||||
if (i >= 0xFFF) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//can 2 rx
|
||||
void can_filter_init(void)
|
||||
{
|
||||
CAN_FilterTypeDef can_filter_st;
|
||||
can_filter_st.FilterActivation = ENABLE;
|
||||
can_filter_st.FilterMode = CAN_FILTERMODE_IDMASK;
|
||||
can_filter_st.FilterScale = CAN_FILTERSCALE_32BIT;
|
||||
can_filter_st.FilterIdHigh = (CToC_MasterID1<<5);
|
||||
can_filter_st.FilterIdLow =(CToC_MasterID1<<5);
|
||||
can_filter_st.FilterMaskIdHigh = 0xFFE3;
|
||||
can_filter_st.FilterMaskIdLow = 0xFFE3;
|
||||
can_filter_st.FilterBank = 0;
|
||||
can_filter_st.FilterFIFOAssignment = CAN_RX_FIFO0;
|
||||
|
||||
can_filter_st.SlaveStartFilterBank = 14;
|
||||
can_filter_st.FilterBank = 14;
|
||||
HAL_CAN_ConfigFilter(&hcan2, &can_filter_st);
|
||||
HAL_CAN_Start(&hcan2);
|
||||
HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static CAN_TxHeaderTypeDef TxMessage1;
|
||||
static uint8_t TxMessage_Data1[8];
|
||||
uint8_t CToC_MasterSendControl(void)
|
||||
{
|
||||
|
||||
uint32_t send_mail_box;
|
||||
TxMessage1.StdId=CToC_SlaveID2;
|
||||
TxMessage1.IDE = CAN_ID_STD;
|
||||
TxMessage1.RTR = CAN_RTR_DATA;
|
||||
TxMessage1.DLC=0x08;
|
||||
TxMessage_Data1[0]=Remote_Status;
|
||||
TxMessage_Data1[1]=Remote_RxData.Remote_RS;
|
||||
TxMessage_Data1[2]=Remote_RxData.Remote_KeyPush_Ctrl;
|
||||
TxMessage_Data1[3]=Remote_RxData.Remote_KeyPush_Shift;
|
||||
TxMessage_Data1[4]=Remote_StartFlag;
|
||||
TxMessage_Data1[5]=Remote_RxData.Remote_LS;
|
||||
TxMessage_Data1[6]=Remote_RxData.Remote_Key_Alpha1;
|
||||
TxMessage_Data1[7]=Remote_RxData.Remote_Key_Alpha2;
|
||||
|
||||
HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(&hcan2, &TxMessage1,TxMessage_Data1, &send_mail_box);
|
||||
if (status != HAL_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t i = 0;
|
||||
while ((HAL_CAN_IsTxMessagePending(&hcan2, send_mail_box)) && (i < 0xFFF)) {
|
||||
i++;
|
||||
}
|
||||
if (i >= 0xFFF) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void CToC_CANDataProcess(uint32_t ID,uint8_t *Data)
|
||||
{
|
||||
static uint8_t Last_ShooterStatus=0;
|
||||
if(ID==CToC_MasterID1)
|
||||
{
|
||||
Last_ShooterStatus=RefereeSystem_ShooterStatus;
|
||||
RefereeSystem_ShooterStatus=Data[0];
|
||||
if(Last_ShooterStatus==0 && RefereeSystem_ShooterStatus==1)RefereeSystem_ShooterOpenFlag=1;
|
||||
}
|
||||
}
|
||||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
{
|
||||
CAN_RxHeaderTypeDef rx_header;
|
||||
uint8_t rx_data[8];
|
||||
|
||||
|
||||
HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, rx_data);
|
||||
if (hcan->Instance == CAN2) {
|
||||
|
||||
CToC_CANDataProcess(rx_header.StdId, rx_data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user