WIP
This commit is contained in:
@@ -1,104 +0,0 @@
|
|||||||
#include <SPI.h>;
|
|
||||||
#include <mcp2515.h>;
|
|
||||||
|
|
||||||
const uint32_t HELP_PACKAGE_CAN_ID = 0xFFFF;
|
|
||||||
const uint32_t SWITCH_TRIGGERED_CAN_ID = 0x050;
|
|
||||||
const uint32_t TRIGGER_SWITCH_CAN_ID = 0x055;
|
|
||||||
const uint32_t HELP_PACKAGE_ID = 0xFFFF;
|
|
||||||
|
|
||||||
|
|
||||||
byte MeyCircularShift(byte b)
|
|
||||||
{
|
|
||||||
return (b << 1) | (b >> 7 & 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t GetDeviceId(uint32_t canFrameId)
|
|
||||||
{
|
|
||||||
return canFrameId & 0xFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t GetPackageType(uint32_t canFrameId)
|
|
||||||
{
|
|
||||||
return (canFrameId / 0x10000) & 0xFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
byte DeviceId[1];
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t GetMyDeviceId()
|
|
||||||
{
|
|
||||||
return ( DeviceId[0] << 8) | (DeviceId[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte GetDeviceIdLow() {
|
|
||||||
return (SIGROW.SERNUM0 ^
|
|
||||||
MeyCircularShift(SIGROW.SERNUM2) << 1 ^
|
|
||||||
MeyCircularShift( MeyCircularShift(SIGROW.SERNUM4)) ^
|
|
||||||
MeyCircularShift( MeyCircularShift( MeyCircularShift(SIGROW.SERNUM6))) ^
|
|
||||||
MeyCircularShift( MeyCircularShift( MeyCircularShift( MeyCircularShift(SIGROW.SERNUM8)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
byte GetDeviceIdHigh() {
|
|
||||||
return (SIGROW.SERNUM1 ^
|
|
||||||
MeyCircularShift(SIGROW.SERNUM3) << 1 ^
|
|
||||||
MeyCircularShift( MeyCircularShift(SIGROW.SERNUM5)) ^
|
|
||||||
MeyCircularShift( MeyCircularShift( MeyCircularShift(SIGROW.SERNUM7))) ^
|
|
||||||
MeyCircularShift( MeyCircularShift( MeyCircularShift( MeyCircularShift(SIGROW.SERNUM9)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t sourceDevId;
|
|
||||||
byte sourceMeyPinId;
|
|
||||||
byte targetMeyPinId;
|
|
||||||
bool trigger;
|
|
||||||
|
|
||||||
void InitSimple(uint32_t sourceDevId, byte sourceMeyPinId, byte targetMeyPinId)
|
|
||||||
{
|
|
||||||
this->sourceDevId = sourceDevId;
|
|
||||||
this->sourceMeyPinId = sourceMeyPinId;
|
|
||||||
this->targetMeyPinId = targetMeyPinId;
|
|
||||||
trigger = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitTrigger(uint32_t sourceDevId, byte sourceMeyPinId, byte targetMeyPinId)
|
|
||||||
{
|
|
||||||
this->sourceDevId = sourceDevId;
|
|
||||||
this->sourceMeyPinId = sourceMeyPinId;
|
|
||||||
this->targetMeyPinId = targetMeyPinId;
|
|
||||||
trigger = true;
|
|
||||||
}
|
|
||||||
} Rule;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int pin_id;
|
|
||||||
bool pin_state;
|
|
||||||
bool is_input;
|
|
||||||
byte meyPinId;
|
|
||||||
|
|
||||||
PinState() {}
|
|
||||||
void Init(int pin_id, byte meyPinId)
|
|
||||||
{
|
|
||||||
this->pin_id = pin_id;
|
|
||||||
this->pin_state = true;
|
|
||||||
this->is_input = true;
|
|
||||||
this->meyPinId = meyPinId;
|
|
||||||
}
|
|
||||||
} PinState;
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t CreateCanId(uint32_t commandId)
|
|
||||||
{
|
|
||||||
return ((commandId & 0xFFF) * 0x10000) | ( DeviceId[0] << 8) | (DeviceId[1]) | CAN_EFF_FLAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitMeyCan()
|
|
||||||
{
|
|
||||||
DeviceId[0] = GetDeviceIdLow();
|
|
||||||
DeviceId[1] = GetDeviceIdHigh();
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ const byte HardwareVersionLow = 0;
|
|||||||
const uint32_t HELP_PACKAGE_CAN_ID = 0xFFFF;
|
const uint32_t HELP_PACKAGE_CAN_ID = 0xFFFF;
|
||||||
const uint32_t SWITCH_TRIGGERED_CAN_ID = 0x050;
|
const uint32_t SWITCH_TRIGGERED_CAN_ID = 0x050;
|
||||||
const uint32_t TRIGGER_SWITCH_CAN_ID = 0x055;
|
const uint32_t TRIGGER_SWITCH_CAN_ID = 0x055;
|
||||||
const uint32_t HELP_PACKAGE_ID = 0xFFFF;
|
|
||||||
|
|
||||||
struct can_frame _frame;
|
struct can_frame _frame;
|
||||||
|
|
||||||
@@ -166,7 +165,6 @@ void setup() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -175,6 +173,21 @@ bool debugState = false;
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
|
|
||||||
|
SendSerialPackage(mcp2515_0);
|
||||||
|
SendSerialPackage(mcp2515_1);
|
||||||
|
SendSerialPackage(mcp2515_2);
|
||||||
|
SendSerialPackage(mcp2515_3);
|
||||||
|
|
||||||
|
debugState = !debugState;
|
||||||
|
if (debugState)
|
||||||
|
digitalWrite(PIN_PC7, HIGH);
|
||||||
|
else
|
||||||
|
digitalWrite(PIN_PC7, LOW);
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
return;
|
||||||
|
|
||||||
if (mcp2515_0.readMessage(&_frame) == MCP2515::ERROR_OK)
|
if (mcp2515_0.readMessage(&_frame) == MCP2515::ERROR_OK)
|
||||||
{
|
{
|
||||||
mcp2515_1.sendMessage(MCP2515::TXB1, &_frame);
|
mcp2515_1.sendMessage(MCP2515::TXB1, &_frame);
|
||||||
@@ -269,7 +282,7 @@ uint32_t CreateCanId(uint32_t commandId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SendSerialPackage()
|
void SendSerialPackage(MCP2515 ss)
|
||||||
{
|
{
|
||||||
_frame.can_id = CreateCanId(HELP_PACKAGE_CAN_ID);
|
_frame.can_id = CreateCanId(HELP_PACKAGE_CAN_ID);
|
||||||
_frame.can_dlc = 4;
|
_frame.can_dlc = 4;
|
||||||
@@ -278,7 +291,7 @@ void SendSerialPackage()
|
|||||||
_frame.data[1] = SoftwareVersionLow;
|
_frame.data[1] = SoftwareVersionLow;
|
||||||
_frame.data[2] = HardwareVersionHigh;
|
_frame.data[2] = HardwareVersionHigh;
|
||||||
_frame.data[3] = HardwareVersionLow;
|
_frame.data[3] = HardwareVersionLow;
|
||||||
mcp2515_1.sendMessage(MCP2515::TXB1, &_frame);
|
mcp2515_0.sendMessage(MCP2515::TXB1, &_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSwitchedTriggeredCanPackage(byte pinId, int state)
|
void SendSwitchedTriggeredCanPackage(byte pinId, int state)
|
||||||
|
|||||||
Reference in New Issue
Block a user