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
22
33 include "sys.m";
44 include "draw.m";
5+include "arg.m";
56 include "lock.m";
7+include "string.m";
68
79 include "exactus.m";
810
911 sys: Sys;
10−draw: Draw;
12+str: String;
1113
1214 exactus: Exactus;
13− Instruction, Port: import exactus;
15+ ERmsg, Port: import exactus;
1416
1517 TestExactus: module {
1618 init: fn(ctxt: ref Draw->Context, argv: list of string);
1719 };
1820
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)
2026 {
2127 sys = load Sys Sys->PATH;
28+ str = load String String->PATH;
2229
30+ stderr = sys->fildes(2);
31+ stdout = sys->fildes(1);
32+ stdin = sys->fildes(0);
33+
2334 exactus = load Exactus Exactus->PATH;
2435 exactus->init();
2536
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;
3039
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+ }
3648
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;
4152
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+ }
4659 }
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);
5468 }
5569
56−read(p: ref Exactus->Port): ref Exactus->Instruction
70+testnetwork(p: ref Exactus->Port)
5771 {
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;
6372 }
6473
65−write(p: ref Exactus->Port, b: array of byte)
74+testdata()
6675 {
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));
6982 }
7083
71−dump(b: array of byte): string
84+
85+hexdump(b: array of byte): string
7286 {
7387 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";
7591 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");
7895 }
appl/lib/exactus.b+31−7
@@ -22,6 +22,12 @@ Port.write(p: self ref Port, b: array of byte): int · 21 unmodified lines
2222 return r;
2323 }
2424
25+ERmsg.pack(m: self ref ERmsg): array of byte
26+{
27+ sys->fprint(stderr, "not complete\n");
28+ return m.data;
29+}
30+
2531 stderr: ref Sys->FD;
2632
2733 init()
@@ -43,7 +49,7 @@ open(path: string): ref Exactus->Port · 15 unmodified lines
4349
4450 np := ref Port;
4551 np.mode = ModeModbus;
46− np.local = path;
52+ np.path = path;
4753 np.rdlock = Semaphore.new();
4854 np.wrlock = Semaphore.new();
4955 np.avail = nil;
@@ -67,19 +73,19 @@ openport(p: ref Port) · 17 unmodified lines
6773 p.data = nil;
6874 p.ctl = nil;
6975
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);
7379 if(ok == -1) {
74− raise "can't open "+p.local;
80+ raise "can't open "+p.path;
7581 return;
7682 }
7783
7884 p.ctl = sys->open(net.dir+"/ctl", Sys->ORDWR);
7985 p.data = sys->open(net.dir+"/data", Sys->ORDWR);
8086 } 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);
8389 b := array[] of { byte "b115200" };
8490 sys->write(p.ctl, b, len b);
8591 }
@@ -105,9 +111,27 @@ close(p: ref Port): ref Sys->Connection · 19 unmodified lines
105111 c := ref sys->Connection(p.data, p.ctl, nil);
106112 p.ctl = nil;
107113 p.data = nil;
114+
115+ hangup := array[] of {byte "hangup"};
116+ sys->write(p.ctl, hangup, len hangup);
117+
108118 return c;
109119 }
110120
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+
111135 getreply(p: ref Port, n: int): array of ref ERmsg
112136 {
113137 if(p==nil || n <= 0)
appl/mkfile+1−1
@@ -1,8 +1,8 @@
11 <../mkconfig
22
33 DIRS=\
4− cmd\
54 lib\
5+ cmd\
66
77 <$ROOT/mkfiles/mksubdirs
88
man/mkfile+2−0
@@ -0,0 +1,2 @@
1+
2+all:QV:
module/exactus.m+6−1
@@ -35,7 +35,7 @@ Exactus : module · 34 unmodified lines
3535 {
3636 mode: int;
3737
38− local: string;
38+ path: string;
3939 ctl: ref Sys->FD;
4040 data: ref Sys->FD;
4141
@@ -51,6 +51,9 @@ Exactus : module · 9 unmodified lines
5151
5252 ERmsg: adt {
5353 mode: int;
54+ data: array of byte;
55+
56+ pack: fn(m: self ref ERmsg): array of byte;
5457 };
5558
5659 init: fn();
@@ -58,6 +61,8 @@ Exactus : module · 1 unmodified line
5861 open: fn(path: string): ref Exactus->Port;
5962 close: fn(p: ref Port): ref Sys->Connection;
6063
64+ lrc: fn(buf: array of byte): byte;
65+
6166 getreply: fn(p: ref Port, n: int): array of ref ERmsg;
6267 readreply: fn(p: ref Port, ms: int): ref ERmsg;
6368 };
xcode/exactus.xcodeproj/project.pbxproj+48−6
@@ -7,20 +7,24 @@ · 6 unmodified lines
77 objects = {
88
99 /* 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>"; };
1212 41120B1E12F8C07300576FF7 /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.txt; path = ../README.txt; sourceTree = "<group>"; };
1313 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>"; };
1620 /* End PBXFileReference section */
1721
1822 /* Begin PBXGroup section */
1923 41120B0812F8BF8200576FF7 = {
2024 isa = PBXGroup;
2125 children = (
22− 41120B2412F8C2FC00576FF7 /* appl */,
23− 4130904012F8D2DB00444069 /* mkfile */,
26+ 4153D8F913451DC0005EED5F /* appl */,
27+ 4153D8F71345176B005EED5F /* man */,
2428 41120B2212F8C1D900576FF7 /* module */,
2529 41120B1C12F8C07300576FF7 /* mkconfig */,
2630 41120B1D12F8C07300576FF7 /* mkfile */,
@@ -28,6 +32,44 @@ · 1 unmodified line
2832 );
2933 sourceTree = "<group>";
3034 };
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+ };
3173 /* End PBXGroup section */
3274
3375 /* 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