UNPKG

@opalkelly/frontpanel-platform-api

Version:

TypeScript definitions for Opal Kelly FrontPanel Platform API

3 lines (2 loc) 6.18 kB
import{SubEvent as e}from"sub-events";var t;!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.USB2=1]="USB2",e[e.PCIE=2]="PCIE",e[e.USB3=3]="USB3"}(t||(t={}));var s,i=t;!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.FULL_SPEED=1]="FULL_SPEED",e[e.HIGH_SPEED=2]="HIGH_SPEED",e[e.SUPER_SPEED=3]="SUPER_SPEED"}(s||(s={}));class r{constructor(e){this._Target=e}cancel(){return this._Target.cancel()}}class n{constructor(){this._Target=new e}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)}}class a{constructor(){this._Target=new e}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 u{get wireOutValuesChangedEvent(){return this._WireOutValuesChangedEvent}get triggerOutValuesChangedEvent(){return this._TriggerOutValuesChangedEvent}constructor(e,t){this._WireOutValuesChangedEvent=new a,this._TriggerOutValuesChangedEvent=new a,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)}}class o{constructor(){this._Queue=Promise.resolve()}post(e){const t=this._Queue.then((()=>e())).catch((()=>{}));return this._Queue=t,t}}const c={minimum:0,maximum:31},g={minimum:32,maximum:63},h={minimum:64,maximum:95},m={minimum:96,maximum:127},_={minimum:128,maximum:159},l={minimum:160,maximum:191};class d{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 d(e.minimum,s,t)}}class E{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=d.FromAddressRange(E.WIREIN_ADDRESS_RANGE,this._HostInterfaceInfo.wireWidth),this._WireOutBlock=d.FromAddressRange(E.WIREOUT_ADDRESS_RANGE,this._HostInterfaceInfo.wireWidth),this._TriggerOutVectors=d.FromAddressRange(E.TRIGGEROUT_ADDRESS_RANGE,this._HostInterfaceInfo.triggerWidth),this._RegisterBlock=d.FromAddressRange(E.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){}}E.WIREIN_ADDRESS_RANGE={minimum:0,maximum:31},E.WIREOUT_ADDRESS_RANGE={minimum:32,maximum:63},E.TRIGGERIN_ADDRESS_RANGE={minimum:64,maximum:95},E.TRIGGEROUT_ADDRESS_RANGE={minimum:96,maximum:127},E.PIPEIN_ADDRESS_RANGE={minimum:128,maximum:159},E.PIPEOUT_ADDRESS_RANGE={minimum:160,maximum:191},E.REGISTER_ADDRESS_RANGE={minimum:0,maximum:31};export{n as DeviceEvent,i as DeviceInterfaceType,a as FrontPanelEvent,u as FrontPanelPeriodicUpdateTimer,E as MockFrontPanel,_ as PIPEIN_ADDRESS_RANGE,l as PIPEOUT_ADDRESS_RANGE,h as TRIGGERIN_ADDRESS_RANGE,m as TRIGGEROUT_ADDRESS_RANGE,s as UsbSpeedDesignation,c as WIREIN_ADDRESS_RANGE,g as WIREOUT_ADDRESS_RANGE,o as WorkQueue}; //# sourceMappingURL=index.js.map