ccNOos  v0.0.0
Build Portable Microcontroller Applications!
Application_Solution.c
Go to the documentation of this file.
1 /** \file Application_Solution.c
2 * \brief Cross-Platform Portable ccNOos Tests Definitions
3 
4  Copyright 2021 InMechaSol, Inc
5 
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 
18 Notes:
19 
20 This source demonstrates the usage of the ccNOos library and its dependence
21 on other files in the library. A platform specific main(.c,.cpp) file need
22 only instantiate, configure, then execute the execution system.
23 
24 */
25 #include "Application_Solution.h"
26 
27 
28 // Re-usable, portable, cross-platform (ccNOosTests create() function)
30 {
31  MODdeclareSTRUCT(Mn) outStruct;
32  outStruct.compMod = CreateComputeModuleStruct();
33 
34  outStruct.float_0 = 0.0;
35  outStruct.float_1 = outStruct.float_0;
36  outStruct.double_0 = 0.0;
37  outStruct.double_1 = outStruct.double_0;
38 
39  outStruct.ui64_0 = 0.0;
40  outStruct.ui64_1 = outStruct.ui64_0;
41  outStruct.i64_0 = 0.0;
42  outStruct.i64_1 = outStruct.i64_0;
43 
44  outStruct.ui32_0 = 0.0;
45  outStruct.ui32_1 = outStruct.ui32_0;
46  outStruct.i32_0 = 0.0;
47  outStruct.i32_1 = outStruct.i32_0;
48 
49  outStruct.ui16_0 = 0.0;
50  outStruct.ui16_1 = outStruct.ui16_0;
51  outStruct.i16_0 = 0.0;
52  outStruct.i16_1 = outStruct.i16_0;
53 
54  outStruct.ui8_0 = 0.0;
55  outStruct.ui8_1 = outStruct.ui8_0;
56  outStruct.i8_0 = 0.0;
57  outStruct.i8_1 = outStruct.i8_0;
58 
59  outStruct.charsRead = 1u;
60  outStruct.chars2Write = 0u;
61 
62 #ifdef __USINGCONSOLEMENU
63  UI_8 i = 0;
64  for (i = 0; i < charBuffMax; i++)
65  outStruct.charbuff_In[i] = 0x00;
66  for (i = 0; i < charBuffMax; i++)
67  outStruct.charbuff_Out[i] = 0x00;
68 
69 #endif
70 
71  outStruct.SerializationTestReturn = RETURN_TEST_PASSED;
72  outStruct.TestState = 0x0000;
73 
74  return outStruct;
75 }
76 
77 
78 // Re-usable, portable, cross-platform (ccNOosTests setup() function)
80 {
82 
83  // Setup is running in the loop area to handle exceptions...
85  {
86  CLEAR_MODULE_ERRORS(Mn); // do nothing, clear flags
87  }
88  // Setup is running in the setup area following power on
89  else
90  {
91  UI_16 TestReturn = 0;
92  TestReturn = ExceptionsTest(MODdataPTR(Mn));
93  MODdataPTR(Mn)->ExceptionsTestReturn = TestReturn;
94 
95  // Basic Platfrom Serialization / Deserialization if Included
96 #ifdef __USINGCONSOLEMENU
97  TestReturn = SerializationTest(MODdataPTR(Mn));
98  MODdataPTR(Mn)->SerializationTestReturn = TestReturn;
99  MODdataPTR(Mn)->charbuff_In[0] = ';';
100  MODdataPTR(Mn)->ui16_0 = MODprintMENU(Mn)(compModPtrIn);
101  //MODdataPTR(Mn)->ui16_0 = MODparseINPUT(Mn)(compModPtrIn);
102 #endif
103 
104 // initialize values for timedexecutiontest in loop
105  MODdataPTR(Mn)->ui32_0 = 0;
106  MODdataPTR(Mn)->ui32_1 = 0;
107  MODdataPTR(Mn)->ui16_0 = 0;
108  MODdataPTR(Mn)->ui16_1 = 0;
109 
110 
111  }
112  return RETURN_SUCCESS;
113 }
114 
115 // Re-usable, portable, cross-platform (ccNOosTests loop() function)
117 {
119 
120  UI_16 TestReturn = 0;
121  switch (MODdataPTR(Mn)->TestState)
122  {
123  case 0x0000:// Timed Execution Loop Test
124  TestReturn = TimedExecutionTest(MODdataPTR(Mn));
125  MODdataPTR(Mn)->TimedExecutionTestReturn = TestReturn;
126  if (TestReturn != RETURN_TEST_IN_PROGRESS)
127  MODdataPTR(Mn)->TestState++;
128  break;
129  case 0x0001:// Exception Loop Test
130  TestReturn = ExceptionsTest(MODdataPTR(Mn));
131  MODdataPTR(Mn)->ExceptionsTestReturn = TestReturn;
132  if (TestReturn != RETURN_TEST_IN_PROGRESS)
133  MODdataPTR(Mn)->TestState++;
134  break;
135  default:// Done!!!
136  if (MODdataPTR(Mn)->SerializationTestReturn == RETURN_TEST_PASSED
137  && MODdataPTR(Mn)->TimedExecutionTestReturn == RETURN_TEST_PASSED
138  && MODdataPTR(Mn)->ExceptionsTestReturn == RETURN_TEST_PASSED)
139  MODdataPTR(Mn)->TestState = 0xffff;
140  else
141  MODdataPTR(Mn)->TestState = 0xfffe;
142  break;
143  case 0xfffe:// Done - Failed
144  case 0xffff:// Done - Passed
145 #ifdef __USINGCONSOLEMENU
146  MODdataPTR(Mn)->ui16_0 = MODprintMENU(Mn)(compModPtrIn);
147  MODdataPTR(Mn)->ui16_0 = MODparseINPUT(Mn)(compModPtrIn);
148 #endif
149  break;
150  }
151 
152 
153 
154  return RETURN_SUCCESS;
155 }
156 
157 MODdeclareSYSTICK(Mn) { ; } // do nothing in the systick area
158 
159 #ifdef __USINGCONSOLEMENU
160 
162 {
164 
165  INIT_MENU_VARS(charBuffMax, MODdataPTR(Mn)->charbuff_Out);
166  // looping and printing
167  // for looping...
168  int lines2Print = 1;
169  int linesPrinted = 0;
170  if (MODdataPTR(Mn)->charbuff_In[0] != 0x00 > 0)
171  {
172  MODdataPTR(Mn)->charsRead = 0;
173  while (lines2Print > 0)
174  {
175  switch (linesPrinted)
176  {
177  case 0:
178  PRINT_MENU_LN "\033[2J\033[0;0H\n// Version %s %s //", ccNOosccNOos_VerString(), ccNOosccNOos_VerDateString() END_MENU_LN;
179  //PRINT_MENU_LN "\n///////// Console Menu - ccNOos Tests /////////" END_MENU_LN;
180  case 1:
181  PRINT_MENU_LN "\nStatus-ccNOos Tests:\t\t%s", StatusccNOosTests(MODdataPTR(Mn)) END_MENU_LN;
182  case 2:
183  PRINT_MENU_LN "\nResults-Serialization Tests:\t%s", ResultsSerializationTests(MODdataPTR(Mn)) END_MENU_LN;
184  case 3:
185  PRINT_MENU_LN "\nResults-Timed Execution Tests:\t%s", ResultsTimedExecutionTests(MODdataPTR(Mn)) END_MENU_LN;
186  case 4:
187  PRINT_MENU_LN "\n///////////////////////////////////////////////" END_MENU_LN;
188  case 5:
189  PRINT_MENU_LN "\nType \"ccNOosTests:Var:Val;\" set Var to Val" END_MENU_LN;
190  case 6:
191  PRINT_MENU_LN "\nInput>>" END_MENU_LN;
192  default:
193  lines2Print = 0;
194  break;
195  }
196 
197  MODdataPTR(Mn)->chars2Write = charsWritten;
198  linesPrinted++;
199 
200  if (lines2Print > 0)
201  WriteMenuLine(&MODdataPTR(Mn)->charbuff_Out[0]);
202  }
203  }
204  return charsWritten;
205 }
206 
208 {
210 
211  // loop characters from user input
212  int i = 0;
213  int j = 0, k = 0, l = 0;
214 
215  GetMenuChars(&MODdataPTR(Mn)->charbuff_In[0]);
216  if (MODdataPTR(Mn)->charbuff_In[0] != 0x00)
217  {
218  MODdataPTR(Mn)->charsRead++;
219 #define thisC MODdataPTR(Mn)->charbuff_In[i]
220 
221  while ((thisC != 0x00) && (i < charBuffMax))
222  {
223  // find delimeter or terminator
224  if (thisC == ASCII_colon)
225  {
226  if (j == 0)
227  j = i;
228  else
229  k = i;
230  }
231  else if (thisC == ASCII_semicolon)
232  {
233  if (j == 0 || k == 0 || j >= k)
234  return 0u;
235 
236  // j index of first :
237  // k index of second :
238  // i index of terminator ;
239 
240  MODdataPTR(Mn)->charbuff_In[j] = 0x00;
241  if (stringMatchCaseSensitive(&MODdataPTR(Mn)->charbuff_In[0], "ccNOosTests"))
242  {
243  MODdataPTR(Mn)->charbuff_In[k] = 0x00;
244  if (stringMatchCaseSensitive(&MODdataPTR(Mn)->charbuff_In[j + 1], "Tx"))
245  {
246  l = 0;
247  }
248  else if (stringMatchCaseSensitive(&MODdataPTR(Mn)->charbuff_In[j + 1], "Rx"))
249  {
250  l = 1;
251  }
252  else if (stringMatchCaseSensitive(&MODdataPTR(Mn)->charbuff_In[j + 1], "Xx"))
253  {
254  l = 2;
255  }
256  else
257  return 0u;
258 
259  thisC = 0x00;
260  // if (ATO_F(&MODdataPTR(Mn)->charbuff_In[k + 1], &MODdataPTR(Mn)->AttenuatorValues[l]))
261  // {
262  // // limit command within range
263  // limitDATcmd(&MODdataPTR(Mn)->AttenuatorValues[l]);
264  // // set flag to update
265  // MODdataPTR(Mn)->AttenuatorNeedsWriting[l] = ui8TRUE;
266  // }
267 
268  }
269  else
270  return 0u;
271  }
272  i++;
273  }
274  }
275 #undef thisC
276  return i;
277 }
278 const char* ResultsTimedExecutionTests(MODdeclarePTRIN(Mn))
279 {
280  if (MODdataPTR(Mn)->TimedExecutionTestReturn == RETURN_TEST_PASSED)
281  return "Passed!";
282  else if (MODdataPTR(Mn)->TimedExecutionTestReturn == RETURN_TEST_IN_PROGRESS)
283  return "Running...";
284  else
285  return "Failed";
286 }
287 const char* StatusccNOosTests(MODdeclarePTRIN(Mn))
288 {
289  if (MODdataPTR(Mn)->TestState == 0x0000)
290  return "Not Running";
291  else if (MODdataPTR(Mn)->TestState == 0xffff)
292  return "Passed!";
293  else if (MODdataPTR(Mn)->TestState == 0xfffe)
294  return "Failed - :(";
295  else
296  return "Running...";
297 }
298 const char* ResultsSerializationTests(MODdeclarePTRIN(Mn))
299 {
300  if (MODdataPTR(Mn)->SerializationTestReturn == RETURN_TEST_PASSED)
301  return "Passed!";
302  else if (MODdataPTR(Mn)->SerializationTestReturn == RETURN_FAILED_SERIALIZATION)
303  return "Failed - Serialization";
304  else if (MODdataPTR(Mn)->SerializationTestReturn == RETURN_FAILED_DESERIALIZATION)
305  return "Failed - Deserialization";
306  else if (MODdataPTR(Mn)->SerializationTestReturn == RETURN_FAILED_COMPARISON)
307  return "Failed - Comparison";
308  else
309  return "Status - Unknown";
310 }
311 UI_16 SerializationTest(MODdeclarePTRIN(Mn))
312 {
313  int bytesWritten = 0;
314  UI_8 parseResults = 0;
315 
316 #define DeserializeOnlyPattern(VAR, VAL, FORMAT, LEN, FUNC) stringInit(MODdataPTR(Mn)->charbuff_In, xstr(VAL));\
317  parseResults = FUNC(MODdataPTR(Mn)->charbuff_In, &MODdataPTR(Mn)->VAR##1 );\
318  if(parseResults != ui8TRUE)\
319  return RETURN_FAILED_DESERIALIZATION
320 
321 #define SerializeTestPattern(VAR, VAL, FORMAT, LEN, FUNC) MODdataPTR(Mn)->VAR##0 = VAL;\
322  bytesWritten = SN_PrintF(MODdataPTR(Mn)->charbuff_Out,LEN,FORMAT,MODdataPTR(Mn)->VAR##0);\
323  if( bytesWritten != LEN || \
324  ui8TRUE!=stringMatchCaseSensitive(MODdataPTR(Mn)->charbuff_Out,xstr(VAL))\
325  ){\
326  return RETURN_FAILED_SERIALIZATION;}\
327  DeserializeOnlyPattern(VAR, VAL, FORMAT, LEN, FUNC);\
328  if(MODdataPTR(Mn)->VAR##0 != MODdataPTR(Mn)->VAR##1)\
329  return RETURN_FAILED_COMPARISON;
330 
331  // These lines can be useful when setting up a new platform
332  // to determine which serialization operation is failing
333  // place this code within the failed_serialization conditional
334  // of the SerializeTestPattern Macro...
335  //WriteMenuLine((char*)"\n\nFailed "); \
336  //WriteMenuLine((char*)xstr(VAR)); \
337  //WriteMenuLine((char*)", "); \
338  //WriteMenuLine((char*)xstr(VAL)); \
339  //WriteMenuLine((char*)", "); \
340  //WriteMenuLine((char*)xstr(FORMAT)); \
341  //WriteMenuLine((char*)", "); \
342  //WriteMenuLine((char*)xstr(LEN)); \
343  //WriteMenuLine((char*)", "); \
344  //WriteMenuLine(MODdataPTR(Mn)->charbuff_Out); \
345  //WriteMenuLine((char*)"\n"); \
346 
347 
348 
349  SerializeTestPattern(ui16_, 65535, "%u", 5, ATO_U16);
350  SerializeTestPattern(i16_, -32767, "%i", 6, ATO_I16);
351 
352  SerializeTestPattern(ui8_, 255, "%u", 3, ATO_U8);
353  SerializeTestPattern(i8_, 127, "%i", 3, ATO_I8);
354 
355  SerializeTestPattern(ui32_, 65535, "%u", 5, ATO_U32);
356  SerializeTestPattern(i32_, -32767, "%d", 6, ATO_I32);
357 
358  SerializeTestPattern(ui64_, 65535, "%u", 5, ATO_U64);
359  SerializeTestPattern(i64_, -32767, "%d", 6, ATO_I64);
360 
361 #ifdef __USINGFLOATPRINTF
362  SerializeTestPattern(double_, 3.1457, "%6.4f", 6, ATO_D);
363  SerializeTestPattern(float_, -3.1457, "%6.4f", 7, ATO_F);
364 #else
365  DeserializeOnlyPattern(double_, 3.1457, "%6.4f", 6, ATO_D);
366  DeserializeOnlyPattern(float_, -3.1457, "%6.4f", 7, ATO_F);
367 #endif
368 
369  return RETURN_TEST_PASSED;
370 
371 #undef DeserializeOnlyPattern
372 #undef SerializeTestPattern
373 }
374 #endif // !__USINGCONSOLEMENU
375 
377 {
378 #define uSNOW MODdataPTR(Mn)->ui32_0
379 #define uSTHEN MODdataPTR(Mn)->ui32_1
380 #define LOOPCYCLES MODdataPTR(Mn)->ui16_0
381 
382  uSNOW = getuSecTicks();
383 
384  if (++LOOPCYCLES == 0)
386  else if (LOOPCYCLES == 1)
387  uSTHEN = getuSecTicks();
388 
389  if ((uSNOW - uSTHEN) >= getuSecPerSysTick())
390  {
391  LOOPCYCLES = 0;
392  return RETURN_TEST_PASSED;
393  }
394  else
395  {
397  }
398 
399 #undef uSNOW
400 #undef uSTHEN
401 #undef LOOPCYCLES
402 }
404 {
405 
406  return RETURN_TEST_PASSED;
407 }
408 
TimedExecutionTest
UI_16 TimedExecutionTest(MODdeclarePTRIN(Mn))
Definition: Application_Solution.c:376
ccNOosccNOos_VerString
const char * ccNOosccNOos_VerString()
GetMenuChars
void GetMenuChars(struct uiStruct *uiStructPtrin)
Definition: Application_Platform_Main.c:111
LOOPCYCLES
#define LOOPCYCLES
RETURN_FAILED_COMPARISON
#define RETURN_FAILED_COMPARISON
Definition: Application_Solution.h:80
Mn
MODdeclareCREATE() Mn(MODdeclareCREATEINS)
Definition: Application_Solution.c:29
MODdeclarePTRIN
#define MODdeclarePTRIN(mNAME)
Definition: version_config.h:284
CLEAR_MODULE_ERRORS
#define CLEAR_MODULE_ERRORS(mNAME)
Definition: version_config.h:339
MODprintMENU
#define MODprintMENU(mNAME)
Definition: version_config.h:260
MODDATAPTR_ERROR_RETURN
#define MODDATAPTR_ERROR_RETURN(mNAME)
Definition: version_config.h:331
MODdeclarePRINTm
MODdeclarePRINTm(Mn)
Definition: Application_Solution.c:109
MODdeclareLOOP
MODdeclareLOOP(Mn)
Definition: Application_Solution.c:116
getuSecTicks
UI_32 getuSecTicks()
MODdeclarePARSEi
MODdeclarePARSEi(Mn)
Definition: Application_Solution.c:161
MODdeclareCREATEINS
#define MODdeclareCREATEINS
Definition: Application_Solution.h:58
IF_MODULE_ERROR
#define IF_MODULE_ERROR(mNAME)
Definition: version_config.h:335
WriteMenuLine
void WriteMenuLine(struct uiStruct *uiStructPtrin)
Definition: Application_Platform_Main.c:144
MODparseINPUT
#define MODparseINPUT(mNAME)
Definition: version_config.h:264
ATO_F
UI_8 ATO_F(const char *str, float *val)
MODdeclareSYSTICK
MODdeclareSYSTICK(Mn)
Definition: Application_Solution.c:157
uSNOW
#define uSNOW
ExceptionsTest
UI_16 ExceptionsTest(MODdeclarePTRIN(Mn))
Definition: Application_Solution.c:403
uSTHEN
#define uSTHEN
getuSecPerSysTick
UI_32 getuSecPerSysTick()
MODdeclareCREATE
#define MODdeclareCREATE(mNAME)
Definition: version_config.h:292
charBuffMax
#define charBuffMax
Definition: version_config.h:78
MODdeclareSTRUCT
#define MODdeclareSTRUCT(mNAME)
Definition: version_config.h:277
MODdataPTR
#define MODdataPTR(mNAME)
Definition: version_config.h:244
RETURN_FAILED_SERIALIZATION
#define RETURN_FAILED_SERIALIZATION
Definition: Application_Solution.h:78
RETURN_TEST_IN_PROGRESS
#define RETURN_TEST_IN_PROGRESS
Definition: Application_Solution.h:76
ccNOosccNOos_VerDateString
const char * ccNOosccNOos_VerDateString()
MODdeclareSETUP
MODdeclareSETUP(Mn)
Definition: Application_Solution.c:79
RETURN_TEST_PASSED
#define RETURN_TEST_PASSED
Definition: Application_Solution.h:75
RETURN_FAILED_TIMEDEXECUTION
#define RETURN_FAILED_TIMEDEXECUTION
Definition: Application_Solution.h:77
Application_Solution.h
CreateComputeModuleStruct
struct computeModuleStruct CreateComputeModuleStruct()
Definition: compute_module.c:30
RETURN_SUCCESS
#define RETURN_SUCCESS
Function Return Value for Success.
Definition: version_config.h:87
RETURN_FAILED_DESERIALIZATION
#define RETURN_FAILED_DESERIALIZATION
Definition: Application_Solution.h:79