This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl_calc_assert.lua
80 lines (76 loc) · 2.85 KB
/
cl_calc_assert.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
cl_lib = require 'cl_calc'
print("--- 1.")
errcode , out = cl_lib.cl_calc_freq(4,5)
assert( errcode == 300, "cl_calc_freq() errcode != 300" )
assert( out == 9 , "cl_calc_freq() out != 9" )
print("--- 2.")
errcode, out = cl_lib.cl_calc_alert(4, 5, 10)
assert( errcode == 300, "cl_calc_alert() errcode != 300" )
assert( out == 19 , "cl_calc_alert() out != 19" )
print("--- 3.")
errcode, out = cl_lib.cl_calc_read(5, 9)
assert( errcode == 300, "cl_calc_read() errcode != 300" )
assert( out == 14 , "cl_calc_read() out != 14" )
print("--- 4. errcode == 301. invalid field name.")
-- Invalid field "flag" -> "flags". Expect an error
msg = {}
msg["addr"] = 0x1234
msg["flag"] = 0x0001
msg["len"] = 32
for key,value in pairs(msg) do print(key,value) end
errcode = cl_lib.cl_calc_timer( msg )
assert( errcode == 301, "cl_calc_timer() errcode != 300" )
print("--- 5. in + out")
msg = {}
msg["addr"] = 0x1234
msg["flags"] = 0x0001
msg["len"] = 32
for key,value in pairs(msg) do print("msg:",key,value) end
errcode , bus = cl_lib.cl_calc_timer( msg )
assert( errcode == 300, "cl_calc_timer() errcode != 300" )
for key,value in pairs(bus) do print("bus:", key,value) end
print("--- 6. in (call-by-value) + out")
msg = {}
msg["addr"] = 0x1234
msg["flags"] = 0x0001
msg["len"] = 32
for key,value in pairs(msg) do print("msg:",key,value) end
errcode , bus = cl_lib.cl_calc_write( msg )
assert( errcode == 300, "cl_calc_write() errcode != 300" )
for key,value in pairs(bus) do print("bus:",key,value) end
print("--- 7. inout + out ")
msg = {}
msg["addr"] = 0x1234
msg["flags"] = 0x0001
msg["len"] = 32
for key,value in pairs(msg) do print(key,value) end
errcode , msg1, bus2 = cl_lib.cl_calc_servo( msg )
assert( errcode == 300, "cl_calc_servo() errcode != 300" )
for key,value in pairs(msg1) do print("msg:",key,value) end
for key,value in pairs(bus2) do print("bus:",key,value) end
print("--- 8. in + out x 2 ")
msg = {}
msg["addr"] = 0x1234
msg["flags"] = 0x0001
msg["len"] = 32
for key,value in pairs(msg) do print( "msg:", key,value) end
errcode , bus1, bus2 = cl_lib.cl_calc_filter( msg )
assert( errcode == 300, "cl_calc_filter() errcode != 300" )
for key,value in pairs(bus1) do print( "bus1:", key,value) end
for key,value in pairs(bus2) do print( "bus2:", key,value) end
print("--- 9. in x 2 + out ")
msg1 = {}
msg1["addr"] = 0x1234
msg1["flags"] = 0x0001
msg1["len"] = 32
msg2 = {}
msg2["addr"] = 0x1235
msg2["flags"] = 0x0002
msg2["len"] = 33
for key,value in pairs(msg1) do print("msg1:", key,value) end
for key,value in pairs(msg2) do print("msg2:",key,value) end
errcode , bus = cl_lib.cl_calc_serial( msg1, msg2 )
assert( errcode == 300, "cl_calc_serial() errcode != 300" )
for key,value in pairs(bus) do print( "bus:", key,value) end
assert( bus["length"] == 32, "cl_calc_serial() bus[length] != 32" )
print("--- done")