Compare commits

...

220 Commits

Author SHA1 Message Date
chunyexixiaoyu 858594e5b2 修改 LCD 屏幕驱动 增加像素点上面显示字符串 2022-02-25 17:38:36 +08:00
chunyexixiaoyu 388f897989 这个值可能更好 2022-02-25 16:53:15 +08:00
chunyexixiaoyu 7cbfa2a44b #define BSP_LCD_CLK_FREQ 6000000 屏幕spi 频率得以匹配 2022-02-25 15:38:38 +08:00
chunyexixiaoyu 37e5643861 口罩识别样例 按照螺丝双螺母的情况仿照编写 2022-02-25 15:12:27 +08:00
xuedongliang aa27dea6e9 update knowing framework and ov2640 dirver from Tian_Chunyu
it is OK
2022-01-27 22:31:57 +08:00
xuedongliang dc811358fe move readme.md to nuttx path and fix bug for HCHO_TB600B_WQ_HCHO1OS
it is OK
2022-01-27 22:31:02 +08:00
xuedongliang b927abfd64 feat support lcd driver for aiit-arm32-board
it is OK
2022-01-27 22:29:59 +08:00
chunyexixiaoyu 8fc1462141 Ubiquitous/RT_Thread/: eliminate the Kconfig warning in ov2640 driver 2022-01-25 14:44:27 +08:00
wgzAIIT 7df26b9ce3 move readme.md to nuttx path and fix bug for HCHO_TB600B_WQ_HCHO1OS 2022-01-25 14:15:12 +08:00
chunyexixiaoyu 600d615765 Ubiquitous/RT_Thread/:update stm32f407 lcd driver, support show string. 2022-01-25 11:07:43 +08:00
Liu_Weichao 63ec04cf6e fix xiuos/transform.h code standard problem 2022-01-21 16:03:31 +08:00
chunyexixiaoyu bf17ef10cb APP_Framework/Applications/: make mnist application running on the stm32f407 board,model data is saved in the flash,note the following points
1. the thread which run the mnist needs 10kb
2. Lwip and useless driver must be not loaded.
3. The entire bin file is close to 1024KB.
2022-01-19 14:53:47 +08:00
Liu_Weichao 3a84b9942b fix lcd display error 2022-01-19 13:56:05 +08:00
Liu_Weichao 2c12cac790 Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into aiit_arm_drivers 2022-01-18 17:07:27 +08:00
xuedongliang d5ff9259a0 resubmit the lvgl code
it is OK
2022-01-18 16:45:20 +08:00
Wang_Weigen 65a3861ea7 resubmit the lvgl code 2022-01-18 16:38:38 +08:00
chunyexixiaoyu 0dee89982a Ubiquitous/RT_Thread/:update the ov2640 driver
1.can choose the output format:rgb565 or jpeg
2.resolution and window size can be configured directly
3.add the test that the lcd can show rgb565 image in time
2022-01-18 16:00:16 +08:00
chunyexixiaoyu 1c5047f47a Ubiquitous/RT_Thread/:change the default orientation of the MCU-ATK screen 2022-01-18 15:56:13 +08:00
Liu_Weichao 9223e8214e Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into aiit_arm_drivers 2022-01-18 15:06:42 +08:00
xuedongliang a5066f8a36 1、add lvgl for xiuos;2、add semc and extern sram test for ok-1052;3、add fpu status set
it is OK
2022-01-18 15:01:02 +08:00
Wang_Weigen bc1d8f574b sync upstream 2022-01-18 14:55:00 +08:00
Liu_Weichao 546edab7f0 feat support lcd driver for aiit-arm32-board 2022-01-18 14:11:55 +08:00
xuedongliang 27657d6219 fixed opcua demo bug and show mac address
it is OK
2022-01-18 13:28:59 +08:00
xuedongliang 0172522463 1、add ADC driver for aiit-arm32-board,but there is no extra IO for adc analog input; 2、add ADC driver for stm32f407-st-discovery board
it is OK
2022-01-18 13:27:52 +08:00
Liu_Weichao 109ad93e9e feat support DMA for aiit-arm32-board and stm32f407-st-discovery uart function 2022-01-17 17:15:19 +08:00
Wang_Weigen d56a5315dd modify the extern sram size as 32MBytes 2022-01-17 15:43:06 +08:00
wlyu 169c3c3c5d fixed socket bug and optimize with lwip flag and other codes 2022-01-17 15:21:15 +08:00
Wang_Weigen c88dc282fc add semc and extern sram test for ok-1052 2022-01-17 15:05:42 +08:00
chunyexixiaoyu bc87a72f5d Ubiquitous/RT_Thread/:add LCD driver in stm32f407_core borad,and find a bug that the FSMC_NE4 gpio had been not configured. 2022-01-13 18:48:06 +08:00
wlyu c0de7ca44c fixed the bug of lwip IRQ and optimize TCP and OPCUA demo 2022-01-12 18:49:36 +08:00
Wang_Weigen 27a40042f4 add fpu test 2022-01-11 18:17:26 +08:00
Wang_Weigen 3ca98f520d repair the compiler error of lvgl 2022-01-11 17:51:44 +08:00
Wang_Weigen aa63e53cbc sync upstream branch 2022-01-11 17:13:40 +08:00
Wang_Weigen c6458f1f1d add lvgl for xiuos 2022-01-11 17:11:17 +08:00
Liu_Weichao bac136c51d feat support DAC driver for aiit-arm32-board and stm32f407-st-discovery 2022-01-11 16:56:57 +08:00
wlyu bb0425d1b2 fixed the bug of UaGetInfo 2022-01-10 18:22:44 +08:00
wlyu 51de336db1 remove debug log and optimizing codes 2022-01-10 17:49:37 +08:00
wlyu 6972a14f6d fixed opcua demo exception and added mac address with showip command 2022-01-10 16:21:32 +08:00
Liu_Weichao d789b66ed2 Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into aiit_arm_drivers 2022-01-10 14:10:50 +08:00
Liu_Weichao 2e8383397b feat support ADC driver for aiit-arm32-board and stm32f407-st-discovery 2022-01-10 14:08:58 +08:00
xuedongliang 3a35bee743 support LWIP and demo from Wang_Linyu Liu_Kai Yang Peihao Wang_Weigen
it is OK
2022-01-07 22:00:32 +08:00
wlyu b6bec0c2b6 fixed the bug that updating ip address and TCP recv fault 2022-01-07 18:56:49 +08:00
wlyu a49eeaf548 optimize lwip test 2022-01-07 17:02:55 +08:00
wlyu e2e127bb0e added socket send and recv for udp and tcp 2022-01-07 14:36:57 +08:00
wlyu 877ef9e221 1. fixed IRQ interrupt
2. changed lwip test command
3. merge dns and ping command
4. change test to cmd_lwip
2022-01-07 13:56:54 +08:00
xuedongliang 4179e4910b add hcho1os、iaq10、as830 sensor and tvoc10 sensor support Nuttx from Wang_guozhu
it is OK
2022-01-07 13:55:00 +08:00
wgzAIIT 6bfbbc18f2 add hcho1os sensor support Nuttx 2022-01-07 12:08:14 +08:00
wgzAIIT c08d854d4b add as830 sensor and tvoc10 sensor support Nuttx 2022-01-07 11:01:46 +08:00
wlyu ddb889623d change lwip_demo to resoures directory and mkdir socket_demo on connection_app 2022-01-06 21:20:17 +08:00
wlyu acd53026b0 fixed the exception of close socket and added dhcp and dns demo 2022-01-06 20:37:34 +08:00
wlyu a0337a42e3 change demo command and support DHCP demo 2022-01-06 15:58:43 +08:00
wlyu d1d4632292 1. fixed ping exception
2. added tcp send test example
3. added udp [IP] to test udp
2022-01-05 20:05:07 +08:00
wgzAIIT 1f252e418f add iaq10 sensor support Nuttx 2022-01-05 15:40:01 +08:00
Wang_Weigen 37c247f4d7 add lvgl 2022-01-05 15:23:12 +08:00
chunyexixiaoyu 3c291f075f APP_Framework/Framework/:delete the unuseful cmsis flies in tensorflow-lite 2022-01-05 11:08:55 +08:00
chunyexixiaoyu 9904709d70 Ubiquitous/RT_Thread: update the README file 2022-01-05 09:56:54 +08:00
chunyexixiaoyu 7f24c672dd APP_Framework/Framework: cmsis nn used in tflite was replaced with in knowing cmsis_5 dir 2022-01-04 18:36:30 +08:00
chunyexixiaoyu 1bd8927c5d Eliminate the warning "./../../../APP_Framework/Framework/knowing/Kconfig:13:warning: ignoring unsupported character '" 2022-01-04 15:47:14 +08:00
wlyu d1625c7d84 fixed opcua_demo compilation error 2022-01-01 00:03:18 +08:00
wlyu 37cbb51afa Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into 1220 2021-12-31 23:40:23 +08:00
xuedongliang 711bd5bd15 add hs300x and ps5308 sensor support Nuttx on stm32f407-discovery from Wang_guozhu
it is OK
2021-12-31 17:08:37 +08:00
chunyexixiaoyu a3db2480a1 it's verified 2021-12-31 16:33:16 +08:00
wlyu 7c0b7367d1 optimize LWIP demo and OPCua demo 2021-12-31 14:37:57 +08:00
wgzAIIT b342734aad APP_Framework support Nuttx on aiit-arm32-board 2021-12-30 12:19:58 +08:00
wlyu 372c097688 Merge branch '1220' of https://code.gitlink.org.cn/wlyu/xiuos into 1220 2021-12-30 11:25:54 +08:00
wlyu 62dcbef383 optimize lwip demo and ok1052-c directories 2021-12-30 11:25:22 +08:00
wlyu a672abce6f optimize lwip demo and ok1052-c directories 2021-12-30 11:20:36 +08:00
wgzAIIT bd31aad3ef add d124 and zg09 sensor support Nuttx on stm32f407-discovery 2021-12-29 16:13:23 +08:00
wgzAIIT 97eccb0b36 Update Make.defs 2021-12-28 19:57:25 +08:00
wgzAIIT 491264e3fc Update Make.defs 2021-12-28 19:56:48 +08:00
wgzAIIT fb7a0478e5 Update ps5308.c 2021-12-28 19:29:52 +08:00
wgzAIIT d59acc2e03 add hs300x and ps5308 sensor support Nuttx on stm32f407-discovery 2021-12-28 16:45:44 +08:00
chunyexixiaoyu 17be211288 Merge branch 'wang_dev' into test_pre
solve the Conflicts
# Conflicts:
#	APP_Framework/Framework/knowing/Kconfig
2021-12-24 13:52:24 +08:00
wlyu 8fa0d977a0 Merge branch '1220' of https://code.gitlink.org.cn/wlyu/xiuos into 1220 2021-12-22 19:01:37 +08:00
wlyu aa43d46953 fixed pull conflict and socket ping test bug 2021-12-22 19:00:56 +08:00
wlyu 2af68252cb fixed pull conflict 2021-12-22 16:09:34 +08:00
wlyu ebb1321b7c update ping debug commands 2021-12-22 16:04:28 +08:00
wlyu f98689fc30 change udp test command 2021-12-22 13:48:35 +08:00
wlyu 8992dce241 fixed menu and complilation error 2021-12-22 13:45:52 +08:00
xuedongliang 7ecf1af00f 1、add Framework/connection/industrial_ethernet DIR; 2、add Framework/connection/industrial_fieldbus DIR; 3、add Framework/connection/industrial_wlan DIR from Liu Weichao
it is OK
2021-12-22 13:28:42 +08:00
wlyu 5799b31942 fixed menu and complilation error 2021-12-21 10:20:56 +08:00
wlyu c20c9c20d2 support OPCUA and LWIP 2021-12-20 16:44:03 +08:00
chunyexixiaoyu b6bd1de959 APP_Framework/Applications/:eliminate the warning 2021-12-20 16:33:48 +08:00
Liu_Weichao 60442e489a feat Framework/connection/industrial_xxx DIR 2021-12-20 16:14:02 +08:00
chunyexixiaoyu be4da6f37d Ubiquitous/RT_Thread/:change the path name 2021-12-20 16:05:55 +08:00
wlyu b4730f3f87 support OPCUA and LWIP 2021-12-20 15:52:05 +08:00
Wang_Weigen 36f2ebbf95 add fpu status set 2021-12-20 15:42:24 +08:00
chunyexixiaoyu 12c9220487 the kmodel load function has been verified 2021-12-20 15:18:13 +08:00
xuedongliang cb8c68659c 1. add sensor as830 of ch4; 2、repair a bug of requiring password in letter shell
it is OK
2021-12-16 17:40:29 +08:00
yangtuo250 62df72af5b fix(knowing framework/yolov2 region layer): free region layer thresholds 2021-12-16 15:03:37 +08:00
yangtuo250 c782dd26c4 feat(knowing app): remove json config from menuconfig, adding to detect_app arg 2021-12-15 19:05:07 +08:00
yangtuo250 efb28105e8 fix(knowing framework): fix unproperly named k210 detect procedure, specified yolov2 2021-12-15 17:32:07 +08:00
yangtuo250 4640055ab6 fix(knowing app/yolov2): AI address error while sensor output and net input height mismatch 2021-12-15 17:12:34 +08:00
Wang_Weigen db225df433 add 'TB600B_WQ_HCHO1OS' sensor of hcho to sensor framework 2021-12-15 16:28:51 +08:00
Wang_Weigen 19edea21d7 add 'TB600B_TVOC10' sensor of tvoc to sensor framework 2021-12-15 15:01:30 +08:00
Wang_Weigen 856edb7ec6 add sensor 'TB600B_IAQ10' to sensor framework 2021-12-15 11:10:56 +08:00
yangtuo250 203184e18c fix(bsp/k210): resolve conflict of 235dcb761c path changed 2021-12-14 10:06:53 +00:00
yangtuo250 c07c918150 refactor(knowing app): add common k210 yolov2 detection procedure 2021-12-14 17:43:53 +08:00
yangtuo250 d368db9e76 refactor(knowing apps): yolov2 json parser 2021-12-14 17:43:27 +08:00
chunyexixiaoyu 235dcb761c Ubiquitous/RT_Thread/:change the path name 2021-12-14 17:13:38 +08:00
Wang_Weigen 4a8ac7c02b repair ch4 test 2021-12-14 14:07:09 +08:00
chunyexixiaoyu de27c59e51 Ubiquitous/RT_Thread/: update file system
1.change the tick base on  the board/Kconfig
2.The SD card and FLASH can be mounted to the specified directory of romFS at the same time,and SD card or flash can be used independently
3.Avoid the SD card and Flash mounting sequence. If the Flash mounts the SD card to a specific directory, ensure that the SD card is mounted first
2021-12-14 13:21:42 +08:00
chunyexixiaoyu d71c5fcd2f Ubiquitous/RT_Thread/:add romfs file system ,including SD and FLASH directory 2021-12-14 11:11:09 +08:00
Wang_Weigen e366c8817c repair a bug of inputting password of shell 2021-12-14 10:37:22 +08:00
Wang_Weigen f2ba792380 sync upstream branch and add 'as830' sensor of ch4 2021-12-14 10:32:17 +08:00
xuedongliang cc6c459e7b fix APP_Framework bugs,include sensor framework and Applications
it is OK
2021-12-13 14:18:48 +08:00
Liu_Weichao e9e9080ae0 delete useless DIR connection_app/ and app_test/ 2021-12-10 10:39:37 +08:00
Liu_Weichao ead80da91f fix that i2c device of sensor framework cannot set i2c address 2021-12-10 10:23:30 +08:00
xuedongliang c9db5635b0 add framework configuration select from Wang_Weigen 2021-12-09 11:08:00 +08:00
xuedongliang 3397a5245b Add the cortex-m0 support for XiUOS & Fix bugs on M3 and serial device from ysm
it is Perfect
2021-12-09 11:07:15 +08:00
Wang_Weigen 85cbc7717e add framework configuration select 2021-12-09 10:56:25 +08:00
Kiritoy 58060874d6 rebase prepare_for_master branch 2021-12-08 14:52:10 +08:00
Kiritoy a080d98470 Restore the file directory structure 2021-12-08 14:43:10 +08:00
Kiritoy 4aacf28974 add cortex-m0 support and fix some bugs 2021-12-08 14:43:10 +08:00
xuedongliang 1dfb44a706 1、fix third_party_usb data format bugs; 2、feat riscv64 usb mount file system function.
it is OK
2021-12-07 09:52:09 +08:00
xuedongliang 3306194902 add gd32vf103_rvstar board for xiuos
it is OK
2021-12-07 09:51:12 +08:00
Wang_Weigen fa1637ffbd sync upstream 2021-12-07 09:47:13 +08:00
Liu_Weichao c1036ec9a2 Merge branch 'wang_weigen_master' of https://git.trustie.net/xuos/xiuos into xiuos_connection 2021-12-07 09:44:11 +08:00
Liu_Weichao a7baf1e7ed fix third_party_usb/usbhost data format bugs 2021-12-07 09:43:53 +08:00
xuedongliang 4405b85eae add XiUOS/stm32f103-nano board feature,support uart1 and shell function
It is perfect
2021-12-07 09:31:13 +08:00
Wang_Weigen b76b1506cd modify board name in readme 2021-12-06 09:58:10 +08:00
Wang_Weigen b1e7057b17 add bin file flash way of gd32vf103_rvstar in READ.md 2021-12-03 16:47:17 +08:00
chunyexixiaoyu 6816dc023a update .gitmodules file 2021-12-03 16:35:17 +08:00
Wang_Weigen 644f2bbf37 add gd32vf103 'README.md' 2021-12-03 15:38:10 +08:00
Wang_Weigen 19bd5a4705 repair the uart input of gd32fv103_rvstar 2021-12-03 14:07:05 +08:00
chunyexixiaoyu d99d4e8f52 APP_Framework/Applications/:eliminate some warnings about menuconfig in linux 2021-12-03 13:56:15 +08:00
Wang_Weigen b1264ad3c9 Merge branch 'wang_weigen_master' of https://git.trustie.net/xuos/xiuos into develop 2021-12-02 15:18:33 +08:00
Wang_Weigen 607b8ca017 transplant development board of gd32vf103_rvstar 2021-12-02 15:17:59 +08:00
Liu_Weichao a21ca4af2a fix XiUOS/stm32f103-nano board README.md error 2021-12-02 14:21:54 +08:00
Liu_Weichao a51473d791 Merge branch 'wang_weigen_master' of https://git.trustie.net/xuos/xiuos into xiuos_connection 2021-12-02 11:09:39 +08:00
Liu_Weichao 20b852eb38 add XiUOS/stm32f103-nano board support, feat shell and docs stack-heap-optimize advice 2021-12-02 11:09:17 +08:00
chunyexixiaoyu 60ce72b37a Ubiquitous/RT_Thread/bsp/:fix the problem that the iic parameters were changed when menuconfig 2021-12-02 09:43:59 +08:00
xuedongliang 20bc1e6e8b cortex-m4-emulator support
It is OK
2021-12-01 16:58:59 +08:00
Liu_Weichao c78ab5242c Merge branch 'wang_weigen_master' of https://git.trustie.net/xuos/xiuos into xiuos_connection 2021-12-01 10:28:26 +08:00
Liu_Weichao a42f20ab3c add XiUOS/stm32f103-nano board support, task create function has some bugs 2021-12-01 10:27:25 +08:00
bj 668796ee18 技术文档与视频 2021-12-01 10:10:52 +08:00
xuedongliang 2356e42955 update knowing framework and ov2640 driver from Tian Chunyu
it is OK
2021-12-01 09:59:44 +08:00
xuedongliang 3653ac690d it is OK 2021-12-01 09:59:02 +08:00
chunyexixiaoyu c30ba15c6f Merge branch 'wang_dev' of https://git.trustie.net/chunyexixiaoyu/xiuos into wang_dev 2021-11-30 15:33:45 +08:00
chunyexixiaoyu 0379084f40 Ubiquitous/RT_Thread/:update ov2640 drivers to adapt the hardware,IIC two wires(SCL SDA) switched due to due to hardware design. 2021-11-30 15:23:34 +08:00
chunyexixiaoyu e70244d75e Add cmsis- nn for ARM board , it has been verified on stm32f407-atk-board
1.Limited by hardware resources(ram 128k),so Lwip can't be compiled.
2.the image used in the demo has to be saved on the board.
2021-11-30 10:35:46 +08:00
Wang_Weigen 4fc79c211a add a tip 2021-11-30 10:34:08 +08:00
Wang_Weigen ac69e135ca repair a bug of restart main after ota 2021-11-30 10:12:42 +08:00
WentaoWong 49caa6e533 APP_Framework/Applications/:add CMSIS-NN (version 5) cifar10 example 2021-11-29 18:51:34 +08:00
WentaoWong 96ca3b18f1 APP_Framework/Applications/:add configuration file about CMSIS-NN (version 5) cifar10 example 2021-11-29 18:50:53 +08:00
WentaoWong 86cb28ee4f APP_Framework/Framework/:add CMSIS-NN (version 5) source code 2021-11-29 18:49:41 +08:00
WentaoWong fe06b461ee APP_Framework/Framework/:add Kconfig file and SConscript file about CMSIS-NN (version 5) 2021-11-29 18:48:51 +08:00
Wang_Weigen 1c60efe8a8 add debug info 2021-11-29 17:46:18 +08:00
Wang_Weigen 32cb324324 repair the total bin crc failed problem 2021-11-29 17:33:19 +08:00
Wang_Weigen 592ca413e8 sync with upstream 2021-11-25 14:26:45 +08:00
Wang_Weigen f24189d7e1 repair ota failed by add mutex protect 2021-11-25 14:24:11 +08:00
Wang_Weigen 9d970e7832 add mutex protection for adapter agent 2021-11-22 17:50:27 +08:00
Wang_Weigen 5a8b6d79aa repair somebug of ota/nbiot/adapter agent 2021-11-20 16:52:16 +08:00
chunyexixiaoyu e0c78f200b APP_Framework/Applications/:add TJpgDec example,notes the macro definition (WORK_POOL_SIZE),this value depends on the resolution of the image,user set. 2021-11-19 17:56:08 +08:00
xuedongliang 86b1d9c77d support adapter_ethernet and adapter_lora function from Liu Weichao
it is OK
2021-11-19 09:26:54 +08:00
chunyexixiaoyu e33b0d0264 APP_Framework/Applications/:add configuration file about TJpgDec example 2021-11-18 11:15:16 +08:00
chunyexixiaoyu 2b69d31744 APP_Framework/Framework/:add TJpgDec(Tiny JPEG Decompressor)source code 2021-11-18 11:13:36 +08:00
chunyexixiaoyu a9ac7efed2 APP_Framework/Framework/:add Kconfig file and SConscript file about TJpgDec(Tiny JPEG Decompressor) 2021-11-18 11:12:36 +08:00
Liu_Weichao 5fe8fb59b2 Merge branch 'wang_weigen_master' of https://git.trustie.net/xuos/xiuos into xiuos_connection 2021-11-17 17:37:24 +08:00
Liu_Weichao 7a172fd136 1、support adapter_lora gateway and client state-machine-model;2、fix aiit-arm32-board usb compile error. 2021-11-17 17:37:04 +08:00
xuedongliang ca74d5cb93 Add QEMU support for XiUOS based on Cortex-M4
it is OK
2021-11-16 21:48:24 +08:00
Wang_Weigen 251846604a repair ota_server.c 2021-11-16 09:43:54 +08:00
Wang_Weigen 2930757728 add the totle length with the last frame of ota server 2021-11-15 10:12:45 +08:00
Wang_Weigen 25cd73821f fix a bug of malloc big memory failed 2021-11-12 18:24:52 +08:00
Wang_Weigen eb14677832 1.add an API of finding the first user task in xiuos task manage list; 2.add restart application after ota 2021-11-10 17:31:39 +08:00
Liu_Weichao c631063b7a support adapter_lora and sx1278 device on aiit-arm32-board 2021-11-10 16:32:17 +08:00
Wang_Weigen f3d527cf70 delete useless code 2021-11-09 17:18:21 +08:00
Wang_Weigen b3c770dd26 delete useless code 2021-11-09 17:14:47 +08:00
Wang_Weigen 8609045f2a repair 'mount sd card' 2021-11-09 17:13:07 +08:00
Wang_Weigen 9959ec6470 1.repair the separate compile error;2.modify ota init task 2021-11-09 16:12:07 +08:00
Wang_Weigen 8b2eee0aa0 reapir ota save bin process 2021-11-08 15:56:28 +08:00
Wang_Weigen 224201ba55 add application bin ota function by 4G adapter,this function need save the app bin to sdcard and startup the app from sdcrad 2021-11-05 17:30:00 +08:00
xuedongliang dfdc29b1d8 add K210 fft test
it is OK
2021-10-26 14:02:07 +08:00
xuedongliang 410178e426 add BC28 of NBIoT for connection adapter
it is OK
2021-10-26 14:01:41 +08:00
bj 471e2d7920 cotex-m4-emulator2 2021-10-26 11:31:19 +08:00
chunyexixiaoyu e69139c6b9 APP_Framework/Applications/:add k210 fft(fast Fourier transform) example. 2021-10-26 11:24:49 +08:00
chunyexixiaoyu 4c0b05b752 Ubiquitous/RT_Thread/:rt-thread version update to fix the bug that tensflow lite for mcu can't be compiled. 2021-10-22 14:22:47 +08:00
Wang_Weigen 281a3b672a debug nbiot pass with some modification 2021-10-21 15:17:14 +08:00
Liu_Weichao 7b82f2a60b support adapter_ethernet and hfa21 device 2021-10-20 11:13:49 +08:00
bj 2f86d928c6 cortex-m4-emulator 2021-10-19 15:52:43 +08:00
Wang_Weigen abe138ab27 remove redefinition and repair compile error 2021-10-18 18:17:24 +08:00
Wang_Weigen 9bf26cdbf9 sync wangweigen_master 2021-10-18 18:10:36 +08:00
Wang_Weigen 267528408e repair wait time for 'ATOrderSend',optimize bc28 api 2021-10-18 18:04:46 +08:00
xuedongliang 3f13410d96 support aiit-arm32-board for nuttx
it is OK
2021-10-18 17:55:36 +08:00
xuedongliang ac588f2fcf support adapter_4g and fix connections bugs
it is OK
2021-10-18 17:55:09 +08:00
xuedongliang 7d5149af24 update k210 bsp and solve lcd display problem
It is OK
2021-10-18 17:54:30 +08:00
wang lingyu 48a19fe349 support aiit-arm32-board 2021-10-15 11:19:33 +08:00
wang lingyu 25221ac786 support aiit-arm32-board for nuttx 2021-10-15 11:09:49 +08:00
Liu_Weichao 06c9c6ecc4 refactor connection directory to follow code standards 2021-10-15 11:05:36 +08:00
Liu_Weichao 8f6cac9797 fix adapter_bluetooth test function bugs 2021-10-15 10:12:19 +08:00
Liu_Weichao 8aac82b1b4 support adapter_4G send and receive data function 2021-10-14 17:25:04 +08:00
chunyexixiaoyu bea5eda2e0 APP_Framework/Applications:update face detect and instrusion detect ,the version had been tested for long time,and its's stable.
At the same time,rt-thread and kendryte-sdk-source both sub module must be updated.
2021-10-14 14:15:09 +08:00
chunyexixiaoyu 43f19c4b55 Ubiquitous/RT_Thread/: add lcd test example update main.c function when it starts. 2021-10-14 11:21:06 +08:00
chunyexixiaoyu a184611226 Ubiquitous/RT_Thread/:update K210 bsp base on https://github.com/kendryte/K210-Micropython-OpenMV
Fixed an issue where LCD and RW007 could not be used at the same time
2021-10-14 11:19:40 +08:00
chunyexixiaoyu 0eee31179c Ubiquitous/RT_Thread/:update stm32 configure file and solve ov2640 driver compile bug. 2021-10-14 10:59:18 +08:00
chunyexixiaoyu ecfbdb207f Ubiquitous/RT_Thread/:update submodule version 2021-10-14 10:47:41 +08:00
Liu_Weichao ab578dfe0e support 4G adapter and ec200t device 2021-10-13 17:57:34 +08:00
Wang_Weigen a4f24a29fc add BC28 of nbiot for adapter 2021-10-13 17:22:28 +08:00
xuedongliang 2aa5c0f0ba support adapter_bluetooth and fix at agent bugs
It is OK
2021-10-11 14:06:55 +08:00
Liu_Weichao a5e97b1431 fix cortex-m3-emulator and hifive emulator compile error 2021-10-11 14:04:37 +08:00
Liu_Weichao 92347f7e29 1、support adapter_bluetooth and hc08 device;2、fix adapter at agent bug。 2021-10-11 10:13:01 +08:00
xuedongliang b07ad19dc3 add E18 of zigbee with net-group from Wang_weigen
it is OK
2021-10-10 16:06:57 +08:00
Wang_Weigen ebbb30c763 sync the upstream branch 2021-09-27 17:02:34 +08:00
xuedongliang 58b3e0b6a6 update transform in rt-thread and sensor framework
it is perfect
2021-09-27 16:48:22 +08:00
xuedongliang a85e9fdb6d optimize connection framework kconfig and makefile; 2、transform connection framework api from user-api to priv-api.
it is OK
2021-09-27 16:47:31 +08:00
Wang_Weigen 626cbb084d add reopen zigbee and modify the stacksize of zigbee receive thread 2021-09-27 16:32:44 +08:00
Wang_Weigen b0f717bee4 add zigbee e18 receive function 2021-09-26 16:12:09 +08:00
chunyexixiaoyu 51d3a8ab41 APP_Framework/Applications/:add SConscript in sensor_app ,fix header file in voice_d124.c. 2021-09-24 16:32:35 +08:00
chunyexixiaoyu d7e29f19cc APP_Framework/Framework/:add voice sensor in framework,and update the d124.c file 2021-09-24 16:23:32 +08:00
chunyexixiaoyu d7cb0876f6 APP_Framework/Framework/:add sensor SConscript and the sensor.c file can be compiled by default 2021-09-24 16:16:57 +08:00
Liu_Weichao dd5a68916e transform connection framework api from user-api to priv-api 2021-09-24 16:07:22 +08:00
chunyexixiaoyu d008cbf09f APP_Framework/Applications/:add list function base on rt-thread. 2021-09-24 16:01:40 +08:00
chunyexixiaoyu 2e209ef174 APP_Framework/Applications/:framework initialize in the bsp applications/main.c 2021-09-24 15:54:26 +08:00
chunyexixiaoyu 3fdc18e837 APP_Framework/Framework/:update transform layer in rt-thread. 2021-09-24 15:38:39 +08:00
Wang_Weigen 6be676af78 add e18 of zigbee connection 2021-09-24 15:22:19 +08:00
Wang_Weigen d14ec3cb12 Merge branch 'master' of https://git.trustie.net/xuos/xiuos into develop 2021-09-22 13:29:15 +08:00
xuedongliang 4a07f534d8 modify the api in sensor framework
it is OK
2021-09-17 15:04:44 +08:00
xuedongliang 869e69097f fix two big : fix aiit_board spi_lora bug;fix sensor/voice Kconfig bug
it is OK
2021-09-17 15:04:12 +08:00
Wang_Weigen d77c1828b2 modify the api in sensor framework 2021-09-14 16:49:54 +08:00
Liu_Weichao bb93aefe1d 1、fix aiit_board spi_lora bug;2、fix sensor/voice Kconfig bug。 2021-09-14 15:49:28 +08:00
2316 changed files with 757303 additions and 147801 deletions

