FreeHIL
Loading...
Searching...
No Matches
FH_AO.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_AO</b> (Analog Output)\n
6 * Functions in this file, handle RFCommunication (<b>RobotFramework</b> <b>C</b>ommunication) for all commands related to <b>AO</b> (Analog 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_AO_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>AO</b> (Analog 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_AO_Commands_Init: // If the command is FH_AO_Commands_Init
69 fh_ErrorInfo = FH_AO_ProcessCommand_Init(fh_RFCommunication_Message); // Handle FH_AO_Commands_Init command
70 sprintf(FH_RFCommunication_SendBuf,"%02x|AO|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_AO_Commands_SetStatus: // If the command is FH_AO_Commands_SetStatus
74 fh_ErrorInfo = FH_AO_ProcessCommand_SetStatus(fh_RFCommunication_Message); // Handle FH_AO_Commands_SetStatus command
75 sprintf(FH_RFCommunication_SendBuf,"%02x|AO|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 default:
79 break;
80 }
81 return fh_ErrorInfo;
82}
83
84/**
85 * @brief This function handles <b>FH_AO_Commands_Init</b> command\n
86 * There are 3 main items handled in this function as following:\n
87 * 1 - Verifying the health of the received message\n
88 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) to an array of function pointer\n
89 * 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) according to the first parameter of the Data in the message frame
90 *
91 * @param fh_RFCommunication_Message
92 * The message frame set by <b>RobotFramework</b>
93 *
94 * @verbatim
95 ==============================================================================
96 ##### RobotFramework Example #####
97 ==============================================================================
98 @{MessageData} = Create List ${AO01}
99 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_AO} Command=${AO_Commands_Init} Data=@{MessageData}
100 ${Result} SendMessage &{Message}
101
102 Comments:
103
104 AO01 => It indicates the Analog Output 01
105 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
106 Function_AO => It is the function in the message frame
107 AO_Commands_Init => It is the command of the function in the message frame
108 @endverbatim
109 *
110 * @return FH_ErrorInfo is returned
111 *
112
113*/
115{
116 FH_ErrorInfo fh_ErrorInfo; // Error Information
117 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
118
119 // 1 - Verifying the health of the received message
121 if (fh_ErrorInfo.error_code != FH_ERROR_OK) // Check if the message is healthy or not
122 {
123 return fh_ErrorInfo; // Return the error
124 }
125
126 // 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) to an array of function pointer
127 FH_AO_Init_FuncPtrModel FH_AO_Init_FuncPtr[FH_AO_MaxPeripheralNumber]; // An array of function pointer FH_AO_Init_FuncPtrModel
128 FH_AO_Init_S (FH_AO_Init_FuncPtr); // Setting the address of the functions
129
130 // 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) according to the first parameter of the Data in the message frame
131 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
132 fh_ErrorInfo = FH_AO_Init_C (fh_RFCommunication_Message, FH_AO_Init_FuncPtr); // Calling the related function according to the first parameter of the Data in the message frame
133 return fh_ErrorInfo;
134}
135
136/**
137 * @brief This function handles <b>FH_AO_Commands_SetStatus</b> command\n
138 * There are 3 main items handled in this function as following:\n
139 * 1 - Verifying the health of the received message\n
140 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) to an array of function pointer\n
141 * 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) according to the first parameter of the Data in the message frame\n
142 * (The next 4 parameters after the first one, resemble the analog data to be set as one 32 bit data)
143 *
144 * @param fh_RFCommunication_Message
145 * The message frame set by <b>RobotFramework</b>
146 *
147 * @verbatim
148 ==============================================================================
149 ##### RobotFramework Example #####
150 ==============================================================================
151 @{MessageData} = Create List ${AO01} F1 C2 01 08
152 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_AO} Command=${AO_Commands_SetStatus} Data=@{MessageData}
153 ${Result} SendMessage &{Message}
154
155 Comments:
156
157 AO01 => It indicates the Analog Output 01
158 F1 C2 01 08 => Example data as analog value (0xF1C20108) to be set through the <b>Analog Output 01</b>\n
159 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
160 Function_AO => It is the function in the message frame
161 AO_Commands_SetStatus => It is the command of the function in the message frame
162 @endverbatim
163 *
164 *
165 * @return FH_ErrorInfo is returned
166 *
167
168*/
170{
171 FH_ErrorInfo fh_ErrorInfo; // Error Information
172 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
173
174 // 1 - Verifying the health of the received message
175 fh_ErrorInfo = FH_AO_SetStatus_H(fh_RFCommunication_Message);
176 if (fh_ErrorInfo.error_code != FH_ERROR_OK) // Check if the message is healthy or not
177 {
178 return fh_ErrorInfo; // Return the error
179 }
180
181 // 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) to an array of function pointer
182 FH_AO_SetStatus_FuncPtrModel FH_AO_SetStatus_FuncPtr[FH_AO_MaxPeripheralNumber]; // An array of function pointer FH_AO_SetStatus_FuncPtrModel
183 FH_AO_SetStatus_S (FH_AO_SetStatus_FuncPtr); // Setting the address of the functions
184
185 // 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_AO</b> (Analog Output) according to the first parameter of the Data in the message frame
186 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
187 fh_ErrorInfo = FH_AO_SetStatus_C (fh_RFCommunication_Message, FH_AO_SetStatus_FuncPtr); // Calling the related function according to the first 1 + 4 parameters of the Data in the message frame
188 return fh_ErrorInfo;
189}
190
191#endif