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
- Committer:
- ninomedj
- Date:
- 2021-06-15
- Revision:
- 0:aa420961d99b
File content as of revision 0:aa420961d99b:
#include "mbed.h"
#include "CAN.h"
#include "can.h"
Ticker ticker;
Serial pc(USBTX, USBRX);
DigitalOut led2(LED2);
DigitalOut led1(LED1);
//CAN can1(p30, p29);
nodespresponse cc;
char data[8];
float result =0.0;
float result1 =0.0;
int main() {
pc.baud(115200);
can1.frequency(250000);
CANMessage msg;
//printf("received a CANbus message...\n"); // Write to serial terminal
while(1) {
if(can1.read(msg)) {
/*
if(msg.id==128){
if(msg.data[2]==0)
{
cc.ids();
}
}*/
// if message is available, read into msg
/* printf("CAN message received\r\n");
printf("Message read with ID: %d\n", msg.id);
printf("Data:\n");
printf("Byte 0: %x \n", msg.data[0]);
printf("Byte 1: %x \n", msg.data[1]);
printf("Byte 2: %x \n", msg.data[2]);
printf("Byte 3: %x \n", msg.data[3]);
printf("Byte 4: %x \n", msg.data[4]);
printf("Byte 5: %x \n", msg.data[5]);
printf("Byte 6: %x \n", msg.data[6]);
printf("Byte 7: %x \n", msg.data[7]);
printf(" Type = %d\r", msg.type);
printf(" Format = %d\r", msg.format);
printf(" Length = %d\r\n", msg.len);*/
char data1[4];
data1[0]=msg.data[4];
data1[1]=msg.data[5];
data1[2]=msg.data[6];
data1[3]=msg.data[7];
if(msg.id==312){
memcpy(&result,data1,4);
printf("air speed =%f\n", result);
/* printf("node_ID:%x\n",msg.data[0]);
printf("Data_type:%x\n",msg.data[1]);
printf("service code:%x\n",msg.data[2]);
printf("message code:%d\n",msg.data[3]);*/
led2 = !led2;
}else{
memcpy(&result1,data1,4);
printf("attitude ===%f\n",result1);
/*printf("node_ID:%x\n",msg.data[0]);
printf("Data_type:%x\n",msg.data[1]);
printf("service code:%x\n",msg.data[2]);
printf("message code:%d\n",msg.data[3]);*/
led1 = !led1;
}
// toggle receive status LED
}
}
}