onto the run function, Igloo::new and Igloo::start work

unstable
Penguin 3 years ago
parent d33f842166
commit 2afd7d3fd3

77
Cargo.lock generated

@ -93,26 +93,6 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "const_format"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4556f63e28a78fa5e6f310cfea5647a25636def49a338ab69e33b34a3382057b"
dependencies = [
"const_format_proc_macros",
]
[[package]]
name = "const_format_proc_macros"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552782506c398da94466b364973b563887e0ca078bf33a76d4163736165e3594"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "directories"
version = "3.0.2"
@ -173,54 +153,23 @@ name = "igloo"
version = "0.1.0"
dependencies = [
"igloo_agent",
"igloo_cli",
"igloo_core",
"igloo_manifest",
]
[[package]]
name = "igloo_agent"
version = "0.1.0"
dependencies = [
"igloo_base",
"igloo_core",
]
[[package]]
name = "igloo_base"
version = "0.1.0"
dependencies = [
"directories",
]
[[package]]
name = "igloo_cli"
version = "0.1.0"
dependencies = [
"clap",
"config",
"igloo_base",
]
[[package]]
name = "igloo_core"
version = "0.1.0"
dependencies = [
"clap",
"config",
"igloo_base",
"igloo_cli",
"igloo_manifest",
"sscanf",
]
[[package]]
name = "igloo_manifest"
version = "0.1.0"
dependencies = [
"config",
"igloo_base",
"sscanf",
"directories",
]
[[package]]
@ -456,30 +405,6 @@ dependencies = [
"serde 0.8.23",
]
[[package]]
name = "sscanf"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a812bcc6cd3cb6f4832fd68dfd2ce835901ddd592d181b5e5a63f8e1d66257ec"
dependencies = [
"const_format",
"lazy_static",
"regex",
"sscanf_macro",
]
[[package]]
name = "sscanf_macro"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7462034123ad94cc80b60b48d262e622e3689ab25e53ab7a1b8e05c89b98c65"
dependencies = [
"proc-macro2",
"quote",
"regex-syntax",
"syn",
]
[[package]]
name = "static_assertions"
version = "1.1.0"

@ -5,19 +5,14 @@ authors = ["Penguin <...>"]
edition = "2018"
repository = "https://github.com/Embedded-Penguin/ePenguin-igloo/"
readme = "README.md"
description = "
Igloo is a package/project manager. It is used for bare metal embedded systems. It is in its early stages of development. The goal of this project is to reduce the pain of writing embedded code by bridging the gap between many different manufacturers. It is can be thought of as glue for many of the fragmented pieces in the embedded world.
This is also a learning project for me. Not all of this code will be the most efficient. I wanted to use a problem I saw as an opportunity to learn rust. Advice is welcome.
"
description = "Igloo is a package/project manager. It is used for bare metal embedded systems. It is in its early stages of development. The goal of this project is to reduce the pain of writing embedded code by bridging the gap between many different manufacturers. It is can be thought of as glue for many of the fragmented pieces in the embedded world. This is also a learning project for me. Not all of this code will be the most efficient. I wanted to use a problem I saw as an opportunity to learn rust. Advice is welcome."
license="GPL-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
igloo_core = { path = "./igloo_core" }
igloo_cli = { path = "./igloo_cli" }
igloo_agent = { path = "./igloo_agent" }
[workspace]
members = ["igloo_core", "igloo_cli", "igloo_agent"]
members = ["igloo_core", "igloo_agent"]

@ -7,5 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
igloo_base = {path = "../igloo_base"}
igloo_core = {path = "../igloo_core"}

