Skip to content

Commit 4283d6c

Browse files
committed
Merge branch 'main' into fix/TSP-1130
2 parents c375d1f + 9b95164 commit 4283d6c

File tree

23 files changed

+541
-137
lines changed

23 files changed

+541
-137
lines changed

kic-script-gen/src/back_end/client_server.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use actix_ws::{Message, Session};
44
use futures::StreamExt;
55
use script_gen_manager::script_component::script::ScriptModel;
66
use serde::{Deserialize, Serialize};
7+
use std::collections::HashMap;
78
use std::sync::Arc;
89
use tokio::sync::{broadcast, Mutex};
910

@@ -101,6 +102,7 @@ async fn ws_index(
101102
app_state: web::Data<Arc<AppState>>,
102103
) -> Result<HttpResponse, Error> {
103104
let (response, mut session, mut msg_stream) = actix_ws::handle(&req, body)?;
105+
//msg_stream = msg_stream.max_frame_size(50 * 1024 * 1024); // 50MB
104106

105107
// Use the app_state here
106108
{
@@ -110,6 +112,8 @@ async fn ws_index(
110112

111113
let gen_script_tx = app_state.gen_script_tx.clone();
112114

115+
let mut chunk_buffers: HashMap<String, Vec<Option<String>>> = HashMap::new();
116+
113117
actix_web::rt::spawn(async move {
114118
while let Some(Ok(msg)) = msg_stream.next().await {
115119
match msg {
@@ -118,8 +122,55 @@ async fn ws_index(
118122
return;
119123
}
120124
}
121-
Message::Text(msg) => {
122-
// println!("Received input from client in session: {msg}");
125+
Message::Text(mut msg) => {
126+
let mut is_chunked = false;
127+
{
128+
use serde_json::Value;
129+
if let Ok(value) = serde_json::from_str::<Value>(&msg) {
130+
if let (
131+
Some(msg_id),
132+
Some(chunk_index),
133+
Some(total_chunks),
134+
Some(data),
135+
) = (
136+
value.get("msg_id").and_then(|v| v.as_str()),
137+
value.get("chunk_index").and_then(|v| v.as_u64()),
138+
value.get("total_chunks").and_then(|v| v.as_u64()),
139+
value.get("data").and_then(|v| v.as_str()),
140+
) {
141+
is_chunked = true;
142+
let entry = chunk_buffers
143+
.entry(msg_id.to_string())
144+
.or_insert_with(|| vec![None; total_chunks as usize]);
145+
entry[chunk_index as usize] = Some(data.to_string());
146+
if entry.iter().all(|c| c.is_some()) {
147+
let full_msg = entry
148+
.iter()
149+
.map(|c| c.as_ref().unwrap().as_str())
150+
.collect::<String>();
151+
chunk_buffers.remove(msg_id);
152+
println!(
153+
"Received complete chunked message of size: {} bytes",
154+
full_msg.len()
155+
);
156+
msg = full_msg.into();
157+
} else {
158+
println!(
159+
"Received chunk {}/{} for msg_id {}",
160+
chunk_index + 1,
161+
total_chunks,
162+
msg_id
163+
);
164+
continue;
165+
}
166+
}
167+
}
168+
}
169+
// --- End chunked message reassembly logic ---
170+
// Only fall through to normal processing if not a chunked message or if chunk is complete
171+
if is_chunked && msg.is_empty() {
172+
continue;
173+
}
123174
match serde_json::from_str::<IpcData>(&msg) {
124175
Ok(ipc_data) => {
125176
if ipc_data.request_type == "get_data" {
@@ -128,7 +179,6 @@ async fn ws_index(
128179
let mut data_model = app_state.data_model.lock().await;
129180
let response =
130181
data_model.process_data_from_client(ipc_data.json_value);
131-
println!("processed data from client {response}");
132182
// Send generate script signal
133183
if let Err(e) = gen_script_tx.send(()) {
134184
eprintln!("Failed to send signal: {e}");
@@ -173,6 +223,7 @@ async fn ws_index(
173223
_ => (),
174224
}
175225
}
226+
println!("WebSocket message loop ended - connection lost or closed");
176227
});
177228

178229
Ok(response)

kic-script-gen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use script_gen_manager::{catalog, script_component::script::ScriptModel};
33

44
#[actix_web::main]
55
async fn main() -> anyhow::Result<()> {
6-
eprintln!("Welcome to KIC Script Generator!");
6+
println!("Welcome to KIC Script Generator!");
77

88
let mut catalog = catalog::Catalog::new();
99
catalog.refresh_function_metadata();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
"ts-node": "^10.9.2",
2626
"typescript": "^5.3.3"
2727
}
28-
}
28+
}

script-gen-manager/src/instr_metadata/mpsu50_metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ impl Mpsu50Metadata {
2727

2828
base.add_range("source.limiti".to_string(), 0.01, 5.1);
2929

30+
base.add_range("source.step_to_sweep_delay".to_string(), 0.0, 100.0);
31+
3032
// Add region maps
3133
// when pulse mode is off
3234
let exclude_i = NumberLimit::new(-10.0e-9, 10.0e-9, false, None);

script-gen-manager/src/instr_metadata/msmu60_metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ impl Msmu60Metadata {
4646
base.add_range("source.limiti".to_string(), -1e-8, 1.515);
4747
base.add_range("source.limitv".to_string(), -0.02, 60.6);
4848

49+
base.add_range("source.step_to_sweep_delay".to_string(), 0.0, 100.0);
50+
4951
// Add region maps
5052
// when pulse mode is off
5153
let exclude_v = Some(NumberLimit::new(-0.01, 0.01, false, None));

script-gen-manager/src/model/sweep_data/parameters.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ impl ParameterFloat {
5050
unit,
5151
}
5252
}
53+
54+
pub fn limit(&mut self, min: f64, max: f64) {
55+
if self.value >= min && self.value <= max {
56+
return;
57+
} else if self.value < min {
58+
self.value = min
59+
} else {
60+
self.value = max
61+
}
62+
}
5363
}
5464

5565
impl ParameterString {

script-gen-manager/src/model/sweep_data/sweep_config.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::HashMap;
33

44
use crate::{
55
device::Device,
6+
instr_metadata::{base_metadata::Metadata, enum_metadata::MetadataEnum},
67
model::{
78
chan_data::{
89
bias_channel::BiasChannel, step_channel::StepChannel, sweep_channel::SweepChannel,
@@ -370,9 +371,27 @@ impl SweepConfig {
370371
.sweep_timing_config
371372
.measure_count
372373
.limit(1, 60000);
374+
375+
// Validating Step to Sweep Delay
376+
if !self.step_channels.is_empty() {
377+
let device_metadata = self.step_channels[0]
378+
.start_stop_channel
379+
.common_chan_attributes
380+
.device
381+
.get_metadata();
382+
if let Some((min, max)) =
383+
self.get_range_limits(&device_metadata, "source.step_to_sweep_delay")
384+
{
385+
self.step_global_parameters
386+
.step_to_sweep_delay
387+
.limit(min, max);
388+
}
389+
}
390+
373391
for bias_channel in &mut self.bias_channels {
374392
bias_channel.evaluate();
375393
}
394+
376395
for step_channel in &mut self.step_channels {
377396
step_channel
378397
.start_stop_channel
@@ -383,18 +402,6 @@ impl SweepConfig {
383402
.start_stop_channel
384403
.evaluate(self.sweep_global_parameters.sweep_points.value as usize);
385404
}
386-
387-
// Check if only bias channels exist and display appropriate message
388-
// if !self.bias_channels.is_empty()
389-
// && self.step_channels.is_empty()
390-
// && self.sweep_channels.is_empty()
391-
// {
392-
// self.status_msg = Some(StatusMsg::new(
393-
// StatusType::Warning,
394-
// String::from("Only bias channels are configured. Please add a step or sweep channel to generate a functional script."),
395-
// ));
396-
// println!("Warning: Only bias channels are configured. Please add a step or sweep channel to generate a functional script.");
397-
// }
398405
}
399406

400407
pub fn update_channel_devices(&mut self) {
@@ -593,6 +600,14 @@ impl SweepConfig {
593600
}
594601
}
595602

603+
fn get_range_limits(&self, metadata: &MetadataEnum, key: &str) -> Option<(f64, f64)> {
604+
match metadata {
605+
MetadataEnum::Base(base_metadata) => base_metadata.get_range(key),
606+
MetadataEnum::Msmu60(msmu60_metadata) => msmu60_metadata.get_range(key),
607+
MetadataEnum::Mpsu50(mpsu50_metadata) => mpsu50_metadata.get_range(key),
608+
}
609+
}
610+
596611
pub fn reset(&mut self) {
597612
*self = SweepConfig::new();
598613
}

0 commit comments

Comments
 (0)