Skip to content

Commit 112c0d1

Browse files
authored
Update the firware binary to work with latest cc3200-rs (#39)
* Update the firware binary to work with latest cc3200-rs
1 parent ec2880a commit 112c0d1

File tree

7 files changed

+280
-75
lines changed

7 files changed

+280
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ target
22
openocd.log
33
firmware.map
44
Cargo.lock
5+
src/config.rs

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ authors = ["Dave Hylands <[email protected]>"]
77
cc3200 = { path = "cc3200-rs" }
88
freertos_alloc = { path = "cc3200-rs/freertos_alloc" }
99
freertos_rs = "0.1"
10+
log = { version = "0.3", default-features = false }
1011
sensorweb-sys = { path = "sensorweb-sys" }
12+
smallhttp = { git = "https://github.com/fabricedesre/smallhttp.git" }
1113

1214
[profile.dev]
1315
panic = "abort"

cc3200-rs

Submodule cc3200-rs updated 118 files

scripts/travis.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/bin/sh
22

3-
arm-none-eabi-gcc --version
4-
53
curl https://sh.rustup.rs -sSf -o rustup.sh
64
chmod +x ./rustup.sh
75
./rustup.sh -y
86
export PATH=/home/travis/.cargo/bin:$PATH
9-
rustup default nightly
7+
rustup override set nightly-2016-11-06
108
rustup component add rust-src
119
cargo install xargo
10+
cargo --version
11+
xargo --version
12+
rustc --version
13+
arm-none-eabi-gcc --version
14+
15+
cp src/config.rs.sample src/config.rs
1216
./build.sh
1317
./build.sh --release

src/config.rs.sample

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
// You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
use cc3200::simplelink::SlSecParams;
6+
7+
// The default SSID you want to connect to.
8+
pub const SSID: &'static str = "OpenWireless.org";
9+
10+
pub fn security_params() -> Option<SlSecParams> {
11+
// If using an open access point, just return None
12+
Some(SlSecParams::wpa2("YOUR-PASSWORD-HERE"))
13+
//None
14+
}
15+
16+
pub const SENSOR_READING_COUNT: u32 = 10;
17+
pub const SERVER_URL: &'static str = "http://10.252.33.211:8000/endpoint";

src/main.rs

Lines changed: 97 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,101 @@
99
// those are not available in this platform.
1010
#![no_std]
1111
#![feature(alloc)]
12+
#![feature(collections)]
1213

14+
#[macro_use]
1315
extern crate cc3200;
1416
extern crate alloc;
1517
extern crate freertos_rs;
1618
extern crate freertos_alloc;
17-
extern crate sensorweb_sys;
1819

19-
use cc3200::cc3200::{Board, Console, Utils, LedEnum, LedName};
20+
extern crate smallhttp;
2021

21-
use alloc::arc::Arc;
22-
use freertos_rs::{CurrentTask, Duration, Task, Queue};
22+
#[macro_use]
23+
extern crate log;
24+
25+
#[macro_use]
26+
extern crate collections;
27+
28+
use cc3200::cc3200::{Board, I2C, I2COpenMode, LedEnum};
29+
use cc3200::format::*;
30+
use cc3200::simplelink::{self, SimpleLink};
31+
use cc3200::socket_channel::SocketChannel;
32+
33+
use cc3200::i2c_devices::TemperatureSensor;
34+
use cc3200::tmp006::TMP006;
35+
36+
use core::str;
37+
38+
use freertos_rs::{CurrentTask, Duration, Task};
39+
use smallhttp::Client;
40+
use smallhttp::traits::Channel;
41+
42+
static VERSION: &'static str = "1.0";
43+
44+
mod config;
45+
mod wlan;
46+
47+
fn buf_find(buf: &[u8], needle: &str) -> Option<usize> {
48+
if let Ok(s) = str::from_utf8(buf) {
49+
s.find(needle)
50+
} else {
51+
None
52+
}
53+
}
54+
55+
fn run() -> Result<(), wlan::Error> {
56+
57+
Board::led_configure(&[LedEnum::LED1]);
58+
59+
try!(SimpleLink::start_spawn_task());
60+
try!(wlan::wlan_station_mode());
61+
62+
let i2c = I2C::open(I2COpenMode::MasterModeFst).unwrap();
63+
let temp_sensor = TMP006::default(&i2c).unwrap();
64+
65+
println!("Will now send {} temperature sensing to the server...",
66+
config::SENSOR_READING_COUNT);
67+
68+
for _ in 0..config::SENSOR_READING_COUNT {
69+
let temperature = temp_sensor.get_temperature().unwrap();
70+
71+
// Format a simple json payload that we'll POST to the server
72+
let mut buf: [u8; 24] = [b' '; 24];
73+
let json = b"{ \"temperature\": @@@@@ }";
74+
buf[0..json.len()].copy_from_slice(json);
75+
let num_tmpl = "@@@@@";
76+
let num_idx = buf_find(&buf, num_tmpl).unwrap();
77+
if format_float_into(&mut buf[num_idx..num_idx + num_tmpl.len()],
78+
temperature,
79+
1 /* digit after decimal */) {
80+
info!("Feels like {} C",
81+
str::from_utf8(&buf[num_idx..num_idx + num_tmpl.len()]).unwrap());
82+
info!("Sending {}", str::from_utf8(&buf).unwrap());
83+
84+
let mut client = Client::new(SocketChannel::new().unwrap());
85+
let response = client.post(config::SERVER_URL)
86+
.open()
87+
.unwrap()
88+
.send(json)
89+
.unwrap()
90+
.response(|_| false) // Not interested in any header.
91+
.unwrap();
92+
let mut buffer = [0u8; 256];
93+
info!("Received {}",
94+
response.body.read_string_to_end(&mut buffer).unwrap());
95+
} else {
96+
error!("Failed to format temperature float.");
97+
}
98+
99+
100+
CurrentTask::delay(Duration::ms(1000))
101+
}
102+
103+
// Power off the network processor.
104+
try!(SimpleLink::stop(simplelink::SL_STOP_TIMEOUT));
105+
Ok(())
106+
}
23107

24108
// Conceptually, this is our program "entry point". It's the first thing the microcontroller will
25109
// 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() -> ! {
33117

34118
Board::init();
35119

36-
Console::init_term();
37-
Console::clear_term();
38-
Console::message("CC3200 Sample code\n");
39-
40-
unsafe {
41-
sensorweb_sys::sensorweb_test_func();
42-
}
43-
44-
let queue = Arc::new(Queue::new(10).unwrap());
45-
let _producer = {
46-
let queue = queue.clone();
47-
Task::new()
48-
.name("producer")
49-
.start(move || {
50-
let msgs = ["Welcome ", "to ", "CC32xx ", "development !\n"];
51-
loop {
52-
for msg in msgs.iter() {
53-
queue.send(msg, Duration::ms(15)).unwrap();
54-
CurrentTask::delay(Duration::ms(15))
55-
}
56-
CurrentTask::delay(Duration::ms(1000))
57-
}
58-
})
59-
.unwrap()
60-
};
61-
62-
let _consumer = {
63-
let queue = queue.clone();
64-
Task::new()
65-
.name("consumer")
66-
.start(move || {
67-
loop {
68-
let msg = queue.receive(Duration::ms(2000)).unwrap();
69-
Console::message("Received: ");
70-
Console::message(msg);
71-
Console::message("\n");
72-
}
73-
})
74-
.unwrap()
75-
};
120+
println!("Welcome to SensorWeb {}", VERSION);
76121

77-
let _blinky = {
122+
let _client = {
78123
Task::new()
79-
.name("blinky")
124+
.name("client")
125+
.stack_size(2048) // 32-bit words
80126
.start(|| {
81-
Board::led_configure(&[LedEnum::LED1, LedEnum::LED2, LedEnum::LED3]);
82-
Board::led_off(LedName::MCU_ALL_LED_IND);
83-
let mut counter = 0;
84-
loop {
85-
Board::led_on(LedName::MCU_RED_LED_GPIO);
86-
if counter & 1 != 0 {
87-
Board::led_on(LedName::MCU_ORANGE_LED_GPIO);
88-
} else {
89-
Board::led_off(LedName::MCU_ORANGE_LED_GPIO);
90-
}
91-
if counter & 2 != 0 {
92-
Board::led_on(LedName::MCU_GREEN_LED_GPIO);
93-
} else {
94-
Board::led_off(LedName::MCU_GREEN_LED_GPIO);
95-
}
96-
Utils::delay(1333333);
97-
Board::led_off(LedName::MCU_RED_LED_GPIO);
98-
Utils::delay(1333333);
99-
Board::led_on(LedName::MCU_RED_LED_GPIO);
100-
Utils::delay(1333333);
101-
Board::led_off(LedName::MCU_RED_LED_GPIO);
102-
Utils::delay(1333333 * 6);
103-
104-
counter += 1;
105-
}
127+
match run() {
128+
Ok(()) => { println!("sensorweb succeeded"); },
129+
Err(e) => { println!("sensorweb failed: {:?}", e); },
130+
};
131+
loop {}
106132
})
107133
.unwrap()
108134
};

0 commit comments

Comments
 (0)