@ -3,66 +3,65 @@ use std::process::{Command, Stdio};
use std::sync::mpsc::{channel, Sender};
use std::thread;
use igloo_base::*;
use igloo_core::igloo_target;
fn openocd_thread(sender: Sender<String>, child: std::process::Child)
{
let mut f = BufReader::new(child.stdout.unwrap());
loop
{
let mut buf = String::new();
match f.read_line(&mut buf)
{
Ok(_) =>
{
if !buf.is_empty()
{
sender.send(buf).unwrap();
}
}
Err(e) => println!("error: {:?}", e),
}
}
}
// fn openocd_thread(sender: Sender<String>, child: std::process::Child)
// {
// let mut f = BufReader::new(child.stdout.unwrap());
// loop
// {
// let mut buf = String::new();
// match f.read_line(&mut buf)
// {
// Ok(_) =>
// {
// if !buf.is_empty()
// {
// sender.send(buf).unwrap();
// }
// }
// Err(e) => println!("error: {:?}", e),
// }
// }
// }
fn gdb_thread(sender: &Sender<String>, child: std::process::Child)
{
let mut f = BufReader::new(child.stdout.unwrap());
loop
{
let mut buf = String::new();
match f.read_line(&mut buf)
{
Ok(_) =>
{
if !buf.is_empty()
{
sender.send(buf).unwrap();
}
}
Err(e) => println!("error: {:?}", e),
}
}
}
// fn gdb_thread(sender: &Sender<String>, child: std::process::Child)
// {
// let mut f = BufReader::new(child.stdout.unwrap());
// loop
// {
// let mut buf = String::new();
// match f.read_line(&mut buf)
// {
// Ok(_) =>
// {
// if !buf.is_empty()
// {
// sender.send(buf).unwrap();
// }
// }
// Err(e) => println!("error: {:?}", e),
// }
// }
// }
fn start_openocd_listener(sender: Sender<String>, target: &igloo_target::IglooTarget)
{
let child = Command::new("openocd")
.args(["-f", board_cfg_file])
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start openocd process");
// fn start_openocd_listener(sender: Sender<String>, target: &igloo_target::IglooTarget)
// {
// let child = Command::new("openocd")
// .args(["-f", board_cfg_file])
// .stdout(Stdio::piped())
// .spawn()
// .expect("Failed to start openocd process");
println!("Started openocd process: {}", child.id());
// println!("Started openocd process: {}", child.id());
thread::spawn(move || openocd_thread(sender, child));
}
// thread::spawn(move || openocd_thread(sender, child));
// }
fn ia_push(target: &igloo_target::IglooTarget) -> Result<String, igloo_base::IglooErrType>
{
let (oo_tx, oo_rx) = channel();
start_openocd_listener(oo_tx, target);
let (gdb_tx, gdb_rx) = channel();
// fn ia_push(target: &igloo_target::IglooTarget) -> Result<String, igloo_base::IglooErrType>
// {
// let (oo_tx, oo_rx) = channel();
// start_openocd_listener(oo_tx, target);
// let (gdb_tx, gdb_rx) = channel();
Ok(String::from("working"))
}
// Ok(String::from("working"))
// }

@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
clap = "3.0.0-beta.2"
config = "0.10"
directories = "3.0.1"

@ -0,0 +1,63 @@
use clap::ArgMatches;
use crate::IglooType;
use crate::IglooType::*;
use crate::IglooStatus;
use crate::IglooStatus::*;
pub fn igloo_subcommand(args: &ArgMatches) -> Result<IglooType, IglooStatus>
{
let mut _res_type: IglooType = IT_NULL;
match args.subcommand_name()
{
Some("new") =>
{
println!("Igloo new was called!");
_res_type = IT_NEW;
}
Some("run") =>
{
println!("Igloo run was called!");
_res_type = IT_RUN;
}
Some("build") =>
{
println!("Igloo build was called!");
_res_type = IT_BUILD;
}
Some("push") =>
{
println!("Igloo flash was called!");
_res_type = IT_PUSH;
}
Some("pull") =>
{
println!("Igloo pull was called!");
_res_type = IT_PULL;
}
Some("erase") =>
{
println!("Igloo erase was called!");
_res_type = IT_ERASE;
}
Some("info") =>
{
println!("Igloo info was called!");
_res_type = IT_INFO;
}
Some("target") =>
{
println!("Igloo target was called");
_res_type = IT_TARGET;
}
None => unreachable!(),
_ => unreachable!(),
}
if _res_type == IT_NULL
{
return Err(IS_UNKNOWN)
}
Ok(_res_type)
}

