2008-12-03 05:40:16 +00:00
|
|
|
#include "can.h"
|
|
|
|
#include "lap.h"
|
|
|
|
#include "borg_can.h"
|
|
|
|
#include "spi.h"
|
2010-01-22 00:17:29 +00:00
|
|
|
#include "../borg_hw/borg_hw.h"
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
#include <setjmp.h>
|
2012-05-06 18:45:43 +00:00
|
|
|
|
|
|
|
#ifdef __AVR__
|
|
|
|
# include <avr/pgmspace.h>
|
|
|
|
# include <avr/interrupt.h>
|
|
|
|
# include <avr/eeprom.h>
|
|
|
|
#else
|
|
|
|
# include "../compat/eeprom.h"
|
|
|
|
#endif
|
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-05-06 18:45:43 +00:00
|
|
|
can_addr_t myaddr;
|
2008-12-03 05:40:16 +00:00
|
|
|
extern jmp_buf newmode_jmpbuf;
|
|
|
|
|
2011-10-28 18:53:38 +00:00
|
|
|
#ifdef LAP_TIME_EXTENSION
|
|
|
|
//variables to save the last received hours and minutes
|
|
|
|
//(accessible via lap.h)
|
|
|
|
uint8_t lap_time_h, lap_time_m, lap_time_update = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void bcan_init()
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
spi_init();
|
|
|
|
can_init();
|
|
|
|
|
|
|
|
myaddr = eeprom_read_byte(0x00);
|
|
|
|
pdo_message *msg = (pdo_message *)can_buffer_get();
|
|
|
|
msg->addr_src = myaddr;
|
|
|
|
msg->addr_dst = 0xff;
|
|
|
|
msg->port_src = PORT_BORG;
|
|
|
|
msg->port_dst = PORT_BORG;
|
|
|
|
msg->dlc = 4;
|
|
|
|
msg->cmd = FKT_BORG_INFO;
|
|
|
|
msg->data[0] = NUM_ROWS;
|
|
|
|
msg->data[1] = NUM_COLS;
|
2010-01-22 00:17:29 +00:00
|
|
|
msg->data[2] = NUMPLANE;
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
can_transmit((can_message *)msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void process_mgt_msg(pdo_message *msg)
|
|
|
|
{
|
|
|
|
pdo_message *rmsg;
|
|
|
|
|
|
|
|
switch(msg->cmd) {
|
|
|
|
case FKT_MGT_RESET:
|
2012-05-06 18:45:43 +00:00
|
|
|
#ifdef __AVR__
|
2008-12-03 05:40:16 +00:00
|
|
|
timer0_off();
|
|
|
|
cli();
|
|
|
|
while(1);
|
2012-05-06 18:45:43 +00:00
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
break;
|
|
|
|
case FKT_MGT_PING:
|
|
|
|
rmsg = (pdo_message *)can_buffer_get();
|
|
|
|
rmsg->addr_dst = msg->addr_src;
|
|
|
|
rmsg->addr_src = myaddr;
|
|
|
|
rmsg->port_dst = msg->port_src;
|
|
|
|
rmsg->port_src = msg->port_dst;
|
|
|
|
rmsg->cmd = FKT_MGT_PONG;
|
|
|
|
rmsg->dlc = 1;
|
|
|
|
can_transmit((can_message *)rmsg);
|
|
|
|
break;
|
2011-10-28 18:53:38 +00:00
|
|
|
|
|
|
|
#ifdef LAP_TIME_EXTENSION
|
|
|
|
//if we get a time reply, save it
|
|
|
|
case FKT_MGT_TIMEREPLY:
|
|
|
|
lap_time_h = msg->data[0];
|
|
|
|
lap_time_m = msg->data[1];
|
|
|
|
lap_time_update = 1;
|
|
|
|
break;
|
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void process_borg_msg(pdo_message *msg)
|
|
|
|
{
|
|
|
|
unsigned char i, j;
|
|
|
|
|
2012-05-06 18:45:43 +00:00
|
|
|
switch (msg->cmd) {
|
2008-12-03 05:40:16 +00:00
|
|
|
case FKT_BORG_MODE:
|
|
|
|
longjmp(newmode_jmpbuf, msg->data[0]);
|
|
|
|
break;
|
2012-05-06 18:45:43 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
case FKT_BORG_SCROLLTEXT_RESET:
|
2012-05-06 18:45:43 +00:00
|
|
|
for (i = 0; i < msg->dlc - 1; i++) {
|
2012-09-08 01:35:32 +00:00
|
|
|
scrolltext_text[i] = (char)msg->data[i];
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
scrolltext_text[i] = 0;
|
|
|
|
break;
|
2012-05-06 18:45:43 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
case FKT_BORG_SCROLLTEXT_APPEND:
|
2012-05-06 18:45:43 +00:00
|
|
|
j = 0;
|
|
|
|
while (scrolltext_text[j])
|
|
|
|
j++;
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2012-05-06 18:45:43 +00:00
|
|
|
for (i = 0; i < msg->dlc - 1; i++) {
|
2012-09-08 01:35:32 +00:00
|
|
|
scrolltext_text[i + j] = (char)msg->data[i];
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
2012-05-06 18:45:43 +00:00
|
|
|
scrolltext_text[i + j] = 0;
|
2008-12-03 05:40:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef Hansi_hat_gelernt_Werte_vorher_zu_definieren
|
|
|
|
|
|
|
|
//========== blinkenstuff
|
2011-10-28 18:53:38 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
//clear the blinkenbackbuffer to color
|
|
|
|
case FKT_BLINK_CLEARBUF:
|
|
|
|
blink_clearbuf(msg->data[0]);
|
|
|
|
break;
|
2011-10-28 18:53:38 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
//set auto position increment flag
|
|
|
|
case FKT_BLINK_SETAUTOPOS:
|
|
|
|
blink_setautopos(msg->data[0]);
|
|
|
|
break;
|
2011-10-28 18:53:38 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
//set the current blinkenbuffer offset position
|
|
|
|
case FKT_BLINK_SETPOS:
|
|
|
|
blink_setpos(msg->data[0]);
|
|
|
|
break;
|
2011-10-28 18:53:38 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
//puts the current blinkenbuffer to the frontbuffer
|
|
|
|
case FKT_BLINK_SHOW:
|
|
|
|
blink_show();
|
|
|
|
break;
|
2011-10-28 18:53:38 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
//puts data into the blinkenbuffer
|
|
|
|
case FKT_BLINK_DATA:
|
|
|
|
blink_data(msg->data, msg->dlc - 1);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 18:45:43 +00:00
|
|
|
void bcan_process_messages() {
|
2008-12-03 05:40:16 +00:00
|
|
|
pdo_message *msg = (pdo_message*) can_get_nb();
|
|
|
|
|
2012-05-06 18:45:43 +00:00
|
|
|
while (msg) {
|
2008-12-03 05:40:16 +00:00
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
|
2012-05-06 18:45:43 +00:00
|
|
|
if (msg->addr_dst == myaddr && msg->port_dst == PORT_MGT)
|
2008-12-03 05:40:16 +00:00
|
|
|
process_mgt_msg(msg);
|
|
|
|
|
2012-05-06 18:45:43 +00:00
|
|
|
if (msg->addr_dst == myaddr && msg->port_dst == PORT_BORG)
|
2008-12-03 05:40:16 +00:00
|
|
|
process_borg_msg(msg);
|
|
|
|
|
|
|
|
msg = (pdo_message*) can_get_nb();
|
2012-05-06 18:45:43 +00:00
|
|
|
}
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|