Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "CAN.h" 00003 #include "can.h" 00004 Ticker ticker; 00005 00006 Serial pc(USBTX, USBRX); 00007 00008 DigitalOut led2(LED2); 00009 DigitalOut led1(LED1); 00010 00011 //CAN can1(p30, p29); 00012 nodespresponse cc; 00013 00014 char data[8]; 00015 float result =0.0; 00016 float result1 =0.0; 00017 00018 int main() { 00019 pc.baud(115200); 00020 can1.frequency(250000); 00021 00022 CANMessage msg; 00023 00024 //printf("received a CANbus message...\n"); // Write to serial terminal 00025 while(1) { 00026 if(can1.read(msg)) { 00027 /* 00028 if(msg.id==128){ 00029 if(msg.data[2]==0) 00030 { 00031 cc.ids(); 00032 } 00033 }*/ 00034 // if message is available, read into msg 00035 /* printf("CAN message received\r\n"); 00036 printf("Message read with ID: %d\n", msg.id); 00037 printf("Data:\n"); 00038 printf("Byte 0: %x \n", msg.data[0]); 00039 printf("Byte 1: %x \n", msg.data[1]); 00040 printf("Byte 2: %x \n", msg.data[2]); 00041 printf("Byte 3: %x \n", msg.data[3]); 00042 printf("Byte 4: %x \n", msg.data[4]); 00043 printf("Byte 5: %x \n", msg.data[5]); 00044 printf("Byte 6: %x \n", msg.data[6]); 00045 printf("Byte 7: %x \n", msg.data[7]); 00046 printf(" Type = %d\r", msg.type); 00047 printf(" Format = %d\r", msg.format); 00048 printf(" Length = %d\r\n", msg.len);*/ 00049 char data1[4]; 00050 data1[0]=msg.data[4]; 00051 data1[1]=msg.data[5]; 00052 data1[2]=msg.data[6]; 00053 data1[3]=msg.data[7]; 00054 if(msg.id==312){ 00055 memcpy(&result,data1,4); 00056 printf("air speed =%f\n", result); 00057 /* printf("node_ID:%x\n",msg.data[0]); 00058 printf("Data_type:%x\n",msg.data[1]); 00059 printf("service code:%x\n",msg.data[2]); 00060 printf("message code:%d\n",msg.data[3]);*/ 00061 00062 led2 = !led2; 00063 }else{ 00064 memcpy(&result1,data1,4); 00065 printf("attitude ===%f\n",result1); 00066 /*printf("node_ID:%x\n",msg.data[0]); 00067 printf("Data_type:%x\n",msg.data[1]); 00068 printf("service code:%x\n",msg.data[2]); 00069 printf("message code:%d\n",msg.data[3]);*/ 00070 led1 = !led1; 00071 } 00072 00073 00074 // toggle receive status LED 00075 } 00076 } 00077 }
Generated on Sun Jul 24 2022 22:36:02 by
