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:
- mariob
- Date:
- 2015-08-02
- Revision:
- 0:8097eeede645
- Child:
- 1:8446a0d14877
File content as of revision 0:8097eeede645:
#include "mbed.h"
#include "net.hpp"
/*
Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(p9, p10);
CAN can2(p30, p29);
char counter = 0;
void send() {
printf("send()\r\n");
if(can1.write(CANMessage(1337, &counter, 1))) {
printf("wloop()\r\n");
counter++;
printf("Message sent: %d\r\n", counter);
}
led1 = !led1;
}
*/
Ticker ticker;
DigitalOut led_body(LED1);
DigitalOut led_engine(LED2);
DigitalOut led_time(LED3);
CAN can(p9, p10);
can_cmd_body_t can_cmd_body;
int counter = 0;
#define BODY_ 2
#define ENGINE_ 13
#define TIME_ 40
void send() {
printf("send()\r\n");
static int body_n_sent = 0;
counter++;
if ((counter%BODY_)==0) {
can_cmd_body.payload.msg.light_r = (body_n_sent&0x0001)==0x0001;
can_cmd_body.payload.msg.light_l = (body_n_sent&0x0002)==0x0002;
can_cmd_body.payload.msg.light_c = (body_n_sent&0x0004)==0x0004;
if(can.write(CANMessage(CAN_CMD_BODY_ID, (char*)(can_cmd_body.payload.buf), 4)))
printf("BODY OK\r\n");
else
printf("BODY NOT OK\r\n");
led_body = !led_body;
body_n_sent++;
}
}
int main() {
/*
printf("main()\r\n");
ticker.attach(&send, 1);
CANMessage msg;
while(1) {
printf("loop()\r\n");
if(can2.read(msg)) {
printf("Message received: %d\r\n", msg.data[0]);
led2 = !led2;
}
wait(0.2);
}
*/
printf("main()\r\n");
ticker.attach(&send, 1);
CANMessage msg;
while(1) {
if(can.read(msg)) {
can_sts_body_payload_t x;
x.buf[0] = msg.data[0]; x.buf[1] = msg.data[1]; x.buf[2] = msg.data[2]; x.buf[3] = msg.data[3];
x.buf[4] = msg.data[4]; x.buf[5] = msg.data[5]; x.buf[6] = msg.data[6]; x.buf[7] = msg.data[7];
printf("Message received: %d %d %d %d\r\n", x.buf[0], x.msg.eye_back_l, x.msg.eye_back_r, x.msg.eye_front);
}
wait(1.0);
}
}