EtherTesterViewerImpl.mesa
last edited by Willie-Sue, January 10, 1986 4:45:50 pm PST
sugested by: EtherTesterTajo.mesa, AOF, 26-Sep-83 17:13:41
DIRECTORY
Atom,
Buttons USING [ButtonProc, Create, SetDisplayStyle],
IO,
Labels USING [Create, Set],
NumberLabels USING [NumberLabel, CreateNumber, NumberLabelUpdate],
Rope USING [ROPE, Length],
VFonts,
ViewerClasses USING [Viewer, ViewerRec],
ViewerOps,
ViewerTools USING [GetContents, MakeNewTextViewer, SetContents, SetSelection],
NewEthernetFace USING [Status],
NSPilotSystem USING [HostNumber],
Unformat USING [Error, HostNumber],
EtherTesterOps USING [HWTestMode, Pattern, StatsType, hwMode, pattern, realBackground, stats],
EtherTesterViewer;
EtherTesterViewerImpl: PROGRAM
IMPORTS
Buttons, IO, Labels, NumberLabels, Rope, ViewerOps, ViewerTools,
Unformat,
EtherTesterOps, EtherTesterViewer
EXPORTS EtherTesterViewer =
BEGIN OPEN IO, EtherTesterViewer;
Global Data
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
Creating and using viewers *********************************
ViewerRec: TYPE = ViewerClasses.ViewerRec;
ButtonAndText: PUBLIC PROC[name: ROPE, sib: Viewer, width: INTEGER, newLine: BOOLFALSE,
  default: ROPENIL, valType: ValueType ← cardinal] RETURNS[item: ButtonItem] =
BEGIN
button, text: Viewer;
info: ViewerRec ←
[name: name, parent: sib.parent, wy: sib.wy, wh: entryHeight, border: FALSE,
scrollable: FALSE];
IF newLine THEN
{ info.wx ← IF sib.parent.scrollable THEN 0 ELSE xFudge;
info.wy ← info.wy + sib.wh + 2;
}
ELSE info.wx ← sib.wx+sib.ww+8;
button ← Buttons.Create[info: info, proc: ButtonItemProc];
text ← ViewerTools.MakeNewTextViewer[
info: [parent: sib.parent, wx: button.wx+button.ww+xFudge, wy: button.wy,
 ww: width, wh: entryHeight, border: FALSE, scrollable: FALSE]];
ViewerTools.SetContents[text, default];
item ← NEW[ButtonItemObject ← [button: button, text: text, default: default, valType: valType]];
ViewerOps.AddProp[button, $ButtonItem, item];
END;
ButtonItemProc: Buttons.ButtonProc = TRUSTED
BEGIN
v: Viewer = NARROW[parent];
item: ButtonItem = NARROW[ViewerOps.FetchProp[v, $ButtonItem]];
SELECT mouseButton FROM
red, blue => ViewerTools.SetSelection[item.text, NIL];
yellow => ViewerTools.SetContents[item.text, item.default];
ENDCASE => NULL;
END;
ReadCard: PUBLIC PROC[item: ButtonItem] RETURNS[val: CARDINAL] =
BEGIN
v: Viewer ← item.text;
h: IO.STREAM;
txt: ROPE ← ViewerTools.GetContents[v];
parseError: BOOLFALSE;
IF txt.Length[] = 0 THEN txtitem.default;
h ← IO.RIS[txt];
val ← h.GetCard[ ! IO.Error => {parseError ← TRUE; CONTINUE}];
IF parseError THEN SIGNAL ParseError;
END;
ReadINT: PUBLIC PROC[item: ButtonItem] RETURNS[val: INT] =
BEGIN
v: Viewer ← item.text;
h: IO.STREAM;
txt: ROPE ← ViewerTools.GetContents[v];
parseError: BOOLFALSE;
IF txt.Length[] = 0 THEN txtitem.default;
h ← IO.RIS[txt];
val ← h.GetInt[ ! IO.Error => {parseError ← TRUE; CONTINUE}];
IF parseError THEN SIGNAL ParseError;
END;
ReadHostNum: PUBLIC PROC[v: Viewer] RETURNS[num: NSPilotSystem.HostNumber] =
BEGIN
txt: ROPE ← ViewerTools.GetContents[v];
parseError: BOOLFALSE;
num ← Unformat.HostNumber[txt, octal ! Unformat.Error => {parseError ← TRUE; CONTINUE}];
IF parseError THEN SIGNAL ParseError;
END;
StatusToRope: PUBLIC PROC[s: NewEthernetFace.Status] RETURNS [r: ROPE] =
BEGIN
SELECT s FROM
pending => r ← "pending";
ok => r ← "ok";
overrun => r ← "overrun";
underrun => r ← "underrun";
packetTooLong => r ← "packetTooLong";
tooManyCollisions => r ← "tooManyCollisions";
lateCollision => r ← "lateCollision";
crc => r ← "crc";
crcAndBadAlignment => r ← "crcAndBadAlignment";
badAlignmentButOkCrc => r ← "badAlignmentButOkCrc";
otherError=> r ← "otherError";
ENDCASE => r ← "ERROR";
END;
procs for Boolean buttons *********************
MakeFirstBoolItem: PUBLIC PROC[name: ROPE, proc: BoolItemProc, parent: Viewer, init: BOOL]
  RETURNS[button: Viewer] =
