FreeHIL
Loading...
Searching...
No Matches
FH_DO_SetStatus_C.c
Go to the documentation of this file.
1/**
2 * @file
3 * @brief
4 * <b>File Map:</b>\n
5 * <b>FH_Root</b>, Section <b>FH_Perif</b>, <b>FH_DO</b> (Digital Output), <b>Cmd</b> (Command), <b>SetStatus</b>, <b>SetStatus_C</b> (SetStatus Call)\n
6 * Functions in this file, Call the related function in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output)
7 *
8 * @attention <b>FH</b> user could left this file intact
9 *
10 *******************************************************************************
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Copyright 2026 Vahid Hasirchi
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 * http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 ********************************************************************************
27
28 *
29 * <b>For more information refer to FreeHIL.com</b>
30 *
31*/
32
33/* Includes ------------------------------------------------------------------*/
34#include "../../../../../../../FH_Embedded/FH_Root/FH_Perif/FH_DO/Cmd/SetStatus/SetStatus_C/FH_DO_SetStatus_C.h"
35
36#include "../../../../../../../FH_Embedded/FH_Root/FH_General/FH_GeneralFunctions/FH_GeneralFunctions.h"
38
39#if FH_DO_MaxPeripheralNumber > 0 // It is configurable in FH_DevicePeripherals.h
40
41/**
42 * @brief This function calls the related function in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) according to the first parameter of the Data in the message frame
43 *
44 * @param fh_RFCommunication_Message
45 * The message frame set by <b>RobotFramework</b>
46 * @param fH_DO_SetStatus_FuncPtr
47 * The array of function pointers
48 *
49 * @verbatim
50 ==============================================================================
51 ##### RobotFramework Example #####
52 ==============================================================================
53 @{MessageData} = Create List ${DO01} ${DO_Set}
54 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_SetStatus} Data=@{MessageData}
55 ${Result} SendMessage &{Message}
56
57 Comments:
58
59 DO01 => It indicates the Digital Output 01
60 DO_Set => It indicates the Digital Output 01 shall be Set (DO_Reset indicates the Digital Output 01 shall be Reset)
61 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
62 Function_DO => It is the function in the message frame
63 DO_Commands_SetStatus => It is the command of the function in the message frame
64 @endverbatim
65 *
66 * @return FH_ErrorInfo is returned
67 *
68
69*/
71{
72 FH_ErrorInfo fh_ErrorInfo; // Error Information
73 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
74
75 for (uint8_t i = 1; i <= FH_DO_MaxPeripheralNumber; i++) // Iteration through all defined peripherals
76 {
77 if (i == fh_RFCommunication_Message -> Data[DO_SetStatus_PeripheralNumber]) // If the PeripheralNumber in the message frame is met
78 {
79 if (FH_DO_SetStatus_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
80 {
81 fh_ErrorInfo = FH_DO_SetStatus_FuncPtr[i-1](fh_RFCommunication_Message -> Data[1]); // Call the related function
82 }
83 else
84 {
85 fh_ErrorInfo.error_code = FH_ERROR_Root; // There is Root error
86 }
87 return fh_ErrorInfo;
88 }
89 }
90 fh_ErrorInfo.error_code = FH_ERROR_MessageFrame; // There is message frame error
91 return fh_ErrorInfo;
92}
93
94/**
95 * @brief This function calls the related function in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) according to the 16 first parameters of the Data in the message frame\n
96 * (The first 8 bytes as mask resemble 64 bits and each bit resembles 1 <b>DO</b> (Digital Output) and if the bit is 1, the related <b>DO</b> (Digital Output) function will be called)\n
97 * (The second 8 bytes as data resemble 64 bits and each bit resembles status of 1 <b>DO</b> (Digital Output) as 1 or 0 of the corresponding bit in the first 8 bytes)
98 *
99 * @param fh_RFCommunication_Message
100 * The message frame set by <b>RobotFramework</b>
101 * @param fH_DO_SetStatus_FuncPtr
102 * The array of function pointers
103 *
104 * @verbatim
105 ==============================================================================
106 ##### RobotFramework Example #####
107 ==============================================================================
108 @{MessageData} = Create List FF FF FF FF FF FF FF FF 01 02 03 04 05 06 07 08
109 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_SetStatusMULTI} Data=@{MessageData}
110 ${Result} SendMessage &{Message}
111
112 Comments:
113
114 FF FF FF FF FF FF FF FF => Example data as the first 8 parameters of the Data in the message frame utilized as mask (In this example it means all 64 digital outputs shall set status)
115 01 02 03 04 05 06 07 08 => Example data as the second 8 parameters of the Data in the message frame as data value of 1 or 0, corresponding to the first 8 bytes)
116 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
117 Function_DO => It is the function in the message frame
118 DO_Commands_SetStatusMULTI => It is the command of the function in the message frame
119 @endverbatim
120 *
121 * @return FH_ErrorInfo is returned
122 *
123 * @warning
124 * By default, in <b>SetStatusMULTI</b> (Which is mass status set of up to 64 <b>DO</b> (Digital Output)) command, 8 bytes which is 64 bits (which means 64 <b>DO</b> (Digital Output)) is used in the command\n
125 * To use <b>SetStatusMULTI</b> (Which is mass status set of up to 64 <b>DO</b> (Digital Output)) command, <b>FH_DO_MaxPeripheralNumber</b> and <b>FH_DO_MULTI_MaxPeripheralNumberLimit</b> shall be set to 64
126 *
127
128*/
130{
131 FH_ErrorInfo fh_ErrorInfo; // Error Information
132 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
133
134 uint8_t DO_SetStatusMULTI_StatusMaskByteCounter = 0; // It temporarily stores the index (0 - 7) of the 8 bytes of mask in the Data part of the message frame
135 uint8_t DO_SetStatusMULTI_StatusMaskByte = 0; // It temporarily stores the byte value with the index number (DO_SetStatusMULTI_StatusMaskByteCounter) of the 8 bytes of mask in the Data part of the message frame
136 uint8_t DO_SetStatusMULTI_StatusMaskBitCounter = 0; // It temporarily stores the index (0 - 7) of the every bit in the byte of mask in the Data part of the message frame
137 uint8_t DO_SetStatusMULTI_StatusMaskBit = 0; // It temporarily stores the bit value with the index number (DO_SetStatusMULTI_StatusMaskBitCounter) of every bit in the byte of mask in the Data part of the message frame
138
139 uint8_t DO_SetStatusMULTI_StatusByteCounter = 0; // It temporarily stores the index (0 - 7) of the 8 bytes of data after mask in the Data part of the message frame
140 uint8_t DO_SetStatusMULTI_StatusByte = 0; // It temporarily stores the byte value with the index number (DO_SetStatusMULTI_StatusByteCounter) of the 8 bytes of data after mask in the Data part of the message frame
141 uint8_t DO_SetStatusMULTI_StatusBitCounter = 0; // It temporarily stores the index (0 - 7) of the every bit in the byte of data after mask in the Data part of the message frame
142 uint8_t DO_SetStatusMULTI_StatusBit = 0; // It temporarily stores the bit value with the index number (DO_SetStatusMULTI_StatusBitCounter) of every bit in the byte of data after mask in the Data part of the message frame
143
144 uint8_t MaxPeripheralNumber = 0; // MaxPeripheralNumber shall be the minimum of FH_DO_MaxPeripheralNumber and FH_DO_MULTI_MaxPeripheralNumberLimit to prevent calling an undefined function (with wrong address)
145 if (FH_DO_MaxPeripheralNumber > FH_DO_MULTI_MaxPeripheralNumberLimit) // If FH_DO_MaxPeripheralNumber is bigger than FH_DO_MULTI_MaxPeripheralNumberLimit (while both shall be 64)
146 {
147 MaxPeripheralNumber = FH_DO_MULTI_MaxPeripheralNumberLimit; // The minimum is FH_DO_MULTI_MaxPeripheralNumberLimit
148 }
149 else
150 {
151 MaxPeripheralNumber = FH_DO_MaxPeripheralNumber; // The minimum is FH_DO_MaxPeripheralNumber
152 }
153
154 for (uint8_t i = 1; i <= MaxPeripheralNumber; i++) // Iteration through all defined peripherals
155 {
156 DO_SetStatusMULTI_StatusMaskByte = fh_RFCommunication_Message -> Data[DO_SetStatusMULTI_StatusMaskByteCounter]; // Temporarily store the related byte value with the related index number of the 8 bytes of mask
157 DO_SetStatusMULTI_StatusMaskBit = DO_SetStatusMULTI_StatusMaskByte & (0x80 >> DO_SetStatusMULTI_StatusMaskBitCounter); // Temporarily store the related bit value from the related byte value from the 8 bytes of mask
158
159 if (DO_SetStatusMULTI_StatusMaskBit != 0) // If the specified bit is 1, start the related process (If it is 0, it shall be neglected)
160 {
161 if (FH_DO_SetStatus_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
162 {
163 DO_SetStatusMULTI_StatusByteCounter = DO_SetStatusMULTI_StatusMaskByteCounter + 8; // 8 bytes ahead is the position of the data byte related to a mask byte
164 DO_SetStatusMULTI_StatusByte = fh_RFCommunication_Message -> Data[DO_SetStatusMULTI_StatusByteCounter]; // Temporarily store the related byte value with the related index number of the 8 bytes of data after mask
165 DO_SetStatusMULTI_StatusBit = DO_SetStatusMULTI_StatusByte & (0x80 >> DO_SetStatusMULTI_StatusBitCounter); // Temporarily store the related bit value from the related byte value from the 8 bytes of data after mask
166
167 if (DO_SetStatusMULTI_StatusBit != 0)
168 {
169 DO_SetStatusMULTI_StatusBit = 1; // Status is Set (1)
170 }
171 else
172 {
173 DO_SetStatusMULTI_StatusBit = 0; // Status is Reset (0)
174 }
175 FH_DO_SetStatus_FuncPtr[i-1](DO_SetStatusMULTI_StatusBit); // Call the related function with the specified bit value as argument
176 }
177 else
178 {
179 }
180 }
181 DO_SetStatusMULTI_StatusBitCounter++; // Increase the DO_SetStatusMULTI_StatusBitCounter
182 DO_SetStatusMULTI_StatusMaskBitCounter++; // Increase the DO_SetStatusMULTI_StatusMaskBitCounter
183 if (DO_SetStatusMULTI_StatusMaskBitCounter == 8) // If the whole bits of the byte are already processed
184 {
185 DO_SetStatusMULTI_StatusMaskBitCounter = 0; // Reset DO_SetStatusMULTI_StatusMaskBitCounter
186 DO_SetStatusMULTI_StatusMaskByteCounter++; // Increase DO_SetStatusMULTI_StatusMaskByteCounter
187 DO_SetStatusMULTI_StatusBitCounter = 0;
188 }
189 }
190 return fh_ErrorInfo;
191}
192
193#endif