89 lines
3.3 KiB
Markdown
89 lines
3.3 KiB
Markdown
# Satellite Propulsion System
|
|
|
|
## Approach
|
|
This program will be using standard I/O for getting data.
|
|
|
|
Tackling this problem requires the use of asynchronous code. This is because
|
|
the user will constantly be giving input on the command line yet time needs
|
|
to keep moving forward to fire any propulsion commands.
|
|
|
|
To handle this the program uses two separate tasks. One for handling
|
|
the input and one for running the commands given. The input, coming from
|
|
standard I/O, will run on a separate thread because it will use blocking
|
|
functions. The command processing can be handled in an asynchronous
|
|
task since it can use completely asynchronous functions.
|
|
|
|
The two tasks are linked with message passing channels. One channel is for
|
|
passing commands from the input task to the command processing task. The
|
|
other channel is a watch channel on a boolean value that the input task
|
|
will flip from true to false. This will designate that the program should
|
|
no longer be running and needs to terminate.
|
|
|
|
The input reading task is the main driver of the program. It will loop until
|
|
the program is told to stop running. This is done by the user typing "exit",
|
|
"stop", or "quit". It will then trigger termination through the watch
|
|
channel. If the user types a whole number between 0 and i32::MAX, it
|
|
will create and send a propulsion command with a delay time of the given
|
|
number, as seconds, and send it over the command channel. If the user types
|
|
a '-1', it will create a cancel command and send it over the command
|
|
channel. Cancel is handled as a separate command because it is a different
|
|
action and it is clearer to handle it separately.
|
|
|
|
The command processing task will loop until the termination channel tells
|
|
it to end. It will handle two async jobs. The first is processing
|
|
commands from the command channel, either creating a propulsion interval
|
|
countdown or clearing any that are already running. The second job is
|
|
to run the current propulsion firing interval until it completes one firing.
|
|
|
|
|
|
|
|
## Instructions
|
|
### Build
|
|
To build the program you must have rustc and cargo installed.
|
|
The instructions to do so can be found
|
|
[here](https://www.rust-lang.org/tools/install).
|
|
|
|
Then to build the program navigate to the directory and run the
|
|
following command.
|
|
```
|
|
cargo build --release
|
|
```
|
|
|
|
If you would like to include debugging symbols then you can run the
|
|
following command.
|
|
```
|
|
cargo build
|
|
```
|
|
|
|
This will pull all the required dependencies from crates.io.
|
|
Below is the list of dependencies; this can be verified in Cargo.toml.
|
|
* tokio
|
|
|
|
|
|
### Run
|
|
To run the program type the following command.
|
|
```
|
|
cargo run --release
|
|
```
|
|
|
|
If you want to run a version with all the debugging symbols then run the
|
|
following command.
|
|
```
|
|
cargo run
|
|
```
|
|
|
|
You can also run the currently built version from the 'target' subdirectory.
|
|
Debug builds can be found in target/debug.
|
|
Release builds can be found in target/release.
|
|
The executable's name is satellite.
|
|
|
|
### Operation
|
|
Once the program is running it will expect input commands from the user.
|
|
The commands can either be:
|
|
* A whole number - To specify the amount of delay, in seconds, before the
|
|
next time the satellite will fire its engine.
|
|
* The number '-1' - To specify that all current propulsion commands should
|
|
be canceled.
|
|
* The any one of the case sensitive words
|
|
"quit", "stop", or "exit" - To specify that the program should terminate.
|