X-CUBE-SPN11 for X-NUCLEO-IHM11M1: UART_UI.c Source File

X-CUBE-SPN11 for X-NUCLEO-IHM11M1

UART_UI.c
Go to the documentation of this file.
1 /**
2  ******************************************************************************
3  * @file UART_UI.c
4  * @author IPC
5  * @version V0
6  * @date 10/07/2016
7  * @brief This file provides a set of functions needed to manage the UART com.
8  ******************************************************************************
9  * @attention
10  *
11  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
12  *
13  * Redistribution and use in source and binary forms, with or without modification,
14  * are permitted provided that the following conditions are met:
15  * 1. Redistributions of source code must retain the above copyright notice,
16  * this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  * 3. Neither the name of STMicroelectronics nor the names of its contributors
21  * may be used to endorse or promote products derived from this software
22  * 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, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************
36  */
37 
38 /* Includes ------------------------------------------------------------------*/
39 #include "UART_UI.h"
40 
41 #ifdef UART_COMM
42 
43 extern SIXSTEP_Base_InitTypeDef SIXSTEP_parameters; /*!< Main SixStep structure*/
44 extern SIXSTEP_PI_PARAM_InitTypeDef_t PI_parameters; /*!< SixStep PI regulator structure*/
45 extern uint8_t Enable_start_button;
46 extern void CMD_Parser(char* pCommandString);
48 
49 static uint16_t Uart_cmd_flag = 0;
50 const CMD_T CmdTable[] = {
51  {"STARTM", CMD_STARTM},
52  {"STOPMT", CMD_STOPMT},
53  {"DIRECT", CMD_DIRECTION},
54  {"SETSPD", CMD_SETSPD},
55  {"STATUS", CMD_STATUS},
56  {"GETSPD", CMD_GETSPD},
57  {"POTENZ", CMD_POTENZ},
58  {"INIREF", CMD_INIREF},
59  {"POLESP", CMD_POLESP},
60  {"ACCELE", CMD_ACCELE},
61  {"KP-PRM", CMD_KP_PRM},
62  {"KI-PRM", CMD_KI_PRM},
63  {"HELP", CMD_HELP},
64  {"", NULL}
65 };
66 
67 uint8_t BUFF_RCV = RXBUFFERSIZE;
68 uint8_t aRxBuffer[8] = {'0'}; /*!< Buffer used for reception */
69 uint8_t row0TxBuffer[] = "\033[2J"; /*!< Buffer used for transmission */
70 uint8_t row1TxBuffer[] = "*******************************************************************************\n\r";
71 uint8_t row2TxBuffer[] = "* X-NUCLEO-IHM11M1 - 6-Step Motor Control Expansion board *\n\r";
72 uint8_t row3TxBuffer[] = "*******************************************************************************\n\r";
73 uint8_t row4TxBuffer[] = " List of commands:\n\r\n\r";
74 uint8_t row5TxBuffer[] = " <STARTM> -- Start Motor\n\r";
75 uint8_t row6TxBuffer[] = " <STOPMT> -- Stop Motor\n\r";
76 uint8_t row7aTxBuffer[] = " <DIRECT> -- Set the Motor direction CW or CCW \n\r";
77 uint8_t row7TxBuffer[] = " <SETSPD> -- Set the Motor Speed\n\r";
78 uint8_t row7bTxBuffer[] = " <GETSPD> -- Get the Motor Speed\n\r";
79 uint8_t row7cTxBuffer[] = " <STATUS> -- Get the Status of system \n\r";
80 uint8_t row71TxBuffer[] = " <POTENZ> -- Enable/Disable the potentiometer\n\r";
81 uint8_t row71bTxBuffer[] = " <HELP> -- Show the help menu \n\r";
82 uint8_t rowVTxBuffer[] = " >>> Insert the value: ";
83 uint8_t rowVTBxBuffer[] = " >>> ENABLE <1> DISABLE <0>: ";
84 uint8_t rowV1TBxBuffer[] = " >>> CW <0> CCW <1>: ";
85 uint8_t rowMxBuffer[] = " >>> START MOTOR COMMAND RECEIVED ! <<< \n\r >";
86 uint8_t rowSxBuffer[] = " >>> STOP MOTOR COMMAND RECEIVED ! <<< \n\r >";
87 uint8_t rowETxBuffer[] = " >>> ERROR - PLEASE TYPE AGAIN ! <<< \n\r >";
88 uint8_t row8TxBuffer[] = " ************* MAIN MOTOR PARAMETERS *************** \n\r";
89 uint8_t row9TxBuffer[] = " <INIREF> -- Start-up current reference (0-4095) \n\r";
90 uint8_t row10TxBuffer[] = " <ACCELE> -- Motor acceleration value during startup \n\r";
91 uint8_t row11TxBuffer[] = " <POLESP> -- Set the Motor pole pairs \n\r";
92 uint8_t row14TxBuffer[] = " ****** PI REGULATOR PARAMETERS - SPEED LOOP ******\n\r";
93 uint8_t row15TxBuffer[] = " <KP-PRM> -- Set the PI proportional term \n\r";
94 uint8_t row16TxBuffer[] = " <KI-PRM> -- Set the PI integral term \n\r\n\r >";
95 uint8_t rowLxBuffer[] = " --- OK ---\n\r >";
96 extern uint8_t UART_FLAG_RECEIVE;
97 extern uint8_t UART_FLAG_POTENZ;
98 
99 
100 /** @addtogroup MIDDLEWARES MIDDLEWARES
101  * @brief Middlewares Layer
102  * @{
103  */
104 
105 
106 /** @addtogroup UART_UI UART_UI
107  * @brief Serial communication through PC serial terminal
108  * @{
109  */
110 
111 
112 /** @defgroup UART_Communication_Task UART_Communication_Task
113  * @{
114  * @brief UART start receive function
115 */
117 {
118  if(HAL_UART_Receive_IT(&huart2, (uint8_t *)aRxBuffer, 10) != HAL_OK)
119  { huart2.State = HAL_UART_STATE_READY; }
120  else UART_FLAG_RECEIVE = FALSE;
121 }
122 /**
123  * @}
124  */
125 
126 /** @defgroup MC_UI_INIT MC_UI_INIT
127  * @{
128  * @brief UART User Interface init
129 */
130  void MC_UI_INIT()
131  {
132  HAL_UART_Transmit(&huart2, (uint8_t *)row0TxBuffer, (COUNTOF(row0TxBuffer) - 1),5000);
133  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
134  {
135  }
136  HAL_UART_Transmit(&huart2, (uint8_t *)row1TxBuffer, (COUNTOF(row1TxBuffer) - 1),5000);
137  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
138  {
139  }
140  HAL_UART_Transmit(&huart2, (uint8_t *)row2TxBuffer, (COUNTOF(row2TxBuffer) - 1),5000);
141  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
142  {
143  }
144  HAL_UART_Transmit(&huart2, (uint8_t *)row3TxBuffer, (COUNTOF(row3TxBuffer) - 1),5000);
145  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
146  {
147  }
148  HAL_UART_Transmit(&huart2, (uint8_t *)row4TxBuffer, (COUNTOF(row4TxBuffer) - 1),5000);
149  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
150  {
151  }
152  HAL_UART_Transmit(&huart2, (uint8_t *)row5TxBuffer, (COUNTOF(row5TxBuffer) - 1),5000);
153  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
154  {
155  }
156  HAL_UART_Transmit(&huart2, (uint8_t *)row6TxBuffer, (COUNTOF(row6TxBuffer) - 1),5000);
157  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
158  {
159  }
160  HAL_UART_Transmit(&huart2, (uint8_t *)row7aTxBuffer, (COUNTOF(row7aTxBuffer) - 1),5000);
161  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
162  {
163  }
164  HAL_UART_Transmit(&huart2, (uint8_t *)row7TxBuffer, (COUNTOF(row7TxBuffer) - 1),5000);
165  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
166  {
167  }
168  HAL_UART_Transmit(&huart2, (uint8_t *)row7bTxBuffer, (COUNTOF(row7bTxBuffer) - 1),5000);
169  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
170  {
171  }
172  HAL_UART_Transmit(&huart2, (uint8_t *)row7cTxBuffer, (COUNTOF(row7cTxBuffer) - 1),5000);
173  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
174  {
175  }
176  HAL_UART_Transmit(&huart2, (uint8_t *)row71TxBuffer, (COUNTOF(row71TxBuffer) - 1),5000);
177  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
178  {
179  }
180  HAL_UART_Transmit(&huart2, (uint8_t *)row71bTxBuffer, (COUNTOF(row71bTxBuffer) - 1),5000);
181  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
182  {
183  }
184  HAL_UART_Transmit(&huart2, (uint8_t *)row8TxBuffer, (COUNTOF(row8TxBuffer) - 1),5000);
185  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
186  {
187  }
188  HAL_UART_Transmit(&huart2, (uint8_t *)row9TxBuffer, (COUNTOF(row9TxBuffer) - 1),5000);
189  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
190  {
191  }
192  HAL_UART_Transmit(&huart2, (uint8_t *)row10TxBuffer, (COUNTOF(row10TxBuffer) - 1),5000);
193  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
194  {
195  }
196  HAL_UART_Transmit(&huart2, (uint8_t *)row11TxBuffer, (COUNTOF(row11TxBuffer) - 1),5000);
197  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
198  {
199  }
200  HAL_UART_Transmit(&huart2, (uint8_t *)row14TxBuffer, (COUNTOF(row14TxBuffer) - 1),5000);
201  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
202  {
203  }
204  HAL_UART_Transmit(&huart2, (uint8_t *)row15TxBuffer, (COUNTOF(row15TxBuffer) - 1),5000);
205  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
206  {
207  }
208  HAL_UART_Transmit(&huart2, (uint8_t *)row16TxBuffer, (COUNTOF(row16TxBuffer) - 1),5000);
209  while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
210  {
211  }
213  SIXSTEP_parameters.Button_ready = TRUE;
214  }
215 /**
216  * @}
217  */
218 
219 
220 /** @defgroup UART_num_decode UART_num_decode
221  * @{
222  * @brief UART Value decoding function
223 */
224 uint32_t UART_num_decode()
225 {
226  static char Value_Buffer[RXBUFFERSIZE];
227 
228  for(uint8_t i=0;i<BUFF_RCV;i++)
229  {
230  Value_Buffer[i] = aRxBuffer[i];
231  }
232 return(atoi(Value_Buffer));
233 }
234 /**
235  * @}
236  */
237 
238 /** @defgroup UART_Set_Value UART_Set_Value
239  * @{
240  * @brief UART Main function
241 */
242 void UART_Set_Value()
243 {
244  if(Get_UART_Data() == 266 && (huart2.State != HAL_UART_STATE_BUSY_TX && huart2.State != HAL_UART_STATE_BUSY_TX_RX))
245  {
246  if(Uart_cmd_flag == 0)
247  {
248  CMD_Parser((char*)aRxBuffer);
249  }
250  else
251  {
252  SIXSTEP_parameters.Uart_value_to_set = UART_num_decode();
253 
254  switch(SIXSTEP_parameters.Uart_cmd_to_set)
255  {
256  case SETSPD_CMD: /*!< Set the new speed value command received */
257  PI_parameters.Reference = SIXSTEP_parameters.Uart_value_to_set;
258  SIXSTEP_parameters.Ramp_Start = 1;
259  BUFF_RCV = RXBUFFERSIZE;
260  Uart_cmd_flag = 0;
261  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
263  huart2.State = HAL_UART_STATE_READY;
264  break;
265  case INIREF_CMD: /*!< Set the new STARUP_CURRENT_REFERENCE value command received */
266  SIXSTEP_parameters.Ireference = SIXSTEP_parameters.Uart_value_to_set;
267  SIXSTEP_parameters.pulse_value= SIXSTEP_parameters.Uart_value_to_set;
268  BUFF_RCV = RXBUFFERSIZE;
269  Uart_cmd_flag = 0;
270  huart2.State = HAL_UART_STATE_READY;
271  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
273  break;
274  case POLESP_CMD: /*!< Set the Pole Pairs value command received */
275  SIXSTEP_parameters.NUMPOLESPAIRS = SIXSTEP_parameters.Uart_value_to_set;
276  BUFF_RCV = RXBUFFERSIZE;
277  Uart_cmd_flag = 0;
278  huart2.State = HAL_UART_STATE_READY;
279  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
281  break;
282  case ACCELE_CMD: /*!< Set the Accelleration for Start-up of the motor command received */
283  SIXSTEP_parameters.ACCEL = SIXSTEP_parameters.Uart_value_to_set;
284  BUFF_RCV = RXBUFFERSIZE;
285  Uart_cmd_flag = 0;
286  huart2.State = HAL_UART_STATE_READY;
287  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
289  break;
290  case DIRECT_CMD: /*!< Set the motor direction */
291  SIXSTEP_parameters.CW_CCW = SIXSTEP_parameters.Uart_value_to_set;
292  MC_Set_PI_param(&PI_parameters);
293  BUFF_RCV = RXBUFFERSIZE;
294  Uart_cmd_flag = 0;
295  huart2.State = HAL_UART_STATE_READY;
296  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
298  break;
299  case KP_PRM_CMD: /*!< Set the KP PI param command received */
300  PI_parameters.Kp_Gain = SIXSTEP_parameters.Uart_value_to_set;
301  BUFF_RCV = RXBUFFERSIZE;
302  Uart_cmd_flag = 0;
303  huart2.State = HAL_UART_STATE_READY;
304  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
306  break;
307  case KI_PRM_CMD: /*!< Set the KI PI param command received */
308  PI_parameters.Ki_Gain = SIXSTEP_parameters.Uart_value_to_set;
309  BUFF_RCV = RXBUFFERSIZE;
310  Uart_cmd_flag = 0;
311  huart2.State = HAL_UART_STATE_READY;
312  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
314  break;
315  case POTENZ_CMD: /*!< Enable Potentiometer command received */
316  BUFF_RCV = RXBUFFERSIZE;
317  Uart_cmd_flag = 0;
318  huart2.State = HAL_UART_STATE_READY;
319  HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),5000);
321  SIXSTEP_parameters.Potentiometer = SIXSTEP_parameters.Uart_value_to_set;
322  break;
323  } /* switch case */
324  } /* else */
325  } /* if */
326 }
327 /**
328  * @}
329  */
330 
331 
332 /** @defgroup CMD_MSG CMD_MSG
333  * @{
334  * @brief UART Transmit standard message
335 */
336 void CMD_MSG()
337 {
338  HAL_UART_Transmit(&huart2, (uint8_t *)rowVTxBuffer, (COUNTOF(rowVTxBuffer) - 1),5000);
339  BUFF_RCV = RXBUFFERSIZE - 1;
340  Uart_cmd_flag = 1;
342  huart2.State = HAL_UART_STATE_READY;
343 }
344 /**
345  * @}
346  */
347 
348 /** @defgroup CMD_MSG_BOOL CMD_MSG_BOOL
349  * @{
350  * @brief UART Transmit standard message for input data
351 */
352 void CMD_MSG_BOOL()
353 {
354  huart2.State = HAL_UART_STATE_READY;
355  HAL_UART_Transmit(&huart2, (uint8_t *)rowVTBxBuffer, (COUNTOF(rowVTBxBuffer) - 1),5000);
356  BUFF_RCV = RXBUFFERSIZE - 1;
357  Uart_cmd_flag = 1;
359 }
360 /**
361  * @}
362  */
363 
364 /** @defgroup CMD_MSG_BOOL_DIRECT CMD_MSG_BOOL_DIRECT
365  * @{
366  * @brief UART Transmit CW or CCW message for input data
367 */
368 void CMD_MSG_BOOL_DIRECT()
369 {
370  huart2.State = HAL_UART_STATE_READY;
371  HAL_UART_Transmit(&huart2, (uint8_t *)rowV1TBxBuffer, (COUNTOF(rowV1TBxBuffer) - 1),5000);
372  BUFF_RCV = RXBUFFERSIZE - 1;
373  Uart_cmd_flag = 1;
375 }
376 /**
377  * @}
378  */
379 
380 /** @defgroup CMD_STARTM CMD_STARTM
381  * @{
382  * @brief UART Transmit Start motor message
383 */
384 void CMD_STARTM()
385 {
386  /*!< Start Motor command received */
387  huart2.State = HAL_UART_STATE_READY;
388  HAL_UART_Transmit(&huart2, (uint8_t *)rowMxBuffer, (COUNTOF(rowMxBuffer) - 1),5000);
389  MC_StartMotor();
392 }
393 /**
394  * @}
395  */
396 
397 /** @defgroup CMD_STOPMT CMD_STOPMT
398  * @{
399  * @brief UART Transmit Stop motor message
400 */
401 void CMD_STOPMT()
402 {
403  /*!< Stop Motor command received */
404  huart2.State = HAL_UART_STATE_READY;
405  HAL_UART_Transmit(&huart2, (uint8_t *)rowSxBuffer, (COUNTOF(rowSxBuffer) - 1),5000);
406  MC_StopMotor();
409 }
410 /**
411  * @}
412  */
413 
414 /** @defgroup CMD_SETSPD CMD_SETSPD
415  * @{
416  * @brief UART Change the motor speed
417 */
418 void CMD_SETSPD()
419 {
420  /*!< Set the new speed value command received */
421  CMD_MSG();
422  SIXSTEP_parameters.Uart_cmd_to_set = SETSPD_CMD;
423 }
424 /**
425  * @}
426  */
427 
428 /** @defgroup CMD_GETSPD CMD_GETSPD
429  * @{
430  * @brief UART Get the motor speed
431 */
432 void CMD_GETSPD()
433 {
434  /*!< Get Mechanical Motor Speed command received */
435  static char strLineMessage[40];
436 
437  huart2.State = HAL_UART_STATE_READY;
438  sprintf(strLineMessage, "-- The Motor Speed is: %d RPM -- \r\n >", SIXSTEP_parameters.speed_fdbk_filtered);
439  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage,sizeof(strLineMessage),5000);
441 }
442 /**
443  * @}
444  */
445 
446 /** @defgroup CMD_POTENZ CMD_POTENZ
447  * @{
448  * @brief UART Enable the potentiometer
449 */
450 void CMD_POTENZ()
451 {
452  /*!< Enable Potentiometer command received */
453  CMD_MSG_BOOL();
454  SIXSTEP_parameters.Uart_cmd_to_set = POTENZ_CMD;
455 }
456 /**
457  * @}
458  */
459 
460 /** @defgroup CMD_HELP CMD_HELP
461  * @{
462  * @brief UART Help command
463 */
464 void CMD_HELP()
465 {
466  /*!< Help command received */
467  huart2.State = HAL_UART_STATE_READY;
468  MC_UI_INIT();
470 }
471 /**
472  * @}
473  */
474 
475 
476 /** @defgroup CMD_INIREF CMD_INIREF
477  * @{
478  * @brief UART Set the current reference
479 */
480 void CMD_INIREF()
481 {
482  /*!< Set the new STARUP_CURRENT_REFERENCE value command received */
483  CMD_MSG();
484  SIXSTEP_parameters.Uart_cmd_to_set = INIREF_CMD;
485 }
486 /**
487  * @}
488  */
489 
490 
491 /** @defgroup CMD_POLESP CMD_POLESP
492  * @{
493  * @brief UART Set the motor poles pairs
494 */
495 void CMD_POLESP()
496 {
497  /*!< Set the Pole Pairs value command received */
498  CMD_MSG();
499  SIXSTEP_parameters.Uart_cmd_to_set = POLESP_CMD;
500 }
501 /**
502  * @}
503  */
504 
505 /** @defgroup CMD_ACCELE CMD_ACCELE
506  * @{
507  * @brief UART Set the accelleration of the motor at start-up
508 */
509 void CMD_ACCELE()
510 {
511  /*!< Set the Accelleration for Start-up of the motor command received */
512  CMD_MSG();
513  SIXSTEP_parameters.Uart_cmd_to_set = ACCELE_CMD;
514 }
515 /**
516  * @}
517  */
518 
519 /** @defgroup CMD_DIRECTION CMD_DIRECTION
520  * @{
521  * @brief UART Set the motor direction
522 */
523 void CMD_DIRECTION()
524 {
525  /*!< Enable the DEMAG dynamic control command received */
526  CMD_MSG_BOOL_DIRECT();
527  SIXSTEP_parameters.Uart_cmd_to_set = DIRECT_CMD;
528 }
529 /**
530  * @}
531  */
532 
533 /** @defgroup CMD_KP_PRM CMD_KP_PRM
534  * @{
535  * @brief UART Set the KP PI param
536 */
537 void CMD_KP_PRM()
538 {
539  /*!< Set the KP PI param command received */
540  CMD_MSG();
541  SIXSTEP_parameters.Uart_cmd_to_set = KP_PRM_CMD;
542 }
543 /**
544  * @}
545  */
546 
547 /** @defgroup CMD_KI_PRM CMD_KI_PRM
548  * @{
549  * @brief UART Set the KI PI param
550 */
551 void CMD_KI_PRM()
552 {
553  /*!< Set the KI PI param command received */
554  CMD_MSG();
555  SIXSTEP_parameters.Uart_cmd_to_set = KI_PRM_CMD;
556 }
557 /**
558  * @}
559  */
560 
561 /** @defgroup CMD_STATUS CMD_STATUS
562  * @{
563  * @brief UART View the STATUS
564 */
565 void CMD_STATUS()
566 {
567  static char strLineMessage1[30];
568  static char strLineMessage2[30];
569  static char strLineMessage3[30];
570  static char strLineMessage4[30];
571  static char strLineMessage5[30];
572  static char strLineMessage6[30];
573  static char strLineMessage7[30];
574  static char strLineMessage8[30];
575 
576  huart2.State = HAL_UART_STATE_READY;
577  switch (SIXSTEP_parameters.STATUS)
578  {
579  case STARTUP:
580  sprintf(strLineMessage1, " -- The status is: STARTUP --\r\n >");
581  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage1,sizeof(strLineMessage1),5000);
582  break;
583  case VALIDATION:
584  sprintf(strLineMessage2, " -- The status is: VALIDATION --\r\n >");
585  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage2,sizeof(strLineMessage2),5000);
586  break;
587  case START:
588  sprintf(strLineMessage3, " -- The status is: START --\r\n >");
589  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage3,sizeof(strLineMessage3),5000);
590  break;
591  case STOP:
592  sprintf(strLineMessage4, " -- The status is: STOP --\r\n >");
593  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage4,sizeof(strLineMessage4),5000);
594  break;
595  case RUN:
596  sprintf(strLineMessage5, " -- The status is: RUN --\r\n >");
597  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage5,sizeof(strLineMessage5),5000);
598  break;
599  case ALIGNMENT:
600  sprintf(strLineMessage6, " -- The status is: ALIGNMENT --\r\n >");
601  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage6,sizeof(strLineMessage6),5000);
602  break;
603  case SPEEDFBKERROR:
604  sprintf(strLineMessage7, " -- The status is: SPEEDFBKERROR --\r\n >");
605  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage7,sizeof(strLineMessage7),5000);
606  break;
607  default:
608  sprintf(strLineMessage8, " -- The status is: IDLE --\r\n >");
609  HAL_UART_Transmit(&huart2, (uint8_t*) strLineMessage8,sizeof(strLineMessage8),5000);
610  break;
611  }
613 }
614 /**
615  * @}
616  */
617 
618 /** @defgroup CMD_Parser CMD_Parser
619  * @{
620  * @brief UART String parser
621 */
622 void CMD_Parser(char* pCommandString)
623 {
624  static uint8_t CmdListIndex;
625  char sCmd[16];
626  #define TOKEN2 "\n"
627 
628  strcpy(sCmd, pCommandString);
629  strtok (sCmd, TOKEN);
630  strtok (sCmd, TOKEN2);
631 
632  /* Command Callback identification */
633  for(CmdListIndex=0;CmdTable[CmdListIndex].pCmdFunc!=NULL; CmdListIndex++) {
634  if (strcmp(CmdTable[CmdListIndex].name, sCmd) == 0 )
635  {
636  break;
637  }
638  }
639  if ( CmdListIndex < CMD_NUM ){
640  // CMD OK --> extract parameters
641  /* Check for valid callback */
642  if(CmdTable[CmdListIndex].pCmdFunc!=NULL) {
643  CmdTable[CmdListIndex].pCmdFunc();
644  }
645  }
646  else{
647  huart2.State = HAL_UART_STATE_READY;
648  HAL_UART_Transmit(&huart2, (uint8_t *)rowETxBuffer, (COUNTOF(rowETxBuffer) - 1),5000);
649  BUFF_RCV = RXBUFFERSIZE;
650  Uart_cmd_flag = 0;
652  return;
653  }
654 }
655 
656 /**
657  * @}
658  */
659 
660 
661 /**
662  * @} end UART_UI
663  */
664 
665 /**
666  * @} end MIDDLEWARES
667  */
668 #endif
void CMD_POTENZ(void)
void CMD_GETSPD(void)
#define POTENZ_CMD
void MC_StopMotor(void)
Definition: 6Step_Lib.c:1000
#define POLESP_CMD
void UART_Set_Value(void)
uint8_t Enable_start_button
Definition: 6Step_Lib.c:99
SIXSTEP_PI_PARAM_InitTypeDef_t PI_parameters
Definition: 6Step_Lib.c:74
#define COUNTOF(__BUFFER__)
Definition: UART_UI.h:46
void CMD_STARTM(void)
UART function.
void CMD_INIREF(void)
Definition: 6Step_Lib.h:75
void CMD_DIRECTION(void)
void CMD_SETSPD(void)
uint8_t UART_FLAG_RECEIVE
Definition: 6Step_Lib.c:92
UART_HandleTypeDef huart2
Definition: main_F401.c:53
void CMD_STATUS(void)
Definition: 6Step_Lib.h:73
Definition: UART_UI.h:50
SIXSTEP_Base_SystStatus_t STATUS
Definition: 6Step_Lib.h:102
void CMD_STOPMT(void)
#define DIRECT_CMD
#define ACCELE_CMD
void CMD_ACCELE(void)
uint32_t Get_UART_Data()
Get the UART value from DR register.
void CMD_POLESP(void)
Six Step parameters.
Definition: 6Step_Lib.h:94
#define TRUE
void CMD_KP_PRM(void)
void CMD_KI_PRM(void)
void CMD_Parser(char *pCommandString)
SIXSTEP_Base_InitTypeDef SIXSTEP_parameters
Definition: 6Step_Lib.c:73
This file provides a set of functions needed to manage the UART com.
void MC_StartMotor(void)
Definition: 6Step_Lib.c:978
#define FALSE
#define KI_PRM_CMD
void UART_Communication_Task(void)
#define TOKEN
Definition: UART_UI.h:43
#define KP_PRM_CMD
void(* pCmdFunc)(void)
Definition: UART_UI.h:52
#define SETSPD_CMD
void MC_Set_PI_param(SIXSTEP_PI_PARAM_InitTypeDef_t *)
Definition: 6Step_Lib.c:740
void MC_UI_INIT(void)
#define RXBUFFERSIZE
Definition: UART_UI.h:48
Six PI regulator parameters.
Definition: 6Step_Lib.h:170
#define INIREF_CMD
#define CMD_NUM
Definition: UART_UI.h:44
void CMD_HELP(void)
Generated by   doxygen 1.8.11