rl_controller.c
1 /****************************************************************************************
2  * FileName : rl_controller.c
3  *
4  * Description : This file defines the functions to construct Radar Messages.
5  *
6  ****************************************************************************************
7  * (C) Copyright 2014, Texas Instruments Incorporated. - TI web address www.ti.com
8  *---------------------------------------------------------------------------------------
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * Neither the name of Texas Instruments Incorporated nor the names of its
21  * contributors may be used to endorse or promote products derived from this
22  * software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37  /*
38  ****************************************************************************************
39  * Revision History :
40  *---------------------------------------------------------------------------------------
41  * Version Date Author Defect No Description
42  *---------------------------------------------------------------------------------------
43  * 0.1.0 12May2015 Kaushal Kukkar Initial Version
44  *
45  * 0.6.0 15Nov2016 Kaushal Kukkar AUTORADAR-666 Logging Feature
46  *
47  * 0.9.1 Jitendra Gupta MMWL-5 Code size optimization
48  ****************************************************************************************
49  */
50 
51 /******************************************************************************
52  * INCLUDE FILES
53  ******************************************************************************
54  */
55 #include <stdlib.h>
56 #include <string.h>
57 #include <ti/control/mmwavelink/include/rl_datatypes.h>
58 #include <ti/control/mmwavelink/include/rl_controller.h>
59 #include <ti/control/mmwavelink/include/rl_driver.h>
60 #include <ti/control/mmwavelink/include/rl_trace.h>
61 
62 /******************************************************************************
63  * GLOBAL VARIABLES/DATA-TYPES DEFINITIONS
64  ******************************************************************************
65  */
66 
67 /******************************************************************************
68  * FUNCTION DEFINITIONS
69  ******************************************************************************
70  */
71 
85 /* DesignId : */
86 /* Requirements : AUTORADAR_REQ-772 */
87 rlReturnVal_t rlAppendSubBlock(rlUInt8_t rhcpPayload[],
88  rlUInt16_t sblkId, rlUInt16_t sbLen, rlUInt8_t* sbData)
89 {
90  rlReturnVal_t retVal;
91  /* check for null pointer */
92  if ((RL_NULL_PTR == rhcpPayload) || (sbLen > RL_CMD_PL_LEN_MAX))
93  {
94  /* set error code */
95  retVal = RL_RET_CODE_FATAL_ERROR;
96  }
97  else
98  {
99  /* Append SB Id */
100  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbId is of type UINT16,
101  * so pointer conversion type to UINT16*
102  * is required" */
103  /*LDRA_INSPECTED 94 S */
104  /*LDRA_INSPECTED 95 S */
105  /*LDRA_INSPECTED 87 S */
106  *((rlUInt16_t*)(rhcpPayload + RL_SBC_ID_INDEX)) = sblkId;
107 
108  /* Append SB Len */
109  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbLen is of type UINT16,
110  * so pointer conversion type to UINT16*
111  * is required" */
112  /*LDRA_INSPECTED 94 S */
113  /*LDRA_INSPECTED 95 S */
114  /*LDRA_INSPECTED 87 S */
115  *((rlUInt16_t*)(rhcpPayload + RL_SBC_LEN_INDEX)) = sbLen + \
116  RL_SBC_ID_SIZE + RL_SBC_LEN_SIZE;
117 
118  /* Append SB Payload */
119  if ((sbLen > 0U) && (RL_NULL_PTR != sbData))
120  {
121  (void)memcpy(&rhcpPayload[RL_SBC_PL_INDEX], sbData, sbLen);
122  retVal = RL_RET_CODE_OK;
123  }
124  else
125  {
126  /* For most of get command sub-block length is zero and sbData is NULL */
127  if ((sbLen == 0U) && (RL_NULL_PTR == sbData))
128  {
129  retVal = RL_RET_CODE_OK;
130  }
131  else
132  {
133  retVal = RL_RET_CODE_INVALID_INPUT;
134  }
135  }
136  }
137  return retVal;
138 }
139 
150 /* DesignId : */
151 /* Requirements : */
152 rlReturnVal_t rlAppendDummy(rlUInt8_t rhcpPayload[], rlUInt8_t dummyLen)
153 {
154  rlUInt8_t indx;
155 
156  RL_LOGV_ARG0("rlAppendDummy starts...\n");
157 
158  /* In the given array fill dummy byte for the requested length */
159  for (indx = 0U; indx < dummyLen; indx++)
160  {
161  /* fill dummy byte */
162  rhcpPayload[indx] = RL_PROTOCOL_DUMMY_BYTE;
163  }
164  RL_LOGV_ARG0("rlAppendDummy ends...\n");
165 
166  return RL_RET_CODE_OK;
167 }
168 
182 /* DesignId : */
183 /* Requirements : */
184 rlReturnVal_t rlGetSubBlock(rlUInt8_t rhcpPayload[],
185  rlUInt16_t* sbcId, rlUInt16_t* sbLen, rlUInt8_t* sbData)
186 {
187  rlReturnVal_t retVal;
188 
189  RL_LOGV_ARG0("rlGetSubBlock starts...\n");
190 
191  /* check for NULL prointer for all input parameters */
192  if ((RL_NULL_PTR == rhcpPayload) || (RL_NULL_PTR == sbcId) ||\
193  (RL_NULL_PTR == sbLen) || (RL_NULL_PTR == sbData))
194  {
195  /* set error code */
196  retVal = RL_RET_CODE_FATAL_ERROR;
197  }
198  else
199  {
200  /* Get SB Id */
201  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbId is of type UINT16,
202  * so pointer conversion type to UINT16*
203  * is required" */
204  /*LDRA_INSPECTED 94 S */
205  /*LDRA_INSPECTED 95 S */
206  /*LDRA_INSPECTED 87 S */
207  *sbcId = *((rlUInt16_t*)(rhcpPayload + RL_SBC_ID_INDEX));
208 
209  /* Get SB Len */
210  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbLen is of type UINT16,
211  * so pointer conversion type to UINT16*
212  * is required" */
213  /*LDRA_INSPECTED 94 S */
214  /*LDRA_INSPECTED 95 S */
215  /*LDRA_INSPECTED 87 S */
216  *sbLen = *((rlUInt16_t*)(rhcpPayload + RL_SBC_LEN_INDEX));
217  /* check if sub-block length is beyond defined limit */
218  if ((*sbLen > RL_CMD_PL_LEN_MAX))
219  {
220  /* set error code */
221  retVal = RL_RET_CODE_FATAL_ERROR;
222  }
223  else
224  {
225  /* Get SB Payload */
226  if ((*sbLen > 0U) && (RL_NULL_PTR != sbData))
227  {
228  /* copy input payload to sub-block data buffer */
229  (void)memcpy(sbData, &rhcpPayload[RL_SBC_PL_INDEX], (*sbLen -
230  (RL_SBC_ID_SIZE + RL_SBC_LEN_SIZE)));
231  RL_LOGD_ARG0("rhcpPayload is copied\n");
232  }
233  retVal = RL_RET_CODE_OK;
234  }
235  }
236  RL_LOGV_ARG0("rlGetSubBlock ends...\n");
237  return retVal;
238 }
239 
250 /* DesignId : */
251 /* Requirements : */
252 void rlGetSubBlockId(const rlUInt8_t rhcpPayload[], rlUInt16_t* sbcId)
253 {
254  /* Get SB Id */
255  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbId is of type UINT16,
256  * so pointer conversion type to UINT16*
257  * is required" */
258  /*LDRA_INSPECTED 94 S */
259  /*LDRA_INSPECTED 95 S */
260  /*LDRA_INSPECTED 87 S */
261  *sbcId = *((rlUInt16_t*)(rhcpPayload + RL_SBC_ID_INDEX));
262  RL_LOGD_ARG0("DEBUG: Parsed sub block ID\n");
263 }
264 
275 /* DesignId : */
276 /* Requirements : */
277 void rlGetSubBlockLen(const rlUInt8_t rhcpPayload[], rlUInt16_t* sbcLen)
278 {
279  /* Get SB Len */
280  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbLen is of type UINT16,
281  * so pointer conversion type to UINT16*
282  * is required" */
283  /*LDRA_INSPECTED 94 S */
284  /*LDRA_INSPECTED 95 S */
285  /*LDRA_INSPECTED 87 S */
286  *sbcLen = *((rlUInt16_t*)(rhcpPayload + RL_SBC_LEN_INDEX));
287  RL_LOGD_ARG0("DEBUG: Parsed sub block len\n");
288 }
289 /*
290  * END OF rl_controller.c FILE
291  */

Copyright 2018, Texas Instruments Incorporated