Skip to content

Commit 4a18cbd

Browse files
committed
Add beam current to wall display
1 parent f908d2d commit 4a18cbd

File tree

7 files changed

+52
-8
lines changed

7 files changed

+52
-8
lines changed

app/components/InstrumentsDisplay.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
IfcInstrumentStatus,
55
IfcPVWSMessage,
66
IfcPVWSRequest,
7+
PVWSRequestType,
78
targetStation,
89
} from "@/app/types";
910
import useWebSocket from "react-use-websocket";
@@ -12,6 +13,7 @@ import { instListFromBytes } from "@/app/components/dehex_and_decompress";
1213
import {
1314
updateInstrumentRunstate,
1415
updateInstrumentRunstatePV,
16+
updateTargetStationBeamCurrent,
1517
} from "@/app/wall/utils";
1618
import TargetStation from "@/app/components/TargetStation";
1719
import ScienceGroup from "@/app/components/ScienceGroup";
@@ -52,6 +54,7 @@ export default function InstrumentsDisplay({
5254
const [data, setData] = useState<Array<targetStation>>([
5355
{
5456
targetStation: "Target Station 1",
57+
beamCurrentPv: "AC:TS1:BEAM:CURR",
5558
instruments: [
5659
{ name: "ALF" },
5760
{ name: "ARGUS" },
@@ -86,6 +89,7 @@ export default function InstrumentsDisplay({
8689
},
8790
{
8891
targetStation: "Target Station 2",
92+
beamCurrentPv: "AC:TS2:BEAM:CURR",
8993
instruments: [
9094
{ name: "CHIPIR" },
9195
{ name: "IMAT" },
@@ -146,10 +150,16 @@ export default function InstrumentsDisplay({
146150
shouldReconnect: (closeEvent) => true,
147151
});
148152

153+
const targetStationCurrentPvs = data.map((ts) => ts.beamCurrentPv).filter((pv) => pv !== undefined);
154+
149155
useEffect(() => {
150156
// On page load, subscribe to the instrument list as it's required to get each instrument's PV prefix.
151157
sendJsonMessage(instListSubscription);
152-
}, [sendJsonMessage]);
158+
sendJsonMessage({
159+
type: PVWSRequestType.subscribe,
160+
pvs: targetStationCurrentPvs,
161+
})
162+
}, [sendJsonMessage, targetStationCurrentPvs]);
153163

154164
useEffect(() => {
155165
// This is a PV update, it could be either the instlist or an instrument's runstate that has changed
@@ -161,25 +171,30 @@ export default function InstrumentsDisplay({
161171
const updatedPVName: string = updatedPV.pv;
162172
const updatedPVbytes: string | null | undefined = updatedPV.b64byt;
163173
let updatedPVvalue: string | null | undefined = updatedPV.text;
174+
let updatedPVnum: number | null | undefined = updatedPV.value;
164175

165176
if (updatedPVName == instListPV && updatedPVbytes != null) {
166177
const instListDict = instListFromBytes(updatedPVbytes);
167178
for (const instrument of instListDict) {
168179
setData((prev) => {
169180
return updateInstrumentRunstatePV(
170-
prev,
171-
instrument,
172-
runstatePV,
173-
sendJsonMessage,
181+
prev,
182+
instrument,
183+
runstatePV,
184+
sendJsonMessage,
174185
);
175186
});
176187
}
188+
} else if (targetStationCurrentPvs.includes(updatedPVName)) {
189+
setData((prev) => {
190+
return updateTargetStationBeamCurrent(prev, updatedPVName, updatedPVnum);
191+
});
177192
} else if (updatedPVvalue) {
178193
setData((prev) => {
179194
return updateInstrumentRunstate(prev, updatedPVName, updatedPVvalue);
180195
});
181196
}
182-
}, [lastJsonMessage, sendJsonMessage]);
197+
}, [lastJsonMessage, sendJsonMessage, targetStationCurrentPvs]);
183198

184199
return (
185200
<div>
@@ -198,6 +213,7 @@ export default function InstrumentsDisplay({
198213
key={targetStation.targetStation}
199214
name={targetStation.targetStation}
200215
instruments={targetStation.instruments}
216+
beamCurrent={targetStation.beamCurrent}
201217
/>
202218
);
203219
})}

app/components/JenkinsJobs.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default function JenkinsJobs() {
4141
const jobs: Array<IfcWallDisplayJob> = resData["jobs"].filter(
4242
(job) => job["color"] != "disabled",
4343
);
44-
console.log(jobs);
4544
setData(jobs);
4645
}
4746
fetchPosts();

app/components/TargetStation.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ it("renders targetstation unchanged", () => {
55
const { container } = render(
66
<TargetStation
77
name={"TS5"}
8+
beamCurrent={1234.5678}
89
instruments={[
910
{ name: "Instrument", runstate: "RESUMING" },
1011
{

app/components/TargetStation.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import { IfcInstrumentStatus } from "@/app/types";
55
export default function TargetStation({
66
name,
77
instruments,
8+
beamCurrent,
89
}: {
910
name: string;
1011
instruments: Array<IfcInstrumentStatus>;
12+
beamCurrent: number | null | undefined;
1113
}) {
1214
return (
1315
<div className="flex flex-col justify-center items-start w-full">
1416
<h1 className="w-full text-left text-gray-600 dark:text-gray-200 font-semibold text-md mt-2 py-2 ">
15-
{name}
17+
{name} {(beamCurrent !== undefined && beamCurrent !== null) ? ("- " + beamCurrent.toFixed(2) + " μA") : ""}
1618
</h1>
1719
<div className="flex flex-wrap gap-1">
1820
{instruments.map((instrument) => (

app/components/__snapshots__/TargetStation.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ exports[`renders targetstation unchanged 1`] = `
99
class="w-full text-left text-gray-600 dark:text-gray-200 font-semibold text-md mt-2 py-2 "
1010
>
1111
TS5
12+
13+
- 1234.57 μA
1214
</h1>
1315
<div
1416
class="flex flex-wrap gap-1"

app/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export interface ConfigOutputIocMacro {
149149

150150
export interface targetStation {
151151
targetStation: string;
152+
beamCurrentPv?: string;
153+
beamCurrent?: number | null;
152154
instruments: Array<IfcInstrumentStatus>;
153155
}
154156

app/wall/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ export function updateInstrumentRunstate(
2626
return newData;
2727
}
2828

29+
/**
30+
* Copy the original array, update the given target stations' beam current value, then return the copied array.
31+
* @param prev the previous array of target stations, containing instruments.
32+
* @param updatedPVName the runstate PV address
33+
* @param updatedPVvalue the runstate
34+
*/
35+
export function updateTargetStationBeamCurrent(
36+
prev: Array<targetStation>,
37+
updatedPVName: string,
38+
updatedPVvalue: number | null | undefined,
39+
) {
40+
const newData: Array<targetStation> = [...prev];
41+
42+
let foundTs = newData.find(
43+
(ts) => ts.beamCurrentPv === updatedPVName,
44+
);
45+
if (foundTs) {
46+
foundTs.beamCurrent = updatedPVvalue;
47+
}
48+
return newData;
49+
}
50+
2951
/**
3052
* Copy an original array then update an instrument's runstate PV, then subscribe to it. return the copied array.
3153
* @param prev the original array of target stations containing instrument runstate information

0 commit comments

Comments
 (0)