History

LRC in place

Jeff Sickel committed 15 years ago

Commit 50944d01 parent 55ec7156 files · +145 −55Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t