Skip to content

Commit db96b56

Browse files
committed
bar
1 parent ba139e3 commit db96b56

File tree

7 files changed

+76
-57
lines changed

7 files changed

+76
-57
lines changed

app/components/Block.tsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ export default function Block({
2323
}
2424
if (pv.value != currentValue) {
2525
setCurrentValue(pv.value);
26-
// Let the user know a change has occurred by lighting up the green dot next to the value
27-
const pvChangedIndicator = document.getElementById(
28-
pv.human_readable_name + "_CIRCLE",
29-
);
30-
if (!pvChangedIndicator) return;
31-
if (pvChangedIndicator.classList.contains("text-green-500")) return;
32-
pvChangedIndicator.classList.remove("text-transparent");
33-
pvChangedIndicator.classList.add("text-green-500");
34-
setTimeout(() => {
35-
pvChangedIndicator.classList.remove("text-green-500");
36-
pvChangedIndicator.classList.add("text-transparent");
37-
}, 2000);
3826
}
3927

4028
const minimum_date_to_be_shown = 631152000; // This is what PVWS thinks epoch time is for some reason. don't bother showing it as the instrument wasn't running EPICS on 01/01/1990
@@ -71,15 +59,6 @@ export default function Block({
7159
{showAdvanced && "Readback: "}
7260
{pv.value} {pv.units != null && pv.units}
7361
</span>
74-
<svg
75-
id={pv.human_readable_name + "_CIRCLE"}
76-
className="min-w-2 min-h-2 max-w-2 max-h-2 transition-all text-transparent"
77-
xmlns="http://www.w3.org/2000/svg"
78-
fill="currentColor"
79-
viewBox="0 0 24 24"
80-
>
81-
<circle cx="12" cy="12" r="12" />
82-
</svg>
8362
</div>
8463

8564
{showAdvanced && (

app/components/CheckToggle.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Dispatch, SetStateAction } from "react";
1+
import { Dispatch, SetStateAction, useCallback } from "react";
2+
import { memo } from "react";
23

3-
export default function CheckToggle({
4+
const CheckToggle = memo(function CheckToggle({
45
checked,
56
setChecked,
67
text,
@@ -11,20 +12,24 @@ export default function CheckToggle({
1112
text: string;
1213
textColour?: string;
1314
}) {
15+
const callback = useCallback(() => {
16+
setChecked(!checked);
17+
}, [checked, setChecked]);
18+
1419
return (
1520
<div className="pt-4">
1621
<label className="inline-flex items-center cursor-pointer">
1722
<input
1823
type="checkbox"
1924
checked={checked}
20-
onChange={() => {
21-
setChecked(!checked);
22-
}}
25+
onChange={callback}
2326
className="sr-only peer"
2427
/>
2528
<div className="relative w-11 h-6 bg-gray-200 rounded-full peer peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
2629
<span className={"ms-3 text-sm font-medium " + textColour}>{text}</span>
2730
</label>
2831
</div>
2932
);
30-
}
33+
});
34+
35+
export default CheckToggle;

app/components/Group.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import Block from "./Block";
22
import { checkIfAllBlocksInGroupAreHidden } from "./GroupUtils";
33

44
import { tBlockMapping } from "@/app/types";
5+
import { memo } from "react";
56

6-
export default function Group({
7+
const Group = memo(function Group({
78
group,
89
blocks,
910
instName,
@@ -51,4 +52,6 @@ export default function Group({
5152
</table>
5253
</div>
5354
);
54-
}
55+
});
56+
57+
export default Group;

app/components/Instrument.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class Instrument {
2323
this.prefix = prefix;
2424
this.dashboard_prefix = `${this.prefix}${DASHBOARD}`;
2525

26-
this.dashboard.set(`${this.prefix}DAE:WD_TITLE`, {
26+
this.dashboard.set(`${this.prefix}DAE:WDTITLE`, {
2727
pvaddress: `${this.prefix}DAE:WDTITLE`,
2828
});
2929
this.dashboard.set(`${this.prefix}DAE:WDUSERS`, {
@@ -161,6 +161,14 @@ export class Instrument {
161161
);
162162
}
163163

164+
clone(): Instrument {
165+
let cloned = new Instrument(this.prefix);
166+
cloned.groups = structuredClone(this.groups);
167+
cloned.runInfoPVs = structuredClone(this.runInfoPVs);
168+
cloned.dashboard = structuredClone(this.dashboard);
169+
return cloned;
170+
}
171+
164172
getAllBlockPVs(): Array<string> {
165173
const blocksPerGroup = Array.from(this.groups.values());
166174
return Array.from(blocksPerGroup)

app/components/InstrumentData.tsx

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import {useEffect, useRef, useState} from "react";
2+
import { RefObject, useEffect, useRef, useState } from "react";
33
import { IfcPVWSMessage, IfcPVWSRequest, PVWSRequestType } from "@/app/types";
44
import {
55
findPVInGroups,
@@ -46,7 +46,7 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
4646
}
4747
}, [instName]);
4848

49-
let messageQueue = useRef([]);
49+
let messageQueue: RefObject<Array<IfcPVWSMessage>> = useRef([]);
5050

5151
const {
5252
sendJsonMessage,
@@ -67,6 +67,7 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
6767
const prefix = getPrefix(instListFromBytes(updatedPVbytes), instName);
6868
const instrument = new Instrument(prefix);
6969
setCurrentInstrument(instrument);
70+
messageQueue.current = [];
7071

7172
// subscribe to dashboard and run info PVs
7273
sendJsonMessage({
@@ -75,14 +76,10 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
7576
.concat(Array.from(instrument.dashboard.keys()))
7677
.concat([`${prefix}${CONFIG_DETAILS}`]),
7778
});
78-
return;
79-
}
80-
81-
if (!currentInstrument) {
82-
return;
8379
}
8480

8581
if (
82+
currentInstrument &&
8683
updatedPVName == `${currentInstrument.prefix}${CONFIG_DETAILS}` &&
8784
updatedPVbytes != null
8885
) {
@@ -91,18 +88,22 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
9188
// config hasnt actually changed so do nothing
9289
return;
9390
}
94-
setLastUpdate(updatedPVbytes);
95-
currentInstrument.groups = getGroupsWithBlocksFromConfigOutput(
96-
currentInstrument.prefix,
91+
let newInstrument = currentInstrument.clone();
92+
newInstrument.groups = getGroupsWithBlocksFromConfigOutput(
93+
newInstrument.prefix,
9794
JSON.parse(dehex_and_decompress(atob(updatedPVbytes))),
9895
);
9996

10097
sendJsonMessage({
10198
type: PVWSRequestType.subscribe,
102-
pvs: currentInstrument.getAllBlockPVs(),
99+
pvs: newInstrument.getAllBlockPVs(),
103100
});
101+
102+
setLastUpdate(updatedPVbytes);
103+
setCurrentInstrument(newInstrument);
104104
} else {
105-
messageQueue.current.push(m);
105+
console.log(updatedPV.b64byt);
106+
messageQueue.current.push(updatedPV);
106107
}
107108
},
108109
onError: () => {
@@ -118,27 +119,37 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
118119

119120
useEffect(() => {
120121
const interval = setInterval(() => {
121-
console.log("Process " + messageQueue.current.length + " queued messages");
122+
if (currentInstrument == null) {
123+
return;
124+
}
125+
console.log(
126+
"Process " + messageQueue.current.length + " queued messages",
127+
);
128+
129+
let newInstrument = currentInstrument.clone();
130+
122131
while (true) {
123-
const m = messageQueue.current.pop();
124-
if (m === undefined) {
132+
const updatedPV = messageQueue.current.shift();
133+
if (updatedPV === undefined) {
125134
break;
126135
}
127-
const updatedPV: IfcPVWSMessage = JSON.parse(m.data);
128136
const updatedPVName: string = updatedPV.pv;
129137

130138
const pvVal = getPvValue(updatedPV);
131139

132140
if (pvVal == undefined) {
133-
console.debug(`initial/blank message from ${updatedPVName}`);
134-
return;
141+
console.debug(
142+
`initial/blank message from ${updatedPVName}: ${updatedPV.b64byt}}`,
143+
);
144+
continue;
135145
}
136146

137147
// Check if this is a dashboard, run info, or block PV update.
138148
const pv =
139-
currentInstrument.dashboard.get(updatedPVName) ||
140-
currentInstrument.runInfoPVs.get(updatedPVName) ||
141-
findPVInGroups(currentInstrument.groups, updatedPVName);
149+
newInstrument.dashboard.get(updatedPVName) ||
150+
newInstrument.runInfoPVs.get(updatedPVName) ||
151+
findPVInGroups(newInstrument.groups, updatedPVName);
152+
142153
if (pv) {
143154
storePrecision(updatedPV, pv);
144155
pv.value = toPrecision(pv, pvVal);
@@ -150,21 +161,21 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
150161
// its object such as its run control status or SP:RBV
151162
if (updatedPVName.endsWith(RC_INRANGE)) {
152163
const underlyingBlock = findPVInGroups(
153-
currentInstrument.groups,
164+
newInstrument.groups,
154165
updatedPVName.replace(RC_INRANGE, ""),
155166
);
156167
if (underlyingBlock)
157168
underlyingBlock.runcontrol_inrange = yesToBoolean(pvVal);
158169
} else if (updatedPVName.endsWith(RC_ENABLE)) {
159170
const underlyingBlock = findPVInGroups(
160-
currentInstrument.groups,
171+
newInstrument.groups,
161172
updatedPVName.replace(RC_ENABLE, ""),
162173
);
163174
if (underlyingBlock)
164175
underlyingBlock.runcontrol_enabled = yesToBoolean(pvVal);
165176
} else if (updatedPVName.endsWith(SP_RBV)) {
166177
const underlyingBlock = findPVInGroups(
167-
currentInstrument.groups,
178+
newInstrument.groups,
168179
updatedPVName.replace(SP_RBV, ""),
169180
);
170181
if (underlyingBlock)
@@ -176,7 +187,8 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
176187
}
177188
}
178189
}
179-
}, 5000);
190+
setCurrentInstrument(newInstrument);
191+
}, 1000);
180192
return () => clearInterval(interval);
181193
}, [currentInstrument]);
182194

app/components/TopBar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66

77
import { tBlockMapping } from "@/app/types";
88
import { DASHBOARD } from "@/app/components/Instrument";
9+
import { memo } from "react";
910

1011
export const runStateStr = "Run state";
1112
export const configName = "Config name";
@@ -18,7 +19,7 @@ export function getRunstate(prefix: string, runInfoPVs: tBlockMapping): string {
1819
return UNREACHABLE;
1920
}
2021

21-
export default function TopBar({
22+
const TopBar = memo(function TopBar({
2223
dashboard,
2324
instName,
2425
runInfoPVs,
@@ -151,4 +152,6 @@ export default function TopBar({
151152
</div>
152153
</div>
153154
);
154-
}
155+
});
156+
157+
export default TopBar;

next.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ const nextConfig: NextConfig = {
66
images: {
77
unoptimized: true,
88
},
9+
// compress: false,
10+
// webpack(webpackConfig) {
11+
// return {
12+
// ...webpackConfig,
13+
// optimization: {
14+
// minimize: false,
15+
// },
16+
// };
17+
// },
918
};
1019

1120
module.exports = nextConfig;

0 commit comments

Comments
 (0)