6
.gitmodules vendored
View File

@ -1,6 +1,6 @@
[submodule "Ubiquitous/RT_Thread/rt-thread"]
path = Ubiquitous/RT_Thread/rt-thread
url = https://git.trustie.net/chunyexixiaoyu/rt-thread.git
url = https://code.gitlink.org.cn/chunyexixiaoyu/rt-thread.git
[submodule "Ubiquitous/RT_Thread/bsp/k210/kendryte-sdk/kendryte-sdk-source"]
path = Ubiquitous/RT_Thread/bsp/k210/kendryte-sdk/kendryte-sdk-source
url = https://git.trustie.net/chunyexixiaoyu/kendryte-sdk-source.git
path = Ubiquitous/RT_Thread/aiit_board/k210/kendryte-sdk/kendryte-sdk-source
url = https://code.gitlink.org.cn/chunyexixiaoyu/kendryte-sdk-source.git

View File

@ -11,6 +11,8 @@ menu "Applications"
default 85 if KTASK_PRIORITY_256
endmenu
source "$APP_DIR/Applications/ota/Kconfig"
source "$APP_DIR/Applications/app_test/Kconfig"
source "$APP_DIR/Applications/connection_app/Kconfig"
source "$APP_DIR/Applications/control_app/Kconfig"

View File

@ -0,0 +1,7 @@
############################################################################
# APP_Framework/Applications/Make.defs
############################################################################
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications/general_functions/list
include $(wildcard $(APPDIR)/../../../APP_Framework/Applications/*/Make.defs)

View File

@ -1,21 +1,39 @@
SRC_DIR := general_functions
include $(KERNEL_ROOT)/.config
SRC_FILES := main.c framework_init.c
ifeq ($(CONFIG_APPLICATION_SENSOR),y)
SRC_DIR += sensor_app
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += framework_init.c
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_APPLICATION_CONNECTION),y)
SRC_DIR += connection_app
endif
ifeq ($(CONFIG_APPLICATION_KNOWING),y)
SRC_DIR += knowing_app
endif
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_DIR := general_functions app_test
ifeq ($(CONFIG_APPLICATION_CONTROL),y)
SRC_DIR += control_app
endif
SRC_FILES := main.c framework_init.c
ifeq ($(CONFIG_LIB_LV),y)
SRC_DIR += lv_app
endif
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_APPLICATION_OTA),y)
SRC_DIR += ota
endif
ifeq ($(CONFIG_APPLICATION_SENSOR),y)
SRC_DIR += sensor_app
endif
ifeq ($(CONFIG_APPLICATION_CONNECTION),y)
SRC_DIR += connection_app
endif
ifeq ($(CONFIG_APPLICATION_KNOWING),y)
SRC_DIR += knowing_app
endif
ifeq ($(CONFIG_APPLICATION_CONTROL),y)
SRC_DIR += control_app
endif
include $(KERNEL_ROOT)/compiler.mk
endif

View File

@ -1,9 +1,15 @@
import os
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
SOURCES = ['framework_init.c']
path = [cwd]
objs = []
group = DefineGroup('sensor', SOURCES, depend = [], CPPPATH = [cwd])
objs = objs + group
list = os.listdir(cwd)
for d in list:

View File

@ -4,17 +4,30 @@ menu "test app"
default n
if USER_TEST
config USER_TEST_LORA_ADHOC
bool "Config test lora adhoc"
default n
config USER_TEST_SPI_LORA
bool "Config test spi lora"
default n
config USER_TEST_SPI_FLASH
bool "Config test spi flash"
default n
menuconfig USER_TEST_ADC
bool "Config test adc"
default n
if USER_TEST_ADC
if ADD_XIUOS_FETURES
config ADC_DEV_DRIVER
string "Set ADC dev path"
default "/dev/adc1_dev"
endif
endif
menuconfig USER_TEST_DAC
bool "Config test dac"
default n
if USER_TEST_DAC
if ADD_XIUOS_FETURES
config DAC_DEV_DRIVER
string "Set DAC dev path"
default "/dev/dac_dev"
endif
endif
endif
endmenu

View File

@ -1,15 +1,15 @@
SRC_FILES :=
ifeq ($(CONFIG_USER_TEST_LORA_ADHOC),y)
SRC_FILES += test_adhoc_lora.c
endif
ifeq ($(CONFIG_USER_TEST_SPI_LORA),y)
SRC_FILES += test_spi_lora.c
endif
ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y)
SRC_FILES += test_spi_flash.c
endif
ifeq ($(CONFIG_USER_TEST_ADC),y)
SRC_FILES += test_adc.c
endif
ifeq ($(CONFIG_USER_TEST_DAC),y)
SRC_FILES += test_dac.c
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file sd_card_mount.c
* @brief Mount SD card when opened SDIO
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.19
*/
#include "user_api/switch_api/user_api.h"
#include <stdio.h>
#if defined(FS_VFS)
#include <iot-vfs.h>
/**
* @description: Mount SD card
* @return 0
*/
int MountSDCard(void)
{
if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, FSTYPE_FATFS, "/") == 0)
DBG("sd card mount to '/'");
else
SYS_WARN("sd card mount to '/' failed!");
return 0;
}
#endif
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),MountSDCard, MountSDCard, MountSDCard );

View File

@ -1,46 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file spi_sd_card_mount.c
* @brief Mount SD card when opened SPI SD card
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.01
*/
#include "user_api/switch_api/user_api.h"
#include <stdio.h>
#if defined(FS_VFS)
#include <iot-vfs.h>
/**
* @description: Mount SD card
* @return 0
*/
int MountSDCard(void)
{
struct Bus *spi_bus;
spi_bus = BusFind(SPI_BUS_NAME_1);
if (NONE == SpiSdInit(spi_bus, SPI_1_DEVICE_NAME_0, SPI_1_DRV_NAME, SPI_SD_NAME)) {
KPrintf("MountSDCard SpiSdInit error!\n");
return 0;
}
if (EOK == MountFilesystem(SPI_BUS_NAME_1, SPI_SD_NAME, SPI_1_DRV_NAME, FSTYPE_FATFS, "/"))
KPrintf("SPI SD card fatfs mounted\n");
return 0;
}
#endif

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: test_adc.c
* @brief: a application of adc function
* @version: 1.1
* @author: AIIT XUOS Lab
* @date: 2022/1/7
*/
#include <stdio.h>
#include <string.h>
#include <transform.h>
void test_adc()
{
int adc_fd;
uint8 adc_channel = 0x0;
uint16 adc_sample, adc_value_decimal = 0;
float adc_value;
adc_fd = PrivOpen(ADC_DEV_DRIVER, O_RDWR);
if (adc_fd < 0) {
KPrintf("open adc fd error %d\n", adc_fd);
return;
}
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = ADC_TYPE;
ioctl_cfg.args = &adc_channel;
if (0 != PrivIoctl(adc_fd, OPE_CFG, &ioctl_cfg)) {
KPrintf("ioctl adc fd error %d\n", adc_fd);
PrivClose(adc_fd);
return;
}
PrivRead(adc_fd, &adc_sample, 2);
adc_value = (float)adc_sample * (3.3 / 4096);
adc_value_decimal = (adc_value - (uint16)adc_value) * 1000;
printf("adc sample %u value integer %u decimal %u\n", adc_sample, (uint16)adc_value, adc_value_decimal);
PrivClose(adc_fd);
return;
}
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
// test_adc, test_adc, read 3.3 voltage data from adc);

View File

@ -1,20 +0,0 @@
#include <xiuos.h>
extern void net_lora_client(int argc, char *argv[]);
extern void net_lora_gateway(int argc, char *argv[]);
void demo_lora_adhoc()
{
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_CLIENT
char pgk_count[32];
char* param[3];
param[0] = "xxx";
param[1] = CONNECTION_COMMUNICATION_LORA_CLIENT_NAME;
itoa(CONNECTION_COMMUNICATION_LORA_CLIENT_PKG_COUNT, pgk_count, 10);
param[2] = pgk_count;
net_lora_client(2, param);
#endif
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_GATEWAY
net_lora_gateway(0, 0);
#endif
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: test_dac.c
* @brief: a application of dac function
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/1/11
*/
#include <stdio.h>
#include <string.h>
#include <transform.h>
void test_dac()
{
int dac_fd;
uint16 dac_set_value = 800;
uint16 dac_sample, dac_value_decimal = 0;
float dac_value;
dac_fd = PrivOpen(DAC_DEV_DRIVER, O_RDWR);
if (dac_fd < 0) {
KPrintf("open dac fd error %d\n", dac_fd);
return;
}
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = DAC_TYPE;
ioctl_cfg.args = &dac_set_value;
if (0 != PrivIoctl(dac_fd, OPE_CFG, &ioctl_cfg)) {
KPrintf("ioctl dac fd error %d\n", dac_fd);
PrivClose(dac_fd);
return;
}
PrivRead(dac_fd, &dac_sample, 2);
dac_value = (float)dac_sample * (3.3 / 4096);//Vref+ need to be 3.3V
dac_value_decimal = (dac_value - (uint16)dac_value) * 1000;
printf("dac sample %u value integer %u decimal %u\n", dac_sample, (uint16)dac_value, dac_value_decimal);
PrivClose(dac_fd);
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
test_dac, test_dac, set digital data to dac);

View File

@ -1,3 +1,7 @@
menu "connection app"
menuconfig APPLICATION_CONNECTION
bool "Using connection apps"
default n
endmenu

View File

@ -1,3 +1,7 @@
SRC_DIR :=wifi_demo
SRC_DIR :=
ifeq ($(CONFIG_RESOURCES_LWIP),y)
SRC_DIR += socket_demo
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,108 +0,0 @@
#include <user_api.h>
#include <string.h>
#include <xs_adapter_lora.h>
#include <xs_adapter_manager.h>
#include <stdio.h>
#include <stdlib.h>
char client_name[DEVNAME_LEN_MAX] = "lora_dev_123";
void success_cb(void *param)
{
printf("success_cb, param = %s\n", param);
}
void invert_param(void *param)
{
printf("success_cb02 invoke, invert bool param.\n");
bool *bparam = (bool *)param;
if (*bparam)
{
*bparam = false;
}
else
{
*bparam = true;
}
}
void net_lora_client(int argc, char *argv[])
{
int pkg_count = 10;
if (argc >= 1)
{
memset(client_name, 0, DEVNAME_LEN_MAX);
strncpy(client_name, argv[1], strlen(argv[1]));
printf("lora client set clientName(%s).\n", client_name);
}
if (argc >= 2)
{
pkg_count = atoi(argv[2]);
printf("lora client set pkg_count(%d).\n", pkg_count);
}
// 1.Create an adapter for a specific agreement (LORA)
static struct AdapterLora lora_adapter;
memset(&lora_adapter, 0, sizeof(lora_adapter));
struct AdapterDone lora_example_done = {
.NetAiitOpen = LoraAdapterOpen,
.NetAiitClose = LoraAdapterCose,
.NetAiitSend = LoraAdapterSendc2g,
.NetAiitReceive = NULL,
.NetAiitJoin = LoraAdapterJoin,
.NetAiitIoctl = NULL,
};
lora_adapter.parent.done = lora_example_done; // Bind adapter operation
lora_adapter.name = client_name; // Set adapter name
lora_adapter.spi_lora_fd = -1; // Set adapter information
lora_adapter.deve_ui = "xxx";
lora_adapter.app_key = "yyy";
// 2.Register the adapter in the list
LoraAdapterInit();
LoraAdapterRegister((adapter_t)&lora_adapter);
// 3.Find from the list of registered adapters
adapter_t padapter = LoraAdapterFind(client_name);
if (NONE == padapter)
{
printf("adapter find failed!\n");
return;
}
// 4.Open adapter
if (0 != padapter->done.NetAiitOpen(padapter))
{
printf("adapter open failed!\n");
return;
}
// 5.Join the specified network segment as client
printf("NetAiitJoin start. \n");
padapter->done.NetAiitJoin(padapter, ROLE_TYPE_SLAVE, CONNECTION_COMMUNICATION_LORA_NET_ID);
printf("NetAiitJoin end. \n");
// 6.Point to point sending data to gateway
int i = 0;
while (i < pkg_count)
{
char data[120] = {0};
sprintf(data, "***** I am %s, data_num = %d ******" ,client_name, i);
bool v = false;
padapter->done.NetAiitSend(padapter, data, strlen(data) + 1, true, 10000, 0, invert_param, &v, NULL);
while (!v) // Asynchronous analog synchronization
{
UserTaskDelay(100);
}
printf("send success(main thread)... %s\n" ,data);
i++;
UserTaskDelay(800); // Contract interval
}
printf("all pkg send success(main thread), quit.\n");
padapter->done.NetAiitClose(padapter);
printf("client quit.\n");
}

View File

@ -1,63 +0,0 @@
#include <user_api.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_lora.h>
#include <xs_adapter_manager.h>
extern DoubleLinklistType online_user_head;
void net_lora_gateway(int argc, char *argv[])
{
// 1.New specific agreement (LORA) adapter
static struct AdapterLora lora_adapter;
memset(&lora_adapter, 0, sizeof(lora_adapter));
struct AdapterDone lora_example_done = {
.NetAiitOpen = LoraAdapterOpen,
.NetAiitClose = NULL,
.NetAiitSend = NULL,
.NetAiitReceive = LoraAdapterReceive,
.NetAiitJoin = LoraAdapterJoin,
.NetAiitIoctl = NULL,
};
lora_adapter.parent.done = lora_example_done; // Bind adapter operation
lora_adapter.name = "lora_dev_456"; // Set adapter name
lora_adapter.spi_lora_fd = -1; // Set adapter information
lora_adapter.deve_ui = "xxx";
lora_adapter.app_key = "yyy";
// 2.Register the adapter in the list
LoraAdapterInit();
LoraAdapterRegister((adapter_t)&lora_adapter);
// 3.Find from the list of registered adapters
adapter_t padapter = LoraAdapterFind("lora_dev_456");
if (NONE == padapter)
{
printf("adapter find failed!\n");
return;
}
// 4.Open adapter
if (0 != padapter->done.NetAiitOpen(padapter))
{
printf("adapter open failed!\n");
return;
}
// 5.Join the specified network segment as gateway
padapter->done.NetAiitJoin(padapter, ROLE_TYPE_MASTER, CONNECTION_COMMUNICATION_LORA_NET_ID);
}
static void net_lora_connectedlist(int argc, char *argv[])
{
DoubleLinklistType* pNode;
printf("******** connected users *********\n");
DOUBLE_LINKLIST_FOR_EACH(pNode, &online_user_head)
{
OnlineUser* pUser =CONTAINER_OF(pNode, OnlineUser, link);
printf("%s\n", pUser->user_name);
}
printf("*********************************\n");
}

View File

@ -1,3 +0,0 @@
SRC_FILES := bluetooth_receive_demo.c bluetooth_send_demo.c
# zigbee_send_demo.c zigbee_receive_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: bluetooth_receive_demo.c
* @brief: using bluetooth to receive message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_bluetooth.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <user_api.h>
#include <string.h>
static int re_sem;
static int buff_sem;
/*Critical zone protection function for*/
void BluetoothWait(char *rev_buffer)
{
while(1){
if (strlen(rev_buffer)>1){
UserSemaphoreAbandon(re_sem);
break;
}
}
}
/* receive message from another bluetooth device*/
void BluetoothReceiveDemo(int argc, char *argv[])
{
adapter_t padapter = BluetoothAdapterFind("Bluetooth");
if (NONE == padapter){
KPrintf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
KPrintf("adapter open failed!\n");
return;
}
char rev_buffer[NAME_NUM_MAX];
/* Initialize semaphore */
re_sem = UserSemaphoreCreate(0);
/* receive buffer from serial port */
padapter->done.NetAiitReceive(padapter,rev_buffer,strlen(rev_buffer),10000,false,NULL);
BluetoothWait(rev_buffer);
UserSemaphoreObtain(re_sem,-1);
printf("\n");
for (int i=0;i<strlen(rev_buffer);i++)
{
if(rev_buffer[i] != 0Xff)
printf("%c",rev_buffer[i]);
}
printf("\n");
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
BluetoothReceiveDemo, BluetoothReceiveDemo, bluetooth receive function );
#endif

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: bluetooth_send_demo.c
* @brief: using bluetooth to send message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_bluetooth.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <string.h>
#include <user_api.h>
adapter_t padapter;
/* a demo function to send message through command line using bluetooth*/
/* first open bluetooth to start demo*/
void BluetoothOpenDemo()
{
/*Find from the list of registered adapters*/
// adapter_t padapter = BluetoothAdapterFind("Bluetoot");
padapter = BluetoothAdapterFind("Bluetooth");
if (NONE == padapter){
printf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
printf("adapter open failed!\n");
return;
}
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
BluetoothOpenDemo, BluetoothOpenDemo, bluetooth send function );
#endif
void BluetoothSendDemo(int argc, char *argv[])
{
/*Find from the list of registered adapters*/
bool v = false;
padapter->done.NetAiitSend(padapter, argv[1], strlen(argv[1]) ,true,10000,0, NULL,&v,NULL);
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
BluetoothSendDemo, BluetoothSendDemo, bluetooth send function );
#endif

View File

@ -1,197 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file ethernet_demo.c
* @brief Demo for ethernet function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.22
*/
#include <string.h>
#include <user_api.h>
#include <xs_adapter_manager.h>
#include <xs_adapter_at_ethernet.h>
static bool opened = false;
void OpenEthernetMsg()
{
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
}
void SendEthernetMsg(int argc, char *argv[])
{
char ethernet_msg[128];
if (argc >= 1){
memset(ethernet_msg, 0, 128);
strncpy(ethernet_msg, argv[1], strlen(argv[1]));
printf("SendEthernetMsg(%s).\n", ethernet_msg);
}
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
at_adapter->parent.done.NetAiitSend(&at_adapter->parent, ethernet_msg, strlen(ethernet_msg), true, 1000, 0, NULL, NULL, NULL);
}
void RecvEthernetMsg()
{
char ethernet_recv_msg[128];
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
while (1){
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, ethernet_recv_msg, 128, 40000, true, NULL))
printf("ethernet_recv_msg (%s)\n", ethernet_recv_msg);
else
printf("ethernet_recv_msg failed .\n");
}
}
void DhcpEthernet()
{
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK != at_adapter->atdone.ATOperateDHCP(at_adapter, 1))
printf("EthernetNetstat failed \n");
}
void PingEthernet()
{
char ethernet_recv_msg[128];
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
struct PingResult result;
char *ip_str = "192.168.250.250";
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK == at_adapter->atdone.ATPing(at_adapter, ip_str, &result))
printf("EthernetPing success (%s)\n", result.ip_addr.ipv4);
else
printf("EthernetPing failed \n");
}
void SetUpEthernet()
{
char ethernet_recv_msg[128];
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
struct PingResult result;
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK == at_adapter->atdone.ATOperateUp(at_adapter))
printf("EthernetSetUp success (%s)\n", result.ip_addr.ipv4);
else
printf("EthernetSetUp failed \n");
}
void NetstatEthernet()
{
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!at_adapter)
printf("ATAdapterFind failed .\n");
printf("Waiting for msg...\n");
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
if (EOK != at_adapter->atdone.ATNetstat(at_adapter))
printf("EthernetNetstat failed \n");
}
void AtTestCmdEthernet(int argc, char *argv[])
{
char cmd[64];
if (argc >= 1){
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, argv[1], strlen(argv[1]));
printf("AT cmd send(%s).\n", cmd);
}
strcat(cmd,"\r");
struct AdapterAT* at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
if (!opened){
opened = true;
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
}
printf("Waiting for msg...\n");
// Send hfa21 handshake, start cmd mode.
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "+++");
UserTaskDelay(100);
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "a");
UserTaskDelay(2500);
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,cmd);
UserTaskDelay(2500);
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
UserTaskDelay(5000);
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file nbiot_demo.c
* @brief Demo for NBIoT function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.22
*/
#include <string.h>
#include <user_api.h>
#include <xs_adapter_at_agent.h>
#include <xs_adapter_manager.h>
#include <xs_adapter_at_nbiot.h>
extern void RegisterAdapterNBIoT(void);
void NbiotEnable(void)
{
struct AdapterAT* at_adapter = ATAdapterFind(NBIOT_ADAPTER_ID);
UserTaskDelay(5000);
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
printf("Waiting for msg...\n");
at_adapter->atdone.ATSocketCreate(at_adapter, 1, SOCKET_TYPE_STREAM, NET_TYPE_AF_INET);
UserTaskDelay(1000);
struct AddressIpv4 addr;
addr.ipv4 = IpTint("115.236.53.226");
at_adapter->atdone.ATSocketConnect(at_adapter, 1, addr, 8989, 0);
int socket_fd = 1;
int count = 0;
while (1) {
UserTaskDelay(1000);
at_adapter->parent.done.NetAiitSend((struct Adapter *)at_adapter, "AB30313233", 5, 0, 0, 0, 0, 0, &socket_fd);
count++;
if (count == 10)
break;
}
}

