FreeHIL
Loading...
Searching...
No Matches
FH_DO.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)\n
6 * Functions in this file, handle RFCommunication (<b>RobotFramework</b> <b>C</b>ommunication) for all commands related to <b>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/* Primary Includes ------------------------------------------------------------------*/
34
35#include "stdio.h"
36
37#if FH_DO_MaxPeripheralNumber > 0 // It is configurable in FH_DevicePeripherals.h
38
39/* Secondary Includes ------------------------------------------------------------------*/
49
50/**
51 * @brief This function is the basic function of handling RFCommunication (<b>RobotFramework</b> <b>C</b>ommunication) for all the <b>Commands</b> related to the <b>Function</b> <b>DO</b> (Digital Output)\n
52 * This function is called from <b>FH_RFCommunication()</b>
53 *
54 * @param fh_RFCommunication_Message
55 * The message frame set by <b>RobotFramework</b>
56 *
57 * @return FH_ErrorInfo is returned
58 *
59
60*/
62{
63 FH_ErrorInfo fh_ErrorInfo; // Error Information
64 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
65
66 switch (fh_RFCommunication_Message -> Command) // Check different commands
67 {
68 case FH_DO_Commands_Init: // If the command is FH_DO_Commands_Init
69 fh_ErrorInfo = FH_DO_ProcessCommand_Init(fh_RFCommunication_Message); // Handle FH_DO_Commands_Init command
70 sprintf(FH_RFCommunication_SendBuf,"%02x|DO|Init|%02x|\n",FH_RFCommunication_DeviceAddress,fh_ErrorInfo.error_code); // set FH_RFCommunication_SendBuf buffer
71 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
72 break;
73 case FH_DO_Commands_SetStatus: // If the command is FH_DO_Commands_SetStatus
74 fh_ErrorInfo = FH_DO_ProcessCommand_SetStatus(fh_RFCommunication_Message); // Handle FH_DO_Commands_SetStatus command
75 sprintf(FH_RFCommunication_SendBuf,"%02x|DO|SetStatus|%02x|\n",FH_RFCommunication_DeviceAddress,fh_ErrorInfo.error_code); // set FH_RFCommunication_SendBuf buffer
76 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
77 break;
78 case FH_DO_Commands_InitMULTI: // If the command is FH_DO_Commands_InitMULTI
79 fh_ErrorInfo = FH_DO_ProcessCommand_InitMULTI(fh_RFCommunication_Message); // Handle FH_DO_Commands_InitMULTI command
80 sprintf(FH_RFCommunication_SendBuf,"%02x|DO|InitMULTI|%02x|\n",FH_RFCommunication_DeviceAddress,fh_ErrorInfo.error_code); // set FH_RFCommunication_SendBuf buffer
81 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
82 break;
83 case FH_DO_Commands_SetStatusMULTI: // If the command is FH_DO_Commands_SetStatusMULTI
84 fh_ErrorInfo = FH_DO_ProcessCommand_SetStatusMULTI(fh_RFCommunication_Message); // Handle FH_DO_Commands_SetStatusMULTI command
85 sprintf(FH_RFCommunication_SendBuf,"%02x|DO|SetStatusMULTI|%02x|\n",FH_RFCommunication_DeviceAddress,fh_ErrorInfo.error_code); // set FH_RFCommunication_SendBuf buffer
86 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
87 break;
88 default:
89 break;
90 }
91 return fh_ErrorInfo;
92}
93
94/**
95 * @brief This function handles <b>FH_DO_Commands_Init</b> command\n
96 * There are 3 main items handled in this function as following:\n
97 * 1 - Verifying the health of the received message\n
98 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer\n
99 * 3 - Calling 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
100 *
101 * @param fh_RFCommunication_Message
102 * The message frame set by <b>RobotFramework</b>
103 *
104 * @verbatim
105 ==============================================================================
106 ##### RobotFramework Example #####
107 ==============================================================================
108 @{MessageData} = Create List ${DO01}
109 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_Init} Data=@{MessageData}
110 ${Result} SendMessage &{Message}
111
112 Comments:
113
114 DO01 => It indicates the Digital Output 01
115 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
116 Function_DO => It is the function in the message frame
117 DO_Commands_Init => It is the command of the function in the message frame
118 @endverbatim
119 *
120 *
121 * @return FH_ErrorInfo is returned
122 *
123
124*/
126{
127 FH_ErrorInfo fh_ErrorInfo; // Error Information
128 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
129
130 // Item 1 - Verifying the health of the received message
131 fh_ErrorInfo = FH_DO_Init_H(fh_RFCommunication_Message); // Calling the related health function
132 if (fh_ErrorInfo.error_code != FH_ERROR_OK) // Check if the message is healthy or not
133 {
134 return fh_ErrorInfo; // Return the error
135 }
136
137 // Item 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer
138 FH_DO_Init_FuncPtrModel FH_DO_Init_FuncPtr[FH_DO_MaxPeripheralNumber]; // An array of function pointer FH_DO_Init_FuncPtrModel
139 FH_DO_Init_S (FH_DO_Init_FuncPtr); // Setting the address of the functions
140
141 // Item 3 - Calling 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
142 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
143 fh_ErrorInfo = FH_DO_Init_C (fh_RFCommunication_Message, FH_DO_Init_FuncPtr); // Calling the related function according to the first parameter of the Data in the message frame
144 return fh_ErrorInfo;
145}
146
147/**
148 * @brief This function handles <b>FH_DO_Commands_SetStatus</b> command\n
149 * There are 3 main items handled in this function as following:\n
150 * 1 - Verifying the health of the received message\n
151 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer\n
152 * 3 - Calling 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
153 * (The second parameter resemble the digital data to be set as 1 or 0)
154 *
155 * @param fh_RFCommunication_Message
156 * The message frame set by <b>RobotFramework</b>
157 *
158 * @verbatim
159 ==============================================================================
160 ##### RobotFramework Example #####
161 ==============================================================================
162 @{MessageData} = Create List ${DO01} ${DO_Set}
163 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_SetStatus} Data=@{MessageData}
164 ${Result} SendMessage &{Message}
165
166 Comments:
167
168 DO01 => It indicates the Digital Output 01
169 DO_Set => It indicates the Digital Output 01 shall be Set (DO_Reset indicates the Digital Output 01 shall be Reset)
170 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
171 Function_DO => It is the function in the message frame
172 DO_Commands_SetStatus => It is the command of the function in the message frame
173 @endverbatim
174 *
175 *
176 * @return FH_ErrorInfo is returned
177 *
178
179*/
181{
182 FH_ErrorInfo fh_ErrorInfo; // Error Information
183 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
184
185 // Item 1 - Verifying the health of the received message
186 fh_ErrorInfo = FH_DO_SetStatus_H(fh_RFCommunication_Message); // Calling the related health function
187 if (fh_ErrorInfo.error_code != FH_ERROR_OK) // Check if the message is healthy or not
188 {
189 return fh_ErrorInfo; // Return the error
190 }
191
192 // Item 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer
193 FH_DO_SetStatus_FuncPtrModel FH_DO_SetStatus_FuncPtr[FH_DO_MaxPeripheralNumber]; // An array of function pointer FH_DO_Init_FuncPtrModel
194 FH_DO_SetStatus_S (FH_DO_SetStatus_FuncPtr); // Setting the address of the functions
195
196 // Item 3 - Calling 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
197 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
198 fh_ErrorInfo = FH_DO_SetStatus_C (fh_RFCommunication_Message, FH_DO_SetStatus_FuncPtr); // Calling the related function according to the first parameter of the Data in the message frame
199 return fh_ErrorInfo;
200}
201
202/**
203 * @brief This function handles <b>FH_DO_ProcessCommand_InitMULTI</b> command\n
204 * With this function, mass initialization of up to 64 <b>DO</b> (Digital Output) is possible instead of just 1 <b>DO</b> (Digital Output)\n
205 * There are 3 main items handled in this function as following:\n
206 * 1 - Verifying the health of the received message\n
207 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer\n
208 * 3 - Calling the related function(s) in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) according to the 8 first parameters of the Data in the message frame
209 * (The first 8 bytes 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)
210 *
211 * @param fh_RFCommunication_Message
212 * The message frame set by <b>RobotFramework</b>
213 *
214 * @verbatim
215 ==============================================================================
216 ##### RobotFramework Example #####
217 ==============================================================================
218 @{MessageData} = Create List FF FF FF FF FF FF FF FF
219 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_InitMULTI} Data=@{MessageData}
220 ${Result} SendMessage &{Message}
221
222 Comments:
223
224 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)
225 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
226 Function_DO => It is the function in the message frame
227 DO_Commands_InitMULTI => It is the command of the function in the message frame
228 @endverbatim
229 *
230 * @return FH_ErrorInfo is returned
231 *
232
233*/
235{
236 FH_ErrorInfo fh_ErrorInfo; // Error Information
237 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
238
239 // Item 1 - Verifying the health of the received message
240 fh_ErrorInfo = FH_DO_InitMULTI_H(fh_RFCommunication_Message); // Calling the related health function
241 if (fh_ErrorInfo.error_code != FH_ERROR_OK) // Check if the message is healthy or not
242 {
243 return fh_ErrorInfo; // Return the error
244 }
245
246 // Item 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer
247 FH_DO_Init_FuncPtrModel FH_DO_Init_FuncPtr[FH_DO_MaxPeripheralNumber]; // An array of function pointer FH_DO_Init_FuncPtrModel
248 FH_DO_Init_S (FH_DO_Init_FuncPtr); // Setting the address of the functions
249
250 // Item 3 - Calling the related function(s) in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) according to the 8 first parameters of the Data in the message frame
251 // (8 bytes 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)
252 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
253 fh_ErrorInfo = FH_DO_InitMULTI_C (fh_RFCommunication_Message, FH_DO_Init_FuncPtr); // Calling the related function according to the first 8 parameters of Data in the message frame
254 return fh_ErrorInfo;
255}
256
257/**
258 * @brief This function handles <b>FH_DO_ProcessCommand_SetStatusMULTI</b> command\n
259 * With this function, mass status set of up to 64 <b>DO</b> (Digital Output) is possible instead of just 1 <b>DO</b> (Digital Output)\n
260 * There are 3 main items handled in this function as following:\n
261 * 1 - Verifying the health of the received message\n
262 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer\n
263 * 3 - Calling 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
264 * (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
265 * (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)
266 *
267 * @param fh_RFCommunication_Message
268 * The message frame set by <b>RobotFramework</b>
269 *
270 * @verbatim
271 ==============================================================================
272 ##### RobotFramework Example #####
273 ==============================================================================
274 @{MessageData} = Create List FF FF FF FF FF FF FF FF 01 02 03 04 05 06 07 08
275 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_DO} Command=${DO_Commands_SetStatusMULTI} Data=@{MessageData}
276 ${Result} SendMessage &{Message}
277
278 Comments:
279
280 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)
281 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)
282 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
283 Function_DO => It is the function in the message frame
284 DO_Commands_SetStatusMULTI => It is the command of the function in the message frame
285 @endverbatim
286 *
287 * @return FH_ErrorInfo is returned
288 *
289
290*/
292{
293 FH_ErrorInfo fh_ErrorInfo; // Error Information
294 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
295
296 // Item 1 - Verifying the health of the received message
297 fh_ErrorInfo = FH_DO_SetStatusMULTI_H(fh_RFCommunication_Message); // Calling the related health function
298 if (fh_ErrorInfo.error_code != FH_ERROR_OK)
299 {
300 return fh_ErrorInfo; // Return the error
301 }
302
303 // Item 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_DO</b> (Digital Output) to an array of function pointer
304 FH_DO_SetStatus_FuncPtrModel FH_DO_SetStatus_FuncPtr[FH_DO_MaxPeripheralNumber]; // An array of function pointer FH_DO_Init_FuncPtrModel
305 FH_DO_SetStatus_S (FH_DO_SetStatus_FuncPtr); // Setting the address of the functions
306
307 // 3 - Calling 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
308 // (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)
309 // (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)
310 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
311 fh_ErrorInfo = FH_DO_SetStatusMULTI_C (fh_RFCommunication_Message, FH_DO_SetStatus_FuncPtr); // Calling the related function according to the first 8 parameters of the Data in the message frame
312 return fh_ErrorInfo;
313}
314
315#endif