try resend on errors
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
#include <mcp2515.h>;
|
#include <mcp2515.h>;
|
||||||
|
|
||||||
const byte SoftwareVersionHigh = 3;
|
const byte SoftwareVersionHigh = 3;
|
||||||
const byte SoftwareVersionLow = 0;
|
const byte SoftwareVersionLow = 1;
|
||||||
const byte HardwareVersionHigh = 6;
|
const byte HardwareVersionHigh = 6;
|
||||||
const byte HardwareVersionLow = 0;
|
const byte HardwareVersionLow = 0;
|
||||||
const uint32_t HELP_PACKAGE_CAN_ID = 0xFFFF;
|
const uint32_t HELP_PACKAGE_CAN_ID = 0xFFFF;
|
||||||
@@ -93,7 +93,7 @@ struct RemotePinInfo
|
|||||||
int16_t Count()
|
int16_t Count()
|
||||||
{
|
{
|
||||||
if (this->next == NULL) return 1;
|
if (this->next == NULL) return 1;
|
||||||
return this->next->Count() + 1;
|
return this->next->Count() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemotePinInfo* FindOrAdd(uint16_t deviceId, byte count = 0)
|
RemotePinInfo* FindOrAdd(uint16_t deviceId, byte count = 0)
|
||||||
@@ -146,9 +146,9 @@ MCP2515 mcp2515_3(PIN_PB1);
|
|||||||
void setup() {
|
void setup() {
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Rules[0] = Rule();
|
Rules[0] = Rule();
|
||||||
Rules[0].InitToggleInverse(0x051F, 5, 0x3D2D, 4); // Lichtschalter Wohnzimmer Licht 1
|
Rules[0].InitToggleInverse(0x051F, 5, 0x3D2D, 4); // Lichtschalter Wohnzimmer Licht 1
|
||||||
Rules[1] = Rule();
|
Rules[1] = Rule();
|
||||||
Rules[1].InitToggleInverse(0x051F, 5, 0x3D2D, 3); // Lichtschalter Wohnzimmer Licht 2
|
Rules[1].InitToggleInverse(0x051F, 5, 0x3D2D, 3); // Lichtschalter Wohnzimmer Licht 2
|
||||||
@@ -162,36 +162,36 @@ Rules[0] = Rule();
|
|||||||
Rules[4].InitToggle(0x0769, 1, 0x3D2D, 6); // Eingangstür Flur Licht 2
|
Rules[4].InitToggle(0x0769, 1, 0x3D2D, 6); // Eingangstür Flur Licht 2
|
||||||
Rules[5] = Rule();
|
Rules[5] = Rule();
|
||||||
Rules[5].InitToggle(0x0769, 1, 0x9829, 1); //Eingangstür Flur Licht 1
|
Rules[5].InitToggle(0x0769, 1, 0x9829, 1); //Eingangstür Flur Licht 1
|
||||||
|
|
||||||
Rules[6] = Rule();
|
Rules[6] = Rule();
|
||||||
Rules[6].InitSimple(0x051F, 3,0x3D2D, 1); // Licht 1 Wochzimmer Eingangstür
|
Rules[6].InitSimple(0x051F, 3, 0x3D2D, 1); // Licht 1 Wochzimmer Eingangstür
|
||||||
Rules[7] = Rule();
|
Rules[7] = Rule();
|
||||||
Rules[7].InitSimple(0x051F, 4,0x3D2D, 2); // Licht 2 Wochzimmer Eingangstür
|
Rules[7].InitSimple(0x051F, 4, 0x3D2D, 2); // Licht 2 Wochzimmer Eingangstür
|
||||||
|
|
||||||
Rules[8] = Rule();
|
Rules[8] = Rule();
|
||||||
Rules[8].InitToggle(0x1177, 1, 0x3D2D, 7); // Licht Papa Büro
|
Rules[8].InitToggle(0x1177, 1, 0x3D2D, 7); // Licht Papa Büro
|
||||||
|
|
||||||
Rules[9] = Rule();
|
Rules[9] = Rule();
|
||||||
Rules[9].InitToggle(0x05A1, 1,0x3D2D, 6); // Flurlicht von Papas Büro
|
Rules[9].InitToggle(0x05A1, 1, 0x3D2D, 6); // Flurlicht von Papas Büro
|
||||||
|
|
||||||
Rules[10] = Rule();
|
Rules[10] = Rule();
|
||||||
Rules[10].InitToggle(0x05A1, 1,0x9829, 1); // Flurlicht von Papas Büro
|
Rules[10].InitToggle(0x05A1, 1, 0x9829, 1); // Flurlicht von Papas Büro
|
||||||
|
|
||||||
Rules[11] = Rule();
|
Rules[11] = Rule();
|
||||||
Rules[11].InitToggle(0x01EF, 1,0x3D2D, 6); // Flurlicht von Papas Büro
|
Rules[11].InitToggle(0x01EF, 1, 0x3D2D, 6); // Flurlicht von Papas Büro
|
||||||
Rules[12] = Rule();
|
Rules[12] = Rule();
|
||||||
Rules[12].InitToggle(0x01EF, 1,0x9829, 1); // Flurlicht von Papas Büro#
|
Rules[12].InitToggle(0x01EF, 1, 0x9829, 1); // Flurlicht von Papas Büro#
|
||||||
|
|
||||||
Rules[13] = Rule();
|
Rules[13] = Rule();
|
||||||
Rules[13].InitToggle(0x0196, 3,0x3D2D, 6); // Flurlicht von Papas Büro
|
Rules[13].InitToggle(0x0196, 3, 0x3D2D, 6); // Flurlicht von Papas Büro
|
||||||
|
|
||||||
Rules[14] = Rule();
|
Rules[14] = Rule();
|
||||||
Rules[14].InitToggle(0x0196, 3,0x9829, 1); // Flurlicht von Papas Büro
|
Rules[14].InitToggle(0x0196, 3, 0x9829, 1); // Flurlicht von Papas Büro
|
||||||
|
|
||||||
Rules[15] = Rule();
|
Rules[15] = Rule();
|
||||||
Rules[15].InitToggle(0x0632, 1, 0x9829, 5); // Flurlicht von Papas Büro
|
Rules[15].InitToggle(0x0632, 1, 0x9829, 5); // Flurlicht von Papas Büro
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
MeyPins[0] = PinState();
|
MeyPins[0] = PinState();
|
||||||
MeyPins[0].Init(PIN_PC7, (byte) 1);
|
MeyPins[0].Init(PIN_PC7, (byte) 1);
|
||||||
|
|
||||||
@@ -254,51 +254,52 @@ delay(10);
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool debugState = false;
|
bool debugState = false;
|
||||||
void ToggleDebug()
|
void ToggleDebug()
|
||||||
{
|
{
|
||||||
debugState = debugState^true;
|
debugState = debugState ^ true;
|
||||||
if (debugState)
|
if (debugState)
|
||||||
digitalWrite(PIN_PC1, HIGH);
|
digitalWrite(PIN_PC1, HIGH);
|
||||||
else
|
else
|
||||||
digitalWrite(PIN_PC1, LOW);
|
digitalWrite(PIN_PC1, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (mcp2515_0.readMessage(&_frame) == MCP2515::ERROR_OK)
|
if (mcp2515_0.readMessage(&_frame) == MCP2515::ERROR_OK)
|
||||||
{
|
{
|
||||||
mcp2515_1.sendMessage(MCP2515::TXB1, &_frame);
|
|
||||||
mcp2515_2.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_1, &_frame);
|
||||||
mcp2515_3.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_2, &_frame);
|
||||||
|
DoSendCanPkg(&mcp2515_3, &_frame);
|
||||||
HandleFrame(&_frame);
|
HandleFrame(&_frame);
|
||||||
}
|
}
|
||||||
if (mcp2515_1.readMessage(&_frame) == MCP2515::ERROR_OK)
|
if (mcp2515_1.readMessage(&_frame) == MCP2515::ERROR_OK)
|
||||||
{
|
{
|
||||||
mcp2515_0.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_0, &_frame);
|
||||||
mcp2515_2.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_2, &_frame);
|
||||||
mcp2515_3.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_3, &_frame);
|
||||||
HandleFrame(&_frame);
|
HandleFrame(&_frame);
|
||||||
}
|
}
|
||||||
if (mcp2515_2.readMessage(&_frame) == MCP2515::ERROR_OK)
|
if (mcp2515_2.readMessage(&_frame) == MCP2515::ERROR_OK)
|
||||||
{
|
{
|
||||||
mcp2515_0.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_0, &_frame);
|
||||||
mcp2515_1.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_1, &_frame);
|
||||||
mcp2515_3.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_3, &_frame);
|
||||||
HandleFrame(&_frame);
|
HandleFrame(&_frame);
|
||||||
}
|
}
|
||||||
if (mcp2515_3.readMessage(&_frame) == MCP2515::ERROR_OK)
|
if (mcp2515_3.readMessage(&_frame) == MCP2515::ERROR_OK)
|
||||||
{
|
{
|
||||||
mcp2515_0.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_0, &_frame);
|
||||||
mcp2515_1.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_1, &_frame);
|
||||||
mcp2515_2.sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(&mcp2515_2, &_frame);;
|
||||||
HandleFrame(&_frame);
|
HandleFrame(&_frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleFrame(can_frame *frame)
|
void HandleFrame(can_frame *frame)
|
||||||
{
|
{
|
||||||
// ToggleDebug();
|
// ToggleDebug();
|
||||||
HandleMeyPinTriggeredCanPackage(frame);
|
HandleMeyPinTriggeredCanPackage(frame);
|
||||||
HandleTriggerMeypinCanPackage(frame);
|
HandleTriggerMeypinCanPackage(frame);
|
||||||
// Handle rules needs to be the last call
|
// Handle rules needs to be the last call
|
||||||
@@ -315,18 +316,18 @@ void HandleMeyPinTriggeredCanPackage(can_frame *frame)
|
|||||||
|
|
||||||
|
|
||||||
if (currentPinState == NULL)
|
if (currentPinState == NULL)
|
||||||
{
|
{
|
||||||
int16_t test2[3];
|
int16_t test2[3];
|
||||||
test2[0] = 'S';
|
test2[0] = 'S';
|
||||||
test2[1] = 'O';
|
test2[1] = 'O';
|
||||||
test2[2] = 'S';
|
test2[2] = 'S';
|
||||||
// SendDebugCanPackage(&mcp2515_3, test2, sizeof(test2) / sizeof(int16_t));
|
// SendDebugCanPackage(&mcp2515_3, test2, sizeof(test2) / sizeof(int16_t));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t test[1];
|
int16_t test[1];
|
||||||
test[0] = remotePinInfos.Count();
|
test[0] = remotePinInfos.Count();
|
||||||
// SendDebugCanPackage(&mcp2515_3, test, sizeof(test) / sizeof(int16_t));
|
// SendDebugCanPackage(&mcp2515_3, test, sizeof(test) / sizeof(int16_t));
|
||||||
|
|
||||||
currentPinState->setPinState(frame->data[0], frame->data[1]);
|
currentPinState->setPinState(frame->data[0], frame->data[1]);
|
||||||
|
|
||||||
@@ -471,7 +472,7 @@ void SendSerialPackage(MCP2515 *interface)
|
|||||||
_frame.data[1] = SoftwareVersionLow;
|
_frame.data[1] = SoftwareVersionLow;
|
||||||
_frame.data[2] = HardwareVersionHigh;
|
_frame.data[2] = HardwareVersionHigh;
|
||||||
_frame.data[3] = HardwareVersionLow;
|
_frame.data[3] = HardwareVersionLow;
|
||||||
interface->sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(interface, &_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSwitchedTriggeredCanPackage(MCP2515 *interface, byte pinId, int state)
|
void SendSwitchedTriggeredCanPackage(MCP2515 *interface, byte pinId, int state)
|
||||||
@@ -480,7 +481,7 @@ void SendSwitchedTriggeredCanPackage(MCP2515 *interface, byte pinId, int state)
|
|||||||
_frame.can_dlc = 2;
|
_frame.can_dlc = 2;
|
||||||
_frame.data[0] = pinId;
|
_frame.data[0] = pinId;
|
||||||
_frame.data[1] = state;
|
_frame.data[1] = state;
|
||||||
interface->sendMessage(MCP2515::TXB1, &_frame);
|
DoSendCanPkg(interface, &_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -492,9 +493,21 @@ void SendDoTriggerSwitchCanPackage(MCP2515 *interface, uint16_t targetCanId, byt
|
|||||||
_frame.data[1] = targetCanId & 0xFF;
|
_frame.data[1] = targetCanId & 0xFF;
|
||||||
_frame.data[2] = pinId;
|
_frame.data[2] = pinId;
|
||||||
_frame.data[3] = state;
|
_frame.data[3] = state;
|
||||||
interface->sendMessage(MCP2515::TXB1, &_frame);
|
|
||||||
|
DoSendCanPkg(interface, &_frame);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DoSendCanPkg(MCP2515 *interface, can_frame *frame)
|
||||||
|
{
|
||||||
|
// ToggleDebug();
|
||||||
|
byte cnt = 0;
|
||||||
|
while (interface->sendMessage(&_frame)) {
|
||||||
|
cnt++;
|
||||||
|
if (cnt > 10) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
void SendDebugCanPackage(MCP2515 *interface, int16_t *data, int len)
|
void SendDebugCanPackage(MCP2515 *interface, int16_t *data, int len)
|
||||||
{
|
{
|
||||||
can_frame frame = can_frame();
|
can_frame frame = can_frame();
|
||||||
@@ -510,5 +523,5 @@ void SendDebugCanPackage(MCP2515 *interface, int16_t *data, int len)
|
|||||||
frame.data[2 * i + 1] = ((byte[])data)[2 * i];
|
frame.data[2 * i + 1] = ((byte[])data)[2 * i];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface->sendMessage(MCP2515::TXB1, &frame);
|
DoSendCanPkg(interface, &frame);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user