Skip to content
Snippets Groups Projects
Commit 38079b77 authored by Joakim Lundberg's avatar Joakim Lundberg
Browse files

Uploaded to wrong repository FIXED

parent 1e5f11c2
No related branches found
No related tags found
No related merge requests found
...@@ -4,23 +4,28 @@ ...@@ -4,23 +4,28 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Debug",
"type": "gdb",
"request": "launch",
"target": "./bin/executable",
"cwd": "${workspaceRoot}"
},
{ {
"type": "gdb", "type": "gdb",
"request": "attach", "request": "attach",
"name": "Debug embedded", "name": "Debug embedded",
"usewsl": true, "gdbpath": "/usr/bin/arm-none-eabi-gdb",
"gdbpath": "arm-none-eabi-gdb", "executable": "./target/thumbv7em-none-eabihf/debug/app",
"executable": "./target/thumbv7em-none-eabihf/debug/d7018e_coap",
"target": "192.168.1.4:3333", "target": "192.168.1.4:3333",
"remote": true, "remote": true,
"autorun": [ "autorun": [
"monitor reset init", "monitor reset init",
"monitor arm semihosting enable", "monitor arm semihosting enable",
"monitor tpiu config internal /tmp/itm.log uart off 84000000", "monitor tpiu config internal itm.log uart off 64000000",
"monitor itm port 0 on", "monitor itm port 0 on",
"load", "load",
"monitor reset init", "monitor reset init"
"continue"
], ],
"cwd": "${workspaceRoot}" "cwd": "${workspaceRoot}"
}, },
......
[package] [package]
name = "d7018e_coap" name = "xoap"
version = "0.1.0" version = "0.1.0"
authors = ["Joakim Lundberg <joakim@joakimlundberg.com>"] description = "A CoAP library for bare-metal applications"
categories = ["embedded", "hardware-support", "no-std"]
description = "CoAP on embedded rust"
readme = "README.md" readme = "README.md"
repository = "https://github.com/Shawnshank/D7018E_Project" documentation = ""
keywords = ["CoAP", "Embedded", "arm", "stm32"] repository = ""
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
authors = ["Joakim Lundberg <joakim@joakimlundberg.com>"]
keywords = ["CoAP", "xoap"]
[dependencies] [dependencies]
cortex-m-semihosting = "0.2.0" # Baremetal dependencies
static-ref = "0.2.0" heapless = {version = "0.2.1"}
volatile-register = "0.2.0" #nb = {git = "https://github.com/japaric/nb", optional = true}
m = "0.1.1" cast = {default-features = false, version = "0.2.2", optional = true}
heapless = "0.2.4"
f4 = {git = "https://github.com/jsjolund/f4"}
#xoap = { path = "../projects/xoap", version = "0.1.0", default-features = false, features = ["baremetal"] }# git = "https://github.com/Shawnshank/xoap"
[dependencies.smoltcp]
git = "https://github.com/m-labs/smoltcp"
rev = "cd893e6a"
default-features = false
features = ["proto-ipv4", "socket-tcp"]
[dependencies.stm32f40x]
git = "https://gitlab.henriktjader.com/pln/STM32F40x.git"
features = ["rt"]
version = "0.2.0"
[dependencies.cast]
default-features = false
version = "0.2.2"
[dependencies.cortex-m]
version = "0.3.1"
[dependencies.either]
default-features = false
version = "1.3.0"
[dependencies.embedded-hal]
git = "https://github.com/japaric/embedded-hal"
rev = "7d904f515d15fd5fe7ea34e18820ea83e2651fa2"
[dependencies.nb]
git = "https://github.com/japaric/nb"
[dependencies.cortex-m-rt]
features = ["abort-on-panic"]
version = "0.3.8"
[dependencies.cortex-m-debug]
git = "https://gitlab.henriktjader.com/pln/cortex-m-debug.git"
[dependencies.cortex-m-rtfm]
version = "0.2.0"
[profile.release] [dev-dependencies]
lto = true quickcheck = "0.2.27"
[profile.dev]
incremental = false
codegen-units = 1
\ No newline at end of file
# Embedded rust with CoAP # XoAP (NOT WORKING YET)
This project aims to make [CoAP](https://tools.ietf.org/html/rfc7252) on ARM embedded systems coded with [Rust](https://www.rust-lang.org) a thing. [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
This project is part of the course D7018E at [Luleå tekniska universitet](https://www.ltu.se) taught by [Per Lindgren](https://www.ltu.se/staff/p/pln-1.11258). CoAp for embedded systems in Rust.
Based on [coap](http://covertness.github.io/coap-rs/coap/index.html) by Covertness
## Installation ## Installation
## Crates used First add this to your `Cargo.toml`:
- [coap](http://covertness.github.io/coap-rs/coap/index.html)
- [smoltcp](https://crates.io/crates/smoltcp) ```toml
[dependencies.xoap]
version = "0.1.0"
git = "https://github.com/Shawnshank/xoap"
```
Then, add this to your crate root:
## ESP8266 ```rust
As a WiFi bridge the ESP8266 is used and communicates with the CoAP server/client over USART using [SLIP](https://tools.ietf.org/html/rfc1055) extern crate xoap;
### Firmware ```
The firmware used for the esp8266 module is [esp-just-slip](https://github.com/krzychb/esp-just-slip)
/// Defines the header for a CoAP message
pub const MAX_OPTIONS: usize = 10;
/* Fixed 4 bytes (Sent/Recived header) */
pub struct HeaderRaw {
ver_type_tkl: u8;
code: u8,
ID: u16,
}
pub struct Header {
version: const u8 = 1,
type: MessageType,
tkl: u8,
code: u8,
ID: u16,
}
// Only use piggyback responses
pub struct Token {
value: u8,
}
pub enum MessageType {
None = -1,
Confirmable = 0,
NonConfirmable = 1,
Acknowledgement = 2,
Reset = 3,
}
impl HeaderRaw {
pub fn new() -> Self {
HeaderRaw {
ver_type_tkl: 64, // version = 1 the rest is 0
code: 0,
ID: 0,
}
}
pub fn decode_raw(&self) -> Header {
let newHeader = Header::new();
newHeader.set_tkl(self.ver_type_tkl & 0x0F);
newHeader.set_type(number_to_type((self.ver_type_tkl >> 4) & 0x02);
newHeader.set_code(self.code);
newHeader.set_ID(self.ID);
return newHeader;
}
}
impl Header{
pub fn new() -> Self {
Header {
//version: 1,
type: MessageType::None,
tkl: 0,
code: 0,
ID: 0,
}
}
pub fn build_raw(&self) -> HeaderRaw {
let newHeader = HeaderRaw::new();
newHeader.ver_type_tkl = (1 << 6) | self.type_to_number(get_type()) << 4 | self.get_tkl();
newHeader.code = self.get_code();
newHeader.ID = self.get_ID();
return newHeader;
}
#[inline]
pub fn get_version(&self) -> u8 {
self.version
}
#[inline]
pub fn get_type(&self) -> MessageType {
self.type
}
#[inline]
pub fn set_type(&mut self, t: MessageType) {
self.type = t;
}
#[inline]
pub fn get_tkl(&self) -> u8 {
self.tkl
}
#[inline]
pub fn set_tkl(&mut self, t: u8) {
self.tkl = t;
}
#[inline]
pub fn get_code(&self) -> u8 {
self.code
}
#[inline]
pub fn set_code(&mut self, c: u8) {
self.code = c;
}
#[inline]
pub fn get_ID(&self) -> u16 {
self.type
}
#[inline]
pub fn set_ID(&mut self, id: u16) {
self.ID = id;
}
#[inline]
pub fn get_classcode(&self) -> u8 {
self.code >> 5
}
#[inline]
pub fn set_classcode(&mut self, c: u8) {
let detailcode = self.code & 0x1F;
self.code = (c<<5) | detailcode;
}
#[inline]
pub fn get_detailcode(&self) -> u8 {
self.code & 0x1F
}
#[inline]
pub fn set_detailcode(&mut self, c: u8) {
let classcode = self.code & 0xE0;
self.code = c | classcode;
}
#[inline]
pub fn type_to_number(t: MessageType) -> u8 {
let num = match t => {
MessageType::Confirmable => 0,
MessageType::NonConfirmable => 1,
MessageType::Acknowledgement => 2,
MessageType::Reset => 3,
_ => -1,
}
}
#[inline]
pub fn number_to_type(n: u8) {
let type = match n {
0 => MessageType::Confirmable,
1 => MessageType::NonConfirmable,
2 => MessageType::Acknowledgement,
3 => MessageType::Reset,
_ => MessageType::None,
}
}
}
\ No newline at end of file
// Xoap lib CoAP for ARM microcontrollers
#![no_std]
#![warn(unreachable_patterns)]
extern crate heapless;
pub mod header;
pub mod options;
\ No newline at end of file
use heapless::Vec;
use heapless::String;
pub const MAX_VALUE_LENGTH: usize = 255;
pub const MAX_OPTIONS: usize = 10;
/*
+-----+---+---+---+---+----------------+--------+--------+-------------+
| No. | C | U | N | R | Name | Format | Length | Default |
+-----+---+---+---+---+----------------+--------+--------+-------------+
| 1 | x | | | x | If-Match | opaque | 0-8 | (none) |
| 3 | x | x | - | | Uri-Host | string | 1-255 | (see note 1)|
| 4 | | | | x | ETag | opaque | 1-8 | (none) |
| 5 | x | | | | If-None-Match | empty | 0 | (none) |
| 7 | x | x | - | | Uri-Port | uint | 0-2 | (see note 1)|
| 8 | | | | x | Location-Path | string | 0-255 | (none) |
| 11 | x | x | - | x | Uri-Path | string | 0-255 | (none) |
| 12 | | | | | Content-Format | uint | 0-2 | (none) |
| 14 | | x | - | | Max-Age | uint | 0-4 | 60 |
| 15 | x | x | - | x | Uri-Query | string | 0-255 | (none) |
| 17 | x | | | | Accept | uint | 0-2 | (none) |
| 20 | | | | x | Location-Query | string | 0-255 | (none) |
| 28 | | | x | | Size2 | uint | 0-4 | (none) |
| 35 | x | x | - | | Proxy-Uri | string | 1-1034 | (none) |
| 39 | x | x | - | | Proxy-Scheme | string | 1-255 | (none) |
| 60 | | | x | | Size1 | uint | 0-4 | (none) |
+-----+---+---+---+---+----------------+--------+--------+-------------+
C = Critical, U = Unsafe, N = No-cache-Key, R = Repeatable,
*/
pub enum ValueFormat {
empty = 0, // A zero-length sequence of bytes.
opaque = 1, // An opaque sequence of bytes.
uint, = 2, // A non-negative integer that is represented in network byte order using the number of bytes given by the Option Length field.
string, = 3, // A Unicode string that is encoded using UTF-8 [RFC3629] in Net-Unicode form [RFC5198].
block, = 4,
}
pub struct Format {
delta: u8, // u4
length: u8, // u4
value: u8, // TODO
}
impl Format {
pub fn new() -> Self {
Format {
delta: 0,
length: 0,
value: 0, // TODO // Network byte order - Big-endian
}
}
}
pub enum Options {
None = 0, // Internal
IfMatch = 1,
URIHost = 3,
ETag = 4,
IfNoneMatch = 5,
URIPort = 7,
LocationPath = 8,
URIPath = 11,
ContentFormat = 12,
MaxAge = 14,
URIQuery = 15,
Accept = 17,
LocationQuery = 20,
Size2 = 28,
ProxyURI = 35,
ProxyScheme = 39,
Size1 = 60,
}
pub struct OptionHeader {
number: u8,
name: u8,
type: u8,
minLen: u8,
maxLen: u8,
multipleValues: u8,
defaultValue: u8,
}
impl OptionHeader {
pub fn new()
}
pub struct CoAPOption {
opt: Options,
format: Format,
length: u8,
}
impl CoAPOption {
pub fn new() -> Self {
CoAPOption {
opt: Options::None,
format: Format::new(),
length: 0,
}
}
pub fn
}
pub fn option_to_number(opt: Options) -> u8 {
let num = match opt {
Options::None => 0,
Options::IfMatch => 1,
Options::URIHost => 3,
Options::ETag => 4,
Options::IfNoneMatch => 5,
Options::URIPort => 7,
Options::LocationPath => 8,
Options::URIPath => 11,
Options::ContentFormat => 12,
Options::MaxAge => 14,
Options::URIQuery => 15,
Options::Accept => 17,
Options::LocationQuery => 20,
Options::Size2 => 28,
Options::ProxyURI => 35,
Options::ProxyScheme => 39,
Options::Size1 => 60,
_ => (),
}
return num;
}
pub fn number_to_option(num: u8) -> Options {
let opt = match num {
1 => Options::IfMatch,
3 => Options::URIHost,
4 => Options::ETag,
5 => Options::IfNoneMatch,
7 => Options::URIPort,
8 => Options::LocationPath,
11 => Options::URIPath,
12 => Options::ContentFormat,
14 => Options::MaxAge,
15 => Options::URIQuery,
17 => Options::Accept,
20 => Options::LocationQuery,
28 => Options::Size2,
35 => Options::ProxyURI,
39 => Options::ProxyScheme ,
60 => Options::Size1,
_ => (),
}
return opt;
}
\ No newline at end of file
use heapless::Vec;
use header;
use options;
const MAX_PACKET_SIZE: usize = 255; // Maximum amount of bytes in a singel packet
pub let PacketRaw: Vec<u8, [u8; MAX_PACKET_SIZE]> = Vec::new();
pub struct Packet {
header: header::HeaderRaw,
token: u32, // Should be 8 bytes
options: Vec<options::CoAPOption, [options::CoAPOption; options::MAX_OPTIONS]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment