Skip to content

Commit 354c6d8

Browse files
committed
merge: move float precision resolve
2 parents 2375966 + b14b494 commit 354c6d8

File tree

6 files changed

+90
-18
lines changed

6 files changed

+90
-18
lines changed

src/aceinna/bootstrap/web.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
import os
55
import sys
6-
#import asyncio
6+
# import asyncio
77
import json
88
import time
99
import traceback
@@ -289,6 +289,48 @@ def stop_log(self, *args): # pylint: disable=invalid-name
289289
self.response_message('stopLog', {'packetType': 'success', 'data': ''})
290290

291291

292+
class UploadHandler(tornado.web.RequestHandler):
293+
def set_default_headers(self):
294+
self.set_header('Access-Control-Allow-Origin', '*')
295+
self.set_header('Access-Control-Allow-Headers',
296+
'x-requested-with, authorization')
297+
self.set_header('Access-Control-Allow-Methods',
298+
'POST, GET, PUT, DELETE')
299+
300+
def get(self):
301+
self.write('some get')
302+
303+
def post(self, *args, **kwargs):
304+
files = self.request.files
305+
uploaded_files = []
306+
307+
try:
308+
for inputname in files:
309+
http_file = files[inputname]
310+
for file_inst in http_file:
311+
file_path = os.path.join(
312+
resource.get_executor_path(), 'upgrade', file_inst.filename)
313+
314+
with open(file_path, 'wb') as file_writer:
315+
file_writer.write(file_inst.body)
316+
317+
uploaded_files.append(
318+
{'name': file_inst.filename, 'path': file_path})
319+
self.write({
320+
'success': True,
321+
'data': uploaded_files
322+
})
323+
except:
324+
self.write({
325+
'success': False
326+
})
327+
328+
def options(self):
329+
# no body
330+
self.set_status(204)
331+
self.finish()
332+
333+
292334
class MessageStore(object):
293335
def __init__(self):
294336
self.messages = Queue()
@@ -330,8 +372,8 @@ class LoggerServerSentEvent(tornado.web.RequestHandler):
330372

331373
def __init__(self, *args, **kwargs):
332374
super(LoggerServerSentEvent, self).__init__(*args, **kwargs)
333-
#self.set_header('Content-Type', 'text/event-stream')
334-
#self.set_header('Access-Control-Allow-Origin', '*')
375+
# self.set_header('Content-Type', 'text/event-stream')
376+
# self.set_header('Access-Control-Allow-Origin', '*')
335377

