Siphon Regulator 1.0
Nanosattelite attitude determination and control system.
Loading...
Searching...
No Matches
Commands

Process commands send to MCU through serial port. More...

Macros

#define CMD_BUFFER_LEN   256
 
#define PULSE_LEN_MIN   100
 
#define PULSE_LEN_MAX   1000
 
#define MAX_TIME   255
 
#define TURN_ANGLE_MIN   10
 
#define TURN_ANGLE_MAX   90
 
#define HOME_ANGLE_MIN   -180
 
#define HOME_ANGLE_MAX   180
 

Functions

void uart_byte_available (uint8_t c, uint32_t *p_reg)
 Recognizes commands in the received characters and sets the cmd register accordingly.
 
static void process_cmd (char *cmd, uint32_t *p_reg)
 Executes the corresponding commands are stores the result in the command register.
 
static void process_cmd_read (char *cmd)
 Sends sensors data based on the command.
 
static void process_cmd_turn (char *cmd, uint32_t *p_reg)
 Triggers a rotation by a defined angle.
 
static void process_cmd_home (uint32_t *p_reg)
 Triggers a home command.
 
static void process_cmd_pulse (char *cmd, uint32_t *p_reg)
 Triggers a pulse with a defined duration.
 
static void process_cmd_set (char *cmd, uint32_t *p_reg)
 Allows modifying the settings global variable and changing the contents of the autoread report.
 
static void process_cmd_ncmd (char *cmd, uint32_t *p_reg)
 Reserved.
 
static void process_cmd_autoread (char *cmd, uint32_t *p_reg)
 Enables and disables autoread.
 
static void process_cmd_reset (uint32_t *p_reg)
 Clears command register. Closes valves.
 
static void process_cmd_set_read (char *cmd, uint32_t *p_reg)
 Enables turn on/off autoreport from these sensors.
 
static void process_cmd_set_auto (char *cmd)
 Enables change the period of autoreading.
 
static void process_cmd_set_time (char *cmd)
 Allows adjusting the valve-opening time settings.
 
static void process_cmd_set_angle (char *cmd)
 Allows setting the rotation angle for the TURN command.
 
static void process_cmd_set_home (char *cmd)
 Allows setting the default orientation for the HOME command.
 

Variables

sensor_data_t measured_data
 Current sensor measured data.
 
settings_t set_data
 Main system settings.
 

Detailed Description

Process commands send to MCU through serial port.

The library contains functions that enables the recognition of the commands HELLO, STATUS, RESET, TURN, PULSE, HOME, SET, READ, AUTOREAD and CMD. Its contents are adapted to the Siphon Regulator project.

Necessary definition and function declaration.

Macro Definition Documentation

◆ CMD_BUFFER_LEN

#define CMD_BUFFER_LEN   256

Maximum length of a received command is 256 characters.

Definition at line 25 of file cmd_processing_def.h.

◆ HOME_ANGLE_MAX

#define HOME_ANGLE_MAX   180

Maximum angle of a default orietation is 180°.

Definition at line 46 of file cmd_processing_def.h.

◆ HOME_ANGLE_MIN

#define HOME_ANGLE_MIN   -180

Minimum angle of a default orietation is -180°.

Definition at line 43 of file cmd_processing_def.h.

◆ MAX_TIME

#define MAX_TIME   255

Maximum period of autoreading is 25.5 s.

Definition at line 34 of file cmd_processing_def.h.

◆ PULSE_LEN_MAX

#define PULSE_LEN_MAX   1000

Maximum open valve time is 1000 ms.

Definition at line 31 of file cmd_processing_def.h.

◆ PULSE_LEN_MIN

#define PULSE_LEN_MIN   100

Minimum open valve time is 100 ms.

Definition at line 28 of file cmd_processing_def.h.

◆ TURN_ANGLE_MAX

#define TURN_ANGLE_MAX   90

Maximum angle of TURN command is 90°.

Definition at line 40 of file cmd_processing_def.h.

