def gen_radio_status_msg_str(): global radio_msg, ancien if radio_msg != "": rssi = extractData(radio_msg) if rssi < 0: rssi = -rssi # create a mavlink instance, which will do IO on file object 'f' mav = mavlink.MAVLink(f, 24, 1) #radio_status_encode(rssi, remrssi, txbuf, noise, remnoise, rxerrors, fixed) m = mav.radio_status_encode(rssi, 0, 9, 0, 0, 0, 9) m.pack(mav) # get the encoded message as a buffer b = m.get_msgbuf() radio_status_str = base64.b64encode(b) # the devEUI is false. We have to modify it if we need the good one. radio_status_msg_str = "{\"devEUI\":\"f03d291000000046\",\"fPort\":99,\"gatewayCount\":99,\"rssi\":99,\"data\":\"" + str( radio_status_str) + "\"}" ancien = str(radio_status_str) return radio_status_msg_str else: radio_status_msg_str = "{\"devEUI\":\"f03d291000000046\",\"fPort\":99,\"gatewayCount\":99,\"rssi\":99,\"data\":\"" + ancien + "\"}" return radio_status_msg_str else: radio_status_msg_str = "{\"devEUI\":\"f03d291000000046\",\"fPort\":99,\"gatewayCount\":99,\"rssi\":99,\"data\":\"" + ancien + "\"}" return radio_status_msg_str
def __init__(self, args, kwargs): """ Initialize the socket connections """ # Call the constructor of the parent class DatastreamManager.__init__(self, args, kwargs) self._mav = mavlink.MAVLink(None) self._conn_manager = MavlinkConnManager(self._mav) self._boot_time = blenderapi.persistantstorage().time.time
def publishMQTT_gps_raw_int(client, fix_type, obs_time=0): global topicToPublishMQTT mav = mavlink.MAVLink(f, 24, 1) #gps_raw_int_encode(usec, fix_type, lat, lon, alt, eph, epv, v, hdg) m = mav.gps_raw_int_encode(obs_time, fix_type, 0, 0, 0, 0, 0, 0, 65535, 255) m.pack(mav) data = m.get_msgbuf() (result, mid) = client.publish(topicToPublishMQTT, encodeData(data))
def gen_heartbeat_msg_str(): # create a mavlink instance, which will do IO on file object 'f' mav = mavlink.MAVLink(f, 24, 1) m = mav.heartbeat_encode(6, 8, 220, 0, 1) m.pack(mav) # get the encoded message as a buffer b = m.get_msgbuf() heartbeat_str = base64.b64encode(b) heartbeat_msg_str = "{\"devEUI\":\"f03d291000000046\",\"fPort\":99,\"gatewayCount\":99,\"rssi\":99,\"data\":\"" + str( heartbeat_str) + "\"}" return heartbeat_msg_str
class fifo(object): def __init__(self): self.buf = [] def write(self, data): self.buf += data return len(data) def read(self): return self.buf.pop(0) # we will use a fifo as an encode/decode buffer f = fifo() # create a mavlink instance, which will do IO on file object 'f' mav = mavlink.MAVLink(f) def encodeBase64(data): return base64.b64encode(data) def encodeData(data): data64 = encodeBase64(data) return "{\"devEUI\":\"f03d291000000046\",\"fPort\":99,\"gatewayCount\":99,\"rssi\":99,\"data\":\"" + str( data64) + "\"}" def extract_observation_time(message): if (len(message) > 20): binString = bin(
#camera = gphoto2.Camera() #camera.init() logger.info("camera init success") except: logger.info("camera init failed") # if os.path.exists("mn") is True: # with open("mn") as f: # mission_num=f.read() logger.info("current mission num is " + str(mission_num)) HeartBeat['mission_id'] = mission_num resetNet() os.system("sudo route add default ppp0") # 创建连接 打开连接飞控的串口 the_connect = mavutil.mavlink_connection("/dev/feikong_uart", baud=57600) #the_connect = mavutil.mavlink_connection("/dev/ttyUSB5", baud=57600) aa = cm.MAVLink(the_connect) # 阿里云初始化 if len(sys.argv) > 1: flag_start = 1 else: flag_start = 0 # whichserver = sys.argv[1] #如果从start.py启动 whichserver = 'hejing' pd_key, pd_secret, dv_secret, dv_name = read_init(whichserver) lk = linkkit.LinkKit(host_name="cn-shanghai", product_key=pd_key, device_name=dv_name, device_secret=dv_secret, product_secret=pd_secret) if dv_secret == "": #如果为空,代表还没有动态注册