Software for V7 refactored
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
|
||||
|
||||
PinState *MeyPin = NULL;
|
||||
CanInterface *Interfaces = NULL;
|
||||
MCP2515* canInterfaces[4];
|
||||
CanInterface *CanBusses = NULL;
|
||||
uint16_t myDeviceId;
|
||||
|
||||
void SetupMeyPin(PinState *state)
|
||||
@@ -15,6 +14,20 @@ void SetupMeyPin(PinState *state)
|
||||
state->pin_state = false;
|
||||
}
|
||||
|
||||
void InitCanInterface(MCP2515 *interface, can_frame *frame) // can_frame is NULL. Reuse ForEach Method for smaller footprint
|
||||
{
|
||||
interface->reset();
|
||||
interface->setBitrate(CAN_500KBPS, MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHz
|
||||
interface->setNormalMode();
|
||||
|
||||
SendVersionPackage(interface);
|
||||
}
|
||||
|
||||
void ForEachCanInterface(void (*handle)(MCP2515 *canInterace))
|
||||
{
|
||||
CanBusses->ForEach(handle);
|
||||
}
|
||||
|
||||
void SetupMeyCan()
|
||||
{
|
||||
CalculateMyDeviceId();
|
||||
@@ -22,19 +35,21 @@ void SetupMeyCan()
|
||||
if (MeyPin != NULL);
|
||||
MeyPin->ForEach(SetupMeyPin);
|
||||
|
||||
for (int i = 0; i < sizeof(canInterfaces) / sizeof(MCP2515*); i++) {
|
||||
|
||||
canInterfaces[i]->reset();
|
||||
canInterfaces[i]->setBitrate(CAN_500KBPS, MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHz
|
||||
canInterfaces[i]->setNormalMode();
|
||||
|
||||
SendVersionPackage(canInterfaces[i]);
|
||||
if (CanBusses != NULL)
|
||||
{
|
||||
CanBusses->ForEach(InitCanInterface, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void SetCanInterface(byte index, byte pinId)
|
||||
{
|
||||
canInterfaces[index] = new MCP2515(pinId);
|
||||
MCP2515* newCanInterface = new MCP2515(pinId);
|
||||
CanInterface* canInterface = new CanInterface();
|
||||
|
||||
if (CanBusses == NULL)
|
||||
CanBusses = canInterface;
|
||||
else
|
||||
CanBusses->AddCanInterface(canInterface);
|
||||
}
|
||||
|
||||
void SetMeyPin(byte index, byte meyPinId, byte pinId)
|
||||
@@ -98,8 +113,9 @@ bool ReadPin(PinState * state)
|
||||
}
|
||||
|
||||
|
||||
void HandleFrame(can_frame *frame)
|
||||
void HandleFrame(can_frame *frame, MCP2515 *source)
|
||||
{
|
||||
CanBusses->ForEach(DoSendCanPkg, frame, source);
|
||||
HandleTriggerMeypinCanPackage(frame);
|
||||
}
|
||||
|
||||
@@ -199,8 +215,7 @@ void BroadcastTriggerMeyPinCanPackage(uint16_t targetCanId, byte pinId, byte sta
|
||||
toSend.data[2] = pinId;
|
||||
toSend.data[3] = state;
|
||||
|
||||
DoSendCanPkg(&toSend);
|
||||
HandleFrame(&toSend);
|
||||
HandleFrame(&toSend, NULL);
|
||||
}
|
||||
|
||||
void SendSwitchedTriggeredCanPackage(byte pinId, int state)
|
||||
@@ -216,11 +231,11 @@ void SendSwitchedTriggeredCanPackage(byte pinId, int state)
|
||||
|
||||
void DoSendCanPkg(can_frame *frame)
|
||||
{
|
||||
for (int i = 0; i < sizeof(canInterfaces) / sizeof(MCP2515*); i++)
|
||||
DoSendCanPkg(canInterfaces[i], frame);
|
||||
if (CanBusses != NULL)
|
||||
CanBusses->ForEach(DoSendCanPkg, frame);
|
||||
}
|
||||
|
||||
void DoSendCanPkg(MCP2515* interface, can_frame *frame)
|
||||
void DoSendCanPkg(MCP2515 *interface, can_frame *frame)
|
||||
{
|
||||
byte cnt = 0;
|
||||
while (interface->sendMessage(frame))
|
||||
|
||||
Reference in New Issue
Block a user