Skip to content

Commit 11f7368

Browse files
authored
Merge pull request #108 from ISISComputingGroup/beam_current_wall_display
Add beam current to wall display
2 parents fb8fbb5 + 263e0c5 commit 11f7368

File tree

8 files changed

+72
-2
lines changed

8 files changed

+72
-2
lines changed

app/components/InstrumentsDisplay.tsx

Lines changed: 24 additions & 0 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";
@@ -49,9 +51,13 @@ export default function InstrumentsDisplay({
4951
}) {
5052
const runstatePV = "DAE:RUNSTATE_STR";
5153

54+
const ts1BeamCurrentPv = "AC:TS1:BEAM:CURR";
55+
const ts2BeamCurrentPv = "AC:TS2:BEAM:CURR";
56+
5257
const [data, setData] = useState<Array<targetStation>>([
5358
{
5459
targetStation: "Target Station 1",
60+
beamCurrentPv: ts1BeamCurrentPv,
5561
instruments: [
5662
{ name: "ALF" },
5763
{ name: "ARGUS" },
@@ -86,6 +92,7 @@ export default function InstrumentsDisplay({
8692
},
8793
{
8894
targetStation: "Target Station 2",
95+
beamCurrentPv: ts2BeamCurrentPv,
8996
instruments: [
9097
{ name: "CHIPIR" },
9198
{ name: "IMAT" },
@@ -149,6 +156,10 @@ export default function InstrumentsDisplay({
149156
useEffect(() => {
150157
// On page load, subscribe to the instrument list as it's required to get each instrument's PV prefix.
151158
sendJsonMessage(instListSubscription);
159+
sendJsonMessage({
160+
type: PVWSRequestType.subscribe,
161+
pvs: [ts1BeamCurrentPv, ts2BeamCurrentPv],
162+
});
152163
}, [sendJsonMessage]);
153164

154165
useEffect(() => {
@@ -161,6 +172,7 @@ export default function InstrumentsDisplay({
161172
const updatedPVName: string = updatedPV.pv;
162173
const updatedPVbytes: string | null | undefined = updatedPV.b64byt;
163174
let updatedPVvalue: string | null | undefined = updatedPV.text;
175+
let updatedPVnum: number | null | undefined = updatedPV.value;
164176

165177
if (updatedPVName == instListPV && updatedPVbytes != null) {
166178
const instListDict = instListFromBytes(updatedPVbytes);
@@ -174,6 +186,17 @@ export default function InstrumentsDisplay({
174186
);
175187
});
176188
}
189+
} else if (
190+
updatedPVName == ts1BeamCurrentPv ||
191+
updatedPVName == ts2BeamCurrentPv
192+
) {
193+
setData((prev) => {
194+
return updateTargetStationBeamCurrent(
195+
prev,
196+
updatedPVName,
197+
updatedPVnum,
198+
);
199+
});
177200
} else if (updatedPVvalue) {
178201
setData((prev) => {
179202
return updateInstrumentRunstate(prev, updatedPVName, updatedPVvalue);
@@ -198,6 +221,7 @@ export default function InstrumentsDisplay({
198221
key={targetStation.targetStation}
199222
name={targetStation.targetStation}
200223
instruments={targetStation.instruments}
224+
beamCurrent={targetStation.beamCurrent}
201225
/>
202226
);
203227
})}

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ 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}{" "}
18+
{beamCurrent !== undefined && beamCurrent !== null
19+
? "- " + beamCurrent.toFixed(2) + " μA"
20+
: ""}
1621
</h1>
1722
<div className="flex flex-wrap gap-1">
1823
{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.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
updateInstrumentRunstate,
33
updateInstrumentRunstatePV,
4+
updateTargetStationBeamCurrent,
45
} from "@/app/wall/utils";
56
import { IfcInstrumentStatus, instListEntry, targetStation } from "@/app/types";
67

@@ -21,6 +22,22 @@ test("updateInstrumentRunstate returns new array with runstate of instrument cha
2122
.instruments[0].runstate,
2223
).toBe(expectedValue);
2324
});
25+
26+
test("updateTargetStationBeamCurrent returns new array with beam current of target station changed", () => {
27+
const beamCurrPv = "AC:TS123:BEAM:CURR";
28+
const original: targetStation = {
29+
targetStation: "Target station 123",
30+
beamCurrentPv: beamCurrPv,
31+
beamCurrent: 0.0,
32+
instruments: [],
33+
};
34+
const expectedValue = 3.14159265358979;
35+
expect(
36+
updateTargetStationBeamCurrent([original], beamCurrPv, expectedValue)[0]
37+
.beamCurrent,
38+
).toBe(expectedValue);
39+
});
40+
2441
test("updateInstrumentRunstate returns untouched array if runstate PV is not found", () => {
2542
const runStatePV = "AN:INST:DAE:RUNSTATE";
2643
const instrument: IfcInstrumentStatus = {

app/wall/utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ 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+
const foundTs = newData.find((ts) => ts.beamCurrentPv === updatedPVName);
43+
if (foundTs) {
44+
foundTs.beamCurrent = updatedPVvalue;
45+
}
46+
return newData;
47+
}
48+
2949
/**
3050
* Copy an original array then update an instrument's runstate PV, then subscribe to it. return the copied array.
3151
* @param prev the original array of target stations containing instrument runstate information

0 commit comments

Comments
 (0)