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  rlUInt8_t* payloadBuf;
189 
190  RL_LOGV_ARG0("rlGetSubBlock starts...\n");
191 
192  /* check for NULL prointer for all input parameters */
193  if ((RL_NULL_PTR == rhcpPayload) || (RL_NULL_PTR == sbcId) ||\
194  (RL_NULL_PTR == sbLen) || (RL_NULL_PTR == sbData))
195  {
196  /* set error code */
197  retVal = RL_RET_CODE_FATAL_ERROR;
198  }
199  else
200  {
201  /* Get SB Id */
202  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbId is of type UINT16,
203  * so pointer conversion type to UINT16*
204  * is required" */
205  /*LDRA_INSPECTED 94 S */
206  /*LDRA_INSPECTED 95 S */
207  /*LDRA_INSPECTED 87 S */
208  *sbcId = *((rlUInt16_t*)(rhcpPayload + RL_SBC_ID_INDEX));
209 
210  /* Get SB Len */
211  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbLen is of type UINT16,
212  * so pointer conversion type to UINT16*
213  * is required" */
214  /*LDRA_INSPECTED 94 S */
215  /*LDRA_INSPECTED 95 S */
216  /*LDRA_INSPECTED 87 S */
217  *sbLen = *((rlUInt16_t*)(rhcpPayload + RL_SBC_LEN_INDEX));
218  /* check if sub-block length is beyond defined limit */
219  if ((*sbLen > RL_CMD_PL_LEN_MAX))
220  {
221  /* set error code */
222  retVal = RL_RET_CODE_FATAL_ERROR;
223  }
224  else
225  {
226  payloadBuf = &rhcpPayload[RL_SBC_PL_INDEX];
227  /* Get SB Payload */
228  if ((*sbLen > 0U) && (RL_NULL_PTR != sbData) && \
229  (RL_NULL_PTR != payloadBuf))
230  {
231  /* copy input payload to sub-block data buffer */
232  (void)memcpy(sbData, payloadBuf, (*sbLen -
233  (RL_SBC_ID_SIZE + RL_SBC_LEN_SIZE)));
234  RL_LOGD_ARG0("rhcpPayload is copied\n");
235  }
236  retVal = RL_RET_CODE_OK;
237  }
238  }
239  RL_LOGV_ARG0("rlGetSubBlock ends...\n");
240  return retVal;
241 }
242 
253 /* DesignId : */
254 /* Requirements : */
255 void rlGetSubBlockId(const rlUInt8_t rhcpPayload[], rlUInt16_t* sbcId)
256 {
257  /* Get SB Id */
258  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbId is of type UINT16,
259  * so pointer conversion type to UINT16*
260  * is required" */
261  /*LDRA_INSPECTED 94 S */
262  /*LDRA_INSPECTED 95 S */
263  /*LDRA_INSPECTED 87 S */
264  *sbcId = *((rlUInt16_t*)(rhcpPayload + RL_SBC_ID_INDEX));
265  RL_LOGD_ARG0("DEBUG: Parsed sub block ID\n");
266 }
267 
278 /* DesignId : */
279 /* Requirements : */
280 void rlGetSubBlockLen(const rlUInt8_t rhcpPayload[], rlUInt16_t* sbcLen)
281 {
282  /* Get SB Len */
283  /*AR_CODE_REVIEW MR:R.11.2 <APPROVED> "The Payload SbLen is of type UINT16,
284  * so pointer conversion type to UINT16*
285  * is required" */
286  /*LDRA_INSPECTED 94 S */
287  /*LDRA_INSPECTED 95 S */
288  /*LDRA_INSPECTED 87 S */
289  *sbcLen = *((rlUInt16_t*)(rhcpPayload + RL_SBC_LEN_INDEX));
290  RL_LOGD_ARG0("DEBUG: Parsed sub block len\n");
291 }
292 /*
293  * END OF rl_controller.c FILE
294  */

Copyright 2021, Texas Instruments Incorporated