b8aef2f8cc9fa8e8a0819228599346f7fb97fab8
[apps/agl-service-unicens.git] / ucs2-lib / src / ucs_dec.c
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
4 /*                                                                                                */
5 /* This program is free software: you can redistribute it and/or modify                           */
6 /* it under the terms of the GNU General Public License as published by                           */
7 /* the Free Software Foundation, either version 2 of the License, or                              */
8 /* (at your option) any later version.                                                            */
9 /*                                                                                                */
10 /* This program is distributed in the hope that it will be useful,                                */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
13 /* GNU General Public License for more details.                                                   */
14 /*                                                                                                */
15 /* You should have received a copy of the GNU General Public License                              */
16 /* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22 /*!
23  * \file
24  * \brief Implementation of the Command Interpreter Module.
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup G_DEC_INT
28  * @{
29  */
30
31 /*------------------------------------------------------------------------------------------------*/
32 /* Includes                                                                                       */
33 /*------------------------------------------------------------------------------------------------*/
34 #include "ucs_dec.h"
35 #include "ucs_misc.h"
36 #include "ucs_ret_pb.h"
37
38 /*------------------------------------------------------------------------------------------------*/
39 /* Implementation                                                                                 */
40 /*------------------------------------------------------------------------------------------------*/
41 /*! \brief  Search in a FktOp table for matching FktID and OPType. This function is used for
42  *          incoming ICM messages.
43  *  \param   list            FktOp table
44  *  \param   index_ptr       Reference to array index of the matching array element
45  *  \param   function_id     FktID
46  *  \param   op_type         OPType
47  *  \return  DEC_RET_SUCCESS                 Decoding was successful
48  *           DEC_RET_FKTID_NOT_FOUND         FktID/OPType not found
49  */
50 Dec_Return_t Dec_SearchFktOpIcm(Dec_FktOpIcm_t const list[], uint16_t *index_ptr, 
51                                 uint16_t function_id, Ucs_OpType_t op_type)
52 {
53     uint16_t     fktop;
54     uint16_t     i       = 0U;
55     Dec_Return_t ret_val = DEC_RET_FKTID_NOT_FOUND;
56     bool         loop    = true;
57
58     fktop = DEC_FKTOP(function_id, op_type);
59     *index_ptr = 0U;
60
61     while ((list[i].handler_function_ptr != NULL)  && (loop != false))
62     {
63         if(list[i].fkt_op == fktop)
64         {
65             ret_val = DEC_RET_SUCCESS;
66             *index_ptr = i;
67             loop = false;
68         }
69         else if (list[i].fkt_op > fktop)
70         {
71             loop = false;
72         }
73         else
74         {
75             i++;
76         }
77     }
78
79     return ret_val;
80 }
81
82 /*! \brief  Search in a FktOp table for matching FktID and OPType. This function is used for
83  *          MCM messages coming from FBlocks inside the INIC.
84  *  \param   list            FktOp table
85  *  \param   index_ptr       Reference to array index of the matching array element
86  *  \param   function_id     FktID
87  *  \param   op_type         OPType
88  *  \return  DEC_RET_SUCCESS                 Decoding was successful
89  *           DEC_RET_FKTID_NOT_FOUND         FktID/OPType not found
90  */
91 Dec_Return_t Dec_SearchFktOpIsh(Dec_FktOpIsh_t const list[], uint16_t *index_ptr, 
92                                 uint16_t function_id, Ucs_OpType_t op_type)
93 {
94     uint16_t     fktop;
95     uint16_t     i       = 0U;
96     Dec_Return_t ret_val = DEC_RET_FKTID_NOT_FOUND;
97     bool         loop    = true;
98
99     fktop = DEC_FKTOP(function_id, op_type);
100     *index_ptr = 0U;
101
102     while ((list[i].handler_function_ptr != NULL)  && (loop != false))
103     {
104         if(list[i].fkt_op == fktop)
105         {
106             ret_val = DEC_RET_SUCCESS;
107             *index_ptr = i;
108             loop = false;
109         }
110         else if (list[i].fkt_op > fktop)
111         {
112             loop = false;
113         }
114         else
115         {
116             i++;
117         }
118     }
119
120     return ret_val;
121 }
122
123 /*!
124  * @}
125  * \endcond
126  */
127
128 /*------------------------------------------------------------------------------------------------*/
129 /* End of file                                                                                    */
130 /*------------------------------------------------------------------------------------------------*/
131