|
|
@ -6,12 +6,12 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "hbw.h"
|
|
|
|
#include "hbw.h"
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t my_address[4];
|
|
|
|
uint32_t my_address;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t rind;
|
|
|
|
uint8_t rind;
|
|
|
|
uint16_t rcrc;
|
|
|
|
uint16_t rcrc;
|
|
|
|
uint8_t raddress[4];
|
|
|
|
uint32_t raddress;
|
|
|
|
uint8_t rdest[4];
|
|
|
|
uint32_t rdest;
|
|
|
|
uint8_t resc;
|
|
|
|
uint8_t resc;
|
|
|
|
uint8_t rctl;
|
|
|
|
uint8_t rctl;
|
|
|
|
volatile uint8_t rready;
|
|
|
|
volatile uint8_t rready;
|
|
|
@ -23,16 +23,23 @@ uint8_t sdisc;
|
|
|
|
uint8_t sctl;
|
|
|
|
uint8_t sctl;
|
|
|
|
uint16_t scrc;
|
|
|
|
uint16_t scrc;
|
|
|
|
uint8_t sesc;
|
|
|
|
uint8_t sesc;
|
|
|
|
uint8_t saddress[4];
|
|
|
|
uint32_t saddress;
|
|
|
|
uint8_t slen;
|
|
|
|
uint8_t slen;
|
|
|
|
uint8_t smessage[62];
|
|
|
|
uint8_t smessage[62];
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t sdelay;
|
|
|
|
uint16_t sdelay;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t asent;
|
|
|
|
|
|
|
|
uint8_t waitack;
|
|
|
|
uint8_t waitack;
|
|
|
|
|
|
|
|
uint32_t aaddress;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t asent;
|
|
|
|
uint8_t gotack;
|
|
|
|
uint8_t gotack;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t configled;
|
|
|
|
|
|
|
|
uint8_t configbutton;
|
|
|
|
|
|
|
|
uint8_t configstate;
|
|
|
|
|
|
|
|
uint16_t configtimer;
|
|
|
|
|
|
|
|
|
|
|
|
static uint16_t crc16shift(uint16_t crc, uint8_t data)
|
|
|
|
static uint16_t crc16shift(uint16_t crc, uint8_t data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int stat, i;
|
|
|
|
int stat, i;
|
|
|
@ -53,16 +60,14 @@ static uint16_t crc16shift(uint16_t crc, uint8_t data)
|
|
|
|
|
|
|
|
|
|
|
|
static void readaddr(void)
|
|
|
|
static void readaddr(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
my_address[0]=eeprom_read_byte((const uint8_t *)EESIZE-4);
|
|
|
|
// my_address=eeprom_read_dword((const uint32_t *)EESIZE-4);
|
|
|
|
my_address[1]=eeprom_read_byte((const uint8_t *)EESIZE-3);
|
|
|
|
((uint8_t*)&my_address)[0]=eeprom_read_byte((const uint8_t *)EESIZE-4);
|
|
|
|
my_address[2]=eeprom_read_byte((const uint8_t *)EESIZE-2);
|
|
|
|
((uint8_t*)&my_address)[1]=eeprom_read_byte((const uint8_t *)EESIZE-3);
|
|
|
|
my_address[3]=eeprom_read_byte((const uint8_t *)EESIZE-1);
|
|
|
|
((uint8_t*)&my_address)[2]=eeprom_read_byte((const uint8_t *)EESIZE-2);
|
|
|
|
|
|
|
|
((uint8_t*)&my_address)[3]=eeprom_read_byte((const uint8_t *)EESIZE-1);
|
|
|
|
|
|
|
|
|
|
|
|
if ((my_address[0] == 0xFF) &&
|
|
|
|
if (my_address == 0xFFFFFFFF)
|
|
|
|
(my_address[1] == 0xFF) &&
|
|
|
|
((uint8_t*)&my_address)[0] = 0x42;
|
|
|
|
(my_address[2] == 0xFF) &&
|
|
|
|
|
|
|
|
(my_address[3] == 0xFF))
|
|
|
|
|
|
|
|
my_address[0] = 0x42;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void send(uint8_t i,uint8_t crc)
|
|
|
|
static void send(uint8_t i,uint8_t crc)
|
|
|
@ -124,7 +129,7 @@ void rloop(void)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sind < 5) {
|
|
|
|
if (sind < 5) {
|
|
|
|
send(saddress[sind-1],1);
|
|
|
|
send(((uint8_t*)&saddress)[sind-1],1);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sind == 5) {
|
|
|
|
if (sind == 5) {
|
|
|
@ -132,7 +137,7 @@ void rloop(void)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sind < 10) {
|
|
|
|
if (sind < 10) {
|
|
|
|
send(my_address[sind-6],1);
|
|
|
|
send(((uint8_t*)&my_address)[sind-6],1);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sind == 10) {
|
|
|
|
if (sind == 10) {
|
|
|
@ -208,10 +213,7 @@ static void announce(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sctl = 0xF8;
|
|
|
|
sctl = 0xF8;
|
|
|
|
|
|
|
|
|
|
|
|
saddress[0] = 0xFF;
|
|
|
|
saddress = 0xFFFFFFFF;
|
|
|
|
saddress[1] = 0xFF;
|
|
|
|
|
|
|
|
saddress[2] = 0xFF;
|
|
|
|
|
|
|
|
saddress[3] = 0xFF;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
slen = 16;
|
|
|
|
slen = 16;
|
|
|
|
|
|
|
|
|
|
|
@ -244,6 +246,16 @@ void hbw_init(void)
|
|
|
|
PORTD &= ~(1<<SenderEnable);
|
|
|
|
PORTD &= ~(1<<SenderEnable);
|
|
|
|
PORTD &= ~(1<<ReceiverDisable);
|
|
|
|
PORTD &= ~(1<<ReceiverDisable);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ConfigButton
|
|
|
|
|
|
|
|
DDRD &= ~(1<<ConfigButton);
|
|
|
|
|
|
|
|
PORTD |= (1<<ConfigButton);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ConfigLED
|
|
|
|
|
|
|
|
DDRD |= (1<<ConfigLED);
|
|
|
|
|
|
|
|
PORTD &= ~(1<<ConfigLED);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
UBRR0L = ((F_CPU/(BAUDRATE*16))-1) & 0xFF;
|
|
|
|
UBRR0L = ((F_CPU/(BAUDRATE*16))-1) & 0xFF;
|
|
|
|
UBRR0H = 0;
|
|
|
|
UBRR0H = 0;
|
|
|
|
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 << RXCIE0);
|
|
|
|
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 << RXCIE0);
|
|
|
@ -260,9 +272,14 @@ void hbw_init(void)
|
|
|
|
rready = 0;
|
|
|
|
rready = 0;
|
|
|
|
asent = 0;
|
|
|
|
asent = 0;
|
|
|
|
hbw_timer = 0;
|
|
|
|
hbw_timer = 0;
|
|
|
|
|
|
|
|
gotack = 0;
|
|
|
|
|
|
|
|
waitack = 0;
|
|
|
|
|
|
|
|
configled = 0;
|
|
|
|
|
|
|
|
configbutton = 0;
|
|
|
|
|
|
|
|
configstate = 0;
|
|
|
|
|
|
|
|
|
|
|
|
readaddr();
|
|
|
|
readaddr();
|
|
|
|
srand(my_address[3]);
|
|
|
|
srand(my_address);
|
|
|
|
sdelay = 1000 + (rand() & 0x1F);
|
|
|
|
sdelay = 1000 + (rand() & 0x1F);
|
|
|
|
sei();
|
|
|
|
sei();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -272,30 +289,23 @@ static void process(void)
|
|
|
|
uint8_t seq,i;
|
|
|
|
uint8_t seq,i;
|
|
|
|
uint16_t addr;
|
|
|
|
uint16_t addr;
|
|
|
|
|
|
|
|
|
|
|
|
if ((rdest[0] == my_address[0]) &&
|
|
|
|
if ((rdest == my_address) &&
|
|
|
|
(rdest[1] == my_address[1]) &&
|
|
|
|
(raddress == aaddress) &&
|
|
|
|
(rdest[2] == my_address[2]) &&
|
|
|
|
waitack) {
|
|
|
|
(rdest[3] == my_address[3]) &&
|
|
|
|
|
|
|
|
((rctl & 0x13) == 0x11)) {
|
|
|
|
|
|
|
|
if (waitack) {
|
|
|
|
|
|
|
|
waitack = 0;
|
|
|
|
waitack = 0;
|
|
|
|
gotack = 1;
|
|
|
|
gotack = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
if ((rdest == my_address) &&
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rdest[0] == my_address[0]) &&
|
|
|
|
|
|
|
|
(rdest[1] == my_address[1]) &&
|
|
|
|
|
|
|
|
(rdest[2] == my_address[2]) &&
|
|
|
|
|
|
|
|
(rdest[3] == my_address[3]) &&
|
|
|
|
|
|
|
|
((rctl & 0x11) == 0x10)) {
|
|
|
|
((rctl & 0x11) == 0x10)) {
|
|
|
|
saddress[0] = raddress[0];
|
|
|
|
saddress = raddress;
|
|
|
|
saddress[1] = raddress[1];
|
|
|
|
|
|
|
|
saddress[2] = raddress[2];
|
|
|
|
|
|
|
|
saddress[3] = raddress[3];
|
|
|
|
|
|
|
|
seq = (rctl >> 1) & 3;
|
|
|
|
seq = (rctl >> 1) & 3;
|
|
|
|
|
|
|
|
if(!rlen)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
switch (rmessage[0]) {
|
|
|
|
switch (rmessage[0]) {
|
|
|
|
case '@':
|
|
|
|
case '@':
|
|
|
|
|
|
|
|
if (rlen != 6)
|
|
|
|
|
|
|
|
return;
|
|
|
|
if (rmessage[1] == 'a') {
|
|
|
|
if (rmessage[1] == 'a') {
|
|
|
|
eeprom_write_byte((uint8_t *)EESIZE-4, rmessage[2]);
|
|
|
|
eeprom_write_byte((uint8_t *)EESIZE-4, rmessage[2]);
|
|
|
|
eeprom_write_byte((uint8_t *)EESIZE-3, rmessage[3]);
|
|
|
|
eeprom_write_byte((uint8_t *)EESIZE-3, rmessage[3]);
|
|
|
@ -332,6 +342,8 @@ static void process(void)
|
|
|
|
sendmsg();
|
|
|
|
sendmsg();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
case 'v':
|
|
|
|
|
|
|
|
if (rlen != 2)
|
|
|
|
|
|
|
|
return;
|
|
|
|
smessage[0] = HBWMAJOR;
|
|
|
|
smessage[0] = HBWMAJOR;
|
|
|
|
smessage[1] = HBWMINOR;
|
|
|
|
smessage[1] = HBWMINOR;
|
|
|
|
slen = 2;
|
|
|
|
slen = 2;
|
|
|
@ -340,6 +352,10 @@ static void process(void)
|
|
|
|
sendmsg();
|
|
|
|
sendmsg();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
case 'R':
|
|
|
|
|
|
|
|
if (rlen != 4)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rmessage[3] > 62)
|
|
|
|
|
|
|
|
return;
|
|
|
|
addr = (rmessage[1] >> 8) | rmessage[2];
|
|
|
|
addr = (rmessage[1] >> 8) | rmessage[2];
|
|
|
|
for (i = 0; i < rmessage[3]; i++)
|
|
|
|
for (i = 0; i < rmessage[3]; i++)
|
|
|
|
smessage[i] = eeprom_read_byte((const uint8_t *)addr+i);
|
|
|
|
smessage[i] = eeprom_read_byte((const uint8_t *)addr+i);
|
|
|
@ -349,6 +365,10 @@ static void process(void)
|
|
|
|
sendmsg();
|
|
|
|
sendmsg();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
case 'W':
|
|
|
|
|
|
|
|
if (rlen <= 4)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rlen != rmessage[3] + 4)
|
|
|
|
|
|
|
|
return;
|
|
|
|
addr = (rmessage[1] >> 8) | rmessage[2];
|
|
|
|
addr = (rmessage[1] >> 8) | rmessage[2];
|
|
|
|
for (i = 0; i < rmessage[3]; i++)
|
|
|
|
for (i = 0; i < rmessage[3]; i++)
|
|
|
|
eeprom_write_byte((uint8_t *)addr+i, rmessage[4+i]);
|
|
|
|
eeprom_write_byte((uint8_t *)addr+i, rmessage[4+i]);
|
|
|
@ -358,8 +378,12 @@ static void process(void)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'x':
|
|
|
|
case 's':
|
|
|
|
case 's':
|
|
|
|
|
|
|
|
if (rlen <= 2)
|
|
|
|
|
|
|
|
return;
|
|
|
|
hbw_set_channel(rmessage[1], rlen - 2, &(rmessage[2]));
|
|
|
|
hbw_set_channel(rmessage[1], rlen - 2, &(rmessage[2]));
|
|
|
|
case 'S':
|
|
|
|
case 'S':
|
|
|
|
|
|
|
|
if (rlen < 2)
|
|
|
|
|
|
|
|
return;
|
|
|
|
smessage[0] = 'i';
|
|
|
|
smessage[0] = 'i';
|
|
|
|
smessage[1] = rmessage[1];
|
|
|
|
smessage[1] = rmessage[1];
|
|
|
|
slen = hbw_get_channel(rmessage[1], &(smessage[2])) + 2;
|
|
|
|
slen = hbw_get_channel(rmessage[1], &(smessage[2])) + 2;
|
|
|
@ -368,6 +392,7 @@ static void process(void)
|
|
|
|
sendmsg();
|
|
|
|
sendmsg();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
case 'C':
|
|
|
|
|
|
|
|
hbw_read_config();
|
|
|
|
slen = 0;
|
|
|
|
slen = 0;
|
|
|
|
sctl = 0x19 | (seq << 5);
|
|
|
|
sctl = 0x19 | (seq << 5);
|
|
|
|
sendmsg();
|
|
|
|
sendmsg();
|
|
|
@ -376,6 +401,14 @@ static void process(void)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void eeprom_clear(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint16_t i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i=0; i < EESIZE-4; i++)
|
|
|
|
|
|
|
|
eeprom_write_byte((uint8_t *)i, 0xFF);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void hbw_loop(void)
|
|
|
|
void hbw_loop(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rloop();
|
|
|
|
rloop();
|
|
|
@ -388,33 +421,111 @@ void hbw_loop(void)
|
|
|
|
announce();
|
|
|
|
announce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ConfigButton
|
|
|
|
|
|
|
|
switch (configstate) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
if (bit_is_clear(PIND, ConfigButton)) {
|
|
|
|
|
|
|
|
configtimer = hbw_timer;
|
|
|
|
|
|
|
|
configstate = 1;
|
|
|
|
|
|
|
|
configled = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
if (((hbw_timer - configtimer) > 20) &&
|
|
|
|
|
|
|
|
(bit_is_set(PIND, ConfigButton))) {
|
|
|
|
|
|
|
|
asent = 0;
|
|
|
|
|
|
|
|
configstate = 2;
|
|
|
|
|
|
|
|
configtimer = hbw_timer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hbw_timer - configtimer) > 8000) {
|
|
|
|
|
|
|
|
configstate = 3;
|
|
|
|
|
|
|
|
configtimer = hbw_timer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
if ((hbw_timer - configtimer) > 2000) {
|
|
|
|
|
|
|
|
configstate = 0;
|
|
|
|
|
|
|
|
configled = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
configled = ((hbw_timer % 400) > 200)?0:1;
|
|
|
|
|
|
|
|
if (bit_is_set(PIND, ConfigButton)) {
|
|
|
|
|
|
|
|
configstate = 4;
|
|
|
|
|
|
|
|
configtimer = hbw_timer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
configled = ((hbw_timer % 400) > 200)?0:1;
|
|
|
|
|
|
|
|
if (((hbw_timer - configtimer) > 2000) &&
|
|
|
|
|
|
|
|
(bit_is_set(PIND, ConfigButton))) {
|
|
|
|
|
|
|
|
configstate = 0;
|
|
|
|
|
|
|
|
configled = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((hbw_timer - configtimer) > 20) &&
|
|
|
|
|
|
|
|
(bit_is_clear(PIND, ConfigButton))) {
|
|
|
|
|
|
|
|
configstate = 5;
|
|
|
|
|
|
|
|
configled = 0;
|
|
|
|
|
|
|
|
eeprom_clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
if (((hbw_timer - configtimer) > 20) &&
|
|
|
|
|
|
|
|
(bit_is_set(PIND, ConfigButton))) {
|
|
|
|
|
|
|
|
configstate = 0;
|
|
|
|
|
|
|
|
configled = 0;
|
|
|
|
|
|
|
|
asent = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ConfigLED
|
|
|
|
|
|
|
|
if (configled)
|
|
|
|
|
|
|
|
PORTD |= (1<<ConfigLED);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
PORTD &= ~(1<<ConfigLED);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t hbw_send_channel(uint8_t channel, uint8_t length, uint8_t const * const data, uint32_t target_address)
|
|
|
|
uint8_t hbw_send_channel(uint8_t channel, uint8_t length, uint8_t const * const data, uint32_t target_address)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (gotack) {
|
|
|
|
if (gotack) {
|
|
|
|
gotack = 0;
|
|
|
|
gotack = 0;
|
|
|
|
|
|
|
|
waitack = 0;
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!is_bus_free())
|
|
|
|
if (!is_bus_free())
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (waitack)
|
|
|
|
if(waitack > 2) {
|
|
|
|
return 0;
|
|
|
|
waitack = 0;
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
slen = length + 2;
|
|
|
|
slen = length + 2;
|
|
|
|
sctl = 0xF8;
|
|
|
|
sctl = 0xF8;
|
|
|
|
saddress[0] = eeprom_read_byte((const uint8_t *)2);
|
|
|
|
aaddress = target_address;
|
|
|
|
saddress[1] = eeprom_read_byte((const uint8_t *)3);
|
|
|
|
if(aaddress == 0) {
|
|
|
|
saddress[2] = eeprom_read_byte((const uint8_t *)4);
|
|
|
|
((uint8_t*)&aaddress)[0]=eeprom_read_byte((const uint8_t *)2);
|
|
|
|
saddress[3] = eeprom_read_byte((const uint8_t *)5);
|
|
|
|
((uint8_t*)&aaddress)[1]=eeprom_read_byte((const uint8_t *)3);
|
|
|
|
|
|
|
|
((uint8_t*)&aaddress)[2]=eeprom_read_byte((const uint8_t *)4);
|
|
|
|
|
|
|
|
((uint8_t*)&aaddress)[3]=eeprom_read_byte((const uint8_t *)5);
|
|
|
|
|
|
|
|
// aaddress = eeprom_read_dword((const uint32_t *)2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saddress = aaddress;
|
|
|
|
smessage[0] = 'i';
|
|
|
|
smessage[0] = 'i';
|
|
|
|
smessage[1] = channel;
|
|
|
|
smessage[1] = channel;
|
|
|
|
memcpy(&(smessage[2]), data, length);
|
|
|
|
memcpy(&(smessage[2]), data, length);
|
|
|
|
sendmsg();
|
|
|
|
sendmsg();
|
|
|
|
waitack = 1;
|
|
|
|
if (aaddress == 0xFFFFFFFF)
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
waitack++;
|
|
|
|
gotack = 0;
|
|
|
|
gotack = 0;
|
|
|
|
|
|
|
|
sdelay = hbw_timer + 100 + (rand() & 0x1F);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -449,7 +560,7 @@ ISR(USART_RX_vect)
|
|
|
|
if ((rind == 1) || (rind == 255))
|
|
|
|
if ((rind == 1) || (rind == 255))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
if (rind < 6) {
|
|
|
|
if (rind < 6) {
|
|
|
|
rdest[rind-2] = c;
|
|
|
|
((uint8_t*)&rdest)[rind-2] = c;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rind == 6) {
|
|
|
|
if (rind == 6) {
|
|
|
@ -457,7 +568,7 @@ ISR(USART_RX_vect)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rind < 11) {
|
|
|
|
if (rind < 11) {
|
|
|
|
raddress[rind-7] = c;
|
|
|
|
((uint8_t*)&raddress)[rind-7] = c;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rind == 11) {
|
|
|
|
if (rind == 11) {
|
|
|
@ -479,6 +590,7 @@ ISR(USART_RX_vect)
|
|
|
|
if (rcrc)
|
|
|
|
if (rcrc)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
rready = 1;
|
|
|
|
rready = 1;
|
|
|
|
|
|
|
|
rlen = rlen - 2;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|