BEGIN
boolItem: BoolItem;
info: ViewerRec ←
[name: name, parent: parent, wx: 0, wy: 0, wh: entryHeight, border: FALSE];
button ← Buttons.Create[info: info, proc: BooleanButton];
IF ~init THEN Buttons.SetDisplayStyle[button, $WhiteOnBlack];
boolItem ← NEW[BoolItemObject ← [button, proc, init]];
ViewerOps.AddProp[button, $BoolItem, boolItem];
END;
MakeBoolItem: PUBLIC PROC[
 name: ROPE, proc: BoolItemProc, sib: Viewer, init: BOOL, newLine: BOOLFALSE]
  RETURNS[button: Viewer] =
BEGIN
boolItem: BoolItem;
info: ViewerRec ←
[name: name, parent: sib.parent, wy: sib.wy, wh: entryHeight, border: FALSE];
IF newLine THEN
{ info.wx ← IF sib.parent.scrollable THEN 0 ELSE xFudge;
info.wy ← info.wy + sib.wh + 2;
}
ELSE info.wx ← sib.wx+sib.ww+4;
button ← Buttons.Create[info: info, proc: BooleanButton];
IF init THEN Buttons.SetDisplayStyle[button, $WhiteOnBlack];
boolItem ← NEW[BoolItemObject ← [button, proc, init]];
ViewerOps.AddProp[button, $BoolItem, boolItem];
END;
BooleanButton: Buttons.ButtonProc = TRUSTED
BEGIN
v: Viewer ← NARROW[parent];
item: BoolItem ← NARROW[ViewerOps.FetchProp[v, $BoolItem]];
IF ~item.value THEN Buttons.SetDisplayStyle[v, $WhiteOnBlack]
ELSE Buttons.SetDisplayStyle[v, $BlackOnWhite];
item.value ← ~item.value;  -- complement the value
item.proc[item.value];   -- call proc to change its stored value
END;
PatternButton: PUBLIC PROC[sib: Viewer, newLine: BOOLFALSE] =
BEGIN
button: Viewer;
info: ViewerRec ←
[name: "Pattern:", parent: sib.parent, wy: sib.wy, wh: entryHeight, border: FALSE];
IF newLine THEN
{ info.wx ← IF sib.parent.scrollable THEN 0 ELSE xFudge;
info.wy ← info.wy + sib.wh;
}
ELSE info.wx ← sib.wx+sib.ww;
button ← Buttons.Create[info: info, proc: PatternItemProc];
patternButton ← Labels.Create[
info: [name: " ", parent: sib.parent, wx: button.wx+button.ww+xFudge,
 wy: button.wy, wh: entryHeight, border: FALSE]];
