From: snickersun Date: Sat, 27 Jun 2026 03:32:50 +0000 (+0800) Subject: 优化ws 接收代码,采用c代替python接收。 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ae1f438481df8119ee27efee4497b2d36460c5fc;p=mirrors%2FASR1603_G5.git 优化ws 接收代码,采用c代替python接收。 --- diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/microPython.mk b/2.sdk/project/7PIN_1_5/sdk/services/microPython/microPython.mk new file mode 100644 index 00000000..7fdb7168 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/microPython.mk @@ -0,0 +1,877 @@ + +NAME := MICROPYTHON + +include config/$(KCONFIG_CONFIG) + +PY_SRCS = \ + py/argcheck.c \ + py/asmarm.c \ + py/asmbase.c \ + py/asmthumb.c \ + py/asmx64.c \ + py/asmx86.c \ + py/asmxtensa.c \ + py/bc.c \ + py/binary.c \ + py/builtinevex.c \ + py/builtinhelp.c \ + py/builtinimport.c \ + py/compile.c \ + py/emitbc.c \ + py/emitcommon.c \ + py/emitglue.c \ + py/emitinlinethumb.c \ + py/emitinlinextensa.c \ + py/emitnarm.c \ + py/emitnthumb.c \ + py/emitnx64.c \ + py/emitnx86.c \ + py/emitnxtensa.c \ + py/emitnxtensawin.c \ + py/formatfloat.c \ + py/frozenmod.c \ + py/gc.c \ + py/lexer.c \ + py/malloc.c \ + py/map.c \ + py/modarray.c \ + py/modbuiltins.c \ + py/modcmath.c \ + py/modcollections.c \ + py/modgc.c \ + py/modio.c \ + py/modmath.c \ + py/modmicropython.c \ + py/modstruct.c \ + py/modsys.c \ + py/modthread.c \ + py/moduerrno.c \ + py/mpprint.c \ + py/mpstate.c \ + py/mpz.c \ + py/nativeglue.c \ + py/nlr.c \ + py/nlrpowerpc.c \ + py/nlrsetjmp.c \ + py/nlrthumb.c \ + py/nlrx64.c \ + py/nlrx86.c \ + py/nlrxtensa.c \ + py/obj.c \ + py/objarray.c \ + py/objattrtuple.c \ + py/objbool.c \ + py/objboundmeth.c \ + py/objcell.c \ + py/objclosure.c \ + py/objcomplex.c \ + py/objdeque.c \ + py/objdict.c \ + py/objenumerate.c \ + py/objexcept.c \ + py/objfilter.c \ + py/objfloat.c \ + py/objfun.c \ + py/objgenerator.c \ + py/objgetitemiter.c \ + py/objint.c \ + py/objint_longlong.c \ + py/objint_mpz.c \ + py/objlist.c \ + py/objmap.c \ + py/objmodule.c \ + py/objnamedtuple.c \ + py/objnone.c \ + py/objobject.c \ + py/objpolyiter.c \ + py/objproperty.c \ + py/objrange.c \ + py/objreversed.c \ + py/objset.c \ + py/objsingleton.c \ + py/objslice.c \ + py/objstr.c \ + py/objstringio.c \ + py/objstrunicode.c \ + py/objtuple.c \ + py/objtype.c \ + py/objzip.c \ + py/opmethods.c \ + py/pairheap.c \ + py/parse.c \ + py/parsenum.c \ + py/parsenumbase.c \ + py/persistentcode.c \ + py/profile.c \ + py/pystack.c \ + py/qstr.c \ + py/reader.c \ + py/repl.c \ + py/ringbuf.c \ + py/runtime.c \ + py/runtime_utils.c \ + py/scheduler.c \ + py/scope.c \ + py/sequence.c \ + py/showbc.c \ + py/smallint.c \ + py/stackctrl.c \ + py/stream.c \ + py/unicode.c \ + py/vm.c \ + py/vstr.c \ + py/warning.c + + +EXTMOD_SRCS = \ + extmod/mb_ussl_error.c \ + extmod/modaes.c \ + extmod/modhash.c \ + extmod/moduasyncio.c \ + extmod/moduwebsocket.c \ + extmod/modubinascii.c \ + extmod/moducryptolib.c \ + extmod/moductypes.c \ + extmod/moduhashlib.c \ + extmod/modujson.c \ + extmod/modurandom.c \ + extmod/modure.c \ + extmod/moduselect.c \ + extmod/modussl_mbedtls.c \ + extmod/moduzlib.c \ + extmod/utime_mphal.c \ + extmod/vfs.c \ + extmod/vfs_blockdev.c \ + extmod/vfs_efs.c \ + extmod/vfs_efs_file.c \ + extmod/vfs_fat.c \ + extmod/vfs_fat_file.c \ + extmod/vfs_lfs.c \ + extmod/vfs_reader.c \ + extmod/vfs_temp.c \ + extmod/vfs_temp_file.c \ + extmod/vfs_fat_sdio.c \ + extmod/vfs_fat_sdio_file.c \ + lib/littlefs/lfs1.c \ + lib/littlefs/lfs1_util.c \ + lib/littlefs/lfs2.c \ + lib/littlefs/lfs2_util.c \ + lib/mp-readline/readline.c \ + lib/netutils/netutils.c \ + lib/timeutils/timeutils.c \ + lib/utils/interrupt_char.c \ + lib/utils/pyexec.c \ + lib/utils/stdout_helpers.c \ + lib/utils/sys_stdio_mphal.c + + +QPY_SRCS = \ + ports/quectel/core/build/_frozen_mpy.c \ + ports/quectel/core/source/random.c \ + ports/quectel/core/source/audio_audio.c \ + ports/quectel/core/source/audio_handle.c \ + ports/quectel/core/source/audio_queue.c \ + ports/quectel/core/source/audio_record.c \ + ports/quectel/core/source/audio_tts.c \ + ports/quectel/core/source/audiocodec_rt5616.c \ + ports/quectel/core/source/callbackdeal.c \ + ports/quectel/core/source/camera_capture.c \ + ports/quectel/core/source/camera_preview.c \ + ports/quectel/core/source/camera_scandecode.c \ + ports/quectel/core/source/devreport.c \ + ports/quectel/core/source/gccollect.c \ + ports/quectel/core/source/help.c \ + ports/quectel/core/source/linklist.c \ + ports/quectel/core/source/machine_extint.c \ + ports/quectel/core/source/machine_hw_spi.c \ + ports/quectel/core/source/machine_iic.c \ + ports/quectel/core/source/machine_iic_simulation.c \ + ports/quectel/core/source/machine_keypad.c \ + ports/quectel/core/source/machine_lcd.c \ + ports/quectel/core/source/machine_nandflash.c \ + ports/quectel/core/source/machine_pin.c \ + ports/quectel/core/source/machine_rtc.c \ + ports/quectel/core/source/machine_timer.c \ + ports/quectel/core/source/machine_uart.c \ + ports/quectel/core/source/machine_wdt.c \ + ports/quectel/core/source/misc_adc.c \ + ports/quectel/core/source/misc_power.c \ + ports/quectel/core/source/misc_powerkey.c \ + ports/quectel/core/source/misc_pwm.c \ + ports/quectel/core/source/misc_temperature.c \ + ports/quectel/core/source/misc_usb.c \ + ports/quectel/core/source/misc_usbnet.c \ + ports/quectel/core/source/modatcmd.c \ + ports/quectel/core/source/modaudio.c \ + ports/quectel/core/source/modaudiocodec.c \ + ports/quectel/core/source/modble.c \ + ports/quectel/core/source/modbt.c \ + ports/quectel/core/source/modcamera.c \ + ports/quectel/core/source/modcelllocator.c \ + ports/quectel/core/source/modcelllocator_qpy.c \ + ports/quectel/core/source/locator.c \ + ports/quectel/core/source/modcsd.c \ + ports/quectel/core/source/moddatacall.c \ + ports/quectel/core/source/moddev.c \ + ports/quectel/core/source/modethernet.c \ + ports/quectel/core/source/modethernet_dm9051.c \ + ports/quectel/core/source/modethernet_w5500.c \ + ports/quectel/core/source/modethernet_ch395.c \ + ports/quectel/core/source/modexample.c \ + ports/quectel/core/source/modfota.c \ + ports/quectel/core/source/modgnss.c \ + ports/quectel/core/source/modlpm.c \ + ports/quectel/core/source/modlvgl.c \ + ports/quectel/core/source/modlvgl_other_hander.c \ + ports/quectel/core/source/modlwm2m.c \ + ports/quectel/core/source/modmachine.c \ + ports/quectel/core/source/modmisc.c \ + ports/quectel/core/source/modnb.c \ + ports/quectel/core/source/modnet.c \ + ports/quectel/core/source/modostimer.c \ + ports/quectel/core/source/modpoc.c \ + ports/quectel/core/source/modqrcode.c \ + ports/quectel/core/source/modrtmp.c \ + ports/quectel/core/source/modsecuredata.c \ + ports/quectel/core/source/modsensor.c \ + ports/quectel/core/source/modsha1.c \ + ports/quectel/core/source/modsim.c \ + ports/quectel/core/source/modslipif.c \ + ports/quectel/core/source/modsms.c \ + ports/quectel/core/source/modussd.c \ + ports/quectel/core/source/modsocket.c \ + ports/quectel/core/source/modwifi.c \ + ports/quectel/core/source/modtp.c \ + ports/quectel/core/source/moduos.c \ + ports/quectel/core/source/modutils.c \ + ports/quectel/core/source/modutime.c \ + ports/quectel/core/source/modvoicecall.c \ + ports/quectel/core/source/modwifilocator.c \ + ports/quectel/core/source/modwifiscan.c \ + ports/quectel/core/source/mphalport.c \ + ports/quectel/core/source/mpthreadport.c \ + ports/quectel/core/source/nb_aep.c \ + ports/quectel/core/source/nb_oc.c \ + ports/quectel/core/source/nb_onenet.c \ + ports/quectel/core/source/quecpython.c \ + ports/quectel/core/source/sensor_sn95500.c \ + ports/quectel/core/source/sensor_icckey.c \ + ports/quectel/core/source/sensor_gnss.c \ + ports/quectel/core/source/sensor_handmic_key.c \ + ports/quectel/core/source/tp_gt9xx.c \ + ports/quectel/core/source/tp_xpt2046.c \ + ports/quectel/core/source/tp_cst816.c \ + ports/quectel/core/source/tp_ft6x36.c \ + ports/quectel/core/source/tp_st1615.c \ + ports/quectel/core/source/modGsensor.c \ + ports/quectel/core/source/modGsensor_SC7A20.c \ + ports/quectel/core/source/modHsensor.c \ + ports/quectel/core/source/modHsensor_GH3018.c \ + ports/quectel/core/source/modHsensor_HX3918.c \ + ports/quectel/core/source/modgpio_encoder.c \ + ports/quectel/core/source/modVideoCall.c \ + ports/quectel/core/source/modVideoCall_juphoon.c \ + ports/quectel/core/source/modrsa.c \ + ports/quectel/core/source/modsftp.c \ + ports/quectel/core/source/utils_crc32.c \ + ports/quectel/core/source/modwebserver.c \ + ports/quectel/core/source/http_parser.c \ + ports/quectel/core/source/modethernet_yt8512h.c \ + ports/quectel/core/source/sim_esim.c \ + ports/quectel/core/source/modG711.c \ + ports/quectel/core/source/modG729.c \ + ports/quectel/core/source/modG722.c \ + ports/quectel/core/source/modcan_mcp2515.c \ + ports/quectel/core/source/modextuart_wk2114.c \ + ports/quectel/core/source/modgpio_encoder.c \ + ports/quectel/core/source/modextgpio_aw9523.c \ + ports/quectel/core/source/modalipay.c \ + ports/quectel/core/source/machine_key.c \ + ports/quectel/core/source/lpm_wakeup.c \ + ports/quectel/core/source/modnetwork.c \ + ports/quectel/core/source/modwlan_ASR5803.c \ + ports/quectel/core/source/machine_soft_spi.c \ + ports/quectel/core/source/modwlan.c\ + ports/quectel/core/source/code128_p.c \ + ports/quectel/core/source/modmask.c \ + ports/quectel/core/source/modcws_frame.c \ + ports/quectel/core/source/modVad.c \ + ports/quectel/core/source/machine_one_wire.c\ + ports/quectel/core/source/modalipay_collection.c \ + ports/quectel/core/source/modsif.c\ + ports/quectel/core/source/jrtc.c \ + ports/quectel/core/source/modnfc.c \ + ports/quectel/core/source/nfc_sl6320.c \ + ports/quectel/core/source/modstk.c \ + ports/quectel/core/source/modalipay_se.c \ + ports/quectel/core/source/modvoip.c \ + ports/quectel/core/source/modipsec.c \ + ports/quectel/core/source/modecdsa.c \ + ports/quectel/core/source/modecdh.c \ + ports/quectel/core/source/moddlms.c \ + ports/quectel/core/source/modai_rtc.c + +ifeq ($(CONFIG_QUECTHING), y) +ifeq ($(strip $(PLAT)),RDA) +QPY_SRCS += ../../components/quecsdk/cloud/python/modquecIot-BC25old.c +else +QPY_SRCS += ../../components/quecsdk/cloud/python/modquecIot.c +endif +endif + + +$(NAME)_ARCHIVES = \ + ports/quectel/core/source/libimslvad.a +-include services/microPython/microPython_imsl_vad.mk +# Opus:须在 $(NAME)_SRCS)+= 之前;路径相对 Helios 根(勿用 lastword,config.mk include 后会指错目录) +-include services/microPython/microPython_opus.mk + +ifeq ($(CONFIG_USQLITE), y) +EXTMOD_SRCS += lib/usqlite/usqlite_connection.c \ + lib/usqlite/usqlite_cursor.c \ + lib/usqlite/usqlite_row.c \ + lib/usqlite/usqlite_file.c \ + lib/usqlite/usqlite_mem.c \ + lib/usqlite/usqlite_vfs.c \ + lib/usqlite/usqlite_utils.c \ + lib/usqlite/usqlite.c \ + lib/usqlite/usqlite_module.c +$(NAME)_INCS += lib/usqlite +endif + + +ifeq ($(CONFIG_LVGL), y) + +LVGL_SRCS_1 += \ +lib/lvgl/src/extra/layouts/flex/lv_flex.c \ +lib/lvgl/src/extra/layouts/grid/lv_grid.c \ +lib/lvgl/src/extra/libs/bmp/lv_bmp.c \ +lib/lvgl/src/extra/libs/ffmpeg/lv_ffmpeg.c \ +lib/lvgl/src/extra/libs/freetype/lv_freetype.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_posix.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_helios.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_stdio.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_win32.c \ +lib/lvgl/src/extra/libs/gif/gifdec.c \ +lib/lvgl/src/extra/libs/gif/lv_gif.c \ +lib/lvgl/src/extra/libs/png/lodepng.c \ +lib/lvgl/src/extra/libs/png/lv_png.c \ +lib/lvgl/src/extra/libs/qrcode/lv_qrcode.c \ +lib/lvgl/src/extra/libs/qrcode/qrcodegen.c \ +lib/lvgl/src/extra/libs/rlottie/lv_rlottie.c \ +lib/lvgl/src/extra/libs/sjpg/lv_sjpg.c \ +lib/lvgl/src/extra/libs/sjpg/tjpgd.c \ +lib/lvgl/src/extra/lv_extra.c \ +lib/lvgl/src/extra/others/gridnav/lv_gridnav.c \ +lib/lvgl/src/extra/others/monkey/lv_monkey.c \ +lib/lvgl/src/extra/others/snapshot/lv_snapshot.c \ +lib/lvgl/src/extra/themes/basic/lv_theme_basic.c \ +lib/lvgl/src/extra/themes/default/lv_theme_default.c \ +lib/lvgl/src/extra/themes/mono/lv_theme_mono.c \ +lib/lvgl/src/extra/widgets/animimg/lv_animimg.c \ +lib/lvgl/src/extra/widgets/calendar/lv_calendar.c \ +lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_arrow.c \ +lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_dropdown.c \ +lib/lvgl/src/extra/widgets/chart/lv_chart.c \ +lib/lvgl/src/extra/widgets/colorwheel/lv_colorwheel.c \ +lib/lvgl/src/extra/widgets/imgbtn/lv_imgbtn.c \ +lib/lvgl/src/extra/widgets/keyboard/lv_keyboard.c \ +lib/lvgl/src/extra/widgets/led/lv_led.c \ +lib/lvgl/src/extra/widgets/list/lv_list.c \ +lib/lvgl/src/extra/widgets/menu/lv_menu.c \ +lib/lvgl/src/extra/widgets/meter/lv_meter.c \ +lib/lvgl/src/extra/widgets/msgbox/lv_msgbox.c \ +lib/lvgl/src/extra/widgets/span/lv_span.c \ +lib/lvgl/src/extra/widgets/spinbox/lv_spinbox.c \ +lib/lvgl/src/extra/widgets/spinner/lv_spinner.c \ +lib/lvgl/src/extra/widgets/tabview/lv_tabview.c \ +lib/lvgl/src/extra/widgets/tileview/lv_tileview.c \ +lib/lvgl/src/extra/widgets/win/lv_win.c \ +lib/lvgl/src/extra/others/ime/lv_ime_pinyin.c \ +lib/lvgl/src/core/lv_disp.c \ +lib/lvgl/src/core/lv_group.c \ +lib/lvgl/src/core/lv_indev.c \ +lib/lvgl/src/core/lv_indev_scroll.c \ +lib/lvgl/src/core/lv_obj.c \ +lib/lvgl/src/core/lv_obj_class.c \ +lib/lvgl/src/core/lv_obj_draw.c \ +lib/lvgl/src/core/lv_obj_pos.c \ +lib/lvgl/src/core/lv_obj_scroll.c \ +lib/lvgl/src/core/lv_obj_style.c \ +lib/lvgl/src/core/lv_obj_style_gen.c \ +lib/lvgl/src/core/lv_obj_tree.c \ +lib/lvgl/src/core/lv_event.c \ +lib/lvgl/src/core/lv_refr.c \ +lib/lvgl/src/core/lv_theme.c \ +lib/lvgl/src/draw/lv_draw_arc.c \ +lib/lvgl/src/draw/lv_draw.c \ +lib/lvgl/src/draw/lv_draw_img.c \ +lib/lvgl/src/draw/lv_draw_label.c \ +lib/lvgl/src/draw/lv_draw_layer.c \ +lib/lvgl/src/draw/lv_draw_line.c \ +lib/lvgl/src/draw/lv_draw_mask.c \ +lib/lvgl/src/draw/lv_draw_rect.c \ +lib/lvgl/src/draw/lv_draw_transform.c \ +lib/lvgl/src/draw/lv_draw_triangle.c \ +lib/lvgl/src/draw/lv_img_buf.c \ +lib/lvgl/src/draw/lv_img_cache.c \ +lib/lvgl/src/draw/lv_img_decoder.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_arc.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_bg.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_composite.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_img.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_label.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_line.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_mask.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_polygon.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_rect.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_stack_blur.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_texture_cache.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_utils.c \ +lib/lvgl/src/draw/sw/lv_draw_sw.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_arc.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_blend.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_img.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_letter.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_line.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_rect.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_polygon.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_gradient.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_dither.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_transform.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_layer.c \ +lib/lvgl/src/font/lv_font.c \ +lib/lvgl/src/font/lv_font_fmt_txt.c \ +lib/lvgl/src/font/lv_font_loader.c \ +lib/lvgl/src/font/lv_font_dejavu_16_persian_hebrew.c \ +lib/lvgl/src/font/lv_font_montserrat_8.c \ +lib/lvgl/src/font/lv_font_montserrat_10.c \ +lib/lvgl/src/font/lv_font_montserrat_12.c \ +lib/lvgl/src/font/lv_font_montserrat_12_subpx.c \ +lib/lvgl/src/font/lv_font_montserrat_14.c \ +lib/lvgl/src/font/lv_font_montserrat_16.c \ +lib/lvgl/src/font/lv_font_montserrat_18.c \ +lib/lvgl/src/font/lv_font_montserrat_20.c \ +lib/lvgl/src/font/lv_font_montserrat_22.c \ +lib/lvgl/src/font/lv_font_montserrat_24.c \ +lib/lvgl/src/font/lv_font_montserrat_26.c \ +lib/lvgl/src/font/lv_font_montserrat_28.c \ +lib/lvgl/src/font/lv_font_montserrat_28_compressed.c \ +lib/lvgl/src/font/lv_font_montserrat_30.c \ +lib/lvgl/src/font/lv_font_montserrat_32.c \ +lib/lvgl/src/font/lv_font_montserrat_34.c \ +lib/lvgl/src/font/lv_font_montserrat_36.c \ +lib/lvgl/src/font/lv_font_montserrat_38.c \ +lib/lvgl/src/font/lv_font_montserrat_40.c \ +lib/lvgl/src/font/lv_font_montserrat_42.c \ +lib/lvgl/src/font/lv_font_montserrat_44.c \ +lib/lvgl/src/font/lv_font_montserrat_46.c \ +lib/lvgl/src/font/lv_font_montserrat_48.c \ +lib/lvgl/src/font/lv_font_simsun_16_cjk.c \ +lib/lvgl/src/font/lv_font_unscii_8.c \ +lib/lvgl/src/font/lv_font_unscii_16.c \ +lib/lvgl/src/font/lv_font_siyun_18.c \ +lib/lvgl/src/font/lv_font_arial_54.c \ +lib/lvgl/src/font/lv_font_siyuan_32.c \ +lib/lvgl/src/font/lv_font_sdSiyuan16.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_8.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_10.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_12.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_14.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_16.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_18.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_20.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_22.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_24.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_26.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_28.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_30.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_32.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_34.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_36.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_38.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_40.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_42.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_44.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_46.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_48.c \ +lib/lvgl/src/font/lv_11_siyuan_light.c \ + +LVGL_SRCS_2 = \ +lib/lvgl/src/font/lv_14_ali.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Bold_60.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Bold_100.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Regular_28.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Regular_48.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Regular_20.c \ +lib/lvgl/src/font/lv_font_siyuan_Bold_26.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_12.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_14.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_16.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_18.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_20.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_22.c \ +lib/lvgl/src/font/lv_bold_18.c \ +lib/lvgl/src/font/lv_bold_34.c \ +lib/lvgl/src/font/lv_bold_48.c \ +lib/lvgl/src/font/lv_regular_12.c \ +lib/lvgl/src/font/lv_regular_14.c \ +lib/lvgl/src/font/lv_regular_18.c \ +lib/lvgl/src/font/lv_regular_20.c \ +lib/lvgl/src/font/lv_regular_22.c \ +lib/lvgl/src/font/lv_regular_24.c \ +lib/lvgl/src/font/lv_regular_29.c \ +lib/lvgl/src/font/lv_font_tianbo_10.c \ +lib/lvgl/src/font/lv_font_tianbo_12.c \ +lib/lvgl/src/font/lv_font_tianbo_14.c \ +lib/lvgl/src/font/lv_font_tianbo_16.c \ +lib/lvgl/src/font/lv_font_12_qs.c \ +lib/lvgl/src/font/lv_font_12.c \ +lib/lvgl/src/font/lv_font_21_light.c \ +lib/lvgl/src/font/lv_font_30_light.c \ +lib/lvgl/src/font/lv_font_14_simsum.c \ +lib/lvgl/src/font/lv_font_16_simsum.c \ +lib/lvgl/src/font/lv_font_18_simsum.c \ +lib/lvgl/src/font/lv_font_70_bold.c \ +lib/lvgl/src/font/lv_font_28_dial.c \ +lib/lvgl/src/font/lv_font_60_main_menu.c \ +lib/lvgl/src/font/lv_font_50_main_menu_e.c \ +lib/lvgl/src/font/K01_font_16_ALL.c \ +lib/lvgl/src/font/K01_font_30_DIAL.c \ +lib/lvgl/src/hal/lv_hal_disp.c \ +lib/lvgl/src/hal/lv_hal_indev.c \ +lib/lvgl/src/hal/lv_hal_tick.c \ +lib/lvgl/src/misc/lv_anim.c \ +lib/lvgl/src/misc/lv_anim_timeline.c \ +lib/lvgl/src/misc/lv_area.c \ +lib/lvgl/src/misc/lv_async.c \ +lib/lvgl/src/misc/lv_bidi.c \ +lib/lvgl/src/misc/lv_color.c \ +lib/lvgl/src/misc/lv_fs.c \ +lib/lvgl/src/misc/lv_gc.c \ +lib/lvgl/src/misc/lv_ll.c \ +lib/lvgl/src/misc/lv_log.c \ +lib/lvgl/src/misc/lv_lru.c \ +lib/lvgl/src/misc/lv_math.c \ +lib/lvgl/src/misc/lv_mem.c \ +lib/lvgl/src/misc/lv_printf.c \ +lib/lvgl/src/misc/lv_style.c \ +lib/lvgl/src/misc/lv_style_gen.c \ +lib/lvgl/src/misc/lv_timer.c \ +lib/lvgl/src/misc/lv_tlsf.c \ +lib/lvgl/src/misc/lv_txt.c \ +lib/lvgl/src/misc/lv_txt_ap.c \ +lib/lvgl/src/misc/lv_utils.c \ +lib/lvgl/src/widgets/lv_arc.c \ +lib/lvgl/src/widgets/lv_bar.c \ +lib/lvgl/src/widgets/lv_btn.c \ +lib/lvgl/src/widgets/lv_btnmatrix.c \ +lib/lvgl/src/widgets/lv_canvas.c \ +lib/lvgl/src/widgets/lv_checkbox.c \ +lib/lvgl/src/widgets/lv_dropdown.c \ +lib/lvgl/src/widgets/lv_img.c \ +lib/lvgl/src/widgets/lv_label.c \ +lib/lvgl/src/widgets/lv_line.c \ +lib/lvgl/src/widgets/lv_roller.c \ +lib/lvgl/src/widgets/lv_slider.c \ +lib/lvgl/src/widgets/lv_switch.c \ +lib/lvgl/src/widgets/lv_table.c \ +lib/lvgl/src/widgets/lv_textarea.c \ +lib/lvgl/freetype-2.11.1/src/autofit/autofit.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbase.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbbox.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbdf.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbitmap.c \ +lib/lvgl/freetype-2.11.1/src/base/ftcid.c \ +lib/lvgl/freetype-2.11.1/src/base/ftfstype.c \ +lib/lvgl/freetype-2.11.1/src/base/ftgasp.c \ +lib/lvgl/freetype-2.11.1/src/base/ftglyph.c \ +lib/lvgl/freetype-2.11.1/src/base/ftgxval.c \ +lib/lvgl/freetype-2.11.1/src/base/ftinit.c \ +lib/lvgl/freetype-2.11.1/src/base/ftmm.c \ +lib/lvgl/freetype-2.11.1/src/base/ftotval.c \ +lib/lvgl/freetype-2.11.1/src/base/ftpatent.c \ +lib/lvgl/freetype-2.11.1/src/base/ftpfr.c \ +lib/lvgl/freetype-2.11.1/src/base/ftstroke.c \ +lib/lvgl/freetype-2.11.1/src/base/ftsynth.c \ +lib/lvgl/freetype-2.11.1/src/base/fttype1.c \ +lib/lvgl/freetype-2.11.1/src/base/ftwinfnt.c \ +lib/lvgl/freetype-2.11.1/src/bdf/bdf.c \ +lib/lvgl/freetype-2.11.1/src/bzip2/ftbzip2.c \ +lib/lvgl/freetype-2.11.1/src/cache/ftcache.c \ +lib/lvgl/freetype-2.11.1/src/cff/cff.c \ +lib/lvgl/freetype-2.11.1/src/cid/type1cid.c \ +lib/lvgl/freetype-2.11.1/src/gzip/ftgzip.c \ +lib/lvgl/freetype-2.11.1/src/lzw/ftlzw.c \ +lib/lvgl/freetype-2.11.1/src/pcf/pcf.c \ +lib/lvgl/freetype-2.11.1/src/pfr/pfr.c \ +lib/lvgl/freetype-2.11.1/src/psaux/psaux.c \ +lib/lvgl/freetype-2.11.1/src/pshinter/pshinter.c \ +lib/lvgl/freetype-2.11.1/src/psnames/psnames.c \ +lib/lvgl/freetype-2.11.1/src/raster/raster.c \ +lib/lvgl/freetype-2.11.1/src/sdf/sdf.c \ +lib/lvgl/freetype-2.11.1/src/sfnt/sfnt.c \ +lib/lvgl/freetype-2.11.1/src/smooth/smooth.c \ +lib/lvgl/freetype-2.11.1/src/truetype/truetype.c \ +lib/lvgl/freetype-2.11.1/src/type1/type1.c \ +lib/lvgl/freetype-2.11.1/src/type42/type42.c \ +lib/lvgl/freetype-2.11.1/src/winfonts/winfnt.c \ +lib/lvgl/freetype-2.11.1/src/base/ftsystem.c \ +lib/lvgl/freetype-2.11.1/src/base/ftdebug.c +endif + + + +$(NAME)_SRCS += $(PY_SRCS) $(EXTMOD_SRCS) $(QPY_SRCS) +ifeq ($(CONFIG_LVGL), y) +$(NAME)_SRCS_2 = $(LVGL_SRCS_1) +$(NAME)_SRCS_3 = $(LVGL_SRCS_2) +endif + +$(NAME)_INCS = \ + . \ + extmod \ + genhdr \ + lib \ + lib/littlefs \ + lib/mp-readline \ + lib/netutils \ + lib/timeutils \ + lib/utils \ + ports/quectel/core/source \ + py + +ifeq ($(CONFIG_LVGL), y) +$(NAME)_INCS += \ + lib/lvgl \ + lib/lvgl \ + lib/lvgl/src \ + lib/lvgl/src/core \ + lib/lvgl/src/draw \ + lib/lvgl/src/extra \ + lib/lvgl/src/font \ + lib/lvgl/src/gpu \ + lib/lvgl/src/hal \ + lib/lvgl/src/misc \ + lib/lvgl/src/widgts \ + lib/lvgl/freetype-2.11.1/include \ + lib/lvgl/freetype-2.11.1/include/dlg \ + lib/lvgl/freetype-2.11.1/include/freetype \ + lib/lvgl/freetype-2.11.1/include/freetype/config \ + lib/lvgl/freetype-2.11.1/include/freetype/internal \ + lib/lvgl/freetype-2.11.1/include/freetype/internal/services \ + lib/lvgl/freetype-2.11.1/src/base \ + lib/lvgl/freetype-2.11.1/src/autofit \ + lib/lvgl/freetype-2.11.1/src/bdf \ + lib/lvgl/freetype-2.11.1/src/bzip2 \ + lib/lvgl/freetype-2.11.1/src/cache \ + lib/lvgl/freetype-2.11.1/src/cff \ + lib/lvgl/freetype-2.11.1/src/cid \ + lib/lvgl/freetype-2.11.1/src/gzip \ + lib/lvgl/freetype-2.11.1/src/lzw \ + lib/lvgl/freetype-2.11.1/src/pcf \ + lib/lvgl/freetype-2.11.1/src/pfr \ + lib/lvgl/freetype-2.11.1/src/psaux \ + lib/lvgl/freetype-2.11.1/src/pshinter \ + lib/lvgl/freetype-2.11.1/src/psnames \ + lib/lvgl/freetype-2.11.1/src/raster \ + lib/lvgl/freetype-2.11.1/src/sdf \ + lib/lvgl/freetype-2.11.1/src/sfnt \ + lib/lvgl/freetype-2.11.1/src/smooth \ + lib/lvgl/freetype-2.11.1/src/truetype \ + lib/lvgl/freetype-2.11.1/src/type1 \ + lib/lvgl/freetype-2.11.1/src/type42 \ + lib/lvgl/freetype-2.11.1/src/winfonts +endif + +EMPTY= +SPACE=$(EMPTY) $(EMPTY) +COMMA=$(EMPTY),$(EMPTY) +BUILD_TIMESTAMP=\\\"$(subst $(SPACE),_,$(subst $(COMMA),,$(shell echo $$(env LANG=en_US.UTF-8 date))))\\\" +$(NAME)_DEFINE = \ + MP_ENDIANNESS_LITTLE \ + MICROPY_BUILD_DATE=${BUILD_TIMESTAMP} + + + +ifneq ($(strip $(PLAT)),Qualcomm) +$(NAME)_CFLAGS = \ + -Wno-error=unused-parameter \ + -Wno-error=format-truncation \ + -Wno-error=unused-variable \ + -Wno-error=unused-function \ + -Wno-error=format= +else +$(NAME)_CFLAGS = -Wno-error=tautological-constant-out-of-range-compare \ + -Wno-error=missing-field-initializers \ + -Wno-error=unused-parameter \ + -Wno-error=unused-variable \ + -Wno-error=unused-function \ + -Wno-error=missing-braces \ + -Wno-error=sometimes-uninitialized +endif + + +ifeq ($(CONFIG_LVGL), y) +$(NAME)_CFLAGS += \ + -Wno-error=incompatible-pointer-types \ + -Wno-error=sign-compare \ + -Wno-error=unused-but-set-variable \ + -Wno-error=switch-unreachable \ + -Wno-error=unused-function \ + -Wno-error=implicit-function-declaration \ + -Wno-error=missing-field-initializers \ + -Wno-error=unused-parameter \ + -Wno-error=unused-variable \ + -Wno-error=type-limits \ + -Wno-error=format= \ + -Wno-error=discarded-qualifiers \ + -Wno-error=maybe-uninitialized \ + -Wno-error=int-conversion +endif + +ifeq ($(CONFIG_SPINAND), y) +$(NAME)_CFLAGS += \ + -Wno-error=restrict \ + -Wno-error=format-overflow= +endif + +$(NAME)_COMPONENTS = peripheral + +$(NAME)_COMPONENTS += driver + +ifeq ($(CONFIG_DECODE_QUECTEL), y) +$(NAME)_COMPONENTS += components/decode/quectel +endif + +ifeq ($(CONFIG_DECODE_QINGYA), y) +ifneq ($(strip $(PLAT)),ASR) +ifneq ($(strip $(PLAT)),ASR_1606) +$(NAME)_COMPONENTS += components/decode/qingya +endif +endif +endif + +ifeq ($(CONFIG_JPEG), y) +$(NAME)_COMPONENTS += components/jpeg +endif + +$(NAME)_COMPONENTS += utilities + + +$(NAME)_COMPONENTS += components/audio + +ifneq (,$(filter y,$(CONFIG_SPINAND) $(CONFIG_SPI_SDCARD))) +$(NAME)_COMPONENTS += components/fs +endif + +ifeq ($(CONFIG_RTMP), y) +$(NAME)_COMPONENTS += components/rtmpdump +endif +ifeq ($(CONFIG_JRTC), y) +$(NAME)_COMPONENTS += components/jpeg +$(NAME)_COMPONENTS += components/jrtc +$(NAME)_INCS += ../../components/jrtc/inc + +endif + +ifeq ($(CONFIG_SENSOR_VC9202), y) +$(NAME)_COMPONENTS += components/sensor/VC9202 +$(NAME)_INCS += ../../components/sensor/VS9202/inc +$(NAME)_INCS += ../../components/sensor/VS9202/algo/inc +endif + +ifeq ($(CONFIG_POC), y) +$(NAME)_CFLAGS += \ + -Wno-error=incompatible-pointer-types \ + -Wno-error=ignored-qualifiers \ + -Wno-error=int-conversion \ + -Wno-error=implicit-function-declaration \ + -Wno-error=discarded-qualifiers \ + -Wno-error=unused-const-variable= + +$(NAME)_COMPONENTS += components/poc +endif + +ifeq ($(CONFIG_QRCODE), y) +$(NAME)_COMPONENTS += components/qrcode +endif + +ifeq ($(CONFIG_HX3918), y) +$(NAME)_COMPONENTS += components/HX3918 +endif +ifeq ($(CONFIG_GH301x), y) +$(NAME)_COMPONENTS += components/GH301X +endif +ifeq ($(CONFIG_SC7A20), y) +$(NAME)_COMPONENTS += components/SC7A20 +endif +ifeq ($(CONFIG_juphoon), y) +$(NAME)_COMPONENTS += components/juphoon +endif + +ifeq ($(CONFIG_LIBSSH2), y) +$(NAME)_INCS += ../../components/ssh2/include \ + ../../components/ssh2/src +$(NAME)_COMPONENTS += components/ssh2 +endif + +ifeq ($(CONFIG_QUECTHING), y) +$(NAME)_INCS += ../../components/quecsdk +$(NAME)_COMPONENTS += components/quecsdk +endif + +ifeq ($(CONFIG_GMSSL), y) +$(NAME)_COMPONENTS += components/GMSSL +endif + +ifeq ($(CONFIG_GB2312), y) +$(NAME)_COMPONENTS += components/decode/gb2312 +endif + +ifeq ($(CONFIG_ESIMSDK), y) +$(NAME)_COMPONENTS += components/esim +endif + +ifeq ($(CONFIG_NFC_SL6320), y) +$(NAME)_COMPONENTS += components/NFC/SL6320 +endif + +ifeq ($(CONFIG_VOIP), y) +$(NAME)_INCS += ../../components/voip/libexosip2/include \ + ../../components/voip/libosip2/include \ + ../../components/voip/rtp +$(NAME)_COMPONENTS += components/voip +endif + +ifeq ($(CONFIG_ETHERNET_W5500), y) +$(NAME)_COMPONENTS += components/ethernet +$(NAME)_INCS += ../../components/ethernet/wiznet +endif + +ifeq ($(CONFIG_SLIP), y) +$(NAME)_COMPONENTS += components/slip +$(NAME)_INCS += ../../components/slip +endif + +ifeq ($(CONFIG_DLMS), y) +$(NAME)_COMPONENTS += components/dlms +endif + +ifeq ($(CONFIG_MICROPYTHON_EXTENSION_PERF), y) +$(NAME)_COMPONENTS += components/micropython_extension +$(NAME)_INCS += ../../components/micropython_extension/perf +endif + +ifeq ($(CONFIG_MICROPYTHON_EXTENSION_SECURE_APP), y) +$(NAME)_COMPONENTS += components/micropython_extension +$(NAME)_INCS += ../../components/micropython_extension/secure_app +endif + +$(NAME)_CFLAGS += -Wno-error=implicit-fallthrough + +$(NAME)_PRIVATE_SCRIPT = private.mk + +$(NAME)_PRIVATE_SCRIPT_TARGETS = construct clean diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile index 26456dd5..8246a3e1 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile @@ -380,6 +380,7 @@ SRC_QSTR += \ source/modwlan.c\ source/modwlan.c \ source/modmask.c \ + source/modcws_frame.c \ source/modVad.c \ source/machine_one_wire.c diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py index 06c8e487..156ee434 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py @@ -26,7 +26,7 @@ PRODUCT_KEY = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX" # 32 字节,运行时转为 # ============================================================================= # --- 2.1 三色 LED(Pin 属性名字符串,vc_config 转为 Pin.GPIOxx)--- -LED_GPIO = ("GPIO36", "GPIO44", "GPIO43") # (R, G, B) +LED_GPIO = ("GPIO36", "GPIO21", "GPIO19") # (R, G, B) # 点亮电平:False=高电平亮;True=低电平亮;仅某路反相用 LED_ACTIVE_LOW_RGB LED_ACTIVE_LOW = False @@ -34,7 +34,7 @@ LED_ACTIVE_LOW_RGB = None # 例 (True, False, False) 仅红灯反相 # --- 2.2 按键 ExtInt --- EXTINT_AI_GPIO = "GPIO22" # AI 键 -PWK_KEY_GPIO = "GPIO26" # 电源键(短按/双击切模式等) +PWK_KEY_GPIO = "GPIO41" # 电源键(短按/双击切模式等) #AI Key 按键有效电平是否取反:0=不取反,1=取反 AI_KEY_PRESS_LEVEL_REVERSE = 1 @@ -43,7 +43,7 @@ BTN_WECHAT_GPIO = None BTN_SOS_GPIO = None # --- 2.3 马达(motor.py / motorEventManager)--- -MOTOR_PIN_GPIO = "GPIO20" # None 表示无马达 +MOTOR_PIN_GPIO = None # None 表示无马达 MOTOR_TICK_MS = 100 MOTOR_ACTIVE_LOW = False MOTOR_BOOT_VIBRATE_MS = 200 # 开机震动时长(ms) @@ -213,13 +213,6 @@ VC_IDLE_AUTO_CLOSE_SEC_PTT = 0 # 单对话预留,当前与 idle 统一处理 VC_IDLE_DEEP_SLEEP_SEC = 60 VC_IDLE_DEEP_SLEEP_ENABLE = 1 - # conf->sil_threshold = 63; - # conf->energy_threshold = 15000; - # conf->min_speech_length = 240; - # conf->silence_detect_length = 300; - # conf->rule1_min_tailing_silence = 480; - # conf->rule2_min_tailing_silence = 500; - # conf->rule3_min_tailing_silence = 960; # 本地 imsl 断句静音(ms) —— 映射 silence_detect_length;可被 storage vad_silence 覆盖 VAD_SILENCE_DEFAULT = 300 # rule2 尾部静音(ms):0‑10s 最短连续静音判定语音结束(之前跟随 VAD_SILENCE_DEFAULT,现已独立) @@ -329,7 +322,7 @@ ASR_EMPTY_HINT_TTS = "我没有听清,请再说一遍" # asr.completed 无 # 无按键确认音:不按 key_prompt;仅按键/PTT 开录时播 start.mp3(自动续聊不播) # PTT idle 短按:notify 话术 PTT_HINT;长按开录:start.mp3 -RECORD_START_TONE_FILE = "U:/static/start.pcm" # 按键/PTT 开录提示音(PCM èµ° play_pcm 复用) +RECORD_START_TONE_FILE = "U:/static/start.pcm" # 按键/PTT 开录提示音(非 server.started 自动开麦) RECORD_START_TONE_GAP_MS = 180 PTT_MIN_RECORD_MS = 1200 # 键按到松手最短时间(ms),从 ptt_begin 算起 @@ -346,4 +339,4 @@ PTT_POST_MUTE_MS = 30 # 本地硬静音后 codec 收尾 LED_DEBUG = False LED_STATE_DEBUG = False KEY_LED_DEBUG = False -HW_STATUS_DEBUG = True \ No newline at end of file +HW_STATUS_DEBUG = False \ No newline at end of file diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modcws_frame.c b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modcws_frame.c new file mode 100644 index 00000000..964cc14e --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modcws_frame.c @@ -0,0 +1,208 @@ +/** + * _cws_frame - C-level WebSocket frame reader + * + * 将 uwebsocket.read_frame() 的帧头解析 + unmask 迁入 C 层, + * 消除 Python struct.unpack / 位运算 / 逐字节 XOR 的开销。 + * + * 注:socket 读取仍走 Python sock.read(),以兼容 settimeout / SSL 等机制。 + * C 层的收益在帧解析(位操作 + unmask),而非网络 I/O。 + * + * Python API: + * import _cws_frame + * fin, opcode, data = _cws_frame.read_frame(sock_obj, max_size=-1) + */ +#include +#include +#include + +#include "py/runtime.h" +#include "py/obj.h" +#include "mphal.h" + +/* ---- WS opcodes ---- */ +#define CWS_OP_CONT 0x0 +#define CWS_OP_TEXT 0x1 +#define CWS_OP_BYTES 0x2 +#define CWS_OP_CLOSE 0x8 +#define CWS_OP_PING 0x9 +#define CWS_OP_PONG 0xa + +/* 特殊返回码(非 RFC6455 合法 opcode) */ +#define CWS_RET_NO_DATA (-1) +#define CWS_RET_TOO_BIG (-2) + +/* ---- 帧解析结构 ---- */ +typedef struct { + bool fin; + int opcode; + uint8_t *payload; + size_t payload_len; +} cws_frame_t; + +/* ------------------------------------------------------------------ */ +/* sock.read(n) — 通过 Python 层读取(兼容 timeout/SSL) */ +/* ------------------------------------------------------------------ */ +static size_t cws_sock_read(mp_obj_t sock_obj, uint8_t *buf, size_t n) +{ + mp_obj_t dest[2]; + mp_load_method(sock_obj, MP_QSTR_read, dest); + + mp_obj_t arg = mp_obj_new_int((mp_int_t)n); + mp_obj_t args[3] = {dest[0], dest[1], arg}; + mp_obj_t result = mp_call_method_n_kw(1, 0, args); + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_READ); + + size_t actual = bufinfo.len; + if (actual > n) actual = n; + if (actual > 0) { + memcpy(buf, bufinfo.buf, actual); + } + return actual; +} + +/* ------------------------------------------------------------------ */ +/* 原地 XOR unmask */ +/* ------------------------------------------------------------------ */ +static void cws_unmask_inplace(uint8_t *data, size_t len, + const uint8_t *mask) +{ + size_t i = 0; + if (len >= 4 + && ((uintptr_t)data & 3) == 0 + && ((uintptr_t)mask & 3) == 0) { + uint32_t m = *(const uint32_t *)mask; + uint32_t *d = (uint32_t *)data; + size_t wc = len / 4; + for (i = 0; i < wc; i++) d[i] ^= m; + i *= 4; + } + for (; i < len; i++) data[i] ^= mask[i & 3]; +} + +/* ------------------------------------------------------------------ */ +/* 主解析逻辑 */ +/* ------------------------------------------------------------------ */ +static int cws_read_frame_impl(mp_obj_t sock_obj, int max_size, + cws_frame_t *out) +{ + memset(out, 0, sizeof(*out)); + + /* 1. 2 字节帧头 */ + uint8_t hdr[2]; + if (cws_sock_read(sock_obj, hdr, 2) < 2) { + out->opcode = CWS_RET_NO_DATA; + return -1; + } + uint8_t byte1 = hdr[0]; + uint8_t byte2 = hdr[1]; + + out->fin = (byte1 & 0x80) != 0; + out->opcode = byte1 & 0x0f; + bool masked = (byte2 & 0x80) != 0; + size_t length = byte2 & 0x7f; + + /* 2. 扩展长度 */ + if (length == 126) { + uint8_t ext[2]; + if (cws_sock_read(sock_obj, ext, 2) < 2) goto proto_err; + length = ((size_t)ext[0] << 8) | ext[1]; + } else if (length == 127) { + uint8_t ext[8]; + if (cws_sock_read(sock_obj, ext, 8) < 8) goto proto_err; + length = 0; + for (int i = 0; i < 8; i++) length = (length << 8) | ext[i]; + } + + /* 3. 掩码键 */ + uint8_t mask_key[4] = {0}; + if (masked) { + if (cws_sock_read(sock_obj, mask_key, 4) < 4) goto proto_err; + } + + /* 4. 大小校验 -> FrameTooBig */ + if (max_size > 0 && length > (size_t)max_size) { + out->opcode = CWS_RET_TOO_BIG; + out->fin = true; + return -1; + } + + /* 5. 读 payload */ + if (length == 0) return 0; + + out->payload = m_malloc(length ? length : 1); + if (!out->payload) goto proto_err; + + size_t total = 0; + while (total < length) { + size_t n = cws_sock_read(sock_obj, + out->payload + total, + length - total); + if (n == 0) { + m_free(out->payload); + out->payload = NULL; + goto proto_err; + } + total += n; + } + out->payload_len = length; + + /* 6. Unmask */ + if (masked) { + cws_unmask_inplace(out->payload, length, mask_key); + } + return 0; + +proto_err: + mp_raise_msg(&mp_type_ValueError, "WS frame read protocol error"); +} + +/* ------------------------------------------------------------------ */ +/* 导出: read_frame(sock, max_size=-1) -> (fin,opcode,data) */ +/* ------------------------------------------------------------------ */ +STATIC mp_obj_t cws_frame_read_frame(mp_obj_t sock_obj, mp_obj_t max_size_obj) +{ + int max_size = -1; + if (max_size_obj != mp_const_none) { + max_size = (int)mp_obj_get_int(max_size_obj); + } + + cws_frame_t f; + int ret = cws_read_frame_impl(sock_obj, max_size, &f); + + if (ret < 0) { + mp_obj_t tuple[3] = { + mp_obj_new_bool(f.fin), + mp_obj_new_int(f.opcode), + mp_obj_new_bytes(NULL, 0), + }; + return mp_obj_new_tuple(3, tuple); + } + + mp_obj_t tuple[3] = { + mp_obj_new_bool(f.fin), + mp_obj_new_int(f.opcode), + (f.payload_len > 0) + ? mp_obj_new_bytes(f.payload, f.payload_len) + : mp_obj_new_bytes(NULL, 0), + }; + mp_obj_t result = mp_obj_new_tuple(3, tuple); + + if (f.payload) m_free(f.payload); + return result; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(cws_frame_read_frame_obj, cws_frame_read_frame); + +/* ---- 模块注册 ---- */ +STATIC const mp_rom_map_elem_t cws_frame_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__cws_frame) }, + { MP_ROM_QSTR(MP_QSTR_read_frame), MP_ROM_PTR(&cws_frame_read_frame_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(mp_module_cws_frame_globals, cws_frame_globals_table); + +const mp_obj_module_t mp_module_cws_frame = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&mp_module_cws_frame_globals, +}; diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modmask.c b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modmask.c new file mode 100644 index 00000000..cca91b9f --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modmask.c @@ -0,0 +1,62 @@ +#include +#include +#include + +#include "obj.h" +#include "runtime.h" + +#include "mphal.h" + + + +/* websocket_mask.MASK(data, data_len, mask):原地 XOR 掩码/反掩码(XOR 对称),data 必须可写 */ +STATIC mp_obj_t websocket_mask_func_withargs(mp_obj_t data, mp_obj_t data_len, mp_obj_t mask) +{ + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_WRITE); + + mp_buffer_info_t mask_bufinfo; + mp_get_buffer_raise(mask, &mask_bufinfo, MP_BUFFER_WRITE); + + int len = mp_obj_get_int(data_len); + unsigned char *data_buf = (unsigned char *)bufinfo.buf; + unsigned char *mask_buf = (unsigned char *)mask_bufinfo.buf; + + /* 4 字节对齐且长度 >= 4:按 uint32_t 批量 XOR,减少循环次数 */ + size_t i = 0; + if (len >= 4 && ((uintptr_t)data_buf & 3) == 0 && ((uintptr_t)mask_buf & 3) == 0) { + uint32_t mask32 = *(uint32_t *)mask_buf; + uint32_t *data32 = (uint32_t *)data_buf; + size_t word_count = len / 4; + for (i = 0; i < word_count; i++) { + data32[i] ^= mask32; + } + i *= 4; + } + /* 剩余尾部逐字节 XOR */ + for (; i < (size_t)len; i++) { + data_buf[i] ^= mask_buf[i & 3]; + } + return mp_obj_new_int(len); +} + +/* + * 这里使用的宏定义和前面的名称不一样,后缀是1,不是0 + * 后缀是几,表示该方法携带几个参数 + */ +STATIC const MP_DEFINE_CONST_FUN_OBJ_3(websocket_mask_obj_func_withargs, websocket_mask_func_withargs); + +/* 定义的websocket_mask全局字典,之后我们添加type和function就要添加在这里 */ +STATIC const mp_rom_map_elem_t websocket_mask_globals_table[] = { + {MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket_mask)}, //这个对应python层面的__name__ 属性 + {MP_OBJ_NEW_QSTR(MP_QSTR_MASK), MP_ROM_PTR(&websocket_mask_obj_func_withargs)}, //新增的websocket_mask_obj_func_withargs对象注册到websocket_mask中 +}; + +/* 把websocket_mask_globals_table注册到 mp_module_websocket_mask_globals里面去 */ +STATIC MP_DEFINE_CONST_DICT(mp_module_websocket_mask_globals, websocket_mask_globals_table); + +/* 定义一个module类型 */ +const mp_obj_module_t mp_module_websocket_mask = { + .base = {&mp_type_module}, + .globals = (mp_obj_dict_t *)&mp_module_websocket_mask_globals, +}; diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/mpconfigport.h b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/mpconfigport.h new file mode 100644 index 00000000..6d862daf --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/mpconfigport.h @@ -0,0 +1,1074 @@ +/* + * Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#if defined(PLAT_Unisoc) || defined(PLAT_Unisoc_8910_R05) || defined(PLAT_Unisoc_8850_R02) || defined(PLAT_Unisoc_8910_R06) +#include "quec_proj_config.h" +#endif +#include "mpconfigboard.h" +#include "mpconfigplatform.h" +#include "random.h" + +#ifdef CONFIG_LVGL +#ifndef MICROPY_INCLUDED_PY_MPSTATE_H +#define MICROPY_INCLUDED_PY_MPSTATE_H +#include "misc/lv_gc.h" +#undef MICROPY_INCLUDED_PY_MPSTATE_H +#else +#include "misc/lv_gc.h" +#endif +#endif + + +#if !(defined(BOARD_EC600MCN_CC_EXT) || defined(BOARD_EC600MCN_CC_EXT_TTS) || defined(BOARD_EC800MCN_CC_TTS) \ + || defined(BOARD_EC800KCN_CC_TTS) || defined(BOARD_EC600KCN_CC_TTS)) || defined(PLAT_aic8800m40) +#define MICROPY_PY_REPL_PASSWORD_PROTECT (1) +#endif + + // options to control how MicroPython is built +#define MICROPY_ENABLE_COMPILER (1) +#define MICROPY_USE_INTERNAL_ERRNO (1) +#define MICROPY_QSTR_BYTES_IN_HASH (1) +#define MICROPY_ALLOC_PATH_MAX (512) + +#define MICROPY_EMIT_X64 (0) +#define MICROPY_EMIT_THUMB (0) +#define MICROPY_EMIT_INLINE_THUMB (0) +#define MICROPY_COMP_MODULE_CONST (1) +#define MICROPY_COMP_CONST (1) +#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (0) +#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1) +#define MICROPY_MEM_STATS (0) +#define MICROPY_DEBUG_PRINTERS (MICROPY_QPY_DEBUG_PRINTERS) +#define MICROPY_ENABLE_GC (1) +#define MICROPY_HELPER_REPL (1) +#define MICROPY_ENABLE_DOC_STRING (0) + +#if (defined(BOARD_EC600MCN_CC_EXT) || defined(BOARD_EC800MCN_CC_TTS) \ + || defined(BOARD_EC800KCN_CC_TTS) || defined(BOARD_EC600KCN_CC_TTS)) +#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE) +#else +#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL) +#endif + +#if MICROPY_ENABLE_GC +#ifndef MICROPY_QPY_GC_HEAP_SIZE +#define MICROPY_QPY_GC_HEAP_SIZE (512 * 1024) +#endif +#define MICROPY_GC_HEAP_SIZE (MICROPY_QPY_GC_HEAP_SIZE) +#endif + +#ifdef MICROPY_QPY_MAIN_TASK_STACK_SIZE +#define MP_QPY_TASK_STACK_SIZE (MICROPY_QPY_MAIN_TASK_STACK_SIZE) +#else +#if defined(PLAT_RDA) +#define MP_QPY_TASK_STACK_SIZE (32 * 1024) +#elif defined(PLAT_EIGEN) +#define MP_QPY_TASK_STACK_SIZE (32 * 1024) +#elif defined(PLAT_EIGEN_718) +#define MP_QPY_TASK_STACK_SIZE (32 * 1024) +#elif defined(PLAT_ECR6600) +#define MP_QPY_TASK_STACK_SIZE (8 * 1024) +#elif defined(PLAT_aic8800m40) +#define MP_QPY_TASK_STACK_SIZE (10 * 1024) +#elif defined(PLAT_Unisoc_8850) || defined(PLAT_Unisoc_8850_R02) + #if defined(BOARD_EC600GCN_LD) || defined(BOARD_EC800GCN_LD) || defined(BOARD_EC800GCN_LD_XBND) \ + || defined(BOARD_EC800GCN_LD_HRXM) || defined(BOARD_EC600GCN_LD_YM) || defined(BOARD_EC800GCN_TT) \ + || defined(BOARD_EG800GLA_LD) || defined(BOARD_EG800GEU_LD) + #define MP_QPY_TASK_STACK_SIZE (16 * 1024) + #else + #define MP_QPY_TASK_STACK_SIZE (64 * 1024) + #endif +#else +#define MP_QPY_TASK_STACK_SIZE (64 * 1024) +#endif +#endif + +#if !(defined(BOARD_EC600MCN_CC_EXT) || defined(BOARD_EC600MCN_CC_EXT_TTS) || defined(BOARD_EC800MCN_CC_TTS) \ + || defined(BOARD_EC800KCN_CC_TTS) || defined(BOARD_EC600KCN_CC_TTS)) +#define MICROPY_STACK_CHECK (1) +#endif +#define MICROPY_PY_BUILTINS_BYTEARRAY (1) +#define MICROPY_PY_BUILTINS_DICT_FROMKEYS (0) +#define MICROPY_PY_BUILTINS_MEMORYVIEW (1) +#define MICROPY_PY_BUILTINS_FROZENSET (1) +#define MICROPY_PY_BUILTINS_REVERSED (1) +#define MICROPY_PY_BUILTINS_SET (1) +#define MICROPY_PY_BUILTINS_SLICE (1) +#define MICROPY_PY_BUILTINS_PROPERTY (1) +#define MICROPY_PY_BUILTINS_STR_COUNT (1) +#define MICROPY_PY_BUILTINS_STR_OP_MODULO (1) + +#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) +#define MICROPY_PY_BUILTINS_SLICE_INDICES (1) +#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1) +#define MICROPY_PY_BUILTINS_ROUND_INT (1) + +#define MICROPY_PY_BUILTINS_TIMEOUTERROR (1) +#define MICROPY_PY_ALL_SPECIAL_METHODS (1) +#define MICROPY_PY_BUILTINS_COMPILE (1) +#define MICROPY_PY_BUILTINS_ENUMERATE (1) +#define MICROPY_PY_BUILTINS_EXECFILE (1) +#define MICROPY_PY_BUILTINS_FILTER (1) +#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) +#define MICROPY_PY_BUILTINS_MIN_MAX (1) +#define MICROPY_PY_BUILTINS_POW3 (1) + + +#define MICROPY_KBD_EXCEPTION (1) +#define MICROPY_PY___FILE__ (1) +#define MICROPY_PY_GC (1) +#define MICROPY_PY_ARRAY (1) +#define MICROPY_PY_ATTRTUPLE (1) +#define MICROPY_PY_COLLECTIONS (1) +#define MICROPY_PY_MATH (MICROPY_QPY_PY_MATH) +#define MICROPY_PY_CMATH (MICROPY_QPY_PY_CMATH) +#define MICROPY_PY_IO (1) +#define MICROPY_PY_IO_IOBASE (1) +#define MICROPY_PY_IO_BYTESIO (1) +#define MICROPY_PY_STRUCT (1) +#define MICROPY_PY_SYS (1) +#define MICROPY_PY_SYS_MAXSIZE (1) +#define MICROPY_PY_SYS_MODULES (1) +#define MICROPY_PY_SYS_EXIT (1) +#define MICROPY_PY_SYS_STDFILES (1) +#define MICROPY_PY_SYS_STDIO_BUFFER (1) +#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_VFS (1) +/****************@20221217 Added by Mark****************/ +/*Add a macro to control LFS Version in mpconfigboard.h*/ +/*******************************************************/ +#if MICROPY_QPY_MODULE_LFS2_SUPPORT +//LFS2 will be used in pythonSDK when macro 'MICROPY_QPY_MODULE_LFS2_SUPPORT' is defined as 1 +#define MICROPY_VFS_LFS2 (1) +#else +//LFS1 will be used in pythonSDK when macro 'MICROPY_QPY_MODULE_LFS2_SUPPORT' is defined as 0 or undefined +#define MICROPY_VFS_LFS1 (1) +#endif +/**************************END***************************/ +#if CONFIG_SPI_SDCARD//forrest.liu@20210731 add for SPI SD card function +#define MICROPY_VFS_FAT (1) +#else +#define MICROPY_VFS_FAT (0) +#endif +#define MICROPY_PY_IO_FILEIO (1) +#define MICROPY_PY_BUILTINS_INPUT (1) + +#if (defined(PLAT_ASR_1803s) || defined(PLAT_ASR_1803sc)) && MICROPY_QPY_MODULE_VFS_FAT_SDIO + +#define MICROPY_VFS_FAT_SDIO (1) + +#endif + +// jaxsen 2021-09-11 +#if !defined(PLAT_RDA) +#define MICROPY_PY_UASYNCIO (MICROPY_QPY_PY_UASYNCIO) +#else +#define MICROPY_PY_UASYNCIO (0) +#endif +#define MICROPY_PY_USELECT (MICROPY_QPY_PY_USELECT) +#define MICROPY_PY_UERRNO (1) +// 2021-09-11 +#define MICROPY_CPYTHON_COMPAT (1) +#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) +#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) //decimal numbers support +#define MICROPY_USE_INTERNAL_PRINTF (0) +#define MICROPY_REPL_AUTO_INDENT (1) + //baron 2020/04/17 +#if !(defined(BOARD_EC600MCN_CC_EXT) || defined(BOARD_EC600MCN_CC_EXT_TTS) || defined(BOARD_EC800MCN_CC_TTS) \ + || defined(BOARD_EC800KCN_CC_TTS) || defined(BOARD_EC600KCN_CC_TTS)) +#define MICROPY_REPL_EMACS_WORDS_MOVE (1) +#define MICROPY_REPL_EMACS_KEYS (1) +#define MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE (1) +#define MICROPY_REPL_PASSWORD_PROTECT (1) //mia.zhong @20220224 +#endif +#define MICROPY_PY_BUILTINS_HELP (1) + +//#define MICROPY_PY_BUILTINS_HELP_TEXT quecpython_help_text + +#define MICROPY_PY_BUILTINS_HELP_MODULES (1) +#define MICROPY_MODULE_BUILTIN_INIT (1) +#define MICROPY_DEBUG_VERBOSE (0) + // Allow enabling debug prints after each REPL line +#define MICROPY_REPL_INFO (1) + // Whether to include information in the byte code to determine source + // line number (increases RAM usage, but doesn't slow byte code execution) +#define MICROPY_ENABLE_SOURCE_LINE (1) +#define MICROPY_PY_USOCKET_EVENTS (1) +#define MICROPY_ENABLE_SCHEDULER (1) +#define MICROPY_SCHEDULER_DEPTH (64)//8 +#define MICROPY_PY_BUILTINS_FILTER (1) +#define MICROPY_MODULE_FROZEN_MPY (1) +#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool + + + //ext modules +#define MICROPY_PY_UWEBSOCKET (1) +#define MICROPY_PY_UCTYPES (MICROPY_QPY_PY_UCTYPES) +#define MICROPY_PY_UZLIB (MICROPY_QPY_PY_UZLIB) +#define MICROPY_PY_UJSON (1) +#define MICROPY_PY_URE (1) +#define MICROPY_PY_UBINASCII (1) +#define MICROPY_PY_UBINASCII_LRC (1) +#define MICROPY_READER_VFS (1) +#define MICROPY_PY_URANDOM (1) +#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (qpy_rng_get()) +#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_THREAD (1) +#define MICROPY_PY_THREAD_GIL (1) +#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32) + +#if MICROPY_QPY_MODULE_USSL +#define MICROPY_PY_USSL (1) // (1) for original, modified by Chavis for compilation on 1/7/2021 +#define MICROPY_PY_USSL_FINALISER (1) +#endif +#if MICROPY_QPY_SSL_MBEDTLS +#define MICROPY_SSL_MBEDTLS (1) // (1) for original, modified by Chavis for compilation on 1/7/2021 + +#if MICROPY_QPY_MODULE_UHASHLIB +#if MICROPY_QPY_MODULE_UHASHLIB_ONLYMD5 +#define MICROPY_PY_UHASHLIB (1) +#define MICROPY_PY_UHASHLIB_SHA256 (0) +#if MICROPY_QPY_MODULE_UHASHLIB_SHA1 +#define MICROPY_PY_UHASHLIB_SHA1 (1) +#define MICROPY_PY_UHASHLIB_ONLYSHA1 (1) +#else +#define MICROPY_PY_UHASHLIB_SHA1 (0) +#endif + +#define MICROPY_PY_UHASHLIB_MD5 (1) +#else +#define MICROPY_PY_UHASHLIB (1) +#define MICROPY_PY_UHASHLIB_SHA256 (1) +#define MICROPY_PY_UHASHLIB_SHA1 (1) +#define MICROPY_PY_UHASHLIB_MD5 (1) +#endif +#endif + +#if MICROPY_QPY_MODULE_UCRYPTOLIB +#define MICROPY_PY_UCRYPTOLIB (1) +#if !(defined(BOARD_EC600MCN_CC_EXT_TTS) || defined(BOARD_EC800MCN_CC_TTS) \ + || defined(BOARD_EC800KCN_CC_TTS) || defined(BOARD_EC600KCN_CC_TTS)) +#define MICROPY_PY_UCRYPTOLIB_CTR (1) +#define MICROPY_PY_UCRYPTOLIB_CONSTS (1) +#define MICROPY_PY_UCRYPTOLIB_GCM (1) +#define MICROPY_PY_UCRYPTOLIB_WRAP (1) +#endif + +#if MICROPY_QPY_UCRYPTOLIB_ECDSA +#define MICROPY_PY_UCRYPTOLIB_ECDSA (1) +#endif + +#if MICROPY_QPY_UCRYPTOLIB_ECDH +#define MICROPY_PY_UCRYPTOLIB_ECDH (1) +#endif + +#endif + +#endif + +#if !defined(PLAT_RDA) +#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1) +#endif + +#if defined(PLAT_RDA) +/* burols add Either quething or NB cloud platform can be chosen at the same time */ +#if defined(CONFIG_QUECTHING) + #define MICROPY_PY_NB (0) + #define MICROPY_PY_NB_OC (0) + #define MICROPY_PY_NB_AEP (0) + #define MICROPY_PY_NB_ONENET (0) +#else + #define MICROPY_PY_NB (1) + #define MICROPY_PY_NB_OC (1) + #define MICROPY_PY_NB_AEP (1) + #define MICROPY_PY_NB_ONENET (1) +#endif +#endif + +#define MICROPY_PY_COLLECTIONS_DEQUE (1) +//#define MICROPY_CAN_OVERRIDE_BUILTINS (1) + + + //end + + + // type definitions for the specific machine +#define MICROPY_PY_MACHINE (1) +#define MICROPY_PY_EXAMPLE (1) +#define MICROPY_PY_QUECLIB (1) +#define MICROPY_PY_NET (1) +#define MICROPY_PY_FOTA (1) +#define MICROPY_PY_MISC (1) + +#define MICROPY_NLR_SETJMP (1) +// optimisations +#if !defined(PLAT_Qualcomm) +#define MICROPY_OPT_COMPUTED_GOTO (1) +#else +#define MICROPY_OPT_COMPUTED_GOTO (0)//forrest.liu@20210926 add for dump when python use "param = xxx" +#endif +#define MICROPY_OPT_MPZ_BITWISE (1) + +// emitters +#define MICROPY_PERSISTENT_CODE_LOAD (MICROPY_QPY_PERSISTENT_CODE_LOAD) +#define MICROPY_EMIT_XTENSAWIN (MICROPY_QPY_EMIT_XTENSAWIN) + + +//#define MICROPY_WARNINGS (1) +//#define MICROPY_STREAMS_NON_BLOCK (1) + +#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) +#define MICROPY_ENABLE_FINALISER (1) // Pawn 2020/11/03 + +#if defined(BOARD_EC600MCN_CC_EXT) || defined(BOARD_EC600MCN_CC_EXT_TTS) || defined(BOARD_EC800MCN_CC_TTS) \ + || defined(BOARD_EC800KCN_CC_TTS) || defined(BOARD_EC600KCN_CC_TTS) +#define MICROPY_ROM_TEXT_COMPRESSION (1) +#endif + +#define MICROPY_ENABLE_DEVICE_REPORT (MICROPY_QPY_DEVICE_REPORT) + +#define MICROPY_ENABLE_CALLBACK_DEAL (1) + +#define MICROPY_PY_SOFT_RESET (1) + +//==Start Add by freddy.li for raise error has no reason. @20230625 +#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) +#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256) +//==End + +/*#if MICROPY_QPY_ETHERNET_W5500 || MICROPY_QPY_MISC_USBNET +#define MICROPY_PY_ENABLE_WEBSERVER (MICROPY_QPY_PY_ENABLE_WEBSERVER) +#else +#define MICROPY_PY_ENABLE_WEBSERVER (0) +#endif*/ +#define MICROPY_PY_ENABLE_WEBSERVER (0) + + +#define UINT_FMT "%lu" +#define INT_FMT "%ld" + +#define BYTES_PER_WORD (4) + +typedef int32_t mp_int_t; // must be pointer size +typedef uint32_t mp_uint_t; // must be pointer size +typedef long mp_off_t; + +#if MICROPY_PY_USOCKET_EVENTS && MICROPY_QPY_MODULE_USOCKET +#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void usocket_events_handler(void); usocket_events_handler(); +#else +#define MICROPY_PY_USOCKET_EVENTS_HANDLER +#endif + +#if defined(PLAT_Qualcomm) +#define mp_type_fileio mp_type_vfs_efs_fileio +#define mp_type_textio mp_type_vfs_efs_textio +#elif MICROPY_VFS_LFS1 +#define mp_type_fileio mp_type_vfs_lfs1_fileio +#define mp_type_textio mp_type_vfs_lfs1_textio +#elif MICROPY_VFS_LFS2 +#define mp_type_fileio mp_type_vfs_lfs2_fileio +#define mp_type_textio mp_type_vfs_lfs2_textio +#endif + + + +/////////////////// +#if MICROPY_QPY_MODULE_ATCMD +extern const struct _mp_obj_module_t mp_module_atcmd; +#define MICROPY_PORT_BUILTIN_MODULES_ATCMD { MP_OBJ_NEW_QSTR(MP_QSTR_atcmd), (mp_obj_t)&mp_module_atcmd}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_ATCMD +#endif + +#if MICROPY_QPY_MODULE_UOS +extern const struct _mp_obj_module_t uos_module; +#define MICROPY_PORT_BUILTIN_MODULES_UOS { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_UOS +#endif + +#if MICROPY_QPY_MODULE_MACHINE +extern const struct _mp_obj_module_t mp_module_machine; +#define MICROPY_PORT_BUILTIN_MODULES_MACHINE { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_MACHINE +#endif + +#if MICROPY_QPY_MODULE_USOCKET +extern const struct _mp_obj_module_t mp_module_usocket; +#define MICROPY_PORT_BUILTIN_MODULES_USOCKET { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_USOCKET +#endif + +#if MICROPY_QPY_MODULE_USQLITE +extern const struct _mp_obj_module_t mp_module_usqlite; +#define MICROPY_PORT_BUILTIN_MODULES_USQLITE { MP_OBJ_NEW_QSTR(MP_QSTR_usqlite), (mp_obj_t)&mp_module_usqlite}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_USQLITE +#endif + +#if MICROPY_QPY_MODULE_URSA +extern const struct _mp_obj_module_t mp_module_rsa; +#define MICROPY_PORT_BUILTIN_MODULES_URSA { MP_OBJ_NEW_QSTR(MP_QSTR_rsa), (mp_obj_t)&mp_module_rsa }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_URSA +#endif + +#if MICROPY_QPY_MODULE_SFTP +extern const struct _mp_obj_module_t mp_module_usftp; +#define MICROPY_PORT_BUILTIN_MODULES_SFTP { MP_OBJ_NEW_QSTR(MP_QSTR_usftp), (mp_obj_t)&mp_module_usftp }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SFTP +#endif + +#if MICROPY_QPY_MODULE_SSH +extern const struct _mp_obj_module_t mp_module_ussh; +#define MICROPY_PORT_BUILTIN_MODULES_SSH { MP_OBJ_NEW_QSTR(MP_QSTR_ussh), (mp_obj_t)&mp_module_ussh }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SSH +#endif + +#if MICROPY_QPY_MODULE_MISC +extern const struct _mp_obj_module_t mp_module_misc; +#define MICROPY_PORT_BUILTIN_MODULES_MISC { MP_OBJ_NEW_QSTR(MP_QSTR_misc), (mp_obj_t)&mp_module_misc}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_MISC +#endif + +#if MICROPY_QPY_MODULE_OSTIMER +extern const struct _mp_obj_type_t mp_ostimer_type; +#define MICROPY_PORT_BUILTIN_MODULES_OSTIMER { MP_OBJ_NEW_QSTR(MP_QSTR_osTimer), (mp_obj_t)&mp_ostimer_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_OSTIMER +#endif + +#if MICROPY_QPY_MODULE_EXAMPLE +extern const struct _mp_obj_module_t example_module; +#define MICROPY_PORT_BUILTIN_MODULES_EXAMPLE { MP_OBJ_NEW_QSTR(MP_QSTR_example), (mp_obj_t)&example_module }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_EXAMPLE +#endif + +#if MICROPY_QPY_MODULE_DATACALL +extern const struct _mp_obj_module_t mp_module_dial; +#define MICROPY_PORT_BUILTIN_MODULES_DATACALL { MP_OBJ_NEW_QSTR(MP_QSTR_dial), (mp_obj_t)&mp_module_dial}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_DATACALL +#endif + +#if MICROPY_QPY_MODULE_MODEM +extern const struct _mp_obj_module_t mp_module_modem; +#define MICROPY_PORT_BUILTIN_MODULES_MODEM { MP_OBJ_NEW_QSTR(MP_QSTR_modem), (mp_obj_t)&mp_module_modem}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_MODEM +#endif + +#if MICROPY_QPY_MODULE_UTIME +extern const struct _mp_obj_module_t utime_module; +#define MICROPY_PORT_BUILTIN_MODULES_UTIME { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, +#define MICROPY_PORT_BUILTIN_MODULES_TIME { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&utime_module }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_UTIME +#define MICROPY_PORT_BUILTIN_MODULES_TIME +#endif + +#if MICROPY_QPY_MODULE_UTILS +extern const struct _mp_obj_module_t mp_module_utils; +#define MICROPY_PORT_BUILTIN_MODULES_UTILS { MP_OBJ_NEW_QSTR(MP_QSTR_utils), (mp_obj_t)&mp_module_utils}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_UTILS +#endif + +#if MICROPY_QPY_MODULE_HMACSHA1 +extern const struct _mp_obj_module_t mp_module_hmacSha1; +#define MICROPY_PORT_BUILTIN_MODULES_HMACSHA1 { MP_OBJ_NEW_QSTR(MP_QSTR_hmacSha1), (mp_obj_t)&mp_module_hmacSha1}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_HMACSHA1 +#endif + +#if MICROPY_QPY_MODULE_SMS +extern const struct _mp_obj_module_t mp_module_sms; +#define MICROPY_PORT_BUILTIN_MODULES_SMS { MP_OBJ_NEW_QSTR(MP_QSTR_sms), (mp_obj_t)&mp_module_sms}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SMS +#endif + +#if MICROPY_QPY_MODULE_USSD +extern const struct _mp_obj_module_t mp_module_ussd; +#define MICROPY_PORT_BUILTIN_MODULES_USSD { MP_OBJ_NEW_QSTR(MP_QSTR_ussd), (mp_obj_t)&mp_module_ussd}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_USSD +#endif + +#if MICROPY_QPY_MODULE_SIM +extern const struct _mp_obj_module_t mp_module_sim; +#define MICROPY_PORT_BUILTIN_MODULES_SIM { MP_OBJ_NEW_QSTR(MP_QSTR_sim), (mp_obj_t)&mp_module_sim}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SIM +#endif + +#if MICROPY_QPY_MODULE_LPM +extern const struct _mp_obj_module_t mp_module_pm; +#define MICROPY_PORT_BUILTIN_MODULES_LPM { MP_OBJ_NEW_QSTR(MP_QSTR_pm), (mp_obj_t)&mp_module_pm}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_LPM +#endif + +#if MICROPY_QPY_MODULE_NET +extern const struct _mp_obj_module_t mp_module_net; +#define MICROPY_PORT_BUILTIN_MODULES_NET { MP_OBJ_NEW_QSTR(MP_QSTR_net), (mp_obj_t)&mp_module_net}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_NET +#endif + +#if MICROPY_QPY_MODULE_CELLLOCATOR +extern const struct _mp_obj_module_t mp_module_celllocator; +#define MICROPY_PORT_BUILTIN_MODULES_CELLLOCATOR { MP_OBJ_NEW_QSTR(MP_QSTR_cellLocator), (mp_obj_t)&mp_module_celllocator}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_CELLLOCATOR +#endif + +#if MICROPY_QPY_MODULE_CELLLOCATOR_QPY +extern const struct _mp_obj_module_t mp_module_celllocator_qpy; +#define MICROPY_PORT_BUILTIN_MODULES_CELLLOCATOR_QPY { MP_OBJ_NEW_QSTR(MP_QSTR_cellLocator_qpy), (mp_obj_t)&mp_module_celllocator_qpy}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_CELLLOCATOR_QPY +#endif + + +#if MICROPY_QPY_MODULE_AUDIO +extern const struct _mp_obj_module_t mp_module_audio; +#define MICROPY_PORT_BUILTIN_MODULES_AUDIO { MP_OBJ_NEW_QSTR(MP_QSTR_audio), (mp_obj_t)&mp_module_audio}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_AUDIO +#endif + +#if MICROPY_QPY_MODULE_FOTA +extern const struct _mp_obj_type_t mp_fota_type; +#define MICROPY_PORT_BUILTIN_MODULES_FOTA { MP_OBJ_NEW_QSTR(MP_QSTR_fota), (mp_obj_t)&mp_fota_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_FOTA +#endif + +#if MICROPY_QPY_MODULE_G711 +extern const struct _mp_obj_type_t mp_G711_type; +#define MICROPY_PORT_BUILTIN_MODULES_G711 { MP_OBJ_NEW_QSTR(MP_QSTR_G711), (mp_obj_t)&mp_G711_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_G711 +#endif + +#if MICROPY_QPY_MODULE_G729 +extern const struct _mp_obj_type_t mp_G729_type; +#define MICROPY_PORT_BUILTIN_MODULES_G729 { MP_OBJ_NEW_QSTR(MP_QSTR_G729), (mp_obj_t)&mp_G729_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_G729 +#endif + +#if MICROPY_QPY_MODULE_G722 +extern const struct _mp_obj_type_t mp_G722_type; +#define MICROPY_PORT_BUILTIN_MODULES_G722 { MP_OBJ_NEW_QSTR(MP_QSTR_G722), (mp_obj_t)&mp_G722_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_G722 +#endif + + + +#if MICROPY_QPY_MODULE_QUECIOT +extern const struct _mp_obj_module_t mp_module_quecIot; +#define MICROPY_PORT_BUILTIN_MODULES_QUECTHING { MP_OBJ_NEW_QSTR(MP_QSTR_quecIot), (mp_obj_t)&mp_module_quecIot}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_QUECTHING +#endif + +#if MICROPY_QPY_MODULE_WIFISCAN +extern const struct _mp_obj_module_t mp_module_wifiscan; +#define MICROPY_PORT_BUILTIN_MODULES_WIFISCAN { MP_OBJ_NEW_QSTR(MP_QSTR_wifiScan), (mp_obj_t)&mp_module_wifiscan}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_WIFISCAN +#endif + +#if MICROPY_QPY_MODULE_QUECGNSS +extern const struct _mp_obj_module_t mp_module_quecgnss; +#define MICROPY_PORT_BUILTIN_MODULES_QUECGNSS { MP_OBJ_NEW_QSTR(MP_QSTR_quecgnss), (mp_obj_t)&mp_module_quecgnss}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_QUECGNSS +#endif + +#if MICROPY_QPY_MODULE_WIFILOCATOR +extern const struct _mp_obj_module_t mp_module_wifilocator; +#define MICROPY_PORT_BUILTIN_MODULES_WIFILOCATOR { MP_OBJ_NEW_QSTR(MP_QSTR___wifiLocator), (mp_obj_t)&mp_module_wifilocator }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_WIFILOCATOR +#endif + +#if MICROPY_QPY_MODULE_WIFI +extern const struct _mp_obj_module_t mp_module_wifi; +#define MICROPY_PORT_BUILTIN_MODULES_WIFI { MP_OBJ_NEW_QSTR(MP_QSTR_wifi), (mp_obj_t)&mp_module_wifi }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_WIFI +#endif + +#if MICROPY_QPY_MODULE_ETHERNET || CONFIG_ETHERNET +extern const struct _mp_obj_module_t mp_module_ethernet; +#define MICROPY_PORT_BUILTIN_MODULES_ETHERNET { MP_OBJ_NEW_QSTR(MP_QSTR_ethernet), (mp_obj_t)&mp_module_ethernet }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_ETHERNET +#endif + +#if MICROPY_QPY_MODULE_LVGL +extern const struct _mp_obj_module_t mp_module_lvgl; +#define MICROPY_PORT_BUILTIN_MODULES_LVGL { MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_LVGL +#endif + +#if MICROPY_QPY_MODULE_CAMERA +extern const struct _mp_obj_module_t mp_module_camera; +#define MICROPY_PORT_BUILTIN_MODULES_CAMERA { MP_OBJ_NEW_QSTR(MP_QSTR_camera), (mp_obj_t)&mp_module_camera}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_CAMERA +#endif + +#if MICROPY_QPY_MODULE_BLE +extern const struct _mp_obj_module_t mp_module_ble; +#define MICROPY_PORT_BUILTIN_MODULES_BLE { MP_OBJ_NEW_QSTR(MP_QSTR_ble), (mp_obj_t)&mp_module_ble}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_BLE +#endif + +#if MICROPY_QPY_MODULE_BT +extern const struct _mp_obj_module_t mp_module_bt; +#define MICROPY_PORT_BUILTIN_MODULES_BT { MP_OBJ_NEW_QSTR(MP_QSTR_bt), (mp_obj_t)&mp_module_bt}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_BT +#endif + +#if MICROPY_QPY_MODULE_SENSOR +extern const struct _mp_obj_module_t mp_module_sensor; +#define MICROPY_PORT_BUILTIN_MODULES_SENSOR { MP_OBJ_NEW_QSTR(MP_QSTR_sensor), (mp_obj_t)&mp_module_sensor}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SENSOR +#endif + +#if MICROPY_QPY_MODULE_RTMP +extern const struct _mp_obj_module_t mp_module_rtmp; +#define MICROPY_PORT_BUILTIN_MODULES_RTMP { MP_OBJ_NEW_QSTR(MP_QSTR_librtmp), (mp_obj_t)&mp_module_rtmp}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_RTMP +#endif + +#if MICROPY_QPY_MODULE_VIOCE_CALL +extern const struct _mp_obj_module_t mp_module_voicecall; +#define MICROPY_PORT_BUILTIN_MODULES_VOICECALL { MP_OBJ_NEW_QSTR(MP_QSTR_voiceCall), (mp_obj_t)&mp_module_voicecall}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_VOICECALL +#endif + +#if MICROPY_QPY_MODULE_SECUREDATA +extern const struct _mp_obj_module_t module_SecureData; +#define MICROPY_PORT_BUILTIN_MODULES_SECUREDATA { MP_OBJ_NEW_QSTR(MP_QSTR_SecureData), (mp_obj_t)&module_SecureData}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SECUREDATA +#endif + +#if MICROPY_QPY_MODULE_SLIP || CONFIG_SLIP +extern const struct _mp_obj_module_t module_slip; +#define MICROPY_PORT_BUILTIN_MODULES_SLIP { MP_OBJ_NEW_QSTR(MP_QSTR_slip), (mp_obj_t)&module_slip}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SLIP +#endif + +#if MICROPY_QPY_MODULE_POC +extern const struct _mp_obj_module_t mp_module_poc; +#define MICROPY_PORT_BUILTIN_MODULES_POC { MP_OBJ_NEW_QSTR(MP_QSTR_poc), (mp_obj_t)&mp_module_poc}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_POC +#endif + +#if MICROPY_QPY_MODULE_QRCODE +extern const struct _mp_obj_module_t mp_module_qrcode; +#define MICROPY_PORT_BUILTIN_MODULES_QRCODE { MP_OBJ_NEW_QSTR(MP_QSTR_qrcode), (mp_obj_t)&mp_module_qrcode}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_QRCODE +#endif + +#if MICROPY_QPY_MODULE_AUDIOCODEC +extern const struct _mp_obj_module_t mp_module_audiocodec; +#define MICROPY_PORT_BUILTIN_MODULES_AUDIOCODEC { MP_OBJ_NEW_QSTR(MP_QSTR_audioCodec), (mp_obj_t)&mp_module_audiocodec}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_AUDIOCODEC +#endif + +#if MICROPY_QPY_MODULE_CSD +extern const struct _mp_obj_module_t mp_module_csd; +#define MICROPY_PORT_BUILTIN_MODULES_CSD { MP_OBJ_NEW_QSTR(MP_QSTR_csd), (mp_obj_t)&mp_module_csd}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_CSD +#endif + +#if MICROPY_QPY_MODULE_LWM2M +extern const struct _mp_obj_type_t module_lwm2m_type; +#define MICROPY_PORT_BUILTIN_MODULES_LWM2M { MP_OBJ_NEW_QSTR(MP_QSTR_lwm2m), (mp_obj_t)&module_lwm2m_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_LWM2M +#endif + +#if MICROPY_QPY_MODULE_DLMS +extern const struct _mp_obj_module_t mp_module_dlms; +#define MICROPY_PORT_BUILTIN_MODULES_DLMS { MP_OBJ_NEW_QSTR(MP_QSTR_dlms), (mp_obj_t)&mp_module_dlms}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_DLMS +#endif + +#if MICROPY_QPY_MODULE_NB +extern const struct _mp_obj_module_t mp_module_nb; +#define MICROPY_PORT_BUILTIN_MODULES_NB { MP_OBJ_NEW_QSTR(MP_QSTR_nb), (mp_obj_t)&mp_module_nb}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_NB +#endif +#if MICROPY_QPY_MODULE_TP +extern const struct _mp_obj_module_t mp_module_tp; +#define MICROPY_PORT_BUILTIN_MODULES_TP { MP_OBJ_NEW_QSTR(MP_QSTR_tp), (mp_obj_t)&mp_module_tp}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_TP +#endif + +#if MICROPY_PY_ENABLE_WEBSERVER +extern const struct _mp_obj_type_t webserver_type; +#define MICROPY_PORT_BUILTIN_MODULES_WEBSERVER { MP_OBJ_NEW_QSTR(MP_QSTR_webserver), (mp_obj_t)&webserver_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_WEBSERVER +#endif + +#if MICROPY_QPY_MODULE_CAN_MCP2515 +extern const struct _mp_obj_type_t can_mcp2515_type; +#define MICROPY_PORT_BUILTIN_MODULES_CAN_MCP2515 { MP_OBJ_NEW_QSTR(MP_QSTR_MCP2515), (mp_obj_t)&can_mcp2515_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_CAN_MCP2515 +#endif + +#if MICROPY_QPY_MODULE_EXTUART_WK2114 +extern const struct _mp_obj_type_t extuart_wk2114_type; +#define MICROPY_PORT_BUILTIN_MODULES_EXTUART_WK2114 { MP_OBJ_NEW_QSTR(MP_QSTR_WK2114), (mp_obj_t)&extuart_wk2114_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_EXTUART_WK2114 +#endif + +#if MICROPY_QPY_MODULE_EXTGPIO_AW9523 +extern const struct _mp_obj_type_t extgpio_aw9523_type; +#define MICROPY_PORT_BUILTIN_MODULES_EXTGPIO_AW9523 { MP_OBJ_NEW_QSTR(MP_QSTR_AW9523), (mp_obj_t)&extgpio_aw9523_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_EXTGPIO_AW9523 +#endif + +#if MICROPY_QPY_MODULE_ALIPAY +extern const struct _mp_obj_type_t ALIPAY_type; +#define MICROPY_PORT_BUILTIN_MODULES_ALIPAY { MP_OBJ_NEW_QSTR(MP_QSTR_ALIPAY), (mp_obj_t)&ALIPAY_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_ALIPAY +#endif +#if 1 //MICROPY_QPY_MODULE_Gsensor +extern const struct _mp_obj_module_t mp_module_Gsensor; +#define MICROPY_PORT_BUILTIN_MODULES_Gsensor { MP_OBJ_NEW_QSTR(MP_QSTR_Gsensor), (mp_obj_t)&mp_module_Gsensor}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_Gsensor +#endif +extern const struct _mp_obj_module_t mp_module_websocket_mask; +#define MICROPY_PORT_BUILTIN_MODULES_WEBSOCKET_MASK { MP_OBJ_NEW_QSTR(MP_QSTR_websocket_mask), (mp_obj_t)&mp_module_websocket_mask}, +extern const struct _mp_obj_module_t mp_module_cws_frame; +#define MICROPY_PORT_BUILTIN_MODULES_CWS_FRAME { MP_OBJ_NEW_QSTR(MP_QSTR__cws_frame), (mp_obj_t)&mp_module_cws_frame}, +#if CONFIG_VAD +extern const struct _mp_obj_module_t mp_module_VAD ; +#define MICROPY_PORT_BUILTIN_MODULES_VAD { MP_OBJ_NEW_QSTR(MP_QSTR_VAD), (mp_obj_t)&mp_module_VAD}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_VAD +#endif +#if MICROPY_QPY_MODULE_GPIO_ENCODER +extern const struct _mp_obj_type_t encoder_type; +#define MICROPY_PORT_BUILTIN_MODULES_ENCODER { MP_OBJ_NEW_QSTR(MP_QSTR_encoder), (mp_obj_t)&encoder_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_ENCODER +#endif + +#if 1 //MICROPY_QPY_MODULE_Hsensor +extern const struct _mp_obj_module_t mp_module_Hsensor; +#define MICROPY_PORT_BUILTIN_MODULES_Hsensor { MP_OBJ_NEW_QSTR(MP_QSTR_Hsensor), (mp_obj_t)&mp_module_Hsensor}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_Hsensor +#endif + +// #if 1 //MICROPY_QPY_MODULE_VideoCall +// extern const struct _mp_obj_module_t mp_module_VideoCall; +// #define MICROPY_PORT_BUILTIN_MODULES_VideoCall { MP_OBJ_NEW_QSTR(MP_QSTR_VideoCall), (mp_obj_t)&mp_module_VideoCall}, +// #else +// #define MICROPY_PORT_BUILTIN_MODULES_VideoCall +// #endif +#if CONFIG_juphoon || MICROPY_QPY_MODULE_JRTC +extern const struct _mp_obj_module_t mp_module_jrtc; +#define MICROPY_PORT_BUILTIN_MODULES_JRTC { MP_OBJ_NEW_QSTR(MP_QSTR_jrtc), (mp_obj_t)&mp_module_jrtc}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_JRTC +#endif + +extern const struct _mp_obj_module_t mp_module_code128; +#define MICROPY_PORT_BUILTIN_MODULES_code128 { MP_OBJ_NEW_QSTR(MP_QSTR_code128), (mp_obj_t)&mp_module_code128 }, /* ע��`code128`� */ + +#if MICROPY_QPY_MODULE_NETWORK +extern const struct _mp_obj_module_t mp_module_network; +#define MICROPY_PORT_BUILTIN_MODULES_NETWORK { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network }, +#else +#define MICROPY_PORT_BUILTIN_MODULES_NETWORK +#endif + +#if MICROPY_QPY_MODULE_ALIPAY_COLLECTION +extern const struct _mp_obj_type_t ALIPAY_COLLECTION_type; +#define MICROPY_PORT_BUILTIN_MODULES_ALIPAY_COLLECTION { MP_OBJ_NEW_QSTR(MP_QSTR_ALIPAY_COLLECTION), (mp_obj_t)&ALIPAY_COLLECTION_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_ALIPAY_COLLECTION +#endif + +#if MICROPY_QPY_MODULE_GPIO_ENCODER +extern const struct _mp_obj_type_t encoder_type; +#define MICROPY_PORT_BUILTIN_MODULES_GPIO_ENCODER { MP_OBJ_NEW_QSTR(MP_QSTR_encoder), (mp_obj_t)&encoder_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_GPIO_ENCODER +#endif + +#if MICROPY_QPY_MODULE_SIF +extern const struct _mp_obj_module_t mp_module_modsif; +#define MICROPY_PORT_BUILTIN_MODULES_SIF { MP_OBJ_NEW_QSTR(MP_QSTR_sif), (mp_obj_t)&mp_module_modsif}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_SIF +#endif + + + +#if MICROPY_QPY_MODULE_NFC +extern const struct _mp_obj_module_t mp_module_nfc; +#define MICROPY_PORT_BUILTIN_MODULES_NFC { MP_OBJ_NEW_QSTR(MP_QSTR_nfc), (mp_obj_t)&mp_module_nfc}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_NFC +#endif + +#if MICROPY_QPY_MODULE_STK +extern const struct _mp_obj_module_t mp_module_stk; +#define MICROPY_PORT_BUILTIN_MODULES_STK { MP_OBJ_NEW_QSTR(MP_QSTR_stk), (mp_obj_t)&mp_module_stk}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_STK +#endif + +#if MICROPY_QPY_MODULE_ALIPAY_SE +extern const struct _mp_obj_type_t ALIPAY_SE_type; +#define MICROPY_PORT_BUILTIN_MODULES_ALIPAY_SE { MP_OBJ_NEW_QSTR(MP_QSTR_ALIPAY_SE), (mp_obj_t)&ALIPAY_SE_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_ALIPAY_SE +#endif + +#if MICROPY_QPY_MODULE_VOIP +extern const struct _mp_obj_type_t mp_voip_type; +#define MICROPY_PORT_BUILTIN_MODULES_VOIP { MP_OBJ_NEW_QSTR(MP_QSTR_voip), (mp_obj_t)&mp_voip_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_VOIP +#endif + +#if MICROPY_QPY_MODULE_IPSEC +extern const struct _mp_obj_type_t mp_ipsec_type; +#define MICROPY_PORT_BUILTIN_MODULES_IPSEC { MP_OBJ_NEW_QSTR(MP_QSTR_ipsec), (mp_obj_t)&mp_ipsec_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_IPSEC +#endif + +#if CONFIG_TIKTIK_RTC +extern const struct _mp_obj_type_t TiktokRTC_type; +#define MICROPY_PORT_BUILTIN_MODULES_TiktokRTC { MP_OBJ_NEW_QSTR(MP_QSTR_TiktokRTC), (mp_obj_t)&TiktokRTC_type}, +#else +#define MICROPY_PORT_BUILTIN_MODULES_TiktokRTC +#endif + +////////////////// + +#define MICROPY_PORT_BUILTIN_MODULES \ + MICROPY_PORT_BUILTIN_MODULES_UOS \ + MICROPY_PORT_BUILTIN_MODULES_MACHINE \ + MICROPY_PORT_BUILTIN_MODULES_USOCKET \ + MICROPY_PORT_BUILTIN_MODULES_USQLITE \ + MICROPY_PORT_BUILTIN_MODULES_MISC \ + MICROPY_PORT_BUILTIN_MODULES_OSTIMER \ + MICROPY_PORT_BUILTIN_MODULES_EXAMPLE \ + MICROPY_PORT_BUILTIN_MODULES_DATACALL \ + MICROPY_PORT_BUILTIN_MODULES_MODEM \ + MICROPY_PORT_BUILTIN_MODULES_UTIME \ + MICROPY_PORT_BUILTIN_MODULES_TIME \ + MICROPY_PORT_BUILTIN_MODULES_UTILS \ + MICROPY_PORT_BUILTIN_MODULES_HMACSHA1 \ + MICROPY_PORT_BUILTIN_MODULES_SMS \ + MICROPY_PORT_BUILTIN_MODULES_USSD \ + MICROPY_PORT_BUILTIN_MODULES_VOICECALL \ + MICROPY_PORT_BUILTIN_MODULES_SECUREDATA \ + MICROPY_PORT_BUILTIN_MODULES_SIM \ + MICROPY_PORT_BUILTIN_MODULES_LPM \ + MICROPY_PORT_BUILTIN_MODULES_NET \ + MICROPY_PORT_BUILTIN_MODULES_CELLLOCATOR \ + MICROPY_PORT_BUILTIN_MODULES_CELLLOCATOR_QPY \ + MICROPY_PORT_BUILTIN_MODULES_WIFISCAN \ + MICROPY_PORT_BUILTIN_MODULES_AUDIO \ + MICROPY_PORT_BUILTIN_MODULES_ETHERNET \ + MICROPY_PORT_BUILTIN_MODULES_WIFILOCATOR \ + MICROPY_PORT_BUILTIN_MODULES_WIFI \ + MICROPY_PORT_BUILTIN_MODULES_FOTA \ + MICROPY_PORT_BUILTIN_MODULES_LVGL \ + MICROPY_PORT_BUILTIN_MODULES_QRCODE \ + MICROPY_PORT_BUILTIN_MODULES_CAMERA \ + MICROPY_PORT_BUILTIN_MODULES_BLE \ + MICROPY_PORT_BUILTIN_MODULES_BT \ + MICROPY_PORT_BUILTIN_MODULES_QUECTHING \ + MICROPY_PORT_BUILTIN_MODULES_SENSOR \ + MICROPY_PORT_BUILTIN_MODULES_QUECGNSS \ + MICROPY_PORT_BUILTIN_MODULES_RTMP \ + MICROPY_PORT_BUILTIN_MODULES_SLIP \ + MICROPY_PORT_BUILTIN_MODULES_POC \ + MICROPY_PORT_BUILTIN_MODULES_AUDIOCODEC \ + MICROPY_PORT_BUILTIN_MODULES_ATCMD \ + MICROPY_PORT_BUILTIN_MODULES_TP \ + MICROPY_PORT_BUILTIN_MODULES_CSD \ + MICROPY_PORT_BUILTIN_MODULES_LWM2M \ + MICROPY_PORT_BUILTIN_MODULES_URSA \ + MICROPY_PORT_BUILTIN_MODULES_SFTP \ + MICROPY_PORT_BUILTIN_MODULES_SSH \ + MICROPY_PORT_BUILTIN_MODULES_NB \ + MICROPY_PORT_BUILTIN_MODULES_WEBSERVER \ + MICROPY_PORT_BUILTIN_MODULES_G711 \ + MICROPY_PORT_BUILTIN_MODULES_CAN_MCP2515 \ + MICROPY_PORT_BUILTIN_MODULES_EXTUART_WK2114 \ + MICROPY_PORT_BUILTIN_MODULES_EXTGPIO_AW9523 \ + MICROPY_PORT_BUILTIN_MODULES_ALIPAY \ + MICROPY_PORT_BUILTIN_MODULES_G729 \ + MICROPY_PORT_BUILTIN_MODULES_G722 \ + MICROPY_PORT_BUILTIN_MODULES_Gsensor \ + MICROPY_PORT_BUILTIN_MODULES_ENCODER \ + MICROPY_PORT_BUILTIN_MODULES_Hsensor \ + MICROPY_PORT_BUILTIN_MODULES_JRTC \ + MICROPY_PORT_BUILTIN_MODULES_code128\ + MICROPY_PORT_BUILTIN_MODULES_WEBSOCKET_MASK\ + MICROPY_PORT_BUILTIN_MODULES_CWS_FRAME\ + MICROPY_PORT_BUILTIN_MODULES_VAD\ + MICROPY_PORT_BUILTIN_MODULES_NETWORK \ + MICROPY_PORT_BUILTIN_MODULES_ALIPAY_COLLECTION \ + MICROPY_PORT_BUILTIN_MODULES_GPIO_ENCODER \ + MICROPY_PORT_BUILTIN_MODULES_SIF\ + MICROPY_PORT_BUILTIN_MODULES_NFC \ + MICROPY_PORT_BUILTIN_MODULES_STK \ + MICROPY_PORT_BUILTIN_MODULES_ALIPAY_SE \ + MICROPY_PORT_BUILTIN_MODULES_VOIP \ + MICROPY_PORT_BUILTIN_MODULES_IPSEC \ + MICROPY_PORT_BUILTIN_MODULES_DLMS \ + MICROPY_PORT_BUILTIN_MODULES_TiktokRTC + + + +// use vfs's functions for import stat and builtin open +#define mp_import_stat mp_vfs_import_stat +#define mp_builtin_open mp_vfs_open +#define mp_builtin_open_obj mp_vfs_open_obj + + // dummy print + //#define MP_PLAT_PRINT_STRN(str, len) uart_printf("%s", str) + //#define MP_PLAT_PRINT_STRN(str, len) ql_micropy_print_str(QL_MAIN_UART_PORT, str, len) +#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len) + + +//#define MICROPY_BEGIN_ATOMIC_SECTION() disableInterrupts() + +//#define MICROPY_END_ATOMIC_SECTION(state) restoreInterrupts(state) + + + + + // extra built in names to add to the global namespace +#define MICROPY_PORT_BUILTINS \ + { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, + + + +#if MICROPY_PY_THREAD +#define MICROPY_EVENT_POLL_HOOK \ + do { \ + extern void mp_handle_pending(bool); \ + mp_handle_pending(true); \ + MICROPY_PY_USOCKET_EVENTS_HANDLER \ + MP_THREAD_GIL_EXIT(); \ + MP_THREAD_GIL_ENTER(); \ + } while (0); +#else +#define MICROPY_EVENT_POLL_HOOK \ + do { \ + extern void mp_handle_pending(bool); \ + mp_handle_pending(true); \ + MICROPY_PY_USOCKET_EVENTS_HANDLER \ + asm ("waiti 0"); \ + } while (0); +#endif + + +#ifdef __thumb__ +#define MICROPY_MIN_USE_CORTEX_CPU (1) +#define MICROPY_MIN_USE_STM32_MCU (1) +#endif + +#define MP_STATE_PORT MP_STATE_VM + +#ifdef CONFIG_LVGL +#define MICROPY_PORT_ROOT_POINTERS \ + LV_ROOTS \ + void *mp_lv_user_data; \ + const char *readline_hist[8]; \ + struct _machine_timer_obj_t *machine_timer_obj_head; \ + volatile void *global_stacktop_ptr; \ + void *loadmeth_para; +#else +#define MICROPY_PORT_ROOT_POINTERS \ + void *mp_lv_user_data; \ + const char *readline_hist[8]; \ + struct _machine_timer_obj_t *machine_timer_obj_head; \ + volatile void *global_stacktop_ptr; \ + void *loadmeth_para; +#endif + +#define STRINGIFY_VALUE(s) STRINGIFY(s) +#define STRINGIFY(s) #s + +#define MICROPY_HW_BOARD_NAME STRINGIFY_VALUE(BOARD) +#define MICROPY_HW_MCU_NAME "QUECTEL" + +// board specifics +#define MICROPY_PY_SYS_PLATFORM STRINGIFY_VALUE(BOARD) + +#define QUECPYTHON_VERSION_STRING STRINGIFY_VALUE(QPYVER) + +#if !defined(PLAT_Qualcomm) +#ifndef SSIZE_MAX +#define SSIZE_MAX 0xFFFFFFFF +#endif +#else +typedef int intptr_t; +typedef unsigned int uintptr_t; +#endif + +// We need to provide a declaration/definition of alloca() +#include "stdlib.h" diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/uwebsocket.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/uwebsocket.py new file mode 100644 index 00000000..6dd164ef --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/uwebsocket.py @@ -0,0 +1,350 @@ +import log +import usocket as socket +import ubinascii as binascii +import urandom as random +import log +import ure as re +import ustruct as struct +import urandom as random +import usocket as socket +from ucollections import namedtuple +import websocket_mask +try: + import _cws_frame +except ImportError: + _cws_frame = None +LOGGER = log.getLogger(__name__) + + +def _vc_ws_native_ping_tx_enabled(): + """1=客户端主动发 RFC6455 OP_PING;0=不发。入站 OP_PING 始终回 OP_PONG(与配置无关)。""" + try: + import vc_config + return int(vc_config.get_int("VC_WS_NATIVE_PING_ENABLE", 0)) != 0 + except Exception: + return False + + +# Opcodes +OP_CONT = 0x0 +OP_TEXT = 0x1 +OP_BYTES = 0x2 +OP_CLOSE = 0x8 +OP_PING = 0x9 +OP_PONG = 0xa + +# Close codes +CLOSE_OK = 1000 +CLOSE_GOING_AWAY = 1001 +CLOSE_PROTOCOL_ERROR = 1002 +CLOSE_DATA_NOT_SUPPORTED = 1003 +CLOSE_BAD_DATA = 1007 +CLOSE_POLICY_VIOLATION = 1008 +CLOSE_TOO_BIG = 1009 +CLOSE_MISSING_EXTN = 1010 +CLOSE_BAD_CONDITION = 1011 + +URL_RE = re.compile(r'(wss|ws)://([A-Za-z0-9-\.]+)(?:\:([0-9]+))?(/.+)?') +URI = namedtuple('URI', ('protocol', 'hostname', 'port', 'path')) + + +def urlparse(uri): + """Parse ws:// URLs""" + match = URL_RE.match(uri) + if match: + protocol = match.group(1) + host = match.group(2) + port = match.group(3) + path = match.group(4) + + if protocol == 'wss': + if port is None: + port = 443 + elif protocol == 'ws': + if port is None: + port = 80 + else: + raise ValueError('Scheme {} is invalid'.format(protocol)) + + return URI(protocol, host, int(port), path) + + +class NoDataException(Exception): + pass + + +class ConnectionClosed(Exception): + pass + + +class Websocket(object): + """ + Basis of the Websocket protocol. + + This can probably be replaced with the C-based websocket module, but + this one currently supports more options. + """ + is_client = False + + def __init__(self, sock, debug=False): + self.sock = sock + self.open = True + self.debug = debug + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc, tb): + self.close() + + def settimeout(self, timeout): + self.sock.settimeout(timeout) + + def read_frame(self, max_size=None): + """ + Read a frame from the socket. + See https://tools.ietf.org/html/rfc6455#section-5.2 for the details. + """ + # C 加速路径:_cws_frame 可用时,帧头解析 + unmask 在 C 层完成 + if _cws_frame is not None: + _max = -1 if max_size is None else max_size + try: + fin, opcode, data = _cws_frame.read_frame(self.sock, _max) + if opcode == -1: # CWS_RET_NO_DATA + raise NoDataException + if opcode == -2: # CWS_RET_TOO_BIG + if self.debug: + LOGGER.info("Frame too big (C). Closing") + self.close(code=CLOSE_TOO_BIG) + return True, OP_CLOSE, None + return fin, opcode, data + except (ValueError, RuntimeError): + # 协议错误或 C 侧异常,回退 Python 路径 + pass + + # Python 回退路径 + # Frame header + two_bytes = self.sock.read(2) + + if not two_bytes: + raise NoDataException + + byte1, byte2 = struct.unpack('!BB', two_bytes) + + # Byte 1: FIN(1) _(1) _(1) _(1) OPCODE(4) + fin = bool(byte1 & 0x80) + opcode = byte1 & 0x0f + + # Byte 2: MASK(1) LENGTH(7) + mask = bool(byte2 & (1 << 7)) + length = byte2 & 0x7f + + if length == 126: # Magic number, length header is 2 bytes + length, = struct.unpack('!H', self.sock.read(2)) + elif length == 127: # Magic number, length header is 8 bytes + length, = struct.unpack('!Q', self.sock.read(8)) + + if mask: # Mask is 4 bytes + mask_bits = self.sock.read(4) + + try: + data = self.sock.read(length) + except MemoryError: + # We can't receive this many bytes, close the socket + if self.debug: LOGGER.info("Frame of length %s too big. Closing", length) + self.close(code=CLOSE_TOO_BIG) + return True, OP_CLOSE, None + + if mask: + _arr = bytearray(data) + websocket_mask.MASK(_arr, len(_arr), bytearray(mask_bits)) + data = bytes(_arr) + + return fin, opcode, data + + def write_frame(self, opcode, data=b''): + """ + Write a frame to the socket. + See https://tools.ietf.org/html/rfc6455#section-5.2 for the details. + """ + fin = True + mask = self.is_client # messages sent by client are masked + + length = len(data) + + # Frame header + # Byte 1: FIN(1) _(1) _(1) _(1) OPCODE(4) + byte1 = 0x80 if fin else 0 + byte1 |= opcode + + # Byte 2: MASK(1) LENGTH(7) + byte2 = 0x80 if mask else 0 + + if length < 126: # 126 is magic value to use 2-byte length header + byte2 |= length + self.sock.write(struct.pack('!BB', byte1, byte2)) + + elif length < (1 << 16): # Length fits in 2-bytes + byte2 |= 126 # Magic code + self.sock.write(struct.pack('!BBH', byte1, byte2, length)) + + elif length < (1 << 64): + byte2 |= 127 # Magic code + self.sock.write(struct.pack('!BBQ', byte1, byte2, length)) + + else: + raise ValueError() + if mask: # Mask is 4 bytes + mask_bits = struct.pack('!I', random.getrandbits(32)) + self.sock.write(mask_bits) + + data_array = bytearray(data) + mask_bits_array = bytearray(mask_bits) + websocket_mask.MASK(data_array,len(data_array),mask_bits_array) + data=bytes(data_array) + self.sock.write(data) + + def recv(self): + """ + Receive data from the websocket. + + This is slightly different from 'websockets' in that it doesn't + fire off a routine to process frames and put the data in a queue. + If you don't call recv() sufficiently often you won't process control + frames. + """ + assert self.open + + while self.open: + try: + fin, opcode, data = self.read_frame() + except NoDataException: + return '' + except ValueError: + if self.debug: LOGGER.info("Failed to read frame. Socket dead.") + self._close() + raise ConnectionClosed() + + if not fin: + raise NotImplementedError() + + if opcode == OP_TEXT: + return data.decode('utf-8') + elif opcode == OP_BYTES: + return data + elif opcode == OP_CLOSE: + self._close() + return + elif opcode == OP_PONG: + # Ignore this frame, keep waiting for a data frame + continue + elif opcode == OP_PING: + if self.debug: + LOGGER.info("Sending PONG") + self.write_frame(OP_PONG, data) + continue + elif opcode == OP_CONT: + # This is a continuation of a previous frame + raise NotImplementedError(opcode) + else: + raise ValueError(opcode) + + def send(self, buf): + """Send data to the websocket.""" + + assert self.open + + if isinstance(buf, str): + opcode = OP_TEXT + buf = buf.encode('utf-8') + elif isinstance(buf, bytes): + opcode = OP_BYTES + else: + raise TypeError() + + self.write_frame(opcode, buf) + + def ping(self): + if _vc_ws_native_ping_tx_enabled(): + self.write_frame(OP_PING, b'ping') + + def close(self, code=CLOSE_OK, reason=''): + """Close the websocket.""" + if not self.open: + return + + buf = struct.pack('!H', code) + reason.encode('utf-8') + + self.write_frame(OP_CLOSE, buf) + self._close() + + def _close(self): + if self.debug: LOGGER.info("Connection closed") + self.open = False + self.sock.close() + + +class WebsocketClient(Websocket): + is_client = True + + +class Client(object): + + @staticmethod + def connect(uri, headers=None, debug=False): + """ + Connect a websocket. + :param uri: example ws://172.16.185.123/ + :param headers: k, v of header + :param debug: allow output log + :return: + """ + if not headers: + headers = dict() + if not isinstance(headers, dict): + raise Exception("headers must be dict type but {} you given.".format(type(headers))) + + uri = urlparse(uri) + assert uri + + if debug: LOGGER.info("open connection %s:%s", + uri.hostname, uri.port) + + sock = socket.socket() + addr = socket.getaddrinfo(uri.hostname, uri.port) + sock.connect(addr[0][4]) + + if uri.protocol == 'wss': + import ussl + sock = ussl.wrap_socket(sock) + + def send_header(header, *args): + if debug: LOGGER.info(str(header), *args) + sock.write(header % args + '\r\n') + + # Sec-WebSocket-Key is 16 bytes of random base64 encoded + key = binascii.b2a_base64(bytes(random.getrandbits(8) for _ in range(16)))[:-1] + send_header(b'GET %s HTTP/1.1', uri.path or '/') + send_header(b'Host: %s:%s', uri.hostname, uri.port) + send_header(b'Connection: Upgrade') + send_header(b'Upgrade: websocket') + send_header(b'Sec-WebSocket-Key: %s', key) + send_header(b'Sec-WebSocket-Version: 13') + send_header(b'Origin: http://{hostname}:{port}'.format( + hostname=uri.hostname, + port=uri.port) + ) + for k, v in headers.items(): + send_header('{}:{}'.format(k, v).encode()) + send_header(b'') + + header = sock.readline()[:-2] + assert header.startswith(b'HTTP/1.1 101 '), header + + # We don't (currently) need these headers + # FIXME: should we check the return key? + while header: + if debug: LOGGER.info(str(header)) + header = sock.readline()[:-2] + + return WebsocketClient(sock, debug)