Git Product home page Git Product logo

rscp's Introduction

rscp

Crate Docs License Coverage

This lib is a Rust based E3/DC RSCP connector.

  • omit the use of double namings and wrappings
  • implemented native type parsing without wrapping types

The response bit in the Tag field is ignored due the fact there is no known need to take care on this.

Ths lib is in early stage.

Usage

There are multiple user levels (NO_AUTH => USER ... => ADMIN => E3DC_ROOT). For most cases NO_AUTH and USER level access is enough. Therefore before sending a request towards you E3DC system we need to authenticate first.

Every requests towards RSCP system consists of a rscp::Frame (container) with multiple rscp::Item with the later holding the tags and data.

Login and First Frame

RSCP_KEY is the password you define on your S10 screen in Settings => Personalize => User Profile +> local.user
RSCP_USER is is the username (i.e. email ) in your S10 portal.
RSCP_PASSWORD is the password in your S10 portal

use rscp::GetItem;

let mut c = rscp::Client::new("RSCP_KEY", "RSCP_USER".to_string(), "RSCP_PASSWORD".to_string());
match c.connect("energy.storage.local", None) {
    Ok(_) => (),
    Err(err) => {
        panic!("Unable to connect: {:?}", err);
    }
}

let mut info_frame = rscp::Frame::new();
info_frame.push_item(rscp::Item { tag: rscp::tags::INFO::SERIAL_NUMBER.into(), data: None } );
info_frame.push_item(rscp::Item { tag: rscp::tags::INFO::MAC_ADDRESS.into(), data: None } );
info_frame.push_item(rscp::Item { tag: rscp::tags::INFO::SW_RELEASE.into(), data: None } );

match c.send_receive_frame(&info_frame) {
    Ok(result_frame) => {
        println!("{}", result_frame.get_item_data::<String>(rscp::tags::INFO::SERIAL_NUMBER.into()).unwrap());
    },
    Err(err) => {
        warn!("Unable send: {:?}", err);
    }
}

c.disconnect().unwrap();

Compose Battery Information Request

Similarly to the official example of the rscp call to request battery information, we can also define a containered request. The BAT::DATA tag defines that the following tags should be evaluated to receive some data about the battery.

let mut battery_info_frame = Frame::new();
battery_info_frame.push_item(rscp::Item::new(rscp::tags::BAT::DATA.into(),
    vec![
        rscp::Item { tag: rscp::tags::BAT::INDEX.into(), data: Some(Box::new(0)), },
        rscp::Item { tag: rscp::tags::BAT::RSOC.into(), data: None },
        rscp::Item { tag: rscp::tags::BAT::MODULE_VOLTAGE.into(), data: None },
        rscp::Item { tag: rscp::tags::BAT::CURRENT.into(), data: None },
        rscp::Item { tag: rscp::tags::BAT::STATUS_CODE.into(), data: None },
        rscp::Item { tag: rscp::tags::BAT::ERROR_CODE.into(), data: None },
    ]));

Expected output of println!("Result: {:?}", result_frame.items.get_item(DATA.into())); inside match

Result: Ok(Item 
{ tag: "BAT_DATA", data: [
    Item { tag: "BAT_INDEX", data: 0 }, 
    Item { tag: "BAT_RSOC", data: 38.218014 }, 
    Item { tag: "BAT_MODULE_VOLTAGE", data: 51.7 }, 
    Item { tag: "BAT_CURRENT", data: 108.9 }, 
    Item { tag: "BAT_STATUS_CODE", data: 0 }, 
    Item { tag: "BAT_ERROR_CODE", data: 0 }
] })

Tags vs Tags

Be careful which tag you use in your requests because some tags set values instead of getting them. The official example app documentation and excel table provide necessary information to distinguish between these tags.

The structure of tags in this project is similar to the documentation of tags but not necessarily to the tags in the official example app. For Example this official tag: #define TAG_BAT_INDEX 0x03040001 corresponds to project tag:

rscp::tags::BAT::INDEX:

  • BAT = 0x03,
  • INDEX = 0x040001,

The advantage lies in the reuse of tag names and therefore in readability of code.

Project Tags Example App Tags
PVI::DATA = 0x040000, TAG_PVI_DATA = 0x02840000
BAT::DATA = 0x040000, TAG_BAT_INDEX = 0x03840000
DCDC::DATA = 0x040000, TAG_DCDC_REQ_DATA = 0x04040000
... ...

rscp's People

Contributors

mr-sven avatar

Stargazers

Vitaliy Schreibmann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.