Skip to content

Commit

Permalink
Update the firware binary to work with latest cc3200-rs (#39)
Browse files Browse the repository at this point in the history
* Update the firware binary to work with latest cc3200-rs
  • Loading branch information
fabricedesre committed Nov 28, 2016
1 parent ec2880a commit 112c0d1
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target
openocd.log
firmware.map
Cargo.lock
src/config.rs
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ authors = ["Dave Hylands <dhylands@gmail.com>"]
cc3200 = { path = "cc3200-rs" }
freertos_alloc = { path = "cc3200-rs/freertos_alloc" }
freertos_rs = "0.1"
log = { version = "0.3", default-features = false }
sensorweb-sys = { path = "sensorweb-sys" }
smallhttp = { git = "https://github.com/fabricedesre/smallhttp.git" }

[profile.dev]
panic = "abort"
Expand Down
2 changes: 1 addition & 1 deletion cc3200-rs
Submodule cc3200-rs updated 118 files
10 changes: 7 additions & 3 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/sh

arm-none-eabi-gcc --version

curl https://sh.rustup.rs -sSf -o rustup.sh
chmod +x ./rustup.sh
./rustup.sh -y
export PATH=/home/travis/.cargo/bin:$PATH
rustup default nightly
rustup override set nightly-2016-11-06
rustup component add rust-src
cargo install xargo
cargo --version
xargo --version
rustc --version
arm-none-eabi-gcc --version

cp src/config.rs.sample src/config.rs
./build.sh
./build.sh --release
17 changes: 17 additions & 0 deletions src/config.rs.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

use cc3200::simplelink::SlSecParams;

// The default SSID you want to connect to.
pub const SSID: &'static str = "OpenWireless.org";

pub fn security_params() -> Option<SlSecParams> {
// If using an open access point, just return None
Some(SlSecParams::wpa2("YOUR-PASSWORD-HERE"))
//None
}

pub const SENSOR_READING_COUNT: u32 = 10;
pub const SERVER_URL: &'static str = "http://10.252.33.211:8000/endpoint";
168 changes: 97 additions & 71 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,101 @@
// those are not available in this platform.
#![no_std]
#![feature(alloc)]
#![feature(collections)]

#[macro_use]
extern crate cc3200;
extern crate alloc;
extern crate freertos_rs;
extern crate freertos_alloc;
extern crate sensorweb_sys;

use cc3200::cc3200::{Board, Console, Utils, LedEnum, LedName};
extern crate smallhttp;

use alloc::arc::Arc;
use freertos_rs::{CurrentTask, Duration, Task, Queue};
#[macro_use]
extern crate log;

#[macro_use]
extern crate collections;

use cc3200::cc3200::{Board, I2C, I2COpenMode, LedEnum};
use cc3200::format::*;
use cc3200::simplelink::{self, SimpleLink};
use cc3200::socket_channel::SocketChannel;

use cc3200::i2c_devices::TemperatureSensor;
use cc3200::tmp006::TMP006;

use core::str;

use freertos_rs::{CurrentTask, Duration, Task};
use smallhttp::Client;
use smallhttp::traits::Channel;

static VERSION: &'static str = "1.0";

mod config;
mod wlan;

fn buf_find(buf: &[u8], needle: &str) -> Option<usize> {
if let Ok(s) = str::from_utf8(buf) {
s.find(needle)
} else {
None
}
}

fn run() -> Result<(), wlan::Error> {

Board::led_configure(&[LedEnum::LED1]);

try!(SimpleLink::start_spawn_task());
try!(wlan::wlan_station_mode());

let i2c = I2C::open(I2COpenMode::MasterModeFst).unwrap();
let temp_sensor = TMP006::default(&i2c).unwrap();

println!("Will now send {} temperature sensing to the server...",
config::SENSOR_READING_COUNT);

for _ in 0..config::SENSOR_READING_COUNT {
let temperature = temp_sensor.get_temperature().unwrap();

// Format a simple json payload that we'll POST to the server
let mut buf: [u8; 24] = [b' '; 24];
let json = b"{ \"temperature\": @@@@@ }";
buf[0..json.len()].copy_from_slice(json);
let num_tmpl = "@@@@@";
let num_idx = buf_find(&buf, num_tmpl).unwrap();
if format_float_into(&mut buf[num_idx..num_idx + num_tmpl.len()],
temperature,
1 /* digit after decimal */) {
info!("Feels like {} C",
str::from_utf8(&buf[num_idx..num_idx + num_tmpl.len()]).unwrap());
info!("Sending {}", str::from_utf8(&buf).unwrap());

let mut client = Client::new(SocketChannel::new().unwrap());
let response = client.post(config::SERVER_URL)
.open()
.unwrap()
.send(json)
.unwrap()
.response(|_| false) // Not interested in any header.
.unwrap();
let mut buffer = [0u8; 256];
info!("Received {}",
response.body.read_string_to_end(&mut buffer).unwrap());
} else {
error!("Failed to format temperature float.");
}


CurrentTask::delay(Duration::ms(1000))
}

// Power off the network processor.
try!(SimpleLink::stop(simplelink::SL_STOP_TIMEOUT));
Ok(())
}

// Conceptually, this is our program "entry point". It's the first thing the microcontroller will
// execute when it (re)boots. (As far as the linker is concerned the entry point must be named
Expand All @@ -33,76 +117,18 @@ pub fn start() -> ! {

Board::init();

Console::init_term();
Console::clear_term();
Console::message("CC3200 Sample code\n");

unsafe {
sensorweb_sys::sensorweb_test_func();
}

let queue = Arc::new(Queue::new(10).unwrap());
let _producer = {
let queue = queue.clone();
Task::new()
.name("producer")
.start(move || {
let msgs = ["Welcome ", "to ", "CC32xx ", "development !\n"];
loop {
for msg in msgs.iter() {
queue.send(msg, Duration::ms(15)).unwrap();
CurrentTask::delay(Duration::ms(15))
}
CurrentTask::delay(Duration::ms(1000))
}
})
.unwrap()
};

let _consumer = {
let queue = queue.clone();
Task::new()
.name("consumer")
.start(move || {
loop {
let msg = queue.receive(Duration::ms(2000)).unwrap();
Console::message("Received: ");
Console::message(msg);
Console::message("\n");
}
})
.unwrap()
};
println!("Welcome to SensorWeb {}", VERSION);

let _blinky = {
let _client = {
Task::new()
.name("blinky")
.name("client")
.stack_size(2048) // 32-bit words
.start(|| {
Board::led_configure(&[LedEnum::LED1, LedEnum::LED2, LedEnum::LED3]);
Board::led_off(LedName::MCU_ALL_LED_IND);
let mut counter = 0;
loop {
Board::led_on(LedName::MCU_RED_LED_GPIO);
if counter & 1 != 0 {
Board::led_on(LedName::MCU_ORANGE_LED_GPIO);
} else {
Board::led_off(LedName::MCU_ORANGE_LED_GPIO);
}
if counter & 2 != 0 {
Board::led_on(LedName::MCU_GREEN_LED_GPIO);
} else {
Board::led_off(LedName::MCU_GREEN_LED_GPIO);
}
Utils::delay(1333333);
Board::led_off(LedName::MCU_RED_LED_GPIO);
Utils::delay(1333333);
Board::led_on(LedName::MCU_RED_LED_GPIO);
Utils::delay(1333333);
Board::led_off(LedName::MCU_RED_LED_GPIO);
Utils::delay(1333333 * 6);

counter += 1;
}
match run() {
Ok(()) => { println!("sensorweb succeeded"); },
Err(e) => { println!("sensorweb failed: {:?}", e); },
};
loop {}
})
.unwrap()
};
Expand Down
Loading

0 comments on commit 112c0d1

Please sign in to comment.