SetPatternText[EtherTesterOps.pattern];
END;
SetPatternText: PROC[pat: EtherTesterOps.Pattern] =
BEGIN
r: ROPE;
r ← SELECT pat FROM
ignore => "Ignore",
zeros => "Zeros",
ones => "Ones",
alternating => "125252B",
pairs => "146314B",
oneTwentyFive => "125B",
countBytes => "CountBytes",
countWords => "CountWords",
lenOne => "Len-1",
lenSix => "Len-6",
ENDCASE => ERROR;
Labels.Set[patternButton, r];
END;
PatternItemProc: Buttons.ButtonProc = TRUSTED
BEGIN OPEN EtherTesterOps;
new: Pattern ← IF pattern = LAST[Pattern] THEN FIRST[Pattern] ELSE SUCC[pattern];
pattern ← new;
SetPatternText[pattern];
END;
HWModeButton: PUBLIC PROC[sib: Viewer, newLine: BOOLFALSE] =
BEGIN
button: Viewer;
info: ViewerRec ←
[name: "HWMode:", parent: sib.parent, wy: sib.wy, wh: entryHeight, border: FALSE];
IF newLine THEN
{ info.wx ← IF sib.parent.scrollable THEN 0 ELSE xFudge;
info.wy ← info.wy + sib.wh;
}
ELSE info.wx ← sib.wx+sib.ww;
button ← Buttons.Create[info: info, proc: HWModeItemProc];
hwModeButton ← Labels.Create[
info: [name: " ", parent: sib.parent, wx: button.wx+button.ww+xFudge,
 wy: button.wy, wh: entryHeight, border: FALSE]];
SetHWModeText[EtherTesterOps.hwMode];
END;
SetHWModeText: PROC[mode: EtherTesterOps.HWTestMode] =
BEGIN
r: ROPE;
r ← SELECT mode FROM
normal => r ← "normal",
loopBack => r ← "loopback",
other => r ← "other",
ENDCASE => ERROR;
Labels.Set[hwModeButton, r];
END;
HWModeItemProc: Buttons.ButtonProc = TRUSTED
BEGIN OPEN EtherTesterOps;
new: HWTestMode ←
IF hwMode = LAST[HWTestMode] THEN FIRST[HWTestMode] ELSE SUCC[hwMode];
hwMode ← new;
SetHWModeText[hwMode];
END;
MakeStatsDisplayers: PUBLIC PROC[y: INTEGER, parent: Viewer] =
BEGIN
x: INTEGER ← 0;
numY: INTEGER ← y + 3;
labelY: INTEGER ← numY + entryHeight + 4;
last: StatsItem ← NIL;
statsDisplayer ← NIL;
FOR i: EtherTesterOps.StatsType IN [sent .. idle] DO
box: Viewer ← ViewerTools.MakeNewTextViewer[
info: [parent: parent, wx: x + 9, wy: y, ww: 40, wh: 2*entryHeight,
  border: FALSE, scrollable: FALSE]];
num: NumberLabels.NumberLabel ← NumberLabels.CreateNumber[
info: [parent: parent, wx: x+2, wy: numY, ww: 50, wh: entryHeight+1,
  scrollable: FALSE], chars: 6];
label: Viewer ← Labels.Create[
info: [name: StatsTypeToRope[i], parent: parent, wx: x+6, wy: labelY, wh: entryHeight,
  border: FALSE]];
this: StatsItem ← NEW[StatsItemObject ← [box, label, num, right, i, 0, NIL]];
IF last # NIL THEN last.next ← this;
last ← this;
IF statsDisplayer = NIL THEN statsDisplayer ← this;
x ← x + 50;
ENDLOOP;
END;
StatsTypeToRope: PUBLIC PROC[which: EtherTesterOps.StatsType] RETURNS[r: ROPE] =
BEGIN
SELECT which FROM
sent => r ← "sent";
coll => r ← "coll";
errOut => r ← "errOut";
recv => r ← "recv";
noIn => r ← "noIn";
noOut => r ← "noOut";
errIn => r ← "errIn";
echoed => r ← "echoed";
late => r ← "late";
lost => r ← "lost";
dally => r ← "dally";
idle => r ← "idle";
ENDCASE => r ← "ERROR";
END;
UpdateStatsBoxes: PUBLIC PROC =
BEGIN
item: StatsItem ← statsDisplayer;
curr: INT;
IF (curr ← EtherTesterOps.stats.pktsOut) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.collisions) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.errsOut) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.pktsIn) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.missed) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.packetsNotEchoed) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.errsIn) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.packetsEchoed) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.lateEchos) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.echosMissed) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.stats.dallyForEcho) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
item ← item.next;
IF (curr ← EtherTesterOps.realBackground) # item.currentlyDisplayed THEN
 NumberLabels.NumberLabelUpdate[item.num, item.currentlyDisplayed ← curr];
END;
END.