-
Notifications
You must be signed in to change notification settings - Fork 3
Update the firware binary to work with latest cc3200-rs #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ target | |
openocd.log | ||
firmware.map | ||
Cargo.lock | ||
src/config.rs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ authors = ["Dave Hylands <[email protected]>"] | |
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" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where this actually sends a temperature to the server. |
||
|
||
// 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 | ||
|
@@ -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() | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a reasonable way to do it in cc3200-rs as well (and addresses your concern about checking the file in accidentally).