From d8a9bb7610c30f5e441864ece03bb77b8dec24b0 Mon Sep 17 00:00:00 2001 From: Meydin87 Date: Sun, 9 Jul 2023 07:57:06 +0200 Subject: [PATCH] added testcases / a bit refactored --- Software/Protocol.txt | 6 +-- Software/Switch/Swtich/MeyCan.cpp | 2 +- Software/Switch/Swtich/MeyCan.h | 2 +- Software/Switch/Swtich/MeyRule.cpp | 25 +++++++---- Software/Switch/Swtich/MeyRule.h | 1 + Software/Switch/Swtich/Swtich.ino | 2 +- Software/Testfälle.txt | 68 ++++++++++++++++++++++++++++++ 7 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 Software/Testfälle.txt diff --git a/Software/Protocol.txt b/Software/Protocol.txt index 5e52040..6f6687c 100644 --- a/Software/Protocol.txt +++ b/Software/Protocol.txt @@ -15,9 +15,9 @@ Packages --------------------------------- 0xF00: HELLO->ADOPT Payload: - 2 bytes | DeviceId -> DeviceId Explicit 2 bytes | Byte -> Software-Version (1.0) - 2 bytes | Byte -> Hw Version (4.0 + 2 bytes | Byte -> Hw Version (4.0) + 2 bytes | DeviceId -> DeviceId Explicit 0x050: Input Switch Triggered -> Broadcast @@ -29,7 +29,7 @@ Payload: 0x055: Command Set Switch -> Broadcast --------------------------------- - 2 bytes | TargetDeviceId -> The id of the board + 2 bytes | TargetDeviceId -> The id of the device to set the pin of 1 byte | PinId -> Idof the pin of the board 1 byte | state -> 1 to swtich on, 0 to switch off diff --git a/Software/Switch/Swtich/MeyCan.cpp b/Software/Switch/Swtich/MeyCan.cpp index 6609c9b..9310596 100644 --- a/Software/Switch/Swtich/MeyCan.cpp +++ b/Software/Switch/Swtich/MeyCan.cpp @@ -138,7 +138,7 @@ void SendVersionPackage(MCP2515 *interface) DoSendCanPkg(interface, &toSend); } -void SendDoTriggerSwitchCanPackage(uint16_t targetCanId, byte pinId, byte state) +void BroadcastTriggerMeyPinCanPackage(uint16_t targetCanId, byte pinId, byte state) { can_frame toSend; diff --git a/Software/Switch/Swtich/MeyCan.h b/Software/Switch/Swtich/MeyCan.h index 51f6ca9..fde38c3 100644 --- a/Software/Switch/Swtich/MeyCan.h +++ b/Software/Switch/Swtich/MeyCan.h @@ -54,7 +54,7 @@ uint32_t CreateCanId(uint16_t commandId); void SendVersionPackage(MCP2515 *interface); void SendSwitchedTriggeredCanPackage(byte pinId, int state); -void SendDoTriggerSwitchCanPackage(uint16_t targetCanId, byte pinId, byte state); +void BroadcastTriggerMeyPinCanPackage(uint16_t targetCanId, byte pinId, byte state); void DoSendCanPkg(can_frame *frame); void DoSendCanPkg(MCP2515 *interface, can_frame *frame); diff --git a/Software/Switch/Swtich/MeyRule.cpp b/Software/Switch/Swtich/MeyRule.cpp index fb376a5..5211f90 100644 --- a/Software/Switch/Swtich/MeyRule.cpp +++ b/Software/Switch/Swtich/MeyRule.cpp @@ -71,20 +71,27 @@ void CheckRule(uint16_t deviceId, uint8_t dt, uint8_t state, Rule *rule) if (rule->toggle) pinState = (currentPinState->getPinState(rule->targetMeyPinId) ^ true); - - SendDoTriggerSwitchCanPackage(rule->targetDevId, rule->targetMeyPinId, pinState); - // //digitalWrite(foundPinId->pin_id, pinState); - // //foundPinId->pin_state = pinState; - // - currentPinState->setPinState(rule->targetMeyPinId, pinState); - - - + BroadcastTriggerMeyPinCanPackage(rule->targetDevId, rule->targetMeyPinId, pinState); + currentPinState->setPinState(rule->targetMeyPinId, pinState); } +void HandleTriggered(can_frame *frame) +{ + if (GetPackageType(frame->can_id) == SWITCH_TRIGGERED_CAN_ID) + { + RemotePinInfo *currentPinState = remotePinInfo.FindOrAdd(GetDeviceId(frame->can_id) ); + + if (currentPinState == NULL) + return; + + currentPinState->setPinState(frame->data[0], frame->data[1]); + } +} void HandleRules(can_frame *frame) { + HandleTriggered(frame); + if (rules == NULL) return; if (GetPackageType(frame->can_id) == SWITCH_TRIGGERED_CAN_ID) { diff --git a/Software/Switch/Swtich/MeyRule.h b/Software/Switch/Swtich/MeyRule.h index 5105b6a..2245767 100644 --- a/Software/Switch/Swtich/MeyRule.h +++ b/Software/Switch/Swtich/MeyRule.h @@ -107,4 +107,5 @@ void AddToggle(uint16_t sourceDevId, byte sourceMeyPinId, uint16_t targetDevId, void AddToggleInverse(uint16_t sourceDevId, byte sourceMeyPinId, uint16_t targetDevId, byte targetMeyPinId); void HandleRules(can_frame *frame); void PutRule(Rule *rule); +void CheckRule(uint16_t deviceId, uint8_t dt, uint8_t state, Rule *rule); #endif diff --git a/Software/Switch/Swtich/Swtich.ino b/Software/Switch/Swtich/Swtich.ino index 62aad6c..129a7db 100644 --- a/Software/Switch/Swtich/Swtich.ino +++ b/Software/Switch/Swtich/Swtich.ino @@ -63,7 +63,7 @@ void loop() } HandleFrame(&incomingCanFrame); - HandleRules(&incomingCanFrame); + // HandleRules(&incomingCanFrame); } } } diff --git a/Software/Testfälle.txt b/Software/Testfälle.txt new file mode 100644 index 0000000..f7d652e --- /dev/null +++ b/Software/Testfälle.txt @@ -0,0 +1,68 @@ +Testfälle Meycan Switch + +PreCons for each: +GIVEN XX XX is the deviceId of the target device +GIVEN YY YY is another device id, which is NOT XX XX +GIVEN 2nd CAN Debug Device on another CanBus of switch + +1) A MeyPin can be triggered directly (repeat Test for all MeyPins and each CAN Bus Interface specified) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 01 01 -> (MeyPin1 Should switch to on) + THEN The MeyPin 1 should trigger + THEN you receive a message 00 50 XX XX | 01 01 + THEN 2nd device should receive 2 messages + * 00 50 XX XX | 01 01 + * 00 55 11 11 | XX XX 01 01 + +1a) A MeyPin trigger is effecltess, if only set + GIVEN the above testcast + WHEN Send CAN Pkg 00 55 11 11 | XX XX 01 01 + THEN Nothing changed + THEN you dont receive a message + THEN 2nd device should receive 00 55 11 11 | XX XX 01 01 + + WHEN Send CAN Pkg 00 55 11 11 | XX XX 01 00 -> (MeyPin1 Should switch to off) + THEN The MeyPin 1 should switch to OFF + THEN you receive a message 00 50 XX XX | 01 00 + THEN 2nd device should receive 2 messages + * 00 50 XX XX | 01 00 + * 00 55 11 11 | XX XX 01 00 + + +2) A MeyPin is not triggered, if the device id dont match + WHEN Send CAN Pkg 00 55 11 11 | YY YY 01 01 + THEN None of the pins of the device triggered + THEN you receive no message + THEN 2nd device should receive 1 messages + * 00 55 11 11 | XX XX 01 01 + + +3) A MeyPin is not triggered, if the Package Type dont match + WHEN Send CAN Pkg 50 00 11 11 | YY YY 01 01 + THEN None of the pins of the device triggered + THEN you receive no message + THEN 2nd device should receive 1 messages + * 50 00 11 11 | XX XX 01 01 + +3) A MeyPin is not triggered, if the MeyPin is above 8 (max pins) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 09 01 + THEN None of the pins of the device triggered + THEN you receive no message + THEN 2nd device should receive 1 messages + * 00 55 11 11 | XX XX 09 01 + THEN you can execute any other testcase, as the switch didnt crash + +4) All MeyPins can be activated more than 15 minutes in parallel(Activate each port for at least 15 mins) + GIVE You have a relais connected to each of the ports + WHEN Send CAN Pkg 00 55 11 11 | XX XX 01 01 -> (MeyPin1 Should switch to on) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 02 01 -> (MeyPin2 Should switch to on) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 03 01 -> (MeyPin3 Should switch to on) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 04 01 -> (MeyPin4 Should switch to on) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 05 01 -> (MeyPin5 Should switch to on) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 06 01 -> (MeyPin6 Should switch to on) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 07 01 -> (MeyPin7 Should switch to on) + WHEN Send CAN Pkg 00 55 11 11 | XX XX 08 01 -> (MeyPin8 Should switch to on) + THEN you should only receive the packages from above. + THEN you should NOT receive a VersionPackage + WHEN you wait 15 Minutes + THEN nothing should be send + THEN the Pins should not trigger \ No newline at end of file