connect: rewrite initial_state and CommandSender

This commit is contained in:
awiouy 2018-02-17 10:15:09 +01:00
parent 15909613e9
commit 1cd7d4d145

View file

@ -64,16 +64,15 @@ fn now_ms() -> i64 {
} }
fn initial_state() -> State { fn initial_state() -> State {
{ let mut frame = protocol::spirc::State::new();
let mut msg = protocol::spirc::State::new(); frame.set_repeat(false);
msg.set_repeat(false); frame.set_shuffle(false);
msg.set_shuffle(false); frame.set_status(PlayStatus::kPlayStatusStop);
msg.set_status(PlayStatus::kPlayStatusStop); frame.set_position_ms(0);
msg.set_position_ms(0); frame.set_position_measured_at(0);
msg.set_position_measured_at(0); frame
msg
}
} }
fn initial_device_state(config: ConnectConfig, volume: u16) -> DeviceState { fn initial_device_state(config: ConnectConfig, volume: u16) -> DeviceState {
{ {
let mut msg = DeviceState::new(); let mut msg = DeviceState::new();
@ -718,17 +717,14 @@ struct CommandSender<'a> {
impl<'a> CommandSender<'a> { impl<'a> CommandSender<'a> {
fn new(spirc: &'a mut SpircTask, cmd: MessageType) -> CommandSender { fn new(spirc: &'a mut SpircTask, cmd: MessageType) -> CommandSender {
let frame = { let mut frame = protocol::spirc::Frame::new();
let mut msg = protocol::spirc::Frame::new(); frame.set_version(1);
msg.set_version(1); frame.set_protocol_version(::std::convert::Into::into("2.0.0"));
msg.set_protocol_version(::std::convert::Into::into("2.0.0")); frame.set_ident(spirc.ident.clone());
msg.set_ident(spirc.ident.clone()); frame.set_seq_nr(spirc.sequence.get());
msg.set_seq_nr(spirc.sequence.get()); frame.set_typ(cmd);
msg.set_typ(cmd); frame.set_device_state(spirc.device.clone());
msg.set_device_state(spirc.device.clone()); frame.set_state_update_id(now_ms());
msg.set_state_update_id(now_ms());
msg
};
CommandSender { CommandSender {
spirc: spirc, spirc: spirc,
frame: frame, frame: frame,