-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12891d2
commit 666e9b2
Showing
9 changed files
with
212 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Dict, EpicsData } from "../assets/interfaces"; | ||
import Thresholds from "./threshold"; | ||
import EpicsCon from "./epics_con"; | ||
|
||
/** | ||
* Create a basic Epics object that updates its values in | ||
* fixed time intervals. | ||
*/ | ||
class EpicsBase<T extends string|string[]> { | ||
public update_interval: number; | ||
public thresholds: Thresholds; | ||
public pv_name: T; | ||
private timer: any; | ||
|
||
constructor(pvname: T){ | ||
this.update_interval = 100; | ||
this.pv_name = pvname; | ||
this._subscribe2epics_con(); | ||
this.timer = null; | ||
this.thresholds = new Thresholds(); | ||
} | ||
|
||
initialize(pv_name: T, threshold: undefined|Dict<number>, update_interval: undefined|number): void { | ||
this.set_pvname(pv_name); | ||
this._subscribe2epics_con(); | ||
|
||
if(threshold !== undefined) { | ||
this.thresholds.set_thresholds(threshold); | ||
} | ||
if(update_interval !=undefined){ | ||
this._set_update_interval(update_interval); | ||
} | ||
} | ||
|
||
start_timer(fun: ()=>void): void { | ||
this.timer = setInterval( | ||
fun, this.update_interval); | ||
} | ||
|
||
get_pv_data<M>(): Dict<EpicsData<M>> { | ||
let pvData: Dict<EpicsData<M>> = EpicsCon.get_pv_data(); | ||
return pvData; | ||
} | ||
|
||
get_threshold(value: number): string { | ||
return this.thresholds.get_biggest_threshold(value); | ||
} | ||
|
||
set_pvname(pvname: T): void { | ||
if(this._equal_check(pvname)){ | ||
this.pv_name = pvname; | ||
this._subscribe2epics_con(); | ||
} | ||
} | ||
|
||
destroy(): void { | ||
if(this.timer!=null){ | ||
clearInterval(this.timer); | ||
this._unsubscribe2epics_con(); | ||
} | ||
} | ||
|
||
_equal_check(pvname: T): boolean { | ||
return JSON.stringify(this.pv_name) != JSON.stringify(pvname); | ||
} | ||
|
||
_set_update_interval(milliseconds: number): void { | ||
this.update_interval = milliseconds; | ||
} | ||
|
||
_subscribe2epics_con(){ | ||
EpicsCon.add_new_pv<T>(this.pv_name); | ||
} | ||
|
||
_unsubscribe2epics_con(){ | ||
EpicsCon.remove_pv<T>(this.pv_name); | ||
} | ||
} | ||
|
||
export default EpicsBase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Epics from "../access_data/Epics"; | ||
import { Dict, EpicsData } from "../assets/interfaces"; | ||
|
||
/** | ||
* Create an static Epics connection that allows | ||
* widget to subscribe or unsubscribe to the monitoring. | ||
*/ | ||
class EpicsCon { | ||
private static epics: Epics = new Epics([]); | ||
private static pv_name: string[] = []; | ||
|
||
static convert2list<T extends string|string[]>(new_pv: T): string[]{ | ||
if(Array.isArray(new_pv)){ | ||
return new_pv; | ||
} | ||
return [new_pv]; | ||
} | ||
|
||
/** | ||
* Returns a list with the PVs that are not already subscribed. | ||
*/ | ||
static new_pvs_list(pv_list: string[]): string[]{ | ||
let pvs2add: string[] = []; | ||
pv_list.map((pvname: string) => { | ||
if(!(pvname in this.pv_name)){ | ||
pvs2add.push(pvname); | ||
} | ||
}) | ||
return pvs2add; | ||
} | ||
|
||
/** | ||
* Create a new connection using the Epics Object. | ||
*/ | ||
static create_epics(){ | ||
this.epics.disconnect(); | ||
return new Epics(this.pv_name); | ||
} | ||
|
||
/** | ||
* Subscribe new list of PVs. | ||
*/ | ||
static add_new_pv<T extends string|string[]>(new_pv: T){ | ||
let list2add: string[] = []; | ||
let new_pv_list: string[] = this.convert2list<T>(new_pv); | ||
list2add = this.new_pvs_list(new_pv_list); | ||
this.pv_name = this.pv_name.concat(list2add); | ||
this.epics = this.create_epics(); | ||
} | ||
|
||
/** | ||
* Unsubscribe new list of PVs. | ||
*/ | ||
static remove_pv<T extends string|string[]>(rem_pv: T){ | ||
let pv_list: string[] = this.pv_name; | ||
const rem_pv_list: string[] = this.convert2list<T>(rem_pv); | ||
rem_pv_list.map((pvname: string) => { | ||
if(pvname in this.pv_name){ | ||
delete pv_list[pvname]; | ||
} | ||
}) | ||
this.pv_name = pv_list; | ||
} | ||
|
||
/** | ||
* Get a list of the current values of all subscribed PVs. | ||
*/ | ||
static get_pv_data<M>(): Dict<EpicsData<M>> { | ||
let pvData: Dict<EpicsData<M>> = this.epics.pvData; | ||
return pvData; | ||
} | ||
} | ||
|
||
export default EpicsCon; |
Oops, something went wrong.