@ -1,7 +1,9 @@
use clap::{App, Arg, ArgMatches};
use IglooType::*;
use IglooStatus::*;
use crate::IglooType;
use crate::IglooType::*;
use crate::IglooStatus;
use crate::IglooStatus::*;
/// Information input via cli will be stored here for the lifetime of the process
pub struct IglooCliInfo
@ -19,7 +21,7 @@ impl IglooCliInfo
{
Self
{
raw: igloo_app(),
raw: igloo_run_cli(),
version_major: env!("CARGO_PKG_VERSION_MAJOR")
.to_string()
.parse()
@ -99,60 +101,3 @@ fn igloo_run_cli() -> clap::ArgMatches
.get_matches();
ret_app
}
pub fn igloo_subcommand(args: &ArgMatches) -> Result<IglooType, IglooStatus>
{
let mut _res_type: IglooType = Null;
match args.subcommand_name()
{
Some("new") =>
{
println!("Igloo new was called!");
_res_type = IT_NEW;
}
Some("run") =>
{
println!("Igloo run was called!");
_res_type = IT_RUN;
}
Some("build") =>
{
println!("Igloo build was called!");
_res_type = IT_BUILD;
}
Some("push") =>
{
println!("Igloo flash was called!");
_res_type = IT_PUSH;
}
Some("pull") =>
{
println!("Igloo pull was called!");
_res_type = IT_PULL;
}
Some("erase") =>
{
println!("Igloo erase was called!");
_res_type = IT_ERASE;
}
Some("info") =>
{
println!("Igloo info was called!");
_res_type = IT_INFO;
}
Some("target") =>
{
println!("Igloo target was called");
_res_type = IT_TARGET;
}
None => unreachable!(),
_ => unreachable!(),
}
if _res_type == Null
{
return Err(ErrUnknown)
}
Ok(_res_type)
}

@ -0,0 +1,45 @@
#[derive(Debug)]
#[derive(PartialEq)]
#[derive(Clone)]
pub struct IglooEnv
{
// Current Working Directory
pub cwd: PathBuf,
// Home Directory
pub hd: PathBuf,
// ESF Directory
pub esfd: PathBuf,
}
impl IglooEnv
{
pub fn get_env() -> IglooEnvInfo
{
cwd: env::current_dir().unwrap(),
hd: match UserDirs::new()
{
Some(v) => v.home_dir().to_owned(),
None =>
{
println!("Error: Failed to get home directory.\n\
This should never happen. Exiting...");
std::process::exit(1);
}
},
esfd: match std::env::var("ESF_DIR")
{
Ok(v)
{
std::path::PathBuf::from(&v.to_owned())
}
Err(e) =>
{
// Note : Need to change new to return actual errors
// instead of exiting early
println!("Error: $ESF_DIR not defined as an environment\
variable -- {:?}", e);
std::process::exit(1);
}
}
}
}

@ -0,0 +1,29 @@
// igloo_manifest is a simple collection of functions that work with configs
use crate::Igloo;
use crate::IglooStatus;
use crate::IglooStatus::*;
use crate::IglooType;
use crate::IglooType::*;
/// USES: environment variables (home dir, esf dir, current dir)
/// DOES: brings target manifest into memory
pub fn get_master_target_manifest(inst: &mut Igloo) -> IglooStatus
{
let mut ret: IglooStatus = IS_GOOD;
match inst.master_target_manifest.merge(
config::File::with_name(
inst.env.esfd.join("manifest/target-manifest.toml").to_str.unwrap()))
{
Ok(_v) => (),
Err(e) =>
{
println!("Error: {:?}", e);
ret = IS_FAILED_TO_LOAD_MTM;
}
}
ret
}

@ -0,0 +1,9 @@
pub struct IglooProject
{
}
impl IglooProject
{
}

@ -1,12 +1,24 @@
#![allow(warnings)]
extern crate clap;
extern crate config;
use config::Config;
use std::path::PathBuf;
use std::env;
use directories::*;
pub mod igloo_target;
mod igloo_action;
mod igloo_project;
mod igloo_target;
mod igloo_manifest;
mod igloo_cli;
mod igloo_env;
use igloo_cli::IglooCliInfo;
use igloo_env::IglooEnv;
#[derive(Debug)]
#[derive(PartialEq)]
pub enum IglooType
{
IT_NEW = 0,
@ -15,21 +27,41 @@ pub enum IglooType
IT_PULL,
IT_HELP,
IT_BUILD,
IT_ERASE,
IT_INFO,
IT_TARGET,
IT_NULL,
}
#[derive(Debug)]
#[derive(PartialEq)]
pub enum IglooDebugSeverity
{
CRITICAL = 0,
WARNING = 1,
INFO = 2,
TRACE = 3,
}
#[derive(Debug)]
#[derive(PartialEq)]
pub enum IglooStatus
{
IS_GOOD = 0x00,
IS_BAD = 0x01,
IS_UNKNOWN = 0x02,
IS_FAILED_TO_LOAD_MTM = 0x03,
}
use IglooStatus::*;
use IglooType::*;
pub struct Igloo
{
cli_conf: IglooCliConfig,
cli_info: IglooCliInfo,
// manifest containing all mcu information
master_target_manifest: Config,
env: IglooEnv,
}
impl Igloo
@ -39,13 +71,35 @@ impl Igloo
Igloo
{
master_target_manifest: Config::new(),
cli_conf: IglooCliConfig::new(),
cli_info: IglooCliInfo::new(),
env: IglooEnv::get_env(),
}
}
pub fn start(&mut self) -> Result<IglooType, IglooStatus>
{
let mut res: IglooType = IT_NULL;
match igloo_manifest::get_master_target_manifest(self)
{
IS_GOOD => (),
e =>
{
println!("{:?}", e);
return Err(e)
},
}
// Assign instance type (new, run, push, etc)
igloo_action::igloo_subcommand(&self.cli_info.raw)
}
pub fn start(&mut self) -> Result<IglooInstType, IglooErrType>
pub fn run(&self, inst_type: IglooType) -> IglooStatus
{
let mut res: IglooInstType = Null;
let mut res_err = IS_GOOD;
let mut prj: IglooProject;
res_err
}
}

Loading…
Cancel
Save