◆ TURN_ANGLE_MIN

#define TURN_ANGLE_MIN   10

Minimum angle of TURN command is 10°.

Definition at line 37 of file cmd_processing_def.h.

Function Documentation

◆ process_cmd()

static void process_cmd ( char * cmd,
uint32_t * p_reg )
static

Executes the corresponding commands are stores the result in the command register.

Parameters
cmdpointer to the string with processed command
p_regcommand register, involves information about system state and switching time of valves

It processes the first word of the command. It handles the HELLO and STATUS commands directly. For the remaining commands, it calls a dedicated function.

◆ process_cmd_autoread()

static void process_cmd_autoread ( char * cmd,
uint32_t * p_reg )
static

Enables and disables autoread.

Parameters
cmdpointer to the string with processed command
p_regcommand register, involves information about system state and switching time of valves

Allows setting and clearing the AUTOREAD_BIT flag.

  • Available arguments:
    Argument Description AUTOREAD_BIT
    OFF disable autoread 0
    ON enable autoread 1

◆ process_cmd_home()

static void process_cmd_home ( uint32_t * p_reg)
static

Triggers a home command.

Parameters
p_regcommand register, involves information about system state and switching time of valves

It forwards the home request by writing it into the command register. It sets the RUN_BIT and HOME_BIT flag. It also updates the timing configuration in the command register, using the time value from the global variable settings.

◆ process_cmd_ncmd()

static void process_cmd_ncmd ( char * cmd,
uint32_t * p_reg )
static

Reserved.

Parameters
cmdpointer to the string with processed command
p_regcommand register, involves information about system state and switching time of valves
Note
Setting CMD0_BIT disables regulation.

Allow arguments are 0 to 3. Based on the argument, it toggles the bits CMD0_BIT to CMD3_BIT.

◆ process_cmd_pulse()

static void process_cmd_pulse ( char * cmd,
uint32_t * p_reg )
static

Triggers a pulse with a defined duration.

Parameters
cmdpointer to the string with processed command
p_regcommand register, involves information about system state and switching time of valves
Warning
It does not work together with the regulation system. Intended for testing only. The regulation must be disabled (CMD 0).

It forwards the pulse request by writing it into the command register. It sets the RUN_BIT and PULSE_BIT flag. Depending on the direction, it sets the DIR_BIT flag. It also updates the timing configuration in the command register.

The pulse duration can be specified by the user using the <time> argument. The time is given in milliseconds. The time is divided by PULSE_REPRE because the value is provided in tens of milliseconds. If it is not specified, the value from the global variable settings is used.

Available arguments:

Argument Description DIR_BIT
LEFT rotation to the left 0
RIGHT rotation to the right 1

◆ process_cmd_read()

static void process_cmd_read ( char * cmd)
static

Sends sensors data based on the command.

Parameters
cmdpointer to the string with processed command

Available arguments:

Argument Description
ACC accelerometer
GYR gyroscope - angular velocity
POS gyroscope - orientation
ALL all available data

◆ process_cmd_reset()

static void process_cmd_reset ( uint32_t * p_reg)
static

Clears command register. Closes valves.

Parameters
p_regcommand register, involves information about system state and switching time of valves

Emergency command. Reset to defaut settings. Interrupts any running commands. Stop the valves.

◆ process_cmd_set()

static void process_cmd_set ( char * cmd,
uint32_t * p_reg )
static

Allows modifying the settings global variable and changing the contents of the autoread report.

Parameters
cmdpointer to the string with processed command
p_regcommand register, involves information about system state and switching time of valves

Processes the second arguments of the command. Calls the corresponding function.

  • Available arguments:
    Argument Description Function
    ANGLE set angle of TURN command process_cmd_set_angle
    TIME set valve switching time process_cmd_set_time
    AUTO set period of autoreading process_cmd_set_auto
    HOME set default orientation process_cmd_set_home
    READ set content of autoreading process_cmd_set_read

◆ process_cmd_set_angle()

static void process_cmd_set_angle ( char * cmd)
static

