Added cert for convenience(it's public already) and and fleshed out on_match_list_update

master
noah metz 2024-01-21 01:24:16 -07:00
parent c6d4336abc
commit 4273d926a6
2 changed files with 95 additions and 39 deletions

@ -160,14 +160,8 @@ struct Event {
}
impl Event {
fn new() -> Event {
Event{
divisions: HashMap::new(),
}
}
fn recreate_match_list(self: &mut Event, msg: BackendMessage) {
self.divisions = HashMap::new();
fn from_match_list(msg: BackendMessage) -> Event {
let mut divisions: HashMap<i32, Division> = HashMap::new();
match msg.data.match_list {
Some(matches) => {
for m in matches.matches.iter() {
@ -178,7 +172,7 @@ impl Event {
match_num: m.r#match.unwrap(),
session: m.session.unwrap(),
};
match self.divisions.get_mut(&match_tuple.division) {
match divisions.get_mut(&match_tuple.division) {
Some(division) => {
division.matches.push(Match{
match_tuple: match_tuple.clone(),
@ -193,13 +187,16 @@ impl Event {
new_division.matches.push(Match{
match_tuple: match_tuple.clone(),
});
self.divisions.insert(match_tuple.division, new_division);
divisions.insert(match_tuple.division, new_division);
},
}
}
},
None => log::warn!("Parsed match list without match_list"),
}
};
return Event{
divisions,
};
}
}
@ -578,15 +575,15 @@ impl TMClient {
}
}
type NoticeCallback = fn(tm::Notice, Event) -> (Vec<MQTTMessage>, Event);
type NoticeCallback = fn(tm::Notice, Event, &TMConnection) -> (Vec<MQTTMessage>, Event);
fn get_game_score(scores: tm::MatchScore) -> Option<GameScore> {
if scores.alliances.len() != 2 {
return None;
}
let ref red_score = scores.alliances[0];
let ref blue_score = scores.alliances[1];
let ref _red_score = scores.alliances[0];
let ref _blue_score = scores.alliances[1];
// 1) Get the autonomous winner
// 2) Get score object and fill AllianceScore struct
@ -615,7 +612,7 @@ fn get_game_score(scores: tm::MatchScore) -> Option<GameScore> {
return Some(out);
}
fn on_score_change(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
fn on_score_change(notice: tm::Notice, event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
match notice.match_score {
None => return (Vec::new(), event),
Some(game_scores) => {
@ -636,44 +633,60 @@ fn on_score_change(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event
}
}
fn on_match_start(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_match_start(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_match_cancel(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_match_cancel(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_match_reset(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_match_reset(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_match_assigned(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_match_assigned(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_active_field_changed(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_active_field_changed(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_rankings_updated(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_rankings_updated(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_event_status_updated(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_event_status_updated(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_elim_alliance_update(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_elim_alliance_update(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_elim_unavail_teams_update(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_elim_unavail_teams_update(_notice: tm::Notice, _event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), _event);
}
fn on_match_list_update(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>, Event) {
return (Vec::new(), event);
fn on_match_list_update(_notice: tm::Notice, _event: Event, connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
let mut get_match_list_tuple = tm::MatchTuple::default();
get_match_list_tuple.division = Some(0);
get_match_list_tuple.round = None;
get_match_list_tuple.instance = Some(0);
get_match_list_tuple.r#match = Some(0);
get_match_list_tuple.session = Some(0);
let mut get_match_list_data = tm::BackendMessageData::default();
get_match_list_data.match_tuple = Some(get_match_list_tuple);
let get_match_list_req = BackendMessage::new(1002, get_match_list_data.clone());
connection.requests.send(Box::new(get_match_list_req)).unwrap();
let get_match_list_resp = connection.responses.recv().unwrap();
let new_event = Event::from_match_list(*get_match_list_resp);
return (Vec::new(), new_event);
}
fn main() {
@ -738,9 +751,7 @@ fn main() {
let get_match_list_resp = tm_connection.responses.recv().unwrap();
let mut event = Event::new();
event.recreate_match_list(*get_match_list_resp);
println!("Event after parse: {:?}", event);
let mut event = Event::from_match_list(*get_match_list_resp);
while running {
thread::sleep(Duration::from_millis(1000));
@ -755,7 +766,7 @@ fn main() {
}
},
Some(callback) => {
let (messages, next_event) = callback(*notice, event);
let (messages, next_event) = callback(*notice, event, &tm_connection);
event = next_event;
for message in messages {
let result = client.publish(message.topic, QoS::AtMostOnce, true, message.payload);

@ -0,0 +1,45 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAygkWe2HEe8/nk0YeY4GqGIKXnzSXnAvl0T8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