FreeHIL
Loading...
Searching...
No Matches
FH_UART_ReceiveW_H.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_UART</b>, <b>Cmd</b> (Command), <b>ReceiveW</b>, <b>ReceiveW_H</b> (ReceiveW Health)\n
6 * Functions in this file, verify the health of the different message frames related to <b>UART</b>
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 ------------------------------------------------------------------*/
34#include "../../../../../../../FH_Embedded/FH_Root/FH_Perif/FH_UART/Cmd/ReceiveW/ReceiveW_H/FH_UART_ReceiveW_H.h"
35
36#include "../../../../../../../FH_Embedded/FH_Root/FH_General/FH_GeneralFunctions/FH_GeneralFunctions.h"
38
39#if FH_UART_MaxPeripheralNumber > 0 // It is configurable in FH_DevicePeripherals.h
40
41/**
42 * @brief This function verifies the health of <b>FH_UART_Commands_ReceiveW</b> command
43 *
44 * @param fh_RFCommunication_Message
45 * The message frame set by <b>RobotFramework</b>
46 *
47 * @verbatim
48 ==============================================================================
49 ##### RobotFramework Example #####
50 ==============================================================================
51 @{MessageData} = Create List ${UART01} 05 00 00 0B B8
52 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_UART} Command=${UART_Commands_ReceiveW} Data=@{MessageData}
53 ${Result} SendMessage &{Message}
54
55 Comments:
56
57 UART01 => It indicates the UART 01
58 05 => The expected number of bytes of data to be received through the <b>ISR</b> (Interrupt Service Routine) receive buffer (FH_UART01_ReceiveBuf) of the <b>UART 01</b>
59 00 00 0B B8 => Example data (0x00000BB8 mili-seconds) as timeout of receiving the expected number of bytes
60 FH_GlobalTimeCounter which is a global variable is utilized to calculate the timeout
61 FH_GlobalTimeCounter shall be incremented every <b>1 mili-second</b> in an interested timer <b>ISR</b> (Interrupt Service Routine) by <b>FH</b> user
62 For this to happen, <b>FH_GlobalTimerCount.h</b> shall be included in the interested timer <b>ISR</b> (Interrupt Service Routine) file
63 If the expected number of bytes are received, the function does not wait anymore for the remaining time of the timeout
64 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
65 Function_UART => It is the function in the message frame
66 UART_Commands_ReceiveW => It is the command of the function in the message frame
67 @endverbatim
68 *
69 * @return FH_ErrorInfo is returned
70 *
71
72*/
74{
75 FH_ErrorInfo fh_ErrorInfo; // Error Information
76 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
77
78 uint8_t FH_MessageDataLength; // It temporarily stores the DataLength in the message frame
79 uint8_t FH_PeripheralNumber; // It temporarily stores the PeripheralNumber (Data[0]) in the message frame
80 uint32_t FH_MaxTimerCount; // It temporarily stores the MaxTimerCount (Data[2]-Data[5]) in the message frame
81
82 // Verifying the minimum possible length in the message frame
83 FH_MessageDataLength = fh_RFCommunication_Message -> DataLength;
84 if (FH_MessageDataLength < FH_UART_MinCommandSize_ReceiveW) // If the length is less than expected value
85 {
86 fh_ErrorInfo.error_code = FH_ERROR_MessageFrame; // There is message frame error
87 return fh_ErrorInfo;
88 }
89
90 // Verifying the possible PeripheralNumber in the message frame
91 FH_PeripheralNumber = fh_RFCommunication_Message -> Data[UART_ReceiveW_PeripheralNumber] ;
92 if (FH_PeripheralNumber == 0 || FH_PeripheralNumber > FH_UART_MaxPeripheralNumber) // If the PeripheralNumber is not within the expected value
93 {
94 fh_ErrorInfo.error_code = FH_ERROR_MessageFrame; // There is message frame error
95 return fh_ErrorInfo;
96 }
97
98 // Verifying the possible MaxTimerCount in the message frame
100 if (FH_MaxTimerCount == 0)
101 {
102 fh_ErrorInfo.error_code = FH_ERROR_MessageFrame; // There is message frame error
103 return fh_ErrorInfo;
104 }
105
106 fh_ErrorInfo.error_code = FH_ERROR_OK; // There is no error
107 return fh_ErrorInfo;
108}
109
110#endif