ccNOos  v0.0.0
Build Portable Microcontroller Applications!
HMR3300.c
Go to the documentation of this file.
1 /** \file HMR3300.c
2 * \brief <a href="https://www.inmechasol.org/" target="_blank">IMS</a>:
3  <a href="https://github.com/InMechaSol/ccNOos" target="_blank">ccNOos</a>,
4  Implementation for straight C
5 
6  Copyright 2021 <a href="https://www.inmechasol.org/" target="_blank">InMechaSol, Inc</a>
7 
8  Licensed under the Apache License, Version 2.0(the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 Notes:
21  (.c includes .h) - for straight C or
22  (.cpp includes .c which includes .h) - for C++ wrapped straight C
23  *Always compiled to a single compilation unit, either C or CPP, not both
24 
25 */
26 
27 #include "HMR3300.h"
28 
30 {
31  struct eCompDataStruct outStruct;
32  outStruct.pitch = 0;
33  outStruct.roll = 0;
34  outStruct.yaw = 0;
35  return outStruct;
36 }
37 
38 // when possible, simply return snprintf() from std lib
39 // if using in ccNOos and/or ccOS framework, no work to be done
40 // - these functions are defined by the platfrom specification
41 extern UI_8 ATO_F(const char* str, float* val);
42 
43 UI_8 tryParseEcompData(char* eCompStringin, struct eCompDataStruct* eCompDataPtr)
44 {
45  int commaIndex0 = 0;
46  int commaIndex1 = 0;
47 
48  // scan message for valid tokens
49  for (int i = 2; i < charBuffMax; i++)
50  {
51  // find all commas
52  if (eCompStringin[i] == ',')
53  {
54  if(commaIndex0==0)
55  commaIndex0 = i;
56  else if(commaIndex1==0)
57  commaIndex1 = i;
58  else
59  return ui8FALSE;
60  }
61 
62  // find carriage return
63  if (eCompStringin[i] == '\r')
64  {
65  if((commaIndex0>1) && (commaIndex1>(commaIndex0+1)) && (i > (commaIndex1+1)))
66  {
67  // yaw
68  eCompStringin[commaIndex0] = 0x00;
69  if (!ATO_F(&eCompStringin[0], &eCompDataPtr->yaw))
70  {
71  eCompStringin[commaIndex0] = ',';
72  return ui8FALSE;
73  }
74  // pitch
75  eCompStringin[commaIndex1] = 0x00;
76  if (!ATO_F(&eCompStringin[commaIndex0 + 1], &eCompDataPtr->pitch))
77  {
78  eCompStringin[commaIndex1] = ',';
79  return ui8FALSE;
80  }
81  // roll
82  eCompStringin[i] = 0x00;
83  if (!ATO_F(&eCompStringin[commaIndex1 + 1], &eCompDataPtr->roll))
84  {
85  eCompStringin[i] = '\r';
86  return ui8FALSE;
87  }
88  eCompStringin[commaIndex0] = ',';
89  eCompStringin[commaIndex1] = ',';
90  eCompStringin[i] = '\r';
91  return ui8TRUE;
92  }
93  }
94  }
95  return ui8FALSE;
96 
97 
98 }
tryParseEcompData
UI_8 tryParseEcompData(char *eCompStringin, struct eCompDataStruct *eCompDataPtr)
Definition: HMR3300.c:43
HMR3300.h
IMS: ccNOos, Declarations for straight C and C++
eCompDataStruct::roll
float roll
Definition: HMR3300.h:35
str
#define str(s)
Definition: version_config.h:51
eCompDataStruct::pitch
float pitch
Definition: HMR3300.h:35
eCompDataStruct
Definition: HMR3300.h:34
ui8FALSE
#define ui8FALSE
Definition: version_config.h:190
eCompDataStruct::yaw
float yaw
Definition: HMR3300.h:35
createEcompDataStruct
struct eCompDataStruct createEcompDataStruct()
Definition: HMR3300.c:29
ATO_F
UI_8 ATO_F(const char *str, float *val)
ui8TRUE
#define ui8TRUE
Definition: version_config.h:191
charBuffMax
#define charBuffMax
Definition: version_config.h:78