FreeHIL
Loading...
Searching...
No Matches
FH_DO_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_DO</b> (Digital Output), <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_DO</b> (Digital Output) 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 ------------------------------------------------------------------*/
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 * @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
42 *
43 * @param fh_RFCommunication_Message
44 * The message frame set by <b>RobotFramework</b>
45 * @param fH_DO_Init_FuncPtr
46 * The array of function pointers
47 *
48 * @verbatim
49 ==============================================================================
50 ##### RobotFramework Example #####
51 ==============================================================================
52 @{MessageData} = Create List ${DO01}
53 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_Init} Data=@{MessageData}
54 ${Result} SendMessage &{Message}
55
56 Comments:
57
58 DO01 => It indicates the Digital Output 01
59 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
60 Function_DO => It is the function in the message frame
61 DO_Commands_Init => It is the command of the function in the message frame
62 @endverbatim
63 *
64 * @return FH_ErrorInfo is returned
65 *
66
67*/
69{
70 FH_ErrorInfo fh_ErrorInfo; // Error Information
71 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
72
73 for (uint8_t i = 1; i <= FH_DO_MaxPeripheralNumber; i++) // Iteration through all defined peripherals
74 {
75 if (i == fh_RFCommunication_Message -> Data[DO_Init_PeripheralNumber]) // If the PeripheralNumber in the message frame is met
76 {
77 if (FH_DO_Init_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
78 {
79 fh_ErrorInfo = FH_DO_Init_FuncPtr[i-1](); // Call the related function
80 }
81 else
82 {
83 fh_ErrorInfo.error_code = FH_ERROR_Root; // There is Root error
84 }
85 return fh_ErrorInfo;
86 }
87 }
88 fh_ErrorInfo.error_code = FH_ERROR_MessageFrame; // There is message frame error
89 return fh_ErrorInfo;
90}
91
92/**
93 * @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
94 *
95 * @param fh_RFCommunication_Message
96 * The message frame set by <b>RobotFramework</b>
97 * @param fH_DO_Init_FuncPtr
98 * The array of function pointers
99 *
100 * @verbatim
101 ==============================================================================
102 ##### RobotFramework Example #####
103 ==============================================================================
104 @{MessageData} = Create List FF FF FF FF FF FF FF FF
105 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_InitMULTI} Data=@{MessageData}
106 ${Result} SendMessage &{Message}
107
108 Comments:
109
110 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 be initialized)
111 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
112 Function_DO => It is the function in the message frame
113 DO_Commands_InitMULTI => It is the command of the function in the message frame
114 @endverbatim
115 *
116 * @return FH_ErrorInfo is returned
117 *
118 * @warning
119 * By default, in <b>InitMULTI</b> (Which is mass initialization 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
120 * To use <b>InitMULTI</b> (Which is mass initialization 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
121 *
122
123*/
125{
126 FH_ErrorInfo fh_ErrorInfo; // Error Information
127 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
128
129 uint8_t DO_InitMULTI_MaskByteCounter = 0; // It temporarily stores the index (0 - 7) of the 8 bytes of mask in the Data part of the message frame
130 uint8_t DO_InitMULTI_MaskByte = 0; // It temporarily stores the byte value with the index number (DO_InitMULTI_MaskByteCounter) of the 8 bytes of mask in the Data part of the message frame
131 uint8_t DO_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
132 uint8_t DO_InitMULTI_MaskBit = 0; // It temporarily stores the bit value with the index number (DO_InitMULTI_MaskBitCounter) of every bit in the byte of mask in the Data part of the message frame
133
134 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)
135 if (FH_DO_MaxPeripheralNumber > FH_DO_MULTI_MaxPeripheralNumberLimit) // If FH_DO_MaxPeripheralNumber is bigger than FH_DO_MULTI_MaxPeripheralNumberLimit (while both shall be 64)
136 {
137 MaxPeripheralNumber = FH_DO_MULTI_MaxPeripheralNumberLimit; // The minimum is FH_DO_MULTI_MaxPeripheralNumberLimit
138 }
139 else
140 {
141 MaxPeripheralNumber = FH_DO_MaxPeripheralNumber; // The minimum is FH_DI_MaxPeripheralNumber
142 }
143
144 for (uint8_t i = 1; i <= MaxPeripheralNumber; i++) // Iteration through all defined peripherals
145 {
146 DO_InitMULTI_MaskByte = fh_RFCommunication_Message -> Data[DO_InitMULTI_MaskByteCounter]; // Temporarily store the related byte value with the related index number of the 8 bytes of mask
147 DO_InitMULTI_MaskBit = DO_InitMULTI_MaskByte & (0x80 >> DO_InitMULTI_MaskBitCounter); // Temporarily store the related bit value from the related byte value from the 8 bytes of mask
148 if (DO_InitMULTI_MaskBit != 0) // If the bit is 1
149 {
150 if (FH_DO_Init_FuncPtr[i-1] != NULL_PTR) // If the address of the function is truly assigned
151 {
152 FH_DO_Init_FuncPtr[i-1](); // Call the related function
153 }
154 else
155 {
156 }
157 }
158 DO_InitMULTI_MaskBitCounter++; // Increase the DO_InitMULTI_MaskBitCounter
159 if (DO_InitMULTI_MaskBitCounter == 8) // If the whole bits of the byte are already processed
160 {
161 DO_InitMULTI_MaskBitCounter = 0; // Reset DO_InitMULTI_MaskBitCounter
162 DO_InitMULTI_MaskByteCounter++; // Increase DO_InitMULTI_MaskByteCounter
163 }
164 }
165
166 return fh_ErrorInfo;
167}
168
169#endif