Allows setting the rotation angle for the TURN command.

Parameters
cmdpointer to the string with processed command

The <angle> argument is stored in the global variable settings. It must be an unsigned integer value within the defined limits and is interpreted as degrees.

◆ process_cmd_set_auto()

static void process_cmd_set_auto ( char * cmd)
static

Enables change the period of autoreading.

Parameters
cmdpointer to the string with processed command

The autoread period is stored in the global variable settings Its value is determined by the <time> argument. It is an integer within the specified limits and is interpreted as tenths of a second.

◆ process_cmd_set_home()

static void process_cmd_set_home ( char * cmd)
static

Allows setting the default orientation for the HOME command.

Parameters
cmdpointer to the string with processed command

The <angle> argument is stored in the global variable settings. It must be an signed integer value within the defined limits and is interpreted as degrees.

◆ process_cmd_set_read()

static void process_cmd_set_read ( char * cmd,
uint32_t * p_reg )
static

Enables turn on/off autoreport from these sensors.

Parameters
cmdpointer to the string with processed command
p_regcommand register, involves information about system state and switching time of valves

Sets (ON) or clear (OFF) the corresponding flag in the command register.

Available arguments:

Argument Description Affected bit
ACC accelerometer AUTOREAD_ACC_BIT
GYR gyroscope - angular velocity AUTOREAD_GYR_BIT
POS gyroscope - orientation AUTOREAD_POS_BIT

◆ process_cmd_set_time()

static void process_cmd_set_time ( char * cmd)
static

Allows adjusting the valve-opening time settings.

Parameters
cmdpointer to the string with processed command

Stores the specified time value <time> into the global variable settings. The time value must be an unsinged integer within the defined range and is interpreted as a duration in milliseconds. The time is divided by PULSE_REPRE because the value is provided in tens of milliseconds.

Available arguments:

Argument Affected variables
RIGHT set_data.time_r
LEFT set_data.time_l
ALL set_data.time_r, set_data.time_l

◆ process_cmd_turn()

static void process_cmd_turn ( char * cmd,
uint32_t * p_reg )
static

Triggers a rotation by a defined angle.

Parameters
cmdpointer to the string with processed command
p_regcommand register, involves information about system state and switching time of valves

It forwards the rotation request by writing it into the command register. It sets the RUN_BIT and TURN_BIT flag. Depending on the direction, it sets the DIR_BIT flag. It also updates the timing configuration in the command register, using the time value from the global variable settings.

Available arguments:

Argument Description DIR_BIT
LEFT rotation to the left 0
RIGHT rotation to the right 1

◆ uart_byte_available()

void uart_byte_available ( uint8_t c,
uint32_t * p_reg )

Recognizes commands in the received characters and sets the cmd register accordingly.

Parameters
cprocessed character
p_regcommand register, involves information about system state and switching time of valves The processed character is written into the buffer step by step. The terminating characters '\n' and '\r' are checked. After that, the function that processes the received command is called.

Available commands:

Command Parameters Description
HELLO test communication
STATUS read command register
RESET clear command register
HOME return to home position
TURN (RIGHT/LEFT) rotates by a defined angle
PULSE (RIGHT/LEFT) <time> generates a pulse of a defined duration
READ (ACC/GYR/POS/ALL) read sensor data
AUTOREAD (ON/OFF) repeated reading from the sensors
CMD (0/1/2/3) reserved
SET ANGLE <angle> set angle of TURN command
SET TIME (RIGHT/LEFT) <time> set valve switching time
SET AUTO <time> set period of autoreading
SET READ (ACC/GYR/POS) (ON/OFF) set content of autoreading
SET HOME <angle> set default orientation

Definition at line 28 of file cmd_processing.c.

Variable Documentation

◆ measured_data

sensor_data_t measured_data
extern

Current sensor measured data.

Definition at line 60 of file main.c.

◆ set_data

settings_t set_data
extern

Main system settings.

Definition at line 61 of file main.c.