checkpointing

This commit is contained in:
John Goerzen 2020-09-20 19:36:04 -05:00
parent 4b6543700d
commit 77959423e8
3 changed files with 39 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2019 John Goerzen <jgoerzen@complete.org
Copyright (C) 2019-2020 John Goerzen <jgoerzen@complete.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,16 +22,16 @@ use log::*;
use std::thread;
mod ser;
mod lorastik;
mod xb;
mod xbpacket;
mod pipe;
mod ping;
mod kiss;
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "lorapipe", about = "Tools for LoRa radios", author = "John Goerzen <jgoerzen@complete.org>")]
#[structopt(name = "xbnet", about = "Networking for XBee Radios", author = "John Goerzen <jgoerzen@complete.org>")]
struct Opt {
/// Activate debug mode
// short and long flags (-d, --debug) will be deduced from the field's name

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2019 John Goerzen <jgoerzen@complete.org
Copyright (C) 2019-2020 John Goerzen <jgoerzen@complete.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -16,7 +16,8 @@
*/
use std::io;
use crate::lorastik::{LoraStik, ReceivedFrames};
use crate::xb::*;
use crate::xbpacket::*;
use crossbeam_channel;
use std::thread;
use std::time::Duration;

View File

@ -58,7 +58,7 @@ pub struct XBTXRequest<'a> {
pub payload: &'a [u8],
}
impl XBTXRequest {
impl<'a> XBTXRequest<'a> {
pub fn serialize(&self) -> Result<Bytes, TXGenError> {
if self.payload.is_empty() {
return Err(TXGenError::InvalidLen);
@ -104,7 +104,7 @@ impl XBTXRequest {
/// Calculate an XBee checksum over a slice
pub fn xbchecksum(data: &[u8]) -> u8 {
let sumu64 = data.into_iter().map(|x| u64::from(x)).sum();
let sumu64: u64 = data.into_iter().map(|x| u64::from(*x)).sum();
0xffu8 - (sumu64 as u8)
}
@ -137,3 +137,33 @@ pub fn mac48to64(mac48: &[u8; 6], pattern64: u64) -> u64 {
mac64
}
/** Convert the given data into zero or more packets for transmission.
We create a leading byte that indicates how many more XBee packets are remaining
for the block. When zero, the receiver should process the accumulated data. */
pub fn packetize_data(maxpacketsize: usize, dest: XBDestAddr, data: &[u8]) -> Result<Vec<XBTXRequest>, String> {
let mut retval = Vec::new();
if data.is_empty() {
return retval;
}
let chunks: Vec<&[u8]> = data.chunks(maxpacketsize - 1).collect();
let mut chunks_remaining: u8 = u8::try_from(chunks.len() - 1).map_err(|e| String::from("More than 255 chunks to transmit"))?;
for chunk in chunks {
let mut payload = Bytes::new();
payload.push_u8(chunks_remaining);
payload.push_slice(chunk);
let packet = XBTXRequest{
frame_id: 0,
dest_addr: dest,
broadcast_radius: 0,
transmit_options: 0,
payload
};
retval.push(packet);
chunks_remaining -= 1;
}
Ok(retval)
}