44 IfcInstrumentStatus ,
55 IfcPVWSMessage ,
66 IfcPVWSRequest ,
7+ PVWSRequestType ,
78 targetStation ,
89} from "@/app/types" ;
910import useWebSocket from "react-use-websocket" ;
@@ -12,6 +13,7 @@ import { instListFromBytes } from "@/app/components/dehex_and_decompress";
1213import {
1314 updateInstrumentRunstate ,
1415 updateInstrumentRunstatePV ,
16+ updateTargetStationBeamCurrent ,
1517} from "@/app/wall/utils" ;
1618import TargetStation from "@/app/components/TargetStation" ;
1719import 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,18 @@ export default function InstrumentsDisplay({
146150 shouldReconnect : ( closeEvent ) => true ,
147151 } ) ;
148152
153+ const targetStationCurrentPvs = data
154+ . map ( ( ts ) => ts . beamCurrentPv )
155+ . filter ( ( pv ) => pv !== undefined ) ;
156+
149157 useEffect ( ( ) => {
150158 // On page load, subscribe to the instrument list as it's required to get each instrument's PV prefix.
151159 sendJsonMessage ( instListSubscription ) ;
152- } , [ sendJsonMessage ] ) ;
160+ sendJsonMessage ( {
161+ type : PVWSRequestType . subscribe ,
162+ pvs : targetStationCurrentPvs ,
163+ } ) ;
164+ } , [ sendJsonMessage , targetStationCurrentPvs ] ) ;
153165
154166 useEffect ( ( ) => {
155167 // This is a PV update, it could be either the instlist or an instrument's runstate that has changed
@@ -161,6 +173,7 @@ export default function InstrumentsDisplay({
161173 const updatedPVName : string = updatedPV . pv ;
162174 const updatedPVbytes : string | null | undefined = updatedPV . b64byt ;
163175 let updatedPVvalue : string | null | undefined = updatedPV . text ;
176+ let updatedPVnum : number | null | undefined = updatedPV . value ;
164177
165178 if ( updatedPVName == instListPV && updatedPVbytes != null ) {
166179 const instListDict = instListFromBytes ( updatedPVbytes ) ;
@@ -174,12 +187,20 @@ export default function InstrumentsDisplay({
174187 ) ;
175188 } ) ;
176189 }
190+ } else if ( targetStationCurrentPvs . includes ( updatedPVName ) ) {
191+ setData ( ( prev ) => {
192+ return updateTargetStationBeamCurrent (
193+ prev ,
194+ updatedPVName ,
195+ updatedPVnum ,
196+ ) ;
197+ } ) ;
177198 } else if ( updatedPVvalue ) {
178199 setData ( ( prev ) => {
179200 return updateInstrumentRunstate ( prev , updatedPVName , updatedPVvalue ) ;
180201 } ) ;
181202 }
182- } , [ lastJsonMessage , sendJsonMessage ] ) ;
203+ } , [ lastJsonMessage , sendJsonMessage , targetStationCurrentPvs ] ) ;
183204
184205 return (
185206 < div >
@@ -198,6 +219,7 @@ export default function InstrumentsDisplay({
198219 key = { targetStation . targetStation }
199220 name = { targetStation . targetStation }
200221 instruments = { targetStation . instruments }
222+ beamCurrent = { targetStation . beamCurrent }
201223 />
202224 ) ;
203225 } ) }
0 commit comments