本文整理匯總了C++中CAN_Transmit函數的典型用法代碼示例。如果您正苦於以下問題:C++ CAN_Transmit函數的具體用法?C++ CAN_Transmit怎麽用?C++ CAN_Transmit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CAN_Transmit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CAN_requestHandler
void CAN_requestHandler(void)
{
int count = 0;
int16_t norm;
//float F_T_units[6];
uint8_t forceIssue[6];
uint8_t torqueIssue[6];
if(cbIsFull(&cb)) GaugeVectorConversion(/*&F_T_units[0]*/);
/* Debug section BEGIN */
/*if(DEBUG_count < 250)
DEBUG_count++;
else
errFlag = 3;*/
/* Debug section END */
for(count = 0; count < 6; count += 2)
{
norm = (int16_t)(F_T_units[count / 2] / 10000);
forceIssue[count] = (uint8_t)(norm >> 8);
forceIssue[count + 1] = (uint8_t)(norm);
norm = (int16_t)(F_T_units[3 + count / 2] / 10000);
torqueIssue[count] = (uint8_t)(norm >> 8);
torqueIssue[count + 1] = (uint8_t)(norm);
}
CanTxMsgStructure.ExtId = (CanTxMsgStructure.ExtId & 0x1FFF80FF) | \
(CanRxMsgStructure.ExtId & 0x7F00);
switch (CanRxMsgStructure.ExtId & 0xFF)
{
case 1:
for(count = 0; count < 6; count++)
CanTxMsgStructure.Data[count] = forceIssue[count];
CAN_Transmit(CAN1, &CanTxMsgStructure);
break;
case 2:
for(count = 0; count < 6; count++)
CanTxMsgStructure.Data[count] = torqueIssue[count];
CAN_Transmit(CAN1, &CanTxMsgStructure);
break;
case 3:
for(count = 0; count < 6; count++)
CanTxMsgStructure.Data[count] = forceIssue[count];
CAN_Transmit(CAN1, &CanTxMsgStructure);
for(count = 0; count < 6; count++)
CanTxMsgStructure.Data[count] = torqueIssue[count];
CAN_Transmit(CAN1, &CanTxMsgStructure);
break;
default:
for(count = 0; count < 6; count++)
CanTxMsgStructure.Data[count] = 0;
CAN_Transmit(CAN1, &CanTxMsgStructure);
}
}
示例2: CanHexProg
/*******************************************************************************
* Function Name : CanHexProg request, server
* Description : dekodira in razbije vrstice hex fila na pakete 8 bytov in jih
* : pošlje na CAN bootloader
* Input : pointer na string, zaporedne vrstice hex fila, <cr> <lf> ali <null> niso nujni
* Output :
* Return : 0 ce je checksum error sicer eof(-1). bootloader asinhrono odgovarja z ACK message
* : za vsakih 8 bytov !!!
*******************************************************************************/
int CanHexProg(char *p) {
static int ExtAddr=0;
int n,a,i=FLASH_COMPLETE;
CanTxMsg TxMessage;
int *d=(int *)TxMessage.Data;
if(!p)
p=_Iap_string;
if(HexChecksumError(p))
return(0);
TxMessage.RTR=CAN_RTR_DATA;
TxMessage.IDE=CAN_ID_STD;
n=str2hex(&p,2);
a=(ExtAddr<<16)+str2hex(&p,4);
switch(str2hex(&p,2)) {
case 00:
TxMessage.StdId=_ID_IAP_ADDRESS;
d[0]=a;
TxMessage.DLC=sizeof(int);
if(p==_Iap_string)
PollCAN((CanRxMsg *)&TxMessage);
else
while(CAN_Transmit(CAN1,&TxMessage)==CAN_NO_MB);
TxMessage.StdId=_ID_IAP_DWORD;
for(i=0; n--;) {
TxMessage.Data[i++]=str2hex(&p,2);
if(i==8 || !n) {
TxMessage.DLC=i;
i=0;
if(p==_Iap_string)
PollCAN((CanRxMsg *)&TxMessage);
else
while(CAN_Transmit(CAN1,&TxMessage)==CAN_NO_MB);
}
}
break;
case 01:
break;
case 02:
break;
case 04:
case 05:
ExtAddr=str2hex(&p,4);
break;
}
return(EOF);
}
示例3: send_can_msg
/*! \fn static int32_t send_can_msg(void)
*
* \brief 發送CAN消息
*
* \param 無
*
* \exception 無
*
* \return EXIT_SUCCESS:成功; EXIT_FAILURE:失敗
*/
static int32_t send_can_msg(void)
{
int32_t lRet = EXIT_FAILURE;
do
{
if(s_unCanMsgTxWrIndex == s_unCanMsgTxRdIndex)
{
/*! 發送緩衝區無數據可發送 */
NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn);
lRet = EXIT_SUCCESS;
break;
}
/*! can發送消息 */
if(CAN_TxStatus_NoMailBox == CAN_Transmit(CAN1, &(s_astCanMsgTxBuf[s_unCanMsgTxRdIndex])))
{
//DEBUG_MSG("N: Can send mailbox full! %s %d\r\n", __FILE__, __LINE__);
}
else
{
/*! 發送成功,改變發送緩衝區的讀索引 */
s_unCanMsgTxRdIndex++;
if(CAN_MSG_BUF_SIZE <= s_unCanMsgTxRdIndex)
{
s_unCanMsgTxRdIndex = 0;
}
}
lRet = EXIT_SUCCESS;
}while(0);
return lRet;
}
示例4: CAN_transmitByte
/**
* @brief Transmit byte
* @param None
* @retval The number of unprocessed messages (uint8_t).
*/
extern void CAN_transmitByte(uint16_t StdId, uint8_t data){
/* Toggle status LED */
// GPIOC->ODR ^= GPIO_Pin_13; // Flip receive-LED. BRUKE DENNE??
/* Configure the message to be transmitted. */
TxMsg.StdId = StdId;
TxMsg.ExtId = 0x00;
TxMsg.RTR = CAN_RTR_DATA;
TxMsg.IDE = CAN_ID_STD;
TxMsg.DLC = 1;
TxMsg.Data[0] = data;
/* Put message in Tx Mailbox and store the mailbox number.
* Stall for a while (<1 second) if no mailbox is available.
*/
TransmitMailbox = CAN_TxStatus_NoMailBox;
volatile uint32_t watchdog = 200000;
while(1){
TransmitMailbox = CAN_Transmit(CAN1, &TxMsg);
if(TransmitMailbox != CAN_TxStatus_NoMailBox){
break;
} else if(watchdog--<10){
/* Return if no mailbox available within a few 100's of milliseconds. */
return;
}
}
}
示例5: comm_sendmsg
void comm_sendmsg(uint8_t id, uint8_t *data, uint8_t len) {
#if COMM_USE_CAN
if (len > 8) {
len = 8;
}
TxMessage.StdId = id;
TxMessage.DLC = len;
int i;
for (i = 0;i < len;i++) {
TxMessage.Data[i] = data[i];
}
CAN_Transmit(CAN1, &TxMessage);
#else
uint8_t buf[len + 1];
buf[0] = PACKET_INT_CMD_CLOCK;
int i = 0;
for (i = 0;i < len;i++) {
buf[i + 1] = data[i];
}
packet_send_packet(buf, len + 1, 0);
#endif
}
示例6: CanWriteData
/*******************************************************************************
* Function Name : CanWriteData
* Description : Can Write Date to CAN-BUS
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void CanWriteData(uint16_t ID)
{
CanTxMsg TxMessage;
CAN_DATA0=rand()%0xff;
CAN_DATA1=rand()%0xff;
CAN_DATA2=rand()%0xff;
CAN_DATA3=rand()%0xff;
CAN_DATA4=rand()%0xff;
CAN_DATA5=rand()%0xff;
CAN_DATA6=rand()%0xff;
CAN_DATA7=rand()%0xff;
/* transmit */
TxMessage.StdId = ID;
//TxMessage.ExtId = 0x00;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD;
TxMessage.DLC = 8;
TxMessage.Data[0] = CAN_DATA0;
TxMessage.Data[1] = CAN_DATA1;
TxMessage.Data[2] = CAN_DATA2;
TxMessage.Data[3] = CAN_DATA3;
TxMessage.Data[4] = CAN_DATA4;
TxMessage.Data[5] = CAN_DATA5;
TxMessage.Data[6] = CAN_DATA6;
TxMessage.Data[7] = CAN_DATA7;
CAN_Transmit(Open207Z_CANx,&TxMessage);
}
示例7: _CAN_SendMsg
void _CAN_SendMsg(uint8 *Buf,uint8 Length)
{
static uint8 TestValue;
u8 TransmitMailbox=0,i=0;
CanTxMsg TxMessage;
CanRxMsg RxMessage;
TxMessage.StdId=0x00;//接收板地址
TxMessage.RTR=CAN_RTR_DATA;//發送數據幀
TxMessage.IDE=CAN_ID_STD;
TxMessage.DLC=2;//發送數據的長度
TxMessage.Data[0]=TestValue;
TxMessage.Data[1]=0xFE;
TransmitMailbox=CAN_Transmit(CAN1,&TxMessage);
while((CAN_TransmitStatus(CAN1,TransmitMailbox)!=CANTXOK)&&(i!=0xff))
{
i++;
}
if(i==0xff)DeBug("Can Send TimeOut2",Infor_Infor);
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
if(RxMessage.Data[0]==TestValue%0xff)
{
DeBug("Can_PoolBack_Ok TestValue=%d",TestValue,Infor_Infor);
}
TestValue++;
}
示例8: PIOS_CAN_TxGeneric
/**
* @brief This function handles CAN1 TX irq and sends more data if available
*/
static void PIOS_CAN_TxGeneric(void)
{
CAN_ClearITPendingBit(can_dev->cfg->regs, CAN_IT_TME);
bool valid = PIOS_CAN_validate(can_dev);
PIOS_Assert(valid);
bool tx_need_yield = false;
if (can_dev->tx_out_cb) {
// Prepare CAN message structure
CanTxMsg msg;
msg.StdId = CAN_COM_ID;
msg.ExtId = 0;
msg.IDE = CAN_ID_STD;
msg.RTR = CAN_RTR_DATA;
msg.DLC = (can_dev->tx_out_cb)(can_dev->tx_out_context, msg.Data, MAX_SEND_LEN, NULL, &tx_need_yield);
// Send message and get mailbox number
if (msg.DLC > 0) {
CAN_Transmit(can_dev->cfg->regs, &msg);
} else {
CAN_ITConfig(can_dev->cfg->regs, CAN_IT_TME, DISABLE);
}
// TODO: deal with failure to send and keep the message to retransmit
}
#if defined(PIOS_INCLUDE_FREERTOS)
portEND_SWITCHING_ISR(tx_need_yield ? pdTRUE : pdFALSE);
#endif /* defined(PIOS_INCLUDE_FREERTOS) */
}
示例9: CAN1_Send
void CAN1_Send(uint32_t ID,u8 *Data)
{
u8 TransmitMailbox=0,i=0;
CanTxMsg TxMessage;
TxMessage.StdId = ID;
TxMessage.ExtId = 0x0000;
TxMessage.IDE = CAN_ID_STD;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.DLC = 8;
for(i=0;i<8;i++)
{
TxMessage.Data[i] = *Data++;
}
TransmitMailbox=CAN_Transmit(CAN1,&TxMessage);
while((CAN_TransmitStatus(CAN1,TransmitMailbox)!=CANTXOK)&&(i!=0xFF))
{
i++;
}
i=0;
while((CAN_MessagePending(CAN1,CAN_FIFO0)<1)&&(i!=0xFF))
{
i++;
}
}
示例10: while
/**
* \brief Transmits a test message just to see some
* bits on the bus lines.
*/
void CANTestcase::sendTestMessageInALoop()
{
while(true)
{
// Wait for ~10ms.
// TODO why has the loop variable to be marked as volatile? It's just a standard for-loop, the actual value
// of the variable should be evaluated without that.
for(volatile uint32_t a=0; a<60000;a++)
{
;
}
// Toggle the status LED.
this->toggleLED();
// Toggle CANTx to see if the pin'S state can be set. To do so, Configure pin as generel-purpose push pull in the setUp([...]) method.
//this->toggleCANTx();
// Variable to take the return value of the CAN_Transmit([...]) function.
uint8_t TransmitMailbox = 0;
// Define message.
CanTxMsg TxMessage;
TxMessage.StdId=0x11;
TxMessage.RTR=CAN_RTR_DATA;
TxMessage.IDE=CAN_ID_STD;
TxMessage.DLC=2;
TxMessage.Data[0]=0xCA;
TxMessage.Data[1]=0xFE;
// Send Message.
TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);
}
return;
}//eof
示例11: main
/*
* 函數名:main
* 描述 : "主機"的主函數
* 輸入 :無
* 輸出 : 無
*/
int main(void)
{
/*初始化串口模塊*/
USART1_Config();
/* 配置CAN模塊 */
CAN_Config();
printf( "\r\n***** 這是一個雙CAN通訊實驗******** \r\n");
printf( "\r\n 這是 “主機端” 的反饋信息: \r\n");
/*設置要通過CAN發送的信息*/
CAN_SetMsg();
printf("\r\n將要發送的報文內容為:\r\n");
printf("\r\n 擴展ID號ExtId:0x%x",TxMessage.ExtId);
printf("\r\n 數據段的內容:Data[0]=0x%x ,Data[1]=0x%x \r\n",TxMessage.Data[0],TxMessage.Data[1]);
/*發送消息 “ABCD”**/
CAN_Transmit(CAN1, &TxMessage);
while( flag == 0xff ); //flag =0 ,success
printf( "\r\n 成功接收到“從機”返回的數據\r\n ");
printf("\r\n 接收到的報文為:\r\n");
printf("\r\n 擴展ID號ExtId:0x%x",RxMessage.ExtId);
printf("\r\n 數據段的內容:Data[0]= 0x%x ,Data[1]=0x%x \r\n",RxMessage.Data[0],RxMessage.Data[1]);
while(1);
}
示例12: platform_can_send
int platform_can_send( unsigned id, u32 canid, u8 idtype, u8 len, const u8 *data )
{
CanTxMsg TxMessage;
const char *s = ( char * )data;
char *d;
switch( idtype )
{
case ELUA_CAN_ID_STD:
TxMessage.IDE = CAN_ID_STD;
TxMessage.StdId = canid;
break;
case ELUA_CAN_ID_EXT:
TxMessage.IDE = CAN_ID_EXT;
TxMessage.ExtId = canid;
break;
}
TxMessage.RTR=CAN_RTR_DATA;
TxMessage.DLC=len;
d = ( char * )TxMessage.Data;
DUFF_DEVICE_8( len, *d++ = *s++ );
if( CAN_Transmit( CAN1, &TxMessage ) == CAN_NO_MB )
return PLATFORM_ERR;
return PLATFORM_OK;
}
示例13: platform_can_send
void platform_can_send( unsigned id, u32 canid, u8 idtype, u8 len, const u8 *data )
{
CanTxMsg TxMessage;
const char *s = ( char * )data;
char *d;
switch( idtype )
{
case 0: /* Standard ID Type */
TxMessage.IDE = CAN_ID_STD;
TxMessage.StdId = canid;
break;
case 1: /* Extended ID Type */
TxMessage.IDE=CAN_ID_EXT;
TxMessage.ExtId = canid;
break;
}
TxMessage.RTR=CAN_RTR_DATA;
TxMessage.DLC=len;
d = ( char * )TxMessage.Data;
DUFF_DEVICE_8( len, *d++ = *s++ );
CAN_Transmit( CAN1, &TxMessage );
}
示例14: CAN_Transmit
//發送CAN1命令
uint8_t DST_CAN_1::Send_CAN1_CMD(int16_t current_201,int16_t current_202,int16_t current_203)
{
uint8_t mbox; //發送郵箱
uint16_t i= 0;
CanTxMsg tx_message; //CAN Tx message structure definition
tx_message.StdId = 0x200; //標準ID
tx_message.IDE = CAN_Id_Standard; //標準幀
tx_message.RTR = CAN_RTR_Data; //數據幀
tx_message.DLC = 0x08; //要發送的數據長度
/*********************數據*********************/
tx_message.Data[0] = (unsigned char)(current_201 >> 8);
tx_message.Data[1] = (unsigned char)current_201;
tx_message.Data[2] = (unsigned char)(current_202 >> 8);
tx_message.Data[3] = (unsigned char)current_202;
tx_message.Data[4] = (unsigned char)(current_203 >> 8);
tx_message.Data[5] = (unsigned char)current_203;
tx_message.Data[6] = 0x00;
tx_message.Data[7] = 0x00;
mbox = CAN_Transmit(CAN1,&tx_message);
while((CAN_TransmitStatus(CAN1, mbox)==CAN_TxStatus_Failed)&&(i<0XFFF))i++; //等待發送結束
if(i>=0XFFF)return _DEFEATED; //發送失敗
return _SUCCEED; //發送成功
}
示例15: Display_TransmittedMsg
/**
* @brief Display transmitted msg on the LCD
* @param None.
* @retval None
*/
static void Display_TransmittedMsg(uint8_t PushNumber)
{
uint8_t text[50] = {0}, dataindex =0;
uint8_t TxMessages[6] = { 0, 1, 2, 3, 4, 5 };
/* Set the LCD Back Color and Text Color*/
LCD_SetBackColor(Blue);
LCD_SetTextColor(White);
/* Set the LCD Text size */
LCD_SetFont(&Font12x12);
/* Display Messages on the the LCD */
LCD_DisplayStringLine(LINE(5), (uint8_t *)MESSAGE3);
for(dataindex = 0 ; dataindex < 6 ;dataindex++)
{
TxMessage.Data[0] = (uint8_t)(TxMessages[dataindex] + (6 * PushNumber));
CAN_Transmit(CANx, &TxMessage);
sprintf((char*)text,"Send Message Num%d = %d ",dataindex+1,TxMessage.Data[0] );
LCD_SetBackColor(Cyan);
LCD_SetTextColor(Black);
LCD_DisplayStringLine(LINE(6+dataindex),text);
}
}