View File

@ -0,0 +1,3 @@
SRC_FILES := lwip_tcp_socket_demo.c lwip_udp_socket_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,200 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file tcp_echo_socket_demo.c
* @brief One UDP demo based on LwIP
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-29
*/
#include <transform.h>
#include <xiuos.h>
#include "board.h"
#include "sys_arch.h"
#include <lwip/sockets.h>
#include "lwip/sys.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
char tcp_socket_ip[] = {192, 168, 250, 252};
#define TCP_DEMO_BUF_SIZE 65535
/*******************************************************************************
* Code
******************************************************************************/
static void tcp_recv_demo(void *arg)
{
int fd = -1, clientfd;
int recv_len;
char *recv_buf;
struct sockaddr_in tcp_addr;
socklen_t addr_len;
while(1)
{
recv_buf = (char *)malloc(TCP_DEMO_BUF_SIZE);
if (recv_buf == NULL)
{
lw_print("No memory\n");
goto __exit;
}
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
{
lw_print("Socket error\n");
goto __exit;
}
tcp_addr.sin_family = AF_INET;
tcp_addr.sin_addr.s_addr = INADDR_ANY;
tcp_addr.sin_port = htons(LWIP_LOCAL_PORT);
memset(&(tcp_addr.sin_zero), 0, sizeof(tcp_addr.sin_zero));
if (bind(fd, (struct sockaddr *)&tcp_addr, sizeof(struct sockaddr)) == -1)
{
lw_print("Unable to bind\n");
goto __exit;
}
lw_print("tcp bind success, start to receive.\n");
lw_print("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT);
// setup socket fd as listening mode
if (listen(fd, 5) != 0 )
{
lw_print("Unable to listen\n");
goto __exit;
}
// accept client connection
clientfd = accept(fd, (struct sockaddr *)&tcp_addr, (socklen_t*)&addr_len);
lw_print("client %s connected\n", inet_ntoa(tcp_addr.sin_addr));
while(1)
{
memset(recv_buf, 0, TCP_DEMO_BUF_SIZE);
recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, (struct sockaddr *)&tcp_addr, &addr_len);
if(recv_len > 0)
{
lw_pr_info("Receive from : %s\n", inet_ntoa(tcp_addr.sin_addr));
lw_pr_info("Receive data : %d - %s\n\n", recv_len, recv_buf);
}
sendto(clientfd, recv_buf, recv_len, 0, (struct sockaddr*)&tcp_addr, addr_len);
}
__exit:
if (fd >= 0)
closesocket(fd);
if (recv_buf)
free(recv_buf);
}
}
void tcp_socket_recv_run(int argc, char *argv[])
{
int result = 0;
pthread_t th_id;
pthread_attr_t attr;
if(argc == 2)
{
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
}
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
sys_thread_new("tcp_recv_demo", tcp_recv_demo, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
TCPSocketRecv, tcp_socket_recv_run, TCP recv echo);
static void tcp_send_demo(void *arg)
{
int cnt = LWIP_DEMO_TIMES;
int fd = -1;
char send_msg[128];
lw_print("%s start\n", __func__);
memset(send_msg, 0, sizeof(send_msg));
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
{
lw_print("Socket error\n");
goto __exit;
}
struct sockaddr_in tcp_sock;
tcp_sock.sin_family = AF_INET;
tcp_sock.sin_port = htons(LWIP_TARGET_PORT);
tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_socket_ip[0], tcp_socket_ip[1], tcp_socket_ip[2], tcp_socket_ip[3]));
memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero));
if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)))
{
lw_print("Unable to connect\n");
goto __exit;
}
lw_print("tcp connect success, start to send.\n");
lw_pr_info("\n\nTarget Port:%d\n\n", tcp_sock.sin_port);
while (cnt --)
{
lw_print("Lwip client is running.\n");
snprintf(send_msg, sizeof(send_msg), "TCP test package times %d\r\n", cnt);
sendto(fd, send_msg, strlen(send_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
lw_pr_info("Send tcp msg: %s ", send_msg);
MdelayKTask(1000);
}
__exit:
if (fd >= 0)
closesocket(fd);
return;
}
void tcp_socket_send_run(int argc, char *argv[])
{
if(argc == 2)
{
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
}
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
sys_thread_new("tcp socket", tcp_send_demo, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
TCPSocketSend, tcp_socket_send_run, TCP send demo);

View File

@ -0,0 +1,209 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file lwip_udp_socket_demo.c
* @brief One UDP demo based on LwIP
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-29
*/
#include <transform.h>
#include <xiuos.h>
#include "board.h"
#include "sys_arch.h"
#include "lwip/udp.h"
#include "lwip/opt.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
extern char udp_target[];
static struct udp_pcb *udpecho_raw_pcb;
char udp_socket_ip[] = {192, 168, 250, 252};
/*******************************************************************************
* Code
******************************************************************************/
#include <lwip/sockets.h>
#include "lwip/sys.h"
#define LWIP_UDP_TASK_STACK 4096
#define LWIP_UDP_TASK_PRIO 25
#define UDP_BUF_SIZE 1024
static void udp_recv_demo(void *arg)
{
lw_print("udp_recv_demo start.\n");
int socket_fd = -1;
char *recv_buf;
struct sockaddr_in udp_addr, server_addr;
int recv_len;
socklen_t addr_len;
while(1)
{
recv_buf = (char *)malloc(UDP_BUF_SIZE);
if (recv_buf == NULL)
{
lw_print("No memory\n");
goto __exit;
}
socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (socket_fd < 0)
{
lw_print("Socket error\n");
goto __exit;
}
udp_addr.sin_family = AF_INET;
udp_addr.sin_addr.s_addr = INADDR_ANY;
udp_addr.sin_port = htons(LWIP_LOCAL_PORT);
memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
if (bind(socket_fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1)
{
lw_print("Unable to bind\n");
goto __exit;
}
lw_print("UDP bind sucess, start to receive.\n");
lw_print("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT);
while(1)
{
memset(recv_buf, 0, UDP_BUF_SIZE);
recv_len = recvfrom(socket_fd, recv_buf, UDP_BUF_SIZE, 0, (struct sockaddr *)&server_addr, &addr_len);
lw_print("Receive from : %s\n", inet_ntoa(server_addr.sin_addr));
lw_print("Receive data : %s\n\n", recv_buf);
sendto(socket_fd, recv_buf, recv_len, 0, (struct sockaddr*)&server_addr, addr_len);
}
__exit:
if (socket_fd >= 0)
closesocket(socket_fd);
if (recv_buf)
free(recv_buf);
}
}
static void udp_recv_demo_thread(void* param)
{
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
sys_thread_new("udp_recv_demo", udp_recv_demo, NULL, LWIP_UDP_TASK_STACK, LWIP_UDP_TASK_PRIO);
}
void udp_socket_recv_run(int argc, char *argv[])
{
int result = 0;
pthread_t th_id;
pthread_attr_t attr;
if(argc == 2)
{
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
}
sys_thread_new("udp socket send", udp_recv_demo_thread, NULL, 4096, 15);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UDPSocketRecv, udp_socket_recv_run, UDP recv echo);
static void udp_send_demo(void *arg)
{
int cnt = LWIP_DEMO_TIMES;
char send_str[128];
lw_print("udp_send_demo start.\n");
int socket_fd = -1;
memset(send_str, 0, sizeof(send_str));
socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (socket_fd < 0)
{
lw_print("Socket error\n");
goto __exit;
}
struct sockaddr_in udp_sock;
udp_sock.sin_family = AF_INET;
udp_sock.sin_port = htons(LWIP_TARGET_PORT);
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_target[0],udp_target[1],udp_target[2],udp_target[3]));
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
if (connect(socket_fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)))
{
lw_print("Unable to connect\n");
goto __exit;
}
lw_print("UDP connect success, start to send.\n");
lw_print("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
while (cnt --)
{
snprintf(send_str, sizeof(send_str), "UDP test package times %d\r\n", cnt);
sendto(socket_fd, send_str, strlen(send_str), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
lw_pr_info("Send UDP msg: %s ", send_str);
MdelayKTask(1000);
}
__exit:
if (socket_fd >= 0)
{
closesocket(socket_fd);
}
return;
}
static void udp_send_demo_thread(void* param)
{
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
sys_thread_new("udp_send_demo", udp_send_demo, NULL, LWIP_UDP_TASK_STACK, LWIP_UDP_TASK_PRIO);
}
void udp_socket_send_run(int argc, char *argv[])
{
int result = 0;
pthread_t th_id;
pthread_attr_t attr;
if(argc == 2)
{
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
}
sys_thread_new("udp socket send", udp_send_demo_thread, NULL, 4096, 15);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UDPSocketSend, udp_socket_send_run, UDP send echo);

View File

@ -1,223 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file wifi_demo.c
* @brief Demo for wifi function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.04.22
*/
#include <at_agent.h>
#include <adapter.h>
void SendWiftMsg(int argc, char *argv[])
{
char wifi_msg[128];
int len;
if (argc >= 1) {
memset(wifi_msg, 0, 128);
strncpy(wifi_msg, argv[1], (len = strlen(argv[1])));
printf("SendWiftMsg(%s).\n", wifi_msg);
}
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
AdapterDeviceOpen(adapter);
AdapterDeviceSend(adapter, wifi_msg, len);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), SendWiftMsg, SendWiftMsg, SendWiftMsg);
void RecvWifiMsg()
{
char wifi_recv_msg[128];
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
AdapterDeviceOpen(adapter);
while (1) {
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
if (EOK == AdapterDeviceRecv(adapter, wifi_recv_msg, 128)) {
printf("wifi_recv_msg (%s)\n", wifi_recv_msg);
} else {
printf("wifi_recv_msg failed .\n");
}
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), RecvWifiMsg, RecvWifiMsg, RecvWifiMsg);
void SetUpWifi()
{
char wifi_recv_msg[128];
int baud_rate = BAUD_RATE_57600;
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
if (EOK == AdapterDeviceSetUp(adapter)) {
printf("SetUpWifi success \n");
} else {
printf("SetUpWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetUpWifi, SetUpWifi, SetUpWifi);
void SetDownWifi()
{
char wifi_recv_msg[128];
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if (EOK == AdapterDeviceSetDown(adapter)) {
printf("SetDownWifi success \n");
} else {
printf("SetDownWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetDownWifi, SetDownWifi, SetDownWifi);
void SetAddrWifi()
{
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if(EOK == AdapterDeviceSetAddr(adapter, "192.168.66.253", "255.255.255.0", "192.168.66.1")){
printf("SetAddrWifi success \n");
} else {
printf("SetAddrWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetAddrWifi, SetAddrWifi, SetAddrWifi);
void PingWifi()
{
char wifi_recv_msg[128];
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
//www.baidu.com
char *ip_str = "36.152.44.95";
AdapterDeviceOpen(adapter);
if (EOK == AdapterDevicePing(adapter, ip_str)) {
printf("PingWifi success \n");
} else {
printf("PingWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), PingWifi, PingWifi, PingWifi);
void NetstatWifi()
{
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if (EOK == AdapterDeviceNetstat(adapter)) {
printf("NetstatWifi success \n");
} else {
printf("NetstatWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), NetstatWifi, NetstatWifi, NetstatWifi);
int ConnectWifi()
{
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
const char *ip = "192.168.66.33";
const char *port = "12345";
enum NetRoleType net_role = CLIENT;
enum IpType ip_type = IPV4;
if (!adapter) {
printf("ATAdapterFind failed .\n");
}
printf("Waiting for msg...\n");
AdapterDeviceOpen(adapter);
if (EOK == AdapterDeviceConnect(adapter, net_role, ip, port, ip_type)) {
printf("ConnectWifi success \n");
} else {
printf("ConnectWifi failed \n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), ConnectWifi, ConnectWifi, ConnectWifi);
void AtTestCmdWifi(int argc, char *argv[])
{
char cmd[64];
if (argc >= 1) {
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, argv[1], strlen(argv[1]));
printf("AT cmd send(%s).\n", cmd);
}
strcat(cmd,"\r");
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
// AdapterDeviceOpen(adapter);
printf("Waiting for msg...\n");
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
UserTaskDelay(100);
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "a");
UserTaskDelay(2500);
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,cmd);
UserTaskDelay(2500);
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
UserTaskDelay(5000);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), AtTestCmdWifi, AtTestCmdWifi, AtTestCmdWifi);

View File

@ -1,3 +0,0 @@
SRC_FILES := zigbee_receive_demo.c
# zigbee_send_demo.c zigbee_receive_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: zigbee_receive_demo.c
* @brief: using zigbee to receive message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_zigbee.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <user_api.h>
#include <string.h>
static int re_sem;
static int buff_sem;
/*Critical zone protection function for*/
void ZigbeeWait(char *rev_buffer)
{
while(1){
if (strlen(rev_buffer)>1){
UserSemaphoreAbandon(re_sem);
break;
}
}
}
/* receive message from another zigbee device*/
void ZigbeeReceiveDemo(int argc, char *argv[])
{
adapter_t padapter = ZigbeeAdapterFind("zigbee");
if (NONE == padapter){
KPrintf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
KPrintf("adapter open failed!\n");
return;
}
char rev_buffer[NAME_NUM_MAX];
/* Initialize semaphore */
re_sem = UserSemaphoreCreate(0);
/* receive buffer from serial port */
padapter->done.NetAiitReceive(padapter,rev_buffer,strlen(rev_buffer),10000,false,NULL);
ZigbeeWait(rev_buffer);
UserSemaphoreObtain(re_sem,-1);
printf("\n");
for (int i=0;i<strlen(rev_buffer);i++)
{
if(rev_buffer[i] != 0Xff)
printf("%c",rev_buffer[i]);
}
printf("\n");
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
ZigbeeReceiveDemo, ZigbeeReceiveDemo, zigbee receive function );
#endif

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: zigbee_send_demo.c
* @brief: using zigbee to send message
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/4/30
*
*/
#include <xs_adapter_zigbee.h>
#include <string.h>
#include <xs_klist.h>
#include <xs_adapter_manager.h>
#include <string.h>
#include <user_api.h>
adapter_t padapter;
/* a demo function to send message through command line using zigbee*/
/* first open zigbee to start demo*/
void ZigbeeOpenDemo()
{
/*Find from the list of registered adapters*/
// adapter_t padapter = ZigbeeAdapterFind("zigbee");
padapter = ZigbeeAdapterFind("zigbee");
if (NONE == padapter){
printf("adapter find failed!\n");
return;
}
/*Open adapter*/
if (0 != padapter->done.NetAiitOpen(padapter)){
printf("adapter open failed!\n");
return;
}
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
ZigbeeOpenDemo, ZigbeeOpenDemo, zigbee send function );
#endif
void ZigbeeSendDemo(int argc, char *argv[])
{
/*Find from the list of registered adapters*/
bool v = false;
padapter->done.NetAiitSend(padapter, argv[1], strlen(argv[1]) ,true,10000,0, NULL,&v,NULL);
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
ZigbeeSendDemo, ZigbeeSendDemo, zigbee send function );
#endif

View File

@ -3,6 +3,7 @@ menu "control app"
menuconfig APPLICATION_CONTROL
bool "Using control apps"
default n
depends on SUPPORT_CONTROL_FRAMEWORK
endmenu

View File

@ -0,0 +1,11 @@
SRC_DIR :=
ifeq ($(CONFIG_RESOURCES_LWIP),y)
ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y)
SRC_DIR += opcua_demo
endif
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,3 @@
SRC_FILES :=nbiot_demo.c
SRC_FILES :=opcua_demo.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,211 @@
/*
* Copyright (c) 2021 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file ua_demo.c
* @brief Demo for OpcUa function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.11.11
*/
#include <list.h>
#include <transform.h>
#include "board.h"
#include <lwip/altcp.h>
#include "open62541.h"
#include "ua_api.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define TCP_LOCAL_PORT 4840
#define UA_URL_SIZE 100
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
char test_ua_ip[] = {192, 168, 250, 5};
/*******************************************************************************
* Code
******************************************************************************/
static void test_ua_connect(void *arg)
{
struct netif net;
UA_StatusCode retval;
char ua_uri[UA_URL_SIZE];
memset(ua_uri, 0, sizeof(ua_uri));
UA_Client *client = UA_Client_new();
if (client == NULL)
{
ua_print("ua: [%s] tcp client null\n", __func__);
return;
}
UA_ClientConfig *config = UA_Client_getConfig(client);
UA_ClientConfig_setDefault(config);
snprintf(ua_uri, UA_URL_SIZE, "opc.tcp://%d.%d.%d.%d:4840",
test_ua_ip[0], test_ua_ip[1], test_ua_ip[2], test_ua_ip[3]);
retval = UA_Client_connect(client, ua_uri);
if (retval != UA_STATUSCODE_GOOD)
{
ua_print("ua: [%s] ret %x\n", __func__, retval);
}
ua_print("ua: [%s] start Ua Test!\n", __func__);
UA_Client_disconnect(client);
UA_Client_delete(client);
}
void test_ua_connect_thr(void *arg)
{
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
test_ua_connect(NULL);
}
void test_sh_ua_connect(void)
{
int result = 0;
pthread_t th_id;
pthread_attr_t attr;
sys_thread_new("ua test", test_ua_connect_thr, NULL, 4096, 15);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
UaConnect, test_sh_ua_connect, Test Opc UA connection);
void test_ua_browser_objects(void *param)
{
UA_Client *client = UA_Client_new();
ua_pr_info("ua: [%s] start ...\n", __func__);
if (client == NULL)
{
ua_print("ua: [%s] tcp client null\n", __func__);
return;
}
UA_ClientConfig *config = UA_Client_getConfig(client);
UA_ClientConfig_setDefault(config);
UA_StatusCode retval = UA_Client_connect(client, OPC_SERVER);
if(retval != UA_STATUSCODE_GOOD) {
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
UA_Client_delete(client);
return;
}
ua_print("ua: [%s] connect ok!\n", __func__);
ua_pr_info("--- start read time ---\n", __func__);
ua_read_time(client);
ua_pr_info("--- get server info ---\n", __func__);
ua_browser_objects(client);
/* Clean up */
UA_Client_disconnect(client);
UA_Client_delete(client); /* Disconnects the client internally */
}
void *test_sh_ua_brower_objects(int argc, char *argv[])
{
if(argc == 2)
{
if(isdigit(argv[1][0]))
{
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
{
lw_pr_info("input wrong ip\n");
return NULL;
}
}
}
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
sys_thread_new("ua object", test_ua_browser_objects, NULL, 4096, 15);
return NULL;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UaObj, test_sh_ua_brower_objects, UaObj [IP]);
void test_ua_get_info(void *param)
{
UA_Client *client = UA_Client_new();
ua_pr_info("ua: [%s] start ...\n", __func__);
if (client == NULL)
{
ua_print("ua: [%s] tcp client null\n", __func__);
return;
}
UA_ClientConfig *config = UA_Client_getConfig(client);
UA_ClientConfig_setDefault(config);
UA_StatusCode retval = UA_Client_connect(client, OPC_SERVER);
if(retval != UA_STATUSCODE_GOOD) {
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
UA_Client_delete(client);
return;
}
ua_print("ua: [%s] connect ok!\n", __func__);
ua_pr_info("--- get server info ---\n", __func__);
ua_get_server_info(client);
/* Clean up */
UA_Client_disconnect(client);
UA_Client_delete(client); /* Disconnects the client internally */
}
void *test_sh_ua_get_info(int argc, char *argv[])
{
if(argc == 2)
{
if(isdigit(argv[1][0]))
{
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
{
lw_pr_info("input wrong ip\n");
return NULL;
}
}
}
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
sys_thread_new("ua object", test_ua_browser_objects, NULL, 4096, 15);
return NULL;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UaInfo, test_sh_ua_get_info, UaInfo [IP]);

View File

@ -11,19 +11,32 @@
*/
#include <stdio.h>
#include <string.h>
#include <user_api.h>
#include <transform.h>
extern int SensorFrameworkInit(void);
extern int AdapterFrameworkInit(void);
extern int Adapter4GInit(void);
extern int AdapterNbiotInit(void);
extern int AdapterBlueToothInit(void);
extern int AdapterWifiInit(void);
extern int AdapterEthernetInit(void);
extern int AdapterZigbeeInit(void);
extern int AdapterLoraInit(void);
extern int D124VoiceInit(void);
extern int Hs300xTemperatureInit(void);
extern int Hs300xHumidityInit(void);
extern int Ps5308Pm1_0Init(void);
extern int Ps5308Pm2_5Init(void);
extern int Ps5308Pm10Init(void);
extern int Zg09Co2Init(void);
extern int As830Ch4Init(void);
extern int Tb600bIaq10IaqInit(void);
extern int Tb600bTvoc10TvocInit(void);
extern int Tb600bWqHcho1osInit(void);
extern int lv_port_init(void);
typedef int (*InitFunc)(void);
struct InitDesc
@ -78,22 +91,59 @@ static struct InitDesc sensor_desc[] =
#ifdef SENSOR_QUANTITY_PS5308_PM1_0
{ "ps5308_pm1_0", Ps5308Pm1_0Init },
#endif
#ifdef SENSOR_QUANTITY_PS5308_PM2_5
{ "ps5308_pm2_5", Ps5308Pm2_5Init },
#endif
#ifdef SENSOR_QUANTITY_PS5308_PM10
{ "ps5308_pm10", Ps5308Pm10Init },
#endif
#endif
#ifdef SENSOR_ZG09
{ "zg09_co2", Zg09Co2Init },
#endif
#ifdef SENSOR_AS830
{ "ch4_as830", As830Ch4Init },
#endif
#ifdef SENSOR_TB600B_IAQ10
{ "iaq_tb600b_iaq10", Tb600bIaq10IaqInit },
#endif
#ifdef SENSOR_TB600B_TVOC10
{ "tvoc_tb600b_tvoc10", Tb600bTvoc10TvocInit },
#endif
#ifdef SENSOR_TB600B_WQ_HCHO1OS
{ "tvoc_tb600b_wq_hcho1os", Tb600bWqHcho1osInit },
#endif
{ "NULL", NULL },
};
static struct InitDesc connection_desc[] =
{
#ifdef ADAPTER_4G
{ "4G adpter", Adapter4GInit},
#ifdef CONNECTION_ADAPTER_4G
{ "4G adapter", Adapter4GInit},
#endif
#ifdef ADAPTER_WIFI
{ "Wifi adpter", AdapterWifiInit},
#ifdef CONNECTION_ADAPTER_NB
{ "NB adpter", AdapterNbiotInit},
#endif
#ifdef CONNECTION_ADAPTER_ZIGBEE
{ "zigbee adapter", AdapterZigbeeInit},
#endif
#ifdef CONNECTION_ADAPTER_BLUETOOTH
{ "bluetooth adapter", AdapterBlueToothInit},
#endif
#ifdef CONNECTION_ADAPTER_WIFI
{ "wifi adapter", AdapterWifiInit},
#endif
#ifdef CONNECTION_ADAPTER_ETHERNET
{ "ethernet adapter", AdapterEthernetInit},
#endif
#ifdef CONNECTION_ADAPTER_LORA
{ "lora adapter", AdapterLoraInit},
#endif
{ "NULL", NULL },
};
@ -150,7 +200,7 @@ static int ConnectionDeviceFrameworkInit(struct InitDesc sub_desc[])
* This function will init system framework
*
*/
int FrameworkInit()
int FrameworkInit(void)
{
#ifdef SUPPORT_SENSOR_FRAMEWORK
SensorDeviceFrameworkInit(framework);
@ -160,5 +210,9 @@ int FrameworkInit()
ConnectionDeviceFrameworkInit(framework);
#endif
#ifdef LIB_LV
lv_port_init();
#endif
return 0;
}

View File

@ -1,3 +1,11 @@
SRC_FILES := double_list.c single_list.c
include $(KERNEL_ROOT)/.config
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += double_list.c single_list.c
include $(APPDIR)/Application.mk
endif
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES := double_list.c single_list.c
include $(KERNEL_ROOT)/compiler.mk
endif

View File

@ -0,0 +1,11 @@
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')
cwd = GetCurrentDir()
DEPENDS = [""]
SOURCES = ['double_list.c'] + ['single_list.c']
path = [cwd]
objs = DefineGroup('list', src = SOURCES, depend = DEPENDS,CPPPATH = path)
Return("objs")

View File

@ -22,8 +22,10 @@
#ifndef __LIST_H__
#define __LIST_H__
#include "libc.h"
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
#include<stddef.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -5,9 +5,11 @@ menu "knowing app"
if APPLICATION_KNOWING
source "$APP_DIR/Applications/knowing_app/mnist/Kconfig"
source "$APP_DIR/Applications/knowing_app/face_detect/Kconfig"
source "$APP_DIR/Applications/knowing_app/instrusion_detect/Kconfig"
source "$APP_DIR/Applications/knowing_app/helmet_detect/Kconfig"
source "$APP_DIR/Applications/knowing_app/k210_detect_entry/Kconfig"
source "$APP_DIR/Applications/knowing_app/iris_ml_demo/Kconfig"
source "$APP_DIR/Applications/knowing_app/k210_fft_test/Kconfig"
source "$APP_DIR/Applications/knowing_app/image_processing/Kconfig"
source "$APP_DIR/Applications/knowing_app/cmsis_5_demo/Kconfig"
endif
endmenu

View File

@ -0,0 +1,16 @@
menuconfig USING_CMSIS_5_DEMOAPP
bool "CMSIS-5 demo app"
depends on USING_USING_CMSIS_5_NN
default n
if USING_CMSIS_5_DEMOAPP
config USING_CMSIS_5_NN_DEMOAPP
bool "Using CMSIS-5 NN demo app"
select USING_IMAGE_PROCESSING
select IMAGE_PROCESSING_USING_TJPGD
default n
endif

View File

@ -0,0 +1,14 @@
# CMSIS-NN cifar10 example
The model of this example is from [[ARM-software](https://github.com/ARM-software)/**[ML-examples](https://github.com/ARM-software/ML-examples)**] and can be deployed on Arm Cortex-M CPUs using [CMSIS-NN](https://github.com/ARM-software/CMSIS_5).
## Requirements:
- CMSIS-NN in Framework/knowing/cmsis_5
- TJpgDec in Framework/knowing/image_processing
- Enough stack size (recommend 10240) for finsh thread which can be changed in "RT-Thread Components->Command shell->finsh shell" by menuconfig.
## To run this demo:
- Place the photo where you want
- Run demo by type the command
```
cmsisnn_demo /path/to/photo

View File

@ -0,0 +1,18 @@
from building import *
import os
cwd = GetCurrentDir()
src = Split('''
model/m4/nn.c
demo/cmsisnn_demo.c
''')
path = [
cwd + '/model/m4',
cwd + '/demo'
]
group = DefineGroup('CMSISNN-cifar10', src, depend = ['USING_CMSIS_5_DEMOAPP'], CPPPATH = path)
Return('group')

Binary file not shown.

After

Width:  |  Height:  |  Size: 1000 B

View File

@ -0,0 +1,157 @@
#include <transform.h>
#include <tjpgd.h>
#include "../model/m4/nn.h"
#define WORK_POOL_SIZE (4 * 1024 + 32)
const char *cifar10_label[] = {"Plane", "Car", "Bird", "Cat", "Deer", "Dog", "Frog", "Horse", "Ship", "Truck"};
int get_top_prediction(q7_t *predictions)
{
int max_ind = 0;
int max_val = -128;
for (int i = 0; i < 10; i++)
{
if (max_val < predictions[i])
{
max_val = predictions[i];
max_ind = i;
}
}
return max_ind;
}
int cmsisnn_inference(uint8_t *input_data)
{
q7_t output_data[10];
run_nn((q7_t *)input_data, output_data);
arm_softmax_q7(output_data, IP1_OUT_DIM, output_data);
int top_ind = get_top_prediction(output_data);
printf("\rPrediction: %s \r\n", cifar10_label[top_ind]);
return top_ind;
}
typedef struct
{
FILE *fp;
uint8_t *fbuf;
uint16_t wfbuf;
} IODEV;
unsigned int in_func_cmsisnn(JDEC *jd, uint8_t *buff, unsigned int nbyte)
{
IODEV *dev = (IODEV *)jd->device;
if (buff)
{
return (uint16_t)fread(buff, 1, nbyte, dev->fp);
}
else
{
return fseek(dev->fp, nbyte, SEEK_CUR) ? 0 : nbyte;
}
}
int out_func_cmsisnn(JDEC *jd, void *bitmap, JRECT *rect)
{
IODEV *dev = (IODEV *)jd->device;
uint8_t *src, *dst;
uint16_t y, bws, bwd;
if (rect->left == 0)
{
printf("\r%lu%%", (rect->top << jd->scale) * 100UL / jd->height);
}
src = (uint8_t *)bitmap;
dst = dev->fbuf + 3 * (rect->top * dev->wfbuf + rect->left);
bws = 3 * (rect->right - rect->left + 1);
bwd = 3 * dev->wfbuf;
for (y = rect->top; y <= rect->bottom; y++)
{
memcpy(dst, src, bws);
src += bws;
dst += bwd;
}
return 1;
}
int cmsisnn_demo(int argc, char *argv[])
{
void *work;
JDEC jdec;
JRESULT res;
IODEV devid;
if (argc < 2)
{
printf("Jpeg_Dec illegal arguments ...\n");
return -1;
}
devid.fp = fopen(argv[1], "r+");
if (!devid.fp)
{
printf("Jpeg_Dec open the file failed...\n");
return -1;
}
work = malloc(WORK_POOL_SIZE);
if (work == NULL)
{
printf("Jpeg_Dec work malloc failed...\n");
res = -1;
goto __exit;
}
res = jd_prepare(&jdec, in_func_cmsisnn, work, WORK_POOL_SIZE, &devid);
if (res == JDR_OK)
{
printf("Image dimensions: %u by %u. %u bytes used.\n", jdec.width, jdec.height, 3100 - jdec.sz_pool);
devid.fbuf = malloc(3 * jdec.width * jdec.height);
if (devid.fbuf == NULL)
{
printf("Jpeg_Dec devid.fbuf malloc failed, need to use %d Bytes ...\n", 3 * jdec.width * jdec.height);
res = -1;
goto __exit;
}
devid.wfbuf = jdec.width;
res = jd_decomp(&jdec, out_func_cmsisnn, 0);
if (res == JDR_OK)
{
printf("\rDecompress success \n");
}
else
{
printf("Failed to decompress: rc=%d\n", res);
}
cmsisnn_inference(devid.fbuf);
if (devid.fbuf != NULL)
{
free(devid.fbuf);
}
}
else
{
printf("Failed to prepare: rc=%d\n", res);
}
__exit:
if (work != NULL)
{
free(work);
}
fclose(devid.fp);
return res;
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(cmsisnn_demo, cifar10 demo and filename should be followed);
#endif

View File

@ -0,0 +1,46 @@
#include "nn.h"
// Timer t;
static uint8_t mean[DATA_OUT_CH*DATA_OUT_DIM*DATA_OUT_DIM] = MEAN_DATA;
static q7_t conv1_wt[CONV1_IN_CH*CONV1_KER_DIM*CONV1_KER_DIM*CONV1_OUT_CH] = CONV1_WT;
static q7_t conv1_bias[CONV1_OUT_CH] = CONV1_BIAS;
static q7_t conv2_wt[CONV2_IN_CH*CONV2_KER_DIM*CONV2_KER_DIM*CONV2_OUT_CH] = CONV2_WT;
static q7_t conv2_bias[CONV2_OUT_CH] = CONV2_BIAS;
static q7_t conv3_wt[CONV3_IN_CH*CONV3_KER_DIM*CONV3_KER_DIM*CONV3_OUT_CH] = CONV3_WT;
static q7_t conv3_bias[CONV3_OUT_CH] = CONV3_BIAS;
static q7_t ip1_wt[IP1_IN_DIM*IP1_OUT_DIM] = IP1_WT;
static q7_t ip1_bias[IP1_OUT_DIM] = IP1_BIAS;
//Add input_data and output_data in top main.cpp file
//uint8_t input_data[DATA_OUT_CH*DATA_OUT_DIM*DATA_OUT_DIM];
//q7_t output_data[IP1_OUT_DIM];
q7_t col_buffer[3200];
q7_t scratch_buffer[40960];
void mean_subtract(q7_t* image_data) {
for(int i=0; i<DATA_OUT_CH*DATA_OUT_DIM*DATA_OUT_DIM; i++) {
image_data[i] = (q7_t)__SSAT( ((int)(image_data[i] - mean[i]) >> DATA_RSHIFT), 8);
}
}
void run_nn(q7_t* input_data, q7_t* output_data) {
q7_t* buffer1 = scratch_buffer;
q7_t* buffer2 = buffer1 + 32768;
mean_subtract(input_data);
arm_convolve_HWC_q7_RGB(input_data, CONV1_IN_DIM, CONV1_IN_CH, conv1_wt, CONV1_OUT_CH, CONV1_KER_DIM, CONV1_PAD, CONV1_STRIDE, conv1_bias, CONV1_BIAS_LSHIFT, CONV1_OUT_RSHIFT, buffer1, CONV1_OUT_DIM, (q15_t*)col_buffer, NULL);
arm_maxpool_q7_HWC(buffer1, POOL1_IN_DIM, POOL1_IN_CH, POOL1_KER_DIM, POOL1_PAD, POOL1_STRIDE, POOL1_OUT_DIM, col_buffer, buffer2);
arm_relu_q7(buffer2, RELU1_OUT_DIM*RELU1_OUT_DIM*RELU1_OUT_CH);
arm_convolve_HWC_q7_fast(buffer2, CONV2_IN_DIM, CONV2_IN_CH, conv2_wt, CONV2_OUT_CH, CONV2_KER_DIM, CONV2_PAD, CONV2_STRIDE, conv2_bias, CONV2_BIAS_LSHIFT, CONV2_OUT_RSHIFT, buffer1, CONV2_OUT_DIM, (q15_t*)col_buffer, NULL);
arm_relu_q7(buffer1, RELU2_OUT_DIM*RELU2_OUT_DIM*RELU2_OUT_CH);
arm_avepool_q7_HWC(buffer1, POOL2_IN_DIM, POOL2_IN_CH, POOL2_KER_DIM, POOL2_PAD, POOL2_STRIDE, POOL2_OUT_DIM, col_buffer, buffer2);
arm_convolve_HWC_q7_fast(buffer2, CONV3_IN_DIM, CONV3_IN_CH, conv3_wt, CONV3_OUT_CH, CONV3_KER_DIM, CONV3_PAD, CONV3_STRIDE, conv3_bias, CONV3_BIAS_LSHIFT, CONV3_OUT_RSHIFT, buffer1, CONV3_OUT_DIM, (q15_t*)col_buffer, NULL);
arm_relu_q7(buffer1, RELU3_OUT_DIM*RELU3_OUT_DIM*RELU3_OUT_CH);
arm_avepool_q7_HWC(buffer1, POOL3_IN_DIM, POOL3_IN_CH, POOL3_KER_DIM, POOL3_PAD, POOL3_STRIDE, POOL3_OUT_DIM, col_buffer, buffer2);
arm_fully_connected_q7_opt(buffer2, ip1_wt, IP1_IN_DIM, IP1_OUT_DIM, IP1_BIAS_LSHIFT, IP1_OUT_RSHIFT, ip1_bias, output_data, (q15_t*)col_buffer);
}

View File

@ -0,0 +1,12 @@
#ifndef __NN_H__
#define __NN_H__
// #include "mbed.h"
#include "arm_math.h"
#include "parameter.h"
#include "weights.h"
#include "arm_nnfunctions.h"
void run_nn(q7_t* input_data, q7_t* output_data);
#endif

View File

@ -0,0 +1,69 @@
#define DATA_OUT_CH 3
#define DATA_OUT_DIM 32
#define CONV1_IN_DIM 32
#define CONV1_IN_CH 3
#define CONV1_KER_DIM 5
#define CONV1_PAD 2
#define CONV1_STRIDE 1
#define CONV1_OUT_CH 32
#define CONV1_OUT_DIM 32
#define POOL1_IN_DIM 32
#define POOL1_IN_CH 32
#define POOL1_KER_DIM 3
#define POOL1_STRIDE 2
#define POOL1_PAD 0
#define POOL1_OUT_DIM 16
#define RELU1_OUT_CH 32
#define RELU1_OUT_DIM 16
#define CONV2_IN_DIM 16
#define CONV2_IN_CH 32
#define CONV2_KER_DIM 5
#define CONV2_PAD 2
#define CONV2_STRIDE 1
#define CONV2_OUT_CH 16
#define CONV2_OUT_DIM 16
#define RELU2_OUT_CH 16
#define RELU2_OUT_DIM 16
#define POOL2_IN_DIM 16
#define POOL2_IN_CH 16
#define POOL2_KER_DIM 3
#define POOL2_STRIDE 2
#define POOL2_PAD 0
#define POOL2_OUT_DIM 8
#define CONV3_IN_DIM 8
#define CONV3_IN_CH 16
#define CONV3_KER_DIM 5
#define CONV3_PAD 2
#define CONV3_STRIDE 1
#define CONV3_OUT_CH 32
#define CONV3_OUT_DIM 8
#define RELU3_OUT_CH 32
#define RELU3_OUT_DIM 8
#define POOL3_IN_DIM 8
#define POOL3_IN_CH 32
#define POOL3_KER_DIM 3
#define POOL3_STRIDE 2
#define POOL3_PAD 0
#define POOL3_OUT_DIM 4
#define IP1_IN_DIM 512
#define IP1_OUT_DIM 10
#define DATA_RSHIFT 0
#define CONV1_BIAS_LSHIFT 0
#define CONV1_OUT_RSHIFT 11
#define CONV2_BIAS_LSHIFT 0
#define CONV2_OUT_RSHIFT 8
#define CONV3_BIAS_LSHIFT 0
#define CONV3_OUT_RSHIFT 8
#define IP1_BIAS_LSHIFT 5
#define IP1_OUT_RSHIFT 7

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,46 @@
#include "nn.h"
// Timer t;
static uint8_t mean[DATA_OUT_CH*DATA_OUT_DIM*DATA_OUT_DIM] = MEAN_DATA;
static q7_t conv1_wt[CONV1_IN_CH*CONV1_KER_DIM*CONV1_KER_DIM*CONV1_OUT_CH] = CONV1_WT;
static q7_t conv1_bias[CONV1_OUT_CH] = CONV1_BIAS;
static q7_t conv2_wt[CONV2_IN_CH*CONV2_KER_DIM*CONV2_KER_DIM*CONV2_OUT_CH] = CONV2_WT;
static q7_t conv2_bias[CONV2_OUT_CH] = CONV2_BIAS;
static q7_t conv3_wt[CONV3_IN_CH*CONV3_KER_DIM*CONV3_KER_DIM*CONV3_OUT_CH] = CONV3_WT;
static q7_t conv3_bias[CONV3_OUT_CH] = CONV3_BIAS;
static q7_t ip1_wt[IP1_IN_DIM*IP1_OUT_DIM] = IP1_WT;
static q7_t ip1_bias[IP1_OUT_DIM] = IP1_BIAS;
//Add input_data and output_data in top main.cpp file
//uint8_t input_data[DATA_OUT_CH*DATA_OUT_DIM*DATA_OUT_DIM];
//q7_t output_data[IP1_OUT_DIM];
q7_t col_buffer[6400];
q7_t scratch_buffer[40960];
void mean_subtract(q7_t* image_data) {
for(int i=0; i<DATA_OUT_CH*DATA_OUT_DIM*DATA_OUT_DIM; i++) {
image_data[i] = (q7_t)__SSAT( ((int)(image_data[i] - mean[i]) >> DATA_RSHIFT), 8);
}
}
void run_nn(q7_t* input_data, q7_t* output_data) {
q7_t* buffer1 = scratch_buffer;
q7_t* buffer2 = buffer1 + 32768;
mean_subtract(input_data);
arm_convolve_HWC_q7_RGB(input_data, CONV1_IN_DIM, CONV1_IN_CH, conv1_wt, CONV1_OUT_CH, CONV1_KER_DIM, CONV1_PAD, CONV1_STRIDE, conv1_bias, CONV1_BIAS_LSHIFT, CONV1_OUT_RSHIFT, buffer1, CONV1_OUT_DIM, (q15_t*)col_buffer, NULL);
arm_maxpool_q7_HWC(buffer1, POOL1_IN_DIM, POOL1_IN_CH, POOL1_KER_DIM, POOL1_PAD, POOL1_STRIDE, POOL1_OUT_DIM, col_buffer, buffer2);
arm_relu_q7(buffer2, RELU1_OUT_DIM*RELU1_OUT_DIM*RELU1_OUT_CH);
arm_convolve_HWC_q7_fast(buffer2, CONV2_IN_DIM, CONV2_IN_CH, conv2_wt, CONV2_OUT_CH, CONV2_KER_DIM, CONV2_PAD, CONV2_STRIDE, conv2_bias, CONV2_BIAS_LSHIFT, CONV2_OUT_RSHIFT, buffer1, CONV2_OUT_DIM, (q15_t*)col_buffer, NULL);
arm_relu_q7(buffer1, RELU2_OUT_DIM*RELU2_OUT_DIM*RELU2_OUT_CH);
arm_avepool_q7_HWC(buffer1, POOL2_IN_DIM, POOL2_IN_CH, POOL2_KER_DIM, POOL2_PAD, POOL2_STRIDE, POOL2_OUT_DIM, col_buffer, buffer2);
arm_convolve_HWC_q7_fast(buffer2, CONV3_IN_DIM, CONV3_IN_CH, conv3_wt, CONV3_OUT_CH, CONV3_KER_DIM, CONV3_PAD, CONV3_STRIDE, conv3_bias, CONV3_BIAS_LSHIFT, CONV3_OUT_RSHIFT, buffer1, CONV3_OUT_DIM, (q15_t*)col_buffer, NULL);
arm_relu_q7(buffer1, RELU3_OUT_DIM*RELU3_OUT_DIM*RELU3_OUT_CH);
arm_avepool_q7_HWC(buffer1, POOL3_IN_DIM, POOL3_IN_CH, POOL3_KER_DIM, POOL3_PAD, POOL3_STRIDE, POOL3_OUT_DIM, col_buffer, buffer2);
arm_fully_connected_q7_opt(buffer2, ip1_wt, IP1_IN_DIM, IP1_OUT_DIM, IP1_BIAS_LSHIFT, IP1_OUT_RSHIFT, ip1_bias, output_data, (q15_t*)col_buffer);
}

View File

@ -0,0 +1,12 @@
#ifndef __NN_H__
#define __NN_H__
// #include "mbed.h"
#include "arm_math.h"
#include "parameter.h"
#include "weights.h"
#include "arm_nnfunctions.h"
void run_nn(q7_t* input_data, q7_t* output_data);
#endif

View File

@ -0,0 +1,69 @@
#define DATA_OUT_CH 3
#define DATA_OUT_DIM 32
#define CONV1_IN_DIM 32
#define CONV1_IN_CH 3
#define CONV1_KER_DIM 5
#define CONV1_PAD 2
#define CONV1_STRIDE 1
#define CONV1_OUT_CH 32
#define CONV1_OUT_DIM 32
#define POOL1_IN_DIM 32
#define POOL1_IN_CH 32
#define POOL1_KER_DIM 3
#define POOL1_STRIDE 2
#define POOL1_PAD 0
#define POOL1_OUT_DIM 16
#define RELU1_OUT_CH 32
#define RELU1_OUT_DIM 16
#define CONV2_IN_DIM 16
#define CONV2_IN_CH 32
#define CONV2_KER_DIM 5
#define CONV2_PAD 2
#define CONV2_STRIDE 1
#define CONV2_OUT_CH 32
#define CONV2_OUT_DIM 16
#define RELU2_OUT_CH 32
#define RELU2_OUT_DIM 16
#define POOL2_IN_DIM 16
#define POOL2_IN_CH 32
#define POOL2_KER_DIM 3
#define POOL2_STRIDE 2
#define POOL2_PAD 0
#define POOL2_OUT_DIM 8
#define CONV3_IN_DIM 8
#define CONV3_IN_CH 32
#define CONV3_KER_DIM 5
#define CONV3_PAD 2
#define CONV3_STRIDE 1
#define CONV3_OUT_CH 64
#define CONV3_OUT_DIM 8
#define RELU3_OUT_CH 64
#define RELU3_OUT_DIM 8
#define POOL3_IN_DIM 8
#define POOL3_IN_CH 64
#define POOL3_KER_DIM 3
#define POOL3_STRIDE 2
#define POOL3_PAD 0
#define POOL3_OUT_DIM 4
#define IP1_IN_DIM 1024
#define IP1_OUT_DIM 10
#define DATA_RSHIFT 0
#define CONV1_BIAS_LSHIFT 0
#define CONV1_OUT_RSHIFT 9
#define CONV2_BIAS_LSHIFT 0
#define CONV2_OUT_RSHIFT 9
#define CONV3_BIAS_LSHIFT 0
#define CONV3_OUT_RSHIFT 9
#define IP1_BIAS_LSHIFT 3
#define IP1_OUT_RSHIFT 5

File diff suppressed because one or more lines are too long

View File

@ -1,8 +0,0 @@
config FACE_DETECT
bool "enable apps/face detect"
depends on BOARD_K210_EVB
depends on DRV_USING_OV2640
depends on USING_KPU_POSTPROCESSING
depends on USING_YOLOV2
select LIB_USING_CJSON
default n

View File

@ -1,373 +0,0 @@
#include <transform.h>
#ifdef LIB_USING_CJSON
#include <cJSON.h>
#endif
#include "region_layer.h"
#define ANCHOR_NUM 5
#define STACK_SIZE (128 * 1024)
#define JSON_FILE_PATH "/kmodel/detect.json"
#define JSON_BUFFER_SIZE (4 * 1024)
// params from json
static float anchor[ANCHOR_NUM * 2] = {};
static int net_output_shape[3] = {};
static int net_input_size[2] = {};
static int sensor_output_size[2] = {};
static char kmodel_path[127] = "";
static int kmodel_size = 0;
static float obj_thresh[20] = {};
static float nms_thresh = 0.0;
static char labels[20][32] = {};
static int class_num = 0;
#define THREAD_PRIORITY_FACE_D (11)
static pthread_t facetid = 0;
static void *thread_face_detcet_entry(void *parameter);
static int g_fd = 0;
static int kmodel_fd = 0;
static int if_exit = 0;
static unsigned char *showbuffer = NULL;
static unsigned char *kpurgbbuffer = NULL;
static _ioctl_shoot_para shoot_para_t = {0};
unsigned char *model_data = NULL; // kpu data load memory
unsigned char *model_data_align = NULL;
kpu_model_context_t face_detect_task;
static region_layer_t face_detect_rl;
static obj_info_t face_detect_info;
volatile uint32_t g_ai_done_flag;
static void ai_done(void *ctx) { g_ai_done_flag = 1; }
static void param_parse()
{
int fin;
char buffer[JSON_BUFFER_SIZE] = "";
// char *buffer;
// if (NULL != (buffer = (char*)malloc(JSON_BUFFER_SIZE * sizeof(char)))) {
// memset(buffer, 0, JSON_BUFFER_SIZE * sizeof(char));
// } else {
// printf("Json buffer malloc failed!");
// exit(-1);
// }
int array_size;
cJSON *json_obj;
cJSON *json_item;
cJSON *json_array_item;
fin = open(JSON_FILE_PATH, O_RDONLY);
if (!fin) {
printf("Error open file %s", JSON_FILE_PATH);
exit(-1);
}
read(fin, buffer, sizeof(buffer));
close(fin);
// read json string
json_obj = cJSON_Parse(buffer);
// free(buffer);
char *json_print_str = cJSON_Print(json_obj);
printf("Json file content: \n%s\n", json_print_str);
cJSON_free(json_print_str);
// get anchors
json_item = cJSON_GetObjectItem(json_obj, "anchors");
array_size = cJSON_GetArraySize(json_item);
if (ANCHOR_NUM * 2 != array_size) {
printf("Expect anchor size: %d, got %d in json file", ANCHOR_NUM * 2, array_size);
exit(-1);
} else {
printf("Got %d anchors from json file\n", ANCHOR_NUM);
}
for (int i = 0; i < ANCHOR_NUM * 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
anchor[i] = json_array_item->valuedouble;
printf("%d: %f\n", i, anchor[i]);
}
// net_input_size
json_item = cJSON_GetObjectItem(json_obj, "net_input_size");
array_size = cJSON_GetArraySize(json_item);
if (2 != array_size) {
printf("Expect net_input_size: %d, got %d in json file", 2, array_size);
exit(-1);
} else {
printf("Got %d net_input_size from json file\n", 2);
}
for (int i = 0; i < 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
net_input_size[i] = json_array_item->valueint;
printf("%d: %d\n", i, net_input_size[i]);
}
// net_output_shape
json_item = cJSON_GetObjectItem(json_obj, "net_output_shape");
array_size = cJSON_GetArraySize(json_item);
if (3 != array_size) {
printf("Expect net_output_shape: %d, got %d in json file", 3, array_size);
exit(-1);
} else {
printf("Got %d net_output_shape from json file\n", 3);
}
for (int i = 0; i < 3; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
net_output_shape[i] = json_array_item->valueint;
printf("%d: %d\n", i, net_output_shape[i]);
}
// sensor_output_size
json_item = cJSON_GetObjectItem(json_obj, "sensor_output_size");
array_size = cJSON_GetArraySize(json_item);
if (2 != array_size) {
printf("Expect sensor_output_size: %d, got %d in json file", 2, array_size);
exit(-1);
} else {
printf("Got %d sensor_output_size from json file\n", 2);
}
for (int i = 0; i < 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
sensor_output_size[i] = json_array_item->valueint;
printf("%d: %d\n", i, sensor_output_size[i]);
}
// kmodel_path
json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
memcpy(kmodel_path, json_item->valuestring, strlen(json_item->valuestring));
printf("Got kmodel_path: %s\n", kmodel_path);
// kmodel_size
json_item = cJSON_GetObjectItem(json_obj, "kmodel_size");
kmodel_size = json_item->valueint;
printf("Got kmodel_size: %d\n", kmodel_size);
// labels
json_item = cJSON_GetObjectItem(json_obj, "labels");
class_num = cJSON_GetArraySize(json_item);
if (0 >= class_num) {
printf("No labels!");
exit(-1);
} else {
printf("Got %d labels\n", class_num);
}
for (int i = 0; i < class_num; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
memcpy(labels[i], json_array_item->valuestring, strlen(json_array_item->valuestring));
printf("%d: %s\n", i, labels[i]);
}
// obj_thresh
json_item = cJSON_GetObjectItem(json_obj, "obj_thresh");
array_size = cJSON_GetArraySize(json_item);
if (class_num != array_size) {
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", class_num, array_size);
exit(-1);
} else {
printf("Got %d obj_thresh\n", array_size);
}
for (int i = 0; i < array_size; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
obj_thresh[i] = json_array_item->valuedouble;
printf("%d: %f\n", i, obj_thresh[i]);
}
// nms_thresh
json_item = cJSON_GetObjectItem(json_obj, "nms_thresh");
nms_thresh = json_item->valuedouble;
printf("Got nms_thresh: %f\n", nms_thresh);
cJSON_Delete(json_obj);
return;
}
void face_detect()
{
int ret = 0;
int result = 0;
int size = 0;
param_parse();
g_fd = open("/dev/ov2640", O_RDONLY);
if (g_fd < 0) {
printf("open ov2640 fail !!");
return;
}
_ioctl_set_dvp_reso set_dvp_reso = {sensor_output_size[1], sensor_output_size[0]};
ioctl(g_fd, IOCTRL_CAMERA_SET_DVP_RESO, &set_dvp_reso);
showbuffer = (unsigned char *)malloc(sensor_output_size[0] * sensor_output_size[1] * 2);
if (NULL == showbuffer) {
close(g_fd);
printf("showbuffer apply memory fail !!");
return;
}
kpurgbbuffer = (unsigned char *)malloc(net_input_size[0] * net_input_size[1] * 3);
if (NULL == kpurgbbuffer) {
close(g_fd);
free(showbuffer);
printf("kpurgbbuffer apply memory fail !!");
return;
}
model_data = (unsigned char *)malloc(kmodel_size + 255);
if (NULL == model_data) {
free(showbuffer);
free(kpurgbbuffer);
close(g_fd);
printf("model_data apply memory fail !!");
return;
}
memset(model_data, 0, kmodel_size + 255);
memset(showbuffer, 0, sensor_output_size[0] * sensor_output_size[1] * 2);
memset(kpurgbbuffer, 0, net_input_size[0] * net_input_size[1] * 3);
shoot_para_t.pdata = (unsigned int *)(showbuffer);
shoot_para_t.length = (size_t)(sensor_output_size[0] * sensor_output_size[1] * 2);
/*
load memory
*/
kmodel_fd = open(kmodel_path, O_RDONLY);
if (kmodel_fd < 0) {
printf("open kmodel fail");
close(g_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
} else {
size = read(kmodel_fd, model_data, kmodel_size);
if (size != kmodel_size) {
printf("read kmodel error size %d\n", size);
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
} else {
printf("read kmodel success \n");
}
}
unsigned char *model_data_align = (unsigned char *)(((unsigned int)model_data + 255) & (~255));
dvp_set_ai_addr((uint32_t)kpurgbbuffer, (uint32_t)(kpurgbbuffer + net_input_size[0] * net_input_size[1]),
(uint32_t)(kpurgbbuffer + net_input_size[0] * net_input_size[1] * 2));
if (kpu_load_kmodel(&face_detect_task, model_data_align) != 0) {
printf("\nmodel init error\n");
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
}
face_detect_rl.anchor_number = ANCHOR_NUM;
face_detect_rl.anchor = anchor;
face_detect_rl.threshold = malloc(class_num * sizeof(float));
for (int idx = 0; idx < class_num; idx++) {
face_detect_rl.threshold[idx] = obj_thresh[idx];
}
face_detect_rl.nms_value = nms_thresh;
result = region_layer_init(&face_detect_rl, net_output_shape[0], net_output_shape[1], net_output_shape[2],
net_input_size[1], net_input_size[0]);
printf("region_layer_init result %d \n\r", result);
size_t stack_size = STACK_SIZE;
pthread_attr_t attr; /* 线程属性 */
struct sched_param prio; /* 线程优先级 */
prio.sched_priority = 8; /* 优先级设置为 8 */
pthread_attr_init(&attr); /* 先使用默认值初始化属性 */
pthread_attr_setschedparam(&attr, &prio); /* 修改属性对应的优先级 */
pthread_attr_setstacksize(&attr, stack_size);
/* 创建线程 1, 属性为 attr入口函数是 thread_entry入口函数参数是 1 */
result = pthread_create(&facetid, &attr, thread_face_detcet_entry, NULL);
if (0 == result) {
printf("thread_face_detcet_entry successfully!\n");
} else {
printf("thread_face_detcet_entry failed! error code is %d\n", result);
close(g_fd);
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(face_detect, face detect task);
#endif
static void *thread_face_detcet_entry(void *parameter)
{
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr);
printf("thread_face_detcet_entry start!\n");
int ret = 0;
// sysctl_enable_irq();
while (1) {
// memset(showbuffer,0,320*240*2);
g_ai_done_flag = 0;
ret = ioctl(g_fd, IOCTRL_CAMERA_START_SHOT, &shoot_para_t);
if (RT_ERROR == ret) {
printf("ov2640 can't wait event flag");
rt_free(showbuffer);
close(g_fd);
pthread_exit(NULL);
return NULL;
}
kpu_run_kmodel(&face_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
while (!g_ai_done_flag)
;
float *output;
size_t output_size;
kpu_get_output(&face_detect_task, 0, (uint8_t **)&output, &output_size);
face_detect_rl.input = output;
region_layer_run(&face_detect_rl, &face_detect_info);
/* display result */
#ifdef BSP_USING_LCD
for (int face_cnt = 0; face_cnt < face_detect_info.obj_number; face_cnt++) {
draw_edge((uint32_t *)showbuffer, &face_detect_info, face_cnt, 0xF800, (uint16_t)sensor_output_size[1],
(uint16_t)sensor_output_size[0]);
printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", face_cnt, face_detect_info.obj[face_cnt].x1,
face_detect_info.obj[face_cnt].y1, face_detect_info.obj[face_cnt].x2, face_detect_info.obj[face_cnt].y2,
labels[face_detect_info.obj[face_cnt].class_id], face_detect_info.obj[face_cnt].prob);
}
if (0 != face_detect_info.obj_number) printf("\n");
lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer);
#endif
usleep(1);
if (1 == if_exit) {
if_exit = 0;
printf("thread_face_detcet_entry exit");
pthread_exit(NULL);
}
}
}
void face_detect_delete()
{
if (showbuffer != NULL) {
int ret = 0;
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
printf("face detect task cancel!!! ret %d ", ret);
if_exit = 1;
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(face_detect_delete, face detect task delete);
#endif
void kmodel_load(unsigned char *model_data)
{
int kmodel_fd = 0;
int size = 0;
kmodel_fd = open(kmodel_path, O_RDONLY);
model_data = (unsigned char *)malloc(kmodel_size + 255);
if (NULL == model_data) {
printf("model_data apply memory fail !!");
return;
}
memset(model_data, 0, kmodel_size + 255);
if (kmodel_fd >= 0) {
size = read(kmodel_fd, model_data, kmodel_size);
if (size != kmodel_size) {
printf("read kmodel error size %d\n", size);
} else {
printf("read kmodel success");
}
} else {
free(model_data);
printf("open kmodel fail");
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(kmodel_load, kmodel load memory);
#endif

View File

@ -1,8 +0,0 @@
config HELMET_DETECT
bool "enable apps/helmet detect"
depends on BOARD_K210_EVB
depends on DRV_USING_OV2640
depends on USING_KPU_POSTPROCESSING
depends on USING_YOLOV2
select LIB_USING_CJSON
default n

View File

@ -1,167 +0,0 @@
# Helmet detection demo
### A helmet and head without helmet object detection task demo. Running MobileNet-yolo on K210-based edge devices.
---
## Training
### Enviroment preparation
Model generated by [aXeleRate](https://forgeplus.trustie.net/projects/yangtuo250/aXeleRate) and converted to kmodel by [nncase](https://github.com/kendryte/nncase/tree/v0.1.0-rc5).
```shell
# master branch for MobileNetv1-yolov2 and unstable branch to test MobileNetv1(v2)-yolov2(v3)
git clone https://git.trustie.net/yangtuo250/aXeleRate.git (-b unstable)
cd aXeleRate
pip install -r requirments.txt && pip install -e .
```
### training config setting
Example [config](https://forgeplus.trustie.net/projects/yangtuo250/aXeleRate/tree/master/configs/detector.json), some hyper-parameters:
- architecture: backbone, MobileNet7_5 for default, MobileNet1_0(α = 1.0) and above cannot run on K210 because of OOM on feature map in master branch. For unstable branch MobileNetV2_1_0 is OK.
- input_size: fixed model input size, single integer for height equals to width, otherwise a list([height, width]).
- anchors: yolov2 anchor(for master) or anchor scaled to 1.0(for unstable), can be generate by [darknet](https://github.com/AlexeyAB/darknet).
- labels: labels of all classes.
- train(valid)_image(annot)_folder: path of images and annoations for training and validation.
- saved_folder: path for trainig result storage(models, checkpoints, logs ...).
Mine config for unstable:
```json
{
"model": {
"type": "Detector",
"architecture": "MobileNetV2_1_0",
"input_size": [
224,
320
],
"anchors": [
[
[
0.1043,
0.1560
],
[
0.0839,
0.3036
],
[
0.1109,
0.3923
],
[
0.1378,
0.5244
],
[
0.2049,
0.6673
]
]
],
"labels": [
"human"
],
"obj_thresh": 0.5,
"iou_thresh": 0.45,
"coord_scale": 1.0,
"class_scale": 0.0,
"object_scale": 5.0,
"no_object_scale": 3.0
},
"weights": {
"full": "",
"backend": ""
},
"train": {
"actual_epoch": 2000,
"train_image_folder": "mydata/human/Images/train",
"train_annot_folder": "mydata/human/Annotations/train",
"train_times": 2,
"valid_image_folder": "mydata/human/Images/val",
"valid_annot_folder": "mydata/human/Annotations/val",
"valid_times": 1,
"valid_metric": "precision",
"batch_size": 32,
"learning_rate": 2e-5,
"saved_folder": "mydata/human/results",
"first_trainable_layer": "",
"augmentation": true,
"is_only_detect": false,
"validation_freq": 5,
"quantize": false,
"class_weights": [1.0]
},
"converter": {
"type": [
"k210"
]
}
}
```
*(For more detailed config usage, please refer to original aXeleRate repo.)*
### data preparation
Please refer to [VOC format](https://towardsdatascience.com/coco-data-format-for-object-detection-a4c5eaf518c5), path as config above.
### train it!
```shell
python -m aXeleRate.train -c PATH_TO_YOUR_CONFIG
```
### model convert
Please refer to [nncase repo](https://github.com/kendryte/nncase/tree/v0.1.0-rc5).
---
## Deployment
### compile and burn
Use `(scons --)menuconfig` in bsp folder *(Ubiquitous/RT_Thread/bsp/k210)*, open:
- More Drivers --> ov2640 driver
- Board Drivers Config --> Enable LCD on SPI0
- Board Drivers Config --> Enable SDCARD (spi1(ss0))
- Board Drivers Config --> Enable DVP(camera)
- RT-Thread Components --> POSIX layer and C standard library --> Enable pthreads APIs
- APP_Framework --> Framework --> support knowing framework --> kpu model postprocessing --> yolov2 region layer
- APP_Framework --> Applications --> knowing app --> enable apps/helmet detect
`scons -j(n)` to compile and burn in by *kflash*.
### json config and kmodel
Copy json config for deployment o SD card */kmodel*. Example config file is *helmet.json* in this directory. Something to be modified:
- net_input_size: same as *input_size* in training config file, but array only.
- net_output_shape: final feature map size, can be found in **nncase** output.
- sensor_output_size: image height and width from camera.
- kmodel_size: kmodel size shown in file system.
- anchors: same as *anchor* in training config file(multi-dimention anchors flatten to 1 dim).
- labels: same as *label* in training config file.
- obj_thresh: array, object threshold of each label.
- nms_thresh: NMS threshold of boxes.
Copy final kmodel to SD card */kmodel* either.
---
## Run
In serial terminal, `helmet_detect` to start a detection thread, `helmet_detect_delete` to stop it. Detection results can be found in output.
---
## TODO
- [ ] Fix LCD real-time result display.
- [ ] Test more object detection backbone and algorithm(like yolox).

View File

@ -1,380 +0,0 @@
#include <transform.h>
#ifdef LIB_USING_CJSON
#include <cJSON.h>
#endif
#include "region_layer.h"
#define ANCHOR_NUM 5
#define STACK_SIZE (128 * 1024)
#define JSON_FILE_PATH "/kmodel/helmet.json"
#define JSON_BUFFER_SIZE (4 * 1024)
// params from json
static float anchor[ANCHOR_NUM * 2] = {};
static int net_output_shape[3] = {};
static int net_input_size[2] = {};
static int sensor_output_size[2] = {};
static char kmodel_path[127] = "";
static int kmodel_size = 0;
static float obj_thresh[20] = {};
static float nms_thresh = 0.0;
static char labels[20][32] = {};
static int class_num = 0;
#define THREAD_PRIORITY_HELMET_D (11)
static pthread_t helmettid = 0;
static void *thread_helmet_detect_entry(void *parameter);
static int g_fd = 0;
static int kmodel_fd = 0;
static int if_exit = 0;
static unsigned char *showbuffer = NULL;
static unsigned char *kpurgbbuffer = NULL;
static _ioctl_shoot_para shoot_para_t = {0};
unsigned char *model_data = NULL; // kpu data load memory
unsigned char *model_data_align = NULL;
kpu_model_context_t helmet_detect_task;
static region_layer_t helmet_detect_rl;
static obj_info_t helmet_detect_info;
volatile uint32_t g_ai_done_flag;
static void ai_done(void *ctx) { g_ai_done_flag = 1; }
static void param_parse()
{
int fin;
char buffer[JSON_BUFFER_SIZE] = "";
// char *buffer;
// if (NULL != (buffer = (char*)malloc(JSON_BUFFER_SIZE * sizeof(char)))) {
// memset(buffer, 0, JSON_BUFFER_SIZE * sizeof(char));
// } else {
// printf("Json buffer malloc failed!");
// exit(-1);
// }
int array_size;
cJSON *json_obj;
cJSON *json_item;
cJSON *json_array_item;
fin = open(JSON_FILE_PATH, O_RDONLY);
if (!fin) {
printf("Error open file %s", JSON_FILE_PATH);
exit(-1);
}
read(fin, buffer, sizeof(buffer));
close(fin);
// read json string
json_obj = cJSON_Parse(buffer);
// free(buffer);
char *json_print_str = cJSON_Print(json_obj);
printf("Json file content: \n%s\n", json_print_str);
cJSON_free(json_print_str);
// get anchors
json_item = cJSON_GetObjectItem(json_obj, "anchors");
array_size = cJSON_GetArraySize(json_item);
if (ANCHOR_NUM * 2 != array_size) {
printf("Expect anchor size: %d, got %d in json file", ANCHOR_NUM * 2, array_size);
exit(-1);
} else {
printf("Got %d anchors from json file\n", ANCHOR_NUM);
}
for (int i = 0; i < ANCHOR_NUM * 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
anchor[i] = json_array_item->valuedouble;
printf("%d: %f\n", i, anchor[i]);
}
// net_input_size
json_item = cJSON_GetObjectItem(json_obj, "net_input_size");
array_size = cJSON_GetArraySize(json_item);
if (2 != array_size) {
printf("Expect net_input_size: %d, got %d in json file", 2, array_size);
exit(-1);
} else {
printf("Got %d net_input_size from json file\n", 2);
}
for (int i = 0; i < 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
net_input_size[i] = json_array_item->valueint;
printf("%d: %d\n", i, net_input_size[i]);
}
// net_output_shape
json_item = cJSON_GetObjectItem(json_obj, "net_output_shape");
array_size = cJSON_GetArraySize(json_item);
if (3 != array_size) {
printf("Expect net_output_shape: %d, got %d in json file", 3, array_size);
exit(-1);
} else {
printf("Got %d net_output_shape from json file\n", 3);
}
for (int i = 0; i < 3; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
net_output_shape[i] = json_array_item->valueint;
printf("%d: %d\n", i, net_output_shape[i]);
}
// sensor_output_size
json_item = cJSON_GetObjectItem(json_obj, "sensor_output_size");
array_size = cJSON_GetArraySize(json_item);
if (2 != array_size) {
printf("Expect sensor_output_size: %d, got %d in json file", 2, array_size);
exit(-1);
} else {
printf("Got %d sensor_output_size from json file\n", 2);
}
for (int i = 0; i < 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
sensor_output_size[i] = json_array_item->valueint;
printf("%d: %d\n", i, sensor_output_size[i]);
}
// kmodel_path
json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
memcpy(kmodel_path, json_item->valuestring, strlen(json_item->valuestring));
printf("Got kmodel_path: %s\n", kmodel_path);
// kmodel_size
json_item = cJSON_GetObjectItem(json_obj, "kmodel_size");
kmodel_size = json_item->valueint;
printf("Got kmodel_size: %d\n", kmodel_size);
// labels
json_item = cJSON_GetObjectItem(json_obj, "labels");
class_num = cJSON_GetArraySize(json_item);
if (0 >= class_num) {
printf("No labels!");
exit(-1);
} else {
printf("Got %d labels\n", class_num);
}
for (int i = 0; i < class_num; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
memcpy(labels[i], json_array_item->valuestring, strlen(json_array_item->valuestring));
printf("%d: %s\n", i, labels[i]);
}
// obj_thresh
json_item = cJSON_GetObjectItem(json_obj, "obj_thresh");
array_size = cJSON_GetArraySize(json_item);
if (class_num != array_size) {
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", class_num, array_size);
exit(-1);
} else {
printf("Got %d obj_thresh\n", array_size);
}
for (int i = 0; i < array_size; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
obj_thresh[i] = json_array_item->valuedouble;
printf("%d: %f\n", i, obj_thresh[i]);
}
// nms_thresh
json_item = cJSON_GetObjectItem(json_obj, "nms_thresh");
nms_thresh = json_item->valuedouble;
printf("Got nms_thresh: %f\n", nms_thresh);
cJSON_Delete(json_obj);
return;
}
void helmet_detect()
{
int ret = 0;
int result = 0;
int size = 0;
param_parse();
g_fd = open("/dev/ov2640", O_RDONLY);
if (g_fd < 0) {
printf("open ov2640 fail !!");
return;
}
_ioctl_set_dvp_reso set_dvp_reso = {sensor_output_size[1], sensor_output_size[0]};
ioctl(g_fd, IOCTRL_CAMERA_SET_DVP_RESO, &set_dvp_reso);
showbuffer = (unsigned char *)malloc(sensor_output_size[0] * sensor_output_size[1] * 2);
if (NULL == showbuffer) {
close(g_fd);
printf("showbuffer apply memory fail !!");
return;
}
kpurgbbuffer = (unsigned char *)malloc(net_input_size[0] * net_input_size[1] * 3);
if (NULL == kpurgbbuffer) {
close(g_fd);
free(showbuffer);
printf("kpurgbbuffer apply memory fail !!");
return;
}
model_data = (unsigned char *)malloc(kmodel_size + 255);
if (NULL == model_data) {
free(showbuffer);
free(kpurgbbuffer);
close(g_fd);
printf("model_data apply memory fail !!");
return;
}
memset(model_data, 0, kmodel_size + 255);
memset(showbuffer, 0, sensor_output_size[0] * sensor_output_size[1] * 2);
memset(kpurgbbuffer, 127, net_input_size[0] * net_input_size[1] * 3);
shoot_para_t.pdata = (unsigned int *)(showbuffer);
shoot_para_t.length = (size_t)(sensor_output_size[0] * sensor_output_size[1] * 2);
/*
load memory
*/
kmodel_fd = open(kmodel_path, O_RDONLY);
if (kmodel_fd < 0) {
printf("open kmodel fail");
close(g_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
} else {
size = read(kmodel_fd, model_data, kmodel_size);
if (size != kmodel_size) {
printf("read kmodel error size %d\n", size);
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
} else {
printf("read kmodel success \n");
}
}
unsigned char *model_data_align = (unsigned char *)(((unsigned int)model_data + 255) & (~255));
dvp_set_ai_addr((uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0])),
(uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0]) +
net_input_size[0] * net_input_size[1]),
(uint32_t)(kpurgbbuffer + net_input_size[0] * net_input_size[1] * 2 +
net_input_size[1] * (net_input_size[0] - sensor_output_size[0])));
if (kpu_load_kmodel(&helmet_detect_task, model_data_align) != 0) {
printf("\nmodel init error\n");
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
}
helmet_detect_rl.anchor_number = ANCHOR_NUM;
helmet_detect_rl.anchor = anchor;
helmet_detect_rl.threshold = malloc(class_num * sizeof(float));
for (int idx = 0; idx < class_num; idx++) {
helmet_detect_rl.threshold[idx] = obj_thresh[idx];
}
helmet_detect_rl.nms_value = nms_thresh;
result = region_layer_init(&helmet_detect_rl, net_output_shape[0], net_output_shape[1], net_output_shape[2],
net_input_size[1], net_input_size[0]);
printf("region_layer_init result %d \n\r", result);
size_t stack_size = STACK_SIZE;
pthread_attr_t attr; /* 线程属性 */
struct sched_param prio; /* 线程优先级 */
prio.sched_priority = 8; /* 优先级设置为 8 */
pthread_attr_init(&attr); /* 先使用默认值初始化属性 */
pthread_attr_setschedparam(&attr, &prio); /* 修改属性对应的优先级 */
pthread_attr_setstacksize(&attr, stack_size);
/* 创建线程 1, 属性为 attr入口函数是 thread_entry入口函数参数是 1 */
result = pthread_create(&helmettid, &attr, thread_helmet_detect_entry, NULL);
if (0 == result) {
printf("thread_helmet_detect_entry successfully!\n");
} else {
printf("thread_helmet_detect_entry failed! error code is %d\n", result);
close(g_fd);
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(helmet_detect, helmet detect task);
#endif
static void *thread_helmet_detect_entry(void *parameter)
{
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr);
printf("thread_helmet_detect_entry start!\n");
int ret = 0;
// sysctl_enable_irq();
while (1) {
// memset(showbuffer,0,320*240*2);
g_ai_done_flag = 0;
ret = ioctl(g_fd, IOCTRL_CAMERA_START_SHOT, &shoot_para_t);
if (RT_ERROR == ret) {
printf("ov2640 can't wait event flag");
rt_free(showbuffer);
close(g_fd);
pthread_exit(NULL);
return NULL;
}
kpu_run_kmodel(&helmet_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
while (!g_ai_done_flag)
;
float *output;
size_t output_size;
kpu_get_output(&helmet_detect_task, 0, (uint8_t **)&output, &output_size);
helmet_detect_rl.input = output;
region_layer_run(&helmet_detect_rl, &helmet_detect_info);
/* display result */
#ifdef BSP_USING_LCD
for (int helmet_cnt = 0; helmet_cnt < helmet_detect_info.obj_number; helmet_cnt++) {
// draw_edge((uint32_t *)showbuffer, &helmet_detect_info, helmet_cnt, 0xF800,
// (uint16_t)sensor_output_size[1],
// (uint16_t)sensor_output_size[0]);
printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", helmet_cnt, helmet_detect_info.obj[helmet_cnt].x1,
helmet_detect_info.obj[helmet_cnt].y1, helmet_detect_info.obj[helmet_cnt].x2,
helmet_detect_info.obj[helmet_cnt].y2, labels[helmet_detect_info.obj[helmet_cnt].class_id],
helmet_detect_info.obj[helmet_cnt].prob);
}
if (0 != helmet_detect_info.obj_number) {
printf("\n");
}
lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer);
#endif
usleep(1);
if (1 == if_exit) {
if_exit = 0;
printf("thread_helmet_detect_entry exit");
pthread_exit(NULL);
}
}
}
void helmet_detect_delete()
{
if (showbuffer != NULL) {
int ret = 0;
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
printf("helmet detect task cancel!!! ret %d ", ret);
if_exit = 1;
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(helmet_detect_delete, helmet detect task delete);
#endif
void kmodel_load(unsigned char *model_data)
{
int kmodel_fd = 0;
int size = 0;
kmodel_fd = open(kmodel_path, O_RDONLY);
model_data = (unsigned char *)malloc(kmodel_size + 255);
if (NULL == model_data) {
printf("model_data apply memory fail !!");
return;
}
memset(model_data, 0, kmodel_size + 255);
if (kmodel_fd >= 0) {
size = read(kmodel_fd, model_data, kmodel_size);
if (size != kmodel_size) {
printf("read kmodel error size %d\n", size);
} else {
printf("read kmodel success");
}
} else {
free(model_data);
printf("open kmodel fail");
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(kmodel_load, kmodel load memory);
#endif

View File

@ -0,0 +1,6 @@
menuconfig USING_IMAGE_PROCESSING_APP
bool "image processing app "
default n
if USING_IMAGE_PROCESSING_APP
source "$APP_DIR/Applications/knowing_app/image_processing/TJpgDec_APP/Kconfig"
endif

View File

@ -0,0 +1,14 @@
import os
Import('RTT_ROOT')
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(path, 'SConscript'))
Return('objs')

View File

@ -0,0 +1,4 @@
config IMAGE_PROCESSING_TJPGDEC_APP
bool "image processing apps/TJpgDec(example)"
select IMAGE_PROCESSING_USING_TJPGD
default n

View File

@ -1,9 +1,9 @@
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = ['INSTRUSION_DETECT'], LOCAL_CPPPATH = CPPPATH)
Return('group')
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('TJpgDec(example)', src, depend = ['IMAGE_PROCESSING_TJPGDEC_APP'], LOCAL_CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,151 @@
#include <transform.h>
#include <tjpgd.h>
#define WORK_POOL_SIZE (4*1024+32)//This value depends on the resolution of the image
/* User defined device identifier */
typedef struct {
FILE *fp; /* File pointer for input function */
uint8_t *fbuf; /* Pointer to the frame buffer for output function */
uint16_t wfbuf; /* Width of the frame buffer [pix] */
} IODEV;
/*------------------------------*/
/* User defined input funciton */
/*------------------------------*/
unsigned int in_func (JDEC* jd, uint8_t* buff, unsigned int nbyte)
{
IODEV *dev = (IODEV*)jd->device; /* Device identifier for the session (5th argument of jd_prepare function) */
if (buff) {
/* Read bytes from input stream */
return (uint16_t)fread(buff, 1, nbyte, dev->fp);
} else {
/* Remove bytes from input stream */
return fseek(dev->fp, nbyte, SEEK_CUR) ? 0 : nbyte;
}
}
/*------------------------------*/
/* User defined output funciton */
/*------------------------------*/
int out_func (JDEC* jd, void* bitmap, JRECT* rect)
{
IODEV *dev = (IODEV*)jd->device;
uint8_t *src, *dst;
uint16_t y, bws, bwd;
/* Put progress indicator */
if (rect->left == 0) {
printf("\r%lu%%", (rect->top << jd->scale) * 100UL / jd->height);
}
/* Copy the decompressed RGB rectanglar to the frame buffer (assuming RGB888 cfg) */
src = (uint8_t*)bitmap;
dst = dev->fbuf + 3 * (rect->top * dev->wfbuf + rect->left); /* Left-top of destination rectangular */
bws = 3 * (rect->right - rect->left + 1); /* Width of source rectangular [byte] */
bwd = 3 * dev->wfbuf; /* Width of frame buffer [byte] */
for (y = rect->top; y <= rect->bottom; y++) {
memcpy(dst, src, bws); /* Copy a line */
src += bws; dst += bwd; /* Next line */
}
return 1; /* Continue to decompress */
}
/*------------------------------*/
/* Program Jpeg_Dec */
/*------------------------------*/
int Jpeg_Dec (int argc, char* argv[])
{
void *work; /* Pointer to the decompressor work area */
JDEC jdec; /* Decompression object */
JRESULT res; /* Result code of TJpgDec API */
IODEV devid; /* User defined device identifier */
/* Open a JPEG file */
if (argc < 2)
{
printf("Jpeg_Dec illegal arguments ...\n");
return -1;
}
devid.fp = fopen(argv[1], "r+");
if (!devid.fp)
{
printf("Jpeg_Dec open the file failed...\n");
return -1;
}
/* Allocate a work area for TJpgDec */
work = malloc(WORK_POOL_SIZE);
if(work == NULL)
{
printf("Jpeg_Dec work malloc failed...\n");
res = -1;
goto __exit;
}
/* Prepare to decompress */
res = jd_prepare(&jdec, in_func, work, WORK_POOL_SIZE, &devid);
if (res == JDR_OK)
{
/* Ready to dcompress. Image info is available here. */
printf("Image dimensions: %u by %u. %u bytes used.\n", jdec.width, jdec.height, 3100 - jdec.sz_pool);
devid.fbuf = malloc(3 * jdec.width * jdec.height); /* Frame buffer for output image (assuming RGB888 cfg) */
if(devid.fbuf == RT_NULL)
{
printf("Jpeg_Dec devid.fbuf malloc failed, need to use %d Bytes ...\n", 3 * jdec.width * jdec.height);
res = -1;
goto __exit;
}
devid.wfbuf = jdec.width;
res = jd_decomp(&jdec, out_func, 0); /* Start to decompress with 1/1 scaling */
if (res == JDR_OK) {
/* Decompression succeeded. You have the decompressed image in the frame buffer here. */
printf("\rOK \n");
// for(int j = 0; j<3 * jdec.width * jdec.height;j++)
// {
// printf("%d,",*(devid.fbuf+j));
// }
}
else
{
printf("Failed to decompress: rc=%d\n", res);
}
if(devid.fbuf != NULL)
{
free(devid.fbuf); /* Discard frame buffer */
}
}
else
{
printf("Failed to prepare: rc=%d\n", res);
}
__exit:
if(work != NULL)
{
free(work); /* Discard work area */
}
fclose(devid.fp); /* Close the JPEG file */
return res;
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(Jpeg_Dec, Jpeg Decode Test);
#endif

View File

@ -1,8 +0,0 @@
config INSTRUSION_DETECT
bool "enable apps/instrusion detect"
depends on BOARD_K210_EVB
depends on DRV_USING_OV2640
depends on USING_KPU_POSTPROCESSING
depends on USING_YOLOV2
select LIB_USING_CJSON
default n

View File

@ -1,5 +0,0 @@
# Instrusion detect demo
### A human object detection task demo. Running MobileNet-yolo on K210-based edge devices.
***Training, deployment and running, please see helmet_detect***

View File

@ -1,381 +0,0 @@
#include <transform.h>
#ifdef LIB_USING_CJSON
#include <cJSON.h>
#endif
#include "region_layer.h"
#define ANCHOR_NUM 5
#define STACK_SIZE (128 * 1024)
#define JSON_FILE_PATH "/kmodel/human.json"
#define JSON_BUFFER_SIZE (4 * 1024)
// params from json
static float anchor[ANCHOR_NUM * 2] = {};
static int net_output_shape[3] = {};
static int net_input_size[2] = {};
static int sensor_output_size[2] = {};
static char kmodel_path[127] = "";
static int kmodel_size = 0;
static float obj_thresh[20] = {};
static float nms_thresh = 0.0;
static char labels[20][32] = {};
static int class_num = 0;
#define THREAD_PRIORITY_HUMAN_D (11)
static pthread_t instrusiontid = 0;
static void *thread_instrusion_detect_entry(void *parameter);
static int g_fd = 0;
static int kmodel_fd = 0;
static int if_exit = 0;
static unsigned char *showbuffer = NULL;
static unsigned char *kpurgbbuffer = NULL;
static _ioctl_shoot_para shoot_para_t = {0};
unsigned char *model_data = NULL; // kpu data load memory
unsigned char *model_data_align = NULL;
kpu_model_context_t instrusion_detect_task;
static region_layer_t instrusion_detect_rl;
static obj_info_t instrusion_detect_info;
volatile uint32_t g_ai_done_flag;
static void ai_done(void *ctx) { g_ai_done_flag = 1; }
static void param_parse()
{
int fin;
char buffer[JSON_BUFFER_SIZE] = "";
// char *buffer;
// if (NULL != (buffer = (char*)malloc(JSON_BUFFER_SIZE * sizeof(char)))) {
// memset(buffer, 0, JSON_BUFFER_SIZE * sizeof(char));
// } else {
// printf("Json buffer malloc failed!");
// exit(-1);
// }
int array_size;
cJSON *json_obj;
cJSON *json_item;
cJSON *json_array_item;
fin = open(JSON_FILE_PATH, O_RDONLY);
if (!fin) {
printf("Error open file %s", JSON_FILE_PATH);
exit(-1);
}
read(fin, buffer, sizeof(buffer));
close(fin);
// read json string
json_obj = cJSON_Parse(buffer);
// free(buffer);
char *json_print_str = cJSON_Print(json_obj);
printf("Json file content: \n%s\n", json_print_str);
cJSON_free(json_print_str);
// get anchors
json_item = cJSON_GetObjectItem(json_obj, "anchors");
array_size = cJSON_GetArraySize(json_item);
if (ANCHOR_NUM * 2 != array_size) {
printf("Expect anchor size: %d, got %d in json file", ANCHOR_NUM * 2, array_size);
exit(-1);
} else {
printf("Got %d anchors from json file\n", ANCHOR_NUM);
}
for (int i = 0; i < ANCHOR_NUM * 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
anchor[i] = json_array_item->valuedouble;
printf("%d: %f\n", i, anchor[i]);
}
// net_input_size
json_item = cJSON_GetObjectItem(json_obj, "net_input_size");
array_size = cJSON_GetArraySize(json_item);
if (2 != array_size) {
printf("Expect net_input_size: %d, got %d in json file", 2, array_size);
exit(-1);
} else {
printf("Got %d net_input_size from json file\n", 2);
}
for (int i = 0; i < 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
net_input_size[i] = json_array_item->valueint;
printf("%d: %d\n", i, net_input_size[i]);
}
// net_output_shape
json_item = cJSON_GetObjectItem(json_obj, "net_output_shape");
array_size = cJSON_GetArraySize(json_item);
if (3 != array_size) {
printf("Expect net_output_shape: %d, got %d in json file", 3, array_size);
exit(-1);
} else {
printf("Got %d net_output_shape from json file\n", 3);
}
for (int i = 0; i < 3; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
net_output_shape[i] = json_array_item->valueint;
printf("%d: %d\n", i, net_output_shape[i]);
}
// sensor_output_size
json_item = cJSON_GetObjectItem(json_obj, "sensor_output_size");
array_size = cJSON_GetArraySize(json_item);
if (2 != array_size) {
printf("Expect sensor_output_size: %d, got %d in json file", 2, array_size);
exit(-1);
} else {
printf("Got %d sensor_output_size from json file\n", 2);
}
for (int i = 0; i < 2; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
sensor_output_size[i] = json_array_item->valueint;
printf("%d: %d\n", i, sensor_output_size[i]);
}
// kmodel_path
json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
memcpy(kmodel_path, json_item->valuestring, strlen(json_item->valuestring));
printf("Got kmodel_path: %s\n", kmodel_path);
// kmodel_size
json_item = cJSON_GetObjectItem(json_obj, "kmodel_size");
kmodel_size = json_item->valueint;
printf("Got kmodel_size: %d\n", kmodel_size);
// labels
json_item = cJSON_GetObjectItem(json_obj, "labels");
class_num = cJSON_GetArraySize(json_item);
if (0 >= class_num) {
printf("No labels!");
exit(-1);
} else {
printf("Got %d labels\n", class_num);
}
for (int i = 0; i < class_num; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
memcpy(labels[i], json_array_item->valuestring, strlen(json_array_item->valuestring));
printf("%d: %s\n", i, labels[i]);
}
// obj_thresh
json_item = cJSON_GetObjectItem(json_obj, "obj_thresh");
array_size = cJSON_GetArraySize(json_item);
if (class_num != array_size) {
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", class_num, array_size);
exit(-1);
} else {
printf("Got %d obj_thresh\n", array_size);
}
for (int i = 0; i < array_size; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
obj_thresh[i] = json_array_item->valuedouble;
printf("%d: %f\n", i, obj_thresh[i]);
}
// nms_thresh
json_item = cJSON_GetObjectItem(json_obj, "nms_thresh");
nms_thresh = json_item->valuedouble;
printf("Got nms_thresh: %f\n", nms_thresh);
cJSON_Delete(json_obj);
return;
}
void instrusion_detect()
{
int ret = 0;
int result = 0;
int size = 0;
param_parse();
g_fd = open("/dev/ov2640", O_RDONLY);
if (g_fd < 0) {
printf("open ov2640 fail !!");
return;
}
_ioctl_set_dvp_reso set_dvp_reso = {sensor_output_size[1], sensor_output_size[0]};
ioctl(g_fd, IOCTRL_CAMERA_SET_DVP_RESO, &set_dvp_reso);
showbuffer = (unsigned char *)malloc(sensor_output_size[0] * sensor_output_size[1] * 2);
if (NULL == showbuffer) {
close(g_fd);
printf("showbuffer apply memory fail !!");
return;
}
kpurgbbuffer = (unsigned char *)malloc(net_input_size[0] * net_input_size[1] * 3);
if (NULL == kpurgbbuffer) {
close(g_fd);
free(showbuffer);
printf("kpurgbbuffer apply memory fail !!");
return;
}
model_data = (unsigned char *)malloc(kmodel_size + 255);
if (NULL == model_data) {
free(showbuffer);
free(kpurgbbuffer);
close(g_fd);
printf("model_data apply memory fail !!");
return;
}
memset(model_data, 0, kmodel_size + 255);
memset(showbuffer, 0, sensor_output_size[0] * sensor_output_size[1] * 2);
memset(kpurgbbuffer, 127, net_input_size[0] * net_input_size[1] * 3);
shoot_para_t.pdata = (unsigned int *)(showbuffer);
shoot_para_t.length = (size_t)(sensor_output_size[0] * sensor_output_size[1] * 2);
/*
load memory
*/
kmodel_fd = open(kmodel_path, O_RDONLY);
if (kmodel_fd < 0) {
printf("open kmodel fail");
close(g_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
} else {
size = read(kmodel_fd, model_data, kmodel_size);
if (size != kmodel_size) {
printf("read kmodel error size %d\n", size);
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
} else {
printf("read kmodel success \n");
}
}
unsigned char *model_data_align = (unsigned char *)(((unsigned int)model_data + 255) & (~255));
dvp_set_ai_addr((uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0])),
(uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0]) +
net_input_size[0] * net_input_size[1]),
(uint32_t)(kpurgbbuffer + net_input_size[0] * net_input_size[1] * 2 +
net_input_size[1] * (net_input_size[0] - sensor_output_size[0])));
if (kpu_load_kmodel(&instrusion_detect_task, model_data_align) != 0) {
printf("\nmodel init error\n");
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
return;
}
instrusion_detect_rl.anchor_number = ANCHOR_NUM;
instrusion_detect_rl.anchor = anchor;
instrusion_detect_rl.threshold = malloc(class_num * sizeof(float));
for (int idx = 0; idx < class_num; idx++) {
instrusion_detect_rl.threshold[idx] = obj_thresh[idx];
}
instrusion_detect_rl.nms_value = nms_thresh;
result = region_layer_init(&instrusion_detect_rl, net_output_shape[0], net_output_shape[1], net_output_shape[2],
net_input_size[1], net_input_size[0]);
printf("region_layer_init result %d \n\r", result);
size_t stack_size = STACK_SIZE;
pthread_attr_t attr; /* 线程属性 */
struct sched_param prio; /* 线程优先级 */
prio.sched_priority = 8; /* 优先级设置为 8 */
pthread_attr_init(&attr); /* 先使用默认值初始化属性 */
pthread_attr_setschedparam(&attr, &prio); /* 修改属性对应的优先级 */
pthread_attr_setstacksize(&attr, stack_size);
/* 创建线程 1, 属性为 attr入口函数是 thread_entry入口函数参数是 1 */
result = pthread_create(&instrusiontid, &attr, thread_instrusion_detect_entry, NULL);
if (0 == result) {
printf("thread_instrusion_detect_entry successfully!\n");
} else {
printf("thread_instrusion_detect_entry failed! error code is %d\n", result);
close(g_fd);
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(instrusion_detect, instrusion detect task);
#endif
static void *thread_instrusion_detect_entry(void *parameter)
{
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr);
printf("thread_instrusion_detect_entry start!\n");
int ret = 0;
// sysctl_enable_irq();
while (1) {
// memset(showbuffer,0,320*240*2);
g_ai_done_flag = 0;
ret = ioctl(g_fd, IOCTRL_CAMERA_START_SHOT, &shoot_para_t);
if (RT_ERROR == ret) {
printf("ov2640 can't wait event flag");
rt_free(showbuffer);
close(g_fd);
pthread_exit(NULL);
return NULL;
}
kpu_run_kmodel(&instrusion_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
while (!g_ai_done_flag)
;
float *output;
size_t output_size;
kpu_get_output(&instrusion_detect_task, 0, (uint8_t **)&output, &output_size);
instrusion_detect_rl.input = output;
region_layer_run(&instrusion_detect_rl, &instrusion_detect_info);
/* display result */
for (int instrusion_cnt = 0; instrusion_cnt < instrusion_detect_info.obj_number; instrusion_cnt++) {
// draw_edge((uint32_t *)showbuffer, &instrusion_detect_info, instrusion_cnt, 0xF800,
// (uint16_t)sensor_output_size[1],
// (uint16_t)sensor_output_size[0]);
printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", instrusion_cnt, instrusion_detect_info.obj[instrusion_cnt].x1,
instrusion_detect_info.obj[instrusion_cnt].y1, instrusion_detect_info.obj[instrusion_cnt].x2,
instrusion_detect_info.obj[instrusion_cnt].y2, labels[instrusion_detect_info.obj[instrusion_cnt].class_id],
instrusion_detect_info.obj[instrusion_cnt].prob);
}
if (0 != instrusion_detect_info.obj_number) {
printf("\n");
}
#ifdef BSP_USING_LCD
lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer);
#endif
usleep(1);
if (1 == if_exit) {
if_exit = 0;
printf("thread_instrusion_detect_entry exit");
pthread_exit(NULL);
}
}
}
void instrusion_detect_delete()
{
if (showbuffer != NULL) {
int ret = 0;
close(g_fd);
close(kmodel_fd);
free(showbuffer);
free(kpurgbbuffer);
free(model_data);
printf("instrusion detect task cancel!!! ret %d ", ret);
if_exit = 1;
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(instrusion_detect_delete, instrusion detect task delete);
#endif
void kmodel_load(unsigned char *model_data)
{
int kmodel_fd = 0;
int size = 0;
kmodel_fd = open(kmodel_path, O_RDONLY);
model_data = (unsigned char *)malloc(kmodel_size + 255);
if (NULL == model_data) {
printf("model_data apply memory fail !!");
return;
}
memset(model_data, 0, kmodel_size + 255);
if (kmodel_fd >= 0) {
size = read(kmodel_fd, model_data, kmodel_size);
if (size != kmodel_size) {
printf("read kmodel error size %d\n", size);
} else {
printf("read kmodel success");
}
} else {
free(model_data);
printf("open kmodel fail");
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(kmodel_load, kmodel load memory);
#endif

View File

@ -19,7 +19,8 @@ void simple_CSV_read()
fin = open(CSV_PATH, O_RDONLY);
if (!fin) {
printf("Error open file %s", CSV_PATH);
exit(-1);
// exit(-1);
return;
}
read(fin, buffer, sizeof(buffer));
close(fin);

View File

@ -0,0 +1,10 @@
config K210_DETECT_ENTRY
bool "enable apps/k210 yolov2 detect entry"
depends on BOARD_K210_EVB
depends on DRV_USING_OV2640
depends on USING_KPU_PROCESSING
depends on USING_YOLOV2
depends on USING_YOLOV2_JSONPARSER
depends on USING_K210_YOLOV2_DETECT
select LIB_USING_CJSON
default n

View File

@ -4,6 +4,6 @@ cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = ['FACE_DETECT'], LOCAL_CPPPATH = CPPPATH)
group = DefineGroup('Applications', src, depend = ['USING_K210_YOLOV2_DETECT'], LOCAL_CPPPATH = CPPPATH)
Return('group')

View File

@ -24,7 +24,6 @@
6.718375,
9.01025
],
"kmodel_path": "/kmodel/detect.kmodel",
"kmodel_size": 388776,
"obj_thresh": [
0.7

View File

@ -0,0 +1,38 @@
{
"net_input_size": [
256,
320
],
"net_output_shape": [
10,
8,
35
],
"sensor_output_size": [
240,
320
],
"anchors": [
0.156250,
0.222548,
0.361328,
0.489583,
0.781250,
0.983133,
1.621094,
1.964286,
3.574219,
3.940000
],
"kmodel_size": 555176,
"obj_thresh": [
0.7,
0.7
],
"labels": [
"no_mask",
"mask"
],
"nms_thresh": 0.4
}

View File

@ -24,11 +24,10 @@
2.1128,
3.184
],
"kmodel_path": "/kmodel/helmet.kmodel",
"kmodel_size": 2714044,
"obj_thresh": [
0.7,
0.9
0.99
],
"labels": [
"head",

View File

@ -24,10 +24,9 @@
2.049,
4.6711
],
"kmodel_path": "/kmodel/human.kmodel",
"kmodel_size": 2713236,
"obj_thresh": [
0.55
0.7
],
"labels": [
"human"

View File

@ -0,0 +1,16 @@
#include "k210_yolov2_detect.h"
static void detect_app(int argc, char *argv[])
{
if (2 != argc) {
printf("Usage: detect_app <ABSOLUTE_CONFIG_JSON_PATH>");
} else {
k210_detect(argv[1]);
}
return;
}
// clang-format off
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(detect_app, k210 detect app usage: detect_app <ABSOLUTE_CONFIG_JSON_PATH>);
#endif
// clang-format on

View File

@ -0,0 +1,3 @@
config K210_FFT_TEST
bool "enable apps/k210 fft test"
default n

View File

@ -4,6 +4,6 @@ cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = ['HELMET_DETECT'], LOCAL_CPPPATH = CPPPATH)
group = DefineGroup('Applications', src, depend = ['K210_FFT_TEST'], LOCAL_CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,101 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "fft_soft.h"
#define PI 3.14159265358979323846
complex add(complex a, complex b)
{
complex ret = {a.real + b.real, a.imag + b.imag};
return ret;
}
complex sub(complex a, complex b)
{
complex ret = {a.real - b.real, a.imag - b.imag};
return ret;
}
complex mul(complex a, complex b)
{
complex ret = {a.real * b.real - a.imag * b.imag, a.real * b.imag + a.imag * b.real};
return ret;
}
void bitrev(complex *data, int n)
{
int j = 0;
int m = 0;
for (int i = 0; i < n; i++)
{
if (j > i)
SWAP(data[i], data[j]);
m = n / 2;
while (j >= m && m != 0)
{
j -= m;
m >>= 1;
}
j += m;
}
}
void fft_soft(complex *data, int n)
{
int M = 0;
for (int i = n; i > 1; i = i >> 1, M++);
bitrev(data, n);
for (int m = 0; m < M; m++)
{
int K = n >> (m + 1);
for (int k = 0; k < K; k++)
{
int J = 2 << m;
int base = k * J;
for (int j = 0; j < J / 2; j++)
{
int t = base + j;
complex w = {cos(-2 * PI * j * K / n), sin(-2 * PI * j * K / n)};
complex wn = mul(data[t + J / 2], w);
complex temp = data[t];
data[t] = add(data[t], wn);
data[t + J / 2] = sub(temp, wn);
}
}
}
}
void ifft_soft(complex *data, int n)
{
int M = 0;
for (int i = n; i > 1; i = i >> 1, M++);
bitrev(data, n);
for (int m = 0; m < M; m++)
{
int K = n >> (m + 1);
for (int k = 0; k < K; k++)
{
int J = 2 << m;
int base = k * J;
for (int j = 0; j < J / 2; j++)
{
int t = base + j;
complex w = {cos(2 * PI * j * K / n), sin(2 * PI * j * K / n)};
complex wn = mul(data[t + J / 2], w);
complex temp = data[t];
data[t] = add(data[t], wn);
data[t + J / 2] = sub(temp, wn);
}
}
}
for (int i = 0; i < n; i++)
{
data[i].real /= n;
data[i].imag /= n;
}
}

View File

@ -0,0 +1,14 @@
#ifndef _FFT_SOFT_H
#define _FFT_SOFT_H
#include <stdint.h>
#define SWAP(a, b) do {complex t = (a); (a) = (b); (b) = t;} while(0)
typedef struct{double real, imag;} complex;
void fft_soft(complex *data, int n);
void ifft_soft(complex *data, int n);
void show(complex *data, int n);
#endif /* _FFT_SOFT_H */

View File

@ -0,0 +1,159 @@
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <transform.h>
#include <math.h>
#include "encoding.h"
#include "dmac.h"
#include "fft.h"
#include "encoding.h"
#include "sysctl.h"
#include "fft_soft.h"
#define FFT_N 512U
#define FFT_FORWARD_SHIFT 0x0U
#define FFT_BACKWARD_SHIFT 0x1ffU
#define PI 3.14159265358979323846
typedef enum _complex_mode
{
FFT_HARD = 0,
FFT_SOFT = 1,
FFT_COMPLEX_MAX,
} complex_mode_t;
int16_t real[FFT_N];
int16_t imag[FFT_N];
float hard_power[FFT_N];
float soft_power[FFT_N];
float hard_angel[FFT_N];
float soft_angel[FFT_N];
uint64_t fft_out_data[FFT_N / 2];
uint64_t buffer_input[FFT_N];
uint64_t buffer_output[FFT_N];
uint64_t cycle[FFT_COMPLEX_MAX][FFT_DIR_MAX];
uint16_t get_bit1_num(uint32_t data)
{
uint16_t num;
for (num = 0; data; num++)
data &= data - 1;
return num;
}
void k210_fft_test(void)
{
int32_t i;
float tempf1[3];
fft_data_t *output_data;
fft_data_t *input_data;
uint16_t bit1_num = get_bit1_num(FFT_FORWARD_SHIFT);
complex_hard_t data_hard[FFT_N] = {0};
complex data_soft[FFT_N] = {0};
for (i = 0; i < FFT_N; i++)
{
tempf1[0] = 0.3 * cosf(2 * PI * i / FFT_N + PI / 3) * 256;
tempf1[1] = 0.1 * cosf(16 * 2 * PI * i / FFT_N - PI / 9) * 256;
tempf1[2] = 0.5 * cosf((19 * 2 * PI * i / FFT_N) + PI / 6) * 256;
data_hard[i].real = (int16_t)(tempf1[0] + tempf1[1] + tempf1[2] + 10);
data_hard[i].imag = (int16_t)0;
data_soft[i].real = data_hard[i].real;
data_soft[i].imag = data_hard[i].imag;
}
for (int i = 0; i < FFT_N / 2; ++i)
{
input_data = (fft_data_t *)&buffer_input[i];
input_data->R1 = data_hard[2 * i].real;
input_data->I1 = data_hard[2 * i].imag;
input_data->R2 = data_hard[2 * i + 1].real;
input_data->I2 = data_hard[2 * i + 1].imag;
}
cycle[FFT_HARD][FFT_DIR_FORWARD] = read_cycle();
fft_complex_uint16_dma(DMAC_CHANNEL0, DMAC_CHANNEL1, FFT_FORWARD_SHIFT, FFT_DIR_FORWARD, buffer_input, FFT_N, buffer_output);
cycle[FFT_HARD][FFT_DIR_FORWARD] = read_cycle() - cycle[FFT_HARD][FFT_DIR_FORWARD];
cycle[FFT_SOFT][FFT_DIR_FORWARD] = read_cycle();
fft_soft(data_soft, FFT_N);
cycle[FFT_SOFT][FFT_DIR_FORWARD] = read_cycle() - cycle[FFT_SOFT][FFT_DIR_FORWARD];
for (i = 0; i < FFT_N / 2; i++)
{
output_data = (fft_data_t*)&buffer_output[i];
data_hard[2 * i].imag = output_data->I1 ;
data_hard[2 * i].real = output_data->R1 ;
data_hard[2 * i + 1].imag = output_data->I2 ;
data_hard[2 * i + 1].real = output_data->R2 ;
}
for (i = 0; i < FFT_N; i++)
{
hard_power[i] = sqrt(data_hard[i].real * data_hard[i].real + data_hard[i].imag * data_hard[i].imag) * 2;
soft_power[i] = sqrt(data_soft[i].real * data_soft[i].real + data_soft[i].imag * data_soft[i].imag) * 2;
}
printf("\n[hard fft real][soft fft real][hard fft imag][soft fft imag]\n");
for (i = 0; i < FFT_N / 2; i++)
printf("%3d:%7d %7d %7d %7d\n",
i, data_hard[i].real, (int32_t)data_soft[i].real, data_hard[i].imag, (int32_t)data_soft[i].imag);
printf("\nhard power soft power:\n");
printf("%3d : %f %f\n", 0, hard_power[0] / 2 / FFT_N * (1 << bit1_num), soft_power[0] / 2 / FFT_N);
for (i = 1; i < FFT_N / 2; i++)
printf("%3d : %f %f\n", i, hard_power[i] / FFT_N * (1 << bit1_num), soft_power[i] / FFT_N);
printf("\nhard phase soft phase:\n");
for (i = 0; i < FFT_N / 2; i++)
{
hard_angel[i] = atan2(data_hard[i].imag, data_hard[i].real);
soft_angel[i] = atan2(data_soft[i].imag, data_soft[i].real);
printf("%3d : %f %f\n", i, hard_angel[i] * 180 / PI, soft_angel[i] * 180 / PI);
}
for (int i = 0; i < FFT_N / 2; ++i)
{
input_data = (fft_data_t *)&buffer_input[i];
input_data->R1 = data_hard[2 * i].real;
input_data->I1 = data_hard[2 * i].imag;
input_data->R2 = data_hard[2 * i + 1].real;
input_data->I2 = data_hard[2 * i + 1].imag;
}
cycle[FFT_HARD][FFT_DIR_BACKWARD] = read_cycle();
fft_complex_uint16_dma(DMAC_CHANNEL0, DMAC_CHANNEL1, FFT_BACKWARD_SHIFT, FFT_DIR_BACKWARD, buffer_input, FFT_N, buffer_output);
cycle[FFT_HARD][FFT_DIR_BACKWARD] = read_cycle() - cycle[FFT_HARD][FFT_DIR_BACKWARD];
cycle[FFT_SOFT][FFT_DIR_BACKWARD] = read_cycle();
ifft_soft(data_soft, FFT_N);
cycle[FFT_SOFT][FFT_DIR_BACKWARD] = read_cycle() - cycle[FFT_SOFT][FFT_DIR_BACKWARD];
for (i = 0; i < FFT_N / 2; i++)
{
output_data = (fft_data_t*)&buffer_output[i];
data_hard[2 * i].imag = output_data->I1 ;
data_hard[2 * i].real = output_data->R1 ;
data_hard[2 * i + 1].imag = output_data->I2 ;
data_hard[2 * i + 1].real = output_data->R2 ;
}
printf("\n[hard ifft real][soft ifft real][hard ifft imag][soft ifft imag]\n");
for (i = 0; i < FFT_N / 2; i++)
printf("%3d:%7d %7d %7d %7d\n",
i, data_hard[i].real, (int32_t)data_soft[i].real, data_hard[i].imag, (int32_t)data_soft[i].imag);
printf("[hard fft test] [%d bytes] forward time = %ld us, backward time = %ld us\n",
FFT_N,
cycle[FFT_HARD][FFT_DIR_FORWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000),
cycle[FFT_HARD][FFT_DIR_BACKWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000));
printf("[soft fft test] [%d bytes] forward time = %ld us, backward time = %ld us\n",
FFT_N,
cycle[FFT_SOFT][FFT_DIR_FORWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000),
cycle[FFT_SOFT][FFT_DIR_BACKWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000));
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(k210_fft_test,k210 fft test );
#endif

View File

@ -1,4 +1,4 @@
unsigned char mnist_model[] = {
const unsigned char mnist_model[] = {
0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x14, 0x00, 0x20, 0x00,
0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00,
0x18, 0x00, 0x1c, 0x00, 0x14, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,

View File

@ -0,0 +1,3 @@
SRC_FILES := lv_init.c lv_demo.c lv_demo_calendar.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-10-17 Meco Man First version
*/
#include <lvgl.h>
#include <lv_port_indev_template.h>
#include "lv_demo_calendar.h"
#include <transform.h>
extern void lv_example_chart_2(void);
extern void lv_example_img_1(void);
extern void lv_example_img_2(void);
extern void lv_example_img_3(void);
extern void lv_example_img_4(void);
extern void lv_example_line_1(void);
extern void lv_example_aoteman(void);
void* lvgl_thread(void *parameter)
{
/* display demo; you may replace with your LVGL application at here */
// lv_demo_calendar();
// lv_example_img_1();
// lv_example_chart_2();
// lv_example_line_1();
lv_example_aoteman();
/* handle the tasks of LVGL */
while(1)
{
lv_task_handler();
PrivTaskDelay(10);
}
}
pthread_t lvgl_task;
static int lvgl_demo_init(void)
{
pthread_attr_t attr;
attr.schedparam.sched_priority = 25;
attr.stacksize = 4096;
PrivTaskCreate(&lvgl_task, &attr, lvgl_thread, NULL);
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),lvgl_demo_init, lvgl_demo_init, lvgl_demo_init );

View File

@ -0,0 +1,50 @@
#include <lvgl.h>
#include "lv_demo_calendar.h"
// #include <drv_lcd.h>
static void event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_current_target(e);
if(code == LV_EVENT_VALUE_CHANGED) {
lv_calendar_date_t date;
if(lv_calendar_get_pressed_date(obj, &date)) {
LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year);
}
}
}
void lv_demo_calendar(void)
{
lv_obj_t * calendar = lv_calendar_create(lv_scr_act());
lv_obj_set_size(calendar, 320, 240);
lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL);
lv_calendar_set_today_date(calendar, 2021, 02, 23);
lv_calendar_set_showed_date(calendar, 2021, 02);
/*Highlight a few days*/
static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/
highlighted_days[0].year = 2021;
highlighted_days[0].month = 02;
highlighted_days[0].day = 6;
highlighted_days[1].year = 2021;
highlighted_days[1].month = 02;
highlighted_days[1].day = 11;
highlighted_days[2].year = 2021;
highlighted_days[2].month = 02;
highlighted_days[2].day = 22;
lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
#if LV_USE_CALENDAR_HEADER_DROPDOWN
lv_calendar_header_dropdown_create(calendar);
#elif LV_USE_CALENDAR_HEADER_ARROW
lv_calendar_header_arrow_create(calendar);
#endif
// lv_calendar_set_showed_date(calendar, 2021, 10);
}

View File

@ -0,0 +1,6 @@
#ifndef __LV_DEMO_CALENDAR_H__
#define __LV_DEMO_CALENDAR_H__
void lv_demo_calendar(void);
#endif

View File

@ -0,0 +1,39 @@
#include <lvgl.h>
#define DBG_TAG "LVGL"
#define DBG_LVL DBG_INFO
#ifndef PKG_USING_LVGL_DISP_DEVICE
#include <lv_port_disp_template.h>
#endif
#ifndef PKG_USING_LVGL_INDEV_DEVICE
#include <lv_port_indev_template.h>
#endif
extern void lv_port_disp_init(void);
extern void lv_port_indev_init(void);
#if LV_USE_LOG && LV_LOG_PRINTF
static void lv_rt_log(const char *buf)
{
printf(buf);
printf("\n");
}
#endif
int lv_port_init(void)
{
#if LV_USE_LOG && LV_LOG_PRINTF
lv_log_register_print_cb(lv_rt_log);
#endif
lv_init();
#ifndef PKG_USING_LVGL_DISP_DEVICE
lv_port_disp_init();
#endif
#ifndef PKG_USING_LVGL_INDEV_DEVICE
lv_port_indev_init();
#endif
return 0;
}

View File

@ -12,14 +12,18 @@
#include <stdio.h>
#include <string.h>
#include <user_api.h>
// #include <user_api.h>
#include <transform.h>
extern int FrameworkInit();
extern void ApplicationOtaTaskInit(void);
int main(void)
{
printf("Hello, world!\n");
printf("Hello, world! \n");
FrameworkInit();
#ifdef APPLICATION_OTA
ApplicationOtaTaskInit();
#endif
return 0;
}
// int cppmain(void);

View File

@ -0,0 +1,7 @@
menu "ota app "
menuconfig APPLICATION_OTA
bool "Using app bin ota"
default n
endmenu

View File

@ -1,3 +1,3 @@
SRC_FILES := hfa21.c
SRC_FILES := ota.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,19 @@
# OTA README
xiuos当前的ota功能允许应用bin文件可以通过4G实现远程的bin文件更新限制1、bin文件存放在设备SD卡并且应用从SD卡启动2、暂且支持4G实现3、暂时只支持aiit终端;4、只支持xiuos内核
## 文件说明
| 名称 | 说明 |
| -- | -- |
| ota.c| xiuos设备OTA代码 |
| ota_server.c | pc服务端的实例代码供参考 |
## 使用说明
xiuos的应用bin文件更新依赖上层的adapter框架因此需要在menuconfig同时配置以下选项
1、ota开关APPLICATION_OTA打开
2、adapter的4G功能开关
3、拆分的应用启动SEPARATE_COMPILE开关从SD卡启动的配置开关APP_STARTUP_FROM_SDCARD。

View File

@ -0,0 +1,411 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: ota.c
* @brief: a application ota task of system
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/11/3
*
*/
#include <transform.h>
#include <adapter.h>
extern int main(void);
struct ota_header_t
{
int16 frame_flag; ///< frame start flag 2 Bytes
uint8 dev_type; ///< device type
uint8 burn_mode; ///< data burn way
uint32 total_len; ///< send data total length caculated from each frame_len
uint32 dev_hid; ///< device hardware version
uint32 dev_sid; ///< device software version
char resv[8]; ///< reserve
};
struct ota_frame_t
{
uint32 frame_id; ///< Current frame id
uint32 frame_len; ///< Current frame data length
char frame_data[64]; ///< Current frame data,max length 64
uint32 crc; ///< Current frame data crc
};
struct ota_data
{
struct ota_header_t header;
struct ota_frame_t frame;
char end[4];
};
pthread_t ota_task;
pthread_t restart_main;
/**
* @description: CRC16 check
* @param data data buffer
* @param length data length
* @return check code
*/
uint32_t OtaCrc16(uint8_t * data, uint32_t length)
{
int j;
unsigned int reg_crc=0xFFFF;
printf("crc data length[%d] Bytes,",length);
while (length--) {
reg_crc ^= *data++;
for (j=0;j<8;j++) {
if(reg_crc & 0x01)
reg_crc=reg_crc >>1 ^ 0xA001;
else
reg_crc=reg_crc >>1;
}
}
printf(" crc = [0x%x]\n",reg_crc);
return reg_crc;
}
uint32_t FileCrc16(uint8_t * data, uint32_t length, unsigned int last_crc)
{
int j;
//printf("crc data length[%d] Bytes,",length);
while (length--) {
last_crc ^= *data++;
for (j=0;j<8;j++) {
if(last_crc & 0x01)
last_crc = last_crc >>1 ^ 0xA001;
else
last_crc = last_crc >>1;
}
}
//printf(" crc = [0x%x]\n",last_crc);
return last_crc;
}
static int SaveAppBin(int fd, char* buf, int len)
{
int ret = 0;
int fd_t = 0;
fd_t = open( BOARD_APP_NAME, O_RDWR | O_APPEND);
ret = write(fd, buf, len);
if(ret < 0){
printf("fd = %d write buf len[%d] failed.ret = %d\n",fd_t,len,ret);
}
else
{
printf("fd[%d] write buf length[%d] done.\n",fd_t,ret);
}
close(fd_t);
}
static int CrcFileCheck(uint32 crc_check, unsigned long total_len)
{
int ret = 0;
int fd = 0;
int len = 0;
char *buf = NULL;
unsigned int last_crc = 0xffff;
unsigned long already_crc_length = 0;
fd = open( BOARD_APP_NAME, O_RDONLY );
if(fd < 0){
printf("open %s bin failed.\n",BOARD_APP_NAME);
return -1;
}
buf = PrivMalloc(128);
if(NULL == buf)
{
printf("malloc failed.\n");
close(fd);
return 0;
}
/* crc check every 1024 Bytes until crc all the total file */
while(already_crc_length != total_len)
{
memset(buf , 0 , 128);
len = read(fd, buf, 128);
if(len < 0)
{
printf("file read failed.ret = %d\n",len);
ret = -1;
break;
}
last_crc = FileCrc16(buf, len, last_crc);
already_crc_length += len;
printf("read len[%d] Bytes,already_crc_length[%d]\n",len,already_crc_length);
}
if (last_crc != crc_check)
{
printf("file crc error!!! last crc[%x] != check[%x]\n",last_crc,crc_check);
ret =-1;
}
PrivFree(buf);
close(fd);
return ret;
}
static void RestartApplication(void)
{
pthread_attr_t attr;
attr.schedparam.sched_priority = 10;
attr.stacksize = 2048;
while(1)
{
unsigned long pid = PrivUserTaskSearch();
if ((pid > 0) && (pid != pthread_self()))
{
printf("kill usertask pid[%d]\n",pid);
PrivTaskDelete(pid, 0);
PrivTaskDelay(1000); /* NOTE:this delay will make a schedule and recycle all user task */
}
else
{
break;
}
}
printf("restart main.\n");
PrivTaskCreate(&restart_main, &attr, (void *)main, NULL);
}
static int OtaDataRecv(struct Adapter* adapter)
{
struct ota_data recv_msg;
char reply[16] = {0};
int ret = 0;
int try_times = 10;
int fd = 0;
int frame_cnt = 0;
fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if(fd < 0)
{
printf("open %s failed\n",BOARD_APP_NAME);
return -1;
}
close(fd);
while(1) {
memset(&recv_msg, 0, sizeof(struct ota_data));
printf("recv msg...\n");
ret = AdapterDeviceRecv(adapter, &recv_msg, sizeof(struct ota_data));
if(ret >= 0 && recv_msg.header.frame_flag == 0x5A5A)
{
if(0 == strncmp("aiit_ota_end",recv_msg.frame.frame_data, strlen("aiit_ota_end")))
{
printf("total [%d]frames [%d]Bytes crc[%x],receive successful,\n",frame_cnt,recv_msg.header.total_len,recv_msg.frame.crc);
if(0 != CrcFileCheck(recv_msg.frame.crc, recv_msg.header.total_len))
{
printf("crc check %s bin failed.please try again.\n", BOARD_APP_NAME);
ret = -1;
break;
}
PrivTaskDelay(500);
printf("tolal file crc done.send ok\n");
memset(reply, 0, 16);
memcpy(reply, "ok", strlen("ok"));
AdapterDeviceSend(adapter, reply, strlen(reply));
ret = 0;
break;
}
frame_cnt = recv_msg.frame.frame_id;
if(0 == strncmp("wait_ok_timeout",recv_msg.frame.frame_data, strlen("wait_ok_timeout")))
{
printf("go to send ok again.\n");
goto send_ok_again;
}
if (recv_msg.frame.crc == OtaCrc16(recv_msg.frame.frame_data,recv_msg.frame.frame_len))
{
printf("save current [%d] frame,length[%d] Bytes.\n",frame_cnt,recv_msg.frame.frame_len);
for(int i = 0; i < recv_msg.frame.frame_len;i++ ){
printf(" %x ",*((char *)&recv_msg.frame.frame_data + i));
}
printf("\n");
SaveAppBin(fd, recv_msg.frame.frame_data, recv_msg.frame.frame_len);
}
else
{
printf("current [%d] frame crc check failed,try again!\n",frame_cnt);
goto try_again;
}
send_ok_again:
memset(reply, 0, 16);
memcpy(reply, "ok", strlen("ok"));
// PrivTaskDelay(100);
ret = AdapterDeviceSend(adapter, reply, strlen(reply));
if(ret < 0){
printf("send ok failed.\n");
goto send_ok_again;
}
printf("send reply[%s] done.\n",reply);
try_times = 10;
continue;
}
else
{
try_again:
if(try_times == 0)
{
printf("oops!!! current [%d] frame try 10 times failed,break out!\n",frame_cnt);
ret = -1;
break;
}
memset(reply, 0, 16);
memcpy(reply, "retry", strlen("retry"));
printf("[%d] frame receive failed. retry\n",frame_cnt);
AdapterDeviceSend(adapter, reply, strlen(reply));
try_times--;
continue;
}
}
close(fd);
if(0 == ret) {
printf("ota file done,start application.\n");
RestartApplication();
}
return ret;
}
static void *OtaKTaskEntry(void *parameter)
{
struct ota_data recv_msg;
char reply[16] = {0};
int baud_rate = BAUD_RATE_115200;
int len = 0;
int ret = 0;
struct Adapter* adapter = AdapterDeviceFindByName("4G");
uint8 server_addr[64] = "115.238.53.61";
uint8 server_port[64] = "9898";
adapter->socket.socket_id = 0;
AdapterDeviceOpen(adapter);
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
AdapterDeviceConnect(adapter, CLIENT, server_addr, server_port, IPV4);
/* using nbiot as connection way*/
// struct Adapter* adapter = AdapterDeviceFindByName("nbiot");
// while(1)
// {
// int connect_times = 5;
// ret = AdapterDeviceOpen(adapter);
// if(ret < 0)
// {
// printf("open adapter failed\n");
// continue;
// }
// connect_again:
// connect_times--;
// ret = AdapterDeviceConnect(adapter, 1, "115.238.53.61","9898",1);
// if(ret < 0)
// {
// if(connect_times > 0){
// goto connect_again;
// }
// else
// {
// AdapterDeviceClose(adapter);
// continue;
// }
// }
// break;
// }
PrivTaskDelay(5000);
while(1)
{
memset(&recv_msg, 0, sizeof(struct ota_data));
/* step1: Confirm the start signal of transmission*/
printf("waiting for start msg...\n");
ret = AdapterDeviceRecv(adapter, &recv_msg, sizeof(struct ota_data));
for(int i = 0; i < sizeof(struct ota_data);i++ ){
printf(" %x ",*((char *)&recv_msg + i));
}
printf("\n");
if(ret >= 0 && recv_msg.header.frame_flag == 0x5A5A)
{
if (0 == strncmp("aiit_ota_start",recv_msg.frame.frame_data, strlen("aiit_ota_start")))
{
memset(reply, 0, 16);
memcpy(reply, "ready", strlen("ready"));
// PrivTaskDelay(3000);
printf("receive start signal,send [ready] signal to server\n");
send_ready_again:
ret = AdapterDeviceSend(adapter, reply, strlen(reply));
if(ret < 0)
{
goto send_ready_again;
}
PrivTaskDelay(3000);
printf("start receive ota file.\n");
/* step2: start receive source bin file of application*/
ret = OtaDataRecv(adapter);
if (0 != ret)
{
memset(reply, 0, 16);
memcpy(reply, "ota_restart", strlen("ota_restart"));
AdapterDeviceSend(adapter, reply, strlen(reply));
continue;
}
else
{
break;
}
}
}
else
{
memset(reply, 0, 16);
memcpy(reply, "notready", strlen("notready"));
printf("ota status:not ready\n");
ret = AdapterDeviceSend(adapter, reply, strlen(reply));
}
PrivTaskDelay(3000); /* check ota signal every 5s */
}
AdapterDeviceClose(adapter);
}
void ApplicationOtaTaskInit(void)
{
pthread_attr_t attr;
attr.schedparam.sched_priority = 20;
attr.stacksize = 4096;
PrivTaskCreate(&ota_task, &attr, OtaKTaskEntry, NULL);
}

View File

@ -0,0 +1,364 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <pthread.h>
#include <time.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/time.h>
#include <assert.h>
#include <netdb.h>
#include <sys/stat.h>
#include <fcntl.h>
typedef int BOOL;
#define true 1
#define false 0
int serverfd;//服务器socket
int clientfd[100000];//客户端的socketfd,100个元素clientfd[0]~clientfd[99]
int size = 99999;//用来控制进入聊天室的人数为50以内
int PORT = 9898;//端口号
typedef struct sockaddr meng;
struct ota_header_t
{
int16_t frame_flag; ///< frame start flag 2 Bytes
uint8_t dev_type; ///< device type
uint8_t burn_mode; ///< data burn way
uint32_t total_len; ///< send data total length caculated from each frame_len
uint32_t dev_hid; ///< device hardware version
uint32_t dev_sid; ///< device software version
char resv[8]; ///< reserve
};
struct ota_frame_t
{
uint32_t frame_id; ///< Current frame id
uint32_t frame_len; ///< Current frame data length
char frame_data[64]; ///< Current frame data,max length 224
uint32_t crc; ///< Current frame data crc
};
struct ota_data
{
struct ota_header_t header;
struct ota_frame_t frame;
char end[4];
};
pthread_t ota_ktask;
/**
* @description: CRC16 check
* @param data data buffer
* @param length data length
* @return check code
*/
uint32_t OtaCrc16(uint8_t * data, uint32_t length)
{
int j;
unsigned int reg_crc=0xFFFF;
printf("crc data length[%d] Bytes,",length);
while (length--) {
reg_crc ^= *data++;
for (j=0;j<8;j++) {
if(reg_crc & 0x01)
reg_crc=reg_crc >>1 ^ 0xA001;
else
reg_crc=reg_crc >>1;
}
}
printf(" crc = [0x%x]\n",reg_crc);
return reg_crc;
}
void init(void)
{
serverfd = socket(PF_INET,SOCK_STREAM,0);
if (serverfd == -1)
{
perror("创建socket失败");
exit(-1);
}
//为套接字设置ip协议 设置端口号 并自动获取本机ip转化为网络ip
struct sockaddr_in addr;//存储套接字的信息
addr.sin_family = AF_INET;//地址族
addr.sin_port = htons(PORT);//设置server端端口号你可以随便设置,当sin_port = 0时系统随机选择一个未被使用的端口号
addr.sin_addr.s_addr = htons(INADDR_ANY);//当sin_addr = INADDR_ANY时表示从本机的任一网卡接收数据
//绑定套接字
// int on = 1;
struct timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
if(setsockopt(serverfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0)
{
perror("端口设置失败");
exit(-1);
}
if (bind(serverfd,(meng*)&addr,sizeof(addr)) == -1)
{
perror("绑定失败");
exit(-1);
}
if (listen(serverfd,100) == -1)
{//监听最大连接数
perror("设置监听失败");
exit(-1);
}
}
int OtaFileSend(int fd)
{
unsigned char buf[32] = { 0 };
struct ota_data data;
FILE *file_fd;
char ch;
int length = 0;
int try_times = 10;
int recv_end_times = 3;
int ret = 0;
int frame_cnt = 0;
int file_length = 0;
char * file_buf = NULL;
file_fd = fopen("/home/aep04/wwg/XiUOS_aiit-arm32-board_app.bin", "r");
if (NULL == file_fd){
printf("open file failed.\n");
return -1;
}
fseek(file_fd, 0, SEEK_SET);
printf("start send file.\n");
while(!feof(file_fd))
{
memset(&data, 0, sizeof(data));
data.header.frame_flag = 0x5A5A;
length = fread( data.frame.frame_data, 1, 64, file_fd );
if(length > 0)
{
printf("read %d Bytes\n",length);
data.frame.frame_id = frame_cnt;
data.frame.frame_len = length;
data.frame.crc = OtaCrc16(data.frame.frame_data, length);
file_length += length;
}
send_again:
usleep(50000);
printf("ota send current[%d] frame.\n",frame_cnt);
length = send(fd, &data, sizeof(data), MSG_NOSIGNAL);
if(length < 0){
printf("send [%d] frame faile.go to send again\n",frame_cnt);
goto send_again;
}
recv_again:
memset(buf, 0, 32);
length = recv(fd, buf, sizeof(buf), 0);
if(length < 0 ){
printf("[%d] frame waiting for ok timeout,receive again.\n",frame_cnt);
goto recv_again;
}
printf("receive buf[%s] length = %d\n",buf, length);
if(0 == strncmp(buf, "ok", length))
{
try_times = 10;
printf("[%d]frame data send done.\n",frame_cnt);
frame_cnt++;
continue;
}
else
{
if(try_times > 0)
{
try_times--;
goto send_again;
}
else
{
printf("send frame[%d] 10 times failed.\n",frame_cnt);
ret = -1;
break;
}
}
}
/* finally,crc check total bin file.*/
if (ret == 0)
{
sleep(1);
printf("total send file length[%d] Bytes [%d] frames.\n",file_length,frame_cnt);
printf("now crc check total bin file.\n");
file_buf = malloc(file_length);
memset(file_buf, 0, file_length);
memset(&data, 0, sizeof(data));
data.header.frame_flag = 0x5A5A;
file_fd = fopen("/home/aep04/wwg/XiUOS_aiit-arm32-board_app.bin", "r");
if (NULL == file_fd){
printf("open file failed.\n");
return -1;
}
fseek(file_fd, 0, SEEK_SET);
length = fread(file_buf,1, file_length, file_fd);
printf("read file length = %d\n",length);
if(length > 0) {
data.frame.frame_id = frame_cnt;
data.header.total_len = file_length;
data.frame.frame_len = strlen("aiit_ota_end");
data.frame.crc = OtaCrc16(file_buf, length);
memcpy(data.frame.frame_data,"aiit_ota_end",strlen("aiit_ota_end"));
}
send_end_signal:
printf("send aiit_ota_end signal.\n");
length = send(fd, &data, sizeof(data), MSG_NOSIGNAL);
if(length < 0){
printf("send end signal faile,send end signal again\n");
goto send_end_signal;
}
recv_end_signal:
memset(buf, 0, 32);
length = recv(fd, buf, sizeof(buf), 0);
if(length < 0 )
{
recv_end_times--;
printf("end signal waiting for ok timeout,receive again.\n");
if(recv_end_times > 0)
{
goto recv_end_signal;
}
else
{
ret = -1;
}
}
if(0 != strncmp(buf, "ok", length))
{
printf("error end !!!\n");
ret = -1;
}
free(file_buf);
}
fclose(file_fd);
return ret;
}
void* server_thread(void* p)
{
int fd = *(int*)p;
unsigned char buf[32] = { 0 };
struct ota_data data;
int ret = 0;
int length = 0;
printf("pthread = %d\n",fd);
sleep(8);
while(1)
{
memset(&data, 0x0 , sizeof(struct ota_data));
data.header.frame_flag = 0x5A5A;
memcpy(data.frame.frame_data,"aiit_ota_start",strlen("aiit_ota_start"));
data.frame.frame_len = strlen("aiit_ota_start");
printf("send start signal.\n");
ret = send(fd, &data, sizeof(data), MSG_NOSIGNAL);
if (ret > 0){
printf("send %s[%d] Bytes\n",data.frame.frame_data,ret);
}
// sleep(1);
memset(buf, 0, 32);
length = recv(fd, buf, sizeof(buf), 0);
if (length <= 0)
{
continue;
}
else
{
printf("recv buf %s length %d\n",buf,length);
if(0 == strncmp(buf, "ready", length))
{
ret = OtaFileSend(fd);
if (ret == 0) {
printf("ota file send successful.\n");
break;
} else { /* ota failed then restart the ota process */
continue;
}
}
}
}
printf("exit fd = %d\n",fd);
close(fd);
pthread_exit(0);
}
void server(void)
{
printf("ota Server startup\n");
while(1)
{
struct sockaddr_in fromaddr;
socklen_t len = sizeof(fromaddr);
int fd = accept(serverfd,(meng*)&fromaddr,&len);
//调用accept进入堵塞状态等待客户端的连接
if (fd == -1)
{
// printf("The client connection is wrong...\n");
continue;
}
int i = 0;
for (i = 0;i < size;i++)
{
if (clientfd[i] == 0)
{
//记录客户端的socket
clientfd[i] = fd;
//有客户端连接之后,启动线程给此客户服务
pthread_t tid;
pthread_create(&tid,0,server_thread,&fd);
break;
}
if (size == i)
{
//发送给客户端说聊天室满了
char* str = "Devices full";
printf("%s", str);
send(fd,str,strlen(str),0);
close(fd);
}
}
}
}
int main(void)
{
init();
server();
}

View File

@ -5,6 +5,46 @@ menu "sensor app"
default n
if APPLICATION_SENSOR
menuconfig APPLICATION_SENSOR_HCHO
bool "Using sensor HCHO apps"
default n
if APPLICATION_SENSOR_HCHO
config APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS
bool "Using sensor TB600B_WQ_HCHO1OS apps"
default n
endif
menuconfig APPLICATION_SENSOR_TVOC
bool "Using sensor TVOC apps"
default n
if APPLICATION_SENSOR_TVOC
config APPLICATION_SENSOR_TVOC_TB600B_TVOC10
bool "Using sensor TB600B_TVOC10 apps"
default n
endif
menuconfig APPLICATION_SENSOR_IAQ
bool "Using sensor IAQ apps"
default n
if APPLICATION_SENSOR_IAQ
config APPLICATION_SENSOR_IAQ_TB600B_IAQ10
bool "Using sensor TB600B_IAQ10 apps"
default n
endif
menuconfig APPLICATION_SENSOR_CH4
bool "Using sensor CH4 apps"
default n
if APPLICATION_SENSOR_CH4
config APPLICATION_SENSOR_CH4_AS830
bool "Using sensor AS830 apps"
default n
endif
menuconfig APPLICATION_SENSOR_CO2
bool "Using sensor CO2 apps"
default n
@ -25,6 +65,26 @@ menu "sensor app"
default n
endif
menuconfig APPLICATION_SENSOR_PM2_5
bool "Using sensor PM2.5 apps"
default n
if APPLICATION_SENSOR_PM2_5
config APPLICATION_SENSOR_PM2_5_PS5308
bool "Using sensor PS5308 apps"
default n
endif
menuconfig APPLICATION_SENSOR_PM10
bool "Using sensor PM10 apps"
default n
if APPLICATION_SENSOR_PM10
config APPLICATION_SENSOR_PM10_PS5308
bool "Using sensor PS5308 apps"
default n
endif
menuconfig APPLICATION_SENSOR_VOICE
bool "Using sensor voice apps"
default n
@ -35,16 +95,6 @@ menu "sensor app"
default n
endif
menuconfig APPLICATION_SENSOR_HUMIDITY
bool "Using sensor humidity apps"
default n
if APPLICATION_SENSOR_HUMIDITY
config APPLICATION_SENSOR_HUMIDITY_HS300X
bool "Using sensor HS300x apps"
default n
endif
menuconfig APPLICATION_SENSOR_TEMPERATURE
bool "Using sensor temperature apps"
default n
@ -53,7 +103,26 @@ menu "sensor app"
config APPLICATION_SENSOR_TEMPERATURE_HS300X
bool "Using sensor HS300x apps"
default n
if ADD_NUTTX_FETURES
endif
endif
menuconfig APPLICATION_SENSOR_HUMIDITY
bool "Using sensor humidity apps"
default n
if APPLICATION_SENSOR_HUMIDITY
config APPLICATION_SENSOR_HUMIDITY_HS300X
bool "Using sensor HS300x apps"
default n
if ADD_NUTTX_FETURES
endif
endif
endif
endmenu

View File

@ -0,0 +1,6 @@
############################################################################
# APP_Framework/Applications/sensor_app/Make.defs
############################################################################
ifneq ($(CONFIG_APPLICATION_SENSOR),)
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications/sensor_app
endif

View File

@ -1,23 +1,103 @@
SRC_FILES :=
include $(KERNEL_ROOT)/.config
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
CSRCS += hcho_tb600b_wq_hcho1os.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
CSRCS += tvoc_tb600b_tvoc10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
CSRCS += iaq_tb600b_iaq10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
CSRCS += ch4_as830.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
CSRCS += co2_zg09.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
CSRCS += pm1_0_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y)
CSRCS += pm2_5_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM10_PS5308), y)
CSRCS += pm10_0_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y)
CSRCS += voice_d124.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y)
CSRCS += humidity_hs300x.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y)
CSRCS += temperature_hs300x.c
endif
include $(APPDIR)/Application.mk
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
SRC_FILES += co2_zg09.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
SRC_FILES += pm1_0_ps5308.c
endif
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES :=
ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y)
SRC_FILES += voice_d124.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
SRC_FILES += hcho_tb600b_wq_hcho1os.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y)
SRC_FILES += humidity_hs300x.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
SRC_FILES += tvoc_tb600b_tvoc10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y)
SRC_FILES += temperature_hs300x.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
SRC_FILES += iaq_tb600b_iaq10.c
endif
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
SRC_FILES += ch4_as830.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
SRC_FILES += co2_zg09.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
SRC_FILES += pm1_0_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y)
SRC_FILES += pm2_5_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM10_PS5308), y)
SRC_FILES += pm10_0_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y)
SRC_FILES += voice_d124.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y)
SRC_FILES += humidity_hs300x.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y)
SRC_FILES += temperature_hs300x.c
endif
include $(KERNEL_ROOT)/compiler.mk
endif

View File

@ -0,0 +1,20 @@
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')
cwd = GetCurrentDir()
DEPENDS = ["SUPPORT_SENSOR_FRAMEWORK"]
SOURCES = []
if GetDepend(['APPLICATION_SENSOR_CO2_ZG09']):
SOURCES = ['co2_zg09.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_PM1_0_PS5308']):
SOURCES = ['pm1_0_ps5308.c.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_VOICE_D124']):
SOURCES = ['voice_d124.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_HUMIDITY_HS300X']):
SOURCES = ['humidity_hs300x.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_TEMPERATURE_HS300X']):
SOURCES = ['temperature_hs300x.c'] + SOURCES
path = [cwd]
objs = DefineGroup('sensor_app', src = SOURCES, depend = DEPENDS,CPPPATH = path)
Return("objs")

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file ch4_as830.c
* @brief CH4 AS830 example
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.10
*/
#ifdef ADD_XIUOS_FETURES
# include <user_api.h>
#endif
#include <sensor.h>
/**
* @description: Read a ch4
* @return 0
*/
void Ch4As830(void)
{
struct SensorQuantity *ch4 = SensorQuantityFind(SENSOR_QUANTITY_AS830_CH4, SENSOR_QUANTITY_CH4);
SensorQuantityOpen(ch4);
printf("CH4 : %d %%LTL\n", SensorQuantityRead(ch4));
SensorQuantityClose(ch4);
}

Some files were not shown because too many files have changed in this diff Show More