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
|
# File 'lib/coban/tk103b.rb', line 23
def self.message(content)
= [
:imei, :type, :date, :phone, :gps_status, :time,
:gps_signal, :latitude, :north_south, :longitude,
:east_west, :speed, :direction, :elevation, :acc,
:door, :fuel, :oil, :temperatura
]
splited_content = content.gsub('imei:','').gsub(';','').split(',', -1)
result = {
imei: splited_content[.index(:imei)],
type: splited_content[.index(:type)],
phone: splited_content[.index(:phone)],
gps_status: splited_content[.index(:gps_status)],
gps_signal: splited_content[.index(:gps_signal)],
speed: splited_content[.index(:speed)],
direction: splited_content[.index(:direction)]
}
if splited_content.count > 13
result[:elevation] = splited_content[.index(:elevation)]
result[:acc] = splited_content[.index(:acc)]
result[:door] = splited_content[.index(:door)]
result[:fuel] = splited_content[.index(:fuel)]
result[:oil] = splited_content[.index(:oil)]
result[:temperatura] = splited_content[.index(:temperatura)]
end
pre_latitude = splited_content[.index(:latitude)]
latitude = pre_latitude[0...2].to_i(10) + ( pre_latitude[2...pre_latitude.size].to_f / 60 )
latitude *= -1 if splited_content[.index(:north_south)] == 'S'
pre_longitude = splited_content[.index(:longitude)]
longitude = pre_longitude[0...3].to_i(10) + ( pre_longitude[3...pre_longitude.size].to_f / 60 )
longitude *= -1 if splited_content[.index(:east_west)] == 'W'
result[:latitude] = latitude.round(8)
result[:longitude] = longitude.round(8)
date = splited_content[.index(:date)]
time = splited_content[.index(:time)]
unless date.size == date.count('0')
time = splited_content[.index(:time)]
result[:date] = DateTime.strptime('20' + date[0...6] + time.split('.').first,'%Y%m%d%H%M%S')
end
result[:type] = 'message'
result[:sub_type] = 'tracker'
result[:response] = nil
return result
end
|