├── .github └── workflows │ ├── issue_comment.yml │ ├── new_issues.yml │ └── new_prs.yml ├── .gitignore ├── .gitlab-ci.yml ├── CMakeLists.txt ├── Kconfig ├── README.md ├── component.mk ├── config └── mass_mfg │ ├── multipule_mfg_config.csv │ ├── multipule_mfg_values.csv │ └── single_mfg_config.csv ├── docs ├── _picture │ ├── Demo二维码.jpg │ ├── UUID、CID和PID.jpg │ ├── ota_后台版本设置.png │ ├── 使能BLE.jpg │ ├── 公钥、私钥和MAC.jpg │ ├── 微联APP-配网界面.jpg │ ├── 环境搭建.jpg │ ├── 配网方式后台配置界面.jpg │ └── 配网选择.jpg └── md │ └── 量产说明.md ├── examples └── light_demo │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── components │ └── joylink_extern │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ ├── joylink_dev.h │ │ ├── joylink_extern.c │ │ ├── joylink_extern.h │ │ ├── joylink_extern_json.c │ │ ├── joylink_extern_json.h │ │ ├── joylink_extern_ota.c │ │ ├── joylink_extern_ota.h │ │ ├── joylink_extern_sub_dev.c │ │ ├── joylink_extern_sub_dev.h │ │ ├── joylink_extern_user.c │ │ ├── joylink_extern_user.h │ │ ├── joylink_led_rgb.c │ │ ├── joylink_led_rgb.h │ │ ├── joylink_light.c │ │ └── joylink_light.h │ ├── default_configs │ ├── esp32 │ │ ├── joylink_demo.csv │ │ └── sdkconfig.defaults │ ├── esp32c3 │ │ ├── joylink_demo.csv │ │ └── sdkconfig.defaults │ ├── esp32s2 │ │ ├── joylink_demo.csv │ │ └── sdkconfig.defaults │ ├── esp32s3 │ │ ├── joylink_demo.csv │ │ └── sdkconfig.defaults │ └── esp8266 │ │ ├── joylink_demo.csv │ │ └── sdkconfig.defaults │ └── main │ ├── CMakeLists.txt │ ├── app_main.c │ ├── component.mk │ ├── esp_joylink_app.c │ └── esp_joylink_app.h ├── joylink_dev_sdk ├── COPYING ├── Makefile ├── README ├── RELEASENOTES ├── ble_sdk │ ├── adapter │ │ └── joylink_adapter.c │ ├── include │ │ ├── joylink_adapter.h │ │ ├── joylink_platform.h │ │ ├── joylink_sdk.h │ │ └── joylink_utils.h │ └── target │ │ └── lib │ │ ├── esp32 │ │ └── libjoylinkblesdk.a │ │ ├── esp32c3 │ │ └── libjoylinkblesdk.a │ │ └── esp32s3 │ │ └── libjoylinkblesdk.a ├── example │ ├── Makefile │ ├── joylink_extern.c │ ├── joylink_extern.h │ ├── joylink_extern_json.c │ ├── joylink_extern_json.h │ ├── joylink_extern_ota.c │ ├── joylink_extern_ota.h │ ├── joylink_extern_sub_dev.c │ ├── joylink_extern_sub_dev.h │ ├── joylink_extern_user.c │ ├── joylink_extern_user.h │ └── test.c ├── joylink │ ├── inc │ │ ├── joylink.h │ │ ├── joylink_dev_active.h │ │ ├── joylink_ret_code.h │ │ ├── joylink_sub_dev.h │ │ ├── joylink_tempkey.h │ │ ├── joylink_version.h │ │ └── softap │ │ │ └── joylink_softap_start.h │ └── lib │ │ ├── esp32 │ │ └── libjoylink.a │ │ ├── esp32c3 │ │ └── libjoylink.a │ │ ├── esp32s2 │ │ └── libjoylink.a │ │ ├── esp32s3 │ │ └── libjoylink.a │ │ └── esp8266 │ │ └── libjoylink.a ├── lua │ ├── JDB0.lua │ ├── delete_snapshot.lua │ ├── example.lua │ └── only_trans.lua ├── pal │ ├── Makefile │ ├── inc │ │ ├── joylink_flash.h │ │ ├── joylink_http.h │ │ ├── joylink_log.h │ │ ├── joylink_memory.h │ │ ├── joylink_socket.h │ │ ├── joylink_softap.h │ │ ├── joylink_stdint.h │ │ ├── joylink_stdio.h │ │ ├── joylink_string.h │ │ ├── joylink_thread.h │ │ └── joylink_time.h │ └── src │ │ ├── joylink_flash.c │ │ ├── joylink_http.c │ │ ├── joylink_memory.c │ │ ├── joylink_socket.c │ │ ├── joylink_softap.c │ │ ├── joylink_stdio.c │ │ ├── joylink_string.c │ │ ├── joylink_thread.c │ │ └── joylink_time.c └── scripts │ └── config.mk └── port ├── include ├── ifaddrs.h ├── joylink_ble.h └── joylink_upgrade.h ├── joylink_ble.c └── joylink_upgrade.c /.github/workflows/issue_comment.yml: -------------------------------------------------------------------------------- 1 | name: Sync issue comments to JIRA 2 | 3 | # This workflow will be triggered when new issue comment is created (including PR comments) 4 | on: issue_comment 5 | 6 | jobs: 7 | sync_issue_comments_to_jira: 8 | name: Sync Issue Comments to Jira 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Sync issue comments to JIRA 13 | uses: espressif/github-actions/sync_issues_to_jira@master 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | JIRA_PASS: ${{ secrets.JIRA_PASS }} 17 | JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} 18 | JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }} 19 | JIRA_URL: ${{ secrets.JIRA_URL }} 20 | JIRA_USER: ${{ secrets.JIRA_USER }} 21 | -------------------------------------------------------------------------------- /.github/workflows/new_issues.yml: -------------------------------------------------------------------------------- 1 | name: Sync issues to Jira 2 | 3 | # This workflow will be triggered when a new issue is opened 4 | on: issues 5 | 6 | jobs: 7 | sync_issues_to_jira: 8 | name: Sync issues to Jira 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Sync GitHub issues to Jira project 13 | uses: espressif/github-actions/sync_issues_to_jira@master 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | JIRA_PASS: ${{ secrets.JIRA_PASS }} 17 | JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} 18 | JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }} 19 | JIRA_URL: ${{ secrets.JIRA_URL }} 20 | JIRA_USER: ${{ secrets.JIRA_USER }} 21 | -------------------------------------------------------------------------------- /.github/workflows/new_prs.yml: -------------------------------------------------------------------------------- 1 | name: Sync remain PRs to Jira 2 | 3 | # This workflow will be triggered every 6 hours, to sync remaining PRs (i.e. PRs with zero comment) to Jira project 4 | # Note that, PRs can also get synced when new PR comment is created 5 | on: 6 | schedule: 7 | - cron: "0 */6 * * *" 8 | 9 | jobs: 10 | sync_prs_to_jira: 11 | name: Sync PRs to Jira 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@master 15 | - name: Sync PRs to Jira project 16 | uses: espressif/github-actions/sync_issues_to_jira@master 17 | with: 18 | cron_job: true 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 21 | JIRA_PASS: ${{ secrets.JIRA_PASS }} 22 | JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} 23 | JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }} 24 | JIRA_URL: ${{ secrets.JIRA_URL }} 25 | JIRA_USER: ${{ secrets.JIRA_USER }} 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .cproject 3 | .project 4 | .DS_Store 5 | .vscode 6 | examples/*/build 7 | examples/*/sdkconfig* 8 | examples/*/*.csv 9 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(JOYLINK_SDK_DIR joylink_dev_sdk) 2 | set(includes 3 | ${JOYLINK_SDK_DIR}/joylink/inc 4 | ${JOYLINK_SDK_DIR}/joylink/inc/softap 5 | ${JOYLINK_SDK_DIR}/pal/inc 6 | port/include) 7 | 8 | 9 | # Edit following two lines to set component requirements (see docs) 10 | set(components ${IDF_TARGET} nvs_flash app_update esp-tls tcpip_adapter joylink_extern) 11 | 12 | set(srcs 13 | ${JOYLINK_SDK_DIR}/pal/src/joylink_flash.c 14 | ${JOYLINK_SDK_DIR}/pal/src/joylink_memory.c 15 | ${JOYLINK_SDK_DIR}/pal/src/joylink_socket.c 16 | ${JOYLINK_SDK_DIR}/pal/src/joylink_softap.c 17 | ${JOYLINK_SDK_DIR}/pal/src/joylink_stdio.c 18 | ${JOYLINK_SDK_DIR}/pal/src/joylink_string.c 19 | ${JOYLINK_SDK_DIR}/pal/src/joylink_thread.c 20 | ${JOYLINK_SDK_DIR}/pal/src/joylink_time.c) 21 | 22 | if (("${IDF_TARGET}" STREQUAL "esp32") OR ("${IDF_TARGET}" STREQUAL "esp32s3") 23 | OR ("${IDF_TARGET}" STREQUAL "esp32c3")) 24 | list(APPEND components "bt") 25 | endif() 26 | 27 | if(CONFIG_JOYLINK_BLE_ENABLE) 28 | list(APPEND includes ${JOYLINK_SDK_DIR}/ble_sdk/include) 29 | list(APPEND srcs ${JOYLINK_SDK_DIR}/ble_sdk/adapter/joylink_adapter.c port/joylink_ble.c) 30 | endif() 31 | 32 | list(APPEND srcs port/joylink_upgrade.c) 33 | 34 | idf_component_register(SRCS "${srcs}" 35 | INCLUDE_DIRS "${includes}" 36 | REQUIRES "${components}") 37 | 38 | if(CONFIG_JOYLINK_BLE_ENABLE) 39 | message(STATUS "CHIP is ${IDF_TARGET},linking ble libary") 40 | set(LIBBLE joylinkblesdk) 41 | add_library(${LIBBLE} STATIC IMPORTED) 42 | set_property(TARGET ${LIBBLE} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/${JOYLINK_SDK_DIR}/ble_sdk/target/lib/${IDF_TARGET}/lib${LIBBLE}.a) 43 | target_link_libraries(${COMPONENT_LIB} INTERFACE ${LIBBLE}) 44 | set_property(TARGET ${LIBBLE} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${COMPONENT_LIB}) 45 | endif() 46 | 47 | set(LIBS joylink) 48 | add_library(${LIBS} STATIC IMPORTED) 49 | set_property(TARGET ${LIBS} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/${JOYLINK_SDK_DIR}/joylink/lib/${IDF_TARGET}/lib${LIBS}.a) 50 | target_link_libraries(${COMPONENT_LIB} INTERFACE ${LIBS}) 51 | set_property(TARGET ${LIBS} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${COMPONENT_LIB}) 52 | target_compile_definitions(${COMPONENT_LIB} PUBLIC -D __LINUX_PAL__=1) 53 | 54 | component_compile_options(-D__LINUX_UB2__ -D__LINUX__ -DJLdevice_aes_decrypt=device_aes_decrypt -D_GET_HOST_BY_NAME_ -Wno-error=unused-label -Wno-error=maybe-uninitialized -Wno-error=implicit-function-declaration -Wno-error=pointer-sign -Wno-error=char-subscripts -Wno-error=sizeof-pointer-memaccess -Wno-error=format -Wno-error=return-type -lpthread) -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | menu "Joylink" 2 | 3 | menu "Joylink_light" 4 | config JOYLINK_LIGHT_R 5 | default "25" 6 | int "the GPIO of light_Red" 7 | 8 | config JOYLINK_LIGHT_G 9 | default "26" 10 | int "the GPIO of light_green" 11 | 12 | config JOYLINK_LIGHT_B 13 | default "27" 14 | int "the GPIO of light_blue" 15 | endmenu 16 | 17 | config JOYLINK_DEVICE_UUID 18 | default "972212" 19 | string "The device uuid, you can get it from Joylink" 20 | 21 | config JOYLINK_PUBLIC_KEY 22 | default "035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C" 23 | string "The public key, you can get it from JD" 24 | 25 | config JOYLINK_DEVICE_MAC 26 | default "240AAEEBCF20" 27 | string "DEVICE MAC" 28 | 29 | config JOYLINK_PRIVATE_KEY 30 | default "6F5111A86101EECCCF6CB791FDD447E6DBC953F73E30D4BB3826527C4BBF50F3" 31 | string "The private key, you can get it from JD" 32 | 33 | config JOYLINK_DEVICE_BRAND 34 | default "549" 35 | string "The brand of the product,you can get it from JD" 36 | 37 | config JOYLINK_DEVICE_CID 38 | default "102009" 39 | string "The category of the product,you can get it from JD" 40 | 41 | config JOYLINK_SOFTAP_ENABLE 42 | bool "Enabe Joylink softap configure wifi" 43 | default y 44 | 45 | config JOYLINK_SOFTAP_SSID 46 | default "JDDeng9141" 47 | string "The SoftAP SSID" 48 | depends on JOYLINK_SOFTAP_ENABLE 49 | 50 | config JOYLINK_BLE_ENABLE 51 | bool "Whether or not use Joylink ble configure wifi" 52 | default n 53 | depends on (IDF_TARGET_ESP32 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3) 54 | endmenu 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 章节介绍: 2 | 3 | * **1. 概述:** 介绍背景。 4 | * **2. Demo 使用:** 介绍 Demo 如何跑起来。包括环境搭建,编译下载,设备控制。 5 | * **3. 开发指南:** 介绍 Demo 如何二次开发。包括文件结构,功能介绍,API介绍,资源占用。 6 | * **4. 相关链接:** 给出与 joylink 相关的链接。包括 Demo 下载,微联文档。 7 | 8 | ## 1. 概述 9 | ESP 平台实现了京东微联 Joylink2.1.22 协议。用户可以参考 Espressif 提供的设备端 Demo 进行二次开发,快速接入京东微联云平台。 10 | 11 | Demo 参考京东官方 [Joylink2.1.22 SDK](https://smartdev.jd.com/docCenterDownload/list/2),添加了 WiFi 相关、OTA、Flash 存储等适配层,用户只需要关心少部分 API,如初始化、数据收发、事件回调等,加快了用户的二次开发速度。适配层具有一定的通用性且开源,用户可根据产品需求自行修改。 12 | Demo 使用的通讯方式为非透传模式。非透传模式下需要在开发者中心上传空实现的 lua 脚本: `only_trans.lua`。 13 | 14 | 目前京东微联已经停止支持 SmartConfig 的配网方式,所以 Demo 中删除 SmartConfig 配网,目前支持 SoftAp 和 Thunder 配网,芯片上电默认进入 SoftAP 配网,如果用户需要使用 Thunder 配网,需要购买京东的音箱,音箱需要进入沙箱模式,与音箱相关的设置,用户可以咨询京东。 15 | 16 | ## 2. Demo 使用 17 | 用户拿到乐鑫提供的 esp-joylink 后,根据不同的 example 编译下载固件到乐鑫 ESP8266 、 ESP32 或者 ESP32-S 系列和 ESP32-C 系列开发板或模组。使用京东微联 APP 扫描测试设备的二维码进行配置。配置激活成功后便可进行设备控制。此 Demo 对应的测试设备类型为“智能家居 / 生活电器 / 灯具”。 18 | 19 | ### 2.1. 环境搭建 20 | 21 | * 环境准备 22 | * **ESP32**:[开发环境准备](https://docs.espressif.com/projects/esp-idf/en/stable/get-started/) 23 | * **ESP32-S2**:[开发环境准备](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html) 24 | * **ESP8266**:[开发环境准备](https://github.com/espressif/ESP8266_RTOS_SDK/blob/release/v3.0/docs/en/get-started/get-started-devkitc.rst) 25 | * **ESP32-S3**:[开发环境准备](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/get-started/index.html) 26 | * **ESP32-C3**:[开发环境准备](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html) 27 | 28 | * 硬件准备 29 | * **开发板**:ESP8266 、ESP32、ESP32-S 系列或 ESP32-C 系列开发板 30 | * **路由器**:使用 2.4GHz 网络,可以连接外网 31 | * **手机**:安装[京东微联沙箱 APP](https://smartdev.jd.com/docCenterDownload/list/2) 32 | 33 | * 软件准备 34 | 35 | * **Demo下载**:下载 Demo 工程 [esp-joylink](https://github.com/espressif/esp-joylink.git) 36 | 37 | * Demo 的网络拓扑结构 38 | 39 | i2c hardware 40 | 41 | ### 2.2 编译下载 42 | 43 | * 工程编译 44 | 首先设置 `IDF_PATH` 的路径,并使用对应芯片支持的 esp-idf 版本进行下一步配置 45 | 46 | | Chip | v4.2 | v4.3 | v4.4 | 47 | | -------- | --------- | --------- | --------- | 48 | | ESP32 | supported | supported | supported | 49 | | ESP32-S2 | supported | supported | supported | 50 | | ESP32-C3 | | supported | supported | 51 | | ESP32-S3 | | | supported | 52 | 53 | 对于 ESP8266 & ESP8285 芯片,支持使用 ESP8266_RTOS_SDK v3.3 或 v3.4 版本。 54 | 55 | 然后在 menuconfig 里面配置 joylink 相关参数 `UUID`,`CID`,`PID`, `PUBLIC_KEY`,`PRIVATE_KEY`,`MAC_ADDRESS`,其中 `UUID`、`CID` 和 `PID` 分别代表产品的唯一标识码、品类和品牌,在云端产品中的位置如下 56 | 57 | i2c hardware 58 | 59 | `PUBLIC_KEY ` 为产品公钥,显示在设备端开发页面,设备认证采用一机一密的方式 ,用户需导入 `MAC_ADDRESS` (设备 MAC 地址) 来生成 `PRIVATE_KEY` (设备私钥) ,具体生成方式请在设备端开发页面点击 “导入 MAC 地址生成私钥” 选项并按提示进行。 60 | 61 | i2c hardware 62 | 63 | 以light_demo为例,我们提供了默认的sdkconfig.defaults及partiton table文件(light_demo/default_configs目录下),用户可根据芯片不同,进行使用和参考。 64 | 65 | 进入example/light_demo目录,然后输入命令 `$IDF_PATH/tools/idf.py build`, 编译工程。对于 ESP32-S2 平台,执行 `build` 命令之前应先执行`$IDF_PATH/tools/idf.py set-target esp32s2 ` 命令,切换为 ESP32-S2 的编译环境,之后再 `$IDF_PATH/tools/idf.py build` 编译工程。同样对于 ESP32-S3 和 ESP32-C3 平台,也需要在执行 `build` 命令之前执行 ESP32-S2 平台相类似的命令。 66 | 67 | (如果使用 ESP8266_RTOS_SDK v3.2,请使用 `make` 命令进行编译工程) 68 | 69 | * 固件烧写 70 | 1. 如果没有安装串口驱动,需要先安装[串口驱动](http://www.usb-drivers.org/ft232r-usb-uart-driver.html)。 71 | 2. 输入命令 `$IDF_PATH/tools/idf.py -p PORT flash` (ESP8266_RTOS_SDK v3.2 使用 `make flash ESPPORT=PORT` ) ,将编译好的 bin 文件烧录到开发板中,`PORT` 选择和配置请参考[文档说明](https://docs.espressif.com/projects/esp-idf/en/stable/get-started/index.html#step-6-connect-your-device)。 72 | 73 | 对于ESP32、ESP32-S3 和 ESP32-C3 平台,Demo中包含两种配网方式: SoftAP 配网和 BLE 配网,可在 menuconfig 的 joylink 组件配置中进行选择切换,默认是使用SoftAP 配网 74 | 75 | i2c hardware 76 | 77 | 若切换 BLE 配网,首先需使能 `Whether or not use Joylink ble configure wifi` 选项,然后要在云端产品的基本信息页面中选择 "京东BLE配网" 并保存,最后重新编译和烧写后方可使用。 78 | 79 | i2c hardware 80 | 81 | ## 3. 开发指南 82 | 本章详细介绍 Demo 工程,如需二次开发请关注本章。 83 | 用户需要调用的 API 和参数配置相关的头文件在 `port/include/esp_joylink.h` 中。 84 | 85 | ### 3.1 文件结构 86 | 87 | . 88 | ├── CMakeLists.txt 89 | ├── component.mk 90 | ├── docs 91 | │   ├── md // md files 92 | │   │   └── 量产说明.md 93 | │   └── _picture 94 | │ 95 | ├── config 96 | │   └── mass_mfg 97 | │   ├── multipule_mfg_config.csv 98 | │     ├── multipule_mfg_values.csv 99 | │   └── single_mfg_config.csv 100 | │   101 | ├── examples 102 | │   ├── light_demo // light_demo 103 | │   │   ├── CMakeLists.txt 104 | │   │   ├── components 105 | │   │   ├── default_configs // default sdkconfigs 106 | │   │   ├── main 107 | │   │   ├── README.md 108 | │   │   └── Makefile 109 | │   └── transparent_transmission 110 | │   111 | ├── joylink_dev_sdk // joylink SDK source code 112 | │   ├── ble_sdk 113 | │   ├── example 114 | │   ├── joylink 115 | │   ├── lua 116 | │   ├── Makefile 117 | │   ├── pal 118 | │   ├── README 119 | │   └── scripts 120 | │   121 | ├── Kconfig 122 | ├── port // joylink SDK adaptation 123 | │   ├── include 124 | │   ├── joylink_ble.c 125 | │   └── joylink_upgrade.c 126 | │ 127 | └── README.md 128 | 129 | 130 | ### 3.2 参数配置 131 | 132 | * 产品信息配置 133 | 在 `memuconfig` 中, 用户可以修改以下这些参数,如 AES_KEY, UUID, PID等,系统会调用 `joylink_dev_init()` 传入产品注册的信息,注册事件回调函数。用户如果需要修改为自己的设备,首先需要在京东开发者中心上申请自己的设备,并根据相应设备信息在此处修改。 134 | 因为这些参数需要在服务器后台产品基本信息里获取,或者向京东有关部门咨询。 135 | 136 | ### 3.3 配网 137 | 京东配网方式目前主推 SoftAP(自主激活), Demo 中同时支持 SoftAP(自主激活+代理激活)、Thunder 配网, 默认设置是进入 SoftAP 自主激活, 如果需要代理激活,可以在 Makefile 中将自主激活的宏关闭。 138 | 139 | i2c hardware 140 | 141 | ### 3.4 固件升级 142 | 实现固件升级需要上传新的固件到服务器后台。并填写正确的版本信息。 143 | **注意**: 厂商必须严格按照固定格式填写版本号,如(1.1.1.20151020_release)。 144 | 如下图,后台设置在线升级界面。序号是上传 bin 文件后自动生成的。设备端上传的 version 如果与这个版本号不同, APP 会自动推送 OTA 的提示。 145 | 146 | i2c hardware 147 | 148 | ### 3.5量产功能 149 | 150 | 每台设备对应唯一的UUID、DeviceMAC、PrivateKey,用户除了可以在`menuconfig`配置相关参数信息,也可以通过烧录NVS分区的方式进行量产。 151 | 152 | 具体请参考[量产说明](docs/md/量产说明.md) 153 | 154 | >如果执行了`idf.py erase_flash`, 需要重新烧录三元组 155 | 156 | ## 4. 相关链接 157 | 158 | * Espressif 官网: http://espressif.com 159 | * ESP32 SDK 下载: https://github.com/espressif/esp-idf 160 | * ESP8266 SDK 下载: https://github.com/espressif/ESP8266_RTOS_SDK 161 | * 烧录工具:http://espressif.com/en/support/download/other-tools 162 | * 京东微联官网:https://smartcloud.jd.com 163 | * 官方JoyLink协议SDK: https://storage.jd.com/testsmartcloud/joylink_dev_sdk.zip 164 | * 设备入网的协议文档: https://storage.jd.com/testsmartcloud/JoylinkConfigDoc.zip 165 | -------------------------------------------------------------------------------- /component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # component Makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | JOYLINK_SDK_DIR ?= joylink_dev_sdk 7 | 8 | JOYLINK_LIB = $(JOYLINK_SDK_DIR)/joylink 9 | JOYLINK_PAL = $(JOYLINK_SDK_DIR)/pal 10 | JOYLINK_PORT ?= port 11 | JOYLINK_BLE ?= $(JOYLINK_SDK_DIR)/ble_sdk 12 | 13 | JOYLINK_LIB_INCLUDEDIRS = inc inc/json inc/softap 14 | COMPONENT_ADD_INCLUDEDIRS += $(addprefix $(JOYLINK_LIB)/,$(JOYLINK_LIB_INCLUDEDIRS)) 15 | 16 | JOYLINK_PAL_INCLUDEDIRS = inc 17 | JOYLINK_PAL_SRCDIRS = src 18 | 19 | COMPONENT_ADD_INCLUDEDIRS += $(addprefix $(JOYLINK_PAL)/,$(JOYLINK_PAL_INCLUDEDIRS)) 20 | COMPONENT_SRCDIRS += $(addprefix $(JOYLINK_PAL)/,$(JOYLINK_PAL_SRCDIRS)) 21 | 22 | JOYLINK_PORT_INCLUDEDIRS = include 23 | COMPONENT_ADD_INCLUDEDIRS += $(addprefix $(JOYLINK_PORT)/,$(JOYLINK_PORT_INCLUDEDIRS)) 24 | 25 | COMPONENT_DEPENDS = joylink_extern 26 | 27 | ifeq ($(strip $(CONFIG_JOYLINK_BLE_ENABLE)), y) 28 | JOYLINK_BLE_INCLUDEDIRS = include 29 | JOYLINK_BLE_SRCDIRS = adapter 30 | COMPONENT_ADD_INCLUDEDIRS += $(addprefix $(JOYLINK_BLE)/,$(JOYLINK_BLE_INCLUDEDIRS)) 31 | COMPONENT_SRCDIRS += $(addprefix $(JOYLINK_BLE)/,$(JOYLINK_BLE_SRCDIRS)) 32 | endif 33 | 34 | COMPONENT_SRCDIRS += ${JOYLINK_PORT} 35 | 36 | LIBS = joylink 37 | 38 | ifeq ($(strip $(CONFIG_IDF_TARGET_ESP8266)), y) 39 | CONFIG_IDF_TARGET ?= esp8266 40 | endif 41 | 42 | COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/$(JOYLINK_SDK_DIR)/joylink/lib/${CONFIG_IDF_TARGET} \ 43 | $(addprefix -l,$(LIBS)) 44 | 45 | ifeq ($(strip $(CONFIG_JOYLINK_BLE_ENABLE)), y) 46 | LIBS += joylinkblesdk 47 | COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/$(JOYLINK_SDK_DIR)/ble_sdk/target/lib/${CONFIG_IDF_TARGET} \ 48 | $(addprefix -l,$(LIBS)) 49 | endif 50 | 51 | CFLAGS += -D__LINUX_PAL__ -Wno-error=maybe-uninitialized -Wno-error=return-type -------------------------------------------------------------------------------- /config/mass_mfg/multipule_mfg_config.csv: -------------------------------------------------------------------------------- 1 | joylink-key,namespace, 2 | UUID,data,string 3 | DeviceMAC,data,string 4 | PrivateKey,data,string 5 | PublicKey,data,string -------------------------------------------------------------------------------- /config/mass_mfg/multipule_mfg_values.csv: -------------------------------------------------------------------------------- 1 | id,UUID,DeviceMAC,PrivateKey,PublicKey 2 | 1,972212,240AAEEBCF18,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C 3 | 2,972212,240AAEEBCF18,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C 4 | 3,972212,240AAEEBCF18,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C -------------------------------------------------------------------------------- /config/mass_mfg/single_mfg_config.csv: -------------------------------------------------------------------------------- 1 | key,type,encoding,value 2 | joylink-key,namespace,, 3 | UUID,data,string,972212 4 | DeviceMAC,data,string,240AAEEBCF18 5 | PrivateKey,data,string,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089 6 | PublicKey,data,string,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C -------------------------------------------------------------------------------- /docs/_picture/Demo二维码.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/Demo二维码.jpg -------------------------------------------------------------------------------- /docs/_picture/UUID、CID和PID.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/UUID、CID和PID.jpg -------------------------------------------------------------------------------- /docs/_picture/ota_后台版本设置.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/ota_后台版本设置.png -------------------------------------------------------------------------------- /docs/_picture/使能BLE.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/使能BLE.jpg -------------------------------------------------------------------------------- /docs/_picture/公钥、私钥和MAC.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/公钥、私钥和MAC.jpg -------------------------------------------------------------------------------- /docs/_picture/微联APP-配网界面.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/微联APP-配网界面.jpg -------------------------------------------------------------------------------- /docs/_picture/环境搭建.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/环境搭建.jpg -------------------------------------------------------------------------------- /docs/_picture/配网方式后台配置界面.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/配网方式后台配置界面.jpg -------------------------------------------------------------------------------- /docs/_picture/配网选择.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/docs/_picture/配网选择.jpg -------------------------------------------------------------------------------- /docs/md/量产说明.md: -------------------------------------------------------------------------------- 1 | # 量产说明 2 | 3 | joylink 在使用一机一密的情况下,需要在每个设备上烧写与设备对应的 UUID、DeviceMAC、PrivateKey、PublicKey。 4 | 5 | 为了使烧录和软件读取流程尽量简化,我们将使用 IDF 的 NVS 分区功能,将 UUID、DeviceMAC、PrivateKey、PublicKey 信息通过 **NVS 分区生成工具**或**量产工具**生成对应的 NVS 分区,该分区中利用 NVS 结构保存了 UUID、DeviceMAC、PrivateKey、PublicKey 的键值对。生成后的 NVS 分区 bin 可以通过 esptool 或其他烧写工具直接烧录到 NVS 分区对应的起始扇区,partition 分区表中指明了该 NVS 分区的起始地址。软件可以通过 NVS 相关接口读取到 UUID、DeviceMAC、PrivateKey、PublicKey 的具体值。 6 | 7 | 请参照`default_configs`文件夹中不同芯片分区表的 mfg_nvs 起始地址进行烧录,也可根据实际项目对 partitions 进行调整,但一定要保证 partitons 中 mfg_nvs 的实际地址与烧录地址保持吻合。 8 | 9 | 关于 NVS、NVS 分区生成工具、量产工具,请参考: 10 | 11 | - [NVS](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html) 12 | - [NVS 分区生成工具](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_partition_gen.html) 13 | - [量产工具](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/mass_mfg.html) 14 | 15 | ## 单个 bin 生成 16 | 17 | 在调试过程中,建议使用该方式。 18 | 19 | mass_mfg 目录中有一参考配置:single_mfg_config.csv,请拷贝成自己的配置文件,如 my_single_mfg_config.csv。 20 | 21 | ``` 22 | cp single_mfg_config.csv my_single_mfg_config.csv 23 | ``` 24 | 25 | 使用自己的 UUID、DeviceMAC、PrivateKey、PublicKey 对 my_single_mfg_config.csv 进行修改: 26 | 27 | ``` 28 | key,type,encoding,value 29 | joylink-key,namespace,, 30 | UUID,data,string,972212 31 | DeviceMAC,data,string,240AAEEBCF18 32 | PrivateKey,data,string,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089 33 | PublicKey,data,string,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C 34 | ``` 35 | 36 | 将 972212,240AAEEBCF18,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C修改为你对应的值。 37 | 38 | 修改完成后,使用如下命令生成对应的 NVS 分区: 39 | 40 | ``` 41 | $IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py generate my_single_mfg_config.csv my_single_mfg.bin 0x4000 42 | ``` 43 | 44 | 如针对 esp8266 平台,请使用如下命令: 45 | 46 | ``` 47 | $IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py --input my_single_mfg_config.csv --output my_single_mfg.bin --size 0x4000 48 | ``` 49 | 50 | > 说明:esp8266 的 NVS 格式当前为 v1, 默认已设置。 51 | 52 | 可以使用 esptool 工具将生成的包含秘钥的 NVS 分区烧入对应的 sector,针对 example 中默认提供的 partitions,esp32、esp32S2 和 esp8266 将烧写到不同的分区,其中 esp32、esp32S2 的默认烧录地址为 0x340000,esp8266 的默认烧录地址为 0x100000。 53 | 54 | 针对 esp32、esp32S2: 55 | 56 | ``` 57 | $IDF_PATH/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 write_flash 0x340000 my_single_mfg.bin 58 | ``` 59 | 60 | 针对 esp8266: 61 | 62 | ``` 63 | $IDF_PATH/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 write_flash 0x100000 my_single_mfg.bin 64 | ``` 65 | 66 | > 注,当前 esp32 默认使用 4MB 的模组,esp8266 默认使用 2MB 的模组,如使用其他大小的 Flash,请适当调整 partitions 分区表,并确认烧写地址。 67 | 68 | ## 多个 bin 批量生成 69 | 70 | 量产过程中如采用以上方法单个生成对应的 NVS 分区会很繁琐,因此采用 IDF 中的量产工具,该量产工具也是基于 NVS 分区生成工具的扩充。 71 | 72 | mass_mfg 目录中提供了一套参考的配置,其中 multipule_mfg_config.csv 为参数区配置文件,已做好针对 joylink的配置,用户无需修改,multipule_mfg_values.csv 中可以包含所有需要生成 NVS 分区的 UUID、DeviceMAC、PrivateKey、PublicKey 信息,请将 multipule_mfg_values.csv 复制为 my_multipule_mfg_values.csv 并对该文件进行修改,包含所有希望用于量产的 UUID、DeviceMAC、PrivateKey、PublicKey 信息。 73 | 74 | my_multipule_mfg_values.csv 中内容如下: 75 | 76 | ``` 77 | id,UUID,DeviceMAC,PrivateKey,PublicKey 78 | 1,972212,240AAEEBCF18,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C 79 | 2,972212,240AAEEBCF18,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C 80 | 3,972212,240AAEEBCF18,B1120284273A1686E9B518FA49248CFA65C8D229581BB075860EFD895829C089,035CAF2E8DDD4B5667DD2199E3809615BA84E5D8FDDE7B5F9A3310D476EC52ED7C 81 | ``` 82 | 83 | 每一行代表了一组秘钥信息,第一列的为 id 信息,不会生成到对应的 NVS 分区中,仅用作标号。 84 | 85 | 采用如下命令批量生成 NVS 分区。 86 | 87 | 88 | ``` 89 | $IDF_PATH/tools/mass_mfg/mfg_gen.py generate multipule_mfg_config.csv my_multipule_mfg_values.csv espressif 0x4000 90 | ``` 91 | 92 | >multipule_mfg_config.csv --conf(Path to configuration csv file to parse) 93 | > 94 | >my_multipule_mfg_values.csv --values(Path to values csv file to parse) 95 | > 96 | >espressif --prefix(Unique name for each output filename prefix) 97 | > 98 | >0x4000 --size(Size of NVS partition in bytes) 99 | 100 | 执行完成后,会在当前目录下生成一 bin 目录,里面保持了所有可用于量产的 NVS 分区 bin。 101 | 对于 ESP32、ESP32S2,执行上述命令可以顺利完成量产 bin 的操作,但是如果您使用 ESP8266,执行量产操作时要先切换至 ESP-IDF 环境,否则上述命令会执行失败,执行完生成 bin 目录之后,可将环境切换至 ESP8266_RTOS_SDK。 102 | 103 | ESP32S3 和 ESP32C3 也支持量产 bin 的烧录,操作方法同 ESP32S2。 -------------------------------------------------------------------------------- /examples/light_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 2 | 3 | # The following lines of boilerplate have to be in your project's CMakeLists 4 | # in this exact order for cmake to work correctly 5 | cmake_minimum_required(VERSION 3.5) 6 | 7 | execute_process(COMMAND git rev-parse --short HEAD 8 | OUTPUT_VARIABLE ESP_JOYLINK_VER 9 | OUTPUT_STRIP_TRAILING_WHITESPACE) 10 | add_compile_options("-DESP_JOYLINK_COMMIT_ID=\"${ESP_JOYLINK_VER}\"") 11 | 12 | if (NOT DEFINED ESP_JOYLINK_DIR) 13 | if (NOT DEFINED ENV{ESP_JOYLINK_DIR}) 14 | set (ESP_JOYLINK_DIR "../..") 15 | else() 16 | set (ESP_JOYLINK_DIR $ENV{ESP_JOYLINK_DIR}) 17 | endif() 18 | endif() 19 | 20 | set (EXTRA_COMPONENT_DIRS ${ESP_JOYLINK_DIR}) 21 | 22 | if(EXISTS "$ENV{IDF_PATH}/components/esp8266") 23 | set(IDF_TARGET "esp8266") 24 | else() 25 | if(NOT DEFINED IDF_TARGET) 26 | set(IDF_TARGET "esp32") 27 | endif() 28 | endif() 29 | 30 | if(NOT DEFINED SDKCONFIG_DEFAULTS) 31 | set(SDKCONFIG_DEFAULTS ${CMAKE_CURRENT_LIST_DIR}/default_configs/${IDF_TARGET}/sdkconfig.defaults) 32 | endif() 33 | 34 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 35 | project(esp-joylink) 36 | -------------------------------------------------------------------------------- /examples/light_demo/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := esp-joylink 7 | 8 | ESP_JOYLINK_VER := $(shell git rev-parse --short HEAD) 9 | 10 | CFLAGS += -DESP_JOYLINK_COMMIT_ID=\"$(ESP_JOYLINK_VER)\" 11 | 12 | 13 | ifeq ($(ESP_JOYLINK_DIR), ) 14 | ESP_JOYLINK_DIR := $(realpath ../..) 15 | endif 16 | 17 | EXTRA_COMPONENT_DIRS += $(ESP_JOYLINK_DIR) 18 | 19 | ifneq (,$(wildcard $(IDF_PATH)/components/esp8266/*)) 20 | export IDF_TARGET = esp8266 21 | else 22 | ifndef IDF_TARGET 23 | export IDF_TARGET := esp32 24 | endif 25 | endif 26 | 27 | SDKCONFIG_DEFAULTS ?= $(realpath .)/default_configs/$(IDF_TARGET)/sdkconfig.defaults 28 | 29 | include $(IDF_PATH)/make/project.mk 30 | -------------------------------------------------------------------------------- /examples/light_demo/README.md: -------------------------------------------------------------------------------- 1 | # Light Demo of Joylink 2 | 3 | ## 一、介绍 4 | 5 | `light demo`为客户提供一种简易的智能灯解决方案,客户可根据自己的需要进行二次开发,实现更加更加丰富的控制操作。 6 | 7 | ## 二、解决方案部署 8 | 9 | **1.参考[README](../../README.md)文档进行硬件准备、环境搭建、SDK 准备** 10 | 11 | **2.烧录三元组信息** 12 | 13 | - 调试使用可通过menuconfig录入`UUID`、`PRIVATE_KEY`、`MAC_ADDRESS`等信息 14 | - 量产使用请参考 [量产说明](../../docs/md/量产说明) 文档烧录三元组 NVS 分区. 15 | 16 | > 如果执行了 `make erase_flash`, 需要重新烧录三元组. 17 | 18 | **3.配置 `Light Demo`** 19 | 20 | - ESP32 开发板:RGB 灯默认分别接在 `GPIO25`, `GPIO26`, `GPIO27` 21 | - ESP32S2 和 ESP32S3 开发板:RGB 灯默认分别接在 `GPIO15`, `GPIO16`, `GPIO17` 22 | - ESP8266 开发板:RGB 灯默认分别接在 `GPIO4`, `GPIO5`, `GPIO15` 23 | - ESP32C3 开发板:RGB 灯默认分别接在 `GPIO5`, `GPIO6`, `GPIO7` 24 | 25 | >GPIO可通过menuconfig中`Joylink->light_red、light_green、light_blue`进行个性化配置 26 | 27 | **4.编译`light_demo`并烧录运行** 28 | 29 | 对于 ESP32 平台,请输入如下命令进行编译烧录 30 | 31 | ``` 32 | cd examples/light_demo 33 | idf.py build 34 | idf.py -p /dev/ttyUSBx flash monitor 35 | ``` 36 | 37 | 对于 ESP32S2 平台,请使用如下命令进行编译烧录 38 | 39 | ``` 40 | cd examples/light_demo 41 | idf.py set-target esp32s2 42 | idf.py build 43 | idf.py -p /dev/ttyUSBx flash monitor 44 | ``` 45 | 46 | 对于 ESP32S3 平台,请使用如下命令进行编译烧录 47 | 48 | ``` 49 | cd examples/light_demo 50 | idf.py set-target esp32s3 51 | idf.py build 52 | idf.py -p /dev/ttyUSBx flash monitor 53 | ``` 54 | 55 | 对于 ESP32C3 平台,请使用如下命令进行编译烧录 56 | 57 | ``` 58 | cd examples/light_demo 59 | idf.py set-target esp32c3 60 | idf.py build 61 | idf.py -p /dev/ttyUSBx flash monitor 62 | ``` 63 | 64 | 对于 ESP8266 平台,请使用如下命令进行编译烧录 65 | 66 | ``` 67 | cd examples/light_demo 68 | make -j8 flash monitor 69 | ``` 70 | 71 | >ESP32平台也可使用make指令,但在将来的esp-idf主要版本中,可能会删除对GNU Make构建系统的支持。 72 | 73 | ## 三、运行 74 | 75 | * 扫描二维码 76 | 77 | i2c hardware 78 | 79 | * 配网界面 80 | 81 | i2c hardware 82 | 83 | * 选择合适的AP进行配网(乐鑫设备仅支持 2.4G AP) 84 | 85 | * 等待建立连接 86 | 87 | >若连接过程中app未发现设备的softAP,则可根据提示进行手动连接至设备的softAP 88 | 89 | * 连接服务器成功后用户设备列表中会出现该智能灯设备 90 | 91 | 92 | * 用户可通过点击开关以及氛围灯对智能灯设备进行控制 93 | 94 | > 开启设备显示白色灯光 95 | > 96 | > 开启氛围灯显示紫色灯光 97 | 98 | ## 四、二次开发 99 | 100 | * 用户可通过修改joylink_light.c文件实现更加个性化的智能灯控制 101 | 102 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS ".") 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES esp-joylink nvs_flash app_update esp-tls tcpip_adapter json) 6 | 7 | file(GLOB_RECURSE srcs *.c) 8 | 9 | set(COMPONENT_SRCS ${srcs}) 10 | 11 | register_component() 12 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # component Makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | COMPONENT_ADD_INCLUDEDIRS += ./ -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_dev.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_DEV_H_ 2 | #define _JOYLINK_DEV_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif /* __cplusplus */ 7 | 8 | #include "joylink.h" 9 | 10 | #define LIGHT_CMD_NONE (-1) 11 | #define LIGHT_CMD_POWER (1) 12 | 13 | #define LIGHT_CTRL_NONE (-1) 14 | #define LIGHT_CTRL_ON (1) 15 | #define LIGHT_CTRL_OFF (0) 16 | 17 | typedef struct __light_ctrl{ 18 | char cmd; 19 | int para_power; 20 | int para_state; 21 | int para_look; 22 | int para_move; 23 | }LightCtrl_t; 24 | typedef struct _light_manage_{ 25 | int conn_st; 26 | JLPInfo_t jlp; 27 | jl2_d_idt_t idt; 28 | LightCtrl_t lightCtrl; 29 | }LightManage_t; 30 | 31 | typedef struct _jl_http_t{ 32 | char *url; 33 | char *header; 34 | char *body; 35 | char *response; 36 | int32_t resp_len; 37 | }jl_http_t; 38 | 39 | #define SET_HTTP_RECV_MAX_LEN 64 40 | 41 | /** 42 | * @name:实现HTTPS的POST请求,请求响应填入revbuf参数 43 | * 44 | * @param[in]: url POST请求的链接和路径 45 | * @param[in]: header POST请求的HEADER 46 | * @param[in]: body POST请求的Payload 47 | * @param[out]: revbuf 填入请求的响应信息 48 | * 49 | * @returns: NULL - 发生错误, 其它 - 请求返回的数据 ,使用完毕内存需要释放 50 | * 51 | * @note:此函数必须正确实现,否则设备无法激活绑定 52 | * @note:小京鱼平台HTTPS使用的证书每年都会更新. 53 | * @note:因为Joylink协议层面有双向认证的安全机制,所以此HTTPS请求设备无需校验server的证书. 54 | * @note:如果设备必须校验server的证书,那么需要开发者实现时间同步等相关机制. 55 | */ 56 | int32_t jl_platform_https_request(jl_http_t *info); 57 | 58 | /** 59 | * @name:实现HTTP的POST请求,请求响应填入revbuf参数 60 | * 61 | * @param[in]: url POST请求的链接和路径 62 | * @param[in]: header POST请求的HEADER 63 | * @param[in]: body POST请求的Payload 64 | * @param[out]: revbuf 填入请求的响应信息 65 | * 66 | * @returns: NULL - 发生错误, 其它 - 请求返回的数据 ,使用完毕内存需要释放 67 | */ 68 | int32_t jl_platform_http_request(jl_http_t *info); 69 | 70 | /** 71 | * @brief: 返回是否可以访问互联网 72 | * 73 | * @returns: E_RET_TRUE 可以访问, E_RET_FALSE 不可访问 74 | */ 75 | E_JLBOOL_t joylink_dev_is_net_ok(); 76 | 77 | /** 78 | * @brief: 此函数用作通知应用层设备与云端的连接状态. 79 | * 80 | * @param: st - 当前连接状态 0-Socket init, 1-Authentication, 2-Heartbeat 81 | * 82 | * @returns: 83 | */ 84 | E_JLRetCode_t joylink_dev_set_connect_st(int st); 85 | 86 | /** 87 | * @brief: 存储JLP(Joylink Parameters)信息,将入参jlp结构中的信息持久化存储,如文件、设备flash等方式 88 | * 89 | * @param [in]: jlp-JLP structure pointer 90 | * 91 | * @returns: 92 | */ 93 | E_JLRetCode_t joylink_dev_set_attr_jlp(JLPInfo_t *jlp); 94 | 95 | /** 96 | * @brief: 从永久存储介质(文件或flash)中读取jlp信息,并赋值给参数jlp,其中feedid, accesskey,localkey,joylink_server,server_port必须正确赋值 97 | * 98 | * @param[out] jlp: 将JLP(Joylink Parameters)读入内存,并赋值给该参数 99 | * 100 | * @returns: E_RET_OK:成功, E_RET_ERROR:发生错误 101 | */ 102 | E_JLRetCode_t joylink_dev_get_jlp_info(JLPInfo_t *jlp); 103 | 104 | /** 105 | * @brief: 获取设备快照json结构 106 | * 107 | * @param[out] out_snap: 序列化为字符串的设备快照json结构 108 | * @param[in] out_max: out_snap可写入的最大长度 109 | * 110 | * @returns: 实际写入out_snap的数据长度 111 | */ 112 | int joylink_dev_get_snap_shot(char *out_snap, int32_t out_max); 113 | 114 | /** 115 | * @brief: 获取向App返回的设备快照json结构 116 | * 117 | * @param[out] out_snap: 序列化为字符串的设备快照json结构 118 | * @param[in] out_max: out_snap允许写入的最大长度 119 | * @param[in] code: 返回状态码 120 | * @param[in] feedid: 设备的feedid 121 | * 122 | * @returns: 123 | */ 124 | int joylink_dev_get_json_snap_shot(char *out_snap, int32_t out_max, int code, char *feedid); 125 | 126 | /** 127 | * @brief: 通过App控制设备,需要实现此函数,根据传入的json_cmd对设备进行控制 128 | * 129 | * @param[in] json_cmd: 设备控制命令 130 | * 131 | * @returns: E_RET_OK 控制成功, E_RET_ERROR 发生错误 132 | */ 133 | E_JLRetCode_t joylink_dev_lan_json_ctrl(const char *json_cmd); 134 | 135 | /** 136 | * @brief:根据src参数传入的控制命令数据包对设备进行控制.调用joylink_dev_parse_ctrl进行控制命令解析,并更改设备属性值 137 | * 138 | * @param[in] src: 控制指令数据包 139 | * @param[in] src_len: src长度 140 | * @param[in] ctr: 控制码 141 | * @param[in] from_server: 是否来自server控制 0-App,2-Server 142 | * 143 | * @returns: E_RET_OK 成功, E_RET_ERROR 失败 144 | */ 145 | E_JLRetCode_t joylink_dev_script_ctrl(const char *src, int src_len, JLContrl_t *ctr, int from_server); 146 | 147 | /** 148 | * @brief:特殊场景使用,厨具,下发菜单。 149 | * 150 | * @param[in] src: 数据包 151 | * @param[in] src_len: src长度 152 | * 153 | * @returns: E_RET_OK 成功 154 | */ 155 | E_JLRetCode_t joylink_dev_download_menu(const char *src, int src_len); 156 | 157 | /** 158 | * @brief: 实现接收到ota命令和相关参数后的动作,可使用otaOrder提供的参数进行具体的OTA操作 159 | * 160 | * @param[in] otaOrder: OTA命令结构体 161 | * 162 | * @returns: E_RET_OK 成功, E_RET_ERROR 发生错误 163 | */ 164 | E_JLRetCode_t joylink_dev_ota(JLOtaOrder_t *otaOrder); 165 | 166 | /** 167 | * @brief: OTA执行状态上报,无需返回值 168 | */ 169 | void joylink_dev_ota_status_upload(); 170 | 171 | /** 172 | * @brief: 设置设备认证信息 173 | * 174 | * @param[out]: pidt--设备认证信息结构体指针,需填入必要信息sig,pub_key,f_sig,f_pub_key,cloud_pub_key 175 | * 176 | * @returns: 返回设置成功或失败 177 | */ 178 | E_JLRetCode_t joylink_dev_get_idt(jl2_d_idt_t *pidt); 179 | 180 | /** 181 | * @brief: 用以返回一个整型随机数 182 | * 183 | * @param: 无 184 | * 185 | * @returns: 整型随机数 186 | */ 187 | int joylink_dev_get_random(); 188 | 189 | /** 190 | * @brief: SDK main loop 运行状态报告,正常情况下此函数每5秒会被调用一次,可以用来判断SDK主任务的运行状态. 191 | * 192 | * @param[in] status: SDK main loop运行状态 0正常, -1异常 193 | * 194 | * @return: 195 | */ 196 | int joylink_dev_run_status(JLRunStatus_t status); 197 | 198 | /** 199 | * @brief: 每间隔1个main loop周期此函数将在SDK main loop中被调用,让用户有机会将代码逻辑运行在核心任务中. 200 | * 201 | * @note: 正常情况下一个main loop周期为1s(取决于socket等待接收数据的timeout时间),但不保证精度,请勿用作定时器 202 | * @note: 仅用作关键的非阻塞任务执行,例如OTA状态上报或设备状态上报. 203 | * @note: 执行阻塞或耗时较多的代码,将会妨碍主task运行. 204 | */ 205 | void joylink_dev_run_user_code(); 206 | 207 | #ifdef __cplusplus 208 | } 209 | #endif /* __cplusplus */ 210 | #endif 211 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_extern.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_EXTERN_H_ 2 | #define _JOYLINK_EXTERN_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif /* __cplusplus */ 7 | 8 | #include "joylink.h" 9 | #include "sdkconfig.h" 10 | 11 | #define JOYLINK_CLOUD_AUTH 12 | #define JOYLINK_DEVICE_AUTH 13 | 14 | #define JOYLINK_THUNDER_SLAVE 15 | #define JOYLINK_SMART_CONFIG 16 | 17 | /* 18 | * user set 19 | */ 20 | #define JLP_VERSION 1 21 | /* 22 | * Create dev and get the index from developer center 23 | */ 24 | 25 | #define JLP_DEV_TYPE E_JLDEV_TYPE_NORMAL 26 | #define JLP_LAN_CTRL E_LAN_CTRL_ENABLE 27 | #define JLP_CMD_TYPE E_CMD_TYPE_LUA_SCRIPT 28 | #define JLP_SNAPSHOT E_SNAPSHOT_NO 29 | 30 | #define MFG_PARTITION_NAME "mfg_nvs" 31 | #define NVS_PRODUCT "joylink-key" 32 | 33 | #define JLP_UUID CONFIG_JOYLINK_DEVICE_UUID 34 | #define JLP_CLOUD_PUB_KEY CONFIG_JOYLINK_PUBLIC_KEY 35 | #define JLP_PRIVATE_KEY CONFIG_JOYLINK_PRIVATE_KEY 36 | #define JLP_DEVICE_MAC CONFIG_JOYLINK_DEVICE_MAC 37 | 38 | #define USER_DATA_POWER "Power" 39 | #define USER_DATA_AMBIENTLIGHT "AmbientLight" 40 | typedef struct _user_dev_status_t { 41 | int Power; 42 | int AmbientLight; 43 | } user_dev_status_t; 44 | 45 | typedef enum _JL_OTA_UPGRADE_TYPE_E{ 46 | JL_OTA_UPGRADE_TYPE_PROMPT = 1, 47 | JL_OTA_UPGRADE_TYPE_SILENT = 2, 48 | JL_OTA_UPGRADE_TYPE_ENFORCE = 3 49 | }JL_OTA_UPGRADE_TYPE_E; 50 | 51 | typedef struct{ 52 | int serial; 53 | char feedid[JL_MAX_FEEDID_LEN]; 54 | char productuuid[JL_MAX_UUID_LEN]; 55 | int version; 56 | char versionname[JL_MAX_VERSION_NAME_LEN]; 57 | unsigned int crc32; 58 | char url[JL_MAX_URL_LEN]; 59 | JL_OTA_UPGRADE_TYPE_E upgradetype; 60 | }JLOtaOrder_t; 61 | 62 | /** 63 | * @brief: 设置设备RTC时间 64 | * 65 | * @returns: 66 | * 67 | * @note: This function has deprecated. Instead of using it you must implement the function jl_set_UTCtime which defined in pal/src/joylink_time.c 68 | */ 69 | E_JLBOOL_t joylink_dev_sync_clound_timestamp(long long timestamp); 70 | 71 | /** 72 | * @brief: 此函数需返回设备的MAC地址 73 | * 74 | * @param[out] out: 将设备MAC地址赋值给此参数 75 | * 76 | * @returns: E_RET_OK 成功, E_RET_ERROR 失败 77 | */ 78 | E_JLRetCode_t joylink_dev_get_user_mac(char *out); 79 | 80 | /** 81 | * @brief: 此函数需返回设备私钥private key,该私钥可从小京鱼后台获取 82 | * 83 | * @param[out] out: 将私钥字符串赋值给该参数返回 84 | * 85 | * @returns: E_RET_OK:成功, E_RET_ERROR:发生错误 86 | */ 87 | E_JLRetCode_t joylink_dev_get_private_key(char *out); 88 | 89 | /** 90 | * @brief: 根据传入的cmd值,设置对应设备属性 91 | * 92 | * @param[in] cmd: 设备属性名称 93 | * @param[out] user_data: 设备状态结构体 94 | * 95 | * @returns: 0:设置成功 96 | */ 97 | E_JLRetCode_t joylink_dev_user_data_set(char *cmd, user_dev_status_t *user_data); 98 | 99 | /** 100 | * @brief: 传出激活信息 101 | * 102 | * @param[in] message: 激活信息 103 | * 104 | * @returns: 0:设置成功 105 | */ 106 | E_JLRetCode_t joylink_dev_active_message(char *message); 107 | 108 | /** 109 | * @brief: clear wifi information 110 | * 111 | * @returns: void 112 | */ 113 | void esp_joylink_wifi_clear_info(void); 114 | 115 | /** 116 | * brief: 设置局域网待激活模式 117 | * 118 | * @param[in] on_off: 1, 开启激活模式; 0, 关闭激活模式 119 | */ 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif 126 | 127 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_extern_json.c: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @brief: 3 | * 4 | * @version: 1.0 5 | * 6 | * @date: 08/01/2018 7 | * 8 | * @author: 9 | * -------------------------------------------------- 10 | */ 11 | #include 12 | #include 13 | #include 14 | #include "cJSON.h" 15 | 16 | #include "joylink_log.h" 17 | #include "joylink_extern.h" 18 | #include "joylink_memory.h" 19 | #include "joylink_socket.h" 20 | #include "joylink_string.h" 21 | #include "joylink_stdio.h" 22 | #include "joylink_stdint.h" 23 | #include "joylink_time.h" 24 | 25 | /** 26 | * brief: 27 | * 28 | * @Param: pMsg 29 | * @Param: user_dev 30 | * 31 | * @Returns: 32 | */ 33 | int 34 | joylink_dev_parse_ctrl(const char *pMsg, user_dev_status_t *userDev) 35 | { 36 | int ret = -1; 37 | if(NULL == pMsg || NULL == userDev){ 38 | goto RET; 39 | } 40 | log_debug("json_org:%s", pMsg); 41 | cJSON * pSub; 42 | cJSON * pJson = cJSON_Parse(pMsg); 43 | 44 | if(NULL == pJson){ 45 | log_error("--->:ERROR: pMsg is NULL\n"); 46 | goto RET; 47 | } 48 | 49 | char tmp_str[64]; 50 | cJSON *pStreams = cJSON_GetObjectItem(pJson, "streams"); 51 | if(NULL != pStreams){ 52 | int iSize = cJSON_GetArraySize(pStreams); 53 | int iCnt; 54 | for( iCnt = 0; iCnt < iSize; iCnt++){ 55 | pSub = cJSON_GetArrayItem(pStreams, iCnt); 56 | if(NULL == pSub){ 57 | continue; 58 | } 59 | 60 | cJSON *pSId = cJSON_GetObjectItem(pSub, "stream_id"); 61 | if(NULL == pSId){ 62 | break; 63 | } 64 | cJSON *pV = cJSON_GetObjectItem(pSub, "current_value"); 65 | if(NULL == pV){ 66 | continue; 67 | } 68 | 69 | if(!jl_platform_strcmp(USER_DATA_POWER, pSId->valuestring)){ 70 | jl_platform_memset(tmp_str, 0, sizeof(tmp_str)); 71 | jl_platform_strcpy(tmp_str, pV->valuestring); 72 | userDev->Power = atoi(tmp_str); 73 | joylink_dev_user_data_set( USER_DATA_POWER,userDev); 74 | } else if(!jl_platform_strcmp(USER_DATA_AMBIENTLIGHT, pSId->valuestring)) { 75 | jl_platform_memset(tmp_str, 0, sizeof(tmp_str)); 76 | jl_platform_strcpy(tmp_str, pV->valuestring); 77 | userDev->AmbientLight = atoi(tmp_str); 78 | joylink_dev_user_data_set(USER_DATA_AMBIENTLIGHT, userDev); 79 | } 80 | 81 | char *dout = cJSON_PrintUnformatted(pSub); 82 | if(NULL != dout){ 83 | log_debug("org streams:%s", dout); 84 | jl_platform_free(dout); 85 | } 86 | } 87 | } 88 | cJSON_Delete(pJson); 89 | RET: 90 | return ret; 91 | } 92 | 93 | /** 94 | * brief: 95 | * NOTE: If return is not NULL, 96 | * must free it, after use. 97 | * 98 | * @Param: retMsg 99 | * @Param: retCode 100 | * @Param: wci 101 | * @Param: devlist 102 | * 103 | * @Returns: char * 104 | */ 105 | char * 106 | joylink_dev_package_info(const int retCode, user_dev_status_t *userDev) 107 | { 108 | if(NULL == userDev){ 109 | return NULL; 110 | } 111 | cJSON *root, *arrary; 112 | char *out = NULL; 113 | 114 | root = cJSON_CreateObject(); 115 | if(NULL == root){ 116 | goto RET; 117 | } 118 | arrary = cJSON_CreateArray(); 119 | if(NULL == arrary){ 120 | cJSON_Delete(root); 121 | goto RET; 122 | } 123 | cJSON_AddNumberToObject(root, "code", retCode); 124 | cJSON_AddItemToObject(root, "streams", arrary); 125 | 126 | char i2str[64]; 127 | cJSON *data_Power = cJSON_CreateObject(); 128 | cJSON_AddItemToArray(arrary, data_Power); 129 | cJSON_AddStringToObject(data_Power, "stream_id", "Power"); 130 | jl_platform_memset(i2str, 0, sizeof(i2str)); 131 | jl_platform_sprintf(i2str, "%d", userDev->Power); 132 | cJSON_AddStringToObject(data_Power, "current_value", i2str); 133 | 134 | out=cJSON_PrintUnformatted(root); 135 | cJSON_Delete(root); 136 | RET: 137 | return out; 138 | } 139 | 140 | /** 141 | * brief: 142 | * 143 | * @Param: retCode 144 | * @Param: userDev 145 | * 146 | * @Returns: 147 | */ 148 | char * 149 | joylink_dev_modelcode_info(const int retCode, JLPInfo_t *userDev) 150 | { 151 | if(NULL == userDev){ 152 | return NULL; 153 | } 154 | cJSON *root, *arrary; 155 | char *out = NULL; 156 | 157 | root = cJSON_CreateObject(); 158 | if(NULL == root){ 159 | goto RET; 160 | } 161 | arrary = cJSON_CreateArray(); 162 | if(NULL == arrary){ 163 | cJSON_Delete(root); 164 | goto RET; 165 | } 166 | cJSON_AddItemToObject(root, "model_codes", arrary); 167 | 168 | char i2str[32]; 169 | jl_platform_memset(i2str, 0, sizeof(i2str)); 170 | cJSON *element = cJSON_CreateObject(); 171 | cJSON_AddItemToArray(arrary, element); 172 | cJSON_AddStringToObject(element, "feedid", userDev->feedid); 173 | cJSON_AddStringToObject(element, "model_code", "12345678123456781234567812345678"); 174 | 175 | out=cJSON_PrintUnformatted(root); 176 | cJSON_Delete(root); 177 | RET: 178 | return out; 179 | } 180 | /** 181 | * brief: 182 | * 183 | * @Param: jlp 184 | * @Param: pMsg 185 | * 186 | * @Returns: 187 | */ 188 | int 189 | joylink_parse_jlp(JLPInfo_t *jlp, char * pMsg) 190 | { 191 | int ret = -1; 192 | if(NULL == pMsg || NULL == jlp){ 193 | return ret; 194 | } 195 | cJSON *pVal; 196 | cJSON * pJson = cJSON_Parse(pMsg); 197 | 198 | if(NULL == pJson){ 199 | log_error("--->:ERROR: pMsg is NULL\n"); 200 | goto RET; 201 | } 202 | 203 | pVal = cJSON_GetObjectItem(pJson, "uuid"); 204 | if(NULL != pVal){ 205 | jl_platform_strcpy(jlp->uuid, pVal->valuestring); 206 | } 207 | 208 | pVal = cJSON_GetObjectItem(pJson, "feedid"); 209 | if(NULL != pVal){ 210 | jl_platform_strcpy(jlp->feedid, pVal->valuestring); 211 | } 212 | 213 | pVal = cJSON_GetObjectItem(pJson, "accesskey"); 214 | if(NULL != pVal){ 215 | jl_platform_strcpy(jlp->accesskey, pVal->valuestring); 216 | } 217 | 218 | pVal = cJSON_GetObjectItem(pJson, "localkey"); 219 | if(NULL != pVal){ 220 | jl_platform_strcpy(jlp->localkey, pVal->valuestring); 221 | } 222 | 223 | pVal = cJSON_GetObjectItem(pJson, "version"); 224 | if(NULL != pVal){ 225 | jlp->version = pVal->valueint; 226 | } 227 | 228 | cJSON_Delete(pJson); 229 | ret = 0; 230 | RET: 231 | return ret; 232 | } 233 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_extern_json.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_json.h 3 | * 4 | * @brief: 5 | * 6 | * @version: 1.0 7 | * 8 | * @date: 10/26/2015 02:21:59 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #ifndef __JOYLINK_EXTERN_JSON__ 14 | #define __JOYLINK_EXTERN_JSON__ 15 | 16 | #include "joylink_extern.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C"{ 20 | #endif /* __cplusplus */ 21 | 22 | /** 23 | * brief: 24 | * 25 | * @Param: pCtrl 26 | * @Param: pMsg 27 | * 28 | * @Returns: 29 | */ 30 | int 31 | joylink_dev_parse_ctrl(const char * pMsg, user_dev_status_t *userDev); 32 | 33 | /** 34 | * brief: 35 | * 36 | * @Param: retCode 37 | * @Param: pCtrl 38 | * 39 | * @Returns: 40 | */ 41 | char * 42 | joylink_dev_package_info(const int retCode, user_dev_status_t *userDev); 43 | 44 | /** 45 | * brief: 46 | * 47 | * @Param: retCode 48 | * @Param: pCtrl 49 | * 50 | * @Returns: 51 | */ 52 | char * 53 | joylink_dev_modelcode_info(const int retCode, JLPInfo_t *userDev); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif /* __cplusplus */ 58 | #endif 59 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_extern_ota.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_ota.h 3 | * 4 | * @brief: 5 | * 6 | * @version: 2.0 7 | * 8 | * @date: 2018/07/26 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #ifndef _JOYLINK_EXTERN_OTA_H_ 14 | #define _JOYLINK_EXTERN_OTA_H_ 15 | 16 | #ifdef __cplusplus 17 | extern "C"{ 18 | #endif 19 | 20 | #include "joylink_extern.h" 21 | 22 | #define OTA_STATUS_DOWNLOAD 0 23 | #define OTA_STATUS_INSTALL 1 24 | #define OTA_STATUS_SUCCESS 2 25 | #define OTA_STATUS_FAILURE 3 26 | 27 | #define HTTP_DEFAULT_PORT 80 28 | 29 | #define EVERY_PACKET_LEN 1024 30 | 31 | #define OTA_TIME_OUT (5 * 60 * 1000) 32 | 33 | #define HTTP_HEAD "HEAD /%s HTTP/1.1\r\nHOST: %s:%d\r\nConnection: Keep-Alive\r\n\r\n" 34 | #define HTTP_GET "GET /%s HTTP/1.1\r\nHOST: %s:%d\r\nRange: bytes=%ld-%ld\r\nKeep-Alive: 200\r\nConnection: Keep-Alive\r\n\r\n" 35 | 36 | typedef struct _http_ota_st 37 | { 38 | char url[256]; 39 | 40 | char host_name[64]; 41 | int host_port; 42 | 43 | char file_path[64]; 44 | char file_name[64]; 45 | 46 | long int file_size; 47 | long int file_offset; 48 | 49 | int finish_percent; 50 | } http_ota_st; 51 | 52 | 53 | void *joylink_ota_task(void *data); 54 | 55 | void joylink_set_ota_info(JLOtaOrder_t *ota_info); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_extern_sub_dev.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_EXTERN_SUB_DEV_H_ 2 | #define _JOYLINK_EXTERN_SUB_DEV_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif /* __cplusplus */ 7 | 8 | #include "joylink.h" 9 | #include "joylink_sub_dev.h" 10 | 11 | /* 12 | * user set 13 | */ 14 | 15 | #define DEV_AUTH_VALUE 0 // 0: disable; 1: enable. 16 | #define DEV_BATCH_BIND 0 // 0: disable; 1; enable. 17 | 18 | #define SUBDEV_UUID "4E4638" 19 | #define SUBDEV_MAC "AA0011223366" 20 | #define SUBDEV_LICENSE "d91fa7fc6ba19811747d9d6ddc0971f2" 21 | 22 | /*---------------- sub dev api ---------------*/ 23 | 24 | /** 25 | * brief: 26 | * 27 | * @Param: dev 28 | * @Param: num 29 | * 30 | * @Returns: 31 | */ 32 | E_JLRetCode_t 33 | joylink_dev_sub_add(JLSubDevData_t *dev, int num); 34 | 35 | /** 36 | * brief: 37 | * 38 | * @Param: dev 39 | * @Param: num 40 | * 41 | * @Returns: 42 | */ 43 | E_JLRetCode_t 44 | joylink_sub_dev_del(char *feedid); 45 | 46 | /** 47 | * brief: 48 | * 49 | * @Param: feedid 50 | * @Param: dev 51 | * 52 | * @Returns: 53 | */ 54 | E_JLRetCode_t 55 | joylink_dev_sub_get_by_feedid(char *feedid, JLSubDevData_t *dev); 56 | /** 57 | * brief: 58 | * 59 | * @Param: feedid 60 | * @Param: dev 61 | * 62 | * @Returns: 63 | */ 64 | E_JLRetCode_t 65 | joylink_dev_sub_version_update(char *feedid, int version); 66 | /** 67 | * brief: 68 | * 69 | * @Param: uuid 70 | * @Param: mac 71 | * @Param: dev 72 | * 73 | * @Returns: 74 | */ 75 | E_JLRetCode_t 76 | joylink_sub_dev_get_by_uuid_mac(char *uuid, char *mac, JLSubDevData_t *dev); 77 | 78 | /** 79 | * brief: 80 | * 81 | * @Param: uuid 82 | * @Param: mac 83 | * @Param: dev 84 | * 85 | * @Returns: 86 | */ 87 | E_JLRetCode_t 88 | joylink_dev_sub_update_keys_by_uuid_mac(char *uuid, char *mac, JLSubDevData_t *dev); 89 | 90 | /** 91 | * brief: 根据子设备mac查询子设备其他信息。 92 | * 93 | * @Param: macstr 94 | * 95 | * @Returns: 96 | */ 97 | int joylink_sub_dev_get_by_deviceid(char *macstr, JLSubDevData_t *info_out); 98 | 99 | /** 100 | * brief: 更新子设备信息,并根据标识进行保存。 101 | * 102 | * @Param: macstr 103 | * 104 | * @Returns: 105 | */ 106 | int joylink_sub_dev_update_device_info(JLSubDevData_t *info_in, int save_flag); 107 | 108 | 109 | /** 110 | * brief: 子设备上报数据或心跳时调用此函数,设置设备在线标识。 111 | * 112 | * @Param: macstr 113 | * 114 | * @Returns: 115 | */ 116 | 117 | int joylink_sub_dev_hb_event(char *macstr); 118 | 119 | /** 120 | * brief: 子设备上报设备快照,只上报macstr这个的快照。 121 | * 122 | * @Returns: 123 | */ 124 | int joylink_server_sub_dev_event_req(char *macstr, char *event_payload, int length); 125 | 126 | /** 127 | * brief: 128 | * 129 | * @Param: count 130 | * @Param: scan_type 131 | * 132 | * @Returns: 133 | */ 134 | JLSubDevData_t * 135 | joylink_dev_sub_devs_get(int *count); 136 | 137 | /** 138 | * brief: 139 | * 140 | * @Param: cmd 141 | * @Param: cmd_len 142 | * @Param: feedid 143 | * 144 | * @Returns: 145 | */ 146 | E_JLRetCode_t 147 | joylink_dev_sub_ctrl(const char* cmd, int cmd_len, char* feedid); 148 | 149 | /** 150 | * brief: 151 | * 152 | * @Param: feedid 153 | * @Param: out_len 154 | * 155 | * @Returns: 156 | */ 157 | char * 158 | joylink_dev_sub_get_snap_shot(char *feedid, int *out_len); 159 | 160 | /** 161 | * brief: 162 | * 163 | * @Param: feedid 164 | * 165 | * @Returns: 166 | */ 167 | E_JLRetCode_t 168 | joylink_dev_sub_unbind(const char *feedid); 169 | 170 | /** 171 | * brief: 上报子设备快照 172 | * 173 | * @Returns: 174 | */ 175 | extern int joylink_server_subdev_event_req(char *macstr, char *event_payload, int length); 176 | 177 | /** 178 | * brief: 立刻上报子设备快照 179 | * 180 | * @Returns: 181 | */ 182 | 183 | int joylink_sub_dev_report_snapshot_immediately(char *macstr, char *data, int len); 184 | 185 | #define SUBDEV_ACTIVE_STATUS_OPEN 0 186 | #define SUBDEV_ACTIVE_STATUS_OK 1 187 | #define SUBDEV_ACTIVE_STATUS_FAILED 2 188 | 189 | /** 190 | * @brief: SDK subdev active 子设备激活状态报告 191 | * 192 | * @param[in] status: 状态 0打开, 1成功,2失败, 3解邦 193 | * 194 | * @return: reserved 当前此函数仅做通知,调用方不关心返回值. 195 | */ 196 | void joylink_sub_dev_active_status(char status); 197 | 198 | /** 199 | * @brief: delete subdev 删除子设备 200 | * 201 | * @param[in] mac: 删除子设备的 mac 202 | * 203 | * @return: reserved 当前此函数仅做通知,调用方不关心返回值. 204 | */ 205 | void joylink_sub_dev_delete_msg(char *mac); 206 | 207 | /** 208 | * @brief: 添加子设备到全局数组_g_sub_dev中 209 | * 210 | * @param[in]: dev 设备结构 211 | * @param[in]: message 例如: 212 | * { 213 | * "uuid": "D23707", // 小京鱼开放平台创建的虚拟红外被控设备的UUID 214 | * "brandKey": "mm", // 虚拟被控红外设备品牌标识,对接厂商自行定义 215 | * "modelKey": "xx", // 虚拟被控红外设备型号标识,对接厂商自行定义 216 | * "controllerId": "948001623745658402" // 主控红外遥控器的feedid,表示虚拟红外被控设备可以被哪一个遥控器控制。 217 | * } 218 | * 219 | * @returns: E_RET_OK 成功, E_RET_ERROR 发生错误 220 | */ 221 | E_JLRetCode_t joylink_dev_sub_add_infrared_receiver(JLSubDevData_t *dev, char *message); 222 | 223 | #ifdef __cplusplus 224 | } 225 | #endif 226 | 227 | #endif 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_extern_user.c: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_tool.C 3 | * 4 | * @brief: 5 | * 6 | * @version: 2.0 7 | * 8 | * @date: 2018/07/26 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "joylink_extern_user.h" 19 | #include "joylink_stdio.h" 20 | #include "joylink_stdint.h" 21 | 22 | int file_fd = -1; 23 | 24 | int joylink_memory_init(void *index, int flag) 25 | { 26 | char *save_path = (char *)index; 27 | 28 | if(file_fd > 0) 29 | return -1; 30 | 31 | //jl_platform_printf("save_path: %s\n", save_path); 32 | 33 | if(flag == MEMORY_WRITE){ 34 | file_fd = open(save_path, O_WRONLY | O_CREAT | O_TRUNC, 0777); 35 | if(file_fd < 0){ 36 | jl_platform_printf("Open file error!\n"); 37 | return -1; 38 | } 39 | } 40 | else if(flag == MEMORY_READ){ 41 | file_fd = open(save_path, O_RDONLY | O_CREAT, 0777); 42 | if(file_fd < 0){ 43 | jl_platform_printf("Open file error!\n"); 44 | return -1; 45 | } 46 | } 47 | return 0; 48 | } 49 | 50 | int joylink_memory_write(int offset, char *data, int len) 51 | { 52 | if(file_fd < 0 || data == NULL) 53 | return -1; 54 | 55 | return write(file_fd, data, len); 56 | } 57 | 58 | int joylink_memory_read(int offset, char *data, int len) 59 | { 60 | if(file_fd < 0 || data == NULL) 61 | return -1; 62 | 63 | return read(file_fd, data, len); 64 | } 65 | 66 | int joylink_memory_finish(void) 67 | { 68 | if(file_fd < 0) 69 | return -1; 70 | 71 | close(file_fd); 72 | file_fd = -1; 73 | return 0; 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_extern_user.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_tool.h 3 | * 4 | * @brief: 5 | * 6 | * @version: 2.0 7 | * 8 | * @date: 2018/07/26 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #ifndef _JOYLINK_EXTERN_TOOL_H_ 14 | #define _JOYLINK_EXTERN_TOOL_H_ 15 | 16 | #ifdef __cplusplus 17 | extern "C"{ 18 | #endif 19 | 20 | #define MEMORY_WRITE 0 21 | #define MEMORY_READ 1 22 | 23 | int joylink_memory_init(void *index, int flag); 24 | 25 | int joylink_memory_write(int offset, char *data, int len); 26 | int joylink_memory_read(int offset, char *data, int len); 27 | 28 | int joylink_memory_finish(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_led_rgb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _JOYLINK_LIGHT_H_ 25 | #define _JOYLINK_LIGHT_H_ 26 | 27 | #include 28 | 29 | /** 30 | * @brief initialize the joylink_light lowlevel module 31 | * 32 | * @param none 33 | * 34 | * @return none 35 | */ 36 | void joylink_light_init(void); 37 | 38 | /** 39 | * @brief deinitialize the joylink_light's lowlevel module 40 | * 41 | * @param none 42 | * 43 | * @return none 44 | */ 45 | void joylink_light_deinit(void); 46 | 47 | /** 48 | * @brief turn on/off the lowlevel joylink_light 49 | * 50 | * @param value The "On" value 51 | * 52 | * @return none 53 | */ 54 | int joylink_light_set_on(bool value); 55 | 56 | /** 57 | * @brief set the saturation of the lowlevel joylink_light 58 | * 59 | * @param value The Saturation value 60 | * 61 | * @return 62 | * - 0 : OK 63 | * - others : fail 64 | */ 65 | int joylink_light_set_saturation(float value); 66 | 67 | /** 68 | * @brief set the hue of the lowlevel joylink_light 69 | * 70 | * @param value The Hue value 71 | * 72 | * @return 73 | * - 0 : OK 74 | * - others : fail 75 | */ 76 | int joylink_light_set_hue(float value); 77 | 78 | /** 79 | * @brief set the brightness of the lowlevel joylink_light 80 | * 81 | * @param value The Brightness value 82 | * 83 | * @return 84 | * - 0 : OK 85 | * - others : fail 86 | */ 87 | int joylink_light_set_brightness(int value); 88 | 89 | #endif /* _JOYLINK_LIGHT_H_ */ 90 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_light.c: -------------------------------------------------------------------------------- 1 | #include "joylink_light.h" 2 | #include "joylink_led_rgb.h" 3 | 4 | void light_init(void) 5 | { 6 | joylink_light_init(); 7 | } 8 | 9 | static void joylink_AmbientLight(void) 10 | { 11 | joylink_light_set_hue(300); 12 | } 13 | 14 | void joylink_light_Control(user_dev_status_t user_dev) 15 | { 16 | joylink_light_set_brightness(78); 17 | joylink_light_set_saturation(100); 18 | if (user_dev.Power == 1) { 19 | joylink_light_set_on(true); 20 | if (user_dev.AmbientLight == 1) { 21 | joylink_AmbientLight(); 22 | } else if (user_dev.AmbientLight == 0) { 23 | joylink_light_set_saturation(0); 24 | } 25 | } else if (user_dev.Power == 0) { 26 | joylink_light_set_on(false); 27 | joylink_light_set_brightness(0); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/light_demo/components/joylink_extern/joylink_light.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_LIGHT_H 2 | #define _JOYLINK_LIGHT_H 3 | 4 | #include "joylink_extern.h" 5 | 6 | void light_init(void); 7 | 8 | void joylink_light_Control(user_dev_status_t user_dev); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32/joylink_demo.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0x160000 7 | ota_1, 0, ota_1, 0x170000,0x160000 8 | mfg_nvs, data, nvs, 0x340000,0x4000 -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # 2 | # Serial flasher config 3 | # 4 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | 7 | # 8 | # Partition Table 9 | # 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="default_configs/esp32/joylink_demo.csv" 12 | CONFIG_PARTITION_TABLE_FILENAME="default_configs/esp32/joylink_demo.csv" 13 | 14 | # 15 | # Bluetooth 16 | # 17 | CONFIG_BT_ENABLED=y 18 | 19 | # 20 | # Bluetooth controller 21 | # 22 | CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y 23 | 24 | # 25 | # Wi-Fi 26 | # 27 | CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y 28 | 29 | CONFIG_JOYLINK_BLE_ENABLE=n 30 | 31 | # 32 | # Light GPIO 33 | # 34 | CONFIG_JOYLINK_LIGHT_R=25 35 | CONFIG_JOYLINK_LIGHT_G=26 36 | CONFIG_JOYLINK_LIGHT_B=27 37 | 38 | # 39 | # ESP-TLS 40 | # 41 | CONFIG_ESP_TLS_INSECURE=y 42 | CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32c3/joylink_demo.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0x160000 7 | ota_1, 0, ota_1, 0x170000,0x160000 8 | mfg_nvs, data, nvs, 0x340000,0x4000 -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32c3/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # 2 | # Serial flasher config 3 | # 4 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | 7 | # 8 | # Partition Table 9 | # 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="default_configs/esp32c3/joylink_demo.csv" 12 | CONFIG_PARTITION_TABLE_FILENAME="default_configs/esp32c3/joylink_demo.csv" 13 | 14 | # 15 | # Wi-Fi 16 | # 17 | CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y 18 | 19 | # 20 | # Bluetooth 21 | # 22 | CONFIG_BT_ENABLED=y 23 | 24 | # 25 | # Bluetooth controller 26 | # 27 | CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y 28 | CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n 29 | 30 | # 31 | # Light GPIO 32 | # 33 | CONFIG_JOYLINK_LIGHT_R=5 34 | CONFIG_JOYLINK_LIGHT_G=6 35 | CONFIG_JOYLINK_LIGHT_B=7 36 | 37 | # 38 | # ESP-TLS 39 | # 40 | CONFIG_ESP_TLS_INSECURE=y 41 | CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y 42 | -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32s2/joylink_demo.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0x160000 7 | ota_1, 0, ota_1, 0x170000,0x160000 8 | mfg_nvs, data, nvs, 0x340000,0x4000 -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32s2/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # 2 | # Serial flasher config 3 | # 4 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | 7 | # 8 | # Partition Table 9 | # 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="default_configs/esp32s2/joylink_demo.csv" 12 | CONFIG_PARTITION_TABLE_FILENAME="default_configs/esp32s2/joylink_demo.csv" 13 | 14 | # 15 | # Wi-Fi 16 | # 17 | CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y 18 | 19 | # 20 | # Light GPIO 21 | # 22 | CONFIG_JOYLINK_LIGHT_R=15 23 | CONFIG_JOYLINK_LIGHT_G=16 24 | CONFIG_JOYLINK_LIGHT_B=17 25 | 26 | # 27 | # ESP-TLS 28 | # 29 | CONFIG_ESP_TLS_INSECURE=y 30 | CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32s3/joylink_demo.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0x160000 7 | ota_1, 0, ota_1, 0x170000,0x160000 8 | mfg_nvs, data, nvs, 0x340000,0x4000 -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp32s3/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # 2 | # Serial flasher config 3 | # 4 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 5 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | 7 | # 8 | # Partition Table 9 | # 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="default_configs/esp32s3/joylink_demo.csv" 12 | CONFIG_PARTITION_TABLE_FILENAME="default_configs/esp32s3/joylink_demo.csv" 13 | 14 | # 15 | # Wi-Fi 16 | # 17 | CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y 18 | 19 | # 20 | # Bluetooth 21 | # 22 | CONFIG_BT_ENABLED=y 23 | 24 | # 25 | # Bluetooth controller 26 | # 27 | CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y 28 | CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n 29 | 30 | # 31 | # Light GPIO 32 | # 33 | CONFIG_JOYLINK_LIGHT_R=15 34 | CONFIG_JOYLINK_LIGHT_G=16 35 | CONFIG_JOYLINK_LIGHT_B=17 36 | 37 | # 38 | # ESP-TLS 39 | # 40 | CONFIG_ESP_TLS_INSECURE=y 41 | CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y 42 | -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp8266/joylink_demo.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x4000 4 | otadata, data, ota, 0xd000, 0x2000 5 | phy_init, data, phy, 0xf000, 0x1000 6 | ota_0, 0, ota_0, 0x10000, 0xF0000 7 | mfg_nvs, data, nvs, 0x100000,0x4000 8 | ota_1, 0, ota_1, 0x110000,0xF0000 9 | -------------------------------------------------------------------------------- /examples/light_demo/default_configs/esp8266/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # 2 | # Serial flasher config 3 | # 4 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 5 | CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 6 | 7 | # 8 | # Partition Table 9 | # 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="default_configs/esp8266/joylink_demo.csv" 12 | CONFIG_PARTITION_TABLE_FILENAME="default_configs/esp8266/joylink_demo.csv" 13 | 14 | 15 | CONFIG_ENABLE_PTHREAD=y 16 | 17 | CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=4096 18 | CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=n 19 | CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=n 20 | CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=n 21 | CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=n 22 | CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=n 23 | CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=n 24 | 25 | CONFIG_NEWLIB_NANO_FORMAT=n 26 | 27 | # 28 | # Light GPIO 29 | # 30 | CONFIG_JOYLINK_LIGHT_R=4 31 | CONFIG_JOYLINK_LIGHT_G=5 32 | CONFIG_JOYLINK_LIGHT_B=15 -------------------------------------------------------------------------------- /examples/light_demo/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS "") 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES ) 6 | 7 | set(COMPONENT_SRCS ./app_main.c ./esp_joylink_app.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /examples/light_demo/main/app_main.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "esp_system.h" 18 | #include "esp_system.h" 19 | #include "esp_wifi.h" 20 | #include "esp_event_loop.h" 21 | #include "nvs_flash.h" 22 | 23 | #if !defined(ESP_IDF_VERSION) 24 | #include "apps/sntp/sntp.h" 25 | #elif (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(3,4,0)) 26 | #include "apps/sntp/sntp.h" 27 | #else 28 | #include "esp_sntp.h" 29 | #endif 30 | #include "esp_joylink_app.h" 31 | #include "joylink_light.h" 32 | 33 | #include "joylink_upgrade.h" 34 | 35 | #ifdef CONFIG_JOYLINK_BLE_ENABLE 36 | #include "joylink_sdk.h" 37 | #include "joylink_dev_active.h" 38 | 39 | extern bool get_rst; 40 | extern jl_net_config_data_t ble_net_cfg_data; 41 | extern bool joylink_ble_report_flag; 42 | #endif 43 | 44 | void esp_ota_task_start(char* url) 45 | { 46 | ota_task_start(url); 47 | } 48 | 49 | esp_err_t event_handler(void *ctx, system_event_t *event) 50 | { 51 | int32_t ret = -1; 52 | switch(event->event_id){ 53 | case SYSTEM_EVENT_STA_GOT_IP: 54 | #ifdef CONFIG_JOYLINK_BLE_ENABLE 55 | if (get_rst) { 56 | ret = jl_send_net_config_state(E_JL_NET_CONF_ST_WIFI_CONNECT_SUCCEED, NULL, 0); 57 | log_debug("E_JL_NET_CONF_ST_WIFI_CONNECT_SUCCEED ret = %d", ret); 58 | printf("token: %s\n", ble_net_cfg_data.token); 59 | printf("url: %s\n", ble_net_cfg_data.url); 60 | joylink_dev_active_start((char *)ble_net_cfg_data.url, (char *)ble_net_cfg_data.token); 61 | free(ble_net_cfg_data.token); 62 | free(ble_net_cfg_data.url); 63 | // joylink_dev_active_req(); 64 | joylink_ble_report_flag = false; 65 | } 66 | #endif 67 | break; 68 | default: 69 | break; 70 | } 71 | return ESP_OK; 72 | } 73 | 74 | static void initialise_wifi(void) 75 | { 76 | tcpip_adapter_init(); 77 | ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); 78 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 79 | ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); 80 | ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); 81 | ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) ); 82 | ESP_ERROR_CHECK( esp_wifi_start() ); 83 | } 84 | 85 | static void initialize_sntp(void) 86 | { 87 | /* Start SNTP service */ 88 | sntp_setoperatingmode(SNTP_OPMODE_POLL); 89 | sntp_setservername(0, "pool.ntp.org"); 90 | sntp_init(); 91 | } 92 | 93 | void app_main(void) 94 | { 95 | printf("================== ESPRESSIF ===================\n"); 96 | printf(" ESP_IDF VERSION: %s\n",esp_get_idf_version()); 97 | printf(" JOYLINK COMMIT: %s\n",ESP_JOYLINK_COMMIT_ID); 98 | printf(" Compile time: %s %s\n",__DATE__,__TIME__); 99 | printf("================================================\n"); 100 | 101 | nvs_flash_init(); 102 | initialise_wifi(); 103 | initialize_sntp(); 104 | light_init(); 105 | 106 | esp_joylink_app_start(); 107 | } 108 | -------------------------------------------------------------------------------- /examples/light_demo/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /examples/light_demo/main/esp_joylink_app.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "freertos/FreeRTOS.h" 21 | #include "freertos/task.h" 22 | #include "freertos/event_groups.h" 23 | 24 | #include "esp_system.h" 25 | #include "esp_wifi.h" 26 | #include "esp_event_loop.h" 27 | #include "nvs.h" 28 | #include "nvs_flash.h" 29 | 30 | #include "joylink_softap_start.h" 31 | #include "joylink.h" 32 | 33 | #ifdef CONFIG_JOYLINK_BLE_ENABLE 34 | #define IS_CHOOSE_BLE true 35 | #else 36 | #define IS_CHOOSE_BLE false 37 | #endif 38 | 39 | #ifdef CONFIG_JOYLINK_BLE_ENABLE 40 | #include "joylink_sdk.h" 41 | #include "joylink_ble.h" 42 | #include "joylink_softap.h" 43 | 44 | bool joylink_ble_report_flag = false; 45 | extern wifi_config_t jd_ble_config; 46 | extern bool get_rst; 47 | #endif 48 | static void esp_start_ap_mode(void) 49 | { 50 | wifi_config_t config; 51 | 52 | memset(&config, 0x0, sizeof(config)); 53 | esp_wifi_set_mode(WIFI_MODE_APSTA); 54 | printf("ssid:%s\r\n", CONFIG_JOYLINK_SOFTAP_SSID); 55 | 56 | config.ap.ssid_len = strlen(CONFIG_JOYLINK_SOFTAP_SSID); 57 | 58 | if (config.ap.ssid_len > sizeof(config.ap.ssid)) { 59 | config.ap.ssid_len = sizeof(config.ap.ssid); 60 | } 61 | 62 | memcpy(config.ap.ssid, CONFIG_JOYLINK_SOFTAP_SSID, config.ap.ssid_len); 63 | config.ap.max_connection = 3; 64 | config.ap.channel = 9; 65 | esp_wifi_set_config(WIFI_IF_AP, &config); 66 | } 67 | 68 | static void joylink_task(void *pvParameters) 69 | { 70 | nvs_handle out_handle; 71 | wifi_config_t config; 72 | size_t size = 0; 73 | bool flag = false; 74 | int32_t ret = -1; 75 | 76 | esp_wifi_set_mode(WIFI_MODE_STA); 77 | 78 | if (nvs_open("joylink_wifi", NVS_READONLY, &out_handle) == ESP_OK) { 79 | memset(&config,0x0,sizeof(config)); 80 | size = sizeof(config.sta.ssid); 81 | if (nvs_get_str(out_handle,"ssid",(char*)config.sta.ssid,&size) == ESP_OK) { 82 | if (size > 0) { 83 | size = sizeof(config.sta.password); 84 | if (nvs_get_str(out_handle,"password",(char*)config.sta.password,&size) == ESP_OK) { 85 | flag = true; 86 | } else { 87 | printf("--get password fail"); 88 | } 89 | } 90 | } else { 91 | printf("--get ssid fail"); 92 | } 93 | 94 | nvs_close(out_handle); 95 | } 96 | 97 | if (flag) { 98 | esp_wifi_set_config(ESP_IF_WIFI_STA,&config); 99 | esp_wifi_connect(); 100 | } else if (IS_CHOOSE_BLE == false) 101 | { 102 | esp_start_ap_mode(); 103 | joylink_softap_start(1000*60*60); 104 | } else if (IS_CHOOSE_BLE == true) 105 | { 106 | #ifdef CONFIG_JOYLINK_BLE_ENABLE 107 | esp_wifi_stop(); 108 | esp_wifi_start(); 109 | esp_wifi_set_mode(WIFI_MODE_STA); 110 | ble_start(); 111 | while(1) { 112 | vTaskDelay(10); 113 | if(get_rst) { 114 | joylink_ble_report_flag = true; 115 | ret = jl_send_net_config_state(E_JL_NET_CONF_ST_WIFI_CONNECT_START, NULL, 0); 116 | log_debug("E_JL_NET_CONF_ST_WIFI_CONNECT_START ret = %d", ret); 117 | 118 | log_debug("SSID: %s\r\n", (char *)jd_ble_config.sta.ssid); 119 | log_debug("PWD: %s\r\n", (char *)jd_ble_config.sta.password); 120 | vTaskDelay(100); 121 | esp_wifi_set_config(ESP_IF_WIFI_STA, &jd_ble_config); 122 | esp_wifi_connect(); 123 | 124 | esp_joylink_wifi_save_info(jd_ble_config.sta.ssid, jd_ble_config.sta.password); 125 | vTaskDelete(NULL); 126 | break; 127 | } 128 | } 129 | #endif 130 | } 131 | 132 | vTaskDelete(NULL); 133 | } 134 | 135 | static void joylink_main_task(void *pvParameters) 136 | { 137 | joylink_main_start(); 138 | vTaskDelete(NULL); 139 | } 140 | 141 | void esp_joylink_app_start(void) 142 | { 143 | xTaskCreate(joylink_main_task, "joylink_main_task", 1024*11, NULL, 2, NULL); 144 | xTaskCreate(joylink_task, "jl_task", 1024*6, NULL, 2, NULL); 145 | } -------------------------------------------------------------------------------- /examples/light_demo/main/esp_joylink_app.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __ESP_JOYLINK_APP_H__ 16 | #define __ESP_JOYLINK_APP_H__ 17 | 18 | // start joylink app task 19 | void esp_joylink_app_start(void); 20 | 21 | #endif -------------------------------------------------------------------------------- /joylink_dev_sdk/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2050, JD Smart All rights reserved. 2 | Redistribution and use in source forms, with or without modification, are permitted provided that the following conditions are met: 3 | 4 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 5 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 6 | * Neither the name of joylink nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 7 | 8 | LTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 9 | -------------------------------------------------------------------------------- /joylink_dev_sdk/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = . 2 | 3 | include ${TOP_DIR}/scripts/config.mk 4 | 5 | DEPS := pal example 6 | 7 | all: clean_lib ${DEPS} jt 8 | 9 | clean: clean_lib ${DEPS} 10 | 11 | distclean: ${DEPS} 12 | ${RM} ${TARGET_LIB}/* 13 | 14 | ${DEPS}: 15 | make -C $@ $(MAKECMDGOALS) 16 | 17 | jt: 18 | make jt -C example 19 | 20 | clean_lib: 21 | rm -rf ${TARGET_LIB} 22 | mkdir -p ${TARGET_LIB} 23 | rm -rf ${TARGET_BIN} 24 | mkdir -p ${TARGET_BIN} 25 | 26 | .PHONY:all clean distclean ${DEPS} jt 27 | -------------------------------------------------------------------------------- /joylink_dev_sdk/README: -------------------------------------------------------------------------------- 1 | Where to find complete joylink documentation? 2 | ------------------------------------------- 3 | 4 | This README is just a fast "quick start" document. You can find more detailed 5 | documentation at http://www.jdsmart.com/joylink/ 6 | 7 | Building joylink_dev_sdk 8 | -------------- 9 | 10 | joylink_dev_sdk can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD. 11 | We support big endian and little endian architectures. 12 | 13 | It may compile on Linux. 14 | 15 | step 1: 16 | % ./once.sh /* once.sh can set the path as your project dir in Makefile.rule */ 17 | 18 | step 2: 19 | % make distclean /* Clear all the files generated by the compiler */ 20 | 21 | step 3: 22 | % make 23 | 24 | step 4: 25 | % sudo ./target/bin/jt /* run the program */ 26 | 27 | Enjoy! 28 | -------------------------------------------------------------------------------- /joylink_dev_sdk/RELEASENOTES: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- 3 | Version : 2.1.22.21 4 | Date : 2020年 10月 15日 星期四 11:46:53 CST 5 | Owner : liyanming10 6 | Description : 7 | 1、实现连接退避机制。 8 | 2、露出子设备状态上报接口。 9 | 10 | -------------------------------------------------------------------------------- 11 | Version : 2.1.22.20 12 | Date : 2020年 08月 11日 星期二 10:30:58 CST 13 | Owner : liyanming10 14 | Description : 15 | 1、收数据去除1400字节的限制。 16 | 2、解决IOT通道收数据不完整的bug。 17 | 18 | -------------------------------------------------------------------------------- 19 | Version : 2.1.22.19 20 | Date : 2020年 07月 23日 星期四 11:33:43 CST 21 | Owner : liyanming10 22 | Description : 23 | 1、完成自动化编译sdk脚本。 24 | 2、解决云菜谱返回的biz_code不正确的问题。 25 | 3、alive埋点日志增加离线次数参数上报。 26 | 4、mac的buffer长度统一改成17,防止有些设备是16字节时会崩溃。 27 | 5、jl_platform_send的实现send参数使用从time_out改为flags 28 | 6、解决局域网控制的一个bug,复用了时间戳校验函数的返回值,会导致局域网控制子设备失败。 29 | 30 | -------------------------------------------------------------------------------- 31 | Version : 2.1.22 32 | Date : 2020年 04月 14日 星期二 19:55:29 CST 33 | Owner : liyanming10 34 | Description : 35 | 1、代码中标准库函数的调用改为pal层调用。 36 | 2、解决认证超时导致设备重新建立长连接再次认证。 37 | 3、加版本上报功能。 38 | 4、日志埋点上报线程栈空间从0x4000改为0x1000. 39 | 5、露出激活绑定信息接口;露出局域网激活绑定开关接口(默认关闭激活绑定,防止被别人绑走)。 40 | 6、代码优化,删掉user_jlp。 41 | 7、x86环境下,把OTA升级的源码编译到jt中。 42 | 8、优化ota升级逻辑,crc校验边下载数据边校验。 43 | 9、SoftAP单次配网,保证pubKey和R2不变,防止重发时生成的sessionKey不一致。 44 | 10、WiFi应答包打印日志不匹配(udp 打印成tcp了)。 45 | 11、解决SoftAP配网上报日志点位不正确的问题。 46 | 12、支持通过__JOYLINK_LOG_SUPPORT_HTTP__宏切换激活绑定日志上报的协议,如果定义,则通过http上报,没有定义通过https上报。 47 | 13、加通过__JOYLINK_ALL_ACTIVE_INFO__宏定义控制激活绑定接口。 48 | 14、解决切换到activeAndBindForDevice接口激活绑定失败的问题。 49 | 50 | -------------------------------------------------------------------------------- 51 | Version : 2.1.21 52 | Date : 2020年03月13日 10:17:39 53 | Owner : liyanming10 54 | Description : 55 | 1、增加设备上电埋点。 56 | 2、删除_AGENT_GW_宏控的代码。 57 | 3、connect时上报失败次数,失败之后延时3秒开始再次建立连接。 58 | 4、细化接收数据返回值埋点,区分失败,服务端断开,大数据包长度超限。 59 | 5、优化控制结果上报。 60 | 6、增加定时(10分钟一次)上报alive日志,确保主任务活着。 61 | 7、增加热点断开埋点,热点断开之后计时,连接之后把断开的时间上报。 62 | 8、解决静态扫描的bug,解决ssid为空的bug,会影响一键配网。 63 | 9、softap激活绑定之后将token和url返回给app,以验证其正确性。 64 | 10、其它代码优化,增加可读性。 65 | 11、解决线程不同步导致的日志埋点中参数ip不能实时更新的问题。 66 | 12. 解决一个日志模块计数bug带来的内存泄漏的问题。 67 | 13. 解决断网解析域名内存泄漏的问题。 68 | 14. 埋点上报线程增加网络判断和配网模式判断,配网模式不上报日志,断网时1秒上报一次,每上报一次日志休眠50ms。 69 | 15. 优化日志上报逻辑,当上报失败时,适当的增加休眠时间。 70 | 16. 修改joylink_main_loop末尾的sleep,解决局域网高频压测不通过的问题。 71 | 17. softAP配网函数增加超时机制,超时时间由传入的参数决定。 72 | 18. OTA升级url buffer的长度改为200字节,防止文件名过长导致内存越界。 73 | 19. 解决庆科平台有配网失败的问题。主要是增加client_fd >= 0的判断。 74 | 20. 解决兼容64bits的问题。 75 | 22. 解决代码检测工具扫描出的bug。 76 | 77 | -------------------------------------------------------------------------------- 78 | Version : 2.0.21 79 | Date : Fri Jan 10 17:37:39 2020 +0800 80 | Owner : liyanming10 81 | Description : 82 | 1、解决AUTH时长连接断开,不会重新建立连接,除非断电重启的问题。 83 | 2、解决套接字overflow的bug,体现在长连接成功了,但是设备无法接受云端下发的数据。 84 | 3、内存优化,优化堆空间,节省堆空间约18KB。 85 | 4、增加日志埋点的功能,方便排查设备离线问题。 86 | 87 | -------------------------------------------------------------------------------- 88 | VERSION:2.0.7 89 | HEAD:35fe9dd7501bf5754b8e7e5951ac527926dcd159 90 | DATE:04/24/18 91 | 92 | -------------------------------------------------------------------------------- 93 | 94 | Upgrade urgency levels: 95 | 96 | LOW: No need to upgrade unless there are new features you want to use. 97 | MODERATE: Program an upgrade of the server, but it's not urgent. 98 | HIGH: There is a critical bug that may affect a subset of users. Upgrade! 99 | CRITICAL: There is a critical bug affecting MOST USERS. Upgrade ASAP. 100 | 101 | -------------------------------------------------------------------------------- 102 | --[ joylink 1.3.3 ] Release date: 103 | 104 | # UPGRADE URGENCY: LOW for joylink. 105 | 106 | * [NEW] No. 107 | * [FIX] Add CID firmwareVersion modelCode in func joylink_package_scan 108 | * [FIX] Add productuuid in func joylink_parse_write_key 109 | ======================= 110 | 111 | ** IMPORTANT ** 112 | 113 | 114 | --[ joylink 1.3.3 ] Release date: 115 | 116 | # UPGRADE URGENCY: LOW for joylink. 117 | 118 | * [NEW] No. 119 | * [FIX] joylink_json.c:joylink_parse_scan, add cJSON_Delete(pJson); 120 | * [FIX] joylink_json.c:joylink_package_scan, del cJson_CreateArry; 121 | ======================= 122 | 123 | ** IMPORTANT ** 124 | 125 | -------------------------------------------------------------------------------- 126 | --[ joylink 1.3.2 ] Release date: 127 | 128 | # UPGRADE URGENCY: LOW for joylink. 129 | 130 | * [NEW] No. 131 | * [FIX] Add sdk/lua/example.lua sdk/lua/only_trans.lua 132 | * [FIX] Change var name in joylink.h 133 | ======================= 134 | 135 | ** IMPORTANT ** 136 | 137 | -------------------------------------------------------------------------------- 138 | --[ joylink 1.3.1 ] Release date: 139 | 140 | # UPGRADE URGENCY: LOW for joylink. 141 | 142 | * [NEW] Add big package cut and send ,but code is for debug. 143 | 144 | * [FIX] 145 | ======================= 146 | 147 | ** IMPORTANT ** 148 | 149 | -------------------------------------------------------------------------------- 150 | 151 | --[ joylink 1.3.0 ] Release date: 152 | 153 | # UPGRADE URGENCY: CRITICAL for joylink. 154 | 155 | * [FIX] Fix the error of joylink_parse_lan_write_key() 156 | 157 | * [FIX] Change .jlp.trantype = 0, to .jlp.trantype = 1 158 | 159 | Migrating from 1.2 to 1.3 160 | ========================= 161 | 162 | joylink_dev_sdk 1.2 is mostly a strict subset of 1.3. However there are a few things 163 | that you should be aware of: 164 | 165 | The following default attr changed: 166 | 167 | * .jlp.trantype = 1, means suport lua script. 168 | -------------------------------------------------------------------------------- 169 | 170 | joylink_dev_sdk 1.2 release notes 171 | ======================= 172 | 173 | ** IMPORTANT ** Check the 'Migrating from 1.1 to 1.2' section at the end of 174 | this file for information about what changed between 1.1 and 175 | 1.2 and how this may affect your application. 176 | 177 | -------------------------------------------------------------------------------- 178 | Upgrade urgency levels: 179 | 180 | LOW: No need to upgrade unless there are new features you want to use. 181 | MODERATE: Program an upgrade of the server, but it's not urgent. 182 | HIGH: There is a critical bug that may affect a subset of users. Upgrade! 183 | CRITICAL: There is a critical bug affecting MOST USERS. Upgrade ASAP. 184 | -------------------------------------------------------------------------------- 185 | 186 | --[ joylink 1.2.0 ] Release date: 14 Jul 2014 187 | 188 | # UPGRADE URGENCY: LOW for joylink , this is a features enhancement 189 | release mostly. 190 | 191 | * [FIX] Recive data that's len bigger than 1400 from server. (steven) 192 | 193 | * [NEW] The new OTA feature. (yangnan) 194 | 195 | Migrating from 1.1 to 1.2 196 | ========================= 197 | 198 | joylink_dev_sdk 1.1 is mostly a strict subset of 1.2. However there are a few things 199 | that you should be aware of: 200 | 201 | The following commands changed behavior: 202 | 203 | * XXXX. 204 | * YYYY. 205 | -------------------------------------------------------------------------------- 206 | 207 | Credits: 208 | Thanks to all the contributors and the amazing 209 | community we have. 210 | 211 | See commit messages for more joylink_dev_sdk. 212 | 213 | Cheers! 214 | -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/adapter/joylink_adapter.c: -------------------------------------------------------------------------------- 1 | #include "joylink_sdk.h" 2 | #include "joylink_platform.h" 3 | #include "joylink_adapter.h" 4 | 5 | #include 6 | #include 7 | 8 | #include "esp_wifi.h" 9 | #include "esp_system.h" 10 | #include "esp_partition.h" 11 | #include "tcpip_adapter.h" 12 | #include "esp_ota_ops.h" 13 | #include "sdkconfig.h" 14 | 15 | wifi_config_t jd_ble_config; 16 | bool get_rst = false; 17 | jl_net_config_data_t ble_net_cfg_data; 18 | 19 | extern int esp_ble_gatts_send_data(uint8_t*frame, int32_t frame_len); 20 | 21 | /************************************************* 22 | Function: jl_adapter_send_data 23 | Description: SDK适配接口,GATTS Characteristic发送数据 24 | Calls: GATTS Characteristic发送数据接口 25 | Called By: @jl_send_frame:SDK内部函数 26 | Input: @data:发送的数据 27 | @data_len:发送的数据长度 28 | Output: None 29 | Return: 0:成功 30 | -1:失败 31 | Others: 32 | *************************************************/ 33 | int32_t jl_adapter_send_data(uint8_t* data, uint32_t data_len) 34 | { 35 | int ret = 0; 36 | ret = esp_ble_gatts_send_data(data, data_len); 37 | return ret; 38 | } 39 | 40 | /************************************************* 41 | Function: jl_adapter_set_config_data 42 | Description: SDK适配接口,获取配网与绑定参数 43 | Calls: 配网与绑定接口 44 | Called By: @jl_process_user_data:SDK内部函数 45 | Input: @data->ssid:配网数据,WiFi SSID 46 | @data->ssid_len:WiFi SSID长度 47 | @data->password:配网数据,WiFi密码 48 | @data->password_len:WiFi密码长度 49 | @data->url:绑定云端链接 50 | @data->url_len:绑定云端链接长度 51 | @data->token:绑定参数 52 | @data->token_len:绑定参数长度 53 | Output: None 54 | Return: 0:成功 55 | -1:失败 56 | Others: 设置激活绑定接口:joylink_dev_active_start(data->url, data->token); 57 | *************************************************/ 58 | int32_t jl_adapter_set_config_data(jl_net_config_data_t *data) 59 | { 60 | int status = 0; 61 | ble_net_cfg_data.url = (uint8_t *) malloc(data->url_len + 1); 62 | ble_net_cfg_data.token = (uint8_t *) malloc(data->token_len + 1); 63 | 64 | strncpy((char *)ble_net_cfg_data.url, (char *)data->url, data->url_len + 1); 65 | strncpy((char *)ble_net_cfg_data.token, (char *)data->token, data->token_len + 1); 66 | 67 | memcpy(jd_ble_config.sta.ssid, data->ssid, strlen((char *)data->ssid)); 68 | memcpy(jd_ble_config.sta.password, data->password, strlen((char *)data->password)); 69 | 70 | printf("ble-url: %s\n", ble_net_cfg_data.url); 71 | printf("ble-token: %s\n", ble_net_cfg_data.token); 72 | //to do 73 | //joylink_dev_active_start(data->url, data->token); 74 | return status; 75 | } 76 | 77 | /************************************************* 78 | Function: jl_adapter_set_system_time 79 | Description: SDK适配接口,设置系统时间 80 | Calls: 设置系统时间接口 81 | Called By: SDK内部函数 82 | Input: @time->second:秒 83 | @time->usecond:微妙 84 | Output: None 85 | Return: 0:成功 86 | -1:失败 87 | Others: None 88 | *************************************************/ 89 | int32_t jl_adapter_set_system_time(jl_timestamp_t *time) 90 | { 91 | struct timeval now = { .tv_sec = time->second , .tv_usec = time->usecond}; 92 | settimeofday(&now, NULL); 93 | 94 | struct tm *lt; 95 | lt = localtime(<); 96 | printf("%d/%d/%d %d:%d:%d\n", lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); 97 | 98 | return 0; 99 | } -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/include/joylink_adapter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: joylink_adapter.h 3 | Revised: $Date: 2015-10-14 4 | Revision: $Revision: 1.0, Zhang Hua 5 | 6 | Description: This file contains the Joylink profile definitions and 7 | prototypes. 8 | 9 | Copyright 2010 - 2013 JD.COM. All rights reserved. 10 | 11 | **************************************************************************************************/ 12 | 13 | 14 | #ifndef __JOYLINK_ADAPTER_H__ 15 | #define __JOYLINK_ADAPTER_H__ 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | #include "joylink_sdk.h" 23 | 24 | typedef struct{ 25 | uint32_t second; 26 | uint32_t usecond; 27 | }jl_timestamp_t; 28 | 29 | /************************************************* 30 | Function: jl_adapter_send_data 31 | Description: SDK适配接口,GATTS Characteristic发送数据 32 | Calls: GATTS Characteristic发送数据接口 33 | Called By: @jl_send_frame:SDK内部函数 34 | Input: @data:发送的数据 35 | @data_len:发送的数据长度 36 | Output: None 37 | Return: 0:成功 38 | -1:失败 39 | Others: 40 | *************************************************/ 41 | int32_t jl_adapter_send_data(uint8_t *buf, uint32_t size); 42 | 43 | /************************************************* 44 | Function: jl_adapter_set_config_data 45 | Description: SDK适配接口,获取配网与绑定参数 46 | Calls: 配网与绑定接口 47 | Called By: @jl_process_user_data:SDK内部函数 48 | Input: @data->ssid:配网数据,WiFi SSID 49 | @data->ssid_len:WiFi SSID长度 50 | @data->password:配网数据,WiFi密码 51 | @data->password_len:WiFi密码长度 52 | @data->url:绑定云端链接 53 | @data->url_len:绑定云端链接长度 54 | @data->token:绑定参数 55 | @data->token_len:绑定参数长度 56 | Output: None 57 | Return: 0:成功 58 | -1:失败 59 | Others: 设置激活绑定接口:joylink_dev_active_start(data->url, data->token); 60 | *************************************************/ 61 | int32_t jl_adapter_set_config_data(jl_net_config_data_t *data); 62 | 63 | /************************************************* 64 | Function: jl_adapter_set_system_time 65 | Description: SDK适配接口,设置系统时间 66 | Calls: 设置系统时间接口 67 | Called By: SDK内部函数 68 | Input: @time->second:秒 69 | @time->usecond:微妙 70 | Output: None 71 | Return: 0:成功 72 | -1:失败 73 | Others: None 74 | *************************************************/ 75 | int32_t jl_adapter_set_system_time(jl_timestamp_t *time); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __JOYLINK_ADAPTER_H__ */ 82 | -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/include/joylink_platform.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: joylink_platform.h 3 | Revised: $Date: 2015-10-14 4 | Revision: $Revision: 1.0, Liao Ru Xian 5 | 6 | Description: This file contains the Joylink profile definitions and 7 | prototypes. 8 | 9 | Copyright 2010 - 2013 JD.COM. All rights reserved. 10 | 11 | **************************************************************************************************/ 12 | 13 | #ifndef __JOYLINK_PLATFORM_H__ 14 | #define __JOYLINK_PLATFORM_H__ 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | #include "joylink_stdio.h" 22 | #include "joylink_ret_code.h" 23 | #include "joylink_stdint.h" 24 | #include "joylink_string.h" 25 | #include "joylink_memory.h" 26 | #include "joylink_log.h" 27 | #include "joylink_thread.h" 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* __JOYLINK_PLATFORM_H__ */ 34 | -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/include/joylink_sdk.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_SDK_H__ 2 | #define __JOYLINK_SDK_H__ 3 | 4 | #include "joylink_platform.h" 5 | #include "joylink_utils.h" 6 | 7 | typedef struct{ 8 | uint8_t product_uuid[6]; 9 | uint8_t mac[6]; 10 | uint8_t shared_key[16];//if JL_SECURITY_LEVEL == 1 11 | }jl_dev_info_t; 12 | 13 | typedef struct{ 14 | uint8_t service_uuid16[2]; 15 | uint8_t manufacture_data[14]; 16 | }jl_gap_data_t; 17 | 18 | typedef struct{ 19 | uint8_t service_uuid128[16]; 20 | uint8_t chra_uuid128_write[16]; 21 | uint8_t chra_uuid128_indicate[16]; 22 | }jl_gatt_data_t; 23 | 24 | typedef enum { 25 | E_JL_CHRA_WRITE = 0x00, 26 | E_JL_CHRA_WRITE_NR = 0x01, 27 | }JL_CHRA_TYPE_E; 28 | 29 | //设备给手机返回状态 30 | typedef enum 31 | { 32 | E_JL_NET_CONF_ST_WIFI_CONNECT_FAILED = 0x00, //WiFi连接失败 33 | E_JL_NET_CONF_ST_WIFI_CONNECT_START = 0x01, //开始连接WiFi 34 | E_JL_NET_CONF_ST_WIFI_CONNECT_SUCCEED = 0x02, //WiFi连接成功 35 | E_JL_NET_CONF_ST_WIFI_CONNECT_TIMEOUT = 0x03, //WiFi连接超时,手机APP有超时设置,可以不用该状态 36 | E_JL_NET_CONF_ST_WIFI_CONNECT_SSID_ERROR = 0x04, //WiFi SSID错误,比如:搜索不到该SSID等 37 | E_JL_NET_CONF_ST_WIFI_CONNECT_PSK_ERROR = 0x05, //WiFi密码错误 38 | E_JL_NET_CONF_ST_WIFI_CONNECT_WAN_ERROR = 0x06, //WiFi无法连接广域网 39 | E_JL_NET_CONF_ST_IOT_CONNECT_TIMEOUT = 0x07, //IOT连接超时,手机APP有超时设置,可以不用该状态 40 | E_JL_NET_CONF_ST_IOT_CONNECT_FAILED = 0x08, //IOT连接失败 41 | E_JL_NET_CONF_ST_IOT_CONNECT_SUCCEED = 0x09, //IOT连接成功,发送状态时,data需要带feedid,长度是18 42 | E_JL_NET_CONF_ST_CLOUD_CONNECT_TIMEOUT = 0x0A, //云端连接超时 43 | E_JL_NET_CONF_ST_CLOUD_CONNECT_SUCCEED = 0x0B, //云端连接成功,设备如果没有其他云需要连接(如JAVS云),就在发送IoT连接成功后接着发该消息 44 | E_JL_NET_CONF_ST_TIMEOUT_EXIT = 0x0C, //设备超时退出配网,设备不会一直处于配网状态,超时时间根据产品需求自定义 45 | E_JL_NET_CONF_ST_EXIT = 0x0D, //设备退出配网,例如用户按键等操作让设备退出配网 46 | }E_JL_NET_CONF_ST; 47 | 48 | typedef struct 49 | { 50 | uint8_t *ssid; 51 | uint8_t ssid_len; 52 | 53 | uint8_t *password; 54 | uint8_t password_len; 55 | 56 | uint8_t *url; 57 | uint8_t url_len; 58 | 59 | uint8_t *token; 60 | uint8_t token_len; 61 | }jl_net_config_data_t; 62 | 63 | #define jl_data_handle_t void* 64 | 65 | #define JL_GAP_SERVICE_UUID16 {0x70, 0xFE} 66 | #define JL_GATT_SERVICE_UUID128 {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x70, 0xFE, 0x00, 0x00} 67 | #define JL_GATT_CHRA_UUID128_WRITE {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x71, 0xFE, 0x00, 0x00} 68 | #define JL_GATT_CHRA_UUID128_INDICATE {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x72, 0xFE, 0x00, 0x00} 69 | 70 | /************************************************* 71 | Function: jl_init 72 | Description: SDK初始化 73 | Calls: SDK内部函数 74 | Called By: 一般是调用其他SDK接口之前调用 75 | Input: @dev_info->product_uuid: 产品ID,在基本信息界面获取 76 | @dev_info->mac: 设备端Mac 77 | @dev_info->license: 需要在设备端开发界面,点击导入Mac生成license按钮, 78 | 每个Mac都有对应的license key 79 | @dev_info->shared_key: 加密共享秘钥,基本信息界面选择安全级别是1才会使用 80 | Output: None 81 | Return: 0:成功 82 | -1:失败 83 | Others: 上电后调用其他SDK之前,必须要先初始化, 84 | 查看以上界面:小京鱼.IoT开发平台-控制中心-IoT控制台-产品中心-产品管理-编辑 85 | *************************************************/ 86 | int32_t jl_init(jl_dev_info_t *dev_info); 87 | 88 | 89 | /************************************************* 90 | Function: jl_deinit 91 | Description: SDK反初始化 92 | Calls: SDK内部函数 93 | Called By: SDK使用结束 94 | Input: None 95 | Output: None 96 | Return: 0:成功 97 | -1:失败 98 | Others: None 99 | *************************************************/ 100 | int32_t jl_deinit(); 101 | 102 | 103 | /************************************************* 104 | Function: jl_disconnet_reset 105 | Description: BLE断开后调用该接口释放SDK与通信相关的资源。 106 | Calls: SDK内部函数 107 | Called By: BLE断开后调用 108 | Input: None 109 | Output: None 110 | Return: 0:成功 111 | -1:失败 112 | Others: None 113 | *************************************************/ 114 | int32_t jl_disconnet_reset(); 115 | 116 | /************************************************* 117 | Function: jl_get_gap_config_data 118 | Description: 获取gap信息,添加service uuid和manufacturer data 119 | Calls: SDK内部函数 120 | Called By: 一般是设置gatt前调用 121 | Input: @gap_data->service_uuid16: service uuid 长度2字节 122 | @gap_data->manufacture_data: 厂商数据,长度14字节 123 | Output: None 124 | Return: 0:成功 125 | -1:失败 126 | Others: 广播包里必须包含这两个信息才能被识别 127 | *************************************************/ 128 | int32_t jl_get_gap_config_data(jl_gap_data_t *gap_data); 129 | 130 | 131 | /************************************************* 132 | Function: jl_get_gatt_config_data 133 | Description: 获取gatt配置信息 134 | Calls: None 135 | Called By: 一般是设置gap广播包前调用 136 | Input: @gatt_data->service_uuid128:service uuid值,长度:16字节 137 | @gatt_data->chra_uuid128_write:service characteristic uuid值,长度:16字节,属性:write 138 | @gatt_data->chra_uuid128_indicate:service characteristic uuid值,长度:16字节,属性:indicate 139 | Output: None 140 | Return: 0:成功 141 | -1:失败 142 | Others: 必须添加service和characteristic才能通信 143 | *************************************************/ 144 | int32_t jl_get_gatt_config_data(jl_gatt_data_t *gatt_data); 145 | 146 | 147 | /************************************************* 148 | Function: jl_write_data 149 | Description: ble characteristic通道接收到的数据调用该函数处理 150 | Calls: SDK内部函数 151 | Called By: 一般是收到WRITE事件后调用 152 | Input: @data: 数据指针 153 | @data_len: 数据长度 154 | Output: None 155 | Return: 0:成功 156 | -1:失败 157 | Others: None 158 | *************************************************/ 159 | int32_t jl_write_data(uint8_t* data, int32_t data_len); 160 | 161 | 162 | /************************************************* 163 | Function: jl_send_confirm 164 | Description: ble indicate通道发送数据成功后会返回confirm事件调用该函数通知SDK发送成功 165 | Calls: SDK内部函数 166 | Called By: 收到confirm事件后调用 167 | Input: None 168 | Output: None 169 | Return: 0:成功 170 | -1:失败 171 | Others: 如果数据发送成功后协议栈底层会返回事件,在该事件里调用jl_send_confirm后接着发下一帧数据不会阻塞, 172 | 所以不需要在jl_send_thread线程发送数据了 173 | *************************************************/ 174 | int32_t jl_send_confirm(void); 175 | 176 | 177 | /************************************************* 178 | Function: jl_send_thread 179 | Description: 发送数据线程,该线程会持续发送SDK里的数据,发完后会阻塞进程等待新数据发送, 180 | 所以需要在单独线程中运行才不会阻塞进程或线程 181 | Calls: SDK内部函数 182 | Called By: 线程函数 183 | Input: None 184 | Output: None 185 | Return: 0:成功 186 | -1:失败 187 | Others: 如果发送数据成功后协议栈底层不会返回事件,需要在其他线程里依次发数据 188 | *************************************************/ 189 | void * jl_send_thread(void *arg); 190 | 191 | 192 | /************************************************* 193 | Function: jl_send_net_config_state 194 | Description: 发送配网状态给APP 195 | Calls: SDK内部函数 196 | Called By: 配网状态改变之后 197 | Input: @st: 配网状态 198 | Input: @data: 目前只有st是E_JL_NET_CONF_ST_IOT_CONNECT_SUCCEED,才会带有数据,该数据是feedid 199 | Input: @data_len: 数据长度 200 | Output: None 201 | Return: 0:成功 202 | -1:失败 203 | Others: None 204 | *************************************************/ 205 | int32_t jl_send_net_config_state(E_JL_NET_CONF_ST st, uint8_t* data, int32_t data_len); 206 | #endif 207 | 208 | -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/include/joylink_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_UTILS_H__ 2 | #define __JOYLINK_UTILS_H__ 3 | 4 | #include "joylink_platform.h" 5 | 6 | /** 7 | * brief: 8 | * 9 | * @Param: pBytes 10 | * @Param: srcLen 11 | * @Param: pDstStr 12 | * @Param: dstLen 13 | * 14 | * @Returns: 15 | */ 16 | int jl_util_reverse_buf(const uint8_t *src, uint8_t *dst, int32_t len); 17 | 18 | int jl_util_byte2hexstr(const uint8_t *pBytes, int32_t srcLen, uint8_t *pDstStr, int32_t dstLen); 19 | 20 | 21 | int jl_util_byte2hexcapstr(const uint8_t *pBytes, int32_t srcLen, uint8_t *pDstStr, int32_t dstLen); 22 | 23 | /** 24 | * brief: 25 | * 26 | * @Param: buf 27 | * @Param: buf_len 28 | * @Param: value 29 | * @Param: value_len 30 | * 31 | * @Returns: 32 | */ 33 | int jl_util_str2byte(const uint8_t *buf, int32_t buf_len, void *value, int32_t value_len); 34 | 35 | 36 | /** 37 | * brief: 38 | * 39 | * @Param: hexStr 40 | * @Param: buf 41 | * @Param: bufLen 42 | * 43 | * @Returns: 44 | */ 45 | int jl_util_hexStr2bytes(const char *hexStr, uint8_t *buf, int32_t bufLen); 46 | 47 | 48 | /** 49 | * @name:jl_util_random_buf 50 | * 51 | * @param: dest 52 | * @param: size 53 | * 54 | * @returns: 55 | */ 56 | int32_t jl_util_random_buf(uint8_t *dest, unsigned size); 57 | 58 | /** 59 | * @name:jl_util_print_buffer 60 | * 61 | * @param: msg 62 | * @param: is_fmt 63 | * @param: num_line 64 | * @param: buff 65 | * @param: len 66 | */ 67 | void jl_util_print_buffer(const char *msg, int32_t is_fmt, int32_t num_line, const char *buff, int32_t len); 68 | 69 | 70 | #define JL_UTILS_P_FMT (1) 71 | #define JL_UTILS_P_NO_FMT (0) 72 | 73 | #define joylink_util_fmt_p(msg, buff, len) jl_util_print_buffer(msg, JL_UTILS_P_FMT, 20, (char *)buff, len) 74 | 75 | #endif /* __JOYLINK_UTILS_H__ */ 76 | -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/target/lib/esp32/libjoylinkblesdk.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/ble_sdk/target/lib/esp32/libjoylinkblesdk.a -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/target/lib/esp32c3/libjoylinkblesdk.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/ble_sdk/target/lib/esp32c3/libjoylinkblesdk.a -------------------------------------------------------------------------------- /joylink_dev_sdk/ble_sdk/target/lib/esp32s3/libjoylinkblesdk.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/ble_sdk/target/lib/esp32s3/libjoylinkblesdk.a -------------------------------------------------------------------------------- /joylink_dev_sdk/example/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = .. 2 | include ${TOP_DIR}/scripts/config.mk 3 | 4 | TARGET_DIR = ${TOP_DIR}/target 5 | TARGET_LIB = ${TARGET_DIR}/lib 6 | TARGET_BIN = ${TARGET_DIR}/bin 7 | 8 | INCLUDE_DIRS = $(shell ls -l ../joylink/inc | grep ^d | awk '{print $$9}') 9 | ORG_SOURCES = $(wildcard *.c) 10 | #OUT_SRC = test.c 11 | OUT_SRC = 12 | 13 | SOURCES=$(filter-out ${OUT_SRC}, ${ORG_SOURCES}) 14 | OBJS = $(patsubst %.c, %.o, $(SOURCES)) 15 | 16 | LIBNAME = lib$(strip ${shell pwd |xargs basename}) 17 | 18 | CFLAGS += -I../joylink/inc 19 | CFLAGS += -I../pal/inc 20 | CFLAGS += $(addprefix -I../joylink/inc/,${INCLUDE_DIRS}) 21 | 22 | LIBS += ../joylink/lib/libjoylink.a 23 | LIBS += -lpal 24 | 25 | ifeq (${ARCH}, x86) 26 | LIBS += -lpthread -lm 27 | all:${OBJS} liba libso 28 | else 29 | all:${OBJS} liba 30 | endif 31 | 32 | 33 | jt:${OBJS} 34 | ${CC} ${OBJS} -o $@ -L${TARGET_LIB} ${LIBS} ${LDFLAGS} 35 | $(STRIP) $@ 36 | ${MV} $@ ${TARGET_BIN} 37 | 38 | liba:${OBJS} 39 | @echo ------------------ 40 | @echo ${SOURCES} 41 | @echo ------------------ 42 | @echo ${OUT_SRC} 43 | @echo ------------------ 44 | ${AR} -crs ${LIBNAME}.a ${OBJS} 45 | @echo ------------------ 46 | ${MV} ${LIBNAME}.a ${TARGET_LIB} 47 | 48 | libso:${OBJS} 49 | ${CC} ${OBJS} -shared -fPIC -o ${LIBNAME}.so 50 | ${MV} ${LIBNAME}.so ${TARGET_LIB} 51 | 52 | clean: 53 | ${RM} ${OBJS} *.i *.s $(wildcard src/*.d) $(wildcard src/*/*.d) $(wildcard src/*.su) $(wildcard src/*/*.su) 54 | 55 | $(OBJS):%.o:%.c 56 | $(CC) $(CFLAGS) -c $< -o $@ 57 | 58 | distclean:clean 59 | ${RM} ${TARGET_LIB}/* 60 | 61 | .PHONY:all clean test jt 62 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/joylink_extern.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_EXTERN_H_ 2 | #define _JOYLINK_EXTERN_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif /* __cplusplus */ 7 | 8 | #include "joylink.h" 9 | 10 | /* 11 | * user set 12 | */ 13 | #define JLP_VERSION 0 14 | /* 15 | * Create dev and get the index from developer center 16 | */ 17 | 18 | #define JLP_DEV_TYPE E_JLDEV_TYPE_NORMAL 19 | #define JLP_LAN_CTRL E_LAN_CTRL_ENABLE 20 | #define JLP_CMD_TYPE E_CMD_TYPE_LUA_SCRIPT 21 | #define JLP_SNAPSHOT E_SNAPSHOT_NO 22 | 23 | #ifdef JOYLINK_SDK_EXAMPLE_TEST 24 | #define JLP_UUID "363282" 25 | #define IDT_CLOUD_PUB_KEY "0283866FBE020E880A0D004C7253A5FED07EBEEB618DB4149098F98ED8E5CEF244" 26 | 27 | #define JLP_CHIP_MODEL_CODE "" 28 | 29 | #define USER_DATA_POWER "Power" 30 | #define USER_DATA_MODE "Mode" 31 | #define USER_DATA_STATE "State" 32 | 33 | typedef struct _user_dev_status_t { 34 | int Power; 35 | int Mode; 36 | int State; 37 | } user_dev_status_t; 38 | #else 39 | #define JLP_UUID "" 40 | #define IDT_CLOUD_PUB_KEY "" 41 | 42 | #define JLP_CHIP_MODEL_CODE "" 43 | 44 | typedef struct _user_dev_status_t { 45 | 46 | } user_dev_status_t; 47 | #endif 48 | 49 | 50 | typedef enum _JL_OTA_UPGRADE_TYPE_E{ 51 | JL_OTA_UPGRADE_TYPE_PROMPT = 1, 52 | JL_OTA_UPGRADE_TYPE_SILENT = 2, 53 | JL_OTA_UPGRADE_TYPE_ENFORCE = 3 54 | }JL_OTA_UPGRADE_TYPE_E; 55 | 56 | typedef struct{ 57 | int serial; 58 | char feedid[JL_MAX_FEEDID_LEN]; 59 | char productuuid[JL_MAX_UUID_LEN]; 60 | int version; 61 | char versionname[JL_MAX_VERSION_NAME_LEN]; 62 | unsigned int crc32; 63 | char url[JL_MAX_URL_LEN]; 64 | JL_OTA_UPGRADE_TYPE_E upgradetype; 65 | }JLOtaOrder_t; 66 | 67 | /** 68 | * @brief: 此函数需返回设备的MAC地址 69 | * 70 | * @param[out] out: 将设备MAC地址赋值给此参数 71 | * 72 | * @returns: E_RET_OK 成功, E_RET_ERROR 失败 73 | */ 74 | E_JLRetCode_t joylink_dev_get_user_mac(char *out); 75 | 76 | /** 77 | * @brief: 此函数需返回设备私钥private key,该私钥可从小京鱼后台获取 78 | * 79 | * @param[out] out: 将私钥字符串赋值给该参数返回 80 | * 81 | * @returns: E_RET_OK:成功, E_RET_ERROR:发生错误 82 | */ 83 | E_JLRetCode_t joylink_dev_get_private_key(char *out); 84 | 85 | /** 86 | * @brief: 根据传入的cmd值,设置对应设备属性 87 | * 88 | * @param[in] cmd: 设备属性名称 89 | * @param[out] user_data: 设备状态结构体 90 | * 91 | * @returns: 0:设置成功 92 | */ 93 | E_JLRetCode_t joylink_dev_user_data_set(char *cmd, user_dev_status_t *user_data); 94 | 95 | /** 96 | * @brief: 返回是否可以访问互联网 97 | * 98 | * @returns: E_JL_TRUE 可以访问, E_JL_FALSE 不可访问 99 | */ 100 | E_JLBOOL_t joylink_dev_is_net_ok(); 101 | 102 | /** 103 | * @brief: 此函数用作通知应用层设备与云端的连接状态. 104 | * 105 | * @param: st - 当前连接状态 0-Socket init, 1-Authentication, 2-Heartbeat 106 | * 107 | * @returns: 108 | */ 109 | E_JLRetCode_t joylink_dev_set_connect_st(int st); 110 | 111 | /** 112 | * @brief: 存储JLP(Joylink Parameters)信息,将入参jlp结构中的信息持久化存储,如文件、设备flash等方式 113 | * 114 | * @param [in]: jlp-JLP structure pointer 115 | * 116 | * @returns: 117 | */ 118 | E_JLRetCode_t joylink_dev_set_attr_jlp(JLPInfo_t *jlp); 119 | 120 | /** 121 | * @brief: 从永久存储介质(文件或flash)中读取jlp信息,并赋值给参数jlp,其中feedid, accesskey,localkey,joylink_server,server_port必须正确赋值 122 | * 123 | * @param[out] jlp: 将JLP(Joylink Parameters)读入内存,并赋值给该参数 124 | * 125 | * @returns: E_RET_OK:成功, E_RET_ERROR:发生错误 126 | */ 127 | E_JLRetCode_t joylink_dev_get_jlp_info(JLPInfo_t *jlp); 128 | 129 | /** 130 | * @brief: 返回包含model_code的json结构,该json结构的字符串形式由joylink_dev_modelcode_info(小京鱼后台自动生成代码,其中已经包含model_code)返回 131 | * 132 | * @param[out]: out_modelcode 用以返回序列化为字符串的model_code json结构 133 | * @param[in]: out_max json结构的最大允许长度 134 | * 135 | * @returns: 实际写入out_modelcode的长度 136 | */ 137 | int joylink_dev_get_modelcode(JLPInfo_t *jlp, char *out_modelcode, int32_t out_max); 138 | 139 | /** 140 | * @brief: 获取设备快照json结构 141 | * 142 | * @param[out] out_snap: 序列化为字符串的设备快照json结构 143 | * @param[in] out_max: out_snap可写入的最大长度 144 | * 145 | * @returns: 实际写入out_snap的数据长度 146 | */ 147 | int joylink_dev_get_snap_shot(char *out_snap, int32_t out_max); 148 | 149 | /** 150 | * @brief: 获取向App返回的设备快照json结构 151 | * 152 | * @param[out] out_snap: 序列化为字符串的设备快照json结构 153 | * @param[in] out_max: out_snap允许写入的最大长度 154 | * @param[in] code: 返回状态码 155 | * @param[in] feedid: 设备的feedid 156 | * 157 | * @returns: 158 | */ 159 | int joylink_dev_get_json_snap_shot(char *out_snap, int32_t out_max, int code, char *feedid); 160 | 161 | /** 162 | * @brief: 通过App控制设备,需要实现此函数,根据传入的json_cmd对设备进行控制 163 | * 164 | * @param[in] json_cmd: 设备控制命令 165 | * 166 | * @returns: E_RET_OK 控制成功, E_RET_ERROR 发生错误 167 | */ 168 | E_JLRetCode_t joylink_dev_lan_json_ctrl(const char *json_cmd); 169 | 170 | /** 171 | * @brief:根据src参数传入的控制命令数据包对设备进行控制.调用joylink_dev_parse_ctrl进行控制命令解析,并更改设备属性值 172 | * 173 | * @param[in] src: 控制指令数据包 174 | * @param[in] src_len: src长度 175 | * @param[in] ctr: 控制码 176 | * @param[in] from_server: 是否来自server控制 0-App,2-Server 177 | * 178 | * @returns: E_RET_OK 成功, E_RET_ERROR 失败 179 | */ 180 | E_JLRetCode_t joylink_dev_script_ctrl(const char *src, int src_len, JLContrl_t *ctr, int from_server); 181 | 182 | /** 183 | * @brief: 实现接收到ota命令和相关参数后的动作,可使用otaOrder提供的参数进行具体的OTA操作 184 | * 185 | * @param[in] otaOrder: OTA命令结构体 186 | * 187 | * @returns: E_RET_OK 成功, E_RET_ERROR 发生错误 188 | */ 189 | E_JLRetCode_t joylink_dev_ota(JLOtaOrder_t *otaOrder); 190 | 191 | /** 192 | * @brief: OTA执行状态上报,无需返回值 193 | */ 194 | void joylink_dev_ota_status_upload(); 195 | 196 | 197 | /** 198 | * @brief: 设置设备认证信息 199 | * 200 | * @param[out]: pidt--设备认证信息结构体指针,需填入必要信息sig,pub_key,f_sig,f_pub_key,cloud_pub_key 201 | * 202 | * @returns: 返回设置成功或失败 203 | */ 204 | E_JLRetCode_t joylink_dev_get_idt(jl2_d_idt_t *pidt); 205 | 206 | /** 207 | * @brief: 用以返回一个整型随机数 208 | * 209 | * @param: 无 210 | * 211 | * @returns: 整型随机数 212 | */ 213 | int joylink_dev_get_random(); 214 | 215 | /** 216 | * @brief: SDK main loop 运行状态报告,正常情况下此函数每5秒会被调用一次,可以用来判断SDK主任务的运行状态. 217 | * 218 | * @param[in] status: SDK main loop运行状态 0正常, -1异常 219 | * 220 | * @return: 221 | */ 222 | int joylink_dev_run_status(JLRunStatus_t status); 223 | 224 | /** 225 | * @brief: 每间隔1个main loop周期此函数将在SDK main loop中被调用,让用户有机会将代码逻辑运行在核心任务中. 226 | * 227 | * @note: 正常情况下一个main loop周期为1s(取决于socket等待接收数据的timeout时间),但不保证精度,请勿用作定时器 228 | * @note: 仅用作关键的非阻塞任务执行,例如OTA状态上报或设备状态上报. 229 | * @note: 执行阻塞或耗时较多的代码,将会妨碍主task运行. 230 | */ 231 | void joylink_dev_run_user_code(); 232 | 233 | /** 234 | * @brief: 传出激活信息 235 | * 236 | * @param[in] message: 激活信息 237 | * 238 | * @returns: 0:设置成功 239 | */ 240 | E_JLRetCode_t joylink_dev_active_message(char *message); 241 | 242 | /** 243 | * brief: 设置局域网待激活模式 244 | * 245 | * @param[in] on_off: 1, 开启激活模式; 0, 关闭激活模式 246 | */ 247 | void joylink_dev_lan_active_switch(uint8_t on_off); 248 | 249 | /* 记录错误类型的统计,每种错误类型单独统计错误次数,最多纪录MAX_SIZE种错误类型的数据。*/ 250 | #define MAX_SIZE 10 251 | 252 | typedef struct failedinfo{ 253 | int times; //错误次数 254 | int code; //错误码 255 | char des[32]; //错误描述 256 | }failedinfo_t; 257 | 258 | /******************************接口用于模组连接ap失败 begin*********************************/ 259 | /** 260 | * @brief: 存储模组连接ap失败信息. 261 | * 262 | * @note: 在连接ap失败后调用,将错误码code与错误描述des写入flash保存。 263 | * 264 | * @param[in] code: 错误码 265 | * 266 | * @param[in] des: 错误描述 267 | * 268 | * @returns: 0 存储成功, -1 存储失败 269 | */ 270 | int joylink_set_fac_ap_con_failinfo(int code, char* des); 271 | 272 | /** 273 | * @brief: 读取模组连接ap失败信息. 274 | * 275 | * @note: 上报错误日志前调用,读取flash中的错误信息。 276 | * 277 | * @param[out] info: 错误信息结构体指针 278 | * 279 | * @returns: 读取成功,返回size, 读取失败,返回-1. 280 | */ 281 | int joylink_get_fac_ap_con_failinfo(failedinfo_t* info); 282 | 283 | 284 | /** 285 | * brief: 设置认证方式。 286 | * 287 | * @param[in] mode: 0, 单向认证; 1, 双向认证。 // 默认为双向认证。 288 | */ 289 | extern void joylink_set_device_auth_mode(uint8_t mode); 290 | 291 | /** 292 | * @brief: 检测设备是否绑定,不能检测子设备是否绑定 293 | * 294 | * 295 | * @returns: 1, 已绑定;0, 未绑定;-1, 检测出错。 296 | */ 297 | int joylink_dev_check_bind_status(void); 298 | 299 | #ifdef __cplusplus 300 | } 301 | #endif 302 | 303 | #endif 304 | 305 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/joylink_extern_json.c: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @brief: 3 | * 4 | * @version: 1.0 5 | * 6 | * @date: 08/01/2018 7 | * 8 | * @author: 9 | * -------------------------------------------------- 10 | */ 11 | #include 12 | #include 13 | #include 14 | #include "cJSON.h" 15 | 16 | #include "joylink_log.h" 17 | #include "joylink_extern.h" 18 | #include "joylink_memory.h" 19 | #include "joylink_socket.h" 20 | #include "joylink_string.h" 21 | #include "joylink_stdio.h" 22 | #include "joylink_stdint.h" 23 | #include "joylink_time.h" 24 | 25 | /** 26 | * brief: 27 | * 28 | * @Param: pMsg 29 | * @Param: user_dev 30 | * 31 | * @Returns: 32 | */ 33 | int 34 | joylink_dev_parse_ctrl(const char *pMsg, user_dev_status_t *userDev) 35 | { 36 | int ret = -1; 37 | if(NULL == pMsg || NULL == userDev){ 38 | goto RET; 39 | } 40 | log_debug("json_org:%s", pMsg); 41 | cJSON * pSub; 42 | cJSON * pJson = cJSON_Parse(pMsg); 43 | 44 | if(NULL == pJson){ 45 | log_error("--->:ERROR: pMsg is NULL\n"); 46 | goto RET; 47 | } 48 | 49 | cJSON *pStreams = cJSON_GetObjectItem(pJson, "streams"); 50 | if(NULL != pStreams){ 51 | int iSize = cJSON_GetArraySize(pStreams); 52 | int iCnt; 53 | for( iCnt = 0; iCnt < iSize; iCnt++){ 54 | pSub = cJSON_GetArrayItem(pStreams, iCnt); 55 | if(NULL == pSub){ 56 | continue; 57 | } 58 | 59 | cJSON *pSId = cJSON_GetObjectItem(pSub, "stream_id"); 60 | if(NULL == pSId){ 61 | break; 62 | } 63 | cJSON *pV = cJSON_GetObjectItem(pSub, "current_value"); 64 | if(NULL == pV){ 65 | continue; 66 | } 67 | #ifdef JOYLINK_SDK_EXAMPLE_TEST 68 | if(!jl_platform_strcmp(USER_DATA_POWER, pSId->valuestring)){ 69 | if(pV->type == cJSON_String){ 70 | userDev->Power = jl_platform_atoi(pV->valuestring); 71 | } 72 | else if(pV->type == cJSON_Number){ 73 | userDev->Power = pV->valueint; 74 | } 75 | joylink_dev_user_data_set( USER_DATA_POWER,userDev); 76 | } 77 | if(!jl_platform_strcmp(USER_DATA_MODE, pSId->valuestring)){ 78 | if(pV->type == cJSON_String){ 79 | userDev->Mode = jl_platform_atoi(pV->valuestring); 80 | } 81 | else if(pV->type == cJSON_Number){ 82 | userDev->Mode = pV->valueint; 83 | } 84 | joylink_dev_user_data_set( USER_DATA_MODE,userDev); 85 | } 86 | if(!jl_platform_strcmp(USER_DATA_STATE, pSId->valuestring)){ 87 | if(pV->type == cJSON_String){ 88 | userDev->State = jl_platform_atoi(pV->valuestring); 89 | } 90 | else if(pV->type == cJSON_Number){ 91 | userDev->State = pV->valueint; 92 | } 93 | joylink_dev_user_data_set( USER_DATA_STATE,userDev); 94 | } 95 | #endif 96 | 97 | char *dout = cJSON_PrintUnformatted(pSub); 98 | if(NULL != dout){ 99 | log_debug("org streams:%s", dout); 100 | jl_platform_free(dout); 101 | } 102 | } 103 | } 104 | cJSON_Delete(pJson); 105 | RET: 106 | return ret; 107 | } 108 | 109 | /** 110 | * brief: 111 | * NOTE: If return is not NULL, 112 | * must free it, after use. 113 | * 114 | * @Param: retMsg 115 | * @Param: retCode 116 | * @Param: wci 117 | * @Param: devlist 118 | * 119 | * @Returns: char * 120 | */ 121 | char * 122 | joylink_dev_package_info(const int retCode, user_dev_status_t *userDev) 123 | { 124 | if(NULL == userDev){ 125 | return NULL; 126 | } 127 | cJSON *root, *arrary; 128 | char *out = NULL; 129 | 130 | root = cJSON_CreateObject(); 131 | if(NULL == root){ 132 | goto RET; 133 | } 134 | arrary = cJSON_CreateArray(); 135 | if(NULL == arrary){ 136 | cJSON_Delete(root); 137 | goto RET; 138 | } 139 | cJSON_AddNumberToObject(root, "code", retCode); 140 | cJSON_AddItemToObject(root, "streams", arrary); 141 | 142 | #ifdef JOYLINK_SDK_EXAMPLE_TEST 143 | char i2str[64]; 144 | cJSON *data_Power = cJSON_CreateObject(); 145 | cJSON_AddItemToArray(arrary, data_Power); 146 | cJSON_AddStringToObject(data_Power, "stream_id", "Power"); 147 | jl_platform_memset(i2str, 0, sizeof(i2str)); 148 | jl_platform_sprintf(i2str, "%d", userDev->Power); 149 | cJSON_AddStringToObject(data_Power, "current_value", i2str); 150 | 151 | cJSON *data_Mode = cJSON_CreateObject(); 152 | cJSON_AddItemToArray(arrary, data_Mode); 153 | cJSON_AddStringToObject(data_Mode, "stream_id", "Mode"); 154 | jl_platform_memset(i2str, 0, sizeof(i2str)); 155 | jl_platform_sprintf(i2str, "%d", userDev->Mode); 156 | cJSON_AddStringToObject(data_Mode, "current_value", i2str); 157 | 158 | cJSON *data_State = cJSON_CreateObject(); 159 | cJSON_AddItemToArray(arrary, data_State); 160 | cJSON_AddStringToObject(data_State, "stream_id", "State"); 161 | jl_platform_memset(i2str, 0, sizeof(i2str)); 162 | jl_platform_sprintf(i2str, "%d", userDev->State); 163 | cJSON_AddStringToObject(data_State, "current_value", i2str); 164 | #endif 165 | 166 | out=cJSON_PrintUnformatted(root); 167 | cJSON_Delete(root); 168 | RET: 169 | return out; 170 | } 171 | 172 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/joylink_extern_json.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_json.h 3 | * 4 | * @brief: 5 | * 6 | * @version: 1.0 7 | * 8 | * @date: 10/26/2015 02:21:59 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #ifndef __JOYLINK_EXTERN_JSON__ 14 | #define __JOYLINK_EXTERN_JSON__ 15 | 16 | #include "joylink_extern.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C"{ 20 | #endif /* __cplusplus */ 21 | 22 | /** 23 | * brief: 24 | * 25 | * @Param: pCtrl 26 | * @Param: pMsg 27 | * 28 | * @Returns: 29 | */ 30 | int 31 | joylink_dev_parse_ctrl(const char * pMsg, user_dev_status_t *userDev); 32 | 33 | /** 34 | * brief: 35 | * 36 | * @Param: retCode 37 | * @Param: pCtrl 38 | * 39 | * @Returns: 40 | */ 41 | char * 42 | joylink_dev_package_info(const int retCode, user_dev_status_t *userDev); 43 | 44 | /** 45 | * brief: 46 | * 47 | * @Param: retCode 48 | * @Param: pCtrl 49 | * 50 | * @Returns: 51 | */ 52 | char * 53 | joylink_dev_modelcode_info(const int retCode, JLPInfo_t *userDev); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif /* __cplusplus */ 58 | #endif 59 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/joylink_extern_ota.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_ota.h 3 | * 4 | * @brief: 5 | * 6 | * @version: 2.0 7 | * 8 | * @date: 2018/07/26 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #ifndef _JOYLINK_EXTERN_OTA_H_ 14 | #define _JOYLINK_EXTERN_OTA_H_ 15 | 16 | #ifdef __cplusplus 17 | extern "C"{ 18 | #endif 19 | 20 | #include "joylink_extern.h" 21 | 22 | //#define HTTP_URL "http://storage.360buyimg.com/devh5/micapp_ota_9_1532350290755.bin" 23 | 24 | #define OTA_STATUS_DOWNLOAD 0 25 | #define OTA_STATUS_INSTALL 1 26 | #define OTA_STATUS_SUCCESS 2 27 | #define OTA_STATUS_FAILURE 3 28 | 29 | //#define OTA_PACKET_NUMB 1 30 | 31 | #define HTTP_DEFAULT_PORT 80 32 | 33 | #define EVERY_PACKET_LEN 1024 34 | 35 | #define OTA_TIME_OUT (5 * 60 * 1000) 36 | 37 | #define HTTP_GET "GET /%s HTTP/1.1\r\nHOST: %s\r\nAccept: */*\r\n\r\n" 38 | 39 | typedef struct _http_ota_st 40 | { 41 | char url[256]; 42 | 43 | char host_name[64]; 44 | int host_port; 45 | 46 | char file_path[64]; 47 | char file_name[64]; 48 | 49 | long int file_size; 50 | long int file_offset; 51 | 52 | int finish_percent; 53 | } http_ota_st; 54 | 55 | 56 | void *joylink_ota_task(void *data); 57 | 58 | void joylink_set_ota_info(JLOtaOrder_t *ota_info); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/joylink_extern_sub_dev.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_EXTERN_SUB_DEV_H_ 2 | #define _JOYLINK_EXTERN_SUB_DEV_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif /* __cplusplus */ 7 | 8 | #include "joylink.h" 9 | #include "joylink_sub_dev.h" 10 | 11 | /* 12 | * user set 13 | */ 14 | 15 | #define DEV_AUTH_VALUE 0 // 0: disable; 1: enable. 16 | #define DEV_BATCH_BIND 0 // 0: disable; 1; enable. 17 | 18 | #define SUBDEV_UUID "4E4638" 19 | #define SUBDEV_MAC "AA0011223366" 20 | #define SUBDEV_LICENSE "d91fa7fc6ba19811747d9d6ddc0971f2" 21 | 22 | /*---------------- sub dev api ---------------*/ 23 | 24 | /** 25 | * brief: 26 | * 27 | * @Param: dev 28 | * @Param: num 29 | * 30 | * @Returns: 31 | */ 32 | E_JLRetCode_t 33 | joylink_dev_sub_add(JLSubDevData_t *dev, int num); 34 | 35 | /** 36 | * brief: 37 | * 38 | * @Param: dev 39 | * @Param: num 40 | * 41 | * @Returns: 42 | */ 43 | E_JLRetCode_t 44 | joylink_sub_dev_del(char *feedid); 45 | 46 | /** 47 | * brief: 48 | * 49 | * @Param: feedid 50 | * @Param: dev 51 | * 52 | * @Returns: 53 | */ 54 | E_JLRetCode_t 55 | joylink_dev_sub_get_by_feedid(char *feedid, JLSubDevData_t *dev); 56 | /** 57 | * brief: 58 | * 59 | * @Param: feedid 60 | * @Param: dev 61 | * 62 | * @Returns: 63 | */ 64 | E_JLRetCode_t 65 | joylink_dev_sub_version_update(char *feedid, int version); 66 | /** 67 | * brief: 68 | * 69 | * @Param: uuid 70 | * @Param: mac 71 | * @Param: dev 72 | * 73 | * @Returns: 74 | */ 75 | E_JLRetCode_t 76 | joylink_sub_dev_get_by_uuid_mac(char *uuid, char *mac, JLSubDevData_t *dev); 77 | 78 | /** 79 | * brief: 80 | * 81 | * @Param: uuid 82 | * @Param: mac 83 | * @Param: dev 84 | * 85 | * @Returns: 86 | */ 87 | E_JLRetCode_t 88 | joylink_dev_sub_update_keys_by_uuid_mac(char *uuid, char *mac, JLSubDevData_t *dev); 89 | 90 | /** 91 | * brief: 根据子设备mac查询子设备其他信息。 92 | * 93 | * @Param: macstr 94 | * 95 | * @Returns: 96 | */ 97 | int joylink_sub_dev_get_by_deviceid(char *macstr, JLSubDevData_t *info_out); 98 | 99 | /** 100 | * brief: 更新子设备信息,并根据标识进行保存。 101 | * 102 | * @Param: macstr 103 | * 104 | * @Returns: 105 | */ 106 | int joylink_sub_dev_update_device_info(JLSubDevData_t *info_in, int save_flag); 107 | 108 | 109 | /** 110 | * brief: 子设备上报数据或心跳时调用此函数,设置设备在线标识。 111 | * 112 | * @Param: macstr 113 | * 114 | * @Returns: 115 | */ 116 | 117 | int joylink_sub_dev_hb_event(char *macstr); 118 | 119 | /** 120 | * brief: 子设备上报设备快照,只上报macstr这个的快照。 121 | * 122 | * @Returns: 123 | */ 124 | int joylink_server_sub_dev_event_req(char *macstr, char *event_payload, int length); 125 | 126 | /** 127 | * brief: 128 | * 129 | * @Param: count 130 | * @Param: scan_type 131 | * 132 | * @Returns: 133 | */ 134 | JLSubDevData_t * 135 | joylink_dev_sub_devs_get(int *count); 136 | 137 | /** 138 | * brief: 139 | * 140 | * @Param: cmd 141 | * @Param: cmd_len 142 | * @Param: feedid 143 | * 144 | * @Returns: 145 | */ 146 | E_JLRetCode_t 147 | joylink_dev_sub_ctrl(const char* cmd, int cmd_len, char* feedid); 148 | 149 | /** 150 | * brief: 151 | * 152 | * @Param: feedid 153 | * @Param: out_len 154 | * 155 | * @Returns: 156 | */ 157 | char * 158 | joylink_dev_sub_get_snap_shot(char *feedid, int *out_len); 159 | 160 | /** 161 | * brief: 162 | * 163 | * @Param: feedid 164 | * 165 | * @Returns: 166 | */ 167 | E_JLRetCode_t 168 | joylink_dev_sub_unbind(const char *feedid); 169 | 170 | /** 171 | * brief: 上报子设备快照 172 | * 173 | * @Returns: 174 | */ 175 | extern int joylink_server_subdev_event_req(char *macstr, char *event_payload, int length); 176 | 177 | /** 178 | * brief: 立刻上报子设备快照 179 | * 180 | * @Returns: 181 | */ 182 | 183 | int joylink_sub_dev_report_snapshot_immediately(char *macstr, char *data, int len); 184 | 185 | #define SUBDEV_ACTIVE_STATUS_OPEN 0 186 | #define SUBDEV_ACTIVE_STATUS_OK 1 187 | #define SUBDEV_ACTIVE_STATUS_FAILED 2 188 | 189 | /** 190 | * @brief: SDK subdev active 子设备激活状态报告 191 | * 192 | * @param[in] status: 状态 0打开, 1成功,2失败, 3解邦 193 | * 194 | * @return: reserved 当前此函数仅做通知,调用方不关心返回值. 195 | */ 196 | void joylink_sub_dev_active_status(char status); 197 | 198 | /** 199 | * @brief: delete subdev 删除子设备 200 | * 201 | * @param[in] mac: 删除子设备的 mac 202 | * 203 | * @return: reserved 当前此函数仅做通知,调用方不关心返回值. 204 | */ 205 | void joylink_sub_dev_delete_msg(char *mac); 206 | 207 | /** 208 | * @brief: 添加子设备到全局数组_g_sub_dev中 209 | * 210 | * @param[in]: dev 设备结构 211 | * @param[in]: message 例如: 212 | * { 213 | * "uuid": "D23707", // 小京鱼开放平台创建的虚拟红外被控设备的UUID 214 | * "brandKey": "mm", // 虚拟被控红外设备品牌标识,对接厂商自行定义 215 | * "modelKey": "xx", // 虚拟被控红外设备型号标识,对接厂商自行定义 216 | * "controllerId": "948001623745658402" // 主控红外遥控器的feedid,表示虚拟红外被控设备可以被哪一个遥控器控制。 217 | * } 218 | * 219 | * @returns: E_RET_OK 成功, E_RET_ERROR 发生错误 220 | */ 221 | E_JLRetCode_t joylink_dev_sub_add_infrared_receiver(JLSubDevData_t *dev, char *message); 222 | 223 | #ifdef __cplusplus 224 | } 225 | #endif 226 | 227 | #endif 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/joylink_extern_user.c: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_tool.C 3 | * 4 | * @brief: 5 | * 6 | * @version: 2.0 7 | * 8 | * @date: 2018/07/26 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "joylink_extern_user.h" 19 | #include "joylink_stdio.h" 20 | #include "joylink_stdint.h" 21 | 22 | static FILE *file_fp = NULL; 23 | 24 | int joylink_memory_init(void *index, int flag) 25 | { 26 | char *save_path = (char *)index; 27 | 28 | if(file_fp > 0) 29 | return -1; 30 | 31 | //jl_platform_printf("save_path: %s\n", save_path); 32 | 33 | if(flag == MEMORY_WRITE){ 34 | file_fp = jl_platform_fopen(save_path, "wb+"); 35 | if(file_fp == NULL){ 36 | jl_platform_printf("Open file error!\n"); 37 | return -1; 38 | } 39 | } 40 | else if(flag == MEMORY_READ){ 41 | file_fp = jl_platform_fopen(save_path, "rb"); 42 | if(file_fp == NULL){ 43 | jl_platform_printf("Open file error!\n"); 44 | return -1; 45 | } 46 | } 47 | return 0; 48 | } 49 | 50 | int joylink_memory_write(int offset, char *data, int len) 51 | { 52 | if(file_fp == NULL || data == NULL) 53 | return -1; 54 | 55 | return jl_platform_fwrite(data, 1, len, file_fp); 56 | } 57 | 58 | int joylink_memory_read(int offset, char *data, int len) 59 | { 60 | if(file_fp == NULL || data == NULL) 61 | return -1; 62 | 63 | return jl_platform_fread(data, 1, len, file_fp); 64 | } 65 | 66 | int joylink_memory_finish(void) 67 | { 68 | if(file_fp == NULL) 69 | return -1; 70 | 71 | jl_platform_fclose(file_fp); 72 | file_fp = NULL; 73 | return 0; 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/joylink_extern_user.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------- 2 | * @file: joylink_extern_tool.h 3 | * 4 | * @brief: 5 | * 6 | * @version: 2.0 7 | * 8 | * @date: 2018/07/26 PM 9 | * 10 | * -------------------------------------------------- 11 | */ 12 | 13 | #ifndef _JOYLINK_EXTERN_TOOL_H_ 14 | #define _JOYLINK_EXTERN_TOOL_H_ 15 | 16 | #ifdef __cplusplus 17 | extern "C"{ 18 | #endif 19 | 20 | #define MEMORY_WRITE 0 21 | #define MEMORY_READ 1 22 | 23 | int joylink_memory_init(void *index, int flag); 24 | 25 | int joylink_memory_write(int offset, char *data, int len); 26 | int joylink_memory_read(int offset, char *data, int len); 27 | 28 | int joylink_memory_finish(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /joylink_dev_sdk/example/test.c: -------------------------------------------------------------------------------- 1 | #include "joylink_stdio.h" 2 | #include "joylink_thread.h" 3 | #include "joylink_extern.h" 4 | #include "joylink.h" 5 | 6 | int 7 | main() 8 | { 9 | jl_thread_t task_id; 10 | 11 | task_id.thread_task = (threadtask) joylink_main_start; 12 | task_id.stackSize = 0x5000; 13 | task_id.priority = JL_THREAD_PRI_DEFAULT; 14 | task_id.parameter = NULL; 15 | jl_platform_thread_start(&task_id); 16 | 17 | // joylink_softap_start(); 18 | 19 | jl_platform_msleep(2000); 20 | // 开启局域网激活模式 21 | joylink_dev_lan_active_switch(1); 22 | 23 | while(1) 24 | { 25 | jl_platform_msleep(1000); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/inc/joylink_dev_active.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_DEV_ACTIVE_H_ 2 | #define _JOYLINK_DEV_ACTIVE_H_ 3 | #include "joylink.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C"{ 7 | #endif /* __cplusplus */ 8 | 9 | /** 10 | * 设备激活绑定流程说明: 11 | * 使用softAP配网: 12 | * 1. 只需将设备设置为softAP模式后,调用joylink_softap_start进行配网,如果配网成功SDK内部会自动完成激活绑定流程 13 | * 使用其他配网方式,如摄像头扫码配网,需按照如下步骤进行激活绑定: 14 | * 1. 应用层需通过扫码或其他方式获取到激活绑定所需的url和token 15 | * 2. 调用joylink_dev_active_start函数,通过参数传入激活绑定的url和token 16 | * 3. 调用joylink_dev_active_req函数,此函数会向云端发送设备激活绑定请求,应用层必须实现jl_platform_https_request 17 | */ 18 | 19 | /** 20 | * @brief: 向云端发送设备激活绑定的HTTPS请求 21 | * 22 | * @return: 0 成功, -1 失败 23 | */ 24 | int joylink_dev_active_req(void); 25 | 26 | /** 27 | * @brief: 设置设备激活绑定所需的url和token 28 | * 29 | * @param[in] urlstr: 设备激活绑定请求的目标url 30 | * @param[in] tokenstr: 设备激活绑定请求所需携带的token 31 | * 32 | */ 33 | void joylink_dev_active_start(char *urlstr,char *tokenstr); 34 | 35 | /** 36 | * @brief: 获取设备激活状态 1-正在激活绑定 0-激活绑定停止 37 | */ 38 | int joylink_dev_active_enable(void); 39 | 40 | /** 41 | * @brief: 停止激活绑定 42 | */ 43 | void joylink_dev_active_stop(void); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif /* __cplusplus */ 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/inc/joylink_ret_code.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_RET_CODE_H_ 2 | #define _JOYLINK_RET_CODE_H_ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C"{ 8 | #endif /* __cplusplus */ 9 | 10 | typedef enum _jl_bool{ 11 | E_JL_FALSE = 0, 12 | E_JL_TRUE = 1 13 | }E_JLBOOL_t; 14 | 15 | typedef enum _jl_ret_code{ 16 | E_RET_ERROR_DEV_ACTIVED = -2001, 17 | E_RET_ERROR_PKG_SAME = -1001, 18 | E_RET_ERROR_PKG_NUM_BREAK_MAX = -1002, 19 | E_RET_ERROR_PKG_BREAK_ARRAY = -1003, 20 | E_RET_ERROR_PARAM_INVAID = -3, 21 | E_RET_ERROR_NO_EXIST = -2, 22 | E_RET_ERROR = -1, 23 | E_RET_OK = 0, 24 | E_RET_ALL_DATA_HIT = 1001, 25 | E_RET_DATA_COMING = 1002 26 | }E_JLRetCode_t; 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif /* __cplusplus */ 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/inc/joylink_sub_dev.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_SUB_DEV_H__ 2 | #define __JOYLINK_SUB_DEV_H__ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "joylink_socket.h" 11 | #include "joylink_stdint.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" 15 | { 16 | #endif 17 | 18 | #pragma pack(1) 19 | typedef struct { 20 | unsigned int timestamp; 21 | unsigned int code; 22 | }JLDataSubHbRsp_t; 23 | 24 | typedef struct { 25 | unsigned int timestamp; 26 | unsigned char feedid[JL_MAX_FEEDID_LEN]; 27 | unsigned int code; 28 | }JLDataSubUploadRsp_t; 29 | 30 | typedef struct { 31 | unsigned short version; 32 | unsigned short rssi; 33 | unsigned char feedid[JL_MAX_FEEDID_LEN]; 34 | unsigned char state; 35 | }JLSubDevInfo_t; 36 | 37 | typedef struct { 38 | unsigned int timestamp; 39 | unsigned short verion; 40 | unsigned short rssi; 41 | unsigned short num; 42 | JLSubDevInfo_t sdevinfo[]; 43 | }JLSubHearBeat_t; 44 | 45 | typedef struct { 46 | unsigned int timestamp; 47 | unsigned int biz_code; 48 | unsigned int serial; 49 | char feedid [JL_MAX_FEEDID_LEN]; 50 | unsigned char *cmd; 51 | }JLSubContrl_t; 52 | 53 | typedef struct { 54 | unsigned int timestamp; 55 | unsigned int biz_code; 56 | unsigned int serial; 57 | unsigned short num; 58 | JLSubDevInfo_t *info; 59 | }JLSubUnbind_t; 60 | 61 | typedef struct { 62 | char uuid[8]; 63 | char mac[17]; 64 | 65 | short version; 66 | 67 | char state; 68 | char type; 69 | char lancon; 70 | char cmd_tran_type; 71 | 72 | char protocol; 73 | 74 | char feedid[33]; 75 | char accesskey[33]; 76 | char localkey[33]; 77 | 78 | char pubkey[65]; 79 | 80 | char devAuthValue[33]; 81 | char cloudAuthValue[33]; 82 | 83 | int subNoSnapshot; 84 | }JLSubDevData_t; 85 | 86 | #pragma pack() 87 | 88 | /** 89 | * brief: 90 | * 91 | * @Param: src 92 | * @Param: sin_recv 93 | * @Param: addrlen 94 | * 95 | * @Returns: 96 | */ 97 | E_JLRetCode_t 98 | joylink_proc_lan_sub_add(uint8_t *src, jl_sockaddr_in *sin_recv, int addrlen); 99 | // joylink_proc_lan_sub_add(uint8_t *src, struct sockaddr_in *sin_recv, socklen_t addrlen); 100 | 101 | /** 102 | * brief: 103 | * 104 | * @Param: src 105 | * @Param: sin_recv 106 | * @Param: addrlen 107 | * 108 | * @Returns: 109 | */ 110 | E_JLRetCode_t 111 | joylink_proc_lan_sub_auth(uint8_t *src, jl_sockaddr_in *sin_recv, int addrlen); 112 | // joylink_proc_lan_sub_auth(uint8_t *src, struct sockaddr_in *sin_recv, socklen_t addrlen); 113 | 114 | /** 115 | * brief: 116 | * 117 | * @Param: src 118 | * @Param: src_len 119 | * @Param: sin_recv 120 | * @Param: addrlen 121 | * 122 | * @Returns: 123 | */ 124 | E_JLRetCode_t 125 | joylink_proc_lan_sub_script_ctrl(uint8_t *src, int src_len, jl_sockaddr_in *sin_recv, int addrlen); 126 | // joylink_proc_lan_sub_script_ctrl(uint8_t *src, int src_len, struct sockaddr_in *sin_recv, socklen_t addrlen); 127 | 128 | /** 129 | * brief: 130 | * 131 | * @Returns: 132 | */ 133 | int 134 | joylink_packet_check_sub_hb(void); 135 | /** 136 | * brief: 137 | * 138 | * @Returns: 139 | */ 140 | int 141 | joylink_packet_server_sub_hb_req(int index); 142 | 143 | /** 144 | * brief: 145 | * 146 | * @Param: recPainText 147 | * @Param: ctr 148 | * @Param: payloadlen 149 | * 150 | * @Returns: 151 | */ 152 | int 153 | joylink_subdev_script_ctrl(uint8_t* recPainText, JLSubContrl_t *ctr, unsigned short payloadlen); 154 | 155 | /** 156 | * brief: 157 | * 158 | * @Param: data 159 | * @Param: max 160 | * @Param: ctrl 161 | * 162 | * @Returns: 163 | */ 164 | int 165 | joylink_packet_subdev_script_ctrl_rsp(char *data, int max, JLSubContrl_t *ctrl); 166 | 167 | /** 168 | * brief: 169 | * 170 | * @Param: recPainText 171 | * @Param: unbind 172 | * 173 | * @Returns: 174 | */ 175 | int 176 | joylink_subdev_unbind(uint8_t* recPainText, JLSubUnbind_t* unbind); 177 | 178 | /** 179 | * brief: 180 | * 181 | * @Param: data 182 | * @Param: max 183 | * @Param: unbind 184 | * 185 | * @Returns: 186 | */ 187 | int 188 | joylink_packet_subdev_unbind_rsp(char* data, int max, JLSubUnbind_t* unbind); 189 | #ifdef __cplusplus 190 | } 191 | #endif 192 | 193 | #endif /* __SUB_DEV_H__*/ 194 | -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/inc/joylink_tempkey.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_TEMPKEY_H_ 2 | #define _JOYLINK_TEMPKEY_H_ 3 | 4 | #include "joylink_stdint.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C"{ 8 | #endif /* __cplusplus */ 9 | 10 | typedef struct _jl_devinfo_st{ 11 | uint8_t mac[17]; 12 | uint8_t uuid[7]; 13 | uint8_t public_key[33]; 14 | }jl_devinfo_st; 15 | 16 | /** 17 | * brief: 临时密码加密 18 | * 19 | * @Returns: 20 | */ 21 | int joylink_dev_encode_temp_key(jl_devinfo_st *dev_info, uint8_t *data_in, uint8_t *data_out); 22 | 23 | /** 24 | * brief: 临时秘密解密 25 | * 26 | * @Returns: 27 | */ 28 | int joylink_dev_decode_temp_key(jl_devinfo_st *dev_info, uint8_t *data_in, uint8_t *data_out); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif /* __cplusplus */ 33 | 34 | #endif /* joylink tempkey.h */ 35 | -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/inc/joylink_version.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_VERSION_H__ 2 | #define __JOYLINK_VERSION_H__ 3 | 4 | #define GIT_COMMIT_ID "f7b2c7d64e0ec9c7996143c59b28de0bea56f8b4" 5 | 6 | #define _VERSION_ "2.1.22" 7 | #define JL_MINOR_VERSION 32 8 | #define _RELEASE_TIME_ "2021_09_07" 9 | 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/inc/softap/joylink_softap_start.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_SOFTAP_START_H_ 2 | #define _JOYLINK_SOFTAP_START_H_ 3 | #include "joylink_stdint.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C"{ 7 | #endif /* __cplusplus */ 8 | 9 | /** 10 | * @brief: 开始softAP配网流程. 11 | * 12 | * @note: 在调用此函数开始softAP配网之前,需要确保设备wifi已经进入AP模式,否则无法成功配网. 13 | * 14 | * @param[in] timeout_ms: 配网超时时间,单位毫秒 15 | * 16 | * @returns: 0 配网成功, -1 配网失败 17 | */ 18 | int joylink_softap_start(unsigned int timeout_ms); 19 | 20 | 21 | /** 22 | * @name:joylink_softap_status 23 | * 24 | * @returns: 0,不是softap配网状态;1,softap配网进行中 25 | */ 26 | uint8_t joylink_softap_status(void); 27 | 28 | uint8_t joylink_softap_client_online(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif /* __cplusplus */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/lib/esp32/libjoylink.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/joylink/lib/esp32/libjoylink.a -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/lib/esp32c3/libjoylink.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/joylink/lib/esp32c3/libjoylink.a -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/lib/esp32s2/libjoylink.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/joylink/lib/esp32s2/libjoylink.a -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/lib/esp32s3/libjoylink.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/joylink/lib/esp32s3/libjoylink.a -------------------------------------------------------------------------------- /joylink_dev_sdk/joylink/lib/esp8266/libjoylink.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/joylink/lib/esp8266/libjoylink.a -------------------------------------------------------------------------------- /joylink_dev_sdk/lua/JDB0.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-joylink/9f0c784fea029fd5b01f3265598c22ec55d57fa3/joylink_dev_sdk/lua/JDB0.lua -------------------------------------------------------------------------------- /joylink_dev_sdk/lua/delete_snapshot.lua: -------------------------------------------------------------------------------- 1 | function jds2pri(code, jds) 2 | local error_code = 0 3 | local newJds = rmvSnapshot(jds) 4 | local cmd_length = #newJds 5 | return error_code, cmd_length, newJds 6 | end 7 | 8 | function pri2jds(code, length, bin) 9 | local error_code = 0 10 | return error_code, bin, code 11 | end 12 | 13 | function rmvSnapshot(jds) 14 | local json = decode(jds) 15 | 16 | local streams = json["streams"] 17 | 18 | local retTable = {}; 19 | 20 | retTable["streams"] = streams; 21 | return encode(retTable) 22 | end 23 | 24 | function decode(cmd) 25 | local tb = {} 26 | if cjson == nil then 27 | cjson = (require 'JSON') 28 | tb = cjson:decode(cmd) 29 | cjson = nil 30 | else 31 | tb = cjson.decode(cmd) 32 | end 33 | return tb 34 | end 35 | 36 | function encode(cmd) 37 | local tb = "" 38 | if cjson == nil then 39 | cjson = (require 'JSON') 40 | tb = cjson:encode(cmd) 41 | cjson = nil 42 | else 43 | tb = cjson.encode(cmd) 44 | end 45 | return tb 46 | end -------------------------------------------------------------------------------- /joylink_dev_sdk/lua/example.lua: -------------------------------------------------------------------------------- 1 | function stringToTable( sta ) 2 | local tablesta = {} 3 | local i 4 | for i=1, #sta do 5 | tablesta[i] = sta:byte(i) 6 | end 7 | 8 | return tablesta 9 | end 10 | 11 | function tableTostring(cmd) 12 | local ret="" 13 | local i 14 | for i=1,#cmd do 15 | ret=ret..string.char(cmd[i]) 16 | end 17 | return ret 18 | end 19 | 20 | function stringToHexstring(str) 21 | local ret = '' 22 | for i=1, #str do 23 | ret = ret .. string.format("%02x", str:byte(i)) 24 | end 25 | return ret 26 | end 27 | 28 | function decode(cmd) 29 | local tb 30 | if cjson == nil then 31 | cjson = (require 'JSON') 32 | tb = cjson:decode(cmd) 33 | else 34 | tb = cjson.decode(cmd) 35 | end 36 | return tb 37 | end 38 | 39 | function getKVTable(t,keyName,valueName) 40 | local kvTable = {} 41 | for i=1, #t do 42 | key = t[i][''..keyName] 43 | val = t[i][''..valueName] 44 | kvTable[''..key] = val 45 | end 46 | return kvTable 47 | end 48 | 49 | function table2json(t) 50 | local function serialize(tbl) 51 | local tmp = {} 52 | for k, v in pairs(tbl) do 53 | local k_type = type(k) 54 | local v_type = type(v) 55 | local key = (k_type == "string" and "\"" .. k .. "\":") 56 | or (k_type == "number" and "") 57 | local value = (v_type == "table" and serialize(v)) 58 | or (v_type == "boolean" and tostring(v)) 59 | or (v_type == "string" and "\"" .. v .. "\"") 60 | or (v_type == "number" and v) 61 | tmp[#tmp + 1] = key and value and tostring(key) .. tostring(value) or nil 62 | end 63 | if table.maxn(tbl) == 0 then 64 | return "{" .. table.concat(tmp, ",") .. "}" 65 | else 66 | return "[" .. table.concat(tmp, ",") .. "]" 67 | end 68 | end 69 | assert(type(t) == "table") 70 | return serialize(t) 71 | end 72 | 73 | function jds2pri( bizcode, cmd ) 74 | --return err, length, bin 75 | local bin 76 | if bizcode == 1002 then 77 | local json = decode(cmd) 78 | local streams = json["streams"] 79 | local tabstreams = getKVTable(streams, 'stream_id', 'current_value') 80 | 81 | bin = {0xbb, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,0xfa, 0x44} 82 | if (tabstreams["beep_switch"] == "0") then 83 | bin[2] = 3 84 | elseif (tabstreams["beep_switch"] == "1") then 85 | bin[2] = 2 86 | end 87 | 88 | elseif bizcode == 1004 then --获取快照 89 | bin = {0xbb, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,0xfa, 0x44} 90 | else --错误的code指令,返回获取快照 91 | bin = {0xbb, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,0xfa, 0x44} 92 | end 93 | 94 | local ret = tableTostring(bin) 95 | return 0, string.len(ret), ret 96 | end 97 | 98 | function pri2jds( bizcode, length, bin ) 99 | --return err, jstr, bizcode 100 | local bin_cmd = {} 101 | local pwr 102 | local jdstr = "" 103 | 104 | bin_cmd = stringToTable(bin) 105 | 106 | for i=1, #bin_cmd do 107 | print(string.format("lua_script bin_cmd[%02d] %02x", i, bin_cmd[i])) 108 | end 109 | 110 | pwr = bin_cmd[1]; 111 | jdstr = string.format('{"code":0,"streams":[{"current_value":%x,"stream_id":"switch"}],"msg":"done"}', pwr) 112 | 113 | return 0, jdstr, 102 114 | 115 | end 116 | 117 | 118 | -------------------------------------------------------------------------------- /joylink_dev_sdk/lua/only_trans.lua: -------------------------------------------------------------------------------- 1 | function jds2pri(code, jds) 2 | local error_code = 0 3 | local cmd_length = #jds 4 | return error_code, cmd_length, jds 5 | end 6 | 7 | function pri2jds(code, length, bin) 8 | local error_code = 0 9 | return error_code, bin, code 10 | end 11 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = .. 2 | 3 | include ${TOP_DIR}/scripts/config.mk 4 | 5 | TARGET_DIR = ${TOP_DIR}/target 6 | TARGET_LIB = ${TARGET_DIR}/lib 7 | TARGET_BIN = ${TARGET_DIR}/bin 8 | 9 | INCLUDE_DIRS = $(shell ls -l ../joylink/inc | grep ^d | awk '{print $$9}') 10 | ORG_SOURCES = $(wildcard src/*.c) 11 | OUT_SRC = src/joylink_ota.c src/joylink_wifi.c 12 | 13 | SOURCES=$(filter-out ${OUT_SRC}, ${ORG_SOURCES}) 14 | OBJS = $(patsubst %.c, %.o, $(SOURCES)) 15 | 16 | LIBNAME = lib$(strip ${shell pwd |xargs basename}) 17 | 18 | CFLAGS += -I../example 19 | CFLAGS += -I./inc 20 | CFLAGS += $(addprefix -I../joylink/inc/,${INCLUDE_DIRS}) 21 | 22 | ifeq (${ARCH}, x86) 23 | all:${OBJS} liba libso 24 | else 25 | all:${OBJS} liba 26 | endif 27 | 28 | 29 | .SUFFIXES: .c .o 30 | 31 | liba:${OBJS} 32 | @echo ------------------ 33 | @echo ${SOURCES} 34 | @echo ------------------ 35 | @echo ${OUT_SRC} 36 | @echo ------------------ 37 | ${AR} -crs ${LIBNAME}.a ${OBJS} 38 | @echo ------------------ 39 | ${MV} ${LIBNAME}.a ${TARGET_LIB} 40 | 41 | libso:${OBJS} 42 | ${CC} ${OBJS} -shared -fPIC -o ${LIBNAME}.so 43 | ${MV} ${LIBNAME}.so ${TARGET_LIB} 44 | 45 | clean: 46 | ${RM} ${OBJS} *.i *.s $(wildcard src/*.d) $(wildcard src/*/*.d) $(wildcard src/*.su) $(wildcard src/*/*.su) 47 | 48 | $(OBJS):%.o:%.c 49 | $(CC) $(CFLAGS) -c $< -o $@ 50 | 51 | distclean:clean 52 | ${RM} ${TARGET_LIB}/* 53 | 54 | .PHONY:all clean test jt 55 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_FLASH_H_ 2 | #define _JOYLINK_FLASH_H_ 3 | 4 | #include "joylink_stdint.h" 5 | 6 | //key用于存储:工厂模组连接ap失败原因 7 | #define KEY_FAC "fac_ap_con_fail" 8 | //key用于存储:sdk softap配网失败原因 9 | #define KEY_SDK "sdk_softap_fail" 10 | 11 | /** 12 | * @brief:set data in jl_flash 13 | * 14 | * @param: key, value 15 | * 16 | * @returns: success 0, failed -1 17 | */ 18 | int32_t jl_flash_SetInt8(const char* key, int8_t value); 19 | int32_t jl_flash_SetInt32(const char* key, int32_t value); 20 | int32_t jl_flash_SetInt64(const char* key, int64_t value); 21 | int32_t jl_flash_SetBool(const char* key, int8_t value); 22 | 23 | /** 24 | * @brief:set buff in jl_flash 25 | * 26 | * @param: key, buff, len 27 | * 28 | * @returns: success 0, failed -1 29 | */ 30 | int32_t jl_flash_SetString(const char* key, const char* buff, int32_t len); 31 | 32 | /** 33 | * @brief:get data from jl_flash 34 | * 35 | * @param: key, value 36 | * 37 | * @returns: 读取到的value值, 如果读取失败则返回defaultValue. 38 | */ 39 | int8_t jl_flash_GetInt8(const char* key, int8_t defaultValue); 40 | int32_t jl_flash_GetInt32(const char* key, int32_t defaultValue); 41 | int64_t jl_flash_GetInt64(const char* key, int64_t defaultValue); 42 | int8_t jl_flash_GetBool(const char* key, int8_t defaultValue); 43 | /** 44 | * @brief:get data from jl_flash 45 | * 46 | * @param: key, value 47 | * 48 | * @returns: 读取到value的长度len, 如果无数据则返回0. 49 | */ 50 | int32_t jl_flash_GetString(const char* key, char* buff, int32_t len); 51 | 52 | /** 53 | * @brief:clear jl_flash data 54 | * 55 | * @param: key 56 | * 57 | * @returns: none 58 | */ 59 | void jl_flash_ClearKey(const char *key); 60 | 61 | /** 62 | * @brief: 二进制数据写入flash 63 | * 64 | * @param[in] offset: flash地址偏移 65 | * 66 | * @param[in] buf: 写入flash的数据 67 | * 68 | * @param[in] len: 要写入数据的长度 69 | * 70 | * @return 返回实际写入的数据长度,写入失败则返回-1 71 | * 72 | */ 73 | 74 | int32_t jl_flash_SetBuffer(int32_t offset, const void* buf, int32_t len); 75 | 76 | 77 | /** 78 | * @brief: SDK申请预留flash空间 79 | * 80 | * @param[in] size: 申请空间的大小,字节为单位 81 | * 82 | * @return: 申请flash空间的偏移,如果申请失败则返回-1 83 | * 84 | */ 85 | int32_t jl_flash_request(int32_t size); 86 | 87 | /** 88 | * @brief: 读取指定偏移地址的数据 89 | * 90 | * @param[in] offset: flash偏移地址 91 | * 92 | * @param[out] buf: 存储读取数据的buffer 93 | * 94 | * @param[in] len: 预期读取的数据长度 95 | * 96 | * @return int32_t: 实际读取的数据长度,如果读取失败则返回-1 97 | * 98 | */ 99 | 100 | int32_t jl_flash_GetBuffer(int32_t offset, const void* buf, int32_t len); 101 | 102 | /** 103 | * @brief: 清除指定偏移地址的数据 104 | * 105 | * @param[in] offset: flash偏移地址 106 | * 107 | * @param[in] len: 预期读取的数据长度 108 | * 109 | * @return int32_t: 实际读取的数据长度,如果读取失败则返回-1 110 | * 111 | */ 112 | int32_t jl_flash_ClearBuffer(int32_t offset, int32_t len); 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_http.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: your name 3 | * @Date: 2020-07-09 09:09:21 4 | * @LastEditTime: 2020-12-03 15:49:56 5 | * @LastEditors: Please set LastEditors 6 | * @Description: In User Settings Edit 7 | * @FilePath: \joylink_dev_sdk_2.1\pal\inc\joylink_http.h 8 | */ 9 | #ifndef _JOYLINK_HTTP_H_ 10 | #define _JOYLINK_HTTP_H_ 11 | #include 12 | #include "joylink_stdint.h" 13 | 14 | 15 | typedef struct _jl_http_t{ 16 | char *url; 17 | char *header; 18 | char *body; 19 | char *response; 20 | int32_t resp_len; 21 | }jl_http_t; 22 | 23 | /** 24 | * @name:实现HTTPS的POST请求,请求响应填入revbuf参数 25 | * 26 | * @param[in]: url POST请求的链接和路径 27 | * @param[in]: header POST请求的HEADER 28 | * @param[in]: body POST请求的Payload 29 | * @param[out]: revbuf 填入请求的响应信息 30 | * 31 | * @returns: NULL - 发生错误, 其它 - 请求返回的数据 ,使用完毕内存需要释放 32 | * 33 | * @note:此函数必须正确实现,否则设备无法激活绑定 34 | * @note:小京鱼平台HTTPS使用的证书每年都会更新. 35 | * @note:因为Joylink协议层面有双向认证的安全机制,所以此HTTPS请求设备无需校验server的证书. 36 | * @note:如果设备必须校验server的证书,那么需要开发者实现时间同步等相关机制. 37 | */ 38 | int32_t jl_platform_https_request(jl_http_t *info); 39 | 40 | /** 41 | * @name:实现HTTP的POST请求,请求响应填入revbuf参数 42 | * 43 | * @param[in]: url POST请求的链接和路径 44 | * @param[in]: header POST请求的HEADER 45 | * @param[in]: body POST请求的Payload 46 | * @param[out]: revbuf 填入请求的响应信息 47 | * 48 | * @returns: NULL - 发生错误, 其它 - 请求返回的数据 ,使用完毕内存需要释放 49 | */ 50 | int32_t jl_platform_http_request(jl_http_t *info); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_log.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_LOG_H__ 2 | #define __JOYLINK_LOG_H__ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "joylink_stdio.h" 15 | #include "joylink_time.h" 16 | #include "joylink_stdint.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #define JL_LOG_LEVEL_FATAL (0) 24 | #define JL_LOG_LEVEL_NOTICE (1) 25 | #define JL_LOG_LEVEL_INFO (2) 26 | #define JL_LOG_LEVEL_ERROR (3) 27 | #define JL_LOG_LEVEL_WARN (4) 28 | #define JL_LOG_LEVEL_DEBUG (5) 29 | 30 | #define Black 0;30 31 | #define Red 0;31 32 | #define Green 0;32 33 | #define Brown 0;33 34 | #define Blue 0;34 35 | #define Purple 0;35 36 | #define Cyan 0;36 37 | 38 | //#define JL_LOG_LEVEL JL_LOG_LEVEL_ERROR 39 | #define JL_LOG_LEVEL JL_LOG_LEVEL_DEBUG 40 | 41 | #ifndef __FILENAME__ 42 | #define __FILENAME__ (strrchr("/" __FILE__, '/') + 1) 43 | #endif 44 | 45 | #ifdef __GNUC__ 46 | #define SHORT_FILE __FILENAME__ 47 | #else 48 | #define SHORT_FILE strrchr(__FILE__, '\\')?strrchr(__FILE__, '\\') + 1 : __FILE__ 49 | #endif 50 | 51 | #define log_fatal(format, ...) \ 52 | do{\ 53 | if(JL_LOG_LEVEL >= JL_LOG_LEVEL_FATAL){\ 54 | jl_platform_printf("\033[0;31m[FATAL][%s][%s][%s][%d]\r\n" format "\r\n\033[0m", jl_get_time_str(), SHORT_FILE, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ 55 | }\ 56 | }while(0) 57 | 58 | #define log_notice(format, ...) \ 59 | do{\ 60 | if(JL_LOG_LEVEL >= JL_LOG_LEVEL_NOTICE){\ 61 | jl_platform_printf("\033[0;36m[NOTICE][%s][%s][%s][%d]\r\n" format "\r\n\033[0m", jl_get_time_str(), SHORT_FILE, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ 62 | }\ 63 | }while(0) 64 | 65 | #define log_info(format, ...) \ 66 | do{\ 67 | if(JL_LOG_LEVEL >= JL_LOG_LEVEL_INFO){\ 68 | jl_platform_printf("\033[1;36m[INFO][%s][%s][%s][%d]\r\n" format "\r\n\033[0m", jl_get_time_str(), SHORT_FILE, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ 69 | }\ 70 | }while(0) 71 | 72 | #define log_error(format, ...) \ 73 | do{\ 74 | if(JL_LOG_LEVEL >= JL_LOG_LEVEL_ERROR){\ 75 | jl_platform_printf("\033[0;31m[ERROR][%s][%s][%s][%d]\r\n" format "\r\n\033[0m", jl_get_time_str(), SHORT_FILE, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ 76 | }\ 77 | }while(0) 78 | 79 | #define log_warn(format, ...) \ 80 | do{\ 81 | if(JL_LOG_LEVEL >= JL_LOG_LEVEL_WARN){\ 82 | jl_platform_printf("\033[1;33m[WARN][%s][%s][%s][%d]\r\n" format "\r\n\033[0m", jl_get_time_str(), SHORT_FILE, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ 83 | }\ 84 | }while(0) 85 | 86 | #define log_debug(format, ...) \ 87 | do{\ 88 | if(JL_LOG_LEVEL >= JL_LOG_LEVEL_DEBUG){\ 89 | jl_platform_printf("\033[1;32m[DEBUG][%s][%s][%s][%d]\r\n" format "\r\n\033[0m", jl_get_time_str(), SHORT_FILE, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ 90 | }\ 91 | }while(0) 92 | 93 | 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | #endif 99 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_memory.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_MEMORY_H_ 2 | #define _JOYLINK_MEMORY_H_ 3 | #include 4 | #include "joylink_stdint.h" 5 | 6 | /** 7 | * @brief Allocates a block of size bytes of memory, returning a pointer to the beginning of the block. 8 | * 9 | * @param [in] size @n specify block size in bytes. 10 | * @return A pointer to the beginning of the block. 11 | * @see None. 12 | * @note Block value is indeterminate. 13 | */ 14 | void *jl_platform_malloc(uint32_t size); 15 | 16 | /** 17 | * @brief Changes the size of the memory block pointed to by ptr to size bytes. 18 | * 19 | * @param [in] ptr @n pointer to be realloc 20 | * @param [in] size @n specify block size in bytes for newly allocated memory 21 | * @return A pointer to the beginning of newly allocated memory. 22 | * @see None. 23 | * @note Block value is indeterminate. 24 | */ 25 | void *jl_platform_realloc(void *ptr, uint32_t size); 26 | 27 | /** 28 | * @brief Allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. 29 | * 30 | * @param [in] nmemb @n array elements item counts 31 | * @param [in] size @n specify block size in bytes for every array elements 32 | * @return A pointer to the beginning of allocated memory. 33 | * @see None. 34 | * @note Block value is indeterminate. 35 | */ 36 | void *jl_platform_calloc(uint32_t nmemb, uint32_t size); 37 | 38 | /** 39 | * @brief Deallocate memory block 40 | * 41 | * @param[in] ptr @n Pointer to a memory block previously allocated with platform_malloc. 42 | * @return None. 43 | * @see None. 44 | * @note None. 45 | */ 46 | void jl_platform_free(void *ptr); 47 | 48 | /** 49 | * @brief 复制字符 value(一个无符号字符)到参数 prt 所指向的字符串的前 num 个字符 50 | * 51 | * @param[in] ptr @n 指向要填充的内存块. 52 | * @param[in] value @n 要被设置的值。该值以 int 形式传递,但是函数在填充内存块时是使用该值的无符号字符形式. 53 | * @param[in] num @n 要被设置为该值的字节数. 54 | * @return 55 | 该值返回一个指向存储区 str 的指针 56 | * @see None. 57 | * @note None. 58 | */ 59 | void *jl_platform_memset(void* ptr, int32_t value, uint32_t num); 60 | 61 | /** 62 | * @brief 从存储区 src 复制 num 个字符到存储区 dst 63 | * 64 | * @param[in] dst @n 指向用于存储复制内容的目标数组,类型强制转换为 void* 指针. 65 | * @param[in] src @n 指向要复制的数据源,类型强制转换为 void* 指针. 66 | * @param[in] num @n 要被复制的字节数. 67 | * @return 68 | 该函数返回一个指向目标存储区 str1 的指针 69 | * @see None. 70 | * @note None. 71 | */ 72 | void *jl_platform_memcpy(void* dst, const void* src, uint32_t num); 73 | 74 | /** 75 | * @brief 把存储区 ptr1 和存储区 ptr2 的前 num 个字节进行比较 76 | * 77 | * @param[in] ptr1 @n 指向内存块的指针 78 | * @param[in] ptr2 @n 指向内存块的指针 79 | * @param[in] num @n 要被比较的字节数 80 | * @return 81 | 如果返回值 < 0,则表示 ptr1 小于 ptr2 82 | 如果返回值 > 0,则表示 ptr2 小于 ptr1 83 | 如果返回值 = 0,则表示 ptr1 等于 ptr2 84 | * @see None. 85 | * @note None. 86 | */ 87 | int32_t jl_platform_memcmp(const void* ptr1, const void* ptr2, uint32_t num); 88 | 89 | 90 | /** @} */ /* end of platform_memory_manage */ 91 | 92 | #endif 93 | 94 | 95 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_softap.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_SOFTAP_H_ 2 | #define _JOYLINK_SOFTAP_H_ 3 | 4 | #include "joylink_stdint.h" 5 | 6 | /** 7 | * @brief:set wifi mode to AP mode. 8 | * 9 | * @returns:success 0, others failed 10 | */ 11 | int32_t jl_softap_enter_ap_mode(void); 12 | 13 | /** 14 | * @brief:set softap config stop. 15 | * 16 | * @returns:success 0, others failed 17 | */ 18 | int32_t jl_softap_config_stop(void); 19 | 20 | /** 21 | * @brief:System is expected to get product information that user regiested in Cloud platform. 22 | * 23 | * @param[out]: UUID , max length: 8 24 | * @param[out]: BRAND, max length: 8 25 | * @param[out]: CID, max length: 8 26 | * @param[out]: dev_soft_ssid max length: 32 27 | * 28 | * @returns:success 0, others failed 29 | */ 30 | int32_t jl_softap_get_product_info(char *uuid, char *brand, char *cid, char *dev_soft_ssid); 31 | 32 | /** 33 | * @brief:System is expected to connect wifi router with the in parameters. 34 | * 35 | * @param[in]: ssid of wifi router 36 | * @param[in]: passwd of wifi router 37 | * 38 | * @returns:success 0, others failed 39 | */ 40 | int32_t jl_softap_connect_wifi_router(char *ssid, char *passwd); 41 | 42 | /** 43 | * @brief: save wifi information 44 | * 45 | * @param[in] ssid 46 | * @param[in] password 47 | * 48 | * @returns: void 49 | */ 50 | void esp_joylink_wifi_save_info(uint8_t*ssid,uint8_t*password); 51 | #endif 52 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_stdint.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_STDINT_H_ 2 | #define _JOYLINK_STDINT_H_ 3 | #include 4 | 5 | #endif /* stdint.h */ 6 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_STDIO_H_ 2 | #define _JOYLINK_STDIO_H_ 3 | 4 | #include 5 | #include "joylink_stdint.h" 6 | 7 | /** @} */ /* end of platform_memory_manage */ 8 | 9 | /** 10 | * @brief 将数据格式化打印到流 11 | * 12 | * @param [in] fmt: @n String that contains the text to be written, it can optionally contain embedded format specifiers 13 | that specifies how subsequent arguments are converted for output. 14 | * @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 15 | * @return None. 16 | * @see None. 17 | * @note None. 18 | */ 19 | int32_t jl_platform_printf(const char *fmt, ...); 20 | 21 | /** 22 | * @brief 将数据安格式化写入到字符串 23 | * 24 | * @param [out] str: @n String that holds written text. 25 | * @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers 26 | that specifies how subsequent arguments are converted for output. 27 | * @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 28 | * @return bytes of character successfully written into string. 29 | * @see None. 30 | * @note None. 31 | */ 32 | int32_t jl_platform_sprintf(char *str, const char *fmt, ...); 33 | 34 | /** 35 | * @brief 将数据安指定长度格式化写入到字符串 36 | * 37 | * @param [out] str: @n String that holds written text. 38 | * @param [in] len: @n Maximum length of character will be written 39 | * @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers 40 | that specifies how subsequent arguments are converted for output. 41 | * @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 42 | * @return bytes of character successfully written into string. 43 | * @see None. 44 | * @note None. 45 | */ 46 | int32_t jl_platform_snprintf(char *str, const int32_t len, const char *fmt, ...); 47 | 48 | /** 49 | * @brief 将字符串格式化写入到数据 50 | * 51 | * @param [in] str: @n String that holds written text. 52 | * @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers 53 | that specifies how subsequent arguments are converted for output. 54 | * @param [out] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 55 | * @return bytes of character successfully written into string. 56 | * @see None. 57 | * @note None. 58 | */ 59 | int jl_platform_sscanf(const char *str, const char *format, ...); 60 | 61 | /** @defgroup group_platform_file_api_manage 62 | * @{ 63 | */ 64 | 65 | /** 66 | * @brief Opens the file whose name is specified in the parameter filename and associates it 67 | * with a stream that can be identified in future operations by the void pointer returned. 68 | * 69 | * @param [in] path: @n The file path to open.With reference to fopen 70 | * @param [in] mode: @n C string containing a file access mode. 71 | * @return If the file is successfully opened, the function returns a pointer to void object that can be used to 72 | * identify the stream on future operations.Otherwise, a null pointer is returned. 73 | * @see None. 74 | * @note None. 75 | */ 76 | void *jl_platform_fopen(const char *path, const char *mode); 77 | 78 | /** 79 | * @brief Reads an array of count elements, each one with a size of size bytes, from the stream and 80 | * stores them in the block of memory specified by ptr. 81 | * 82 | * @param [in] buff: @n Pointer to a block of memory with a size of at least (size*count) bytes, converted to a void*. 83 | * @param [in] size: @n size in bytes, of each element to be read. 84 | * @param [in] count: @n Number of elements, each one with a size of size bytes. 85 | * @param [in] stream: @n Pointer to void that specifies an input stream. 86 | * @return The total number of elements successfully read is returned.If either size or count is zero, the function returns zero 87 | * @see None. 88 | * @note None. 89 | */ 90 | uint32_t jl_platform_fread(void *buff, uint32_t size, uint32_t count, void *stream); 91 | 92 | /** 93 | * @brief Writes an array of count elements, each one with a size of size bytes, from the block of memory pointed 94 | * by ptr to the current position in the stream. 95 | * 96 | * @param [in] ptr: @n Pointer to the array of elements to be written, converted to a const void*. 97 | * @param [in] size: @n Size in bytes of each element to be written. 98 | * @param [in] count: @n Number of elements, each one with a size of size bytes. 99 | * @param [in] stream: @n Pointer to void that specifies an output stream. 100 | * @return The total number of elements successfully written is returned.If either size or count is zero, the function returns zero. 101 | * @see None. 102 | * @note None. 103 | */ 104 | uint32_t jl_platform_fwrite(const void *ptr, uint32_t size, uint32_t count, void *stream); 105 | 106 | /** 107 | * @brief Sets the position indicator associated with the stream to a new position. 108 | * 109 | * @param [in] stream: @n Pointer to void that identifies the stream. 110 | * @param [in] offset: @n Binary files: Number of bytes to offset from origin. 111 | * @param [in] origin: @n Position used as reference for the offset. It is specified by one of value enum in hal_fs_seek_type_t. 112 | * 113 | * @return If successful, the function returns zero.Otherwise, it returns non-zero value. 114 | * @see None. 115 | * @note None. 116 | */ 117 | int32_t jl_platform_fseek(void *stream, long offset, int32_t origin); 118 | 119 | /** 120 | * @brief Closes the file associated with the stream and disassociates it. 121 | * 122 | * @param [in] stream: @n Pointer to void that identifies the stream. 123 | * 124 | * @return If the stream is successfully closed, a zero value is returned.On failure, non-zero is returned. 125 | * @see None. 126 | * @note None. 127 | */ 128 | int32_t jl_platform_fclose(void *stream); 129 | 130 | /** 131 | * @brief Closes the file associated with the stream and disassociates it. 132 | * 133 | * @param [in] stream: @n Pointer to void that identifies the stream. 134 | * 135 | * @return If the stream is successfully flushed, a zero value is returned.On failure, non-zero is returned. 136 | * @see None. 137 | * @note None. 138 | */ 139 | int32_t jl_platform_fflush(void *stream); 140 | 141 | /** @} */ /* end of platform_file_api_manage */ 142 | 143 | /** @defgroup group_platform_net_api_manage 144 | * @{ 145 | */ 146 | 147 | /** 148 | * brief: 149 | * 150 | * @Param: msg 151 | * @Param: buff 152 | * @Param: len 153 | */ 154 | void jl_print_buffer(const char *msg, const uint8_t *buff, int len); 155 | 156 | /* 157 | * @brief get a random 158 | * 159 | * @param none 160 | * @return the random value 161 | */ 162 | int32_t jl_get_random(void); 163 | 164 | #endif 165 | 166 | 167 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_string.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_STRING_H_ 2 | #define _JOYLINK_STRING_H_ 3 | 4 | #include 5 | #include "joylink_stdint.h" 6 | 7 | /** @defgroup group_platform_string_api_manage 8 | * @{ 9 | */ 10 | 11 | /** 12 | * @brief 把 src 所指向的字符串复制到 dest 13 | * 14 | * @param[in] dest: 指向用于存储复制内容的目标数组 15 | * @param[in] src: 要复制的字符串 16 | * @return 17 | 一个指向最终的目标字符串 dest 的指针。 18 | * @see None. 19 | * @note None. 20 | */ 21 | char *jl_platform_strcpy(char *dest, const char *src); 22 | 23 | /** 24 | * @brief 把 src 所指向的字符串复制指定长度到 dest 25 | * 26 | * @param[in] dest: 指向用于存储复制内容的目标数组 27 | * @param[in] src: 要复制的字符串 28 | * @param[in] n: 要复制的字符串的长度 29 | * @return 30 | 一个指向最终的目标字符串 dest 的指针。 31 | * @see None. 32 | * @note None. 33 | */ 34 | char *jl_platform_strncpy(char *dest, const char*src, int n); 35 | 36 | /** 37 | * @brief 在参数 str 所指向的字符串中搜索第一次出现字符 c(一个无符号字符)的位置。 38 | * 39 | * @param[in] s: 要被检索的 C 字符串。 40 | * @param[in] c: 在 str 中要搜索的字符。 41 | * @return 42 | 该函数返回在字符串 str 中第一次出现字符 c 的位置,如果未找到该字符则返回 NULL。 43 | * @see None. 44 | * @note None. 45 | */ 46 | char *jl_platform_strchr(const char *s, int32_t c); 47 | 48 | /** 49 | * @brief 在字符串 haystack 中查找第一次出现字符串 needle 的位置,不包含终止符 '\0' 50 | * 51 | * @param[in] haystack: 要被检索的 C 字符串 52 | * @param[in] needle: 在 haystack 字符串内要搜索的小字符串 53 | * @return 54 | 该函数返回在 haystack 中第一次出现 needle 字符串的位置,如果未找到则返回 null 55 | * @see None. 56 | * @note None. 57 | */ 58 | char *jl_platform_strstr(const char *haystack, const char* needle); 59 | 60 | /** 61 | * @brief 把 s1 所指向的字符串和 s2 所指向的字符串进行比较 62 | * 63 | * @param[in] s1: 要进行比较的第一个字符串 64 | * @param[in] s2: 要进行比较的第二个字符串 65 | * @return 66 | 如果返回值 < 0,则表示 s1 小于 s2 67 | 如果返回值 > 0,则表示 s2 小于 s1 68 | 如果返回值 = 0,则表示 s1 等于 s2 69 | * @see None. 70 | * @note None. 71 | */ 72 | int32_t jl_platform_strcmp(const char *s1, const char *s2); 73 | 74 | /** 75 | * @brief 把 s1 所指向的字符串和 s2 所指向的字符串进行比较, 最多比较前 n 个字节 76 | * 77 | * @param[in] s1: 要进行比较的第一个字符串 78 | * @param[in] s2: 要进行比较的第二个字符串 79 | * @param[in] n: 要比较的最大字符数 80 | * @return 81 | 如果返回值 < 0,则表示 s1 小于 s2 82 | 如果返回值 > 0,则表示 s2 小于 s1 83 | 如果返回值 = 0,则表示 s1 等于 s2 84 | * @see None. 85 | * @note None. 86 | */ 87 | int32_t jl_platform_strncmp(const char *s1, const char *s2, uint32_t n); 88 | 89 | /** 90 | * @brief 把参数 str 所指向的字符串转换为一个整数(类型为 int 型) 91 | * 92 | * @param[in] nptr: 要转换为整数的字符串 93 | * @return 94 | 该函数返回转换后的长整数,如果没有执行有效的转换,则返回零 95 | * @see None. 96 | * @note None. 97 | */ 98 | int32_t jl_platform_atoi(const char* nptr); 99 | 100 | /** 101 | * @brief 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符 102 | * 103 | * @param[in] s: 要计算长度的字符串. 104 | * @return 105 | * 该函数返回字符串的长度 106 | * @see None. 107 | * @note None. 108 | */ 109 | uint32_t jl_platform_strlen(const char *s); 110 | 111 | /** @} */ /* end of platform_string_api_manage */ 112 | 113 | 114 | #endif 115 | 116 | 117 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_thread.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYLINK_THREAD_H_ 2 | #define _JOYLINK_THREAD_H_ 3 | 4 | #include 5 | #include "joylink_stdint.h" 6 | 7 | //Mutex 8 | typedef void* jl_mutex_t; 9 | 10 | //Semaphore 11 | typedef void* jl_semaphore_t; 12 | 13 | //Queue 14 | typedef void* jl_queue_handle; 15 | 16 | //Task 17 | typedef void* jl_task_handle_t; 18 | 19 | //Timer 20 | typedef void* jl_timer_handle_t; 21 | 22 | typedef unsigned char JL_THREAD_PRI_T; 23 | 24 | enum JL_THREAD_PRI{ 25 | JL_THREAD_PRI_DEFAULT, /*priority: default*/ 26 | JL_THREAD_PRI_LOWEST, /*priority: lowest*/ 27 | JL_THREAD_PRI_LOW, /*priority: low*/ 28 | JL_THREAD_PRI_HIGH, /*priority: high*/ 29 | JL_THREAD_PRI_HIGHEST, /*priority: highest*/ 30 | } ; 31 | 32 | enum JL_MUTEX_TYPE { 33 | JL_MUTEX_TYPE_NORMAL, 34 | JL_MUTEX_TYPE_RECURSIVE, 35 | }; 36 | 37 | typedef void (*threadtask)(void *arg); 38 | 39 | typedef struct{ 40 | jl_task_handle_t handle; /*thread handle*/ 41 | JL_THREAD_PRI_T priority; /*initial thread priority*/ 42 | size_t stackSize; /*stack size requirements in bytes; 0 is default stack size*/ 43 | threadtask thread_task; /*thread task func*/ 44 | void *parameter; /*thread user para*/ 45 | char isRunning; /*thread running state 0:thread is running 1:thread is ideal*/ 46 | }jl_thread_t; 47 | 48 | typedef void (*TimerCallback)( void *userData); 49 | 50 | typedef struct _jl_timer_t{ 51 | uint32_t periodicInterval; 52 | TimerCallback callback; 53 | void *userData; 54 | jl_timer_handle_t handle; 55 | }jl_timer_t; 56 | 57 | 58 | /*********************************** mutex interface ***********************************/ 59 | 60 | /** @defgroup group_platform_mutex mutex 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @brief 创建互斥锁 66 | * 67 | * @retval NULL : Initialize mutex failed. 68 | * @retval NOT_NULL : The mutex handle. 69 | * @see None. 70 | * @note None. 71 | */ 72 | jl_mutex_t jl_platform_mutex_create(int32_t type); 73 | 74 | /** 75 | * @brief 等待指定的互斥锁 76 | * 77 | * @param [in] mutex @n the specified mutex. 78 | * @return None. 79 | * @see None. 80 | * @note None. 81 | */ 82 | int32_t jl_platform_mutex_lock(jl_mutex_t handle); 83 | 84 | /** 85 | * @brief 释放指定的互斥锁 86 | * 87 | * @param [in] mutex @n the specified mutex. 88 | * @return None. 89 | * @see None. 90 | * @note None. 91 | */ 92 | int32_t jl_platform_mutex_unlock(jl_mutex_t handle); 93 | 94 | /** 95 | * @brief 销毁互斥锁,并回收所占用的资源 96 | * 97 | * @param [in] mutex @n The specified mutex. 98 | * @return None. 99 | * @see None. 100 | * @note None. 101 | */ 102 | void jl_platform_mutex_delete(jl_mutex_t handle); 103 | 104 | /** 105 | * @brief 创建一个计数信号量 106 | * 107 | * @return semaphore handle. 108 | * @see None. 109 | * @note The recommended value of maximum count of the semaphore is 255. 110 | */ 111 | jl_semaphore_t jl_platform_semaphore_create(void); 112 | 113 | /** 114 | * @brief 销毁一个计数信号量, 回收其所占用的资源 115 | * 116 | * @param[in] sem @n the specified sem. 117 | * @return None. 118 | * @see None. 119 | * @note None. 120 | */ 121 | void jl_platform_semaphore_destroy(jl_semaphore_t handle); 122 | 123 | /** 124 | * @brief 在指定的计数信号量上做自减操作并等待 125 | * 126 | * @param[in] sem @n the specified semaphore. 127 | * @param[in] timeout_ms @n timeout interval in millisecond. 128 | If timeout_ms is PLATFORM_WAIT_INFINITE, the function will return only when the semaphore is signaled. 129 | * @return 130 | @verbatim 131 | = 0: The state of the specified object is signaled. 132 | = -1: The time-out interval elapsed, and the object's state is nonsignaled. 133 | @endverbatim 134 | * @see None. 135 | * @note None. 136 | */ 137 | void jl_platform_semaphore_wait(jl_semaphore_t handle, uint32_t timeout_ms); 138 | 139 | /** 140 | * @brief 在指定的计数信号量上做自增操作, 解除其它线程的等待 141 | * 142 | * @param[in] sem @n the specified semaphore. 143 | * @return None. 144 | * @see None. 145 | * @note None. 146 | */ 147 | void jl_platform_semaphore_post(jl_semaphore_t handle); 148 | 149 | /** 150 | * @brief 按照指定入参创建一个线程 151 | * 152 | * @param[out] thread_handle @n The new thread handle, memory allocated before thread created and return it, free it after thread joined or exit. 153 | * @param[in] pri @n thread priority 154 | * @param[in] stacksize @n stack size requirements in bytes 155 | * @return 156 | @verbatim 157 | = 0 : on success. 158 | = -1: error occur. 159 | @endverbatim 160 | * @see None. 161 | * @note None. 162 | */ 163 | int32_t jl_platform_thread_create(jl_thread_t* thread_handle, JL_THREAD_PRI_T pri, size_t stacksize); 164 | 165 | /** 166 | * @brief 通过线程句柄启动指定得任务 167 | * 168 | * @param[in] thread_handle @n the thread handle 169 | * @param[in] task @n specify the task to start on thread_handle 170 | * @param[in] parameter @n user parameter input 171 | * @return 172 | * @see None. 173 | * @note None. 174 | */ 175 | void jl_platform_thread_start(jl_thread_t* thread_handle); 176 | 177 | /** 178 | * @brief 设置指定的线程为`Detach`状态 179 | * 180 | * @param[in] thread_handle: pointer to thread handle. 181 | * @return None. 182 | * @see None. 183 | * @note None. 184 | */ 185 | void jl_platform_thread_detach(jl_thread_t* thread_handle); 186 | 187 | /** 188 | * @brief 线程主动退出 189 | * 190 | * @param[in] thread_handle: pointer to thread handle. 191 | * @return None. 192 | * @see None. 193 | * @note None. 194 | */ 195 | void jl_platform_thread_exit(jl_thread_t* thread_handle); 196 | 197 | /** 198 | * @brief 杀死指定的线程 199 | * 200 | * @param[in] thread_handle: pointer to thread handle, NULL means itself 201 | * @return None. 202 | * @see None. 203 | * @note None. 204 | */ 205 | void jl_platform_thread_delete(jl_thread_t* thread_handle); 206 | 207 | /** 208 | * @brief 获取线程执行状态 209 | * 210 | * @param[in] thread_handle: pointer to thread handle. 211 | * @return 212 | 0:idel 213 | 1:running 214 | * @see None. 215 | * @note None. 216 | */ 217 | int32_t jl_platform_thread_isrunning(jl_thread_t* thread_handle); 218 | 219 | 220 | /** 221 | * 创建定时器 222 | * 223 | * @param htimer:Timer handler 224 | * @return 0:success, -1:failed. 225 | * 226 | */ 227 | int32_t jl_timer_create(jl_timer_t *htimer); 228 | 229 | /** 230 | * 启动定时器 231 | * 232 | * @param htimer:Timer handler 233 | * @return 0:success, -1:failed. 234 | */ 235 | int32_t jl_timer_start(jl_timer_t *htimer); 236 | 237 | /** 238 | * 停止定时器 239 | * 240 | * @param htimer:Timer handler 241 | * @return 0:success, -1:failed. 242 | * 243 | */ 244 | int32_t jl_timer_stop(jl_timer_t *htimer); 245 | 246 | /** 247 | * 删除定时器 248 | * 249 | * @param htimer:Timer handler 250 | * @return 0:success, -1:failed. 251 | * 252 | */ 253 | int32_t jl_timer_delete(jl_timer_t *htimer); 254 | 255 | /** 256 | * @brief 毫秒级休眠 257 | * 258 | * @param [in] ms @n the time interval for which execution is to be suspended, in milliseconds. 259 | * @return None. 260 | * @see None. 261 | * @note None. 262 | */ 263 | void jl_platform_msleep(uint32_t ms); 264 | 265 | #endif 266 | 267 | 268 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/inc/joylink_time.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_TIMER_H__ 2 | #define __JOYLINK_TIMER_H__ 3 | 4 | #include 5 | #include 6 | #include "joylink_stdint.h" 7 | 8 | 9 | typedef struct{ 10 | uint32_t year; /* 年份,其值等于实际年份减去1900 */ 11 | uint8_t month; /* 月份(从一月开始,0代一月),取值区间为[0,11]*/ 12 | uint8_t week; /*星期,取值区间为[0,6],其中0代表星期天,1代表星期一 ,以此内推*/ 13 | uint8_t day; /* 一个月中的日期,取值区间为[1,31] */ 14 | uint8_t hour; /* 时,取值区间为[0 ,23] */ 15 | uint8_t minute; /* 分,取值区间为 [0 ,59] */ 16 | uint8_t second; /* 秒,取值区间为[0,59] */ 17 | uint32_t timestamp; /*秒,时间戳 */ 18 | }jl_time_t; 19 | 20 | typedef struct { 21 | uint32_t second; 22 | uint32_t ms; 23 | } jl_time_stamp_t; 24 | 25 | /** 26 | * set utc timestamp 27 | * @param[in] time_stamp_ms : timestamp(ms) 28 | * @return: success or fail 29 | * 30 | */ 31 | int32_t jl_set_UTCtime(jl_time_stamp_t ts); 32 | 33 | /** 34 | * @brief get timestamp(ms) 35 | * @param none 36 | * @return time ms 37 | */ 38 | int jl_get_time_msec(jl_time_stamp_t *ts); 39 | 40 | /** 41 | * get timestamp(ms) 42 | * 43 | * @return: UTC Second 44 | * 45 | */ 46 | uint32_t jl_get_time_second(uint32_t *jl_time); 47 | 48 | /** 49 | * get time string 50 | * 51 | * @out param: 52 | * @return: success or fail 53 | * 54 | */ 55 | int jl_get_time(jl_time_t *jl_time); 56 | 57 | /** 58 | * get time string 59 | * 60 | * @out param: "year-month-day hour:minute:second" 61 | * @return: success or fail 62 | * 63 | */ 64 | char *jl_get_time_str(void); 65 | 66 | /** 67 | * get os time 68 | * 69 | * @out param: none 70 | * @return: sys time ticks ms since sys start 71 | */ 72 | 73 | uint32_t jl_get_os_time(void); 74 | 75 | #endif 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/src/joylink_flash.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // joylink platform layer header files 7 | #include "joylink_flash.h" 8 | 9 | /** 10 | * @brief:set data in jl_flash 11 | * 12 | * @param: key, value 13 | * 14 | * @returns: success 0, failed -1 15 | */ 16 | int32_t jl_flash_SetInt8(const char* key, int8_t value) 17 | { 18 | #ifdef __LINUX_PAL__ 19 | FILE *fp = NULL; 20 | if (strcmp(key, KEY_FAC) == 0) { 21 | fp = fopen("/tmp/flashfac.txt", "wb+"); 22 | } else if (strcmp(key, KEY_SDK) == 0) { 23 | fp = fopen("/tmp/flashsdk.txt", "wb+"); 24 | } 25 | fwrite(&value, sizeof(int8_t), 1, fp); 26 | fclose(fp); 27 | fp = NULL; 28 | return 0; 29 | #else 30 | return 0; 31 | #endif 32 | } 33 | 34 | int32_t jl_flash_SetInt32(const char* key, int32_t value) 35 | { 36 | #ifdef __LINUX_PAL__ 37 | FILE *fp = NULL; 38 | if (strcmp(key, KEY_FAC) == 0) { 39 | fp = fopen("/tmp/flashfac.txt", "wb+"); 40 | } else if (strcmp(key, KEY_SDK) == 0) { 41 | fp = fopen("/tmp/flashsdk.txt", "wb+"); 42 | } 43 | fwrite(&value, sizeof(int32_t), 1, fp); 44 | fclose(fp); 45 | fp = NULL; 46 | return 0; 47 | #else 48 | return 0; 49 | #endif 50 | } 51 | 52 | int32_t jl_flash_SetInt64(const char* key, int64_t value) 53 | { 54 | #ifdef __LINUX_PAL__ 55 | FILE *fp = NULL; 56 | if (strcmp(key, KEY_FAC) == 0) { 57 | fp = fopen("/tmp/flashfac.txt", "wb+"); 58 | } else if (strcmp(key, KEY_SDK) == 0) { 59 | fp = fopen("/tmp/flashsdk.txt", "wb+"); 60 | } 61 | fwrite(&value, sizeof(int64_t), 1, fp); 62 | fclose(fp); 63 | fp = NULL; 64 | return 0; 65 | #else 66 | return 0; 67 | #endif 68 | } 69 | 70 | int32_t jl_flash_SetString(const char* key, const char* value, int32_t len) 71 | { 72 | #ifdef __LINUX_PAL__ 73 | int32_t ret = -1; 74 | FILE *fp = NULL; 75 | if (strcmp(key, KEY_FAC) == 0) { 76 | fp = fopen("/tmp/flashfac.txt", "wb+"); 77 | } else if (strcmp(key, KEY_SDK) == 0) { 78 | fp = fopen("/tmp/flashsdk.txt", "wb+"); 79 | } 80 | 81 | int write_len = fwrite(value, sizeof(char), len, fp); 82 | if (write_len <= 0 || write_len != len) { 83 | printf("fwrite error!\n"); 84 | ret = -1; 85 | } else { 86 | printf("fwrite success, write_len:%d\n", write_len); 87 | ret = 0; 88 | } 89 | fclose(fp); 90 | fp = NULL; 91 | return ret; 92 | #else 93 | return 0; 94 | #endif 95 | } 96 | 97 | int32_t jl_flash_SetBool(const char* key, int8_t value) 98 | { 99 | #ifdef __LINUX_PAL__ 100 | FILE *fp = NULL; 101 | if (strcmp(key, KEY_FAC) == 0) { 102 | fp = fopen("/tmp/flashfac.txt", "wb+"); 103 | } else if (strcmp(key, KEY_SDK) == 0) { 104 | fp = fopen("/tmp/flashsdk.txt", "wb+"); 105 | } 106 | fwrite(&value, sizeof(int8_t), 1, fp); 107 | fclose(fp); 108 | fp = NULL; 109 | return 0; 110 | #else 111 | return 0; 112 | #endif 113 | } 114 | 115 | 116 | /** 117 | * @brief:get data from jl_flash 118 | * 119 | * @param: key, value 120 | * 121 | * @returns: 读取到的value值或value长度len, 如果读取失败则返回-1 122 | */ 123 | int8_t jl_flash_GetInt8(const char* key, int8_t defaultValue) 124 | { 125 | #ifdef __LINUX_PAL__ 126 | FILE *fp = NULL; 127 | int8_t value = 0; 128 | if (strcmp(key, KEY_FAC) == 0) { 129 | fp = fopen("/tmp/flashfac.txt", "rb+"); 130 | } else if (strcmp(key, KEY_SDK) == 0) { 131 | fp = fopen("/tmp/flashsdk.txt", "rb+"); 132 | } 133 | if (fread(&value, sizeof(int8_t), 1, fp) == 0) { 134 | value = defaultValue; 135 | printf("jl_flash_GetInt8, fread failed, value = defaultValue\n"); 136 | } 137 | fclose(fp); 138 | fp = NULL; 139 | printf("jl_flash_GetInt8, value = %d\n", value); 140 | return value; 141 | #else 142 | return 0; 143 | #endif 144 | } 145 | 146 | int32_t jl_flash_GetInt32(const char* key, int32_t defaultValue) 147 | { 148 | #ifdef __LINUX_PAL__ 149 | FILE *fp = NULL; 150 | int32_t value = 0; 151 | if (strcmp(key, KEY_FAC) == 0) { 152 | fp = fopen("/tmp/flashfac.txt", "rb+"); 153 | } else if (strcmp(key, KEY_SDK) == 0) { 154 | fp = fopen("/tmp/flashsdk.txt", "rb+"); 155 | } 156 | if (fread(&value, sizeof(int32_t), 1, fp) == 0) { 157 | value = defaultValue; 158 | printf("jl_flash_GetInt32, fread failed, value = defaultValue\n"); 159 | } 160 | fclose(fp); 161 | fp = NULL; 162 | printf("jl_flash_GetInt32, value = %d\n", value); 163 | return value; 164 | #else 165 | return 0; 166 | #endif 167 | } 168 | 169 | int64_t jl_flash_GetInt64(const char* key, int64_t defaultValue) 170 | { 171 | #ifdef __LINUX_PAL__ 172 | FILE *fp = NULL; 173 | int64_t value = 0; 174 | if (strcmp(key, KEY_FAC) == 0) { 175 | fp = fopen("/tmp/flashfac.txt", "rb+"); 176 | } else if (strcmp(key, KEY_SDK) == 0) { 177 | fp = fopen("/tmp/flashsdk.txt", "rb+"); 178 | } 179 | if (fread(&value, sizeof(int64_t), 1, fp) == 0) { 180 | value = defaultValue; 181 | printf("jl_flash_GetInt64, fread failed, value = defaultValue\n"); 182 | } 183 | fclose(fp); 184 | fp = NULL; 185 | printf("jl_flash_GetInt64, value = %"PRId64" \n", value); 186 | return value; 187 | #else 188 | return 0; 189 | #endif 190 | } 191 | 192 | int32_t jl_flash_GetString(const char* key, char* buff, int32_t len) 193 | { 194 | #ifdef __LINUX_PAL__ 195 | int32_t read_len; 196 | FILE *fp = NULL; 197 | if (strcmp(key, KEY_FAC) == 0) { 198 | fp = fopen("/tmp/flashfac.txt", "rb+"); 199 | } else if (strcmp(key, KEY_SDK) == 0) { 200 | fp = fopen("/tmp/flashsdk.txt", "rb+"); 201 | } 202 | if (fp == NULL) { 203 | return 0; 204 | } 205 | 206 | read_len = fread(buff, sizeof(char), len, fp); 207 | if (read_len == 0) { 208 | printf("jl_flash_GetString, fread failed, len = %d, read_len = 0\n", len); 209 | } else { 210 | printf("jl_flash_GetString, buff = %s, read_len = %d\n", buff, read_len); 211 | } 212 | 213 | fclose(fp); 214 | fp = NULL; 215 | return read_len; 216 | #else 217 | return 0; 218 | #endif 219 | } 220 | 221 | int8_t jl_flash_GetBool(const char* key, int8_t defaultValue) 222 | { 223 | #ifdef __LINUX_PAL__ 224 | FILE *fp = NULL; 225 | int8_t value = 0; 226 | if (strcmp(key, KEY_FAC) == 0) { 227 | fp = fopen("/tmp/flashfac.txt", "rb+"); 228 | } else if (strcmp(key, KEY_SDK) == 0) { 229 | fp = fopen("/tmp/flashsdk.txt", "rb+"); 230 | } 231 | if (fread(&value, sizeof(int8_t), 1, fp) == 0) { 232 | value = defaultValue; 233 | printf("jl_flash_GetBool, fread failed, value = defaultValue\n"); 234 | } 235 | fclose(fp); 236 | fp = NULL; 237 | printf("jl_flash_GetBool, value = %d\n", value); 238 | return value; 239 | #else 240 | return 0; 241 | #endif 242 | } 243 | 244 | /** 245 | * @brief:clear jl_flash data 246 | * 247 | * @param: key 248 | * 249 | * @returns: none 250 | */ 251 | void jl_flash_ClearKey(const char *key) 252 | { 253 | #ifdef __LINUX_PAL__ 254 | if (strcmp(key, KEY_FAC) == 0) { 255 | system("> /tmp/flashfac.txt"); 256 | } else if (strcmp(key, KEY_SDK) == 0) { 257 | system("> /tmp/flashsdk.txt"); 258 | } 259 | #else 260 | return; 261 | #endif 262 | } 263 | 264 | /** 265 | * @brief: 二进制数据写入flash 266 | * 267 | * @param[in] offset: flash地址偏移 268 | * 269 | * @param[in] buf: 写入flash的数据 270 | * 271 | * @param[in] len: 要写入数据的长度 272 | * 273 | * @return 返回实际写入的数据长度,写入失败则返回-1 274 | * 275 | */ 276 | 277 | int32_t jl_flash_SetBuffer(int32_t offset, const void* buf, int32_t len) 278 | { 279 | return 0; 280 | } 281 | 282 | /** 283 | * @brief: SDK申请预留flash空间 284 | * 285 | * @param[in] size: 申请空间的大小,字节为单位 286 | * 287 | * @return: 申请flash空间的偏移,如果申请失败则返回-1 288 | * 289 | */ 290 | int32_t jl_flash_request(int32_t size) 291 | { 292 | return 0; 293 | } 294 | 295 | /** 296 | * @brief: 读取指定偏移地址的数据 297 | * 298 | * @param[in] offset: flash偏移地址 299 | * 300 | * @param[out] buf: 存储读取数据的buffer 301 | * 302 | * @param[in] len: 预期读取的数据长度 303 | * 304 | * @return int32_t: 实际读取的数据长度,如果读取失败则返回-1 305 | * 306 | */ 307 | 308 | int32_t jl_flash_GetBuffer(int32_t offset, const void* buf, int32_t len) 309 | { 310 | return 0; 311 | } 312 | 313 | /** 314 | * @brief: 清除指定偏移地址的数据 315 | * 316 | * @param[in] offset: flash偏移地址 317 | * 318 | * @param[in] len: 预期读取的数据长度 319 | * 320 | * @return int32_t: 实际读取的数据长度,如果读取失败则返回-1 321 | * 322 | */ 323 | int32_t jl_flash_ClearBuffer(int32_t offset, int32_t len) 324 | { 325 | return 0; 326 | } -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/src/joylink_http.c: -------------------------------------------------------------------------------- 1 | 2 | #include "joylink_socket.h" 3 | #include "joylink_http.h" 4 | #include "joylink_string.h" 5 | #include "joylink_memory.h" 6 | #include "joylink_stdio.h" 7 | #include "joylink_log.h" 8 | #include "esp_tls.h" 9 | 10 | #define SET_HTTP_RECV_MAX_LEN 64 11 | 12 | static int joylink_dev_http_parse_content( 13 | char *response, 14 | int response_len, 15 | char *content, 16 | int content_len) 17 | { 18 | int length = 0; 19 | content[0] = 0; 20 | 21 | char *p = jl_platform_strstr(response, "\r\n\r\n"); 22 | if(p == NULL){ 23 | return -1; 24 | } 25 | p += 4; 26 | length = response_len - (p - response); 27 | length = length > content_len ? content_len - 1 : length; 28 | jl_platform_strncpy(content, p, length); 29 | content[length] = 0; 30 | // log_info("content = \r\n%s", content); 31 | 32 | return length; 33 | } 34 | 35 | static void jl_platform_get_host(char *url, char *host, char *path) 36 | { 37 | char *p = NULL, *p1 = NULL; 38 | int length = 0; 39 | 40 | jl_platform_strcpy(host, url); 41 | path[0] = '\0'; 42 | p = jl_platform_strstr(url, "://"); 43 | if(p == NULL){ 44 | goto RET; 45 | } 46 | p += 3; 47 | p1 = jl_platform_strchr(p, '/'); 48 | length = p1 - p; 49 | if(length >= 0) 50 | { 51 | // 如果有路径 52 | jl_platform_memcpy(host, p, length); 53 | host[length] = '\0'; 54 | jl_platform_strcpy(path, p1); 55 | length = jl_platform_strlen(p1); 56 | path[length] = '\0'; 57 | } 58 | else 59 | { 60 | // 如果没有路径 61 | length = jl_platform_strlen(p); 62 | jl_platform_strcpy(host, p); 63 | host[length] = '\0'; 64 | path[0] = '\0'; 65 | } 66 | 67 | RET: 68 | log_debug("url = %s, host = %s, path = %s", url, host, path); 69 | 70 | return; 71 | } 72 | 73 | static char *jl_platform_get_request_data(char *host, char *path, char *header, char *body) 74 | { 75 | char *request = NULL; 76 | int length = 0, offset = 0; 77 | 78 | if (!path) 79 | { 80 | goto RET; 81 | } 82 | 83 | if (body) 84 | length = jl_platform_strlen(body); 85 | request = jl_platform_malloc(length + 300); 86 | if(request == NULL) 87 | goto RET; 88 | 89 | offset = jl_platform_sprintf(request, "POST %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nAccept: */*\r\n", path, host); 90 | if(header) 91 | offset += jl_platform_sprintf(request + offset, "%s\r\n", header); 92 | if(length) 93 | offset += jl_platform_sprintf(request + offset, "Content-Length:%d\r\n\r\n", length); 94 | if(body) 95 | offset += jl_platform_sprintf(request + offset, "%s", body); 96 | offset += jl_platform_sprintf(request + offset, "\r\n"); 97 | 98 | RET: 99 | if(!request) 100 | log_debug("request is NULL"); 101 | else 102 | log_debug("request = %s", request); 103 | 104 | return request; 105 | } 106 | 107 | int32_t jl_platform_https_request(jl_http_t *info) 108 | { 109 | int len = 0, ret = -1; 110 | char host[50]; 111 | char path[100]; 112 | char *request; 113 | 114 | if ( !info || !info->url || !info->response ) 115 | { 116 | log_error("Invalid argument\n"); 117 | return NULL; 118 | } 119 | 120 | jl_platform_get_host(info->url, host, path); 121 | esp_tls_cfg_t config = { 122 | // .skip_common_name = true, 123 | }; 124 | esp_tls_t *tls = NULL; 125 | log_debug("jl_platform_https_request host:%s\r\n", host); 126 | request = jl_platform_get_request_data(host, path, info->header, info->body); 127 | if(request) 128 | { 129 | tls = esp_tls_conn_new(host, strlen(host), 443, &config); 130 | if (tls == NULL) 131 | { 132 | jl_platform_printf("esp_tls_conn_new failed\n"); 133 | goto RET; 134 | } 135 | esp_tls_conn_write(tls, info->body, strlen(info->body)); 136 | 137 | len = esp_tls_conn_read(tls, info->response, info->resp_len); 138 | esp_tls_conn_delete(tls); 139 | } 140 | 141 | log_info("... read data length = %d, response data = \r\n%s", len, info->response); 142 | ret = joylink_dev_http_parse_content(info->response, len, info->response, info->resp_len); 143 | // log_debug("revbuf:%d, %s\r\n",len,revbuf); 144 | RET: 145 | if(request) 146 | jl_platform_free(request); 147 | 148 | return ret; 149 | } 150 | 151 | int32_t jl_platform_http_request(jl_http_t *info) 152 | { 153 | char *recv_buf = NULL; 154 | int log_socket = -1; 155 | jl_sockaddr_in saServer; 156 | char ip[20] = {0}; 157 | char host[50]; 158 | char path[100]; 159 | char *request = NULL, *p; 160 | int ret = -1; 161 | 162 | if ( !info || !info->url || !info->response) 163 | { 164 | log_error("Invalid argument\n"); 165 | return -1; 166 | } 167 | 168 | jl_platform_get_host(info->url, host, path); 169 | request = jl_platform_get_request_data(host, path, info->header, info->body); 170 | if(!request) 171 | { 172 | goto RET; 173 | } 174 | 175 | p = jl_platform_strchr(host, ':'); 176 | if(p) 177 | *p = '\0'; 178 | jl_platform_memset(ip,0,sizeof(ip)); 179 | ret = jl_platform_gethostbyname(host, ip, SOCKET_IP_ADDR_LEN); 180 | if(ret < 0){ 181 | log_error("get ip error"); 182 | goto RET; 183 | } 184 | 185 | jl_platform_memset(&saServer, 0, sizeof(saServer)); 186 | saServer.sin_family = jl_platform_get_socket_proto_domain(JL_SOCK_PROTO_DOMAIN_AF_INET); 187 | saServer.sin_port = jl_platform_htons(80); 188 | saServer.sin_addr.s_addr = jl_platform_inet_addr(ip); 189 | 190 | log_socket = jl_platform_socket(JL_SOCK_PROTO_DOMAIN_AF_INET, JL_SOCK_PROTO_TYPE_SOCK_STREAM, JL_SOCK_PROTO_PROTO_IPPROTO_TCP); 191 | if(log_socket < 0) { 192 | log_error("... Failed to allocate socket."); 193 | goto RET; 194 | } 195 | int reuseaddrEnable = 1; 196 | if (jl_platform_setsockopt(log_socket, 197 | JL_SOCK_OPT_LEVEL_SOL_SOCKET, 198 | JL_SOCK_OPT_NAME_SO_REUSEADDR, 199 | (uint8_t *)&reuseaddrEnable, 200 | sizeof(reuseaddrEnable)) < 0){ 201 | log_error("set SO_REUSEADDR error"); 202 | } 203 | 204 | /*fcntl(log_socket,F_SETFL,fcntl(log_socket,F_GETFL,0)|O_NONBLOCK);*/ 205 | 206 | if(jl_platform_connect(log_socket, (jl_sockaddr *)&saServer, sizeof(saServer)) != 0) 207 | { 208 | log_error("... socket connect failed"); 209 | goto RET; 210 | } 211 | 212 | if (jl_platform_send(log_socket, request, jl_platform_strlen(request), 0, 5000) < 0) { 213 | log_error("... socket send failed"); 214 | goto RET; 215 | } 216 | 217 | int count = 0; 218 | int offset = 0; 219 | int read_len = 0; 220 | 221 | recv_buf = (char *)jl_platform_malloc(SET_HTTP_RECV_MAX_LEN); 222 | if(recv_buf == NULL){ 223 | goto RET; 224 | } 225 | jl_platform_memset(recv_buf, 0, SET_HTTP_RECV_MAX_LEN); 226 | 227 | while(1){ 228 | offset = count * SET_HTTP_RECV_MAX_LEN + read_len; 229 | int ret_len = jl_platform_recv(log_socket, recv_buf + offset, SET_HTTP_RECV_MAX_LEN - read_len, 0, 20000); 230 | //log_debug("ret_len: %d\n", ret_len); 231 | if(ret_len > 0){ 232 | read_len += ret_len; 233 | if(read_len != SET_HTTP_RECV_MAX_LEN){ 234 | continue; 235 | } 236 | } 237 | if(read_len != SET_HTTP_RECV_MAX_LEN) 238 | { 239 | int len = offset; 240 | if(len <= 0){ 241 | log_error("read len error"); 242 | goto RET; 243 | } 244 | recv_buf[len] = '\0'; 245 | log_debug("... read data length = %d, response data = \r\n%s", len, recv_buf); 246 | joylink_dev_http_parse_content(recv_buf, len, info->response, info->resp_len); 247 | break; 248 | } 249 | char *p_now = jl_platform_realloc(recv_buf, SET_HTTP_RECV_MAX_LEN*(count+2)); 250 | if(p_now == NULL){ 251 | log_error("realloc error"); 252 | goto RET; 253 | } 254 | recv_buf = p_now; 255 | count++; 256 | read_len = 0; 257 | } 258 | ret = 0; 259 | RET: 260 | if(-1 != log_socket){ 261 | jl_platform_close(log_socket); 262 | } 263 | if(recv_buf != NULL){ 264 | jl_platform_free(recv_buf); 265 | } 266 | if(request != NULL){ 267 | jl_platform_free(request); 268 | } 269 | return ret; 270 | } -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/src/joylink_memory.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // joylink platform layer header files 6 | #include "joylink_memory.h" 7 | 8 | 9 | /** @defgroup group_platform_memory_manage memory 10 | * @{ 11 | */ 12 | 13 | 14 | /** 15 | * @brief Allocates a block of size bytes of memory, returning a pointer to the beginning of the block. 16 | * 17 | * @param [in] size @n specify block size in bytes. 18 | * @return A pointer to the beginning of the block. 19 | * @see None. 20 | * @note Block value is indeterminate. 21 | */ 22 | void *jl_platform_malloc(uint32_t size) 23 | { 24 | #ifdef __LINUX_PAL__ 25 | return malloc(size); 26 | #else 27 | return NULL; 28 | #endif 29 | } 30 | 31 | /** 32 | * @brief Changes the size of the memory block pointed to by ptr to size bytes. 33 | * 34 | * @param [in] ptr @n pointer to be realloc 35 | * @param [in] size @n specify block size in bytes for newly allocated memory 36 | * @return A pointer to the beginning of newly allocated memory. 37 | * @see None. 38 | * @note Block value is indeterminate. 39 | */ 40 | void *jl_platform_realloc(void *ptr, uint32_t size) 41 | { 42 | #ifdef __LINUX_PAL__ 43 | return realloc(ptr, size); 44 | #else 45 | return NULL; 46 | #endif 47 | } 48 | 49 | /** 50 | * @brief Allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. 51 | * 52 | * @param [in] nmemb @n array elements item counts 53 | * @param [in] size @n specify block size in bytes for every array elements 54 | * @return A pointer to the beginning of allocated memory. 55 | * @see None. 56 | * @note Block value is indeterminate. 57 | */ 58 | void *jl_platform_calloc(uint32_t nmemb, uint32_t size) 59 | { 60 | return NULL; 61 | } 62 | 63 | /** 64 | * @brief Deallocate memory block 65 | * 66 | * @param[in] ptr @n Pointer to a memory block previously allocated with platform_malloc. 67 | * @return None. 68 | * @see None. 69 | * @note None. 70 | */ 71 | void jl_platform_free(void *ptr) 72 | { 73 | #ifdef __LINUX_PAL__ 74 | free(ptr); 75 | #else 76 | #endif 77 | } 78 | 79 | /** 80 | * @brief 复制字符 value(一个无符号字符)到参数 prt 所指向的字符串的前 num 个字符 81 | * 82 | * @param[in] ptr @n 指向要填充的内存块. 83 | * @param[in] value @n 要被设置的值。该值以 int 形式传递,但是函数在填充内存块时是使用该值的无符号字符形式. 84 | * @param[in] num @n 要被设置为该值的字节数. 85 | * @return 86 | 该值返回一个指向存储区 str 的指针 87 | * @see None. 88 | * @note None. 89 | */ 90 | void *jl_platform_memset(void* ptr, int32_t value, uint32_t num) 91 | { 92 | #ifdef __LINUX_PAL__ 93 | return memset(ptr, value, num); 94 | #else 95 | return NULL; 96 | #endif 97 | } 98 | 99 | /** 100 | * @brief 从存储区 src 复制 num 个字符到存储区 dst 101 | * 102 | * @param[in] dst @n 指向用于存储复制内容的目标数组,类型强制转换为 void* 指针. 103 | * @param[in] src @n 指向要复制的数据源,类型强制转换为 void* 指针. 104 | * @param[in] num @n 要被复制的字节数. 105 | * @return 106 | 该函数返回一个指向目标存储区 str1 的指针 107 | * @see None. 108 | * @note None. 109 | */ 110 | void *jl_platform_memcpy(void* dst, const void* src, uint32_t num) 111 | { 112 | #ifdef __LINUX_PAL__ 113 | return memcpy(dst, src, num); 114 | #else 115 | return NULL; 116 | #endif 117 | } 118 | 119 | /** 120 | * @brief 把存储区 ptr1 和存储区 ptr2 的前 num 个字节进行比较 121 | * 122 | * @param[in] ptr1 @n 指向内存块的指针 123 | * @param[in] ptr2 @n 指向内存块的指针 124 | * @param[in] num @n 要被比较的字节数 125 | * @return 126 | 如果返回值 < 0,则表示 ptr1 小于 ptr2 127 | 如果返回值 > 0,则表示 ptr2 小于 ptr1 128 | 如果返回值 = 0,则表示 ptr1 等于 ptr2 129 | * @see None. 130 | * @note None. 131 | */ 132 | int32_t jl_platform_memcmp(const void* ptr1, const void* ptr2, uint32_t num) 133 | { 134 | #ifdef __LINUX_PAL__ 135 | return memcmp(ptr1, ptr2, num); 136 | #else 137 | return 0; 138 | #endif 139 | } 140 | 141 | 142 | /** @} */ /* end of platform_memory_manage */ 143 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/src/joylink_softap.c: -------------------------------------------------------------------------------- 1 | #include "joylink_string.h" 2 | #include "joylink_memory.h" 3 | #include "joylink_softap.h" 4 | 5 | #ifdef __LINUX_PAL__ 6 | #include "esp_wifi.h" 7 | #include "joylink_log.h" 8 | #include "nvs_flash.h" 9 | #endif 10 | #include "sdkconfig.h" 11 | 12 | /** 13 | * @brief:set wifi mode to AP mode. 14 | * 15 | * @returns:success 0, others failed 16 | */ 17 | int32_t jl_softap_enter_ap_mode(void) 18 | { 19 | // open wifi whit AP mode 20 | #ifdef __LINUX_PAL__ 21 | log_debug("-- set wifi AP mode"); 22 | esp_wifi_set_mode(WIFI_MODE_AP); 23 | #endif 24 | return 0; 25 | } 26 | 27 | 28 | /** 29 | * @brief:System is expected to get product information that user regiested in Cloud platform. 30 | * 31 | * @param[out]: UUID , max length: 8 32 | * @param[out]: BRAND, max length: 8 33 | * @param[out]: CID, max length: 8 34 | * @param[out]: dev_soft_ssid max length: 32 35 | * 36 | * @returns:success 0, others failed 37 | */ 38 | int32_t jl_softap_get_product_info(char *uuid, char *brand, char *cid, char *dev_soft_ssid) 39 | { 40 | char *_uuid = CONFIG_JOYLINK_DEVICE_UUID; 41 | jl_platform_strcpy(uuid, _uuid); 42 | 43 | char* _dev_soft_ssid = CONFIG_JOYLINK_SOFTAP_SSID; 44 | jl_platform_strcpy(dev_soft_ssid, _dev_soft_ssid); 45 | 46 | char *_cid = CONFIG_JOYLINK_DEVICE_CID; 47 | jl_platform_strcpy(cid, _cid); 48 | 49 | char *_brand = CONFIG_JOYLINK_DEVICE_BRAND; 50 | jl_platform_strcpy(brand, _brand); 51 | 52 | return 0; 53 | } 54 | 55 | /** 56 | * @brief: save wifi information 57 | * 58 | * @param[in] ssid 59 | * @param[in] password 60 | * 61 | * @returns: void 62 | */ 63 | void esp_joylink_wifi_save_info(uint8_t*ssid,uint8_t*password) 64 | { 65 | nvs_handle out_handle; 66 | char data[65]; 67 | if (nvs_open("joylink_wifi", NVS_READWRITE, &out_handle) != ESP_OK) { 68 | return; 69 | } 70 | 71 | memset(data,0x0,sizeof(data)); 72 | strncpy(data,(char*)ssid,strlen((char*)ssid)); 73 | if (nvs_set_str(out_handle,"ssid",data) != ESP_OK) { 74 | printf("--set ssid fail"); 75 | } 76 | 77 | memset(data,0x0,sizeof(data)); 78 | strncpy(data,(char*)password,strlen((char*)password)); 79 | if (nvs_set_str(out_handle,"password",data) != ESP_OK) { 80 | printf("--set password fail"); 81 | } 82 | nvs_close(out_handle); 83 | } 84 | 85 | /** 86 | * @brief:System is expected to connect wifi router with the in parameters. 87 | * 88 | * @param[in]: ssid of wifi router 89 | * @param[in]: passwd of wifi router 90 | * 91 | * @returns:success 0, others failed 92 | */ 93 | int32_t jl_softap_connect_wifi_router(char *ssid, char *passwd) 94 | { 95 | // step 1 close AP mode 96 | 97 | // step 2 connect to the router 98 | #ifdef __LINUX_PAL__ 99 | wifi_config_t config; 100 | 101 | log_debug("-- ready to connect to AP"); 102 | esp_wifi_set_mode(WIFI_MODE_STA); 103 | 104 | memset(&config, 0x0, sizeof(config)); 105 | esp_wifi_get_config(ESP_IF_WIFI_STA, &config); 106 | memcpy(config.sta.ssid, ssid, strlen(ssid)); 107 | memcpy(config.sta.password, passwd, strlen(passwd)); 108 | 109 | esp_wifi_set_config(ESP_IF_WIFI_STA, &config); 110 | esp_joylink_wifi_save_info(config.sta.ssid, config.sta.password); 111 | esp_wifi_connect(); 112 | #endif 113 | 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/src/joylink_stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | // joylink platform layer header files 10 | #include "joylink_stdio.h" 11 | 12 | 13 | /** 14 | * @brief 将数据格式化打印到流 15 | * 16 | * @param [in] fmt: @n String that contains the text to be written, it can optionally contain embedded format specifiers 17 | that specifies how subsequent arguments are converted for output. 18 | * @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 19 | * @return None. 20 | * @see None. 21 | * @note None. 22 | */ 23 | int32_t jl_platform_printf(const char *fmt, ...) 24 | { 25 | int32_t ret = 0; 26 | #ifdef __LINUX_PAL__ 27 | va_list args; 28 | va_start(args, fmt); 29 | ret = vprintf(fmt, args); 30 | va_end(args); 31 | #endif 32 | return ret; 33 | } 34 | 35 | /** 36 | * @brief 将数据安格式化写入到字符串 37 | * 38 | * @param [out] str: @n String that holds written text. 39 | * @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers 40 | that specifies how subsequent arguments are converted for output. 41 | * @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 42 | * @return bytes of character successfully written into string. 43 | * @see None. 44 | * @note None. 45 | */ 46 | int32_t jl_platform_sprintf(char *str, const char *fmt, ...) 47 | { 48 | int32_t ret = 0; 49 | #ifdef __LINUX_PAL__ 50 | va_list args; 51 | va_start(args, fmt); 52 | ret = vsprintf(str, fmt, args); 53 | va_end(args); 54 | #endif 55 | return ret; 56 | } 57 | 58 | /** 59 | * @brief 将数据安指定长度格式化写入到字符串 60 | * 61 | * @param [out] str: @n String that holds written text. 62 | * @param [in] len: @n Maximum length of character will be written 63 | * @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers 64 | that specifies how subsequent arguments are converted for output. 65 | * @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 66 | * @return bytes of character successfully written into string. 67 | * @see None. 68 | * @note None. 69 | */ 70 | int32_t jl_platform_snprintf(char *str, const int32_t len, const char *fmt, ...) 71 | { 72 | int32_t ret = 0; 73 | #ifdef __LINUX_PAL__ 74 | va_list args; 75 | va_start(args, fmt); 76 | ret = vsnprintf(str, len, fmt, args); 77 | va_end(args); 78 | #endif 79 | return ret; 80 | } 81 | 82 | /** 83 | * @brief 将字符串格式化写入到数据 84 | * 85 | * @param [in] str: @n String that holds written text. 86 | * @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers 87 | that specifies how subsequent arguments are converted for output. 88 | * @param [out] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers. 89 | * @return bytes of character successfully written into string. 90 | * @see None. 91 | * @note None. 92 | */ 93 | int jl_platform_sscanf(const char *str, const char *format, ...) 94 | { 95 | int ret = 0; 96 | #ifdef __LINUX_PAL__ 97 | va_list ap; 98 | va_start(ap, format); 99 | ret = vsscanf(str, format, ap); 100 | va_end(ap); 101 | #endif 102 | return ret; 103 | } 104 | 105 | /** @defgroup group_platform_file_api_manage 106 | * @{ 107 | */ 108 | 109 | /** 110 | * @brief Opens the file whose name is specified in the parameter filename and associates it 111 | * with a stream that can be identified in future operations by the void pointer returned. 112 | * 113 | * @param [in] path: @n The file path to open.With reference to fopen 114 | * @param [in] mode: @n C string containing a file access mode. 115 | * @return If the file is successfully opened, the function returns a pointer to void object that can be used to 116 | * identify the stream on future operations.Otherwise, a null pointer is returned. 117 | * @see None. 118 | * @note None. 119 | */ 120 | void *jl_platform_fopen(const char *path, const char *mode) 121 | { 122 | #ifdef __LINUX_PAL__ 123 | return fopen(path, mode); 124 | #else 125 | return NULL; 126 | #endif 127 | } 128 | 129 | /** 130 | * @brief Reads an array of count elements, each one with a size of size bytes, from the stream and 131 | * stores them in the block of memory specified by ptr. 132 | * 133 | * @param [in] buff: @n Pointer to a block of memory with a size of at least (size*count) bytes, converted to a void*. 134 | * @param [in] size: @n size in bytes, of each element to be read. 135 | * @param [in] count: @n Number of elements, each one with a size of size bytes. 136 | * @param [in] stream: @n Pointer to void that specifies an input stream. 137 | * @return The total number of elements successfully read is returned.If either size or count is zero, the function returns zero 138 | * @see None. 139 | * @note None. 140 | */ 141 | uint32_t jl_platform_fread(void *buff, uint32_t size, uint32_t count, void *stream) 142 | { 143 | #ifdef __LINUX_PAL__ 144 | return fread(buff, size, count, stream); 145 | #else 146 | return 0; 147 | #endif 148 | } 149 | 150 | /** 151 | * @brief Writes an array of count elements, each one with a size of size bytes, from the block of memory pointed 152 | * by ptr to the current position in the stream. 153 | * 154 | * @param [in] ptr: @n Pointer to the array of elements to be written, converted to a const void*. 155 | * @param [in] size: @n Size in bytes of each element to be written. 156 | * @param [in] count: @n Number of elements, each one with a size of size bytes. 157 | * @param [in] stream: @n Pointer to void that specifies an output stream. 158 | * @return The total number of elements successfully written is returned.If either size or count is zero, the function returns zero. 159 | * @see None. 160 | * @note None. 161 | */ 162 | uint32_t jl_platform_fwrite(const void *ptr, uint32_t size, uint32_t count, void *stream) 163 | { 164 | #ifdef __LINUX_PAL__ 165 | return fwrite(ptr, size, count, stream); 166 | #else 167 | return 0; 168 | #endif 169 | } 170 | 171 | /** 172 | * @brief Sets the position indicator associated with the stream to a new position. 173 | * 174 | * @param [in] stream: @n Pointer to void that identifies the stream. 175 | * @param [in] offset: @n Binary files: Number of bytes to offset from origin. 176 | * @param [in] origin: @n Position used as reference for the offset. It is specified by one of value enum in hal_fs_seek_type_t. 177 | * 178 | * @return If successful, the function returns zero.Otherwise, it returns non-zero value. 179 | * @see None. 180 | * @note None. 181 | */ 182 | int32_t jl_platform_fseek(void *stream, long offset, int32_t origin) 183 | { 184 | #ifdef __LINUX_PAL__ 185 | return fseek(stream, offset, origin); 186 | #else 187 | return -1; 188 | #endif 189 | } 190 | 191 | /** 192 | * @brief Closes the file associated with the stream and disassociates it. 193 | * 194 | * @param [in] stream: @n Pointer to void that identifies the stream. 195 | * 196 | * @return If the stream is successfully closed, a zero value is returned.On failure, non-zero is returned. 197 | * @see None. 198 | * @note None. 199 | */ 200 | int32_t jl_platform_fclose(void *stream) 201 | { 202 | #ifdef __LINUX_PAL__ 203 | return fclose(stream); 204 | #else 205 | return -1; 206 | #endif 207 | } 208 | 209 | /** 210 | * @brief Closes the file associated with the stream and disassociates it. 211 | * 212 | * @param [in] stream: @n Pointer to void that identifies the stream. 213 | * 214 | * @return If the stream is successfully flushed, a zero value is returned.On failure, non-zero is returned. 215 | * @see None. 216 | * @note None. 217 | */ 218 | int32_t jl_platform_fflush(void *stream) 219 | { 220 | #ifdef __LINUX_PAL__ 221 | fflush((FILE*)stream); 222 | return 0; 223 | #else 224 | return -1; 225 | #endif 226 | } 227 | 228 | 229 | /** 230 | * brief: 231 | * 232 | * @Param: msg 233 | * @Param: buff 234 | * @Param: len 235 | */ 236 | void jl_print_buffer(const char *msg, const uint8_t *buff, int len) 237 | { 238 | if(NULL == msg || NULL == buff){ 239 | return; 240 | } 241 | int i = 0; 242 | jl_platform_printf("len = %d, %s\r\n", len, msg); 243 | for(i =0; i < len; i++){ 244 | jl_platform_printf("%02x ", (int)buff[i]); 245 | if(!((i + 1)%4)){ 246 | jl_platform_printf("| "); 247 | } 248 | 249 | if(!((i + 1)%16)){ 250 | jl_platform_printf("\r\n"); 251 | } 252 | } 253 | jl_platform_printf("\r\n"); 254 | } 255 | 256 | /* 257 | * @brief get a random 258 | * 259 | * @param none 260 | * @return the random value 261 | */ 262 | int32_t jl_get_random(void) 263 | { 264 | #ifdef __LINUX_PAL__ 265 | return rand(); 266 | #else 267 | return 0; 268 | #endif 269 | } 270 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/src/joylink_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | // joylink platform layer header files 7 | #include "joylink_string.h" 8 | 9 | 10 | /** @defgroup group_platform_string_api_manage 11 | * @{ 12 | */ 13 | 14 | /** 15 | * @brief 把 src 所指向的字符串复制到 dest 16 | * 17 | * @param[in] dest: 指向用于存储复制内容的目标数组 18 | * @param[in] src: 要复制的字符串 19 | * @return 20 | 一个指向最终的目标字符串 dest 的指针。 21 | * @see None. 22 | * @note None. 23 | */ 24 | char *jl_platform_strcpy(char *dest, const char*src) 25 | { 26 | #ifdef __LINUX_PAL__ 27 | return strcpy(dest, src); 28 | #else 29 | return NULL; 30 | #endif 31 | } 32 | 33 | 34 | /** 35 | * @brief 把 src 所指向的字符串复制指定长度到 dest 36 | * 37 | * @param[in] dest: 指向用于存储复制内容的目标数组 38 | * @param[in] src: 要复制的字符串 39 | * @param[in] n: 要复制的字符串的长度 40 | * @return 41 | 一个指向最终的目标字符串 dest 的指针。 42 | * @see None. 43 | * @note None. 44 | */ 45 | char *jl_platform_strncpy(char *dest, const char*src, int n) 46 | { 47 | #ifdef __LINUX_PAL__ 48 | return strncpy(dest, src, n); 49 | #else 50 | return NULL; 51 | #endif 52 | } 53 | 54 | /** 55 | * @brief 在参数 str 所指向的字符串中搜索第一次出现字符 c(一个无符号字符)的位置。 56 | * 57 | * @param[in] s: 要被检索的 C 字符串。 58 | * @param[in] c: 在 str 中要搜索的字符。 59 | * @return 60 | 该函数返回在字符串 str 中第一次出现字符 c 的位置,如果未找到该字符则返回 NULL。 61 | * @see None. 62 | * @note None. 63 | */ 64 | char *jl_platform_strchr(const char *s, int32_t c) 65 | { 66 | #ifdef __LINUX_PAL__ 67 | return strchr(s, c); 68 | #else 69 | return NULL; 70 | #endif 71 | } 72 | 73 | /** 74 | * @brief 在字符串 haystack 中查找第一次出现字符串 needle 的位置,不包含终止符 '\0' 75 | * 76 | * @param[in] haystack: 要被检索的 C 字符串 77 | * @param[in] needle: 在 haystack 字符串内要搜索的小字符串 78 | * @return 79 | 该函数返回在 haystack 中第一次出现 needle 字符串的位置,如果未找到则返回 null 80 | * @see None. 81 | * @note None. 82 | */ 83 | char *jl_platform_strstr(const char *haystack, const char* needle) 84 | { 85 | #ifdef __LINUX_PAL__ 86 | return strstr(haystack, needle); 87 | #else 88 | return NULL; 89 | #endif 90 | } 91 | 92 | /** 93 | * @brief 把 s1 所指向的字符串和 s2 所指向的字符串进行比较 94 | * 95 | * @param[in] s1: 要进行比较的第一个字符串 96 | * @param[in] s2: 要进行比较的第二个字符串 97 | * @return 98 | 如果返回值 < 0,则表示 s1 小于 s2 99 | 如果返回值 > 0,则表示 s2 小于 s1 100 | 如果返回值 = 0,则表示 s1 等于 s2 101 | * @see None. 102 | * @note None. 103 | */ 104 | int32_t jl_platform_strcmp(const char *s1, const char *s2) 105 | { 106 | #ifdef __LINUX_PAL__ 107 | return strcmp(s1, s2); 108 | #else 109 | return 0; 110 | #endif 111 | } 112 | 113 | /** 114 | * @brief 把 s1 所指向的字符串和 s2 所指向的字符串进行比较, 最多比较前 n 个字节 115 | * 116 | * @param[in] s1: 要进行比较的第一个字符串 117 | * @param[in] s2: 要进行比较的第二个字符串 118 | * @param[in] n: 要比较的最大字符数 119 | * @return 120 | 如果返回值 < 0,则表示 s1 小于 s2 121 | 如果返回值 > 0,则表示 s2 小于 s1 122 | 如果返回值 = 0,则表示 s1 等于 s2 123 | * @see None. 124 | * @note None. 125 | */ 126 | int32_t jl_platform_strncmp(const char *s1, const char *s2, uint32_t n) 127 | { 128 | #ifdef __LINUX_PAL__ 129 | return strncmp(s1, s2, n); 130 | #else 131 | return 0; 132 | #endif 133 | } 134 | 135 | /** 136 | * @brief 把参数 str 所指向的字符串转换为一个整数(类型为 int 型) 137 | * 138 | * @param[in] nptr: 要转换为整数的字符串 139 | * @return 140 | 该函数返回转换后的长整数,如果没有执行有效的转换,则返回零 141 | * @see None. 142 | * @note None. 143 | */ 144 | int32_t jl_platform_atoi(const char* nptr) 145 | { 146 | #ifdef __LINUX_PAL__ 147 | return atoi(nptr); 148 | #else 149 | return 0; 150 | #endif 151 | } 152 | 153 | /** 154 | * @brief 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符 155 | * 156 | * @param[in] s: 要计算长度的字符串. 157 | * @return 158 | * 该函数返回字符串的长度 159 | * @see None. 160 | * @note None. 161 | */ 162 | uint32_t jl_platform_strlen(const char *s) 163 | { 164 | #ifdef __LINUX_PAL__ 165 | return strlen(s); 166 | #else 167 | return 0; 168 | #endif 169 | } 170 | 171 | /** @} */ /* end of platform_string_api_manage */ 172 | -------------------------------------------------------------------------------- /joylink_dev_sdk/pal/src/joylink_time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "joylink_stdio.h" 8 | #include "joylink_time.h" 9 | 10 | /** 11 | * 初始化系统时间 12 | * 13 | * @return: 0 - success or -1 - fail 14 | * 15 | */ 16 | int32_t jl_set_UTCtime(jl_time_stamp_t ts) 17 | { 18 | #ifdef __LINUX_PAL__ 19 | struct timeval tv; 20 | 21 | tv.tv_sec = ts.second; 22 | tv.tv_usec = ts.ms * 1000; 23 | settimeofday(&tv, NULL); 24 | #endif 25 | return 0; 26 | } 27 | 28 | /** 29 | * @brief 获取系统UTC时间,精确到毫秒 30 | * @param none 31 | * @return time ms 32 | */ 33 | int jl_get_time_msec(jl_time_stamp_t *ts) 34 | { 35 | #ifdef __LINUX_PAL__ 36 | struct timeval now; 37 | 38 | if(gettimeofday(&now,NULL) == -1) 39 | return -1; 40 | 41 | if(ts) 42 | { 43 | ts->second = (uint32_t) now.tv_sec; 44 | ts->ms = (uint32_t) (now.tv_usec/1000); 45 | } 46 | return 0; 47 | #else 48 | return -1; 49 | #endif 50 | } 51 | 52 | /** 53 | * 获取系统UTC时间,精确到秒 54 | * 55 | * @return: UTC Second 56 | * 57 | */ 58 | uint32_t jl_get_time_second(uint32_t *jl_time) 59 | { 60 | #ifdef __LINUX_PAL__ 61 | return (uint32_t)time(NULL); 62 | #else 63 | return 0; 64 | #endif 65 | } 66 | 67 | /** 68 | * get time string 69 | * 70 | * @out param: 71 | * @return: success or fail 72 | * 73 | */ 74 | int jl_get_time(jl_time_t *jl_time) 75 | { 76 | #ifdef __LINUX_PAL__ 77 | time_t timep; 78 | 79 | time(&timep); 80 | struct tm *p = localtime(&timep); 81 | 82 | jl_time->year = p->tm_year; 83 | jl_time->month = p->tm_mon; 84 | jl_time->week = p->tm_wday; 85 | jl_time->day = p->tm_mday; 86 | jl_time->hour = p->tm_hour; 87 | jl_time->minute = p->tm_min; 88 | jl_time->second = p->tm_sec; 89 | #endif 90 | return 0; 91 | } 92 | 93 | /** 94 | * 获取时间字符串 95 | * 96 | * @out param: "year-month-day hour:minute:second.millisecond" 97 | * @return: success or fail 98 | * 99 | */ 100 | char *jl_get_time_str(void) 101 | { 102 | static char time_buffer[30]; 103 | #ifdef __LINUX_PAL__ 104 | // 获取“年-月-日 时:分:秒.毫秒”字符串类型的时间戳 105 | time_t timep; 106 | jl_time_stamp_t ts; 107 | struct tm *p; 108 | 109 | time(&timep); 110 | p = localtime(&timep); 111 | jl_get_time_msec(&ts); 112 | 113 | jl_platform_sprintf(time_buffer, "%02d-%02d-%02d %02d:%02d:%02d.%03d", 114 | 1900 + p->tm_year, 115 | 1 + p->tm_mon, 116 | p->tm_mday, 117 | p->tm_hour, 118 | p->tm_min, 119 | p->tm_sec, 120 | ts.ms 121 | ); 122 | #else 123 | // 如果不能获取“年-月-日 时:分:秒.毫秒”时间戳,则获取UTC毫秒数时间戳 124 | jl_time_stamp_t ts; 125 | jl_get_time_msec(&ts); 126 | jl_platform_sprintf(time_buffer, "%d%03d", ts.second, ts.ms); 127 | #endif 128 | return time_buffer; 129 | } 130 | 131 | /** 132 | * get os time 133 | * 134 | * @out param: none 135 | * @return: sys time ticks ms since sys start 136 | */ 137 | uint32_t jl_get_os_time(void) 138 | { 139 | #ifdef __LINUX_PAL__ 140 | jl_time_stamp_t ts; 141 | 142 | jl_get_time_msec(&ts); 143 | return (ts.second * 1000 + ts.ms); // FIXME do not recommand this method 144 | // return clock(); 145 | #else 146 | return 0; 147 | #endif 148 | } 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /joylink_dev_sdk/scripts/config.mk: -------------------------------------------------------------------------------- 1 | # xtensa-esp32s2-elf-gcc (crosstool-NG esp-2020r2) 8.2.0 2 | CROSS_COMPILE := /work/disk1/share/toolchain/xtensa-esp32s2-elf/bin/xtensa-esp32s2-elf- 3 | 4 | # x86 arch 5 | CFLAGS := -DuECC_PLATFORM=uECC_arch_other -std=gnu99 -Og -ggdb -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration 6 | # other arch 7 | # CFLAGS := -DuECC_PLATFORM=uECC_arch_other -D__LINUX_PAL__ -DJOYLINK_SDK_EXAMPLE_TEST -D_SAVE_FILE_ 8 | 9 | LDFLAGS = -lpthread -lm 10 | 11 | USE_JOYLINK_JSON=yes 12 | 13 | #----------------------------------------------以下固定参数 14 | CFLAGS += -D_IS_DEV_REQUEST_ACTIVE_SUPPORTED_ -D_GET_HOST_BY_NAME_ 15 | 16 | TARGET_DIR = ${TOP_DIR}/target 17 | TARGET_LIB = ${TARGET_DIR}/lib 18 | TARGET_BIN = ${TARGET_DIR}/bin 19 | 20 | CC=$(CROSS_COMPILE)gcc 21 | AR=$(CROSS_COMPILE)ar 22 | RANLIB=$(CROSS_COMPILE)ranlib 23 | STRIP=$(CROSS_COMPILE)strip 24 | 25 | RM = rm -rf 26 | CP = cp -rf 27 | MV = mv -f 28 | 29 | 30 | -------------------------------------------------------------------------------- /port/include/ifaddrs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _IFADDRS_H 3 | #define _IFADDRS_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | /* The `getifaddrs' function generates a linked list of these structures. 11 | Each element of the list describes one network interface. */ 12 | struct ifaddrs 13 | { 14 | struct ifaddrs *ifa_next; /* Pointer to the next structure. */ 15 | 16 | char *ifa_name; /* Name of this network interface. */ 17 | unsigned int ifa_flags; /* Flags as from SIOCGIFFLAGS ioctl. */ 18 | 19 | struct sockaddr *ifa_addr; /* Network address of this interface. */ 20 | struct sockaddr *ifa_netmask; /* Netmask of this interface. */ 21 | union 22 | { 23 | /* At most one of the following two is valid. If the IFF_BROADCAST 24 | bit is set in `ifa_flags', then `ifa_broadaddr' is valid. If the 25 | IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid. 26 | It is never the case that both these bits are set at once. */ 27 | struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */ 28 | struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */ 29 | } ifa_ifu; 30 | /* These very same macros are defined by for `struct ifaddr'. 31 | So if they are defined already, the existing definitions will be fine. */ 32 | # ifndef ifa_broadaddr 33 | # define ifa_broadaddr ifa_ifu.ifu_broadaddr 34 | # endif 35 | # ifndef ifa_dstaddr 36 | # define ifa_dstaddr ifa_ifu.ifu_dstaddr 37 | # endif 38 | 39 | void *ifa_data; /* Address-specific data (may be unused). */ 40 | }; 41 | 42 | 43 | /* Create a linked list of `struct ifaddrs' structures, one for each 44 | network interface on the host machine. If successful, store the 45 | list in *IFAP and return 0. On errors, return -1 and set `errno'. 46 | 47 | The storage returned in *IFAP is allocated dynamically and can 48 | only be properly freed by passing it to `freeifaddrs'. */ 49 | extern int getifaddrs (struct ifaddrs **__ifap) __THROW; 50 | 51 | /* Reclaim the storage allocated by a previous `getifaddrs' call. */ 52 | extern void freeifaddrs (struct ifaddrs *__ifa) __THROW; 53 | 54 | __END_DECLS 55 | 56 | #endif /* ifaddrs.h */ -------------------------------------------------------------------------------- /port/include/joylink_ble.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_BLE_H__ 2 | #define __JOYLINK_BLE_H__ 3 | 4 | void ble_start(void); 5 | 6 | #endif -------------------------------------------------------------------------------- /port/include/joylink_upgrade.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOYLINK_UPGRADE_H__ 2 | #define __JOYLINK_UPGRADE_H__ 3 | 4 | void ota_task_start(char* url); 5 | 6 | #endif 7 | --------------------------------------------------------------------------------