-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.rb
executable file
·67 lines (57 loc) · 1.25 KB
/
constants.rb
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
#!/usr/bin/env ruby
#
# Produce the EEPROM data file
#
magic=0x5aa5
battery_cal = 16.0
solar_cal = 20.0
battery_crit=0.0
battery_low=11.0
battery_high=14.5
solar_high=18.0
# Constants: Kp, Ki, Kd, Emul, Ediv, Esigma(0), Eprev(0), Umul, Udiv
wind_consts = [60, 4, 20, 1, 1, 0, 0, 1, 122]
compass_consts = [80, 300, 260, 1, 1, 0, 0, 1, 1]
eeprom = Array(23)
eeprom[0] = magic
eeprom[1] = ((battery_crit * 1024.0 / battery_cal) + 0.5).to_i
eeprom[2] = ((battery_low * 1024.0 / battery_cal) + 0.5).to_i
eeprom[3] = ((battery_high * 1024.0 / battery_cal) + 0.5).to_i
eeprom[4] = ((solar_high * 1024.0 / solar_cal) + 0.5).to_i
idx = 5
wind_consts.each do |val|
eeprom[idx] = val
idx += 1
end
compass_consts.each do |val|
eeprom[idx] = val
idx += 1
end
def dump(addr, data, len)
return if len < 1
str = ":%02X%04X00" % [len, addr]
csum = len
csum += (addr >> 8) & 0xff
csum += addr & 0xff
len.times do |i|
str += "%02X" % data[i]
csum += data[i]
end
str += "%02X" % (-csum & 0xff)
puts str
end
idx = 0
addr = 0
data = Array(16)
eeprom.each do |val|
data[idx] = val & 0xff;
data[idx + 1] = (val >> 8) & 0xff
idx += 2
if idx > 15
dump(addr, data, idx)
addr += 16
idx = 0
end
end
dump(addr, data, idx)
puts ":00000001FF"