-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.js
188 lines (151 loc) · 5.73 KB
/
help.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const Fi_list =
[
{ "val": 0b0000, "F": 372, "fmax": 4 },
{ "val": 0b0001, "F": 372, "fmax": 5 },
{ "val": 0b0010, "F": 558, "fmax": 6 },
{ "val": 0b0011, "F": 774, "fmax": 8 },
{ "val": 0b0100, "F": 1116, "fmax": 12 },
{ "val": 0b0101, "F": 1488, "fmax": 16 },
{ "val": 0b0110, "F": 1860, "fmax": 20 },
{ "val": 0b1001, "F": 512, "fmax": 5 },
{ "val": 0b1010, "F": 768, "fmax": 7.5 },
{ "val": 0b1011, "F": 1024, "fmax": 10 },
{ "val": 0b1100, "F": 1536, "fmax": 15 },
{ "val": 0b1101, "F": 2048, "fmax": 20 },
];
const Di_list =
[
{ "val": 0b0001, "D": 1 },
{ "val": 0b0010, "D": 2 },
{ "val": 0b0011, "D": 4 },
{ "val": 0b0100, "D": 8 },
{ "val": 0b1000, "D": 12 },
{ "val": 0b0101, "D": 16 },
{ "val": 0b1001, "D": 20 },
{ "val": 0b0110, "D": 32 },
{ "val": 0b0111, "D": 64 },
];
function populate_Fi() {
Fi_list.forEach((x) => {
var select = document.getElementById("params_Fi");
var text = `F=${x.F}, fmax=${x.fmax}MHz`;
var el = document.createElement("option");
el.value = x.val;
el.innerText = text;
select.appendChild(el);
});
}
function populate_Di() {
Di_list.forEach((x) => {
var select = document.getElementById("params_Di");
var text = `D=${x.D}`;
var el = document.createElement("option");
el.value = x.val;
el.innerText = text;
select.appendChild(el);
});
}
function calc_baud(Fi, Di){
var info1 = Fi_list.find((x) => (x.val == Fi));
var info2 = Di_list.find((x) => (x.val == Di));
var F = info1.F;
var fmax = info1.fmax * 1e6;
var D = info2.D;
var baud = (fmax * D) / F;
return baud.toFixed(0);
}
function params_changed(ev) {
var Fi_el = document.getElementById("params_Fi");
var Di_el = document.getElementById("params_Di");
var Fi = Fi_el.value;
var Di = Di_el.value;
var maxbaud = calc_baud(Fi, Di);
var text_el = document.getElementById("baud_text");
text_el.innerText = `${maxbaud} bits/s max`;
}
function add_baud_calc() {
var targets = ["#params_Fi", "#params_Di"];
targets.forEach((x) => {
$(x).on("change", params_changed).trigger("change");
});
}
function add_enablers() {
var enable_targets =
[
{ "target": "#params_active", "text": ["#params_active~.form-check-label"], "inputs": ["#params_Fi", "#params_Di"] },
{ "target": "#egt_active", "text": ["#egt_active~.form-check-label"], "inputs": ["#egt"] },
{ "target": "#negotiate_mode_active", "text": ["#negotiate_mode_active~.form-check-label", "#use_speed_param_active~.form-check-label", "#preferred_proto_active~.form-check-label"], "inputs": ["#negotiate_mode", "#use_speed_param", "#preferred_proto"] },
{ "target": "#clockstop_active", "text": ["#clockstop_active~.form-check-label", "#class_active~.form-check-label"], "inputs": ["#clockstop", "#class_a_enable", "#class_b_enable", "#class_c_enable"] },
{ "target": "#hist_active", "text": ["#hist_active~.form-check-label"], "inputs": ["#histtext"] },
{ "target": "#Teq0_wti_active", "text": ["#Teq0_wti_active~.form-check-label"], "inputs": ["#Teq0_wti"] },
{ "target": "#Teq1_ifsc_active", "text": ["#Teq1_ifsc_active~.form-check-label"], "inputs": ["#Teq1_ifsc"] },
{ "target": "#Teq1_cwi_active", "text": ["#Teq1_cwi_active~.form-check-label", "#Teq1_bwi_active~.form-check-label"], "inputs": ["#Teq1_cwi", "#Teq1_bwi"] },
{ "target": "#Teq1_redundancy_active", "text": ["#Teq1_redundancy_active~.form-check-label"], "inputs": ["#Teq1_redundancy"] },
];
var text_disable_class = "text-disable";
enable_targets.forEach((x) => {
$(x.target).on("change", (e) => {
var active = e.target.checked;
x.text.forEach((sel) => {
var el = document.querySelector(sel);
if (!active) {
el.classList.add(text_disable_class);
}
else {
el.classList.remove(text_disable_class);
}
});
x.inputs.forEach((sel) => {
var el = document.querySelector(sel);
el.disabled = !active;
});
}).trigger("change");
});
}
function protocol_collapses() {
var collapse_targets = [
{ "check": "#Teq0_check", "collapse": "#Teq0_collapse" },
{ "check": "#Teq1_check", "collapse": "#Teq1_collapse" },
];
collapse_targets.forEach((x) => {
$(x.check).on("change", (e) => {
var active = e.target.checked;
var collapse = new bootstrap.Collapse(x.collapse, {
toggle: false
});
if (active) {
collapse.show();
}
else {
collapse.hide();
}
update_proto_list();
});
});
}
function update_proto_list() {
var protos = [
{ "proto": 0, "check": "#Teq0_check" },
{ "proto": 1, "check": "#Teq1_check" },
];
var list_el = document.querySelector("#preferred_proto");
list_el.innerHTML = ""; // clear options
protos.forEach((x) => {
var check_el = document.querySelector(x.check);
var active = check_el.checked;
if (active) {
var el = document.createElement("option");
el.value = x.proto;
el.text = x.proto;
list_el.appendChild(el);
}
});
}
function onload() {
populate_Fi();
populate_Di();
add_baud_calc();
add_enablers();
protocol_collapses();
}
$(window).on('load', onload);