代码
tag_uart = "test5_uart"id = 1
len = 1024get_gga_time = 2000data_time = ""
data_longitude = ""
data_latitude = ""
data_GGA = ""
data_GGA_status = ""
GGA_list = {
}
GGA_list["time"] = data_time
GGA_list["x"] = data_longitude
GGA_list["y"] = data_latitude
GGA_list["status"]= data_GGA_statusfunction init_uart_air551()log.info(tag_uart,"init_uart_air551")uart.setup(1, 115200)uart_air551_NMEA_set()sys.wait(1000)timex = sys.timerLoopStart(uart_air551_receive,get_gga_time)log.info(tag_uart,"time:",timex)init_air551G_cont()
endfunction uart_air551_send()uart.write(id, "test")
end
function uart_air551_NMEA_set()log.info("uart_air551_NMEA_set")uart.write(id, "$PGKC242,0,0,0,1*2A\r\n")
end
function uart_air551_receive()log.info("uart_air551_receive start---------------")local s = ""s = uart.read(id, len)if #s > 0 then log.info("get air551","uart", "receive", id, #s)enddata_GGA = get_gga(s)log.info("data_GGA",data_GGA)get_gga_longitude_latitude(data_GGA)log.info("uart_air551_receive end---------------")
end
function test_string_get()string_temp = "xxxxx$GNGGA,000004.811,XXX,N,XXX,E,0,0,,143.01,M,6.99,M,,*6D\r$GNGGA,000003.811,*6A"temp_start = string.find(string_temp,'$GNGGA',1)temp_end = string.find(string_temp,'\r',1)temp_gga = string.sub(string_temp,temp_start,temp_end-1)log.info("temp_x:",temp_start,temp_end,temp_gga)
end
function get_gga(value)temp_start = string.find(value,'GGA',1)-3temp_end = string.find(value,'\r',1)temp_gga = string.sub(value,temp_start,temp_end-1)return temp_gga
endfunction get_gga_longitude_latitude(value_gga)if value_gga == "" then return -1endL2_temp = string.sub(value_gga,8) data_time_h = string.sub(L2_temp,1,2)data_time_m = string.sub(L2_temp,3,4)data_time_s = string.sub(L2_temp,4,5)data_time_h = math.floor(data_time_h +8)if data_time_h >= 24 thendata_time_h = data_time_h -24 endif data_time_h <10 thendata_time_h = '0'..data_time_henddata_time = data_time_h..":"..data_time_m..":"..data_time_sL2_temp_x_start = string.find(L2_temp,',',1)+1L2_temp_x_end = string.find(L2_temp,',N',1)-1data_longitude = string.sub(L2_temp,L2_temp_x_start,L2_temp_x_end)L2_temp_y_start = L2_temp_x_end+4L2_temp_y_end = string.find(L2_temp,',E',1)-1data_latitude = string.sub(L2_temp,L2_temp_y_start,L2_temp_y_end)L2_temp_status_start = L2_temp_y_end + 4L2_temp_status_end = L2_temp_status_start data_GGA_status = string.sub(L2_temp,L2_temp_status_start,L2_temp_status_end)if data_GGA_status == "0" thenlog.info("定位指示为0,未定位")elseif data_GGA_status == "1" thenlog.info("定位指示为1,SPS 模式,定位有效")elseif data_GGA_status == "2" thenlog.info("定位指示为2,差分,SPS 模式,定位有效")endGGA_list["time"] = data_timeGGA_list["x"] = data_longitudeGGA_list["y"] = data_latitudeGGA_list["status"]= data_GGA_statusset_air551G_cont()return temp_gga
endfunction init_air551G_cont()air551G_cont = lvgl.cont_create(lvgl.scr_act(), nil)lvgl.obj_set_size(air551G_cont,128,160)lvgl.obj_set_auto_realign(air551G_cont, true) lvgl.obj_align_origo(air551G_cont, nil, lvgl.ALIGN_CENTER, 0, 0)lvgl.cont_set_fit(air551G_cont, lvgl.FIT_NONE) lvgl.cont_set_layout(air551G_cont, lvgl.LAYOUT_COLUMN_LEFT) log.info("scr_load",lvgl.scr_load(air551G_cont)) GGA_label = lvgl.label_create(air551G_cont, nil)lvgl.label_set_text(GGA_label, "GGA_data")lvgl.obj_set_pos(GGA_label, 2, 5)
endfunction set_air551G_cont()string_GGA = "GGA_data"..'\r'.."time: "..GGA_list["time"]..'\r'.."x: "..GGA_list["x"]..'\r'.."y: "..GGA_list["y"]..'\r'.."status: "..GGA_list["status"]log.info("string_GGA",string_GGA)if string_GGA == "" thenreturn -1endlvgl.label_set_text(GGA_label, string_GGA)end
结果