FreeHIL
Loading...
Searching...
No Matches
FH_DI_Init_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>Init</b>, <b>Init_C</b> (Init Call)\n
6 * Functions in this file, Call 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
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 ------------------------------------------------------------------*/
36
37#include "../../../../../../../FH_Embedded/FH_Root/FH_General/FH_GeneralFunctions/FH_GeneralFunctions.h"
39
40#if FH_DI_MaxPeripheralNumber > 0 // It is configurable in FH_DevicePeripherals.h
41
42/**
43 * @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
44 *
45 * @param fh_RFCommunication_Message
46 * The message frame set by <b>RobotFramework</b>
47 * @param fH_DI_Init_FuncPtr
48 * The array of function pointers
49 *
50 * @verbatim
51 ==============================================================================
52 ##### RobotFramework Example #####
53 ==============================================================================
54 @{MessageData} = Create List ${DI01}
55 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DI} Command=${DI_Commands_Init} Data=@{MessageData}
56 ${Result} SendMessage &{Message}
57
58 Comments:
59
60 DI01 => It indicates the Digital Input 01
61 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
62 Function_DI => It is the function in the message frame
63 DI_Commands_Init => 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_DI_MaxPeripheralNumber; i++) // Iteration through all defined peripherals
76 {
77 if (i == fh_RFCommunication_Message -> Data[DI_Init_PeripheralNumber]) // If the PeripheralNumber in the message frame is met
78 {
79 if (FH_DI_Init_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
80 {
81 fh_ErrorInfo = FH_DI_Init_FuncPtr[i-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_DI</b> (Digital Input) according to the first parameter of the Data in the message frame
96 *
97 * @param fh_RFCommunication_Message
98 * The message frame set by <b>RobotFramework</b>
99 * @param fH_DI_Init_FuncPtr
100 * The array of function pointers
101 *
102 * @verbatim
103 ==============================================================================
104 ##### RobotFramework Example #####
105 ==============================================================================
106 @{MessageData} = Create List FF FF FF FF FF FF FF FF
107 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DI} Command=${DI_Commands_InitMULTI} Data=@{MessageData}
108 ${Result} SendMessage &{Message}
109
110 Comments:
111
112 FF FF FF FF FF FF FF FF => Example data as the first 8 parameters
113 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
114 Function_DI => It is the function in the message frame
115 DI_Commands_InitMULTI => It is the command of the function in the message frame
116 @endverbatim
117 *
118 * @return FH_ErrorInfo is returned
119 *
120 * @warning
121 * By default, in <b>InitMULTI</b> (Which is mass initialization 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
122 * To use <b>InitMULTI</b> (Which is mass initialization 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
123 *
124
125*/
127{
128 FH_ErrorInfo fh_ErrorInfo; // Error Information
129 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
130
131 uint8_t DI_InitMULTI_MaskByteCounter = 0; // It temporarily stores the index (0 - 7) of the 8 bytes of mask in the Data part of the message frame
132 uint8_t DI_InitMULTI_MaskByte = 0; // It temporarily stores the byte value with the index number (DI_InitMULTI_MaskByteCounter) of the 8 bytes of mask in the Data part of the message frame
133 uint8_t DI_InitMULTI_MaskBitCounter = 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
134 uint8_t DI_InitMULTI_MaskBit = 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
135
136 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)
137 if (FH_DI_MaxPeripheralNumber > FH_DI_MULTI_MaxPeripheralNumberLimit) // If FH_DI_MaxPeripheralNumber is bigger than FH_DI_MULTI_MaxPeripheralNumberLimit (while both shall be 64)
138 {
139 MaxPeripheralNumber = FH_DI_MULTI_MaxPeripheralNumberLimit; // The minimum is FH_DI_MULTI_MaxPeripheralNumberLimit
140 }
141 else
142 {
143 MaxPeripheralNumber = FH_DI_MaxPeripheralNumber; // The minimum is FH_DI_MaxPeripheralNumber
144 }
145
146 for (uint8_t i = 1; i <= MaxPeripheralNumber; i++) // Iteration through all defined peripherals
147 {
148 DI_InitMULTI_MaskByte = fh_RFCommunication_Message -> Data[DI_InitMULTI_MaskByteCounter]; // Temporarily store the related byte value with the related index number of the 8 bytes of mask
149 DI_InitMULTI_MaskBit = DI_InitMULTI_MaskByte & (0x80 >> DI_InitMULTI_MaskBitCounter); // Temporarily store the related bit value from the related byte value from the 8 bytes of mask
150 if (DI_InitMULTI_MaskBit != 0) // If the specified bit is 1, start the related process (If it is 0, it shall be neglected)
151 {
152 if (FH_DI_Init_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
153 {
154 FH_DI_Init_FuncPtr[i-1](); // Call the related function
155 }
156 else
157 {
158 }
159 }
160 DI_InitMULTI_MaskBitCounter++; // Increase the DI_InitMULTI_MaskBit
161 if (DI_InitMULTI_MaskBitCounter == 8) // If the whole bits of the byte are already processed
162 {
163 DI_InitMULTI_MaskBitCounter = 0; // Reset DI_InitMULTI_MaskBit
164 DI_InitMULTI_MaskByteCounter++; // Increase DI_InitMULTI_MaskByteCounter
165 }
166 }
167 return fh_ErrorInfo;
168}
169
170#endif