-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abb2988
commit 1a5fc5f
Showing
4 changed files
with
257 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -17,4 +17,5 @@ | |
pub mod data; | ||
pub mod mock; | ||
pub mod test_common; | ||
pub mod udp; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
use serde_json::json; | ||
|
||
pub fn get_lightning_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "ST-00000512", | ||
"type":"evt_strike", | ||
"hub_sn": "HB-00000001", | ||
"evt":[1493322445,27,3848] | ||
})) | ||
.expect("Failed to convert JSON to vector") | ||
} | ||
|
||
pub fn get_hub_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number":"HB-00013030", | ||
"type":"hub_status", | ||
"firmware_revision":"35", | ||
"uptime":1670133, | ||
"rssi":-62, | ||
"timestamp":1495724691, | ||
"reset_flags": "BOR,PIN,POR", | ||
"seq": 48, | ||
"fs": [1, 0, 15675411, 524288], | ||
"radio_stats": [2, 1, 0, 3, 2839], | ||
"mqtt_stats": [1, 0] | ||
})) | ||
.expect("Failured to convert JSON to vector") | ||
} | ||
|
||
pub fn get_device_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "AR-00004049", | ||
"type": "device_status", | ||
"hub_sn": "HB-00000001", | ||
"timestamp": 1510855923, | ||
"uptime": 2189, | ||
"voltage": 3.50, | ||
"firmware_revision": 17, | ||
"rssi": -17, | ||
"hub_rssi": -87, | ||
"sensor_status": 0, | ||
"debug": 0 | ||
})) | ||
.expect("Failed to convert JSON to vector") | ||
} | ||
|
||
pub fn get_station_observation_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "ST-00000512", | ||
"type": "obs_st", | ||
"hub_sn": "HB-00013030", | ||
"obs": [ | ||
[1588948614,0.18,0.22,0.27,144,6,1017.57,22.37,50.26,328,0.03,3,0.000000,0,0,0,2.410,1] | ||
], | ||
"firmware_revision": 129 | ||
})) | ||
.expect("Failured to convert JSON to vector") | ||
} | ||
|
||
pub fn get_secondary_station_observation_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "ST-00000513", | ||
"type": "obs_st", | ||
"hub_sn": "HB-00013030", | ||
"obs": [ | ||
[1588948614,0.18,0.22,0.27,144,6,1017.57,22.37,50.26,328,0.03,3,0.000000,0,0,0,2.410,1] | ||
], | ||
"firmware_revision": 129 | ||
})) | ||
.expect("Failured to convert JSON to vector") | ||
} | ||
|
||
pub fn get_rain_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "ST-00000512", | ||
"type":"evt_precip", | ||
"hub_sn": "HB-00000001", | ||
"evt":[1493322445] | ||
})) | ||
.expect("Failed to convert JSON to vector") | ||
} | ||
|
||
pub fn get_rapidwind_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "ST-00000512", | ||
"type":"rapid_wind", | ||
"hub_sn": "HB-00000001", | ||
"ob":[1493322445,2.3,128] | ||
})) | ||
.expect("Failed to convert JSON to vector") | ||
} | ||
|
||
pub fn get_air_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "ST-00000512", | ||
"type":"obs_air", | ||
"hub_sn": "HB-00000001", | ||
"obs":[[1493164835,835.0,10.0,45,0,0,3.46,1]], | ||
"firmware_revision": 17 | ||
})) | ||
.expect("Failed to convert JSON to vector") | ||
} | ||
|
||
pub fn get_sky_payload() -> Vec<u8> { | ||
serde_json::to_vec(&json!( | ||
{ | ||
"serial_number": "ST-00000512", | ||
"type":"obs_sky", | ||
"hub_sn": "HB-00000001", | ||
"obs":[[1493321340,9000,10,0.0,2.6,4.6,7.4,187,3.12,1,130,null,0,3]], | ||
"firmware_revision": 29 | ||
})) | ||
.expect("Failed to convert JSON to vector") | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
use rtempest::mock::MockSender; | ||
use rtempest::test_common::*; | ||
use rtempest::{data::EventType, udp::Tempest}; | ||
|
||
#[tokio::test] | ||
async fn udp() { | ||
let mock = MockSender::bind(); | ||
let mut receiver = Tempest::listen_udp().await; | ||
|
||
mock.send(get_rain_payload(), 50222); | ||
mock.send(get_lightning_payload(), 50222); | ||
mock.send(get_rapidwind_payload(), 50222); | ||
mock.send(get_air_payload(), 50222); | ||
mock.send(get_sky_payload(), 50222); | ||
mock.send(get_station_observation_payload(), 50222); | ||
mock.send(get_device_payload(), 50222); | ||
mock.send(get_hub_payload(), 50222); | ||
|
||
let mut success = vec![false; 8]; | ||
|
||
while let Some(event) = receiver.recv().await { | ||
match &event { | ||
EventType::Rain(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_timestamp() == 1493322445 { | ||
success[0] = true; | ||
println!("rain"); | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
EventType::Lightning(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_strike_energy() == 3848 { | ||
success[1] = true; | ||
println!("lightning"); | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
EventType::RapidWind(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_wind_direction() == 128 { | ||
println!("wind"); | ||
success[2] = true; | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
EventType::Air(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_hub_sn() == "HB-00000001" { | ||
success[3] = true; | ||
println!("air"); | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
EventType::Sky(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_hub_sn() == "HB-00000001" { | ||
success[4] = true; | ||
println!("sky"); | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
EventType::Observation(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_hub_sn() == "HB-00013030" { | ||
success[5] = true; | ||
println!("observation"); | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
EventType::DeviceStatus(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_rssi() == -17 { | ||
success[6] = true; | ||
println!("device"); | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
EventType::HubStatus(event_data) => { | ||
println!("{event_data}"); | ||
|
||
if event_data.get_uptime() == 1670133 { | ||
success[7] = true; | ||
println!("hub"); | ||
} | ||
|
||
if finished(&success) { | ||
println!("success"); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn finished(success: &Vec<bool>) -> bool { | ||
!success.contains(&false) | ||
} |