-
Notifications
You must be signed in to change notification settings - Fork 2
Misc fixes and changes #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
plaes
wants to merge
14
commits into
endticket:master
Choose a base branch
from
plaes:for-upstream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
154aae4
Clear the serialport and internal buffer in case of checksum errors
plaes f70ff24
protocol: Fix some clippy warnings
plaes cb5ca02
Disable libudev dependency requirement for serialport
plaes b5485c3
Bypass internal buffer, change min message length (#1)
kmuuk e15369f
client: add trace logging cases (#2)
kmuuk 0a67ade
cargo: Bump clap to 3.0.x
plaes fe27638
Bump clap to 3.0.x and update examples
plaes 6e7c840
Bump clap to 3.1 and update examples
plaes f270a53
Add a hacky implementation to query/set cctalk parameters
plaes c3ada0d
Drop redundant field names in struct initialization
plaes 221357d
Simplify code branching in the Message checksum validation
plaes be3d7f9
Fix some unneeded (de)referencing
plaes fa6d146
Use .is_empty() and proper bool checks in conditions
plaes 6295c34
Remove repetitive let statement
plaes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,99 @@ | ||
| use cctalk::{device::CCTalkDevice, protocol::ChecksumType}; | ||
| use clap::{value_t, App, Arg}; | ||
| use clap::{Arg, Command}; | ||
| use std::time::Duration; | ||
|
|
||
| const PROGRAM: Option<&'static str> = option_env!("CARGO_PKG_NAME"); | ||
| const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); | ||
| const DESCRIPTION: Option<&'static str> = option_env!("CARGO_PKG_DESCRIPTION"); | ||
|
|
||
| fn master_inhibit(dev: &str, id: u8, status: Option<&str>) { | ||
| let serial = serialport::new(dev, 9600) | ||
| .timeout(Duration::from_millis(500)) | ||
| .open() | ||
| .expect("Failed to open port"); | ||
|
|
||
| let serial_dev = Box::new(cctalk::client::SerialClient::new(serial, 1).unwrap()); | ||
| let mut cctalk = CCTalkDevice::new(serial_dev, id, ChecksumType::SimpleChecksum).unwrap(); | ||
|
|
||
| if let Some(b) = status { | ||
| let x = match b { | ||
| "1" => 1, | ||
| _ => 0, | ||
| }; | ||
| println!("{:?}", cctalk.modify_master_inhibit_status(x).unwrap()); | ||
| } | ||
| } | ||
|
|
||
| fn request_info(dev: &str, id: u8, field: Option<&str>) { | ||
| let serial = serialport::new(dev, 9600) | ||
| .timeout(Duration::from_millis(500)) | ||
| .open() | ||
| .expect("Failed to open port"); | ||
|
|
||
| let serial_dev = Box::new(cctalk::client::SerialClient::new(serial, 1).unwrap()); | ||
|
|
||
| let mut cctalk = CCTalkDevice::new(serial_dev, id, ChecksumType::SimpleChecksum).unwrap(); | ||
|
|
||
| match field { | ||
| Some("equipment_category_id") => { | ||
| println!("{:?}", cctalk.request_equipment_category().unwrap()); | ||
| } | ||
| _ => {} | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| env_logger::init(); | ||
|
|
||
| let matches = App::new(PROGRAM.unwrap_or("cctalk-host")) | ||
| let matches = Command::new(PROGRAM.unwrap_or("cctalk-host")) | ||
| .version(VERSION.unwrap_or("unknown")) | ||
| .about(DESCRIPTION.unwrap_or("")) | ||
| .arg( | ||
| Arg::with_name("serial") | ||
| .short("s") | ||
| Arg::new("serial") | ||
| .short('s') | ||
| .long("serial") | ||
| .value_name("DEVICE") | ||
| .help("Serial Device for ccTalk host (for example /dev/ttyUSB0 or COM3)") | ||
| .help("ccTalk serial device (for example /dev/ttyUSB0 or COM3)") | ||
| .takes_value(true) | ||
| .required(true), | ||
| ) | ||
| .arg( | ||
| Arg::with_name("target") | ||
| .short("t") | ||
| Arg::new("target") | ||
| .short('t') | ||
| .long("target") | ||
| .value_name("TARGET_ADDRESS") | ||
| .help("Address of the client device") | ||
| .default_value("2"), | ||
| ) | ||
| .subcommand( | ||
| Command::new("request") | ||
| .arg( | ||
| Arg::new("field") | ||
| //.possible_values(["manufacturer_id", "equipment_category_id", "serial_number"]) | ||
| .possible_values(["equipment_category_id"]), | ||
| ) | ||
| .about("Request information from device (status, manufacturer id, ...)"), | ||
| ) | ||
| .subcommand( | ||
| Command::new("set_master_inhibit").arg( | ||
| Arg::new("state") | ||
| .takes_value(true) | ||
| .possible_values(["1", "0"]) | ||
| .required(true), | ||
| ), | ||
| ) | ||
| .get_matches(); | ||
|
|
||
| let dev = matches.value_of("serial").unwrap(); | ||
| let _id: u8 = matches.value_of_t("target").unwrap_or_else(|e| e.exit()); | ||
|
|
||
| let target_device_id = value_t!(matches.value_of("target"), u8).unwrap_or_else(|e| e.exit()); | ||
|
|
||
| let serial = serialport::new(dev, 9600) | ||
| .timeout(Duration::from_millis(500)) | ||
| .open() | ||
| .expect("Failed to open port"); | ||
|
|
||
| // As per ccTalk general usage, there is usually single "master" | ||
| // which initiates the queries and its address is 1. | ||
| let serial_dev = Box::new(cctalk::client::SerialClient::new(serial, 1).unwrap()); | ||
|
|
||
| let mut cctalk = | ||
| CCTalkDevice::new(serial_dev, target_device_id, ChecksumType::SimpleChecksum).unwrap(); | ||
|
|
||
| println!("Querying client device: {}", target_device_id); | ||
|
|
||
| let resp = cctalk.request_equipment_category().unwrap(); | ||
|
|
||
| println!("{}", resp); | ||
| match matches.subcommand() { | ||
| Some(("request", sub_matches)) => request_info(dev, _id, sub_matches.value_of("field")), | ||
| Some(("set_master_inhibit", sub_matches)) => { | ||
| master_inhibit(dev, _id, sub_matches.value_of("state")); | ||
| } | ||
| _ => { | ||
| println!("Expecting subcommand..."); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think by removing this you actually made
self.buffertotally useless: it is never written, only read, but it will always be empty. The whole idea of this buffer was to support partial messages. On my experience it was possible to receive partial messages inread_and_decode, that's why we had to save it in a buffer and append the next message to it and do the decoding on the merged message (not just the currently received stuff).Of course it might be possible that your device is never sending these partial messages, and you have no need for this. But are you sure you have to remove this functionality? Is it causing a problem for you, or you just wanted to simplify things?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this buffer thing was something we really struggled with whenever we connected our Coin Acceptor to the cctalk bus and received the data mid-packet.
Right now we have 30+ coin-acceptor devices working 24/7 and we haven't seen any issues on cctalk side.
@kmuuk Ideas?