@@ -3,23 +3,27 @@ import React, { useEffect, useState } from "react";
33import TopBar from "./TopBar" ;
44import Groups from "./Groups" ;
55import useWebSocket from "react-use-websocket" ;
6- import { dehex_and_decompress } from "./dehex_and_decompress" ;
6+ import {
7+ dehex_and_decompress ,
8+ instListFromBytes ,
9+ } from "./dehex_and_decompress" ;
710import { findPVInDashboard , Instrument } from "./Instrument" ;
811import { useSearchParams } from "next/navigation" ;
912import {
1013 ConfigOutput ,
1114 ConfigOutputBlock ,
1215 IfcBlock ,
1316 IfcGroup ,
14- IfcPV ,
1517 IfcPVWSMessage ,
1618 IfcPVWSRequest ,
19+ PVWSRequestType ,
1720} from "@/app/types" ;
1821import {
19- findPVByAddress ,
2022 ExponentialOnThresholdFormat ,
23+ findPVByAddress ,
2124} from "@/app/components/PVutils" ;
2225import CheckToggle from "@/app/components/CheckToggle" ;
26+ import { instListPV , instListSubscription , socketURL } from "@/app/commonVars" ;
2327
2428let lastUpdate : string = "" ;
2529
@@ -46,7 +50,7 @@ export function subscribeToBlockPVs(
4650 * Subscribes to a block and its associated run control PVs
4751 */
4852 sendJsonMessage ( {
49- type : " subscribe" ,
53+ type : PVWSRequestType . subscribe ,
5054 pvs : [
5155 block_address ,
5256 block_address + RC_ENABLE ,
@@ -101,15 +105,12 @@ export function toPrecision(
101105
102106function InstrumentData ( { instrumentName } : { instrumentName : string } ) {
103107 const [ showHiddenBlocks , setShowHiddenBlocks ] = useState ( false ) ;
104- const [ showSetpoints , setShowSetpoints ] = useState ( false ) ;
105- const [ showTimestamps , setShowTimestamps ] = useState ( false ) ;
106108 const CONFIG_DETAILS = "CS:BLOCKSERVER:GET_CURR_CONFIG_DETAILS" ;
107109 const [ instlist , setInstlist ] = useState < Array < any > | null > ( null ) ;
108110 const [ currentInstrument , setCurrentInstrument ] = useState < Instrument | null > (
109111 null ,
110112 ) ;
111- const socketURL =
112- process . env . NEXT_PUBLIC_WS_URL || "ws://localhost:8080/pvws/pv" ;
113+
113114 const instName = instrumentName ;
114115
115116 useEffect ( ( ) => {
@@ -130,10 +131,7 @@ function InstrumentData({ instrumentName }: { instrumentName: string }) {
130131
131132 useEffect ( ( ) => {
132133 // This is an initial useEffect to subscribe to lots of PVs including the instlist.
133- sendJsonMessage ( {
134- type : "subscribe" ,
135- pvs : [ "CS:INSTLIST" ] ,
136- } ) ;
134+ sendJsonMessage ( instListSubscription ) ;
137135
138136 if ( instName == "" || instName == null || instlist == null ) {
139137 return ;
@@ -156,15 +154,18 @@ function InstrumentData({ instrumentName }: { instrumentName: string }) {
156154 setCurrentInstrument ( instrument ) ;
157155
158156 sendJsonMessage ( {
159- type : " subscribe" ,
157+ type : PVWSRequestType . subscribe ,
160158 pvs : [ `${ prefix } ${ CONFIG_DETAILS } ` ] ,
161159 } ) ;
162160
163161 // subscribe to dashboard and run info PVs
164162 for ( const pv of instrument . runInfoPVs . concat (
165163 instrument . dashboard . flat ( 3 ) ,
166164 ) ) {
167- sendJsonMessage ( { type : "subscribe" , pvs : [ pv . pvaddress ] } ) ;
165+ sendJsonMessage ( {
166+ type : PVWSRequestType . subscribe ,
167+ pvs : [ pv . pvaddress ] ,
168+ } ) ;
168169 }
169170 }
170171 } , [ instlist , instName , sendJsonMessage , currentInstrument ] ) ;
@@ -178,11 +179,8 @@ function InstrumentData({ instrumentName }: { instrumentName: string }) {
178179 const updatedPVName : string = updatedPV . pv ;
179180 const updatedPVbytes : string | null | undefined = updatedPV . b64byt ;
180181
181- if ( updatedPVName == "CS:INSTLIST" && updatedPVbytes != null ) {
182- const dehexedInstList = dehex_and_decompress ( atob ( updatedPVbytes ) ) ;
183- if ( dehexedInstList != null && typeof dehexedInstList == "string" ) {
184- setInstlist ( JSON . parse ( dehexedInstList ) ) ;
185- }
182+ if ( updatedPVName == instListPV && updatedPVbytes != null ) {
183+ setInstlist ( instListFromBytes ( updatedPVbytes ) ) ;
186184 }
187185
188186 if ( ! currentInstrument ) {
@@ -200,9 +198,6 @@ function InstrumentData({ instrumentName }: { instrumentName: string }) {
200198 }
201199 lastUpdate = updatedPVbytes ;
202200 const res = dehex_and_decompress ( atob ( updatedPVbytes ) ) ;
203- if ( res == null || typeof res != "string" ) {
204- return ;
205- }
206201 currentInstrument . groups = getGroupsWithBlocksFromConfigOutput (
207202 JSON . parse ( res ) ,
208203 sendJsonMessage ,
0 commit comments