@@ -8,10 +8,12 @@ import {
88} from "@/app/types" ;
99import useWebSocket from "react-use-websocket" ;
1010import { instListPV , instListSubscription , socketURL } from "@/app/commonVars" ;
11+ import { IfcPVWSRequest , PVWSRequestType } from "@/app/types" ;
1112import { 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,21 @@ export default function InstrumentsDisplay({
146150 shouldReconnect : ( closeEvent ) => true ,
147151 } ) ;
148152
153+ let targetStationCurrentPvs = [ ]
154+ for ( const ts of data ) {
155+ if ( ts . beamCurrentPv != undefined ) {
156+ targetStationCurrentPvs . push ( ts . beamCurrentPv )
157+ }
158+ }
159+
149160 useEffect ( ( ) => {
150161 // On page load, subscribe to the instrument list as it's required to get each instrument's PV prefix.
151162 sendJsonMessage ( instListSubscription ) ;
152- } , [ sendJsonMessage ] ) ;
163+ sendJsonMessage ( {
164+ type : PVWSRequestType . subscribe ,
165+ pvs : targetStationCurrentPvs ,
166+ } )
167+ } , [ sendJsonMessage , targetStationCurrentPvs ] ) ;
153168
154169 useEffect ( ( ) => {
155170 // This is a PV update, it could be either the instlist or an instrument's runstate that has changed
@@ -161,25 +176,30 @@ export default function InstrumentsDisplay({
161176 const updatedPVName : string = updatedPV . pv ;
162177 const updatedPVbytes : string | null | undefined = updatedPV . b64byt ;
163178 let updatedPVvalue : string | null | undefined = updatedPV . text ;
179+ let updatedPVnum : number = updatedPV . value ;
164180
165181 if ( updatedPVName == instListPV && updatedPVbytes != null ) {
166182 const instListDict = instListFromBytes ( updatedPVbytes ) ;
167183 for ( const instrument of instListDict ) {
168184 setData ( ( prev ) => {
169185 return updateInstrumentRunstatePV (
170- prev ,
171- instrument ,
172- runstatePV ,
173- sendJsonMessage ,
186+ prev ,
187+ instrument ,
188+ runstatePV ,
189+ sendJsonMessage ,
174190 ) ;
175191 } ) ;
176192 }
193+ } else if ( targetStationCurrentPvs . includes ( updatedPVName ) ) {
194+ setData ( ( prev ) => {
195+ return updateTargetStationBeamCurrent ( prev , updatedPVName , updatedPVnum ) ;
196+ } ) ;
177197 } else if ( updatedPVvalue ) {
178198 setData ( ( prev ) => {
179199 return updateInstrumentRunstate ( prev , updatedPVName , updatedPVvalue ) ;
180200 } ) ;
181201 }
182- } , [ lastJsonMessage , sendJsonMessage ] ) ;
202+ } , [ lastJsonMessage , sendJsonMessage , targetStationCurrentPvs ] ) ;
183203
184204 return (
185205 < div >
@@ -198,6 +218,7 @@ export default function InstrumentsDisplay({
198218 key = { targetStation . targetStation }
199219 name = { targetStation . targetStation }
200220 instruments = { targetStation . instruments }
221+ beamCurrent = { targetStation . beamCurrent }
201222 />
202223 ) ;
203224 } ) }
0 commit comments