FreeHIL
Loading...
Searching...
No Matches
FH_PWMI.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_PWMI</b> (PWM Input)\n
6 * Functions in this file, handle RFCommunication (<b>RobotFramework</b> <b>C</b>ommunication) for all commands related to <b>PWMI</b> (PWM 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/* Primary Includes ------------------------------------------------------------------*/
34
35#include "stdio.h"
36
37#if FH_PWMI_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>PWMI</b> (PWM Input)\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 uint32_t FH_PWMI_Frequency; // It temporarily stores the frequency of a PWM input
67 uint32_t* FH_PWMI_Frequency_Ptr = &FH_PWMI_Frequency; // Pointer with &FH_PWMI_Frequency address
68
69 uint8_t FH_PWMI_DutyCycle; // It temporarily stores the duty cycle of a PWM input
70 uint8_t* FH_PWMI_DutyCycle_Ptr = &FH_PWMI_DutyCycle; // Pointer with &FH_PWMI_DutyCycle address
71
72 FH_Uint8Uint32 fh_Uint8Uint32; // To convert 32 bits data (uint32_t) to four 8 bits data (uint8_t) in FH_PWMI_Frequency
73
74 switch (fh_RFCommunication_Message -> Command)
75 {
76 case FH_PWMI_Commands_Init: // If the command is FH_PWMI_Commands_Init
77 fh_ErrorInfo = FH_PWMI_ProcessCommand_Init(fh_RFCommunication_Message); // Handle FH_PWMI_Commands_Init command
78 sprintf(FH_RFCommunication_SendBuf,"%02x|PWMI|Init|%02x|\n",FH_RFCommunication_DeviceAddress,fh_ErrorInfo.error_code); // set FH_RFCommunication_SendBuf buffer
79 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
80 break;
81 case FH_PWMI_Commands_GetStatus: // If the command is FH_PWMI_Commands_GetStatus
82 fh_ErrorInfo = FH_PWMI_ProcessCommand_GetStatus(fh_RFCommunication_Message, FH_PWMI_Frequency_Ptr, FH_PWMI_DutyCycle_Ptr); // Handle FH_PWMI_Commands_GetStatus command
83
84 sprintf(FH_RFCommunication_SendBuf,"%02x|PWMI|GetStatus|%02x|",FH_RFCommunication_DeviceAddress,fh_ErrorInfo.error_code); // set FH_RFCommunication_SendBuf buffer
85 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
86
87 fh_Uint8Uint32.value = FH_PWMI_Frequency; // set the 32 bit value
88 for (int i = 3 ; i >= 0; i--)
89 {
90 sprintf(FH_RFCommunication_SendBuf,"%02x",fh_Uint8Uint32.bytes[i]); // Format the data and set FH_RFCommunication_SendBuf buffer
91 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
92 }
93
94 sprintf(FH_RFCommunication_SendBuf,"|%02x|\n",FH_PWMI_DutyCycle); // set FH_RFCommunication_SendBuf buffer
95 FH_RFCommunication_Send(FH_RFCommunication_SendBuf); // Send the result back to the Robot Framework
96 break;
97 default:
98 break;
99 }
100 return fh_ErrorInfo;
101}
102
103/**
104 * @brief This function handles <b>FH_PWMI_Commands_Init</b> command\n
105 * There are 3 main items handled in this function as following:\n
106 * 1 - Verifying the health of the received message\n
107 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) to an array of function pointer\n
108 * 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) according to the first parameter of the Data in the message frame
109 *
110 * @param fh_RFCommunication_Message
111 * The message frame set by <b>RobotFramework</b>
112 *
113 * @verbatim
114 ==============================================================================
115 ##### RobotFramework Example #####
116 ==============================================================================
117 @{MessageData} = Create List ${PWMI01}
118 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_PWMI} Command=${PWMI_Commands_Init} Data=@{MessageData}
119 ${Result} SendMessage &{Message}
120
121 Comments:
122
123 PWMI01 => It indicates the PWM Input 01
124 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
125 Function_PWMI => It is the function in the message frame
126 PWMI_Commands_Init => It is the command of the function in the message frame
127 @endverbatim
128 *
129 * @return FH_ErrorInfo is returned
130 *
131
132*/
134{
135 FH_ErrorInfo fh_ErrorInfo; // Error Information
136 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
137
138 // Item 1 - Verifying the health of the received message
139 fh_ErrorInfo = FH_PWMI_Init_H(fh_RFCommunication_Message);
140 if (fh_ErrorInfo.error_code != FH_ERROR_OK) // Check if the message is healthy or not
141 {
142 return fh_ErrorInfo; // Return the error
143 }
144
145 // 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) to an array of function pointer
146 FH_PWMI_Init_FuncPtrModel FH_PWMI_Init_FuncPtr[FH_PWMI_MaxPeripheralNumber]; // An array of function pointer FH_PWMI_Init_FuncPtrModel
147 FH_PWMI_Init_S (FH_PWMI_Init_FuncPtr); // Setting the address of the functions
148
149 // 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) according to the first parameter of the Data in the message frame
150 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
151 fh_ErrorInfo = FH_PWMI_Init_C (fh_RFCommunication_Message, FH_PWMI_Init_FuncPtr); // Calling the related function according to the first parameter of the Data in the message frame
152 return fh_ErrorInfo;
153}
154
155/**
156 * @brief This function handles <b>FH_PWMI_Commands_GetStatus</b> command\n
157 * There are 3 main items handled in this function as following:\n
158 * 1 - Verifying the health of the received message\n
159 * 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) to an array of function pointer\n
160 * 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) according to the first parameter of the Data in the message frame
161 *
162 * @param fh_RFCommunication_Message
163 * The message frame set by <b>RobotFramework</b>
164 *
165 * @verbatim
166 ==============================================================================
167 ##### RobotFramework Example #####
168 ==============================================================================
169 @{MessageData} = Create List ${PWMI01}
170 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_PWMI} Command=${PWMI_Commands_GetStatus} Data=@{MessageData}
171 ${Result} SendMessage &{Message}
172
173 Comments:
174
175 PWMI01 => It indicates the PWM Input 01
176 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
177 Function_PWMI => It is the function in the message frame
178 PWMI_Commands_GetStatus => It is the command of the function in the message frame
179 @endverbatim
180 *
181 *
182 * @return FH_ErrorInfo is returned
183 *
184
185*/
187{
188 FH_ErrorInfo fh_ErrorInfo; // Error Information
189 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
190
191 // Item 1 - Verifying the health of the received message
192 fh_ErrorInfo = FH_PWMI_GetStatus_H(fh_RFCommunication_Message);
193 if (fh_ErrorInfo.error_code != FH_ERROR_OK) // Check if the message is healthy or not
194 {
195 return fh_ErrorInfo; // Return the error
196 }
197
198 // 2 - Setting the addresses of the functions in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) to an array of function pointer
199 FH_PWMI_GetStatus_FuncPtrModel FH_PWMI_GetStatus_FuncPtr[FH_PWMI_MaxPeripheralNumber]; // An array of function pointer FH_PWMI_GetStatus_FuncPtrModel
200 FH_PWMI_GetStatus_S (FH_PWMI_GetStatus_FuncPtr); // Setting the address of the functions
201
202 // 3 - Calling the related function in <b>FH_Functions</b>, Section <b>FH_PWMI</b> (PWM Input) according to the first parameter of the Data in the message frame
203 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
204 fh_ErrorInfo = FH_PWMI_GetStatus_C (fh_RFCommunication_Message, FH_PWMI_Frequency, FH_PWMI_DutyCycle , FH_PWMI_GetStatus_FuncPtr); // Calling the related function according to the first parameter of the Data in the message frame
205 return fh_ErrorInfo;
206}
207
208#endif