Unified · Split
| @@ -2,77 +2,94 @@ implement TestExactus; · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | include "sys.m"; |
| 4 | 4 | include "draw.m"; |
| 5 | +include "arg.m"; | |
| 5 | 6 | include "lock.m"; |
| 7 | +include "string.m"; | |
| 6 | 8 | |
| 7 | 9 | include "exactus.m"; |
| 8 | 10 | |
| 9 | 11 | sys: Sys; |
| 10 | −draw: Draw; | |
| 12 | +str: String; | |
| 11 | 13 | |
| 12 | 14 | exactus: Exactus; |
| 13 | − Instruction, Port: import exactus; | |
| 15 | + ERmsg, Port: import exactus; | |
| 14 | 16 | |
| 15 | 17 | TestExactus: module { |
| 16 | 18 | init: fn(ctxt: ref Draw->Context, argv: list of string); |
| 17 | 19 | }; |
| 18 | 20 | |
| 19 | −init(ctxt: ref Draw->Context, nil: list of string) | |
| 21 | +stdin, stdout, stderr: ref Sys->FD; | |
| 22 | + | |
| 23 | +port: ref Port; | |
| 24 | + | |
| 25 | +init(nil: ref Draw->Context, argv: list of string) | |
| 20 | 26 | { |
| 21 | 27 | sys = load Sys Sys->PATH; |
| 28 | + str = load String String->PATH; | |
| 22 | 29 | |
| 30 | + stderr = sys->fildes(2); | |
| 31 | + stdout = sys->fildes(1); | |
| 32 | + stdin = sys->fildes(0); | |
| 33 | + | |
| 23 | 34 | exactus = load Exactus Exactus->PATH; |
| 24 | 35 | exactus->init(); |
| 25 | 36 | |
| 26 | −# tls := exactus->open("/dev/eia0"); | |
| 27 | − | |
| 28 | − rfd := sys->open("/dev/eia0", Sys->OREAD); | |
| 29 | − wfd := sys->open("/dev/eia0", Sys->OWRITE); | |
| 37 | + path := "tcp!iolan!exactus"; | |
| 38 | + skip := 0; | |
| 30 | 39 | |
| 31 | − b := array[] of { | |
| 32 | − byte 16r01, byte 16r05, byte 16r00, byte 16r13, byte 16r00, byte 16r00, | |
| 33 | − byte 16r3c, byte 16r0f | |
| 34 | − }; | |
| 35 | − sys->write(wfd, b, len b); | |
| 40 | + arg := load Arg Arg->PATH; | |
| 41 | + arg->init(argv); | |
| 42 | + arg->setusage(arg->progname()+" [-s] [path]"); | |
| 43 | + while((c := arg->opt()) != 0) | |
| 44 | + case c { | |
| 45 | + 's' => skip++; | |
| 46 | + * => arg->usage(); | |
| 47 | + } | |
| 36 | 48 | |
| 37 | − b = array[] of { | |
| 38 | − byte 16r02, byte 16r56, byte 16r56, byte 16r03 | |
| 39 | − }; | |
| 40 | − sys->write(wfd, b, len b); | |
| 49 | + argv = arg->argv(); | |
| 50 | + if(argv != nil) | |
| 51 | + path = hd argv; | |
| 41 | 52 | |
| 42 | − buf := array[1] of byte; | |
| 43 | − while (1) { | |
| 44 | − sys->read(rfd, buf, len buf); | |
| 45 | − dump(buf); | |
| 53 | + if(path != nil && skip == 0) { | |
| 54 | + port = exactus->open(path); | |
| 55 | + if(port.ctl == nil || port.data == nil) { | |
| 56 | + sys->fprint(stderr, "Failed to connect to %s\n", port.path); | |
| 57 | + exit; | |
| 58 | + } | |
| 46 | 59 | } |
| 47 | −# write(tls, b); | |
| 48 | −# read(tls); | |
| 49 | −# read(tls); | |
| 50 | −# read(tls); | |
| 51 | −# read(tls); | |
| 52 | −# | |
| 53 | −# exactus->close(tls); | |
| 60 | + | |
| 61 | + testdata(); | |
| 62 | + | |
| 63 | + if(port != nil && skip == 0) | |
| 64 | + testnetwork(port); | |
| 65 | + | |
| 66 | + if(port != nil) | |
| 67 | + exactus->close(port); | |
| 54 | 68 | } |
| 55 | 69 | |
| 56 | −read(p: ref Exactus->Port): ref Exactus->Instruction | |
| 70 | +testnetwork(p: ref Exactus->Port) | |
| 57 | 71 | { |
| 58 | − r := exactus->readreply(p, 100); | |
| 59 | − if(r != nil) | |
| 60 | − sys->print("RX <- %s\n", dump(r.bytes())); | |
| 61 | − return r; | |
| 62 | − return r; | |
| 63 | 72 | } |
| 64 | 73 | |
| 65 | −write(p: ref Exactus->Port, b: array of byte) | |
| 74 | +testdata() | |
| 66 | 75 | { |
| 67 | − sys->print("TX -> %s\n", dump(b)); | |
| 68 | − p.write(b); | |
| 76 | + b := array[] of {byte 16r44, byte 16r45, byte 16r00, byte 16r42, byte 16rC8, | |
| 77 | + byte 16r00, byte 16r00, byte 16r3F, byte 16r66, byte 16r66, | |
| 78 | + byte 16r66, byte 16r3F, byte 16r00, byte 16r00, byte 16r00}; | |
| 79 | + | |
| 80 | + sys->fprint(stdout, "LRC of:%s\n", hexdump(b)); | |
| 81 | + sys->fprint(stdout, "LRC ==\t%0X\n", int exactus->lrc(b)); | |
| 69 | 82 | } |
| 70 | 83 | |
| 71 | −dump(b: array of byte): string | |
| 84 | + | |
| 85 | +hexdump(b: array of byte): string | |
| 72 | 86 | { |
| 73 | 87 | s := ""; |
| 74 | − for(i:=0; i<len b; i++) | |
| 88 | + for(i:=0; i<len b; i++) { | |
| 89 | + if(i%8 == 0) | |
| 90 | + s = s + "\n\t"; | |
| 75 | 91 | s = sys->sprint("%s %02X", s, int(b[i])); |
| 76 | − s = sys->sprint("%s %s", s, string(b[2:])); | |
| 77 | − return s; | |
| 92 | + } | |
| 93 | + | |
| 94 | + return str->drop(s, "\n"); | |
| 78 | 95 | } |
| @@ -22,6 +22,12 @@ Port.write(p: self ref Port, b: array of byte): int · 21 unmodified lines | ||
| 22 | 22 | return r; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | +ERmsg.pack(m: self ref ERmsg): array of byte | |
| 26 | +{ | |
| 27 | + sys->fprint(stderr, "not complete\n"); | |
| 28 | + return m.data; | |
| 29 | +} | |
| 30 | + | |
| 25 | 31 | stderr: ref Sys->FD; |
| 26 | 32 | |
| 27 | 33 | init() |
| @@ -43,7 +49,7 @@ open(path: string): ref Exactus->Port · 15 unmodified lines | ||
| 43 | 49 | |
| 44 | 50 | np := ref Port; |
| 45 | 51 | np.mode = ModeModbus; |
| 46 | − np.local = path; | |
| 52 | + np.path = path; | |
| 47 | 53 | np.rdlock = Semaphore.new(); |
| 48 | 54 | np.wrlock = Semaphore.new(); |
| 49 | 55 | np.avail = nil; |
| @@ -67,19 +73,19 @@ openport(p: ref Port) · 17 unmodified lines | ||
| 67 | 73 | p.data = nil; |
| 68 | 74 | p.ctl = nil; |
| 69 | 75 | |
| 70 | − if(p.local != nil) { | |
| 71 | − if(str->in('!', p.local)) { | |
| 72 | − (ok, net) := sys->dial(p.local, nil); | |
| 76 | + if(p.path != nil) { | |
| 77 | + if(str->in('!', p.path)) { | |
| 78 | + (ok, net) := sys->dial(p.path, nil); | |
| 73 | 79 | if(ok == -1) { |
| 74 | − raise "can't open "+p.local; | |
| 80 | + raise "can't open "+p.path; | |
| 75 | 81 | return; |
| 76 | 82 | } |
| 77 | 83 | |
| 78 | 84 | p.ctl = sys->open(net.dir+"/ctl", Sys->ORDWR); |
| 79 | 85 | p.data = sys->open(net.dir+"/data", Sys->ORDWR); |
| 80 | 86 | } else { |
| 81 | − p.ctl = sys->open(p.local+"ctl", Sys->ORDWR); | |
| 82 | − p.data = sys->open(p.local, Sys->ORDWR); | |
| 87 | + p.ctl = sys->open(p.path+"ctl", Sys->ORDWR); | |
| 88 | + p.data = sys->open(p.path, Sys->ORDWR); | |
| 83 | 89 | b := array[] of { byte "b115200" }; |
| 84 | 90 | sys->write(p.ctl, b, len b); |
| 85 | 91 | } |
| @@ -105,9 +111,27 @@ close(p: ref Port): ref Sys->Connection · 19 unmodified lines | ||
| 105 | 111 | c := ref sys->Connection(p.data, p.ctl, nil); |
| 106 | 112 | p.ctl = nil; |
| 107 | 113 | p.data = nil; |
| 114 | + | |
| 115 | + hangup := array[] of {byte "hangup"}; | |
| 116 | + sys->write(p.ctl, hangup, len hangup); | |
| 117 | + | |
| 108 | 118 | return c; |
| 109 | 119 | } |
| 110 | 120 | |
| 121 | +# Exactus mode LRC Calculation | |
| 122 | +lrc(buf: array of byte): byte | |
| 123 | +{ | |
| 124 | + r := byte 0; | |
| 125 | + n := len buf; | |
| 126 | + if (n > 0) | |
| 127 | + r = buf[0]; | |
| 128 | + | |
| 129 | + for (i := 1; i < n; i++) | |
| 130 | + r ^= buf[i]; | |
| 131 | + | |
| 132 | + return r; | |
| 133 | +} | |
| 134 | + | |
| 111 | 135 | getreply(p: ref Port, n: int): array of ref ERmsg |
| 112 | 136 | { |
| 113 | 137 | if(p==nil || n <= 0) |
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <../mkconfig |
| 2 | 2 | |
| 3 | 3 | DIRS=\ |
| 4 | − cmd\ | |
| 5 | 4 | lib\ |
| 5 | + cmd\ | |
| 6 | 6 | |
| 7 | 7 | <$ROOT/mkfiles/mksubdirs |
| 8 | 8 | |
| @@ -0,0 +1,2 @@ | ||
| 1 | + | |
| 2 | +all:QV: | |
| @@ -35,7 +35,7 @@ Exactus : module · 34 unmodified lines | ||
| 35 | 35 | { |
| 36 | 36 | mode: int; |
| 37 | 37 | |
| 38 | − local: string; | |
| 38 | + path: string; | |
| 39 | 39 | ctl: ref Sys->FD; |
| 40 | 40 | data: ref Sys->FD; |
| 41 | 41 | |
| @@ -51,6 +51,9 @@ Exactus : module · 9 unmodified lines | ||
| 51 | 51 | |
| 52 | 52 | ERmsg: adt { |
| 53 | 53 | mode: int; |
| 54 | + data: array of byte; | |
| 55 | + | |
| 56 | + pack: fn(m: self ref ERmsg): array of byte; | |
| 54 | 57 | }; |
| 55 | 58 | |
| 56 | 59 | init: fn(); |
| @@ -58,6 +61,8 @@ Exactus : module · 1 unmodified line | ||
| 58 | 61 | open: fn(path: string): ref Exactus->Port; |
| 59 | 62 | close: fn(p: ref Port): ref Sys->Connection; |
| 60 | 63 | |
| 64 | + lrc: fn(buf: array of byte): byte; | |
| 65 | + | |
| 61 | 66 | getreply: fn(p: ref Port, n: int): array of ref ERmsg; |
| 62 | 67 | readreply: fn(p: ref Port, ms: int): ref ERmsg; |
| 63 | 68 | }; |
| @@ -7,20 +7,24 @@ · 6 unmodified lines | ||
| 7 | 7 | objects = { |
| 8 | 8 | |
| 9 | 9 | /* Begin PBXFileReference section */ |
| 10 | − 41120B1C12F8C07300576FF7 /* mkconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mkconfig; path = ../mkconfig; sourceTree = "<group>"; }; | |
| 11 | − 41120B1D12F8C07300576FF7 /* mkfile */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; name = mkfile; path = ../mkfile; sourceTree = "<group>"; }; | |
| 10 | + 41120B1C12F8C07300576FF7 /* mkconfig */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; name = mkconfig; path = ../mkconfig; sourceTree = "<group>"; }; | |
| 11 | + 41120B1D12F8C07300576FF7 /* mkfile */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; name = mkfile; path = ../mkfile; sourceTree = "<group>"; }; | |
| 12 | 12 | 41120B1E12F8C07300576FF7 /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.txt; path = ../README.txt; sourceTree = "<group>"; }; |
| 13 | 13 | 41120B2212F8C1D900576FF7 /* module */ = {isa = PBXFileReference; lastKnownFileType = folder; name = module; path = ../module; sourceTree = "<group>"; }; |
| 14 | − 41120B2412F8C2FC00576FF7 /* appl */ = {isa = PBXFileReference; lastKnownFileType = folder; name = appl; path = ../appl; sourceTree = "<group>"; }; | |
| 15 | − 4130904012F8D2DB00444069 /* mkfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mkfile; path = ../appl/mkfile; sourceTree = SOURCE_ROOT; }; | |
| 14 | + 4153D8F81345176B005EED5F /* mkfile */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = mkfile; sourceTree = "<group>"; }; | |
| 15 | + 4153D8FB13451DC0005EED5F /* mkfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mkfile; sourceTree = "<group>"; }; | |
| 16 | + 4153D8FC13451DC0005EED5F /* testexactus.b */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.limbo; path = testexactus.b; sourceTree = "<group>"; }; | |
| 17 | + 4153D90013451DC0005EED5F /* exactus.b */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.limbo; path = exactus.b; sourceTree = "<group>"; }; | |
| 18 | + 4153D90313451DC0005EED5F /* mkfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mkfile; sourceTree = "<group>"; }; | |
| 19 | + 4153D90413451DC0005EED5F /* mkfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mkfile; sourceTree = "<group>"; }; | |
| 16 | 20 | /* End PBXFileReference section */ |
| 17 | 21 | |
| 18 | 22 | /* Begin PBXGroup section */ |
| 19 | 23 | 41120B0812F8BF8200576FF7 = { |
| 20 | 24 | isa = PBXGroup; |
| 21 | 25 | children = ( |
| 22 | − 41120B2412F8C2FC00576FF7 /* appl */, | |
| 23 | − 4130904012F8D2DB00444069 /* mkfile */, | |
| 26 | + 4153D8F913451DC0005EED5F /* appl */, | |
| 27 | + 4153D8F71345176B005EED5F /* man */, | |
| 24 | 28 | 41120B2212F8C1D900576FF7 /* module */, |
| 25 | 29 | 41120B1C12F8C07300576FF7 /* mkconfig */, |
| 26 | 30 | 41120B1D12F8C07300576FF7 /* mkfile */, |
| @@ -28,6 +32,44 @@ · 1 unmodified line | ||
| 28 | 32 | ); |
| 29 | 33 | sourceTree = "<group>"; |
| 30 | 34 | }; |
| 35 | + 4153D8F71345176B005EED5F /* man */ = { | |
| 36 | + isa = PBXGroup; | |
| 37 | + children = ( | |
| 38 | + 4153D8F81345176B005EED5F /* mkfile */, | |
| 39 | + ); | |
| 40 | + name = man; | |
| 41 | + path = ../man; | |
| 42 | + sourceTree = "<group>"; | |
| 43 | + }; | |
| 44 | + 4153D8F913451DC0005EED5F /* appl */ = { | |
| 45 | + isa = PBXGroup; | |
| 46 | + children = ( | |
| 47 | + 4153D8FA13451DC0005EED5F /* cmd */, | |
| 48 | + 4153D8FF13451DC0005EED5F /* lib */, | |
| 49 | + 4153D90413451DC0005EED5F /* mkfile */, | |
| 50 | + ); | |
| 51 | + name = appl; | |
| 52 | + path = ../appl; | |
| 53 | + sourceTree = "<group>"; | |
| 54 | + }; | |
| 55 | + 4153D8FA13451DC0005EED5F /* cmd */ = { | |
| 56 | + isa = PBXGroup; | |
| 57 | + children = ( | |
| 58 | + 4153D8FB13451DC0005EED5F /* mkfile */, | |
| 59 | + 4153D8FC13451DC0005EED5F /* testexactus.b */, | |
| 60 | + ); | |
| 61 | + path = cmd; | |
| 62 | + sourceTree = "<group>"; | |
| 63 | + }; | |
| 64 | + 4153D8FF13451DC0005EED5F /* lib */ = { | |
| 65 | + isa = PBXGroup; | |
| 66 | + children = ( | |
| 67 | + 4153D90013451DC0005EED5F /* exactus.b */, | |
| 68 | + 4153D90313451DC0005EED5F /* mkfile */, | |
| 69 | + ); | |
| 70 | + path = lib; | |
| 71 | + sourceTree = "<group>"; | |
| 72 | + }; | |
| 31 | 73 | /* End PBXGroup section */ |
| 32 | 74 | |
| 33 | 75 | /* Begin PBXLegacyTarget section */ |