Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pico/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![no_std]
#![no_main]

use atat::asynch::Client;
use alloc::string::ToString;
use atat::asynch::{AtatClient, Client};
use atat::{AtatIngress, DefaultDigester, Ingress, ResponseSlot, UrcChannel};
use core::ptr::addr_of_mut;
use embassy_executor::Spawner;
Expand All @@ -22,7 +23,8 @@ use {defmt_rtt as _, panic_probe as _};
use pico_lib::at::PicoHW;
use pico_lib::poro;
use pico_lib::urc;
use pico_lib::{at, call, network, sms};
use pico_lib::utils::LogBE;
use pico_lib::{at, battery, call, network, sms};

extern crate alloc;

Expand Down Expand Up @@ -141,6 +143,15 @@ async fn main(spawner: Spawner) {
Timer::after(Duration::from_millis(100)).await;
}

{
let _l = LogBE::new("AtBatteryChargeExecute".to_string());
let r = client.send(&battery::AtBatteryChargeExecute).await;
match r {
Ok(b) => log::info!(" OK {:?}", b),
Err(e) => log::info!(" ERROR: {:?}", e),
}
}

call::call_number(
&mut client,
&mut pico,
Expand Down
76 changes: 76 additions & 0 deletions pico/pico-lib/src/battery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use atat::atat_derive::AtatCmd;
use atat::atat_derive::AtatEnum;
use atat::atat_derive::AtatResp;

// 3.2.52 AT+CBC Battery Charge
// AT+CBC
#[derive(Clone, Debug, AtatCmd)]
#[at_cmd("+CBC", BatteryChargeResponse)]
pub struct AtBatteryChargeExecute;

// +CBC: <bcs>,<bcl>,<voltage>
#[derive(Debug, Clone, AtatResp, PartialEq)]
pub struct BatteryChargeResponse {
#[at_arg(position = 0)]
pub bcs: BatteryStatus,
#[at_arg(position = 1)]
pub bcl: u8,
#[at_arg(position = 2)]
pub voltage: u32,
}

#[derive(Debug, Clone, PartialEq, AtatEnum)]
pub enum BatteryStatus {
NotCharging = 0,
Charging = 1,
ChargingFinished = 2,
}

#[cfg(test)]
mod tests {
use crate::cmd_serialization_tests;

use super::*;
use atat::AtatCmd;
use atat::heapless::String;

cmd_serialization_tests! {
test_at_battery_charge_execute: (
AtBatteryChargeExecute,
7,
"AT+CBC\r",
),
}

#[test]
fn test_network_registration_responses() {
let cmd = AtBatteryChargeExecute;

assert_eq!(
BatteryChargeResponse {
bcs: BatteryStatus::NotCharging,
bcl: 50,
voltage: 300,
},
cmd.parse(Ok(b"+CBC: 0,50,300\r\n")).unwrap()
);

assert_eq!(
BatteryChargeResponse {
bcs: BatteryStatus::Charging,
bcl: 75,
voltage: 450,
},
cmd.parse(Ok(b"+CBC: 1,75,450\r\n")).unwrap()
);

assert_eq!(
BatteryChargeResponse {
bcs: BatteryStatus::ChargingFinished,
bcl: 100,
voltage: 600,
},
cmd.parse(Ok(b"+CBC: 2,100,600\r\n")).unwrap()
);
}
}
1 change: 1 addition & 0 deletions pico/pico-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
extern crate alloc;

pub mod at;
pub mod battery;
pub mod call;
pub mod network;
pub mod poro;
Expand Down