FreeHIL
Loading...
Searching...
No Matches
FH_DI_GetStatus_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_DI</b> (Digital Input), <b>Cmd</b> (Command), <b>GetStatus</b>, <b>GetStatus_C</b> (GetStatus Call)\n
6 * Functions in this file, Call the related function in <b>FH_Functions</b>, Section <b>FH_DI</b> (Digital Input)
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_DI/Cmd/GetStatus/GetStatus_C/FH_DI_GetStatus_C.h"
35
36#include "../../../../../../../FH_Embedded/FH_Root/FH_General/FH_GeneralFunctions/FH_GeneralFunctions.h"
38
39#if FH_DI_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_DI</b> (Digital Input) 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_DI_Data
47 * *fH_DI_Data will be set with the value of the related <b>Digital Input</b>
48 * @param fH_DI_GetStatus_FuncPtr
49 * The array of function pointers
50 *
51 * @verbatim
52 ==============================================================================
53 ##### RobotFramework Example #####
54 ==============================================================================
55 @{MessageData} = Create List ${DI01}
56 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DI} Command=${DI_Commands_GetStatus} Data=@{MessageData}
57 ${Result} SendMessage &{Message}
58
59 Comments:
60
61 DI01 => It indicates the Digital Input 01
62 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
63 Function_DI => It is the function in the message frame
64 DI_Commands_GetStatus => It is the command of the function in the message frame
65 @endverbatim
66 *
67 * @return FH_ErrorInfo is returned
68 *
69
70*/
71FH_ErrorInfo FH_DI_GetStatus_C (FH_RFCommunication_Message* fh_RFCommunication_Message, uint8_t* fH_DI_Data, FH_DI_GetStatus_FuncPtrModel *fH_DI_GetStatus_FuncPtr)
72{
73 FH_ErrorInfo fh_ErrorInfo; // Error Information
74 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
75
76 for (uint8_t i = 1; i <= FH_DI_MaxPeripheralNumber; i++) // Iteration through all defined peripherals
77 {
78 if (i == fh_RFCommunication_Message -> Data[DI_GetStatus_PeripheralNumber]) // If the PeripheralNumber in the message frame is met
79 {
80 if (fH_DI_GetStatus_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
81 {
82 fh_ErrorInfo = fH_DI_GetStatus_FuncPtr[i-1](fH_DI_Data); // Call the related function
83 }
84 else
85 {
86 fh_ErrorInfo.error_code = FH_ERROR_Root; // There is Root error
87 }
88 return fh_ErrorInfo;
89 }
90 }
91 fh_ErrorInfo.error_code = FH_ERROR_MessageFrame; // There is message frame error
92 return fh_ErrorInfo;
93}
94
95/**
96 * @brief This function Calls the related function in <b>FH_Functions</b>, Section <b>FH_DI</b> (Digital Input) according to the 8 first parameters of the Data in the message frame\n
97 * (The first 8 parameters as mask resemble 64 bits and each bit resembles 1 <b>DI</b> (Digital Input) and if the bit is 1, the related <b>DI</b> (Digital Input) function will be called)
98 *
99 * @param fh_RFCommunication_Message
100 * The message frame set by <b>RobotFramework</b>
101 * @param fH_DI_MULTIData
102 * *fH_DI_MULTIData will be set with 8 bytes as 64 bits as 64 <b>Digital Input</b>
103 * @param fH_DI_GetStatus_FuncPtr
104 * The array of function pointers
105 *
106 * @verbatim
107 ==============================================================================
108 ##### RobotFramework Example #####
109 ==============================================================================
110 @{MessageData} = Create List FF FF FF FF FF FF FF FF
111 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DI} Command=${DI_Commands_GetStatusMULTI} Data=@{MessageData}
112 ${Result} SendMessage &{Message}
113
114 Comments:
115
116 FF FF FF FF FF FF FF FF => Example data as the first 8 parameters
117 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
118 Function_DI => It is the function in the message frame
119 DI_Commands_GetStatusMULTI => It is the command of the function in the message frame
120 @endverbatim
121 *
122 * @return FH_ErrorInfo is returned
123 *
124 * @warning
125 * By default, in <b>GetStatusMULTI</b> (Which is mass status get of up to 64 <b>DI</b> (Digital Input)) command, 8 bytes which is 64 bits (which means 64 <b>DI</b> (Digital Input)) is used in the command\n
126 * To use <b>GetStatusMULTI</b> (Which is mass status get of up to 64 <b>DI</b> (Digital Input)) command, <b>FH_DI_MaxPeripheralNumber</b> and <b>FH_DI_MULTI_MaxPeripheralNumberLimit</b> shall be set to 64
127 *
128
129*/
130FH_ErrorInfo FH_DI_GetStatusMULTI_C (FH_RFCommunication_Message* fh_RFCommunication_Message, uint8_t* fH_DI_MULTIData, FH_DI_GetStatus_FuncPtrModel *FH_DI_GetStatus_FuncPtr)
131{
132 FH_ErrorInfo fh_ErrorInfo; // Error Information
133 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
134
135 uint8_t FH_DI_Data = 0; // The status of the related digital input
136 uint8_t* FH_DI_Data_Ptr = &FH_DI_Data; // Pointer with &FH_DI_Data address
137
138 uint8_t DI_GetStatusMULTI_StatusMaskByteCounter = 0; // It temporarily stores the index (0 - 7) of the 8 bytes of mask in the Data part of the message frame
139 uint8_t DI_GetStatusMULTI_StatusMaskByte = 0; // It temporarily stores the byte value with the index number (DI_GetStatusMULTI_StatusMaskByteCounter) of the 8 bytes of mask in the Data part of the message frame
140 uint8_t DI_GetStatusMULTI_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
141 uint8_t DI_GetStatusMULTI_StatusMaskBit = 0; // It temporarily stores the bit value with the index number (DI_InitMULTI_MaskBitCounter) of every bit in the byte of mask in the Data part of the message frame
142
143 uint8_t MaxPeripheralNumber = 0; // MaxPeripheralNumber shall be the minimum of FH_DI_MaxPeripheralNumber and FH_DI_MULTI_MaxPeripheralNumberLimit to prevent calling an undefined function (with wrong address)
144 if (FH_DI_MaxPeripheralNumber > FH_DI_MULTI_MaxPeripheralNumberLimit) // If FH_DI_MaxPeripheralNumber is bigger than FH_DI_MULTI_MaxPeripheralNumberLimit (while both shall be 64)
145 {
146 MaxPeripheralNumber = FH_DI_MULTI_MaxPeripheralNumberLimit; // The minimum is FH_DI_MULTI_MaxPeripheralNumberLimit
147 }
148 else
149 {
150 MaxPeripheralNumber = FH_DI_MaxPeripheralNumber; // The minimum is FH_DI_MaxPeripheralNumber
151 }
152
153 for (uint8_t i = 1; i <= MaxPeripheralNumber; i++) // Iteration through all defined peripherals
154 {
155 DI_GetStatusMULTI_StatusMaskByte = fh_RFCommunication_Message -> Data[DI_GetStatusMULTI_StatusMaskByteCounter]; // Temporarily store the related byte value with the related index number of the 8 bytes of mask
156 DI_GetStatusMULTI_StatusMaskBit = DI_GetStatusMULTI_StatusMaskByte & (0x80 >> DI_GetStatusMULTI_StatusMaskBitCounter); // Temporarily store the related bit value from the related byte value from the 8 bytes of mask
157
158 if (DI_GetStatusMULTI_StatusMaskBit != 0) // If the specified bit is 1, start the related process (If it is 0, it shall be neglected)
159 {
160 if (FH_DI_GetStatus_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
161 {
162 FH_DI_Data = 0; // The status of the related digital input
163 FH_DI_GetStatus_FuncPtr[i-1](FH_DI_Data_Ptr); // Call the related function
164
165 if (FH_DI_Data == 1) // If the Status is 1, store 1 in the specific bit position in fH_DI_MULTIData
166 {
167 *(fH_DI_MULTIData + DI_GetStatusMULTI_StatusMaskByteCounter) = *(fH_DI_MULTIData + DI_GetStatusMULTI_StatusMaskByteCounter) |
168 (0x80 >> DI_GetStatusMULTI_StatusMaskBitCounter);
169
170 }
171 else // If the Status is 0, store 0 in the specific bit position in fH_DI_MULTIData
172 {
173 *(fH_DI_MULTIData + DI_GetStatusMULTI_StatusMaskByteCounter) = *(fH_DI_MULTIData + DI_GetStatusMULTI_StatusMaskByteCounter) &
174 ~ (0x80 >> DI_GetStatusMULTI_StatusMaskBitCounter);
175 }
176 }
177 else
178 {
179 }
180 }
181 DI_GetStatusMULTI_StatusMaskBitCounter++; // Increase the DI_GetStatusMULTI_StatusMaskBitCounter
182 if (DI_GetStatusMULTI_StatusMaskBitCounter == 8) // If the whole bits of the byte are already processed
183 {
184 DI_GetStatusMULTI_StatusMaskBitCounter = 0; // Reset DI_GetStatusMULTI_StatusMaskBitCounter
185 DI_GetStatusMULTI_StatusMaskByteCounter++; // Increase DI_GetStatusMULTI_StatusMaskByteCounter
186 }
187 }
188
189 return fh_ErrorInfo;
190}
191
192#endif