<> <> <> DIRECTORY BasicTime USING [Now], Commander USING [CommandProc, Handle, Register], IO, Rope, Buttons USING [Button, ButtonProc, Create, ReLabel], Containers USING [ChildXBound, ChildYBound], Convert USING [CardFromRope, Error, IntFromRope], FS USING [SetKeep], ImagerFont USING [Font, Find], Labels USING [Create, Set], PopUpSelection USING [Request], Rules USING [Create], TypeScript USING [ChangeLooks, Create], ViewerClasses USING [Viewer, ViewerRec], ViewerIO USING [CreateViewerStreams], ViewerOps USING [CreateViewer], ViewerTools USING [GetContents, MakeNewTextViewer, SetContents, SetSelection], SoftcardOps, SoftcardToolPrivate; SoftcardToolImpl: CEDAR MONITOR IMPORTS BasicTime, Commander, Convert, FS, ImagerFont, IO, PopUpSelection, Rope, Buttons, Containers, Labels, Rules, ViewerIO, ViewerOps, ViewerTools, TypeScript, SoftcardOps, SoftcardToolPrivate EXPORTS SoftcardToolPrivate = BEGIN OPEN IO, SoftcardToolPrivate; STREAM: TYPE = IO.STREAM; <> topViewer: PUBLIC Viewer; tsViewer: Viewer; tsOut: PUBLIC STREAM; runOrStopButton: Viewer; runChoice: ROPE = " Is running "; stopChoice: ROPE = " Is stopped "; unknownChoice: ROPE = " Is unknown "; dragonState: DragonState _ unknown; connectionText: Viewer; phaseAdjustText: Viewer; delayText: Viewer; freqSelectLabel: Viewer; freqSelectChoice: INT _ -1; freqSelectArray: PUBLIC ARRAY [0..3] OF SelectRecord; SelectRecord: TYPE = RECORD [name: ROPE, val: CARD16]; activeFont: PUBLIC ImagerFont.Font; labelFont: PUBLIC ImagerFont.Font; tinySelectFont: PUBLIC ImagerFont.Font; selectFont: PUBLIC ImagerFont.Font; <<* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >> MakeControlWindow: PROC[name, tsLogFile: ROPE] RETURNS [STREAM] = { IF topViewer = NIL OR topViewer.destroyed THEN { sib: Viewer; y: INTEGER; topViewer _ ViewerOps.CreateViewer[ flavor: $Container, info: [name: name, iconic: FALSE, scrollable: FALSE] ]; <<>> <> sib _ Buttons.Create[ info: [ name: " EstablishConnection ", parent: topViewer, wx: leftEdge, wy: 4, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: OpenConnectionProc ]; sib _ Buttons.Create[ info: [ name: " CloseConnection ", parent: topViewer, wx: sib.wx+sib.ww+1, wy: sib.wy, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: CloseConnectionProc ]; sib _ Buttons.Create[ info: [ name: "Host:", parent: topViewer, wx: sib.wx+sib.ww+10, wy: sib.wy, wh: entryHeight, border: FALSE, scrollable: FALSE], font: selectFont, proc: ConnectionTextProc ]; sib _ connectionText _ ViewerTools.MakeNewTextViewer[ info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, ww: 1000, wh: entryHeight, border: FALSE, scrollable: TRUE]]; Containers.ChildXBound[topViewer, sib]; <> sib _ Labels.Create[ info: [ name: " DragonRunControl ", parent: topViewer, wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight, border: FALSE, scrollable: FALSE], font: labelFont ]; sib _ runOrStopButton _ Buttons.Create[ info: [ name: unknownChoice, parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: RunOrStopProc ]; <> sib _ Buttons.Create[ info: [ name: " HaltDragonInPhase ", parent: topViewer, wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: HaltDragonProc ]; sib _ Buttons.Create[ info: [ name: " Current Dragon Phase ", parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: CurrentPhaseProc ]; sib _ Labels.Create[ info: [ name: " StepDragon ", parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy, wh: entryHeight, border: FALSE, scrollable: FALSE], font: labelFont ]; sib _ Buttons.Create[ info: [ name: "quarter", parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: QuarterStepProc ]; sib _ Buttons.Create[ info: [ name: "half", parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: HalfStepProc ]; sib _ Buttons.Create[ info: [ name: "full", parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, border: TRUE, scrollable: FALSE], font: activeFont, proc: FullStepProc ]; <> sib _ Labels.Create[ info: [ name: " ClockControl ", parent: topViewer, wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight, border: FALSE, scrollable: FALSE], font: labelFont ]; sib _ Buttons.Create[ info: [name: "Read", parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, scrollable: FALSE ], font: activeFont, proc: ReadClockControl ]; sib _ Buttons.Create[ info: [name: "Write", parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, scrollable: FALSE ], font: activeFont, proc: WriteClockControl ]; sib _ Buttons.Create[ info: [name: " FreqSelect: ", parent: topViewer, wx: sib.wx+sib.ww+xFudge+5, wy: sib.wy, wh: entryHeight, border: FALSE, scrollable: FALSE ], font: tinySelectFont, proc: FreqSelectProc ]; sib _ freqSelectLabel _ Labels.Create[ info: [name: " ", parent: topViewer, wx: sib.wx+sib.ww+xFudge+2, wy: sib.wy, wh: entryHeight, border: FALSE, scrollable: FALSE], font: labelFont ]; sib _ Buttons.Create[ info: [name: "PhaseAdjust [0..7]: ", parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, border: FALSE, scrollable: FALSE ], font: tinySelectFont, proc: PhaseAdjustProc ]; sib _ phaseAdjustText _ ViewerTools.MakeNewTextViewer[ info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, ww: 20, wh: entryHeight, border: FALSE, scrollable: FALSE] ]; sib _ Buttons.Create[ info: [name: "Delay [0..7]: ", parent: topViewer, wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight, border: FALSE, scrollable: FALSE ], font: tinySelectFont, proc: DelayProc ]; sib _ delayText _ ViewerTools.MakeNewTextViewer[ info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+2, wy: sib.wy, ww: 20, wh: entryHeight, border: FALSE, scrollable: FALSE]]; <> sib _ BuildVariousButtons[topViewer, sib]; sib _ BuildRegisterButtons[topViewer, sib]; sib _ BuildPeekPokeButtons[topViewer, sib]; sib _ Rules.Create[ info: [parent: topViewer, wy: sib.wy+sib.wh+2, ww: topViewer.ww, wh: 2]]; Containers.ChildXBound[topViewer, sib]; sib _ BuildMiscButtons[topViewer, sib]; <<>> <> sib _ Rules.Create[ info: [parent: topViewer, wy: sib.wy+sib.wh+1, ww: topViewer.ww, wh: 2]]; Containers.ChildXBound[topViewer, sib]; y _ sib.wy+sib.wh+4; tsViewer _ TypeScript.Create[ info: [parent: topViewer, ww: sib.cw, wy: y, wh: topViewer.ch - y, border: FALSE] ]; TypeScript.ChangeLooks[tsViewer, 'f]; Containers.ChildYBound[topViewer, tsViewer]; Containers.ChildXBound[topViewer, tsViewer]; tsOut _ ViewerIO.CreateViewerStreams[NIL, tsViewer, tsLogFile, FALSE].out; FS.SetKeep[tsLogFile, 6]; TSOutPutF["\tTypescript on file: %g, started at %g\n", [rope[tsLogFile]], [time[BasicTime.Now[]]] ]; }; topViewer.inhibitDestroy _ TRUE; RETURN[tsOut]; }; OpenConnectionProc: ClickProc = { name: ROPE = ViewerTools.GetContents[connectionText]; ok: BOOL = SoftcardOps.EstablishConnection[name]; isRunning: BOOL = SoftcardOps.ReadControlBit[dragonRun]; IF ok THEN { IF isRunning THEN SetDragonStateLabelButton[running] ELSE SetDragonStateLabelButton[stopped]; TSOutPutF["Connection to %g has been established\n", IO.rope[name]] } ELSE TSOutPutF["Could not establish connection with %g has \n", IO.rope[name]]; }; CloseConnectionProc: ClickProc = { SoftcardOps.CloseConnection[]; TSOutPutRope["Connection has been closed\n\n"]; SetDragonStateLabelButton[unknown]; }; ReadClockControl: ClickProc = { current: SoftcardOps.ClockControl = SoftcardOps.ReadClockControl[]; TSOutPutF[ " Current value of clock control is: [freqSelect: %g, phaseAdjust: %g, delay: %g]\n", [rope[freqSelectArray[current.freqSelect].name]], [integer[current.phaseAdjust]], [integer[current.delay]] ]; freqSelectChoice _ current.freqSelect; Labels.Set[freqSelectLabel, freqSelectArray[freqSelectChoice].name ]; ViewerTools.SetContents[phaseAdjustText, IO.PutFR[NIL, [integer[current.phaseAdjust]]] ]; ViewerTools.SetContents[delayText, IO.PutFR[NIL, [integer[current.delay]]] ]; }; WriteClockControl: ClickProc = { new: SoftcardOps.ClockControl; ok: BOOL; typeIn: CARD32; IF freqSelectChoice = -1 THEN { TSOutPutRope[" Please select a frequency first\n"]; RETURN; }; new.freqSelect _ freqSelectArray[freqSelectChoice].val; [ok, typeIn] _ CheckedGetAsCard[phaseAdjustText, "PhaseAdjust", 7]; IF ~ok THEN RETURN; new.phaseAdjust _ typeIn; [ok, typeIn] _ CheckedGetAsCard[delayText, "Delay", 7]; IF ~ok THEN RETURN; new.delay _ typeIn; SoftcardOps.WriteClockControl[new]; TSOutPutRope[" New value of clockControl has been set\n"]; }; RunOrStopProc: ClickProc = { IF dragonState = unknown THEN { TSOutPutRope[" Dragon state is unknown - can't change\n"]; RETURN }; IF dragonState = running THEN { SoftcardOps.DragonStop[]; SetDragonStateLabelButton[stopped]; } ELSE { SoftcardOps.DragonRun[]; SetDragonStateLabelButton[running]; }; }; SetDragonStateLabelButton: PUBLIC PROC[which: DragonState] = { IF dragonState = which THEN RETURN; -- nothing to do SELECT which FROM running => Buttons.ReLabel[runOrStopButton, runChoice]; stopped => Buttons.ReLabel[runOrStopButton, stopChoice]; unknown => Buttons.ReLabel[runOrStopButton, unknownChoice]; ENDCASE => ERROR; dragonState _ which; }; ConnectionTextProc: ClickProc = { ViewerTools.SetSelection[connectionText, NIL] }; FreqSelectProc: ClickProc = { which: INT = PopUpSelection.Request[ header: "Frequency Select", choice: LIST[freqSelectArray[0].name, freqSelectArray[1].name, freqSelectArray[2].name, freqSelectArray[3].name] ]; IF which = 0 THEN RETURN; -- no selection Labels.Set[freqSelectLabel, freqSelectArray[which - 1].name]; freqSelectChoice _ which - 1; }; PhaseAdjustProc: ClickProc = { ViewerTools.SetSelection[phaseAdjustText, NIL] }; DelayProc: ClickProc = { ViewerTools.SetSelection[delayText, NIL] }; HaltDragonProc: ClickProc = { which: INT = PopUpSelection.Request[ header: "DragonPhase", choice: LIST["phaseA", "betweenAandB", "phaseB", "betweenBandA"] ]; phase: SoftcardOps.DragonPhase; name: ROPE; IF which = 0 THEN RETURN; SELECT which FROM 1 => { phase _ phaseA; name _ "phaseA" }; 2 => { phase _ betweenAandB; name _ "betweenAandB" }; 3 => { phase _ phaseB; name _ "phaseB" }; 4 => { phase _ betweenBandA; name _ "betweenBandA" }; ENDCASE => ERROR; SoftcardOps.DragonHaltInPhase[phase]; TSOutPutF[" Dragon has been halted in %g\n", IO.rope[name] ]; SetDragonStateLabelButton[stopped]; }; <> <> <> <> <> <> <> <> <> <> <<};>> <