@opalkelly/frontpanel-platform-api
Version:
TypeScript definitions for Opal Kelly FrontPanel Platform API
3 lines (2 loc) • 6.26 kB
JavaScript
"use strict";var e,t=require("sub-events");!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.USB2=1]="USB2",e[e.PCIE=2]="PCIE",e[e.USB3=3]="USB3"}(e||(e={}));var s,i=e;exports.UsbSpeedDesignation=void 0,(s=exports.UsbSpeedDesignation||(exports.UsbSpeedDesignation={}))[s.UNKNOWN=0]="UNKNOWN",s[s.FULL_SPEED=1]="FULL_SPEED",s[s.HIGH_SPEED=2]="HIGH_SPEED",s[s.SUPER_SPEED=3]="SUPER_SPEED";class r{constructor(e){this._Target=e}cancel(){return this._Target.cancel()}}class n{constructor(){this._Target=new t.SubEvent}dispatch(e){return this._Target.emit(e),!0}subscribe(e){const t=this._Target.subscribe(e);return new r(t)}subscribeAsync(e){const t=this._Target.subscribe(e);return new r(t)}}class a{get baseAddress(){return this._BaseAddress}get count(){return this._Values.length}get mask(){return this._Mask}constructor(e,t,s){this._Values=t,this._BaseAddress=e,this._Mask=Math.pow(2,s)-1}getValue(e){let t;console.log("MockDataBlock.GetValue: address="+e.toString(16));const s=e-this._BaseAddress;return s>=0&&s<this._Values.length?(t=this._Values[s]&this._Mask,console.log("MockDataBlock.GetValue: SUCCESS: value="+t.toString(16))):(console.log("MockDataBlock.GetValue: ERROR: Element address "+e.toString(16)+" is out of range ["+this._BaseAddress.toString(16)+".."+(this._BaseAddress+this._Values.length-1).toString(16)+"]"),t=null),t}setValue(e,t,s){let i;console.log("MockDataBlock.SetValue: address="+e.toString(16)+" value="+t.toString(16)+" mask="+s.toString(16));const r=e-this._BaseAddress;if(r>=0&&r<this._Values.length){const e=this._Values[r]&this._Mask,n=t&this._Mask;this._Values[r]=e&~s|n&s,console.log("MockDataBlock.SetValue: SUCCESS: value="+this._Values[r].toString(16)),i=!0}else console.log("MockDataBlock.SetValue: ERROR: Element address is out of range ["+this._BaseAddress.toString(16)+".."+(this._BaseAddress+this._Values.length-1).toString(16)+"]"),i=!1;return i}static FromAddressRange(e,t){const s=new Array(e.maximum-e.minimum+1);return new a(e.minimum,s,t)}}class u{get WireInBlock(){return this._WireInBlock}get WireOutBlock(){return this._WireOutBlock}get TriggerOutBlock(){return this._TriggerOutVectors}get RegisterBlock(){return this._RegisterBlock}get hostInterfaceInfo(){return this._HostInterfaceInfo}constructor(e,t){this._HostInterfaceInfo={wireWidth:e,triggerWidth:t,pipeWidth:32,registerAddressWidth:32,registerDataWidth:32},this._WireInBlock=a.FromAddressRange(u.WIREIN_ADDRESS_RANGE,this._HostInterfaceInfo.wireWidth),this._WireOutBlock=a.FromAddressRange(u.WIREOUT_ADDRESS_RANGE,this._HostInterfaceInfo.wireWidth),this._TriggerOutVectors=a.FromAddressRange(u.TRIGGEROUT_ADDRESS_RANGE,this._HostInterfaceInfo.triggerWidth),this._RegisterBlock=a.FromAddressRange(u.REGISTER_ADDRESS_RANGE,this._HostInterfaceInfo.registerDataWidth)}getWireInValue(e){return this._WireInBlock.getValue(e)??0}setWireInValue(e,t,s){this._WireInBlock.setValue(e,t,s)}async updateWireIns(){}getWireOutValue(e){return this._WireOutBlock.getValue(e)??0}async updateWireOuts(){}async activateTriggerIn(e,t){console.log("MockFrontPanel.activateTriggerIn: address="+e.toString(16)+" bit="+t)}getTriggerOutVector(e){return this._TriggerOutVectors.getValue(e)??0}isTriggered(e,t){return((this._TriggerOutVectors.getValue(e)??0)&t)===t}async updateTriggerOuts(){}async writeToPipeIn(e,t,s){return 0}async writeToBlockPipeIn(e,t,s,i){return 0}async readFromPipeOut(e,t,s){return 0}async readFromBlockPipeOut(e,t,s,i){return 0}async readRegister(e){return this._RegisterBlock.getValue(e)??0}async readRegisters(e){}async writeRegister(e,t){this._RegisterBlock.setValue(e,t,4294967295)}async writeRegisters(e){}}u.WIREIN_ADDRESS_RANGE={minimum:0,maximum:31},u.WIREOUT_ADDRESS_RANGE={minimum:32,maximum:63},u.TRIGGERIN_ADDRESS_RANGE={minimum:64,maximum:95},u.TRIGGEROUT_ADDRESS_RANGE={minimum:96,maximum:127},u.PIPEIN_ADDRESS_RANGE={minimum:128,maximum:159},u.PIPEOUT_ADDRESS_RANGE={minimum:160,maximum:191},u.REGISTER_ADDRESS_RANGE={minimum:0,maximum:31},exports.DeviceEvent=class{constructor(){this._Target=new t.SubEvent}dispatch(e,t){return this._Target.emit({sender:e,serialNumber:t}),!0}subscribe(e){const t=this._Target.subscribe((({sender:t,serialNumber:s})=>e(t,s)));return new r(t)}subscribeAsync(e){const t=this._Target.subscribe((({sender:t,serialNumber:s})=>e(t,s)));return new r(t)}},exports.DeviceInterfaceType=i,exports.FrontPanelEvent=n,exports.FrontPanelPeriodicUpdateTimer=class{get wireOutValuesChangedEvent(){return this._WireOutValuesChangedEvent}get triggerOutValuesChangedEvent(){return this._TriggerOutValuesChangedEvent}constructor(e,t){this._WireOutValuesChangedEvent=new n,this._TriggerOutValuesChangedEvent=new n,this._UpdateTimer=null,this._IsRunning=!1,this._IsStopPending=!1,this._Device=e,this._UpdatePeriodMilliseconds=t}async start(){let e;return this._IsStopPending&&await this._UpdateTimer,this._IsRunning?e=!1:(this._UpdateTimer=this.updateTimerLoop(),e=this._IsRunning),e}async stop(){this._IsStopPending||(this._IsStopPending=!0,this._CancelTimeout&&this._CancelTimeout(),null!==this._UpdateTimer&&(await this._UpdateTimer,this._UpdateTimer=null),this._IsStopPending=!1)}async updateTimerLoop(){for(this._IsRunning=!0;!this._IsStopPending;){const e=performance.now();await this.updateWireOuts(),await this.updateTriggerOuts();const t=performance.now()-e;if(!this._IsStopPending){const e=this._UpdatePeriodMilliseconds-t;await new Promise((t=>{const s=setTimeout(t,e);this._CancelTimeout=()=>{clearTimeout(s),t()}}))}}this._IsRunning=!1}async updateWireOuts(){await this._Device.updateWireOuts(),this._WireOutValuesChangedEvent.dispatch(this._Device)}async updateTriggerOuts(){await this._Device.updateTriggerOuts(),this._TriggerOutValuesChangedEvent.dispatch(this._Device)}},exports.MockFrontPanel=u,exports.PIPEIN_ADDRESS_RANGE={minimum:128,maximum:159},exports.PIPEOUT_ADDRESS_RANGE={minimum:160,maximum:191},exports.TRIGGERIN_ADDRESS_RANGE={minimum:64,maximum:95},exports.TRIGGEROUT_ADDRESS_RANGE={minimum:96,maximum:127},exports.WIREIN_ADDRESS_RANGE={minimum:0,maximum:31},exports.WIREOUT_ADDRESS_RANGE={minimum:32,maximum:63},exports.WorkQueue=class{constructor(){this._Queue=Promise.resolve()}post(e){const t=this._Queue.then((()=>e())).catch((()=>{}));return this._Queue=t,t}};
//# sourceMappingURL=index.js.map