336378
def initialize(self, store):
337379
'''
@@ -408,7 +450,7 @@ def listen(self):
408450
target=self.detect_device_wrapper, args=(loop,))
409451
thread.start()
410452

411-
#self.non_main_ioloop = tornado.ioloop.IOLoop.current()
453+
# self.non_main_ioloop = tornado.ioloop.IOLoop.current()
412454
# loop.run_forever()
413455

414456
def prepare_logger(self):
@@ -524,7 +566,8 @@ def start_websocket_server(self):
524566
application = tornado.web.Application(
525567
[
526568
(r'/', WSHandler, dict(server=self)),
527-
(r'/sse', LoggerServerSentEvent, dict(store=store))
569+
(r'/sse', LoggerServerSentEvent, dict(store=store)),
570+
(r'/upload', UploadHandler)
528571
])
529572
self.http_server = tornado.httpserver.HTTPServer(application)
530573
# self.http_server.listen(self.options.port)
@@ -584,7 +627,7 @@ def detect_device_wrapper(self, current_loop):
584627
asyncio.set_event_loop(asyncio.new_event_loop())
585628
# asyncio.set_event_loop(current_loop)
586629

587-
#self.non_main_ioloop = tornado.ioloop.IOLoop.current()
630+
# self.non_main_ioloop = tornado.ioloop.IOLoop.current()
588631
self.detect_device(self.device_discover_handler)
589632
except Exception as ex:
590633
print_red(ex)

src/aceinna/devices/base/rtk_provider_base.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def prepare_folders(self):
6767
'''
6868
Prepare folders for data storage and configuration
6969
'''
70+
7071
executor_path = resource.get_executor_path()
7172
setting_folder_name = 'setting'
7273
config_file_name = 'openrtk.json'
@@ -87,6 +88,11 @@ def prepare_folders(self):
8788
if not os.path.isdir(product_folder):
8889
os.makedirs(product_folder)
8990

91+
if product == 'RTK330L':
92+
config_file_name = 'RTK330L.json'
93+
else:
94+
config_file_name = 'openrtk.json'
95+
9096
for app_name in all_products[product]:
9197
app_name_path = os.path.join(product_folder, app_name)
9298
app_name_config_path = os.path.join(
@@ -153,18 +159,23 @@ def _build_app_info(self, text):
153159
}
154160

155161
def load_properties(self):
162+
product_name = self.device_info['name']
163+
app_name = self.app_info['app_name']
164+
165+
json_file_name = 'openrtk.json'
166+
if product_name == 'RTK330L':
167+
json_file_name = 'RTK330L.json'
168+
156169
# Load config from user working path
157-
local_config_file_path = os.path.join(os.getcwd(), 'openrtk.json')
170+
local_config_file_path = os.path.join(os.getcwd(), json_file_name)
158171
if os.path.isfile(local_config_file_path):
159172
with open(local_config_file_path) as json_data:
160173
self.properties = json.load(json_data)
161174
return
162175

163176
# Load the openimu.json based on its app
164-
product_name = self.device_info['name']
165-
app_name = self.app_info['app_name']
166177
app_file_path = os.path.join(
167-
self.setting_folder_path, product_name, app_name, 'openrtk.json')
178+
self.setting_folder_path, product_name, app_name, json_file_name)
168179

169180
if not self.is_app_matched:
170181
print_yellow(

src/aceinna/devices/openimu/uart_provider.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ def _build_app_info(self, text):
140140
}
141141

142142
# Change the device model name if got model name from the first split string of version
143-
if split_text[0] in get_openimu_products():
143+
if len(split_text) > 0 and split_text[0] in get_openimu_products():
144144
self.device_info['name'] = split_text[0]
145145

146+
if len(split_text) == 0:
147+
self.device_info['name'] = 'OpenIMU300ZI'
148+
146149
def load_properties(self):
147150
# Load config from user working path
148151
local_config_file_path = os.path.join(os.getcwd(), 'openimu.json')
@@ -636,10 +639,17 @@ def hard_iron_cal(self, value, data_type):
636639
pi_value = 2 ** 15 / math.pi
637640
return decoded_value / pi_value
638641

639-
def upgrade_framework(self, file, *args): # pylint: disable=invalid-name
642+
def upgrade_framework(self, params, *args): # pylint: disable=invalid-name
640643
'''
641644
upgrade framework
642645
'''
646+
file = ''
647+
if isinstance(params, str):
648+
file = params
649+
650+
if isinstance(params, dict):
651+
file = params['file']
652+
643653
# start a thread to do upgrade
644654
if not self.is_upgrading:
645655
self.is_upgrading = True

src/aceinna/devices/parsers/open_field_parser.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import math
22
import struct
3+
import decimal
34

45

5-
def do_decode_value(data_type, data):
6+
def do_decode_value(data_type, data, conf):
67
if data_type == 'uint64':
78
try:
89
pack_item = struct.pack('8B', *data)
@@ -38,7 +39,14 @@ def do_decode_value(data_type, data):
3839
pack_item = struct.pack('4B', *data)
3940
except: # pylint: disable=bare-except
4041
return False
41-
return struct.unpack('<f', pack_item)[0]
42+
43+
unpack_value = struct.unpack('<f', pack_item)[0]
44+
# use decimal, float type is a special case
45+
if conf and conf['value_accuracy']:
46+
precision = conf['value_accuracy']
47+
decimal_wrapped = decimal.Decimal(unpack_value)
48+
unpack_value = float(round(decimal_wrapped, precision))
49+
return unpack_value
4250
elif data_type == 'uint16':
4351
try:
4452
pack_item = struct.pack('2B', *data)
@@ -104,8 +112,8 @@ def do_decode_value(data_type, data):
104112
return False
105113

106114

107-
def decode_value(data_type, data):
108-
ret_value = do_decode_value(data_type, data)
115+
def decode_value(data_type, data, conf=None):
116+
ret_value = do_decode_value(data_type, data, conf)
109117

110118
if not isinstance(ret_value, float):
111119
return ret_value

src/aceinna/devices/parsers/open_packet_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_parameters_by_block_parser(payload, user_configuration):
104104
data_len = data_len + 2
105105
elif param_type == 'uint32' or param_type == 'int32' or param_type == 'float':
106106
value = decode_value(
107-
param_type, payload[data_len:data_len + 4])
107+
param_type, payload[data_len:data_len + 4], exist_param_conf)
108108
data_len = data_len + 4
109109
elif param_type == 'uint64' or param_type == 'int64' or param_type == 'double':
110110
value = decode_value(

src/aceinna/setting/RTK330L/RTK_INS/openrtk.json renamed to src/aceinna/setting/RTK330L/RTK_INS/RTK330L.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"appVersion": "RTK330LA INS 27.00",
2+
"appVersion": "RTK330LA INS 24.00",
33
"type": "openrtk",
44
"description": "6-axis OpenRTK with INS application",
55
"initial":{

0 commit comments

Comments
 (0)