├── framework ├── readme.txt ├── protocol │ ├── readme.txt │ ├── sub_device_protocol.c.rej │ ├── pando_machine.h │ ├── common_functions.c │ ├── common_functions.h │ ├── pando_machine.c │ ├── pando_endian.h │ ├── Makefile │ └── pando_endian.c ├── gateway │ ├── mqtt │ │ ├── .output │ │ │ └── eagle │ │ │ │ └── debug │ │ │ │ └── obj │ │ │ │ ├── mqtt.d.1000 │ │ │ │ ├── mqtt.d.1004 │ │ │ │ └── mqtt.d.8428 │ │ ├── utils.h │ │ ├── debug.h │ │ ├── typedef.h │ │ ├── ringbuf.h │ │ ├── proto.h │ │ ├── Makefile │ │ ├── ringbuf.c │ │ ├── queue.h │ │ ├── queue.c │ │ └── proto.c │ ├── pando_zero_device.h │ ├── pando_device_login.h │ ├── pando_device_register.h │ ├── pando_gateway.h │ ├── pando_cloud_access.h │ ├── pando_channel.c │ ├── gateway_defs.h │ ├── Makefile │ ├── pando_channel.h │ └── pando_zero_device.c ├── pando_framework.c ├── platform │ ├── include │ │ ├── pando_sys.h.rej │ │ ├── pando_timer.h │ │ ├── pando_types.h │ │ ├── platform_miscellaneous_interface.h │ │ ├── pando_net_http.h │ │ ├── pando_sys.h │ │ └── pando_storage_interface.h │ ├── src │ │ ├── esp8266 │ │ │ ├── pando_timer.c │ │ │ ├── platform_miscellaneous_interface.c │ │ │ └── Makefile │ │ ├── at_stm32 │ │ │ ├── pando_net_http.c │ │ │ └── platform_miscellaneous_interface.c │ │ └── Makefile │ └── Makefile ├── pando_framework.h ├── lib │ ├── converter.h │ ├── pando_json.c │ ├── pando_json.h │ ├── json │ │ ├── Makefile │ │ └── json.h │ ├── Makefile │ ├── converter.c │ ├── private_key.h │ └── cert.h ├── subdevice │ ├── pando_subdevice.h │ ├── pando_event.h │ ├── pando_event.c │ ├── pando_command.c │ ├── pando_command.h │ ├── Makefile │ ├── pando_object.c │ └── pando_object.h └── Makefile ├── example ├── esp8266 │ ├── user │ │ ├── readme.txt │ │ ├── object │ │ │ ├── readme.txt │ │ │ ├── air.h │ │ │ ├── plug.h │ │ │ ├── pm25.h │ │ │ ├── motor.h │ │ │ ├── c_motor.h │ │ │ ├── humiture.h │ │ │ ├── temperature.h │ │ │ ├── led.h │ │ │ ├── Makefile │ │ │ ├── air.c │ │ │ ├── plug.c │ │ │ ├── pm25.c │ │ │ ├── humiture.c │ │ │ ├── temperatrure.c │ │ │ ├── motor.c │ │ │ ├── c_motor.c │ │ │ └── led.c │ │ ├── device_config.h │ │ ├── wifi_config.h │ │ ├── Makefile │ │ └── user_main.c │ ├── util │ │ ├── readme.txt │ │ ├── converter.h │ │ ├── pando_lan_bind.h │ │ ├── httpclient.h │ │ ├── Makefile │ │ ├── converter.c │ │ ├── private_key.h │ │ └── cert.h │ ├── peripheral │ │ ├── readme.txt │ │ ├── driver │ │ │ ├── readme.txt │ │ │ ├── adc.h │ │ │ ├── tisan_gpio_intr.c │ │ │ ├── tisan_gpio_intr.h │ │ │ ├── gpio16.h │ │ │ ├── key.h │ │ │ ├── gpio16.c │ │ │ ├── pwm.h │ │ │ ├── i2c.h │ │ │ ├── Makefile │ │ │ ├── adc.c │ │ │ ├── key.c │ │ │ └── spi.h │ │ ├── peri_ldr.h │ │ ├── peri_jdq.h │ │ ├── peri_motor.h │ │ ├── peri_rgb_light.h │ │ ├── peri_iaq.h │ │ ├── peri_key.h │ │ ├── peri_pm25.h │ │ ├── peri_ldr.c │ │ ├── peri_led.h │ │ ├── peri_dht1122.h │ │ ├── Makefile │ │ ├── peri_key.c │ │ ├── peri_pm25.c │ │ ├── peri_led.c │ │ ├── peri_motor.c │ │ └── peri_i2c_oled.h │ └── readme.txt └── stm32 │ ├── driver │ ├── flash.c │ ├── flash.h │ ├── malloc.h │ ├── usart1.h │ ├── jdqs.h │ ├── usart2.h │ ├── jdqs.c │ ├── timer4.h │ ├── timer4.c │ └── cm3_bitband.h │ ├── objects │ ├── led.h │ └── led.c │ ├── util │ ├── delay.h │ ├── fifo.h │ ├── fifo.c │ ├── delay.c │ ├── task.h │ └── task.c │ └── main.c ├── doc ├── embedded-framework-gateway.md ├── embedded-framework-object.md ├── eg-esp8266.md ├── coding-style.md ├── image │ ├── framework-summary.jpg │ ├── pando-IOT-structure.jpg │ └── normal-IOT-structure.jpg ├── eg-stm32-3g.md └── embedded-framework-summary.md ├── .gitignore ├── LICENSE ├── Makefile └── README.md /framework/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/esp8266/user/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/esp8266/util/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/protocol/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/esp8266/user/object/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/.output/eagle/debug/obj/mqtt.d.1000: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/.output/eagle/debug/obj/mqtt.d.1004: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/.output/eagle/debug/obj/mqtt.d.8428: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/embedded-framework-gateway.md: -------------------------------------------------------------------------------- 1 | # embedded-framework gateway 2 | -------------------------------------------------------------------------------- /doc/embedded-framework-object.md: -------------------------------------------------------------------------------- 1 | # subdevice object abstraction 2 | -------------------------------------------------------------------------------- /doc/eg-esp8266.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/doc/eg-esp8266.md -------------------------------------------------------------------------------- /doc/coding-style.md: -------------------------------------------------------------------------------- 1 | # Coding Style 2 | - Indent 3 | use spaces instead of tabs, and four spaces for a tab. 4 | 5 | -------------------------------------------------------------------------------- /example/esp8266/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/example/esp8266/readme.txt -------------------------------------------------------------------------------- /example/stm32/driver/flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/example/stm32/driver/flash.c -------------------------------------------------------------------------------- /example/stm32/driver/flash.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/example/stm32/driver/flash.h -------------------------------------------------------------------------------- /doc/image/framework-summary.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/doc/image/framework-summary.jpg -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/adc.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADC_H__ 2 | #define __ADC_H__ 3 | 4 | uint16 adc_read(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /example/stm32/driver/malloc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/example/stm32/driver/malloc.h -------------------------------------------------------------------------------- /doc/image/pando-IOT-structure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/doc/image/pando-IOT-structure.jpg -------------------------------------------------------------------------------- /example/esp8266/user/object/air.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_air_H_ 2 | #define OBJECTS_air_H_ 3 | 4 | void air_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /doc/image/normal-IOT-structure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/doc/image/normal-IOT-structure.jpg -------------------------------------------------------------------------------- /example/esp8266/user/object/plug.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_PLUG_H_ 2 | #define OBJECTS_PLUG_H_ 3 | 4 | void plug_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /example/esp8266/user/object/pm25.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_pm25_H_ 2 | #define OBJECTS_pm25_H_ 3 | 4 | void pm25_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /example/esp8266/user/object/motor.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_motor_H_ 2 | #define OBJECTS_motor_H_ 3 | 4 | void motor_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /example/esp8266/user/object/c_motor.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_c_motor_H_ 2 | #define OBJECTS_c_motor_H_ 3 | 4 | void c_motor_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /example/esp8266/user/object/humiture.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_HUMITURE_H_ 2 | #define OBJECTS_HUMITURE_H_ 3 | 4 | void humiture_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /example/esp8266/user/object/temperature.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_temperature_H_ 2 | #define OBJECTS_temperature_H_ 3 | 4 | void temperature_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/tisan_gpio_intr.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/example/esp8266/peripheral/driver/tisan_gpio_intr.c -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/tisan_gpio_intr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-embedded-framework/HEAD/example/esp8266/peripheral/driver/tisan_gpio_intr.h -------------------------------------------------------------------------------- /doc/eg-stm32-3g.md: -------------------------------------------------------------------------------- 1 | ###Introduction 2 | Connect the pandocloud through the 3G module, sim5360. In this example, we use stm32 for application. You can also use other MCU. 3 | -------------------------------------------------------------------------------- /example/stm32/driver/usart1.h: -------------------------------------------------------------------------------- 1 | #ifndef __USART1_H_ 2 | #define __USART1_H_ 3 | 4 | void usart1_init(void); 5 | void usart1_putchar(unsigned char ch); 6 | 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /example/stm32/driver/jdqs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __JDQS_H_ 3 | #define __JDQS_H_ 4 | 5 | extern void jdq_gpio_init(void); 6 | extern void set_jdq(char state); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/gpio16.h: -------------------------------------------------------------------------------- 1 | #ifndef __GPIO16_H__ 2 | #define __GPIO16_H__ 3 | 4 | void gpio16_output_conf(void); 5 | void gpio16_output_set(uint8 value); 6 | void gpio16_input_conf(void); 7 | uint8 gpio16_input_get(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | #include "../../platform/include/pando_types.h" 5 | 6 | uint32_t UTILS_Atoh(const int8_t *s); 7 | uint8_t UTILS_StrToIP(const int8_t* str, void *ip); 8 | uint8_t UTILS_IsIPV4 (int8_t *str); 9 | #endif 10 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.h 3 | * 4 | * Created on: Dec 4, 2014 5 | * Author: Minh 6 | */ 7 | 8 | #ifndef DEBUG_H_ 9 | #define DEBUG_H_ 10 | 11 | #include "../../platform/include/pando_sys.h" 12 | #ifndef INFO 13 | #define INFO pd_printf 14 | #endif 15 | 16 | #endif /* DEBUG_H_ */ 17 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/typedef.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Standard Types definition 4 | */ 5 | 6 | #ifndef _TYPE_DEF_H_ 7 | #define _TYPE_DEF_H_ 8 | 9 | typedef char I8; 10 | typedef unsigned char U8; 11 | typedef short I16; 12 | typedef unsigned short U16; 13 | typedef long I32; 14 | typedef unsigned long U32; 15 | typedef unsigned long long U64; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /framework/pando_framework.c: -------------------------------------------------------------------------------- 1 | #include "gateway/pando_channel.h" 2 | #include "subdevice/pando_subdevice.h" 3 | #include "pando_framework.h" 4 | #include "gateway/pando_gateway.h" 5 | 6 | void FUNCTION_ATTRIBUTE 7 | pando_framework_init() 8 | { 9 | pando_gateway_init(); 10 | 11 | on_subdevice_channel_recv(PANDO_CHANNEL_PORT_1, pando_subdevice_recv); 12 | } 13 | -------------------------------------------------------------------------------- /framework/protocol/sub_device_protocol.c.rej: -------------------------------------------------------------------------------- 1 | diff a/framework/protocol/sub_device_protocol.c b/framework/protocol/sub_device_protocol.c (rejected hunks) 2 | @@ -157,7 +157,7 @@ 3 | return 0; 4 | } 5 | 6 | -struct TLVs * FUNCTION_ATTRIBUTE create_params_block() 7 | +struct TLVs * FUNCTION_ATTRIBUTE create_params_block(void) 8 | { 9 | struct TLVs *tlv_block = NULL; 10 | uint8_t need_length; 11 | -------------------------------------------------------------------------------- /framework/platform/include/pando_sys.h.rej: -------------------------------------------------------------------------------- 1 | diff a/framework/platform/include/pando_sys.h b/framework/platform/include/pando_sys.h (rejected hunks) 2 | @@ -45,8 +45,8 @@ 3 | #include "string.h" 4 | #include "stdio.h" 5 | 6 | -#define pd_malloc malloc 7 | -#define pd_free free 8 | +#define pd_malloc mymalloc //malloc 9 | +#define pd_free myfree //free 10 | 11 | #define pd_memcpy memcpy 12 | #define pd_memcmp memcmp 13 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/key.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEY_H__ 2 | #define __KEY_H__ 3 | 4 | #include "gpio.h" 5 | #include "../peri_key.h" 6 | 7 | #define LONG_PRESS_COUNT 3000 8 | 9 | void key_init(uint32 gpio_name,uint8 gpio_id,uint8 gpio_func); 10 | void key_intr_handler(struct key_param *key); 11 | void peri_vibrate_tim_start(uint16 delay_ms); 12 | void key_5s_cb(struct key_param *single_key); 13 | void key_50ms_cb(struct key_param *single_key); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /example/stm32/objects/led.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: led.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: 6 | * History: 7 | * 1.Date: Sep 15, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef OBJECTS_LED_H_ 13 | #define OBJECTS_LED_H_ 14 | 15 | void led_object_init(void); 16 | 17 | #endif /* APP_USER_OBJECTS_LED_H_ */ 18 | -------------------------------------------------------------------------------- /example/esp8266/user/object/led.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: led.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: 6 | * History: 7 | * 1.Date: Sep 15, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef OBJECTS_LED_H_ 13 | #define OBJECTS_LED_H_ 14 | 15 | void led_object_init(); 16 | 17 | #endif /* APP_USER_OBJECTS_LED_H_ */ 18 | -------------------------------------------------------------------------------- /doc/embedded-framework-summary.md: -------------------------------------------------------------------------------- 1 | # embedded-framework-summary 2 | the main responsibilities of the pando-embedded-framwork: 3 | 4 | - maintain the main gateway business, such as, register, login, access, etc. 5 | - abstract the common interface of hardware, define the device operation object. 6 | - unpack the data packet from the server and control the device; pack the info of the device, and upload to the server. 7 | 8 | ###main summary of the framework 9 | ![summary](image/framework-summary.jpg) 10 | 11 | -------------------------------------------------------------------------------- /framework/pando_framework.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_subdevice.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: pando iot embeded framework. 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: initial code 10 | *********************************************************/ 11 | #ifndef PANDO_FRAMEWORK_H_ 12 | #define PANDO_FRAMEWORK_H_ 13 | 14 | void pando_framework_init(void); 15 | 16 | #endif /* PANDO_FRAMEWORK_H_ */ 17 | -------------------------------------------------------------------------------- /example/stm32/util/delay.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: delay.h 3 | * Author : wfq 4 | * Versions : 1.0 5 | * Description: dev delay 6 | * History: 7 | * 1.Date: 2014-12-10 8 | * Author: wfq 9 | * Action: create 10 | *********************************************************/ 11 | 12 | #ifndef __DELAY_H 13 | #define __DELAY_H 14 | #include 15 | 16 | void delay_init(void); 17 | void delay_ms(uint16_t nms); 18 | void delay_us(uint32_t nus); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /example/esp8266/util/converter.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONVERTER_H__ 2 | #define __CONVERTER_H__ 3 | 4 | #include "c_types.h" 5 | 6 | /****************************************************************************** 7 | * FunctionName : hex2bin. 8 | * Description : convert. string to bin. 9 | * Parameters : dst -- 10 | * hex_str -- 11 | * Returns : none. 12 | *******************************************************************************/ 13 | 14 | void hex2bin(uint8 * dst, char * hex_str); 15 | 16 | const char *u32_to_str(unsigned int val); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/ringbuf.h: -------------------------------------------------------------------------------- 1 | #ifndef _RING_BUF_H_ 2 | #define _RING_BUF_H_ 3 | 4 | #include "../../platform/include/pando_types.h" 5 | #include "typedef.h" 6 | 7 | typedef struct{ 8 | U8* p_o; /**< Original pointer */ 9 | U8* volatile p_r; /**< Read pointer */ 10 | U8* volatile p_w; /**< Write pointer */ 11 | volatile I32 fill_cnt; /**< Number of filled slots */ 12 | I32 size; /**< Buffer size */ 13 | }RINGBUF; 14 | 15 | I16 RINGBUF_Init(RINGBUF *r, U8* buf, I32 size); 16 | I16 RINGBUF_Put(RINGBUF *r, U8 c); 17 | I16 RINGBUF_Get(RINGBUF *r, U8* c); 18 | #endif 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.d 34 | *.crf 35 | *.uvopt 36 | 37 | # Project files 38 | project/ 39 | 40 | # library files platform related 41 | STM32F10x_StdPeriph_Lib/ 42 | *.cproject 43 | *.project 44 | *.rej 45 | -------------------------------------------------------------------------------- /framework/lib/converter.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONVERTER_H__ 2 | #define __CONVERTER_H__ 3 | 4 | #include "../platform/include/pando_types.h" 5 | 6 | /****************************************************************************** 7 | * FunctionName : hex2bin. 8 | * Description : convert. string to bin. 9 | * Parameters : dst -- 10 | * hex_str -- 11 | * Returns : none. 12 | *******************************************************************************/ 13 | 14 | void hex2bin(uint8_t * dst, char * hex_str); 15 | 16 | const char *u32_to_str(unsigned int val); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_ldr.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_ldr.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: light dependent resistor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PERI_LDR_H__ 13 | #define __PERI_LDR_H__ 14 | 15 | #include "c_types.h" 16 | 17 | #pragma pack(1) 18 | 19 | uint16 peri_ldr_read(void); 20 | void peri_ldr_timer_read(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /example/esp8266/user/device_config.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: device_config.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description: user should add the follow user parameter here: 6 | * 1.PANDO_PRODUCT_KEY. 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | #ifndef __DEVICE_CONFIG_H__ 13 | #define __DEVICE_CONFIG_H__ 14 | 15 | #define PANDO_PRODUCT_KEY "8e5be54e561811fa9b403b5387add08ba184855227df729b0998d6898de57a9b" 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /framework/protocol/pando_machine.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name:pando_machine.h 3 | * Author: Zhao Wenwu 4 | * Versions: 0.1 5 | * Description: APIs related to different machine platform, 6 | Such as basic IO operation and some common functions. 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | 13 | #ifndef PD_MACHINE_H 14 | #define PD_MACHINE_H 15 | 16 | #include "../platform/include/pando_types.h" 17 | 18 | 19 | 20 | uint64_t pd_get_timestamp(void); 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_jdq.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_jdq.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: relay. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PERI_JDQ_H__ 13 | #define __PERI_JDQ_H__ 14 | 15 | #include "c_types.h" 16 | 17 | #pragma pack(1) 18 | 19 | void peri_jdq_init(uint8 gpio_id); 20 | uint8 peri_jdq_get(void); 21 | void peri_jdq_set(uint8 on_off); 22 | void peri_jdq_timer_set(void); 23 | #endif 24 | -------------------------------------------------------------------------------- /framework/protocol/common_functions.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: common_functions.c 3 | * Author: Zhao Wenwu 4 | * Versions: 0.1 5 | * Description: Common APIs for all platforms. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "common_functions.h" 13 | #include "../platform/include/pando_sys.h" 14 | 15 | void FUNCTION_ATTRIBUTE show_package(uint8_t *buffer, uint16_t length) 16 | { 17 | int i = 0; 18 | pd_printf("Package length: %d\ncontent is: \n", length); 19 | 20 | for (i = 0; i < length; i++) 21 | { 22 | pd_printf("%02x ",(uint8_t)buffer[i]); 23 | } 24 | 25 | pd_printf("\n"); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_motor.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_motor.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: motor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PERI_MOTOR_H__ 13 | #define __PERI_MOTOR_H__ 14 | 15 | #include "c_types.h" 16 | #include "driver/pwm.h" 17 | #include "peri_rgb_light.h" 18 | 19 | #pragma pack(1) 20 | 21 | 22 | void peri_motor_init(struct PWM_APP_PARAM motor_param,struct PWM_INIT motor_init); 23 | struct PWM_APP_PARAM peri_motor_get(void); 24 | void peri_motor_set( struct PWM_APP_PARAM motor_param); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /example/stm32/driver/usart2.h: -------------------------------------------------------------------------------- 1 | #ifndef _USART2_H 2 | #define _USART2_H 3 | 4 | #include "platform/include/pando_types.h" 5 | 6 | typedef void (* uart2_recv_callback)(uint8_t *buffer, uint16_t length); 7 | 8 | void usart2_init(void); 9 | void usart2_reset_tx_rx(void); 10 | void usart2_putchar(unsigned char ch); 11 | uint16_t usart2_send(uint8_t *buffer, uint16_t length); 12 | /****************************************************************************** 13 | * FunctionName : usart2_register_receive_cb 14 | * Description : register the callback function when uart2 receive data. 15 | * Parameters : recv_cb: the callback function specify when receive data. 16 | * Returns : none. 17 | *******************************************************************************/ 18 | void usart2_register_receive_cb(uart2_recv_callback recv); 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_rgb_light.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_tri_color_light.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: tri-colored light. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef ___PERI_RGB_LIGHT_H__ 13 | #define ___PERI_RGB_LIGHT_H__ 14 | 15 | #include "c_types.h" 16 | #include "driver/pwm.h" 17 | 18 | #pragma pack(1) 19 | 20 | 21 | 22 | //void peri_rgb_light_init(struct PWM_APP_PARAM light_param,struct PWM_INIT light_init); 23 | struct PWM_APP_PARAM peri_rgb_light_param_get(void); 24 | void peri_rgb_light_param_set( struct PWM_APP_PARAM light_param); 25 | void peri_rgb_light_param_timer_set(void); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_iaq.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_plug.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: plug. 6 | in this example:GPIO 15: the plug relay driver; 7 | GPIO 12 a blinking led; 8 | GPIO 0 the wifi connect state indicate; 9 | GPIO 13 a press key. 10 | * History: 11 | * 1.Date: 12 | * Author: 13 | * Modification: 14 | *********************************************************/ 15 | 16 | #ifndef __PERI_IAQ_H__ 17 | #define __PERI_IAQ_H__ 18 | 19 | #include "ets_sys.h" 20 | 21 | 22 | void peri_iaq_init(void); 23 | uint16 peri_iaq_read(void); 24 | uint8* peri_iaq_get(void); 25 | 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /framework/protocol/common_functions.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: common_functions.h 3 | * Author: Zhao Wenwu 4 | * Versions: 0.1 5 | * Description: Common APIs for all platforms. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | 13 | 14 | #ifndef PLATFORM_FUNCTIONS_H 15 | #define PLATFORM_FUNCTIONS_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | #ifdef ESP8266_PLANTFORM 23 | 24 | #else 25 | 26 | #include 27 | #include 28 | #include 29 | #include "../platform/include/pando_types.h" 30 | 31 | #endif 32 | 33 | #include "pando_machine.h" 34 | 35 | void show_package(uint8_t *buffer, uint16_t length); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: proto.h 3 | * Author: ThuHien 4 | * 5 | * Created on November 23, 2012, 8:57 AM 6 | */ 7 | 8 | #ifndef _PROTO_H_ 9 | #define _PROTO_H_ 10 | 11 | #include "typedef.h" 12 | #include "ringbuf.h" 13 | 14 | typedef void(PROTO_PARSE_CALLBACK)(); 15 | 16 | typedef struct{ 17 | U8 *buf; 18 | U16 bufSize; 19 | U16 dataLen; 20 | U8 isEsc; 21 | U8 isBegin; 22 | PROTO_PARSE_CALLBACK* callback; 23 | }PROTO_PARSER; 24 | 25 | I8 PROTO_Init(PROTO_PARSER *parser, PROTO_PARSE_CALLBACK *completeCallback, U8 *buf, U16 bufSize); 26 | I8 PROTO_Parse(PROTO_PARSER *parser, U8 *buf, U16 len); 27 | I16 PROTO_Add(U8 *buf, const U8 *packet, I16 bufSize); 28 | I16 PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len); 29 | I8 PROTO_ParseByte(PROTO_PARSER *parser, U8 value); 30 | I16 PROTO_ParseRb(RINGBUF *rb, U8 *bufOut, U16* len, U16 maxBufLen); 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /framework/lib/pando_json.c: -------------------------------------------------------------------------------- 1 | #include "pando_json.h" 2 | 3 | static char *json_buf; 4 | static int json_buf_len; 5 | static int pos; 6 | 7 | static int FUNCTION_ATTRIBUTE 8 | json_putchar(int c) 9 | { 10 | if (json_buf != NULL && pos < json_buf_len) 11 | { 12 | json_buf[pos++] = c; 13 | return c; 14 | } 15 | 16 | return 0; 17 | } 18 | 19 | int FUNCTION_ATTRIBUTE 20 | pando_json_print(struct jsontree_value * json_value, char * dst, int len) 21 | { 22 | if( dst == NULL) 23 | { 24 | return -1; 25 | } 26 | json_buf = dst; 27 | json_buf_len = len; 28 | pos = 0; 29 | 30 | struct jsontree_context js_ctx; 31 | js_ctx.values[0] = json_value; 32 | jsontree_reset(&js_ctx); 33 | js_ctx.putchar = json_putchar; 34 | 35 | while (jsontree_print_next(&js_ctx)); 36 | 37 | json_buf[pos] = 0; 38 | 39 | return pos; 40 | } 41 | -------------------------------------------------------------------------------- /example/esp8266/util/pando_lan_bind.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * File name: pando_lan_bind.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is to used to send device bind message to mobile phone through lan. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | **********************************************************************************/ 11 | #ifndef __PANDO_LAN_BIND_H__ 12 | #define __PANDO_LAN_BIND_H__ 13 | 14 | /****************************************************************************** 15 | * FunctionName : pando_lan_bind_init 16 | * Description : initialize the lan tcp server. 17 | * Parameters : nonde 18 | * Returns : none 19 | *******************************************************************************/ 20 | void pando_lan_bind_init(); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /framework/gateway/pando_zero_device.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_zero_device.h 3 | * Author: Chongguang Li 4 | * Versions: 1.0 5 | * Description:This module is used to process the gateway business. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef APP_PANDO_GATEWAY_PANDO_ZERO_DEVICE_H_ 13 | #define APP_PANDO_GATEWAY_PANDO_ZERO_DEVICE_H_ 14 | 15 | /****************************************************************************** 16 | * FunctionName : ipando_zero_device_init 17 | * Description : initialize the zero device(zero device is the gateway itself). 18 | * Parameters : none. 19 | * Returns : none. 20 | *******************************************************************************/ 21 | void pando_zero_device_init(void); 22 | 23 | #endif /* APP_PANDO_GATEWAY_PANDO_ZERO_DEVICE_H_ */ 24 | -------------------------------------------------------------------------------- /example/stm32/driver/jdqs.c: -------------------------------------------------------------------------------- 1 | 2 | #include "cm3_bitband.h" 3 | #include "delay.h" 4 | #include "jdqs.h" 5 | 6 | #define GPIO_JDQ1 PBout(6) 7 | 8 | void jdq_gpio_init(void) 9 | { 10 | GPIO_InitTypeDef GPIO_InitStructure; 11 | 12 | // Enable clock 13 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); 14 | 15 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 16 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 17 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 18 | GPIO_Init(GPIOB, &GPIO_InitStructure); 19 | GPIO_ResetBits(GPIOB, GPIO_Pin_6); 20 | } 21 | 22 | void set_jdq_on(void) 23 | { 24 | GPIO_JDQ1 = 1; 25 | } 26 | 27 | void set_jdq_off(void) 28 | { 29 | GPIO_JDQ1 = 0; 30 | } 31 | 32 | void togle_jdq(void) 33 | { 34 | GPIO_JDQ1 = !GPIO_JDQ1; 35 | } 36 | 37 | void set_jdq(char state) 38 | { 39 | if(state == 0) 40 | { 41 | GPIO_JDQ1 = 0; 42 | } 43 | else 44 | { 45 | GPIO_JDQ1 = 1; 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /framework/gateway/pando_device_login.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_device_login.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to login device via pando cloud api. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_DEVICE_LOGIN_H 12 | #define __PANDO_DEVICE_LOGIN_H 13 | 14 | #include "gateway_defs.h" 15 | 16 | /****************************************************************************** 17 | * FunctionName : pando_device_login 18 | * Description : try login device using pando cloud device register api. 19 | * Parameters : the specify login callback function. 20 | * Returns : 21 | *******************************************************************************/ 22 | void pando_device_login(gateway_callback callback); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /framework/gateway/pando_device_register.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_device_register.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to register device via pando cloud api. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_DEVICE_REGISTER_H 12 | #define __PANDO_DEVICE_REGISTER_H 13 | 14 | #include "gateway_defs.h" 15 | 16 | /****************************************************************************** 17 | * FunctionName : pando_device_register 18 | * Description : register pando device using pando cloud device register api. 19 | * Parameters : the specify callback function. 20 | * Returns : 21 | *******************************************************************************/ 22 | void pando_device_register(gateway_callback callback); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /framework/protocol/pando_machine.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_machine.c 3 | * Author: Zhao Wenwu 4 | * Versions: 0.1 5 | * Description: APIs related to different machine platform, 6 | Such as basic IO operation and some common functions. 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | #include 13 | 14 | #include "pando_machine.h" 15 | #include "../platform/include/pando_types.h" 16 | 17 | #ifdef ESP8266_PLANTFORM 18 | 19 | uint64_t FUNCTION_ATTRIBUTE pd_get_timestamp() 20 | { 21 | uint64_t time_now; 22 | //time_now = pando_get_system_time(); 23 | return time_now; 24 | } 25 | 26 | #else 27 | uint64_t FUNCTION_ATTRIBUTE pd_get_timestamp() 28 | { 29 | /* 30 | struct timeval now; 31 | gettimeofday(&now, NULL); 32 | return (now.tv_sec * 1000 + now.tv_usec/1000); 33 | */ 34 | return 0; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /framework/gateway/pando_gateway.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_gateway.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is the interface of the pando gateway. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PANDO_GATEWAY_H__ 13 | #define __PANDO_GATEWAY_H__ 14 | 15 | #include "../platform/include/pando_types.h" 16 | 17 | typedef enum { 18 | GATEWAY_INIT = 0, 19 | GATEWAY_REGISTER, 20 | GATEWAY_LOGIN, 21 | GATEWAY_ACCESS 22 | }GATEWAY_STATUS; 23 | 24 | /****************************************************************************** 25 | * FunctionName : pando_gateway_init 26 | * Description : initialize the gateway. 27 | * Parameters : none 28 | * Returns : none 29 | *******************************************************************************/ 30 | void pando_gateway_init(void); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /framework/gateway/pando_cloud_access.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_cloud_access.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to access to pando cloud. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_CLOUD_ACCESS_H 12 | #define __PANDO_CLOUD_ACCESS_H 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #include "gateway_defs.h" 20 | 21 | /****************************************************************************** 22 | * FunctionName : pando_cloud_access 23 | * Description : pando cloud device access api. 24 | * Parameters : access_error_callback callback:access callback function 25 | * Returns : 26 | *******************************************************************************/ 27 | void pando_cloud_access(gateway_callback callback); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /framework/platform/include/pando_timer.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * File name: pando_timer.h 3 | * Author: xiaoxiao 4 | * Versions: 1.0 5 | * Description: declare the types. 6 | * History: 7 | * 1.Date: Oct 28, 2015 8 | * Author: xiaoxiao 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef _PANDO_TIMER_H_ 13 | #define _PANDO_TIMER_H_ 14 | 15 | #include "pando_types.h" 16 | 17 | typedef void (*expiry_cb)(void* arg); 18 | 19 | //define the timer structure 20 | struct pd_timer 21 | { 22 | //the timer interval (millisecond) 23 | uint16_t interval; 24 | //whether repeat 25 | uint8_t repeated; 26 | uint8_t timer_no; 27 | //the function pointer to callback if expiry 28 | expiry_cb timer_cb; 29 | void* arg; 30 | }; 31 | 32 | 33 | void pando_timer_init(struct pd_timer * timer); 34 | 35 | void pando_timer_start(struct pd_timer * timer); 36 | 37 | void pando_timer_stop(struct pd_timer * timer); 38 | 39 | 40 | #endif /* _PANDO_TIMER_H_ */ 41 | -------------------------------------------------------------------------------- /framework/lib/pando_json.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_json.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module has some json handle utils. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PANDO_JSON_H 13 | #define __PANDO_JSON_H 14 | 15 | #include "json/jsontree.h" 16 | 17 | /****************************************************************************** 18 | * FunctionName : pando_json_print 19 | * Description : print json value to a "char *" string. 20 | * Parameters : json_value: the json_value struct ptr. 21 | * dst: the string buffer to print to. 22 | * len: the length of the output buffer. 23 | * Returns : return the length printed, -1 if error 24 | *******************************************************************************/ 25 | 26 | int pando_json_print(struct jsontree_value * json_value, char * dst, int len); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /framework/protocol/pando_endian.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_endian.h 3 | * Author: Zhao Wenwu 4 | * Versions: 0.1 5 | * Description: APIs to change endian between net and host machine. 6 | Net is big endian, host endian depends machine. 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | 13 | 14 | #ifndef PANDO_ENDIAN_H 15 | #define PANDO_ENDIAN_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | #include "common_functions.h" 23 | 24 | uint16_t net16_to_host(uint16_t A); 25 | uint32_t net32_to_host(uint32_t A); 26 | uint64_t net64_to_host(uint64_t A); 27 | float net32f_to_host(float A); 28 | double net64f_to_host(double A); 29 | 30 | #define host16_to_net net16_to_host 31 | #define host32_to_net net32_to_host 32 | #define host64_to_net net64_to_host 33 | #define host32f_to_net net32f_to_host 34 | #define host64f_to_net net64f_to_host 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | #endif 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PandoCloud 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_key.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_key.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is the key function module. 6 | 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | 13 | #ifndef PERI_KEY_H_ 14 | #define PERI_KEY_H_ 15 | 16 | 17 | #include "gpio.h" 18 | #include "../../include/os_type.h" 19 | 20 | #define CONFIG_KEY_0_IO_MUX PERIPHS_IO_MUX_GPIO4_U 21 | 22 | typedef void (* key_function)(void); 23 | 24 | struct key_param { 25 | uint8 key_level; 26 | uint8 gpio_id; 27 | os_timer_t key_5s; 28 | os_timer_t key_50ms; 29 | key_function short_press; 30 | key_function long_press; 31 | }; 32 | 33 | struct keys_param { 34 | uint8 key_num; 35 | struct key_param **single_key; 36 | }; 37 | 38 | void peri_key_short_press(void); 39 | void peri_key_long_press(void); 40 | void peri_single_key_init(uint8 gpio_id,key_function long_press, key_function short_press); 41 | 42 | 43 | #endif /* APP_INCLUDE_USER_USER_KEY_H_ */ 44 | -------------------------------------------------------------------------------- /framework/platform/include/pando_types.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * File name: pando_types.h 3 | * Author: xiaoxiao 4 | * Versions: 1.0 5 | * Description: declare the types. 6 | * History: 7 | * 1.Date: Oct 28, 2015 8 | * Author: xiaoxiao 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef _PANDO_TYPES_H_ 13 | #define _PANDO_TYPES_H_ 14 | 15 | 16 | 17 | #ifndef NULL 18 | #define NULL (void *)0 19 | #endif /* NULL */ 20 | 21 | #define BIT(nr) (1UL << (nr)) 22 | 23 | #ifdef ESP8266_PLATFORM 24 | #define FUNCTION_ATTRIBUTE ICACHE_FLASH_ATTR 25 | #include "c_types.h" 26 | #else 27 | #define FUNCTION_ATTRIBUTE 28 | #include 29 | #endif 30 | 31 | #ifndef __cplusplus 32 | typedef unsigned char bool; 33 | #define BOOL bool 34 | #define true (1) 35 | #define false (0) 36 | #define TRUE true 37 | #define FALSE false 38 | 39 | #endif /* !__cplusplus */ 40 | 41 | //define data handler callback 42 | typedef void (* data_handler_callback)(uint8_t *buffer, uint16_t length); 43 | 44 | #endif /* _PANDO_TYPES_H_ */ 45 | 46 | -------------------------------------------------------------------------------- /example/stm32/util/fifo.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: fifo.h 3 | * Author: Xiaoxiao Li 4 | * Versions:0.0.1 5 | * Description: the fifo api 6 | *********************************************************/ 7 | 8 | #ifndef FIFO_H_ 9 | #define FIFO_H_ 10 | 11 | #include "stdint.h" 12 | 13 | #define COMMAND_NUM 10 14 | #define NAME_WIDTH 48 15 | #define COMMAND_WIDTH 96 16 | 17 | #define FIFO_OK 1 18 | #define FIFO_ERROR -1 19 | 20 | struct fifo_data{ 21 | uint16_t length; 22 | uint8_t* buf; 23 | }; 24 | 25 | typedef struct FIFO { 26 | char name_buffer[COMMAND_NUM][NAME_WIDTH]; 27 | char command_buffer[COMMAND_NUM][COMMAND_WIDTH]; 28 | struct fifo_data* data[COMMAND_NUM]; 29 | unsigned int head; 30 | unsigned int tail; 31 | unsigned int size; 32 | }FIFO; 33 | 34 | int FIFO_isEmpty (struct FIFO *Fifo); 35 | void FIFO_Init (struct FIFO *Fifo); 36 | void FIFO_Empty (struct FIFO *Fifo); 37 | int FIFO_Put (struct FIFO *Fifo, char* name, char* command); 38 | int FIFO_Get (struct FIFO *Fifo, char* name, char* command); 39 | void fifo_put_data(struct FIFO *Fifo, struct fifo_data* data); 40 | struct fifo_data* fifo_get_data(struct FIFO *Fifo); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_pm25.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_plug.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: plug. 6 | in this example:GPIO 15: the plug relay driver; 7 | GPIO 12 a blinking led; 8 | GPIO 0 the wifi connect state indicate; 9 | GPIO 13 a press key. 10 | * History: 11 | * 1.Date: 12 | * Author: 13 | * Modification: 14 | *********************************************************/ 15 | 16 | #ifndef __PERI_PM25_H__ 17 | #define __PERI_PM25_H__ 18 | 19 | #define PM_SENT_START1 0x32 20 | #define PM_SENT_START2 0x3d 21 | typedef struct 22 | { 23 | uint8 start_byte1; 24 | uint8 start_byte2; 25 | uint16 length; 26 | uint16 pm1_0; 27 | uint16 pm2_5; 28 | uint16 pm10_0; 29 | uint16 um0_3; 30 | uint16 um0_5; 31 | uint16 um1_0; 32 | uint16 um2_5; 33 | uint16 um5_0; 34 | uint16 um10_0; 35 | uint16 save[4]; 36 | uint16 crc; 37 | }PM25_REV_DATA; 38 | 39 | void display_PMdevice_data(PM25_REV_DATA *data_buffer); 40 | uint16 peri_pm_25_get(void); 41 | 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /framework/gateway/pando_channel.c: -------------------------------------------------------------------------------- 1 | #include "pando_channel.h" 2 | #include "../platform/include/pando_sys.h" 3 | 4 | #define MAX_CHAN_LEN 8 5 | 6 | struct pando_channel 7 | { 8 | PANDO_CHANNEL_NAME name; 9 | channel_recv_callback subdevice_cb; 10 | channel_recv_callback device_cb; 11 | }; 12 | 13 | static struct pando_channel channels[MAX_CHAN_LEN]; 14 | 15 | void FUNCTION_ATTRIBUTE 16 | on_subdevice_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb) 17 | { 18 | channels[name].subdevice_cb = cb; 19 | } 20 | 21 | void FUNCTION_ATTRIBUTE 22 | on_device_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb) 23 | { 24 | channels[name].device_cb = cb; 25 | } 26 | 27 | void FUNCTION_ATTRIBUTE 28 | channel_send_to_subdevice(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length) 29 | { 30 | if(channels[name].subdevice_cb != NULL ){ 31 | channels[name].subdevice_cb(buffer, length); 32 | } 33 | } 34 | 35 | void FUNCTION_ATTRIBUTE 36 | channel_send_to_device(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length) 37 | { 38 | pd_printf("send package to device\n"); 39 | if(channels[name].device_cb != NULL ){ 40 | channels[name].device_cb(buffer, length); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /framework/platform/src/esp8266/pando_timer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../../include/pando_timer.h" 3 | #include "os_type.h" 4 | #include "osapi.h" 5 | static os_timer_t timer1; 6 | static os_timer_t timer2; 7 | void FUNCTION_ATTRIBUTE 8 | pando_timer_init(struct pd_timer * timer) 9 | { 10 | if(timer->timer_no==1) 11 | { 12 | os_timer_disarm(&timer1); 13 | os_timer_setfn(&timer1, (os_timer_func_t *)timer->timer_cb, timer->arg); 14 | os_timer_arm(&timer1, timer->interval, timer->repeated); 15 | } 16 | if(timer->timer_no==2) 17 | { 18 | os_timer_disarm(&timer2); 19 | os_timer_setfn(&timer2, (os_timer_func_t *)timer->timer_cb, timer->arg); 20 | os_timer_arm(&timer2, timer->interval, timer->repeated); 21 | } 22 | } 23 | 24 | void FUNCTION_ATTRIBUTE 25 | pando_timer_start(struct pd_timer * timer) 26 | { 27 | if(timer->timer_no==1) 28 | { 29 | os_timer_arm(&timer1, timer->interval, timer->repeated); 30 | } 31 | if(timer->timer_no==2) 32 | { 33 | os_timer_arm(&timer2, timer->interval, timer->repeated); 34 | } 35 | } 36 | void FUNCTION_ATTRIBUTE 37 | pando_timer_stop(struct pd_timer * timer) 38 | { 39 | if(timer->timer_no==1) 40 | { 41 | os_timer_disarm(&timer1); 42 | } 43 | if(timer->timer_no==2) 44 | { 45 | os_timer_disarm(&timer2); 46 | 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /framework/gateway/gateway_defs.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: gateway_defs.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is to used to define the parameter and structure used in gateway. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __GATEWAY_DEFS_H__ 13 | #define __GATEWAY_DEFS_H__ 14 | 15 | #include "../platform/include/pando_types.h" 16 | 17 | #define PANDO_API_URL "https://api.pandocloud.com" 18 | #define DATANAME_DEVICE_ID "pando_device_id" 19 | #define DATANAME_DEVICE_SECRET "pando_device_secret" 20 | #define DATANAME_DEVICE_KEY "pando_device_key" 21 | #define DATANAME_ACCESS_TOKEN "pando_access_token" 22 | #define DATANAME_ACCESS_ADDR "pando_access_addr" 23 | 24 | #define PANDO_KEEPALIVE_TIME 30 25 | 26 | #define PANDO_DEVICE_MODULE "esp8266" 27 | 28 | #define PANDO_SDK_VERSION "0.0.1" 29 | 30 | typedef void(*gateway_callback)(int8_t result); 31 | 32 | #define PANDO_REGISTER_OK 0 33 | #define PANDO_LOGIN_OK 1 34 | #define PANDO_REGISTER_FAIL -1 35 | #define PANDO_NOT_REGISTERED -2 36 | #define PANDO_LOGIN_FAIL -3 37 | #define PANDO_ACCESS_ERR -4 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /framework/subdevice/pando_subdevice.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_subdevice.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description:This module is to used to handle subdevice logic. 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: initial code 10 | *********************************************************/ 11 | #ifndef PANDO_SUBDEVICE_H_ 12 | #define PANDO_SUBDEVICE_H_ 13 | 14 | #include "../platform/include/pando_types.h" 15 | 16 | /****************************************************************************** 17 | * FunctionName : pando_subdevice_recv. 18 | * Description : process buffer receive from channel. 19 | * Parameters : the buffer and length from channel. 20 | * Returns : none. 21 | *******************************************************************************/ 22 | void pando_subdevice_recv(uint8_t * buffer, uint16_t length); 23 | 24 | /****************************************************************************** 25 | * FunctionName : report_event. 26 | * Description : report the specify event. 27 | * Parameters : no: the event no. 28 | * Returns : none. 29 | *******************************************************************************/ 30 | void report_event(uint8_t no); 31 | 32 | #endif /* PANDO_SUBDEVICE_H_ */ 33 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_ldr.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_ldr.c 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: light dependent resistor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_ldr.h" 13 | 14 | #include "user_interface.h" 15 | #include "driver/adc.h" 16 | #include "driver/tisan_gpio.h" 17 | #include "c_types.h" 18 | #include "gpio.h" 19 | /****************************************************************************** 20 | * FunctionName : peri_lsr_read 21 | * Description : read lsr value 22 | * Parameters : none 23 | * Returns : none 24 | *******************************************************************************/ 25 | uint16 ICACHE_FLASH_ATTR 26 | peri_ldr_read(void) 27 | { 28 | return adc_read(); 29 | } 30 | /****************************************************************************** 31 | * FunctionName : peri_lsr_timer_read 32 | * Description : peri_lsr_timer_read 33 | * Parameters : none 34 | * Returns : none 35 | *******************************************************************************/ 36 | void ICACHE_FLASH_ATTR 37 | peri_ldr_timer_read(void) 38 | { 39 | uint16 value; 40 | value = peri_lsr_read(); 41 | PRINTF("lsr_value=%d\n",value); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /example/stm32/util/fifo.c: -------------------------------------------------------------------------------- 1 | #include "FIFO.h" 2 | #include "stdio.h" 3 | #include "string.h" 4 | 5 | void FIFO_Init (struct FIFO *Fifo){ 6 | Fifo->head = 0; 7 | Fifo->tail = 0; 8 | Fifo->size = 0; 9 | } 10 | 11 | void FIFO_Empty (struct FIFO *Fifo){ 12 | Fifo->head = Fifo->tail; 13 | Fifo->size = 0; 14 | } 15 | 16 | int FIFO_isEmpty(struct FIFO *Fifo){ 17 | return Fifo->size == 0; 18 | } 19 | 20 | int FIFO_isFull(struct FIFO *Fifo){ 21 | printf("fifo used:%d/%d\n", Fifo->size, COMMAND_NUM); 22 | return Fifo->size == COMMAND_NUM; 23 | } 24 | 25 | int FIFO_Put (struct FIFO *Fifo, char* name, char* command) 26 | { 27 | if (FIFO_isFull(Fifo)){ 28 | return FIFO_ERROR; 29 | } 30 | 31 | strcpy((Fifo->name_buffer)[Fifo->head], name); 32 | strcpy((Fifo->command_buffer)[Fifo->head], command); 33 | Fifo->head = (Fifo->head + 1) % (COMMAND_NUM); 34 | Fifo->size++; 35 | return FIFO_OK; 36 | } 37 | 38 | void fifo_put_data(struct FIFO *Fifo, struct fifo_data* data) 39 | { 40 | (Fifo->data)[Fifo->head] = data; 41 | } 42 | 43 | int FIFO_Get(struct FIFO *Fifo, char *name, char *command) 44 | { 45 | if (FIFO_isEmpty(Fifo)) 46 | { 47 | return FIFO_ERROR; 48 | } 49 | strcpy(name,(Fifo->name_buffer)[Fifo->tail]); 50 | strcpy(command, (Fifo->command_buffer)[Fifo->tail]); 51 | Fifo->tail = (Fifo->tail + 1) % (COMMAND_NUM); 52 | Fifo->size--; 53 | return FIFO_OK; 54 | } 55 | 56 | struct fifo_data* fifo_get_data(struct FIFO *Fifo) 57 | { 58 | return (Fifo->data)[Fifo->tail]; 59 | } 60 | -------------------------------------------------------------------------------- /framework/platform/src/at_stm32/pando_net_http.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_net_http.c 3 | * Author:Chongguang Li 4 | * Versions:0.0.1 5 | * Description: the http api 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "pando_net_http.h" 13 | #include "sim5360.h" 14 | 15 | /****************************************************************************** 16 | * FunctionName : net_http_post 17 | * Description : the http post api. 18 | * Parameters : url: the url. 19 | * data: the post data. 20 | * http_cb: the specify function called after post successfully. 21 | * Returns : none 22 | *******************************************************************************/ 23 | void net_http_post(const char* url, const char* data, http_callback http_cb) 24 | { 25 | module_http_post(url, data, (module_http_callback)http_cb); 26 | } 27 | 28 | /****************************************************************************** 29 | * FunctionName : net_http_get 30 | * Description : the http get api. 31 | * Parameters : url: the url. 32 | * http_cb: the specify function called after post successfully. 33 | * Returns : none 34 | *******************************************************************************/ 35 | void net_http_get(const char* url, http_callback http_cb) 36 | { 37 | 38 | } 39 | -------------------------------------------------------------------------------- /example/esp8266/util/httpclient.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPCLIENT_H 2 | #define HTTPCLIENT_H 3 | 4 | #define BUFFER_SIZE_MAX 5000 5 | 6 | /* 7 | * "full_response" is a string containing all response headers and the response body. 8 | * "response_body and "http_status" are extracted from "full_response" for convenience. 9 | * 10 | * A successful request corresponds to an HTTP status code of 200 (OK). 11 | * More info at http://en.wikipedia.org/wiki/List_of_HTTP_status_codes 12 | */ 13 | typedef void (* http_callback)(char * response_body, int http_status, char * full_response); 14 | 15 | /* 16 | * Download a web page from its URL. 17 | * Try: 18 | * http_get("http://wtfismyip.com/text", http_callback_example); 19 | */ 20 | void http_get(const char * url, http_callback user_callback); 21 | 22 | /* 23 | * Post data to a web form. 24 | * The data should be encoded as application/x-www-form-urlencoded. 25 | * Try: 26 | * http_post("http://httpbin.org/post", "first_word=hello&second_word=world", http_callback_example); 27 | */ 28 | void http_post(const char * url, const char * post_data, http_callback user_callback); 29 | 30 | /* 31 | * Call this function to skip URL parsing if the arguments are already in separate variables. 32 | */ 33 | void http_raw_request(const char * hostname, int port, const char * path, const char * post_data, http_callback user_callback); 34 | 35 | /* 36 | * Output on the UART. 37 | */ 38 | void http_callback_example(char * response, int http_status, char * full_response); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /framework/platform/src/at_stm32/platform_miscellaneous_interface.c: -------------------------------------------------------------------------------- 1 | #include "../include/pando_sys.h" 2 | #include "../include/pando_types.h" 3 | #include "sim5360.h" 4 | 5 | extern uint8_t g_imei_buf[16]; 6 | 7 | /****************************************************************************** 8 | * FunctionName : net_connect_check 9 | * Description : check whether the platform connect the net. 10 | * Parameters : none. 11 | * Returns : 1: the platform connect the net OK. 12 | * 0: the platform dose not connect the net. 13 | *******************************************************************************/ 14 | bool net_connect_check(void) 15 | { 16 | // TODO: the acquired signal quality is not the current value, but the last inquired value. 17 | uint8_t signal_quality = 0; 18 | signal_quality = inquire_signal_quality(); 19 | if( signal_quality> MIN_SIGNAL_QUAILTY) 20 | { 21 | return 1; 22 | } 23 | else 24 | { 25 | return 0; 26 | } 27 | } 28 | 29 | /****************************************************************************** 30 | * FunctionName : get_device_serial 31 | * Description : get the unique identification of the device, such as mac address of internet device or imei of mobile device. 32 | * Parameters : serial_buf: the buf storage the serial. 33 | * Returns : none. 34 | *******************************************************************************/ 35 | void get_device_serial(char* serial_buf) 36 | { 37 | pd_memcpy(serial_buf, g_imei_buf, sizeof(g_imei_buf)); 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /framework/subdevice/pando_event.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_event.h 3 | * Author: wfq 4 | * Versions: 1.0 5 | * Description: pando object interfaces 6 | * History: 7 | * 1.Date: Jan 14, 2016 8 | * Author: wfq 9 | * Create: 10 | *********************************************************/ 11 | 12 | #ifndef PANDO_EVENT_H_ 13 | #define PANDO_EVENT_H_ 14 | 15 | #include "../platform/include/pando_types.h" 16 | //#include "../protocol/sub_device_protocol.h" 17 | 18 | typedef struct TLVs PARAMS; 19 | 20 | typedef struct { 21 | uint8_t no; 22 | uint8_t priority; 23 | void (*pack)(PARAMS*); 24 | }pd_event; 25 | 26 | /****************************************************************************** 27 | * FunctionName : register_pando_event. 28 | * Description : register a pando event to framework. 29 | * Parameters : a pando event. 30 | * Returns : none. 31 | *******************************************************************************/ 32 | void register_pando_event(pd_event event); 33 | 34 | /****************************************************************************** 35 | * FunctionName : find_pando_event. 36 | * Description : find a pando event by event no. 37 | * Parameters : the event no. 38 | * Returns : the pando event of specified no, NULL if not found. 39 | *******************************************************************************/ 40 | pd_event* find_pando_event(uint8_t no); 41 | 42 | #endif /* PANDO_EVENT_H_ */ 43 | -------------------------------------------------------------------------------- /framework/platform/include/platform_miscellaneous_interface.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: platform_miscellaneous_interface.h 3 | * Author: Chongguang Li 4 | * Versions: 1.0 5 | * Description:This module includes platform relationship api. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: Chongguang Li 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef _PLATFORM_MISCELLANEOUS_INTERFACE_H 12 | #define _PLATFORM_MISCELLANEOUS_INTERFACE_H 13 | 14 | #include "pando_types.h" 15 | 16 | /****************************************************************************** 17 | * FunctionName : net_connect_check 18 | * Description : check whether the platform connect the net. 19 | * Parameters : none. 20 | * Returns : 1: the platform connect the net OK. 21 | * 0: the platform dose not connect the net. 22 | *******************************************************************************/ 23 | bool net_connect_check(void); 24 | 25 | /****************************************************************************** 26 | * FunctionName : get_device_serial 27 | * Description : get the unique identification of the device, such as mac address of internet device or imei of mobile device. 28 | * Parameters : serial_buf: the buf storage the serial. 29 | * Returns : none. 30 | *******************************************************************************/ 31 | void get_device_serial(char* serial_buf); 32 | 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /framework/subdevice/pando_event.c: -------------------------------------------------------------------------------- 1 | 2 | #include "pando_event.h" 3 | #include "../platform/include/pando_sys.h" 4 | #include "../protocol/pando_machine.h" 5 | 6 | #define MAX_EVENTS 16 7 | 8 | static pd_event s_pando_event_list[MAX_EVENTS]; 9 | static int s_pando_event_list_idx = 0; 10 | 11 | /****************************************************************************** 12 | * FunctionName : register_pando_event. 13 | * Description : register a pando event to framework. 14 | * Parameters : a pando event. 15 | * Returns : none. 16 | *******************************************************************************/ 17 | void FUNCTION_ATTRIBUTE 18 | register_pando_event(pd_event event) 19 | { 20 | if(s_pando_event_list_idx > MAX_EVENTS - 1) 21 | { 22 | return; 23 | } 24 | 25 | s_pando_event_list[s_pando_event_list_idx++] = event; 26 | } 27 | 28 | /****************************************************************************** 29 | * FunctionName : find_pando_event. 30 | * Description : find a pando event by event no. 31 | * Parameters : the event no. 32 | * Returns : the pando event of specified no, NULL if not found. 33 | *******************************************************************************/ 34 | pd_event* FUNCTION_ATTRIBUTE 35 | find_pando_event(uint8_t no) 36 | { 37 | int i; 38 | for(i = 0; i < s_pando_event_list_idx; i++) 39 | { 40 | if( s_pando_event_list[i].no == no) 41 | { 42 | return &s_pando_event_list[i]; 43 | } 44 | } 45 | 46 | return NULL; 47 | } 48 | -------------------------------------------------------------------------------- /framework/subdevice/pando_command.c: -------------------------------------------------------------------------------- 1 | 2 | #include "pando_command.h" 3 | #include "../platform/include/pando_sys.h" 4 | #include "../protocol/pando_machine.h" 5 | 6 | #define MAX_COMMANDS 16 7 | 8 | static pd_command s_pando_command_list[MAX_COMMANDS]; 9 | static int s_pando_command_list_idx = 0; 10 | 11 | /****************************************************************************** 12 | * FunctionName : register_pando_command. 13 | * Description : register a pando command to framework. 14 | * Parameters : a pando command. 15 | * Returns : none. 16 | *******************************************************************************/ 17 | void FUNCTION_ATTRIBUTE 18 | register_pando_command(pd_command cmd) 19 | { 20 | if(s_pando_command_list_idx > MAX_COMMANDS - 1) 21 | { 22 | return; 23 | } 24 | 25 | s_pando_command_list[s_pando_command_list_idx++] = cmd; 26 | } 27 | 28 | /****************************************************************************** 29 | * FunctionName : find_pando_command. 30 | * Description : find a pando command by command no. 31 | * Parameters : the command no. 32 | * Returns : the pando command of specified no, NULL if not found. 33 | *******************************************************************************/ 34 | pd_command* FUNCTION_ATTRIBUTE 35 | find_pando_command(uint8_t no) 36 | { 37 | int i; 38 | for(i = 0; i < s_pando_command_list_idx; i++) 39 | { 40 | if( s_pando_command_list[i].no == no) 41 | { 42 | return &s_pando_command_list[i]; 43 | } 44 | } 45 | return NULL; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /example/stm32/driver/timer4.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name锛� timer4.h 3 | * Author : pd 4 | * Versions : 1.0 5 | * Description: timer4 set 6 | * History: 7 | * 1.Date: 2015-7-2 8 | * Author: pd 9 | * Action: create 10 | *********************************************************/ 11 | 12 | #ifndef _TIMER4_H_ 13 | #define _TIMER4_H_ 14 | 15 | #include 16 | 17 | typedef void (*time4_callback)(void *arg); 18 | 19 | /****************************************************************************** 20 | * FunctionName : timer4_init 21 | * Description : init timer4. 22 | * Parameters : time_set: the set time, uint is ms. 23 | * Returns : 24 | ******************************************************************************/ 25 | void timer4_init(uint16_t time_set, uint8_t repeat_flag, time4_callback time4_cb); 26 | 27 | /****************************************************************************** 28 | * FunctionName : timer1_start 29 | * Description : start timer1. 30 | * Parameters : 31 | * Returns : 32 | ******************************************************************************/ 33 | void timer4_start(void); 34 | 35 | /****************************************************************************** 36 | * FunctionName : timer1_stop 37 | * Description : stop timer1. 38 | * Parameters : 39 | * Returns : 40 | ******************************************************************************/ 41 | void timer4_stop(void); 42 | 43 | #endif /* _PANDO_TIMER_H_ */ 44 | 45 | -------------------------------------------------------------------------------- /example/stm32/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pando_framework.h" 3 | #include "usart1.h" 4 | #include "usart2.h" 5 | #include "sim5360.h" 6 | #include 7 | #include "task.h" 8 | #include "delay.h" 9 | #include "malloc.h" 10 | #include "led.h" 11 | 12 | char* g_product_key_buf = "d0375b4180f1ddc44c89a2046e8b841a7d2b642303a026bfc101aa0e448b6dee"; 13 | //char* g_product_key_buf = "fedf2397677f5a03e4cd0e18994e54aeeada7a4fe514bcbaf03c4d2c6f19317e" ; 14 | //char* g_product_key_buf = "b4d967f08c43636cf78c1c6bb1e5835a1795483802b66826f853fe5640ef16ab"; 15 | 16 | char* g_server_url = "https://120.24.222.147"; 17 | //char* g_server_url = "https://api.pandocloud.com"; 18 | 19 | int main(void) 20 | { 21 | usart1_init(); 22 | usart2_init(); 23 | led_object_init(); 24 | delay_init(); 25 | mem_init(); 26 | task *task; 27 | printf("system start\n"); 28 | while(1) 29 | { 30 | if(MODULE_OFF_LINE == get_module_status()) 31 | { 32 | module_system_start(); 33 | } 34 | else if(MODULE_SYNC == get_module_status()) 35 | { 36 | module_system_init(); 37 | } 38 | else if(MODULE_GET_IP == get_module_status()) 39 | { 40 | set_module_status(MODULE_INIT_DONE); 41 | printf("start gateway!\n"); 42 | pando_framework_init(); 43 | } 44 | while((task = pop_task()) != NULL) 45 | { 46 | printf("begin to execute task! %p\r\n", task); 47 | if(task->handler != NULL) 48 | { 49 | task->handler(task->pdata); 50 | } 51 | 52 | if(task != NULL) 53 | { 54 | free(task); 55 | task = NULL; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /example/esp8266/user/wifi_config.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: wifi_config.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description: this module is used to config the wifi ssid and password. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __WIFI_CONFIG_H__ 12 | #define __WIFI_CONFIG_H__ 13 | 14 | typedef enum { 15 | CONFIG_TIMEOUT = -1, 16 | CONFIG_OK 17 | } CONFIG_RESULT; 18 | 19 | 20 | /* 21 | callback function after config. 22 | */ 23 | typedef void (* wifi_config_callback)(CONFIG_RESULT result); 24 | 25 | 26 | /****************************************************************************** 27 | * FunctionName : get_wifi_config_state 28 | * Description : get the wifi config state. 29 | * Parameters : none. 30 | * Returns : 1: the device is in wifi config state. 31 | * 0: the device is not in wifi config state. 32 | *******************************************************************************/ 33 | bool get_wifi_config_state(); 34 | 35 | /****************************************************************************** 36 | * FunctionName : wifi_config 37 | * Description : configure the gateway wifi SSID and password. 38 | * Parameters : config_cb: the call back function after config, can be NULL. 39 | * Returns : none 40 | *******************************************************************************/ 41 | void wifi_config(wifi_config_callback config_cb); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /framework/platform/include/pando_net_http.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_net_http.h 3 | * Author:Chongguang Li 4 | * Versions:0.0.1 5 | * Description: the http api 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef _PANDO_NET_HTTP_H_ 13 | #define _PANDO_NET_HTTP_H_ 14 | 15 | #include "pando_types.h" 16 | 17 | #define BUFFER_SIZE_MAX 5000 18 | 19 | typedef void (* http_callback)(char* response); 20 | 21 | /****************************************************************************** 22 | * FunctionName : net_http_post 23 | * Description : the http post api. 24 | * Parameters : url: the url. 25 | * data: the post data. 26 | * http_cb: the specify function called after post successfully. 27 | * Returns : none 28 | *******************************************************************************/ 29 | void net_http_post(const char* url, const char* data, http_callback http_cb); 30 | 31 | /****************************************************************************** 32 | * FunctionName : net_http_get 33 | * Description : the http get api. 34 | * Parameters : url: the url. 35 | * http_cb: the specify function called after post successfully. 36 | * Returns : none 37 | *******************************************************************************/ 38 | void net_http_get(const char* url, http_callback http_cb); 39 | 40 | #endif /* _PANDO_NET_HTTP_H_ */ 41 | -------------------------------------------------------------------------------- /framework/subdevice/pando_command.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_command.h 3 | * Author: wfq 4 | * Versions: 1.0 5 | * Description: pando object interfaces 6 | * History: 7 | * 1.Date: Jan 14, 2016 8 | * Author: wfq 9 | * create: 10 | *********************************************************/ 11 | 12 | #ifndef PANDO_COMMAND_H_ 13 | #define PANDO_COMMAND_H_ 14 | 15 | #include "../platform/include/pando_types.h" 16 | //#include "../protocol/sub_device_protocol.h" 17 | 18 | typedef struct TLVs PARAMS; 19 | 20 | typedef struct { 21 | uint8_t no; 22 | uint8_t priority; 23 | void (*unpack)(PARAMS*); 24 | }pd_command; 25 | 26 | /****************************************************************************** 27 | * FunctionName : register_pando_command. 28 | * Description : register a pando command to framework. 29 | * Parameters : a pando command. 30 | * Returns : none. 31 | *******************************************************************************/ 32 | void register_pando_command(pd_command cmd); 33 | 34 | /****************************************************************************** 35 | * FunctionName : find_pando_command. 36 | * Description : find a pando command by command no. 37 | * Parameters : the command no. 38 | * Returns : the pando command of specified no, NULL if not found. 39 | *******************************************************************************/ 40 | pd_command* find_pando_command(uint8_t no); 41 | 42 | #endif /* PANDO_OBJECTS_H_ */ 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/gpio16.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "osapi.h" 3 | #include "gpio16.h" 4 | 5 | void ICACHE_FLASH_ATTR 6 | gpio16_output_conf(void) 7 | { 8 | WRITE_PERI_REG(PAD_XPD_DCDC_CONF, 9 | (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0 10 | 11 | WRITE_PERI_REG(RTC_GPIO_CONF, 12 | (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable 13 | 14 | WRITE_PERI_REG(RTC_GPIO_ENABLE, 15 | (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable 16 | } 17 | 18 | void ICACHE_FLASH_ATTR 19 | gpio16_output_set(uint8 value) 20 | { 21 | WRITE_PERI_REG(RTC_GPIO_OUT, 22 | (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1)); 23 | } 24 | 25 | void ICACHE_FLASH_ATTR 26 | gpio16_input_conf(void) 27 | { 28 | WRITE_PERI_REG(PAD_XPD_DCDC_CONF, 29 | (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection 30 | 31 | WRITE_PERI_REG(RTC_GPIO_CONF, 32 | (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable 33 | 34 | WRITE_PERI_REG(RTC_GPIO_ENABLE, 35 | READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable 36 | } 37 | 38 | uint8 ICACHE_FLASH_ATTR 39 | gpio16_input_get(void) 40 | { 41 | return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1); 42 | } 43 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/pwm.h: -------------------------------------------------------------------------------- 1 | #ifndef __PWM_H__ 2 | #define __PWM_H__ 3 | 4 | #include "../peri_rgb_light.h" 5 | 6 | #define PWM_CHANNEL_MAX 5 7 | 8 | struct PWM_APP_PARAM 9 | { 10 | uint16 pwm_freq; //100hz typically 11 | uint8 pwm_duty[PWM_CHANNEL_MAX]; // the sequence is red, green, blue. 12 | uint8 pad[1]; // the save data must aligned. 13 | }; 14 | struct PWM_INIT 15 | { 16 | uint8 io_num; //pwm io number 17 | uint8 io_id[PWM_CHANNEL_MAX]; //list pwm io id 18 | }; 19 | 20 | struct pwm_single_param { 21 | uint16 gpio_set; 22 | uint16 gpio_clear; 23 | uint32 h_time; 24 | }; 25 | 26 | struct pwm_param { 27 | uint32 period; 28 | uint16 freq; 29 | uint8 duty[PWM_CHANNEL_MAX]; 30 | }; 31 | 32 | #define PWM_DEPTH 255 33 | 34 | #define PWM_1S 1000000 35 | 36 | #define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U 37 | #define PWM_0_OUT_IO_NUM 15 38 | #define PWM_0_OUT_IO_FUNC FUNC_GPIO15 39 | 40 | #define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTMS_U 41 | #define PWM_1_OUT_IO_NUM 14 42 | #define PWM_1_OUT_IO_FUNC FUNC_GPIO14 43 | 44 | #define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U 45 | #define PWM_2_OUT_IO_NUM 13 46 | #define PWM_2_OUT_IO_FUNC FUNC_GPIO13 47 | 48 | #define PERI_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U 49 | #define PERI_0_OUT_IO_NUM 12 50 | #define PERI_0_OUT_IO_FUNC FUNC_GPIO12 51 | 52 | 53 | //void pwm_init(struct LIGHT_PARAM light_param,struct LIGHT_INIT light_init); 54 | 55 | void pwm_start(void); 56 | 57 | void pwm_set_duty(uint8 duty, uint8 channel); 58 | uint8 pwm_get_duty(uint8 channel); 59 | void pwm_set_freq(uint16 freq); 60 | uint16 pwm_get_freq(void); 61 | #endif 62 | 63 | 64 | -------------------------------------------------------------------------------- /framework/platform/src/esp8266/platform_miscellaneous_interface.c: -------------------------------------------------------------------------------- 1 | #include "os_type.h" 2 | #include "osapi.h" 3 | #include "espconn.h" 4 | #include "user_interface.h" 5 | 6 | //char* g_product_key_buf = "8e5be54e561811fa9b403b5387add08ba184855227df729b0998d6898de57a9b"; 7 | //#define SERVER_ADDRESS "https://api.pandocloud.com" 8 | 9 | /****************************************************************************** 10 | * FunctionName : wifi_connect_check 11 | * Description : check the wifi connect status. if device has connected the wifi, 12 | * start the gateway flow. 13 | * Parameters : none 14 | * Returns : none 15 | *******************************************************************************/ 16 | bool ICACHE_FLASH_ATTR 17 | net_connect_check(void) 18 | { 19 | struct ip_info device_ip; 20 | uint8 connect_status = 0; 21 | wifi_get_ip_info(STATION_IF, &device_ip); 22 | connect_status = wifi_station_get_connect_status(); 23 | if (connect_status == STATION_GOT_IP && device_ip.ip.addr != 0) 24 | { 25 | // device has connected the wifi. 26 | 27 | // the device is in wifi config mode, waiting for wifi config mode over. 28 | if(get_wifi_config_state() == 1) 29 | { 30 | return 0; 31 | } 32 | return 1; 33 | } 34 | else 35 | { 36 | PRINTF("WIFI status: not connected\n"); 37 | return 0; 38 | } 39 | } 40 | 41 | void ICACHE_FLASH_ATTR 42 | get_device_serial(char* serial_buf) 43 | { 44 | char device_sta_mac[6]; 45 | wifi_get_macaddr(STATION_IF,device_sta_mac); 46 | os_sprintf(serial_buf, "%02x%02x%02x%02x%02x%02x", device_sta_mac[0], device_sta_mac[1], device_sta_mac[2], device_sta_mac[3] \ 47 | , device_sta_mac[4], device_sta_mac[5]); 48 | PRINTF("device_serial:%s\n", serial_buf); 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_led.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_led.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the led. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef APP_PERIPHERAL_PERI_LED_H_ 13 | #define APP_PERIPHERAL_PERI_LED_H_ 14 | 15 | #include "c_types.h" 16 | 17 | typedef enum { 18 | BLINK_QUICK = 50, 19 | BLINK_SLOW = 1000 20 | }BLINK_SPEED; 21 | 22 | /****************************************************************************** 23 | * FunctionName : peri_led_init. 24 | * Description : initialize the led. 25 | * Parameters : uint8 gpio_id: the gpio pin drive the led. 26 | * Returns : none 27 | *******************************************************************************/ 28 | void peri_led_init(uint8 gpio_id); 29 | 30 | /****************************************************************************** 31 | * FunctionName : peri_led_blink. 32 | * Description : blink the led. 33 | * Parameters : BLINK_SPEED speed: the blink speed. 34 | * Returns : none 35 | *******************************************************************************/ 36 | void peri_led_blink(BLINK_SPEED speed); 37 | 38 | /****************************************************************************** 39 | * FunctionName : peri_led_set. 40 | * Description : set the led state. 41 | * Parameters : bool state: the set state of the led, 1:on ; 0:off. 42 | * Returns : none 43 | *******************************************************************************/ 44 | void peri_led_set(bool state); 45 | 46 | #endif /* APP_PERIPHERAL_PERI_LED_H_ */ 47 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_H__ 2 | #define __I2C_H__ 3 | #endif 4 | 5 | /* 6 | I2C driver for the ESP8266 7 | Copyright (C) 2014 Rudy Hardeman (zarya) 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License along 20 | with this program; if not, write to the Free Software Foundation, Inc., 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | */ 23 | 24 | #include "ets_sys.h" 25 | #include "osapi.h" 26 | #include "gpio.h" 27 | 28 | #define I2C_SLEEP_TIME 10 29 | 30 | //SDA on GPIO2 31 | #define I2C_SDA_MUX PERIPHS_IO_MUX_GPIO2_U 32 | #define I2C_SDA_FUNC FUNC_GPIO2 33 | #define I2C_SDA_PIN 2 34 | 35 | //SCK on GPIO14 36 | //#define I2C_SCK_MUX PERIPHS_IO_MUX_MTMS_U 37 | //#define I2C_SCK_FUNC FUNC_GPIO14 38 | //#define I2C_SCK_PIN 14 39 | 40 | //SCK on GPIO0 41 | #define I2C_SCK_MUX PERIPHS_IO_MUX_GPIO0_U 42 | #define I2C_SCK_PIN 0 43 | #define I2C_SCK_FUNC FUNC_GPIO0 44 | 45 | #define i2c_read() GPIO_INPUT_GET(GPIO_ID_PIN(I2C_SDA_PIN)); 46 | 47 | void i2c_init(void); 48 | void i2c_start(void); 49 | void i2c_stop(void); 50 | void i2c_send_ack(uint8 state); 51 | uint8 i2c_check_ack(void); 52 | uint8 i2c_readByte(void); 53 | void i2c_writeByte(uint8 data); 54 | -------------------------------------------------------------------------------- /example/stm32/util/delay.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: delay.c 3 | * Author : wfq 4 | * Versions : 1.0 5 | * Description: dev delay 6 | * History: 7 | * 1.Date: 2014-12-10 8 | * Author: wfq 9 | * Action: create 10 | *********************************************************/ 11 | 12 | #include "stm32f10x.h" 13 | #include "delay.h" 14 | 15 | static uint8_t fac_us=0; //us延时倍乘数 16 | static uint16_t fac_ms=0; //ms延时倍乘数 17 | 18 | //初始化延迟函数 19 | //SYSTICK的时钟固定为HCLK时钟的1/8 20 | //SYSCLK:系统时钟 21 | void delay_init() 22 | { 23 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //选择外部时钟 HCLK/8 24 | fac_us=SystemCoreClock/8000000; //为系统时钟的1/8 25 | fac_ms=(u16)fac_us*1000; //非ucos下,代表每个ms需要的systick时钟数 26 | } 27 | 28 | //延时nus 29 | //nus为要延时的us数. 30 | void delay_us(uint32_t nus) 31 | { 32 | uint32_t temp; 33 | SysTick->LOAD=nus*fac_us; //时间加载 34 | SysTick->VAL=0x00; //清空计数器 35 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 36 | do 37 | { 38 | temp=SysTick->CTRL; 39 | } 40 | while(temp&0x01&&!(temp&(1<<16)));//等待时间到达 41 | 42 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器 43 | SysTick->VAL =0X00; //清空计数器 44 | } 45 | 46 | //延时nms 47 | //注意nms的范围 48 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 49 | //nms<=0xffffff*8*1000/SYSCLK 50 | //SYSCLK单位为Hz,nms单位为ms 51 | //对72M条件下,nms<=1864 52 | void delay_ms(uint16_t nms) 53 | { 54 | uint32_t temp; 55 | SysTick->LOAD=(uint32_t)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 56 | SysTick->VAL =0x00; //清空计数器 57 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 58 | do 59 | { 60 | temp=SysTick->CTRL; 61 | } 62 | while(temp&0x01&&!(temp&(1<<16)));//等待时间到达 63 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器 64 | SysTick->VAL =0X00; //清空计数器 65 | } 66 | -------------------------------------------------------------------------------- /framework/platform/include/pando_sys.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * File name: pando_sys.h 3 | * Author: xiaoxiao 4 | * Versions: 1.0 5 | * Description: declare common base function lib. 6 | * History: 7 | * 1.Date: Oct 28, 2015 8 | * Author: xiaoxiao 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef _PANDO_SYS_H_ 13 | #define _PANDO_SYS_H_ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef ESP8266_PLATFORM 20 | 21 | #include "mem.h" 22 | #include "osapi.h" 23 | #include "user_interface.h" 24 | #include "../../../../user/device_config.h" 25 | 26 | #define pd_malloc os_malloc 27 | #define pd_free os_free 28 | 29 | #define pd_memcpy os_memcpy 30 | #define pd_memcmp os_memcmp 31 | #define pd_memset os_memset 32 | 33 | #define pd_strlen os_strlen 34 | #define pd_strncpy os_strncpy 35 | #define pd_strcpy os_strcpy 36 | #define pd_strcmp os_strcmp 37 | #define pd_strncmp os_strncmp 38 | #define pd_strchr os_strchr 39 | 40 | #define pd_sprintf os_sprintf 41 | #define pd_printf os_printf 42 | 43 | #else 44 | 45 | #include "string.h" 46 | #include "stdio.h" 47 | 48 | #define pd_malloc mymalloc //malloc 49 | #define pd_free myfree //free 50 | 51 | #define pd_memcpy memcpy 52 | #define pd_memcmp memcmp 53 | #define pd_memset memset 54 | 55 | #define pd_strlen strlen 56 | #define pd_strcpy strcpy 57 | #define pd_strncpy strncpy 58 | #define pd_strcmp strcmp 59 | #define pd_strncmp strncmp 60 | #define pd_strchr strchr 61 | 62 | #define pd_sprintf sprintf 63 | #define pd_printf printf 64 | 65 | #endif 66 | 67 | #endif /* _PANDO_SYS_H_ */ 68 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_dht1122.h: -------------------------------------------------------------------------------- 1 | /* 2 | Driver for the temperature and humidity sensor DHT11 and DHT22 3 | Official repository: https://github.com/CHERTS/esp8266-dht11_22 4 | 5 | Copyright (C) 2014 Mikhail Grigorev (CHERTS) 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License along 18 | with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | #ifndef __PERI_DHT11_22_H__ 23 | #define __PERI_DHT11_22_H__ 24 | 25 | #include "ets_sys.h" 26 | #include "osapi.h" 27 | 28 | typedef enum { 29 | DHT11 = 0, 30 | DHT22 31 | } DHTType; 32 | 33 | typedef struct { 34 | float temperature; 35 | float humidity; 36 | } DHT_Sensor_Data; 37 | 38 | typedef struct { 39 | uint8_t pin; 40 | DHTType type; 41 | } DHT_Sensor; 42 | 43 | #define DHT_MAXTIMINGS 10000 44 | #define DHT_BREAKTIME 20 45 | #define DHT_MAXCOUNT 32000 46 | 47 | #define DHT_DATA_IO_MUX PERIPHS_IO_MUX_MTDI_U 48 | #define DHT_DATA_IO_NUM 12 49 | #define DHT_DATA_IO_FUNC FUNC_GPIO12 50 | 51 | //#define DHT_DEBUG true 52 | 53 | void peri_dht_init(DHT_Sensor* sensor); 54 | bool peri_dht_read(DHT_Sensor_Data* output); 55 | char* DHTFloat2String(char* buffer, float value); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = libdriver.a 16 | endif 17 | ############################################################# 18 | # Configuration i.e. compile options etc. 19 | # Target specific stuff (defines etc.) goes in here! 20 | # Generally values applying to a tree are captured in the 21 | # makefile at its root level - these are then overridden 22 | # for a subtree within the makefile rooted therein 23 | # 24 | 25 | #UNIVERSAL_TARGET_DEFINES = \ 26 | 27 | # Other potential configuration flags include: 28 | # -DTXRX_TXBUF_DEBUG 29 | # -DTXRX_RXBUF_DEBUG 30 | # -DWLAN_CONFIG_CCX 31 | ############################################################# 32 | # Recursion Magic - Don't touch this!! 33 | # 34 | # Each subtree potentially has an include directory 35 | # corresponding to the common APIs applicable to modules 36 | # rooted at that subtree. Accordingly, the INCLUDE PATH 37 | # of a module can only contain the include directories up 38 | # its parent path, and not its siblings 39 | # 40 | # Required for each makefile to inherit from the parent 41 | # 42 | 43 | INCLUDES := $(INCLUDES) -I $(PDIR)include 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | .PHONY: FORCE 48 | FORCE: 49 | 50 | -------------------------------------------------------------------------------- /example/esp8266/util/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libutil.a 27 | endif 28 | 29 | # Other potential configuration flags include: 30 | # -DTXRX_TXBUF_DEBUG 31 | # -DTXRX_RXBUF_DEBUG 32 | # -DWLAN_CONFIG_CCX 33 | 34 | ############################################################# 35 | # Recursion Magic - Don't touch this!! 36 | # 37 | # Each subtree potentially has an include directory 38 | # corresponding to the common APIs applicable to modules 39 | # rooted at that subtree. Accordingly, the INCLUDE PATH 40 | # of a module can only contain the include directories up 41 | # its parent path, and not its siblings 42 | # 43 | # Required for each makefile to inherit from the parent 44 | # 45 | 46 | INCLUDES := $(INCLUDES) -I $(PDIR)include 47 | PDIR := ../$(PDIR) 48 | sinclude $(PDIR)Makefile 49 | 50 | .PHONY: FORCE 51 | FORCE: 52 | 53 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libmqtt.a 17 | endif 18 | 19 | 20 | ############################################################# 21 | # Configuration i.e. compile options etc. 22 | # Target specific stuff (defines etc.) goes in here! 23 | # Generally values applying to a tree are captured in the 24 | # makefile at its root level - these are then overridden 25 | # for a subtree within the makefile rooted therein 26 | # 27 | 28 | #UNIVERSAL_TARGET_DEFINES = \ 29 | 30 | # Other potential configuration flags include: 31 | # -DTXRX_TXBUF_DEBUG 32 | # -DTXRX_RXBUF_DEBUG 33 | # -DWLAN_CONFIG_CCX 34 | 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /framework/lib/json/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libjson.a 17 | endif 18 | 19 | 20 | ############################################################# 21 | # Configuration i.e. compile options etc. 22 | # Target specific stuff (defines etc.) goes in here! 23 | # Generally values applying to a tree are captured in the 24 | # makefile at its root level - these are then overridden 25 | # for a subtree within the makefile rooted therein 26 | # 27 | 28 | #UNIVERSAL_TARGET_DEFINES = \ 29 | 30 | # Other potential configuration flags include: 31 | # -DTXRX_TXBUF_DEBUG 32 | # -DTXRX_RXBUF_DEBUG 33 | # -DWLAN_CONFIG_CCX 34 | 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /framework/protocol/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libprotocol.a 17 | endif 18 | 19 | 20 | ############################################################# 21 | # Configuration i.e. compile options etc. 22 | # Target specific stuff (defines etc.) goes in here! 23 | # Generally values applying to a tree are captured in the 24 | # makefile at its root level - these are then overridden 25 | # for a subtree within the makefile rooted therein 26 | # 27 | 28 | #UNIVERSAL_TARGET_DEFINES = \ 29 | 30 | # Other potential configuration flags include: 31 | # -DTXRX_TXBUF_DEBUG 32 | # -DTXRX_RXBUF_DEBUG 33 | # -DWLAN_CONFIG_CCX 34 | 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /example/esp8266/user/object/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libobjects.a 27 | endif 28 | 29 | # Other potential configuration flags include: 30 | # -DTXRX_TXBUF_DEBUG 31 | # -DTXRX_RXBUF_DEBUG 32 | # -DWLAN_CONFIG_CCX 33 | 34 | 35 | ############################################################# 36 | # Recursion Magic - Don't touch this!! 37 | # 38 | # Each subtree potentially has an include directory 39 | # corresponding to the common APIs applicable to modules 40 | # rooted at that subtree. Accordingly, the INCLUDE PATH 41 | # of a module can only contain the include directories up 42 | # its parent path, and not its siblings 43 | # 44 | # Required for each makefile to inherit from the parent 45 | # 46 | 47 | INCLUDES := $(INCLUDES) -I $(PDIR)include 48 | PDIR := ../$(PDIR) 49 | sinclude $(PDIR)Makefile 50 | 51 | .PHONY: FORCE 52 | FORCE: 53 | 54 | -------------------------------------------------------------------------------- /framework/subdevice/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libsubdevice.a 17 | endif 18 | 19 | 20 | ############################################################# 21 | # Configuration i.e. compile options etc. 22 | # Target specific stuff (defines etc.) goes in here! 23 | # Generally values applying to a tree are captured in the 24 | # makefile at its root level - these are then overridden 25 | # for a subtree within the makefile rooted therein 26 | # 27 | 28 | #UNIVERSAL_TARGET_DEFINES = \ 29 | 30 | # Other potential configuration flags include: 31 | # -DTXRX_TXBUF_DEBUG 32 | # -DTXRX_RXBUF_DEBUG 33 | # -DWLAN_CONFIG_CCX 34 | 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /framework/subdevice/pando_object.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_object.c 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "pando_object.h" 13 | #include "../platform/include/pando_sys.h" 14 | #include "../protocol/pando_machine.h" 15 | 16 | #define MAX_OBJECTS 16 17 | 18 | static pando_object s_pando_object_list[MAX_OBJECTS]; 19 | static int s_pando_object_list_idx = 0; 20 | 21 | void FUNCTION_ATTRIBUTE 22 | register_pando_object(pando_object object) 23 | { 24 | if(s_pando_object_list_idx > MAX_OBJECTS - 1) 25 | { 26 | return; 27 | } 28 | 29 | s_pando_object_list[s_pando_object_list_idx++] = object; 30 | } 31 | 32 | pando_object* FUNCTION_ATTRIBUTE 33 | find_pando_object(uint8_t no) 34 | { 35 | int i; 36 | for(i = 0; i < s_pando_object_list_idx; i++) 37 | { 38 | if( s_pando_object_list[i].no == no) 39 | { 40 | return &s_pando_object_list[i]; 41 | } 42 | } 43 | 44 | return NULL; 45 | } 46 | 47 | pando_objects_iterator* FUNCTION_ATTRIBUTE 48 | create_pando_objects_iterator() 49 | { 50 | pando_objects_iterator* it = (pando_objects_iterator*)pd_malloc(sizeof(pando_objects_iterator)); 51 | it->cur = 0; 52 | return it; 53 | } 54 | 55 | void FUNCTION_ATTRIBUTE 56 | delete_pando_objects_iterator(pando_objects_iterator* it) 57 | { 58 | if(it) 59 | { 60 | pd_free(it); 61 | } 62 | } 63 | 64 | pando_object* FUNCTION_ATTRIBUTE 65 | pando_objects_iterator_next(pando_objects_iterator *it) 66 | { 67 | if(it->cur == s_pando_object_list_idx) 68 | { 69 | return NULL; 70 | } 71 | return &s_pando_object_list[it->cur++]; 72 | } 73 | -------------------------------------------------------------------------------- /framework/lib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = liblib.a 17 | SUBDIRS= \ 18 | json 19 | endif 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | 29 | #UNIVERSAL_TARGET_DEFINES = \ 30 | 31 | # Other potential configuration flags include: 32 | # -DTXRX_TXBUF_DEBUG 33 | # -DTXRX_RXBUF_DEBUG 34 | # -DWLAN_CONFIG_CCX 35 | 36 | 37 | ############################################################# 38 | # Recursion Magic - Don't touch this!! 39 | # 40 | # Each subtree potentially has an include directory 41 | # corresponding to the common APIs applicable to modules 42 | # rooted at that subtree. Accordingly, the INCLUDE PATH 43 | # of a module can only contain the include directories up 44 | # its parent path, and not its siblings 45 | # 46 | # Required for each makefile to inherit from the parent 47 | # 48 | 49 | INCLUDES := $(INCLUDES) -I $(PDIR)include 50 | PDIR := ../$(PDIR) 51 | sinclude $(PDIR)Makefile 52 | 53 | .PHONY: FORCE 54 | FORCE: 55 | 56 | -------------------------------------------------------------------------------- /framework/platform/src/esp8266/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libesp8266.a 17 | endif 18 | 19 | 20 | ############################################################# 21 | # Configuration i.e. compile options etc. 22 | # Target specific stuff (defines etc.) goes in here! 23 | # Generally values applying to a tree are captured in the 24 | # makefile at its root level - these are then overridden 25 | # for a subtree within the makefile rooted therein 26 | # 27 | 28 | #UNIVERSAL_TARGET_DEFINES = \ 29 | 30 | # Other potential configuration flags include: 31 | # -DTXRX_TXBUF_DEBUG 32 | # -DTXRX_RXBUF_DEBUG 33 | # -DWLAN_CONFIG_CCX 34 | 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /example/esp8266/user/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libuser.a 27 | SUBDIRS= \ 28 | objects 29 | endif 30 | 31 | 32 | # Other potential configuration flags include: 33 | # -DTXRX_TXBUF_DEBUG 34 | # -DTXRX_RXBUF_DEBUG 35 | # -DWLAN_CONFIG_CCX 36 | 37 | ############################################################# 38 | # Recursion Magic - Don't touch this!! 39 | # 40 | # Each subtree potentially has an include directory 41 | # corresponding to the common APIs applicable to modules 42 | # rooted at that subtree. Accordingly, the INCLUDE PATH 43 | # of a module can only contain the include directories up 44 | # its parent path, and not its siblings 45 | # 46 | # Required for each makefile to inherit from the parent 47 | # 48 | 49 | INCLUDES := $(INCLUDES) -I $(PDIR)include 50 | PDIR := ../$(PDIR) 51 | sinclude $(PDIR)Makefile 52 | 53 | .PHONY: FORCE 54 | FORCE: 55 | -------------------------------------------------------------------------------- /example/stm32/util/task.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: task.h 3 | * Author: Xiaoxiao Li 4 | * Versions:0.0.1 5 | * Description: the task api 6 | *********************************************************/ 7 | 8 | #ifndef TASK_H_ 9 | #define TASK_H_ 10 | 11 | #include "platform/include/pando_types.h" 12 | 13 | //define the task scheduler base type 14 | typedef struct task { 15 | int8_t (*handler)(void *pdata); 16 | void *pdata; 17 | }task; 18 | 19 | /****************************************************************************** 20 | * FunctionName : new_task 21 | * Description : new a empty task 22 | * Parameters : none 23 | * Returns : the created task 24 | *******************************************************************************/ 25 | task* new_task(void); 26 | 27 | /****************************************************************************** 28 | * FunctionName : add_task 29 | * Description : add a new task to the system 30 | * Parameters : the task to be added 31 | * Returns : the add operation result 32 | *******************************************************************************/ 33 | int8_t add_task(task *ptask); 34 | 35 | /****************************************************************************** 36 | * FunctionName : pop_task 37 | * Description : pop a task from the system 38 | * Parameters : none 39 | * Returns : the task 40 | *******************************************************************************/ 41 | task* pop_task(void); 42 | 43 | /****************************************************************************** 44 | * FunctionName : delete_task 45 | * Description : delete a task 46 | * Parameters : the task to be deleted 47 | * Returns : none 48 | *******************************************************************************/ 49 | void delete_task(task *ptask); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/ringbuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Ring Buffer library 4 | */ 5 | 6 | #include "ringbuf.h" 7 | 8 | 9 | /** 10 | * \brief init a RINGBUF object 11 | * \param r pointer to a RINGBUF object 12 | * \param buf pointer to a byte array 13 | * \param size size of buf 14 | * \return 0 if successfull, otherwise failed 15 | */ 16 | I16 FUNCTION_ATTRIBUTE RINGBUF_Init(RINGBUF *r, U8* buf, I32 size) 17 | { 18 | if(r == NULL || buf == NULL || size < 2) return -1; 19 | 20 | r->p_o = r->p_r = r->p_w = buf; 21 | r->fill_cnt = 0; 22 | r->size = size; 23 | 24 | return 0; 25 | } 26 | /** 27 | * \brief put a character into ring buffer 28 | * \param r pointer to a ringbuf object 29 | * \param c character to be put 30 | * \return 0 if successfull, otherwise failed 31 | */ 32 | I16 FUNCTION_ATTRIBUTE RINGBUF_Put(RINGBUF *r, U8 c) 33 | { 34 | if(r->fill_cnt>=r->size)return -1; // ring buffer is full, this should be atomic operation 35 | 36 | 37 | r->fill_cnt++; // increase filled slots count, this should be atomic operation 38 | 39 | 40 | *r->p_w++ = c; // put character into buffer 41 | 42 | if(r->p_w >= r->p_o + r->size) // rollback if write pointer go pass 43 | r->p_w = r->p_o; // the physical boundary 44 | 45 | return 0; 46 | } 47 | /** 48 | * \brief get a character from ring buffer 49 | * \param r pointer to a ringbuf object 50 | * \param c read character 51 | * \return 0 if successfull, otherwise failed 52 | */ 53 | I16 FUNCTION_ATTRIBUTE RINGBUF_Get(RINGBUF *r, U8* c) 54 | { 55 | if(r->fill_cnt<=0)return -1; // ring buffer is empty, this should be atomic operation 56 | 57 | 58 | r->fill_cnt--; // decrease filled slots count 59 | 60 | 61 | *c = *r->p_r++; // get the character out 62 | 63 | if(r->p_r >= r->p_o + r->size) // rollback if write pointer go pass 64 | r->p_r = r->p_o; // the physical boundary 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libperipheral.a 27 | SUBDIRS= \ 28 | driver 29 | endif 30 | 31 | # Other potential configuration flags include: 32 | # -DTXRX_TXBUF_DEBUG 33 | # -DTXRX_RXBUF_DEBUG 34 | # -DWLAN_CONFIG_CCX 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /framework/gateway/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libgateway.a 17 | SUBDIRS= \ 18 | mqtt 19 | endif 20 | 21 | 22 | ############################################################# 23 | # Configuration i.e. compile options etc. 24 | # Target specific stuff (defines etc.) goes in here! 25 | # Generally values applying to a tree are captured in the 26 | # makefile at its root level - these are then overridden 27 | # for a subtree within the makefile rooted therein 28 | # 29 | 30 | #UNIVERSAL_TARGET_DEFINES = \ 31 | 32 | # Other potential configuration flags include: 33 | # -DTXRX_TXBUF_DEBUG 34 | # -DTXRX_RXBUF_DEBUG 35 | # -DWLAN_CONFIG_CCX 36 | 37 | 38 | ############################################################# 39 | # Recursion Magic - Don't touch this!! 40 | # 41 | # Each subtree potentially has an include directory 42 | # corresponding to the common APIs applicable to modules 43 | # rooted at that subtree. Accordingly, the INCLUDE PATH 44 | # of a module can only contain the include directories up 45 | # its parent path, and not its siblings 46 | # 47 | # Required for each makefile to inherit from the parent 48 | # 49 | 50 | INCLUDES := $(INCLUDES) -I $(PDIR)include 51 | PDIR := ../$(PDIR) 52 | sinclude $(PDIR)Makefile 53 | 54 | .PHONY: FORCE 55 | FORCE: 56 | 57 | -------------------------------------------------------------------------------- /framework/platform/src/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libsrc.a 17 | SUBDIRS= \ 18 | esp8266 19 | endif 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | 29 | #UNIVERSAL_TARGET_DEFINES = \ 30 | 31 | # Other potential configuration flags include: 32 | # -DTXRX_TXBUF_DEBUG 33 | # -DTXRX_RXBUF_DEBUG 34 | # -DWLAN_CONFIG_CCX 35 | 36 | 37 | ############################################################# 38 | # Recursion Magic - Don't touch this!! 39 | # 40 | # Each subtree potentially has an include directory 41 | # corresponding to the common APIs applicable to modules 42 | # rooted at that subtree. Accordingly, the INCLUDE PATH 43 | # of a module can only contain the include directories up 44 | # its parent path, and not its siblings 45 | # 46 | # Required for each makefile to inherit from the parent 47 | # 48 | 49 | INCLUDES := $(INCLUDES) -I $(PDIR)include 50 | PDIR := ../$(PDIR) 51 | sinclude $(PDIR)Makefile 52 | 53 | .PHONY: FORCE 54 | FORCE: 55 | 56 | -------------------------------------------------------------------------------- /framework/platform/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libplatform.a 17 | SUBDIRS= \ 18 | src \ 19 | src/esp8266 20 | endif 21 | 22 | ############################################################# 23 | # Configuration i.e. compile options etc. 24 | # Target specific stuff (defines etc.) goes in here! 25 | # Generally values applying to a tree are captured in the 26 | # makefile at its root level - these are then overridden 27 | # for a subtree within the makefile rooted therein 28 | # 29 | 30 | #UNIVERSAL_TARGET_DEFINES = \ 31 | 32 | # Other potential configuration flags include: 33 | # -DTXRX_TXBUF_DEBUG 34 | # -DTXRX_RXBUF_DEBUG 35 | # -DWLAN_CONFIG_CCX 36 | 37 | 38 | ############################################################# 39 | # Recursion Magic - Don't touch this!! 40 | # 41 | # Each subtree potentially has an include directory 42 | # corresponding to the common APIs applicable to modules 43 | # rooted at that subtree. Accordingly, the INCLUDE PATH 44 | # of a module can only contain the include directories up 45 | # its parent path, and not its siblings 46 | # 47 | # Required for each makefile to inherit from the parent 48 | # 49 | 50 | INCLUDES := $(INCLUDES) -I $(PDIR)include 51 | PDIR := ../$(PDIR) 52 | sinclude $(PDIR)Makefile 53 | 54 | .PHONY: FORCE 55 | FORCE: 56 | 57 | -------------------------------------------------------------------------------- /example/esp8266/user/user_main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | /******************************************************* 3 | * File name: user_main.c 4 | * Author:Chongguang Li 5 | * Versions:1.0 6 | * Description:entry file of user application. 7 | * 8 | * History: 9 | * 1.Date: 10 | * Author: 11 | * Modification: 12 | *******************************************************************************/ 13 | 14 | #include "../pando/framework/pando_framework.h" 15 | #include "../peripheral/driver/uart.h" 16 | #include "objects/led.h" 17 | #include "os_type.h" 18 | #include "user_interface.h" 19 | #include "../peripheral/peri_key.h" 20 | #include "wifi_config.h" 21 | #include "espconn.h" 22 | 23 | char* g_product_key_buf = "d0375b4180f1ddc44c89a2046e8b841a7d2b642303a026bfc101aa0e448b6dee"; 24 | //#define SERVER_ADDRESS "https://api.pandocloud.com" 25 | char* g_server_url = "https://120.24.222.147"; 26 | //char* g_server_url = "https://api.pandocloud.com"; 27 | static void ICACHE_FLASH_ATTR 28 | user_key_long_press_cb() 29 | { 30 | PRINTF("Long press occurred"); 31 | wifi_config(NULL); 32 | } 33 | 34 | /****************************************************************************** 35 | * FunctionName : user_init 36 | * Description : entry of user application, init user function here 37 | * Parameters : none 38 | * Returns : none 39 | *******************************************************************************/ 40 | void user_init(void) 41 | { 42 | uart_init(115200, 115200); // serial bound rate:11520. 43 | 44 | //long press gpio4, enter into wifi config mode. 45 | peri_single_key_init(4, user_key_long_press_cb, peri_key_short_press); 46 | 47 | // add you object init here. 48 | led_object_init(); 49 | //c_motor_object_init(); 50 | //temperature_object_init(); 51 | 52 | espconn_secure_set_size(ESPCONN_CLIENT,5120); 53 | pando_framework_init(); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /example/stm32/driver/timer4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "timer4.h" 3 | #include "stm32f10x.h" 4 | #include "stdio.h" 5 | #include "task.h" 6 | 7 | static uint8_t s_repeat_flag; 8 | static time4_callback time_cb; 9 | 10 | void timer4_init(uint16_t time_set, uint8_t repeat_flag, time4_callback time4_cb) 11 | { 12 | s_repeat_flag = repeat_flag; 13 | time_cb = time4_cb; 14 | TIM_TimeBaseInitTypeDef time_structure; 15 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //enable clock 16 | time_structure.TIM_Period = 2 * time_set - 1; 17 | time_structure.TIM_Prescaler = 35999; 18 | time_structure.TIM_ClockDivision = TIM_CKD_DIV1; 19 | time_structure.TIM_CounterMode = TIM_CounterMode_Up; 20 | TIM_TimeBaseInit(TIM4, &time_structure); 21 | TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); 22 | 23 | NVIC_InitTypeDef nvic_structure; 24 | nvic_structure.NVIC_IRQChannel = TIM4_IRQn; //TIM4 interrupt 25 | nvic_structure.NVIC_IRQChannelPreemptionPriority = 5; 26 | nvic_structure.NVIC_IRQChannelSubPriority = 6; 27 | nvic_structure.NVIC_IRQChannelCmd = ENABLE; 28 | NVIC_Init(&nvic_structure); 29 | 30 | timer4_stop(); 31 | } 32 | 33 | void timer4_start(void) 34 | { 35 | TIM_Cmd(TIM4, ENABLE); 36 | } 37 | 38 | void timer4_stop(void) 39 | { 40 | TIM_Cmd(TIM4, DISABLE); 41 | } 42 | 43 | void TIM4_IRQHandler(void) 44 | { 45 | printf("time 4 interrupt!\n"); 46 | 47 | //Checks whether the TIM interrupt has occurred or not 48 | if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET) 49 | { 50 | TIM_ClearITPendingBit(TIM4, TIM_IT_Update); //Clears the TIMx's interrupt pending bits 51 | task * timer4_task; 52 | timer4_task = new_task(); 53 | timer4_task->handler = time_cb; 54 | timer4_task->pdata = NULL; 55 | add_task(timer4_task); 56 | if(0 == s_repeat_flag) 57 | { 58 | printf("time4 stop\n"); 59 | timer4_stop(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /framework/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libframework.a 17 | SUBDIRS= \ 18 | gateway \ 19 | gateway/mqtt \ 20 | lib \ 21 | lib/json \ 22 | platform \ 23 | platform/src \ 24 | platform/src/esp8266 \ 25 | protocol \ 26 | subdevice 27 | endif 28 | 29 | ############################################################# 30 | # Configuration i.e. compile options etc. 31 | # Target specific stuff (defines etc.) goes in here! 32 | # Generally values applying to a tree are captured in the 33 | # makefile at its root level - these are then overridden 34 | # for a subtree within the makefile rooted therein 35 | # 36 | 37 | #UNIVERSAL_TARGET_DEFINES = \ 38 | 39 | # Other potential configuration flags include: 40 | # -DTXRX_TXBUF_DEBUG 41 | # -DTXRX_RXBUF_DEBUG 42 | # -DWLAN_CONFIG_CCX 43 | 44 | 45 | ############################################################# 46 | # Recursion Magic - Don't touch this!! 47 | # 48 | # Each subtree potentially has an include directory 49 | # corresponding to the common APIs applicable to modules 50 | # rooted at that subtree. Accordingly, the INCLUDE PATH 51 | # of a module can only contain the include directories up 52 | # its parent path, and not its siblings 53 | # 54 | # Required for each makefile to inherit from the parent 55 | # 56 | 57 | INCLUDES := $(INCLUDES) -I $(PDIR)include 58 | PDIR := ../$(PDIR) 59 | sinclude $(PDIR)Makefile 60 | 61 | .PHONY: FORCE 62 | FORCE: 63 | 64 | -------------------------------------------------------------------------------- /example/esp8266/user/object/air.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/framework/subdevice/pando_object.h" 2 | #include "c_types.h" 3 | #include "user_interface.h" 4 | #include "air.h" 5 | #include "../../peripheral/peri_iaq.h" 6 | // add your own includes below 7 | 8 | #define AIR_OBJECT_NO 1 9 | struct air { 10 | uint16 quality; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | air_init() { 14 | // TODO: add your object init code here. 15 | peri_iaq_init(); 16 | 17 | } 18 | void ICACHE_FLASH_ATTR 19 | air_set(struct air* value) { 20 | // TODO: implement object set function here. 21 | // the set function read value and operate the hardware. 22 | 23 | 24 | } 25 | void ICACHE_FLASH_ATTR 26 | air_get(struct air* value) { 27 | // TODO: implement object get function here 28 | // get function retrieve hardware status and assign it to value. 29 | value->quality=peri_iaq_read(); 30 | //PRINTF("Air Quality: %d\n",value->quality); 31 | 32 | } 33 | /* 34 | auto generated code below!! 35 | DO NOT edit unless you know how it works. 36 | */ 37 | struct air* ICACHE_FLASH_ATTR 38 | create_air() { 39 | struct air* air = (struct air*)os_malloc(sizeof(air)); 40 | return air; 41 | } 42 | void ICACHE_FLASH_ATTR 43 | delete_air(struct air* air) { 44 | if(air){ 45 | os_free(air); 46 | } 47 | } 48 | void ICACHE_FLASH_ATTR 49 | air_object_pack(PARAMS * params) { 50 | if(NULL == params){ 51 | PRINTF("Create first tlv param failed.\n"); 52 | return; 53 | } 54 | 55 | struct air* air = create_air(); 56 | air_get(air); 57 | 58 | if (add_next_uint16(params, air->quality)){ 59 | PRINTF("Add next param failed.\n"); 60 | return; 61 | } 62 | 63 | delete_air(air); 64 | } 65 | void ICACHE_FLASH_ATTR 66 | air_object_unpack(PARAMS* params) { 67 | struct air* air = create_air(); 68 | 69 | air->quality = get_next_uint16(params); 70 | 71 | air_set(air); 72 | delete_air(air); 73 | } 74 | void ICACHE_FLASH_ATTR 75 | air_object_init() { 76 | air_init(); 77 | pando_object air_object = { 78 | 1, 79 | air_object_pack, 80 | air_object_unpack, 81 | }; 82 | register_pando_object(air_object); 83 | } 84 | -------------------------------------------------------------------------------- /example/esp8266/user/object/plug.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/framework/subdevice/pando_object.h" 2 | #include "../../peripheral/peri_jdq.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "plug.h" 6 | // add your own includes below 7 | #define PLUG_OBJECT_NO 1 8 | 9 | struct plug { 10 | uint8 off_on; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | plug_init() { 14 | // TODO: add your object init code here. 15 | peri_jdq_init(12); 16 | 17 | } 18 | void ICACHE_FLASH_ATTR 19 | plug_set(struct plug* value) { 20 | // TODO: implement object set function here. 21 | // the set function read value and operate the hardware. 22 | peri_jdq_set(value->off_on); 23 | 24 | } 25 | void ICACHE_FLASH_ATTR 26 | plug_get(struct plug* value) { 27 | // TODO: implement object get function here 28 | // get function retrieve hardware status and assign it to value. 29 | value->off_on=peri_jdq_get(); 30 | } 31 | /* 32 | auto generated code below!! 33 | DO NOT edit unless you know how it works. 34 | */ 35 | struct plug* ICACHE_FLASH_ATTR 36 | create_plug() { 37 | struct plug* plug = (struct plug*)os_malloc(sizeof(plug)); 38 | return plug; 39 | } 40 | void ICACHE_FLASH_ATTR 41 | delete_plug(struct plug* plug) { 42 | if(plug){ 43 | os_free(plug); 44 | } 45 | } 46 | void ICACHE_FLASH_ATTR 47 | plug_object_pack(PARAMS * params) { 48 | if(NULL == params){ 49 | PRINTF("Create first tlv param failed.\n"); 50 | return; 51 | } 52 | 53 | struct plug* plug = create_plug(); 54 | plug_get(plug); 55 | 56 | if (add_next_uint8(params, plug->off_on)){ 57 | PRINTF("Add next param failed.\n"); 58 | return; 59 | } 60 | 61 | delete_plug(plug); 62 | } 63 | void ICACHE_FLASH_ATTR 64 | plug_object_unpack(PARAMS* params) { 65 | struct plug* plug = create_plug(); 66 | 67 | plug->off_on = get_next_uint8(params); 68 | 69 | plug_set(plug); 70 | delete_plug(plug); 71 | } 72 | void ICACHE_FLASH_ATTR 73 | plug_object_init() { 74 | plug_init(); 75 | pando_object plug_object = { 76 | 1, 77 | plug_object_pack, 78 | plug_object_unpack, 79 | }; 80 | register_pando_object(plug_object); 81 | } 82 | -------------------------------------------------------------------------------- /framework/lib/converter.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: converter.c 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is to used to covert the data coding. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "converter.h" 13 | 14 | /****************************************************************************** 15 | * FunctionName : char2bin. 16 | * Description : convert char to bin. 17 | * Parameters : dst -- 18 | * hex_str -- 19 | * Returns : none. 20 | *******************************************************************************/ 21 | static uint8_t FUNCTION_ATTRIBUTE 22 | char2bin(char a) 23 | { 24 | uint8_t n; 25 | if(a>='0'&&a<='9') 26 | { 27 | n=a-'0'; 28 | } 29 | else 30 | { 31 | n=a-'a'+10; 32 | } 33 | return n; 34 | } 35 | 36 | /****************************************************************************** 37 | * FunctionName : hex2bin. 38 | * Description : convert string to bin. 39 | * Parameters : dst -- 40 | * hex_str -- 41 | * Returns : none. 42 | *******************************************************************************/ 43 | void FUNCTION_ATTRIBUTE 44 | hex2bin(uint8_t * dst, char * hex_str) 45 | { 46 | char * p = NULL; 47 | int i=0; 48 | for(p=hex_str; *p; p=p+2) 49 | { 50 | dst[i++] = ((char2bin(*p)) << 4) | (char2bin(*(p+1))); 51 | } 52 | } 53 | 54 | const char* FUNCTION_ATTRIBUTE 55 | u32_to_str(unsigned int val) 56 | { 57 | /* Maximum number of decimal digits in u32 is 10 */ 58 | static char num_str[11]; 59 | int pos = 10; 60 | num_str[10] = 0; 61 | 62 | if (val == 0) { 63 | /* If already zero then just return zero */ 64 | return "0"; 65 | } 66 | 67 | while ((val != 0) && (pos > 0)) { 68 | num_str[--pos] = (val % 10) + '0'; 69 | val /= 10; 70 | } 71 | 72 | return &num_str[pos]; 73 | } 74 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libpando.a 17 | SUBDIRS= \ 18 | framework \ 19 | framework/gateway \ 20 | framework/gateway/mqtt \ 21 | framework/lib \ 22 | framework/platform \ 23 | framework/protocol \ 24 | framework/subdevice \ 25 | framework/lib/json \ 26 | framework/platform/src \ 27 | framework/platform/src/esp8266 \ 28 | 29 | 30 | endif 31 | 32 | 33 | ############################################################# 34 | # Configuration i.e. compile options etc. 35 | # Target specific stuff (defines etc.) goes in here! 36 | # Generally values applying to a tree are captured in the 37 | # makefile at its root level - these are then overridden 38 | # for a subtree within the makefile rooted therein 39 | # 40 | 41 | #UNIVERSAL_TARGET_DEFINES = \ 42 | 43 | # Other potential configuration flags include: 44 | # -DTXRX_TXBUF_DEBUG 45 | # -DTXRX_RXBUF_DEBUG 46 | # -DWLAN_CONFIG_CCX 47 | 48 | ############################################################# 49 | # Recursion Magic - Don't touch this!! 50 | # 51 | # Each subtree potentially has an include directory 52 | # corresponding to the common APIs applicable to modules 53 | # rooted at that subtree. Accordingly, the INCLUDE PATH 54 | # of a module can only contain the include directories up 55 | # its parent path, and not its siblings 56 | # 57 | # Required for each makefile to inherit from the parent 58 | # 59 | 60 | INCLUDES := $(INCLUDES) -I $(PDIR)include 61 | PDIR := ../$(PDIR) 62 | sinclude $(PDIR)Makefile 63 | 64 | .PHONY: FORCE 65 | FORCE: 66 | 67 | -------------------------------------------------------------------------------- /example/esp8266/util/converter.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: converter.c 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is to used to covert the data coding. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "converter.h" 13 | #include "user_interface.h" 14 | 15 | /****************************************************************************** 16 | * FunctionName : char2bin. 17 | * Description : convert char to bin. 18 | * Parameters : dst -- 19 | * hex_str -- 20 | * Returns : none. 21 | *******************************************************************************/ 22 | static uint8_t ICACHE_FLASH_ATTR 23 | char2bin(char a) 24 | { 25 | uint8_t n; 26 | if(a>='0'&&a<='9') 27 | { 28 | n=a-'0'; 29 | } 30 | else 31 | { 32 | n=a-'a'+10; 33 | } 34 | return n; 35 | } 36 | 37 | /****************************************************************************** 38 | * FunctionName : hex2bin. 39 | * Description : convert string to bin. 40 | * Parameters : dst -- 41 | * hex_str -- 42 | * Returns : none. 43 | *******************************************************************************/ 44 | void ICACHE_FLASH_ATTR 45 | hex2bin(uint8 * dst, char * hex_str) 46 | { 47 | char * p = NULL; 48 | int i=0; 49 | for(p=hex_str; *p; p=p+2) 50 | { 51 | dst[i++] = ((char2bin(*p)) << 4) | (char2bin(*(p+1))); 52 | } 53 | } 54 | 55 | const char* ICACHE_FLASH_ATTR 56 | u32_to_str(unsigned int val) 57 | { 58 | /* Maximum number of decimal digits in u32 is 10 */ 59 | static char num_str[11]; 60 | int pos = 10; 61 | num_str[10] = 0; 62 | 63 | if (val == 0) { 64 | /* If already zero then just return zero */ 65 | return "0"; 66 | } 67 | 68 | while ((val != 0) && (pos > 0)) { 69 | num_str[--pos] = (val % 10) + '0'; 70 | val /= 10; 71 | } 72 | 73 | return &num_str[pos]; 74 | } 75 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/queue.h: -------------------------------------------------------------------------------- 1 | /* str_queue.h -- 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef USER_QUEUE_H_ 32 | #define USER_QUEUE_H_ 33 | #include "../../platform/include/pando_types.h" 34 | #include "ringbuf.h" 35 | typedef struct { 36 | uint8_t *buf; 37 | RINGBUF rb; 38 | } QUEUE; 39 | 40 | void QUEUE_Init(QUEUE *queue, int bufferSize); 41 | int32_t QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len); 42 | int32_t QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen); 43 | BOOL QUEUE_IsEmpty(QUEUE *queue); 44 | #endif /* USER_QUEUE_H_ */ 45 | -------------------------------------------------------------------------------- /framework/lib/private_key.h: -------------------------------------------------------------------------------- 1 | unsigned char default_private_key[] = { 2 | 0x30, 0x82, 0x01, 0x3d, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xa3, 0x5a, 3 | 0x69, 0x68, 0xaf, 0xff, 0x07, 0x27, 0x46, 0x26, 0x3c, 0xe7, 0x66, 0x90, 4 | 0x15, 0x24, 0x8d, 0x2e, 0x40, 0x22, 0x0d, 0xa5, 0x89, 0x03, 0xd0, 0xc6, 5 | 0x5e, 0x45, 0xf5, 0x03, 0x9b, 0x41, 0x2e, 0xce, 0x95, 0x29, 0x2d, 0x3b, 6 | 0x77, 0x92, 0x1b, 0xd8, 0xf8, 0x73, 0xfd, 0xa9, 0xde, 0xac, 0xee, 0x49, 7 | 0x14, 0x3b, 0x2c, 0xd9, 0x4c, 0x82, 0xad, 0xae, 0x2d, 0xe2, 0x3d, 0xc4, 8 | 0xbc, 0xef, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x41, 0x00, 0x95, 0x43, 9 | 0xef, 0x5f, 0xee, 0xba, 0x1d, 0xe2, 0x40, 0x52, 0x7e, 0x82, 0x80, 0x10, 10 | 0x96, 0x91, 0x40, 0xc4, 0x8b, 0x6b, 0xd2, 0x86, 0x79, 0x6d, 0xd8, 0x1e, 11 | 0xfb, 0x53, 0xf7, 0x70, 0x25, 0x33, 0x73, 0x8b, 0x73, 0x2b, 0x99, 0xd2, 12 | 0xf7, 0xa9, 0x1f, 0x9d, 0x14, 0x1e, 0x62, 0x7e, 0x0e, 0xb0, 0x84, 0x2a, 13 | 0xd7, 0x1e, 0x0a, 0x3e, 0xe7, 0x28, 0xc7, 0xa1, 0x0c, 0x8d, 0x83, 0xba, 14 | 0x88, 0x91, 0x02, 0x21, 0x00, 0xd7, 0x15, 0x37, 0x3b, 0x29, 0xe7, 0x8f, 15 | 0x5c, 0x8e, 0x70, 0xb6, 0x49, 0xee, 0x9c, 0x8c, 0x02, 0xc4, 0xe0, 0xfc, 16 | 0x88, 0x20, 0xbb, 0x3a, 0xd8, 0x40, 0xb4, 0xd2, 0xfc, 0x34, 0x60, 0xca, 17 | 0xf9, 0x02, 0x21, 0x00, 0xc2, 0x6d, 0xe6, 0x56, 0x06, 0x4f, 0x26, 0xbe, 18 | 0xe8, 0x1f, 0x8a, 0x3a, 0x57, 0xe9, 0x2e, 0xb5, 0xee, 0x59, 0x0f, 0x9a, 19 | 0x73, 0xd7, 0xc8, 0xc7, 0xdc, 0xff, 0x5b, 0x2f, 0xd6, 0x2f, 0x99, 0x27, 20 | 0x02, 0x21, 0x00, 0xa8, 0x1e, 0x9a, 0x44, 0x71, 0xb5, 0xe1, 0xb6, 0x8c, 21 | 0x54, 0x87, 0xf8, 0x74, 0x3e, 0x03, 0xa6, 0xea, 0x73, 0x9e, 0x91, 0x5d, 22 | 0x5c, 0x5c, 0x5b, 0xcb, 0x00, 0x4c, 0xe6, 0xfc, 0x9e, 0x28, 0x29, 0x02, 23 | 0x21, 0x00, 0x90, 0xc8, 0x09, 0xb7, 0x91, 0x67, 0x2b, 0x71, 0x09, 0xa5, 24 | 0x42, 0xe7, 0x83, 0x43, 0x2e, 0xf7, 0x67, 0x0f, 0x86, 0xe0, 0xfa, 0xd6, 25 | 0x7a, 0xba, 0xe9, 0xc4, 0x75, 0x80, 0xbf, 0xbc, 0x1e, 0x0d, 0x02, 0x21, 26 | 0x00, 0xd6, 0x9b, 0x2c, 0x71, 0xdc, 0xf6, 0x82, 0xd9, 0x49, 0xdc, 0x0c, 27 | 0xe6, 0xe2, 0x99, 0x00, 0x49, 0x9d, 0x6c, 0x89, 0xa3, 0x0c, 0x60, 0x1b, 28 | 0xb4, 0x80, 0x36, 0x69, 0xd0, 0x14, 0xab, 0x2b, 0xfc 29 | }; 30 | unsigned int default_private_key_len = 321; 31 | -------------------------------------------------------------------------------- /example/esp8266/util/private_key.h: -------------------------------------------------------------------------------- 1 | unsigned char default_private_key[] = { 2 | 0x30, 0x82, 0x01, 0x3d, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xa3, 0x5a, 3 | 0x69, 0x68, 0xaf, 0xff, 0x07, 0x27, 0x46, 0x26, 0x3c, 0xe7, 0x66, 0x90, 4 | 0x15, 0x24, 0x8d, 0x2e, 0x40, 0x22, 0x0d, 0xa5, 0x89, 0x03, 0xd0, 0xc6, 5 | 0x5e, 0x45, 0xf5, 0x03, 0x9b, 0x41, 0x2e, 0xce, 0x95, 0x29, 0x2d, 0x3b, 6 | 0x77, 0x92, 0x1b, 0xd8, 0xf8, 0x73, 0xfd, 0xa9, 0xde, 0xac, 0xee, 0x49, 7 | 0x14, 0x3b, 0x2c, 0xd9, 0x4c, 0x82, 0xad, 0xae, 0x2d, 0xe2, 0x3d, 0xc4, 8 | 0xbc, 0xef, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x41, 0x00, 0x95, 0x43, 9 | 0xef, 0x5f, 0xee, 0xba, 0x1d, 0xe2, 0x40, 0x52, 0x7e, 0x82, 0x80, 0x10, 10 | 0x96, 0x91, 0x40, 0xc4, 0x8b, 0x6b, 0xd2, 0x86, 0x79, 0x6d, 0xd8, 0x1e, 11 | 0xfb, 0x53, 0xf7, 0x70, 0x25, 0x33, 0x73, 0x8b, 0x73, 0x2b, 0x99, 0xd2, 12 | 0xf7, 0xa9, 0x1f, 0x9d, 0x14, 0x1e, 0x62, 0x7e, 0x0e, 0xb0, 0x84, 0x2a, 13 | 0xd7, 0x1e, 0x0a, 0x3e, 0xe7, 0x28, 0xc7, 0xa1, 0x0c, 0x8d, 0x83, 0xba, 14 | 0x88, 0x91, 0x02, 0x21, 0x00, 0xd7, 0x15, 0x37, 0x3b, 0x29, 0xe7, 0x8f, 15 | 0x5c, 0x8e, 0x70, 0xb6, 0x49, 0xee, 0x9c, 0x8c, 0x02, 0xc4, 0xe0, 0xfc, 16 | 0x88, 0x20, 0xbb, 0x3a, 0xd8, 0x40, 0xb4, 0xd2, 0xfc, 0x34, 0x60, 0xca, 17 | 0xf9, 0x02, 0x21, 0x00, 0xc2, 0x6d, 0xe6, 0x56, 0x06, 0x4f, 0x26, 0xbe, 18 | 0xe8, 0x1f, 0x8a, 0x3a, 0x57, 0xe9, 0x2e, 0xb5, 0xee, 0x59, 0x0f, 0x9a, 19 | 0x73, 0xd7, 0xc8, 0xc7, 0xdc, 0xff, 0x5b, 0x2f, 0xd6, 0x2f, 0x99, 0x27, 20 | 0x02, 0x21, 0x00, 0xa8, 0x1e, 0x9a, 0x44, 0x71, 0xb5, 0xe1, 0xb6, 0x8c, 21 | 0x54, 0x87, 0xf8, 0x74, 0x3e, 0x03, 0xa6, 0xea, 0x73, 0x9e, 0x91, 0x5d, 22 | 0x5c, 0x5c, 0x5b, 0xcb, 0x00, 0x4c, 0xe6, 0xfc, 0x9e, 0x28, 0x29, 0x02, 23 | 0x21, 0x00, 0x90, 0xc8, 0x09, 0xb7, 0x91, 0x67, 0x2b, 0x71, 0x09, 0xa5, 24 | 0x42, 0xe7, 0x83, 0x43, 0x2e, 0xf7, 0x67, 0x0f, 0x86, 0xe0, 0xfa, 0xd6, 25 | 0x7a, 0xba, 0xe9, 0xc4, 0x75, 0x80, 0xbf, 0xbc, 0x1e, 0x0d, 0x02, 0x21, 26 | 0x00, 0xd6, 0x9b, 0x2c, 0x71, 0xdc, 0xf6, 0x82, 0xd9, 0x49, 0xdc, 0x0c, 27 | 0xe6, 0xe2, 0x99, 0x00, 0x49, 0x9d, 0x6c, 0x89, 0xa3, 0x0c, 0x60, 0x1b, 28 | 0xb4, 0x80, 0x36, 0x69, 0xd0, 0x14, 0xab, 0x2b, 0xfc 29 | }; 30 | unsigned int default_private_key_len = 321; 31 | -------------------------------------------------------------------------------- /framework/subdevice/pando_object.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_object.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: pando object interfaces 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef PANDO_OBJECTS_H_ 13 | #define PANDO_OBJECTS_H_ 14 | 15 | #include "../platform/include/pando_types.h" 16 | //#include "../protocol/sub_device_protocol.h" 17 | 18 | typedef struct TLVs PARAMS; 19 | 20 | typedef struct { 21 | uint8_t no; 22 | void (*pack)(PARAMS*); 23 | void (*unpack)(PARAMS*); 24 | }pando_object; 25 | 26 | typedef struct { 27 | uint8_t cur; 28 | }pando_objects_iterator; 29 | 30 | /****************************************************************************** 31 | * FunctionName : register_pando_object. 32 | * Description : register a pando object to framework. 33 | * Parameters : a pando object. 34 | * Returns : none. 35 | *******************************************************************************/ 36 | void register_pando_object(pando_object object); 37 | 38 | /****************************************************************************** 39 | * FunctionName : find_pando_object. 40 | * Description : find a pando object by object no. 41 | * Parameters : the object no. 42 | * Returns : the pando object of specified no, NULL if not found. 43 | *******************************************************************************/ 44 | pando_object* find_pando_object(uint8_t no); 45 | 46 | /****************************************************************************** 47 | * FunctionName : create_pando_objects_iterator, delete_pando_objects_iterator. 48 | * Description : iterator for pando object list. 49 | * Parameters : . 50 | * Returns : . 51 | *******************************************************************************/ 52 | pando_objects_iterator* create_pando_objects_iterator(void); 53 | void delete_pando_objects_iterator(pando_objects_iterator*); 54 | pando_object* pando_objects_iterator_next(pando_objects_iterator*); 55 | 56 | #endif /* PANDO_OBJECTS_H_ */ 57 | -------------------------------------------------------------------------------- /example/stm32/driver/cm3_bitband.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CM3_BITBAND_H_ 3 | #define _CM3_BITBAND_H_ 4 | 5 | #include "stm32f10x.h" 6 | #include "stm32f10x_gpio.h" 7 | 8 | //bit band operation, just like 8051 how to operate GPIO 9 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 10 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 11 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 12 | //IO address map 13 | #define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C 14 | #define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C 15 | #define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C 16 | #define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C 17 | #define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C 18 | #define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C 19 | #define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C 20 | 21 | #define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808 22 | #define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08 23 | #define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008 24 | #define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408 25 | #define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808 26 | #define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08 27 | #define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08 28 | 29 | //IO operation,single IO! 30 | //make sure n less than 16! 31 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //output 32 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //input 33 | 34 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //output 35 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //input 36 | 37 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //output 38 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //input 39 | 40 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //output 41 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //input 42 | 43 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //output 44 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //input 45 | 46 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //output 47 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //input 48 | 49 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //output 50 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //input 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /framework/lib/cert.h: -------------------------------------------------------------------------------- 1 | unsigned char default_certificate[] = { 2 | 0x30, 0x82, 0x01, 0x4d, 0x30, 0x81, 0xf8, 0x02, 0x09, 0x00, 0xba, 0x06, 3 | 0x02, 0x36, 0x28, 0x44, 0xd4, 0x58, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 4 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x32, 0x31, 5 | 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x27, 0x54, 0x4c, 6 | 0x53, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x44, 0x6f, 7 | 0x64, 0x67, 0x79, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 8 | 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 9 | 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x33, 0x33, 0x31, 0x30, 10 | 0x36, 0x32, 0x30, 0x34, 0x32, 0x5a, 0x17, 0x0d, 0x32, 0x38, 0x31, 0x32, 11 | 0x30, 0x37, 0x30, 0x36, 0x32, 0x30, 0x34, 0x32, 0x5a, 0x30, 0x2a, 0x31, 12 | 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x54, 0x4c, 13 | 0x53, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x31, 0x12, 0x30, 14 | 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x31, 0x32, 0x37, 0x2e, 15 | 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 16 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 17 | 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xa3, 0x5a, 0x69, 0x68, 0xaf, 0xff, 18 | 0x07, 0x27, 0x46, 0x26, 0x3c, 0xe7, 0x66, 0x90, 0x15, 0x24, 0x8d, 0x2e, 19 | 0x40, 0x22, 0x0d, 0xa5, 0x89, 0x03, 0xd0, 0xc6, 0x5e, 0x45, 0xf5, 0x03, 20 | 0x9b, 0x41, 0x2e, 0xce, 0x95, 0x29, 0x2d, 0x3b, 0x77, 0x92, 0x1b, 0xd8, 21 | 0xf8, 0x73, 0xfd, 0xa9, 0xde, 0xac, 0xee, 0x49, 0x14, 0x3b, 0x2c, 0xd9, 22 | 0x4c, 0x82, 0xad, 0xae, 0x2d, 0xe2, 0x3d, 0xc4, 0xbc, 0xef, 0x02, 0x03, 23 | 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 24 | 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, 0x00, 0x47, 0x53, 0xd3, 25 | 0x8a, 0x21, 0x0d, 0x2f, 0x75, 0xd1, 0x11, 0xbe, 0x42, 0x24, 0xe1, 0x97, 26 | 0xfa, 0xe4, 0xf8, 0x90, 0xa1, 0xe9, 0xb1, 0x2c, 0xe1, 0xc6, 0x4c, 0x3d, 27 | 0x0b, 0x54, 0xe3, 0x4f, 0x79, 0x93, 0x5a, 0x69, 0x91, 0x37, 0x7b, 0x9d, 28 | 0x29, 0x1a, 0x0d, 0x96, 0x86, 0x2f, 0x76, 0xf2, 0xe3, 0xab, 0x27, 0x86, 29 | 0xdc, 0xf5, 0x95, 0x54, 0xe2, 0x3b, 0xc0, 0x8e, 0x1b, 0x2f, 0xc3, 0xc5, 30 | 0xdf 31 | }; 32 | unsigned int default_certificate_len = 337; 33 | -------------------------------------------------------------------------------- /example/esp8266/util/cert.h: -------------------------------------------------------------------------------- 1 | unsigned char default_certificate[] = { 2 | 0x30, 0x82, 0x01, 0x4d, 0x30, 0x81, 0xf8, 0x02, 0x09, 0x00, 0xba, 0x06, 3 | 0x02, 0x36, 0x28, 0x44, 0xd4, 0x58, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 4 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x32, 0x31, 5 | 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x27, 0x54, 0x4c, 6 | 0x53, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x44, 0x6f, 7 | 0x64, 0x67, 0x79, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 8 | 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 9 | 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x33, 0x33, 0x31, 0x30, 10 | 0x36, 0x32, 0x30, 0x34, 0x32, 0x5a, 0x17, 0x0d, 0x32, 0x38, 0x31, 0x32, 11 | 0x30, 0x37, 0x30, 0x36, 0x32, 0x30, 0x34, 0x32, 0x5a, 0x30, 0x2a, 0x31, 12 | 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x54, 0x4c, 13 | 0x53, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x31, 0x12, 0x30, 14 | 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x31, 0x32, 0x37, 0x2e, 15 | 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 16 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 17 | 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xa3, 0x5a, 0x69, 0x68, 0xaf, 0xff, 18 | 0x07, 0x27, 0x46, 0x26, 0x3c, 0xe7, 0x66, 0x90, 0x15, 0x24, 0x8d, 0x2e, 19 | 0x40, 0x22, 0x0d, 0xa5, 0x89, 0x03, 0xd0, 0xc6, 0x5e, 0x45, 0xf5, 0x03, 20 | 0x9b, 0x41, 0x2e, 0xce, 0x95, 0x29, 0x2d, 0x3b, 0x77, 0x92, 0x1b, 0xd8, 21 | 0xf8, 0x73, 0xfd, 0xa9, 0xde, 0xac, 0xee, 0x49, 0x14, 0x3b, 0x2c, 0xd9, 22 | 0x4c, 0x82, 0xad, 0xae, 0x2d, 0xe2, 0x3d, 0xc4, 0xbc, 0xef, 0x02, 0x03, 23 | 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 24 | 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, 0x00, 0x47, 0x53, 0xd3, 25 | 0x8a, 0x21, 0x0d, 0x2f, 0x75, 0xd1, 0x11, 0xbe, 0x42, 0x24, 0xe1, 0x97, 26 | 0xfa, 0xe4, 0xf8, 0x90, 0xa1, 0xe9, 0xb1, 0x2c, 0xe1, 0xc6, 0x4c, 0x3d, 27 | 0x0b, 0x54, 0xe3, 0x4f, 0x79, 0x93, 0x5a, 0x69, 0x91, 0x37, 0x7b, 0x9d, 28 | 0x29, 0x1a, 0x0d, 0x96, 0x86, 0x2f, 0x76, 0xf2, 0xe3, 0xab, 0x27, 0x86, 29 | 0xdc, 0xf5, 0x95, 0x54, 0xe2, 0x3b, 0xc0, 0x8e, 0x1b, 0x2f, 0xc3, 0xc5, 30 | 0xdf 31 | }; 32 | unsigned int default_certificate_len = 337; 33 | -------------------------------------------------------------------------------- /example/stm32/objects/led.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: led.c 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: the led object 6 | * History: 7 | * 1.Date: Sep 15, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | #include "pando_object.h" 12 | #include "stdint.h" 13 | #include "stdio.h" 14 | #include "stdlib.h" 15 | #include "sub_device_protocol.h" 16 | 17 | 18 | struct led { 19 | uint8_t red; 20 | uint8_t green; 21 | uint8_t blue; 22 | }; 23 | 24 | void led_init() 25 | { 26 | 27 | } 28 | 29 | void led_set(struct led* value) 30 | { 31 | 32 | } 33 | 34 | void led_get(struct led* value) 35 | { 36 | value->red = 255; 37 | value->green =255; 38 | value->blue = 255; 39 | } 40 | 41 | 42 | struct led* create_led() 43 | { 44 | struct led* led = (struct led*)malloc(sizeof(led)); 45 | return led; 46 | } 47 | 48 | void delete_led(struct led* led) 49 | { 50 | if(led) 51 | { 52 | free(led); 53 | } 54 | } 55 | 56 | void led_object_pack(PARAMS * params) 57 | { 58 | if(NULL == params) 59 | { 60 | printf("Create first tlv param failed.\n"); 61 | return; 62 | } 63 | 64 | struct led* led = create_led(); 65 | led_get(led); 66 | 67 | if (add_next_uint8(params, led->red)) 68 | { 69 | printf("Add next tlv param failed.\n"); 70 | return; 71 | } 72 | 73 | if (add_next_uint8(params, led->green)) 74 | { 75 | printf("Add next tlv param failed.\n"); 76 | return; 77 | } 78 | 79 | if (add_next_uint8(params, led->blue)) 80 | { 81 | printf("Add next tlv param failed.\n"); 82 | return; 83 | } 84 | 85 | delete_led(led); 86 | } 87 | 88 | void led_object_unpack(PARAMS* params) 89 | { 90 | struct led* led = create_led(); 91 | 92 | led->red = get_next_uint8(params); 93 | led->green = get_next_uint8(params); 94 | led->blue = get_next_uint8(params); 95 | 96 | led_set(led); 97 | 98 | delete_led(led); 99 | 100 | } 101 | 102 | void led_object_init() 103 | { 104 | // init here... 105 | led_init(); 106 | 107 | // register the object 108 | pando_object led_object = { 109 | 3, 110 | led_object_pack, 111 | led_object_unpack, 112 | }; 113 | register_pando_object(led_object); 114 | } 115 | -------------------------------------------------------------------------------- /example/esp8266/user/object/pm25.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/framework/subdevice/pando_object.h" 2 | #include "../../peripheral/peri_pm25.h" 3 | #include "../../peripheral/driver/uart.h" 4 | #include "c_types.h" 5 | #include "user_interface.h" 6 | #include "pm25.h" 7 | 8 | // add your own includes below 9 | #define PM25_OBJECT_NO 1 10 | 11 | struct pm25 { 12 | uint16 quality; 13 | }; 14 | void ICACHE_FLASH_ATTR 15 | pm25_init() { 16 | // TODO: add your object init code here. 17 | 18 | 19 | } 20 | void ICACHE_FLASH_ATTR 21 | pm25_set(struct pm25* value) { 22 | // TODO: implement object set function here. 23 | // the set function read value and operate the hardware. 24 | 25 | 26 | } 27 | void ICACHE_FLASH_ATTR 28 | pm25_get(struct pm25* value) { 29 | // TODO: implement object get function here 30 | // get function retrieve hardware status and assign it to value. 31 | static os_timer_t read_timer; 32 | uart_rx_intr_enable(UART0); 33 | 34 | os_timer_disarm(&read_timer); 35 | os_timer_setfn(&read_timer, (os_timer_func_t *)peri_pm_25_get,NULL); 36 | os_timer_arm(&read_timer, 1000, 0); 37 | 38 | value->quality=peri_pm_25_get(); 39 | //PRINTF("PM25_VALUE:%d \n",value->quality); 40 | } 41 | /* 42 | auto generated code below!! 43 | DO NOT edit unless you know how it works. 44 | */ 45 | struct pm25* ICACHE_FLASH_ATTR 46 | create_pm25() { 47 | struct pm25* pm25 = (struct pm25*)os_malloc(sizeof(pm25)); 48 | return pm25; 49 | } 50 | void ICACHE_FLASH_ATTR 51 | delete_pm25(struct pm25* pm25) { 52 | if(pm25){ 53 | os_free(pm25); 54 | } 55 | } 56 | void ICACHE_FLASH_ATTR 57 | pm25_object_pack(PARAMS * params) { 58 | if(NULL == params){ 59 | PRINTF("Create first tlv param failed.\n"); 60 | return; 61 | } 62 | 63 | struct pm25* pm25 = create_pm25(); 64 | pm25_get(pm25); 65 | 66 | if (add_next_uint16(params, pm25->quality)){ 67 | PRINTF("Add next param failed.\n"); 68 | return; 69 | } 70 | 71 | delete_pm25(pm25); 72 | } 73 | void ICACHE_FLASH_ATTR 74 | pm25_object_unpack(PARAMS* params) { 75 | struct pm25* pm25 = create_pm25(); 76 | 77 | pm25->quality = get_next_uint16(params); 78 | 79 | pm25_set(pm25); 80 | delete_pm25(pm25); 81 | } 82 | void ICACHE_FLASH_ATTR 83 | pm25_object_init() { 84 | pm25_init(); 85 | pando_object pm25_object = { 86 | 1, 87 | pm25_object_pack, 88 | pm25_object_unpack, 89 | }; 90 | register_pando_object(pm25_object); 91 | } 92 | -------------------------------------------------------------------------------- /example/esp8266/user/object/humiture.c: -------------------------------------------------------------------------------- 1 | #include "../../peripheral/peri_dht1122.h" 2 | #include "../../pando/framework/subdevice/pando_object.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "humiture.h" 6 | // add your own includes below 7 | #define HUMITURE_OBJECT_NO 1 8 | 9 | struct humiture { 10 | float32 percent; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | humiture_init() { 14 | // TODO: add your object init code here. 15 | DHT_Sensor dht_sensor; 16 | dht_sensor.pin = 12; 17 | dht_sensor.type = DHT11; 18 | peri_dht_init(&dht_sensor); 19 | 20 | } 21 | void ICACHE_FLASH_ATTR 22 | humiture_set(struct humiture* value) { 23 | // TODO: implement object set function here. 24 | // the set function read value and operate the hardware. 25 | 26 | 27 | } 28 | void ICACHE_FLASH_ATTR 29 | humiture_get(struct humiture* value) { 30 | // TODO: implement object get function here 31 | // get function retrieve hardware status and assign it to value. 32 | DHT_Sensor_Data output; 33 | peri_dht_read(&output); 34 | value->percent = output.humidity; 35 | 36 | } 37 | /* 38 | auto generated code below!! 39 | DO NOT edit unless you know how it works. 40 | */ 41 | struct humiture* ICACHE_FLASH_ATTR 42 | create_humiture() { 43 | struct humiture* humiture = (struct humiture*)os_malloc(sizeof(humiture)); 44 | return humiture; 45 | } 46 | void ICACHE_FLASH_ATTR 47 | delete_humiture(struct humiture* humiture) { 48 | if(humiture){ 49 | os_free(humiture); 50 | } 51 | } 52 | void ICACHE_FLASH_ATTR 53 | humiture_object_pack(PARAMS * params) { 54 | if(NULL == params){ 55 | PRINTF("Create first tlv param failed.\n"); 56 | return; 57 | } 58 | 59 | struct humiture* humiture = create_humiture(); 60 | humiture_get(humiture); 61 | 62 | if (add_next_float32(params, humiture->percent)){ 63 | PRINTF("Add next param failed.\n"); 64 | return; 65 | } 66 | 67 | delete_humiture(humiture); 68 | } 69 | void ICACHE_FLASH_ATTR 70 | humiture_object_unpack(PARAMS* params) { 71 | struct humiture* humiture = create_humiture(); 72 | 73 | humiture->percent = get_next_float32(params); 74 | 75 | humiture_set(humiture); 76 | delete_humiture(humiture); 77 | } 78 | void ICACHE_FLASH_ATTR 79 | humiture_object_init() { 80 | humiture_init(); 81 | pando_object humiture_object = { 82 | 1, 83 | humiture_object_pack, 84 | humiture_object_unpack, 85 | }; 86 | register_pando_object(humiture_object); 87 | } 88 | -------------------------------------------------------------------------------- /framework/platform/include/pando_storage_interface.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_storage_interface.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is the interface used to store the gateway data. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_STORAGE_INTERFACE_H__ 12 | #define __PANDO_STORAGE_INTERFACE_H__ 13 | 14 | #include "pando_types.h" 15 | 16 | typedef enum { 17 | CHANGE_SAVE_OK = 0, 18 | CREAT_SAVE_OK, 19 | FULL_ERROR, 20 | SAVE_ERROR, 21 | } SET_RESULT; 22 | 23 | /****************************************************************************** 24 | * FunctionName : pando_data_set 25 | * Description : set the vale of the parameter stored, if the parameter is existing. 26 | Else creat the parameter, and save it. 27 | * Parameters : key -- the parameter; 28 | value -- the value of the parameter. 29 | * Returns : the save result 30 | *******************************************************************************/ 31 | SET_RESULT pando_data_set(char* key, char* value); 32 | 33 | /****************************************************************************** 34 | * FunctionName : pando_data_get 35 | * Description : get the value of the key. 36 | * Parameters : key -- the parameter 37 | * Returns : the pointer of the value. NULL if not exist 38 | *******************************************************************************/ 39 | char * pando_data_get(char* key); 40 | 41 | /****************************************************************************** 42 | * FunctionName : pando_storage_space_left 43 | * Description : get the space left for pando data saved in the storage. 44 | * Parameters : 45 | * Returns : the space left for pando data saving. 46 | *******************************************************************************/ 47 | uint16_t pando_storage_space_left(void); 48 | 49 | /****************************************************************************** 50 | * FunctionName : pando_storage_clean. 51 | * Description : clean the pando configuration message. 52 | * Parameters : none 53 | * Returns : none 54 | *******************************************************************************/ 55 | void pando_storage_clean(void); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_key.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_key.c 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This is the key function module. 6 | 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | #include "peri_key.h" 13 | #include "user_interface.h" 14 | #include "eagle_soc.h" 15 | #include "driver/key.h" 16 | #include "os_type.h" 17 | #include "mem.h" 18 | #include "driver/tisan_gpio_intr.h" 19 | #include "driver/tisan_gpio.h" 20 | 21 | 22 | /****************************************************************************** 23 | * FunctionName : user_plug_short_press 24 | * Description : key's short press function, needed to be installed 25 | * Parameters : none 26 | * Returns : none 27 | *******************************************************************************/ 28 | void ICACHE_FLASH_ATTR 29 | peri_key_short_press(void) 30 | { 31 | PRINTF("short\n"); 32 | } 33 | 34 | 35 | /****************************************************************************** 36 | * FunctionName : user_plug_long_press 37 | * Description : key's long press function, needed to be installed, preserved function. 38 | * Parameters : none 39 | * Returns : none 40 | *******************************************************************************/ 41 | 42 | void ICACHE_FLASH_ATTR 43 | peri_key_long_press(void) 44 | { 45 | PRINTF("long\n"); 46 | } 47 | /****************************************************************************** 48 | * FunctionName : peri_key_init. 49 | * Description : initialize key device. 50 | * Parameters : none 51 | * Returns : none 52 | *******************************************************************************/ 53 | void ICACHE_FLASH_ATTR 54 | peri_single_key_init(uint8 gpio_id,key_function long_press, key_function short_press) 55 | { 56 | struct key_param *single_key = (struct key_param *)os_zalloc(sizeof(struct key_param)); 57 | uint32 gpio_name=tisan_get_gpio_name(gpio_id); 58 | uint8 gpio_func=tisan_get_gpio_general_func(gpio_id); 59 | single_key->gpio_id = gpio_id; 60 | single_key->key_level = 1; 61 | single_key->long_press = long_press; 62 | single_key->short_press = short_press; 63 | 64 | ETS_GPIO_INTR_ATTACH(gpio_intr_handler, single_key); 65 | ETS_GPIO_INTR_DISABLE(); 66 | 67 | key_init(gpio_name, gpio_id, gpio_func); 68 | 69 | ETS_GPIO_INTR_ENABLE(); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /example/esp8266/user/object/temperatrure.c: -------------------------------------------------------------------------------- 1 | #include "../../peripheral/peri_dht1122.h" 2 | #include "../../pando/framework/subdevice/pando_object.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "temperature.h" 6 | #include "mem.h" 7 | // add your own includes below 8 | 9 | 10 | struct temperature { 11 | uint8 centigrade; 12 | }; 13 | void ICACHE_FLASH_ATTR 14 | temperature_init() { 15 | // TODO: add your object init code here. 16 | DHT_Sensor dht_sensor; 17 | dht_sensor.pin = 12; 18 | dht_sensor.type = DHT11; 19 | peri_dht_init(&dht_sensor); 20 | 21 | } 22 | void ICACHE_FLASH_ATTR 23 | temperature_set(struct temperature* value) { 24 | // TODO: implement object set function here. 25 | // the set function read value and operate the hardware. 26 | 27 | 28 | } 29 | void ICACHE_FLASH_ATTR 30 | temperature_get(struct temperature* value) { 31 | // TODO: implement object get function here 32 | // get function retrieve hardware status and assign it to value. 33 | DHT_Sensor_Data output; 34 | peri_dht_read(&output); 35 | value->centigrade = output.temperature; 36 | 37 | } 38 | /* 39 | auto generated code below!! 40 | DO NOT edit unless you know how it works. 41 | */ 42 | struct temperature* ICACHE_FLASH_ATTR 43 | create_temperature() { 44 | struct temperature* temperature = (struct temperature*)os_malloc(sizeof(temperature)); 45 | return temperature; 46 | } 47 | void ICACHE_FLASH_ATTR 48 | delete_temperature(struct temperature* temperature) { 49 | if(temperature){ 50 | os_free(temperature); 51 | } 52 | } 53 | void ICACHE_FLASH_ATTR 54 | temperature_object_pack(PARAMS * params) { 55 | if(NULL == params){ 56 | PRINTF("Create first tlv param failed.\n"); 57 | return; 58 | } 59 | 60 | struct temperature* temperature = create_temperature(); 61 | temperature_get(temperature); 62 | 63 | if (add_next_uint8(params, temperature->centigrade)){ 64 | PRINTF("Add next param failed.\n"); 65 | return; 66 | } 67 | 68 | delete_temperature(temperature); 69 | } 70 | void ICACHE_FLASH_ATTR 71 | temperature_object_unpack(PARAMS* params) { 72 | struct temperature* temperature = create_temperature(); 73 | 74 | temperature->centigrade = get_next_uint8(params); 75 | 76 | temperature_set(temperature); 77 | delete_temperature(temperature); 78 | } 79 | void ICACHE_FLASH_ATTR 80 | temperature_object_init() { 81 | temperature_init(); 82 | pando_object temperature_object = { 83 | 1, 84 | temperature_object_pack, 85 | temperature_object_unpack, 86 | }; 87 | register_pando_object(temperature_object); 88 | } 89 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/queue.c: -------------------------------------------------------------------------------- 1 | /* str_queue.c 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #include "queue.h" 31 | #include "../../platform/include/pando_types.h" 32 | #include "../../platform/include/pando_sys.h" 33 | #include "proto.h" 34 | 35 | void FUNCTION_ATTRIBUTE QUEUE_Init(QUEUE *queue, int bufferSize) 36 | { 37 | queue->buf = (uint8_t*)pd_malloc(bufferSize); 38 | pd_memset(queue->buf, 0, bufferSize); 39 | RINGBUF_Init(&queue->rb, queue->buf, bufferSize); 40 | } 41 | int32_t FUNCTION_ATTRIBUTE QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len) 42 | { 43 | return PROTO_AddRb(&queue->rb, buffer, len); 44 | } 45 | int32_t FUNCTION_ATTRIBUTE QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen) 46 | { 47 | 48 | return PROTO_ParseRb(&queue->rb, buffer, len, maxLen); 49 | } 50 | 51 | BOOL FUNCTION_ATTRIBUTE QUEUE_IsEmpty(QUEUE *queue) 52 | { 53 | if(queue->rb.fill_cnt<=0) 54 | return TRUE; 55 | return FALSE; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /framework/protocol/pando_endian.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_endian.c 3 | * Author: Zhao Wenwu 4 | * Versions: 0.1 5 | * Description: APIs to change endian between net and host machine. 6 | Net is big endian, host endian depends machine. 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | 13 | 14 | #include "pando_endian.h" 15 | 16 | int little_endian = -1; 17 | 18 | int FUNCTION_ATTRIBUTE is_little_endian() 19 | { 20 | if(little_endian == -1) 21 | { 22 | union int_char 23 | { 24 | int i; 25 | char c; 26 | }x; 27 | x.i = 1; 28 | little_endian = x.c; 29 | } 30 | 31 | return little_endian; 32 | } 33 | 34 | uint16_t FUNCTION_ATTRIBUTE net16_to_host(uint16_t A) 35 | { 36 | if(is_little_endian()) 37 | { 38 | return ((((A) & 0xff00) >> 8) | (((A) & 0x00ff) << 8)); 39 | } 40 | else 41 | { 42 | return A; 43 | } 44 | } 45 | 46 | uint32_t FUNCTION_ATTRIBUTE net32_to_host(uint32_t A) 47 | { 48 | if(is_little_endian()) 49 | { 50 | return ((((A) & 0xff000000) >> 24) | \ 51 | (((A) & 0x00ff0000) >> 8 ) | \ 52 | (((A) & 0x0000ff00) << 8 ) | \ 53 | (((A) & 0x000000ff) << 24)); 54 | } 55 | else 56 | { 57 | return A; 58 | } 59 | } 60 | 61 | uint64_t FUNCTION_ATTRIBUTE net64_to_host(uint64_t A) 62 | { 63 | uint64_t mask = 0xff; 64 | if(is_little_endian()) 65 | { 66 | return ((((A) & (mask << 56)) >> 56) | \ 67 | (((A) & (mask << 48)) >> 40) | \ 68 | (((A) & (mask << 40)) >> 24) | \ 69 | (((A) & (mask << 32)) >> 8) | \ 70 | (((A) & (mask << 24)) << 8) | \ 71 | (((A) & (mask << 16)) << 24) | \ 72 | (((A) & (mask << 8)) << 40) | \ 73 | (((A) & (mask)) << 56)); 74 | } 75 | else 76 | { 77 | return A; 78 | } 79 | } 80 | 81 | 82 | float FUNCTION_ATTRIBUTE net32f_to_host(float A) 83 | { 84 | if(is_little_endian()) 85 | { 86 | union float_int 87 | { 88 | float f; 89 | uint32_t i; 90 | }x; 91 | x.f = A; 92 | x.i = net32_to_host(x.i); 93 | return x.f; 94 | } 95 | else 96 | { 97 | return A; 98 | } 99 | } 100 | 101 | double FUNCTION_ATTRIBUTE net64f_to_host(double A) 102 | { 103 | if(is_little_endian()) 104 | { 105 | union double_uint64 106 | { 107 | double d; 108 | uint64_t i; 109 | }x; 110 | x.d = A; 111 | x.i = net64_to_host(x.i); 112 | return x.d; 113 | } 114 | else 115 | { 116 | return A; 117 | } 118 | } 119 | 120 | 121 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/adc.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "osapi.h" 3 | 4 | #include "adc.h" 5 | 6 | #define i2c_bbpll 0x67 7 | #define i2c_bbpll_en_audio_clock_out 4 8 | #define i2c_bbpll_en_audio_clock_out_msb 7 9 | #define i2c_bbpll_en_audio_clock_out_lsb 7 10 | #define i2c_bbpll_hostid 4 11 | #define i2c_saradc 0x6C 12 | #define i2c_saradc_hostid 2 13 | 14 | #define i2c_saradc_en_test 0 15 | #define i2c_saradc_en_test_msb 5 16 | #define i2c_saradc_en_test_lsb 5 17 | 18 | #define i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) \ 19 | rom_i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) 20 | 21 | #define i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) \ 22 | rom_i2c_readReg_Mask_(block, host_id, reg_add, Msb, Lsb) 23 | 24 | #define i2c_writeReg_Mask_def(block, reg_add, indata) \ 25 | i2c_writeReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb, indata) 26 | 27 | #define i2c_readReg_Mask_def(block, reg_add) \ 28 | i2c_readReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb) 29 | 30 | #ifdef ADC_DEBUG 31 | #define ADC_DBG os_printf 32 | #else 33 | #define ADC_DBG 34 | #endif 35 | 36 | uint16 ICACHE_FLASH_ATTR adc_read(void) 37 | { 38 | uint8 i; 39 | uint16 sar_dout, tout, sardata[8]; 40 | 41 | i2c_writeReg_Mask_def(i2c_saradc, i2c_saradc_en_test, 1); //select test mux 42 | 43 | //PWDET_CAL_EN=0, PKDET_CAL_EN=0 44 | SET_PERI_REG_MASK(0x60000D5C, 0x200000); 45 | 46 | while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0 47 | 48 | sar_dout = 0; 49 | CLEAR_PERI_REG_MASK(0x60000D50, 0x02); //force_en=0 50 | SET_PERI_REG_MASK(0x60000D50, 0x02); //force_en=1 51 | 52 | os_delay_us(2); 53 | 54 | while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0 55 | 56 | read_sar_dout(sardata); 57 | 58 | for (i = 0; i < 8; i++) { 59 | sar_dout += sardata[i]; 60 | ADC_DBG("%d, ", sardata[i]); 61 | } 62 | 63 | tout = (sar_dout + 8) >> 4; //tout is 10 bits fraction 64 | 65 | i2c_writeReg_Mask_def(i2c_saradc, i2c_saradc_en_test, 1); //select test mux 66 | 67 | while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0 68 | 69 | CLEAR_PERI_REG_MASK(0x60000D5C, 0x200000); 70 | SET_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1 71 | CLEAR_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1 72 | 73 | return tout; //tout is 10 bits fraction 74 | } 75 | 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##pando-embedded-framework 2 | #introduction 3 | When connecting a hardware device to the internet, we need a cloud, a device, and a gateway. We have to code in the device to get the data of the real word by hardware driver, code in the gateway to connect our device to the cloud and send data to the cloud by network, code in the cloud to deal with the business. We have to do so much, on the other hand, because of the variety of gateway and device, we have to implement the save business on different platform, such as, esp8266, 5350, stm32, ardunio, and so on. 4 | The structure of conneting things to the internet is like below: 5 | ![normal-IOT-structure](doc/image/normal-IOT-structure.jpg) 6 | pando-embedded-framwork is different in that, it abstracts the common gateway business, such as register, login, access, and so on, leave the driver interface to be implemented on different platform; on the other hand, it abstracts the device common operations. 7 | ![pando-IOT_structure](doc/image/pando-IOT-structure.jpg) 8 | #directory structure 9 | -doc 10 | -framework 11 | |-gateway 12 | |-lib 13 | |-platform 14 | |-include 15 | |-src 16 | |-stm32 17 | |-protocol 18 | |-subdevice 19 | -example 20 | |-stm32 21 | 22 | `doc`:the document. 23 | `gateway`:the common gateway business. 24 | `lib`:the library used. 25 | `include`:the function declarations used in the framework, which should be implemented in different platforms. 26 | `src`:contains the implementation of the interface in `include` for different platforms. 27 | `subdevice`:the abstractation of device common operation. 28 | `example`:because of that this framework is a library, so `example` contains base initialization and main function to run. 29 | #how to 30 | If you want to use this framework in your own project, what you need to do is to implement the interface in `include` directory, and to add your own devices which are defined in `subdevice`. We will offer examples for you to refer to. 31 | If you want to know more about the whole framework, you can follow the project [pando-cloud](https://github.com/PandoCloud/pando-cloud) to learn about the cloud. And the project [tisan-kit](https://github.com/tisan-kit) contains more examples about the framework by our development board `tisan`. 32 | We also appreciate you to share your implementation on your platform or improve this framework. If you want to do so, there is [a coding style](doc/coding-style.md) for you to read first in order to cooperate better. 33 | #Example 34 | [stm32+3G](doc/eg-stm32-3g.md) 35 | [esp8266](doc/eg-esp8266.md) -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_pm25.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_plug.c 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: plug. 6 | in this example:GPIO 15: the plug relay driver; 7 | GPIO 12 a blinking led; 8 | GPIO 0 the wifi connect state indicate; 9 | GPIO 13 a press key. 10 | * History: 11 | * 1.Date: 12 | * Author: 13 | * Modification: 14 | *********************************************************/ 15 | 16 | #include "ets_sys.h" 17 | #include "osapi.h" 18 | #include "os_type.h" 19 | #include "mem.h" 20 | #include "user_interface.h" 21 | #include "driver/key.h" 22 | #include "driver/uart.h" 23 | #include "driver/uart_register.h" 24 | #include "peri_pm25.h" 25 | #include "driver/tisan_gpio.h" 26 | 27 | /* NOTICE---this is for i2c communication. 28 | * 0x84 is the i2c slave device address for 7 bit. */ 29 | 30 | PM25_REV_DATA *PM25_data_buffer; 31 | extern uint8 RcvBuff[128]; 32 | uint16 pm25_data; 33 | void display_PMdevice_data(PM25_REV_DATA *data_buffer) 34 | { 35 | PRINTF("PM device data display\n"); 36 | PRINTF("start_byte1:%x\n", data_buffer->start_byte1); 37 | PRINTF("start_byte2:%x\n", data_buffer->start_byte2); 38 | PRINTF("length:%x\n", data_buffer->length); 39 | PRINTF("pm1.0:%x\n", data_buffer->pm1_0); 40 | PRINTF("pm2.5:%x\n", data_buffer->pm2_5); 41 | PRINTF("pm10:%x\n", data_buffer->pm10_0); 42 | PRINTF("um0.3:%x\n", data_buffer->um0_3); 43 | PRINTF("um0.5:%x\n", data_buffer->um0_5); 44 | PRINTF("um1.0:%x\n", data_buffer->um1_0); 45 | PRINTF("um2.5:%x\n", data_buffer->um2_5); 46 | PRINTF("um5.0:%x\n", data_buffer->um5_0); 47 | PRINTF("um10:%x\n", data_buffer->um10_0); 48 | ETS_UART_INTR_DISABLE(); 49 | } 50 | /****************************************************************************** 51 | * FunctionName : user_mvh3004_read_th 52 | * Description : read mvh3004's humiture data 53 | * Parameters : uint8 *data - where data to put 54 | * Returns : bool - ture or false 55 | ********************************************************************************/ 56 | uint16 ICACHE_FLASH_ATTR 57 | peri_pm_25_get(void) 58 | { 59 | uint8 i,data1,data2; 60 | if(RcvBuff[0]==0x32) 61 | { 62 | data1 = RcvBuff[6]; 63 | data2 = RcvBuff[7]; 64 | pm25_data = data1*256+ data2; 65 | PRINTF("data1=%x , data2=%x\n", data1,data2); 66 | // PM25_data_buffer->pm2_5 = (RcvBuff[6]<<8)&0xff00 + RcvBuff[7] ; 67 | } 68 | 69 | // PRINTF("pm2.5:%x\n", PM25_data_buffer->pm2_5); 70 | PRINTF("pm2.5 : %x\n", pm25_data); 71 | return pm25_data; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /framework/lib/json/json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2012, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the Contiki operating system. 30 | */ 31 | 32 | /** 33 | * \file 34 | * A few JSON defines used for parsing and generating JSON. 35 | * \author 36 | * Niclas Finne 37 | * Joakim Eriksson 38 | */ 39 | 40 | #ifndef __JSON_H__ 41 | #define __JSON_H__ 42 | 43 | #define JSON_TYPE_ARRAY '[' 44 | #define JSON_TYPE_OBJECT '{' 45 | #define JSON_TYPE_PAIR ':' 46 | #define JSON_TYPE_PAIR_NAME 'N' /* for N:V pairs */ 47 | #define JSON_TYPE_STRING '"' 48 | #define JSON_TYPE_INT 'I' 49 | #define JSON_TYPE_NUMBER '0' 50 | #define JSON_TYPE_ERROR 0 51 | 52 | /* how should we handle null vs false - both can be 0? */ 53 | #define JSON_TYPE_NULL 'n' 54 | #define JSON_TYPE_TRUE 't' 55 | #define JSON_TYPE_FALSE 'f' 56 | 57 | #define JSON_TYPE_CALLBACK 'C' 58 | 59 | enum { 60 | JSON_ERROR_OK, 61 | JSON_ERROR_SYNTAX, 62 | JSON_ERROR_UNEXPECTED_ARRAY, 63 | JSON_ERROR_UNEXPECTED_END_OF_ARRAY, 64 | JSON_ERROR_UNEXPECTED_OBJECT, 65 | JSON_ERROR_UNEXPECTED_STRING 66 | }; 67 | 68 | #define JSON_CONTENT_TYPE "application/json" 69 | 70 | #endif /* __JSON_H__ */ 71 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_led.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_led.c 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the led. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_led.h" 13 | #include "eagle_soc.h" 14 | #include "driver/tisan_gpio.h" 15 | #include "os_type.h" 16 | #include "gpio.h" 17 | #include "osapi.h" 18 | 19 | static os_timer_t led_blink_timer; 20 | static uint32 led_pin; 21 | 22 | /****************************************************************************** 23 | * FunctionName : peri_led_init. 24 | * Description : initialize the led. 25 | * Parameters : uint8 gpio_id: the gpio pin drive the led. 26 | * Returns : none 27 | *******************************************************************************/ 28 | void ICACHE_FLASH_ATTR 29 | peri_led_init(uint8 gpio_id) 30 | { 31 | PIN_FUNC_SELECT(tisan_get_gpio_name(gpio_id), tisan_get_gpio_general_func(gpio_id)); 32 | PIN_PULLUP_EN(tisan_get_gpio_name(gpio_id)); 33 | led_pin = gpio_id; 34 | } 35 | 36 | /****************************************************************************** 37 | * FunctionName : led_blink_timer_cb. 38 | * Description : the led_blink_time callback function.. 39 | * Parameters : none. 40 | * Returns : none 41 | *******************************************************************************/ 42 | static void ICACHE_FLASH_ATTR 43 | led_blink_timer_cb(void* arg) 44 | { 45 | static bool state = 0; 46 | if(state == 0) 47 | { 48 | state = 1; 49 | GPIO_OUTPUT_SET(led_pin, state); 50 | } 51 | else 52 | { 53 | state = 0; 54 | GPIO_OUTPUT_SET(led_pin, state); 55 | } 56 | } 57 | 58 | /****************************************************************************** 59 | * FunctionName : peri_led_blink. 60 | * Description : blink the led. 61 | * Parameters : BLINK_SPEED speed: the blink speed. 62 | * Returns : none 63 | *******************************************************************************/ 64 | void ICACHE_FLASH_ATTR 65 | peri_led_blink(BLINK_SPEED speed) 66 | { 67 | os_timer_disarm(&led_blink_timer); 68 | os_timer_setfn(&led_blink_timer, (os_timer_func_t *)led_blink_timer_cb, NULL); 69 | os_timer_arm(&led_blink_timer, speed, 1); 70 | } 71 | 72 | /****************************************************************************** 73 | * FunctionName : peri_led_set. 74 | * Description : set the led state. 75 | * Parameters : bool state: the set state of the led, 1:on ; 0:off. 76 | * Returns : none 77 | *******************************************************************************/ 78 | void ICACHE_FLASH_ATTR 79 | peri_led_set(bool state) 80 | { 81 | os_timer_disarm(&led_blink_timer); 82 | GPIO_OUTPUT_SET(led_pin, state); 83 | } 84 | -------------------------------------------------------------------------------- /framework/gateway/pando_channel.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_channel.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to simulate connection channel (eg. serial port) between device and subdevice. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PANDO_CHANNEL_H__ 13 | #define __PANDO_CHANNEL_H__ 14 | 15 | #include "../platform/include/pando_types.h" 16 | 17 | typedef enum { 18 | PANDO_CHANNEL_PORT_0 = 0, 19 | PANDO_CHANNEL_PORT_1, 20 | PANDO_CHANNEL_PORT_2, 21 | PANDO_CHANNEL_PORT_3, 22 | PANDO_CHANNEL_PORT_4, 23 | PANDO_CHANNEL_PORT_5, 24 | PANDO_CHANNEL_PORT_6, 25 | PANDO_CHANNEL_PORT_7 26 | } PANDO_CHANNEL_NAME; 27 | 28 | /* 29 | * "channel_recv_callback" is a callback function invoked when recving buffer from some channel. 30 | */ 31 | typedef void (* channel_recv_callback)(uint8_t * buffer, uint16_t length); 32 | 33 | /****************************************************************************** 34 | * FunctionName : on_subdevice_channel_recv 35 | * Description : regiseter the callback function when subdevice received buffer from some channel. 36 | * Parameters : name: channel name 37 | * cb: callback 38 | * Returns : 39 | *******************************************************************************/ 40 | void on_subdevice_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb); 41 | 42 | /****************************************************************************** 43 | * FunctionName : on_device_channel_recv 44 | * Description : regiseter the callback function when device received buffer from some channel. 45 | * Parameters : name: channel name 46 | * cb: callback 47 | * Returns : 48 | *******************************************************************************/ 49 | void on_device_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb); 50 | 51 | /****************************************************************************** 52 | * FunctionName : subdevice_channel_send 53 | * Description : send data to subdevice. 54 | * Parameters : name: channel name 55 | * Returns : 56 | *******************************************************************************/ 57 | void channel_send_to_subdevice(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length); 58 | 59 | /****************************************************************************** 60 | * FunctionName : device_channel_send 61 | * Description : send data to device. 62 | * Parameters : name: channel name 63 | * Returns : 64 | *******************************************************************************/ 65 | void channel_send_to_device(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /example/esp8266/user/object/motor.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/framework/subdevice/pando_object.h" 2 | #include "../../peripheral/peri_motor.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "motor.h" 6 | // add your own includes below 7 | 8 | 9 | struct motor { 10 | int8 speed; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | motor_init() { 14 | // TODO: add your object init code here. 15 | struct PWM_APP_PARAM motor_param; 16 | struct PWM_INIT motor_init; 17 | motor_param.pwm_freq=25000; 18 | motor_param.pwm_duty[0]=0; 19 | motor_param.pwm_duty[1]=0; 20 | 21 | motor_init.io_num=2; 22 | motor_init.io_id[0]=12; 23 | motor_init.io_id[1]=13; 24 | 25 | peri_motor_init(motor_param,motor_init); 26 | 27 | } 28 | void ICACHE_FLASH_ATTR 29 | motor_set(struct motor* value) { 30 | // TODO: implement object set function here. 31 | // the set function read value and operate the hardware. 32 | struct PWM_APP_PARAM motor_param; 33 | motor_param.pwm_freq=25000; 34 | if((value->speed)>=0) //forward 35 | { 36 | motor_param.pwm_duty[0]=value->speed; 37 | motor_param.pwm_duty[1]=0; 38 | 39 | } 40 | else 41 | { 42 | motor_param.pwm_duty[0]=0; 43 | motor_param.pwm_duty[1]=0-(value->speed); 44 | 45 | } 46 | 47 | peri_motor_set(motor_param); 48 | 49 | } 50 | void ICACHE_FLASH_ATTR 51 | motor_get(struct motor* value) { 52 | // TODO: implement object get function here 53 | // get function retrieve hardware status and assign it to value. 54 | struct PWM_APP_PARAM motor_param; 55 | motor_param=peri_motor_get(); 56 | if(motor_param.pwm_duty[0]==0) 57 | { 58 | value->speed=0-(motor_param.pwm_duty[1]); 59 | } 60 | if(motor_param.pwm_duty[1]==0) 61 | { 62 | value->speed=(motor_param.pwm_duty[0]); 63 | } 64 | 65 | } 66 | /* 67 | auto generated code below!! 68 | DO NOT edit unless you know how it works. 69 | */ 70 | struct motor* ICACHE_FLASH_ATTR 71 | create_motor() { 72 | struct motor* motor = (struct motor*)os_malloc(sizeof(motor)); 73 | return motor; 74 | } 75 | void ICACHE_FLASH_ATTR 76 | delete_motor(struct motor* motor) { 77 | if(motor){ 78 | os_free(motor); 79 | } 80 | } 81 | void ICACHE_FLASH_ATTR 82 | motor_object_pack(PARAMS * params) { 83 | if(NULL == params){ 84 | PRINTF("Create first tlv param failed.\n"); 85 | return; 86 | } 87 | 88 | struct motor* motor = create_motor(); 89 | motor_get(motor); 90 | 91 | if (add_next_int8(params, motor->speed)){ 92 | PRINTF("Add next param failed.\n"); 93 | return; 94 | } 95 | 96 | delete_motor(motor); 97 | } 98 | void ICACHE_FLASH_ATTR 99 | motor_object_unpack(PARAMS* params) { 100 | struct motor* motor = create_motor(); 101 | 102 | motor->speed = get_next_int8(params); 103 | 104 | motor_set(motor); 105 | delete_motor(motor); 106 | } 107 | void ICACHE_FLASH_ATTR 108 | motor_object_init() { 109 | motor_init(); 110 | pando_object motor_object = { 111 | 1, 112 | motor_object_pack, 113 | motor_object_unpack, 114 | }; 115 | register_pando_object(motor_object); 116 | } 117 | -------------------------------------------------------------------------------- /framework/gateway/pando_zero_device.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_zero_device.c 3 | * Author: Chongguang Li 4 | * Versions: 1.0 5 | * Description:This module is used to process the gateway business. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | #include "pando_channel.h" 12 | #include "../platform/include/pando_types.h" 13 | #include "../protocol/sub_device_protocol.h" 14 | //#include "pando_system_time.h" 15 | #include "pando_zero_device.h" 16 | #include "../platform/include/pando_sys.h" 17 | 18 | #define COMMON_COMMAND_UPGRADE 65529 19 | #define COMMON_COMMAND_REBOOT 65535 20 | #define COMMON_COMMAND_SYN_TIME 65531 21 | 22 | /****************************************************************************** 23 | * FunctionName : zero_device_data_process. 24 | * Description : process the received data of zero device(zero device is the gateway itself). 25 | * Parameters : uint. 26 | * Returns : none. 27 | *******************************************************************************/ 28 | static void FUNCTION_ATTRIBUTE 29 | zero_device_data_process(uint8_t * buffer, uint16_t length) 30 | { 31 | struct pando_command cmd_body; 32 | uint16_t type = 0; 33 | uint16_t len = 0; 34 | struct sub_device_buffer * device_buffer = (struct sub_device_buffer *)pd_malloc(sizeof(struct sub_device_buffer)); 35 | if(device_buffer == NULL) 36 | { 37 | pd_printf("%s:malloc error!\n", __func__); 38 | return; 39 | } 40 | device_buffer->buffer = (uint8_t*)pd_malloc(length); 41 | if(device_buffer->buffer == NULL) 42 | { 43 | pd_printf("%s:malloc error!\n", __func__); 44 | pd_free(device_buffer); 45 | return; 46 | } 47 | pd_memcpy(device_buffer->buffer, buffer, length); 48 | device_buffer->buffer_length = length; 49 | struct TLVs *cmd_param = get_sub_device_command(device_buffer, &cmd_body); 50 | if(COMMON_COMMAND_SYN_TIME == cmd_body.command_num ) 51 | { 52 | pd_printf("PANDO: synchronize time\n"); 53 | uint64_t time = get_next_uint64(cmd_param); 54 | show_package((uint8_t*)(&time), sizeof(time)); 55 | // pando_set_system_time(time); 56 | } 57 | 58 | if( device_buffer->buffer != NULL) 59 | { 60 | pd_free( device_buffer->buffer); 61 | device_buffer->buffer = NULL; 62 | } 63 | 64 | if(device_buffer != NULL) 65 | { 66 | pd_free(device_buffer); 67 | device_buffer = NULL; 68 | } 69 | } 70 | 71 | /****************************************************************************** 72 | * FunctionName : ipando_zero_device_init 73 | * Description : initialize the zero device(zero device is the gateway itself). 74 | * Parameters : none. 75 | * Returns : none. 76 | *******************************************************************************/ 77 | void FUNCTION_ATTRIBUTE 78 | pando_zero_device_init(void) 79 | { 80 | on_subdevice_channel_recv(PANDO_CHANNEL_PORT_0, zero_device_data_process); 81 | } 82 | -------------------------------------------------------------------------------- /example/esp8266/user/object/c_motor.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/framework/subdevice/pando_object.h" 2 | #include "../../peripheral/peri_motor.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "c_motor.h" 6 | #include "mem.h" 7 | // add your own includes below 8 | 9 | 10 | struct c_motor { 11 | int8 content; 12 | }; 13 | void ICACHE_FLASH_ATTR 14 | c_motor_init() { 15 | // TODO: add your object init code here. 16 | // TODO: add your object init code here. 17 | struct PWM_APP_PARAM motor_param; 18 | struct PWM_INIT motor_init; 19 | motor_param.pwm_freq=25000; 20 | motor_param.pwm_duty[0]=0; 21 | motor_param.pwm_duty[1]=0; 22 | 23 | motor_init.io_num=2; 24 | motor_init.io_id[0]=12; 25 | motor_init.io_id[1]=13; 26 | 27 | peri_motor_init(motor_param,motor_init); 28 | 29 | } 30 | void ICACHE_FLASH_ATTR 31 | c_motor_set(struct c_motor* value) { 32 | // TODO: implement object set function here. 33 | // the set function read value and operate the hardware. 34 | struct PWM_APP_PARAM motor_param; 35 | motor_param.pwm_freq=25000; 36 | if((value->content)>=0) //forward 37 | { 38 | motor_param.pwm_duty[0]=value->content; 39 | motor_param.pwm_duty[1]=0; 40 | 41 | } 42 | else 43 | { 44 | motor_param.pwm_duty[0]=0; 45 | motor_param.pwm_duty[1]=0-(value->content); 46 | 47 | } 48 | 49 | peri_motor_set(motor_param); 50 | 51 | } 52 | void ICACHE_FLASH_ATTR 53 | c_motor_get(struct c_motor* value) { 54 | // TODO: implement object get function here 55 | // get function retrieve hardware status and assign it to value. 56 | struct PWM_APP_PARAM motor_param; 57 | motor_param=peri_motor_get(); 58 | if(motor_param.pwm_duty[0]==0) 59 | { 60 | value->content=0-(motor_param.pwm_duty[1]); 61 | } 62 | if(motor_param.pwm_duty[1]==0) 63 | { 64 | value->content=(motor_param.pwm_duty[0]); 65 | } 66 | 67 | } 68 | /* 69 | auto generated code below!! 70 | DO NOT edit unless you know how it works. 71 | */ 72 | struct c_motor* ICACHE_FLASH_ATTR 73 | create_c_motor() { 74 | struct c_motor* c_motor = (struct c_motor*)os_malloc(sizeof(c_motor)); 75 | return c_motor; 76 | } 77 | void ICACHE_FLASH_ATTR 78 | delete_c_motor(struct c_motor* c_motor) { 79 | if(c_motor){ 80 | os_free(c_motor); 81 | } 82 | } 83 | void ICACHE_FLASH_ATTR 84 | c_motor_object_pack(PARAMS * params) { 85 | if(NULL == params){ 86 | PRINTF("Create first tlv param failed.\n"); 87 | return; 88 | } 89 | 90 | struct c_motor* c_motor = create_c_motor(); 91 | c_motor_get(c_motor); 92 | 93 | if (add_next_int8(params, c_motor->content)){ 94 | PRINTF("Add next param failed.\n"); 95 | return; 96 | } 97 | 98 | delete_c_motor(c_motor); 99 | } 100 | void ICACHE_FLASH_ATTR 101 | c_motor_object_unpack(PARAMS* params) { 102 | struct c_motor* c_motor = create_c_motor(); 103 | 104 | c_motor->content = get_next_int8(params); 105 | 106 | c_motor_set(c_motor); 107 | delete_c_motor(c_motor); 108 | } 109 | void ICACHE_FLASH_ATTR 110 | c_motor_object_init() { 111 | c_motor_init(); 112 | pando_object c_motor_object = { 113 | 2, 114 | c_motor_object_pack, 115 | c_motor_object_unpack, 116 | }; 117 | register_pando_object(c_motor_object); 118 | } 119 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/key.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: key.c 5 | * 6 | * Description: key driver, now can use different gpio and install different function 7 | * 8 | * Modification history: 9 | * 2014/5/1, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "os_type.h" 13 | #include "osapi.h" 14 | #include "mem.h" 15 | #include "gpio.h" 16 | #include "user_interface.h" 17 | #include "key.h" 18 | 19 | 20 | /****************************************************************************** 21 | * FunctionName : key_init 22 | * Description : init keys 23 | * Parameters : key_param *keys - keys parameter, which inited by key_init_single 24 | * Returns : none 25 | *******************************************************************************/ 26 | void ICACHE_FLASH_ATTR 27 | key_init(uint32 gpio_name,uint8 gpio_id,uint8 gpio_func) 28 | { 29 | PIN_FUNC_SELECT(gpio_name,gpio_func); 30 | PIN_PULLUP_EN(gpio_name); 31 | gpio_output_set(0, 0, 0, GPIO_ID_PIN(gpio_id)); 32 | 33 | gpio_register_set(GPIO_PIN_ADDR(gpio_id), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) 34 | | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) 35 | | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); 36 | 37 | //clear interrupt status 38 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(gpio_id)); 39 | 40 | //enable interrupt 41 | gpio_pin_intr_state_set(GPIO_ID_PIN(gpio_id), GPIO_PIN_INTR_NEGEDGE); 42 | } 43 | /****************************************************************************** 44 | * FunctionName : key_5s_cb 45 | * Description : long press 5s timer callback 46 | * Parameters : single_key_param *single_key - single key parameter 47 | * Returns : none 48 | *******************************************************************************/ 49 | void ICACHE_FLASH_ATTR 50 | key_5s_cb(struct key_param *single_key) 51 | { 52 | os_timer_disarm(&single_key->key_5s); 53 | 54 | if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { 55 | if (single_key->long_press) { 56 | single_key->long_press(); 57 | } 58 | } 59 | } 60 | 61 | /****************************************************************************** 62 | * FunctionName : key_50ms_cb 63 | * Description : 50ms timer callback to check it's a real key push 64 | * Parameters : single_key_param *single_key - single key parameter 65 | * Returns : none 66 | *******************************************************************************/ 67 | void ICACHE_FLASH_ATTR 68 | key_50ms_cb(struct key_param *single_key) 69 | { 70 | os_timer_disarm(&single_key->key_50ms); 71 | 72 | // high, then key is up 73 | if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { 74 | os_timer_disarm(&single_key->key_5s); 75 | single_key->key_level = 1; 76 | gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_NEGEDGE); 77 | 78 | if (single_key->short_press) { 79 | single_key->short_press(); 80 | } 81 | } else { 82 | gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_POSEDGE); 83 | } 84 | } 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /framework/gateway/mqtt/proto.c: -------------------------------------------------------------------------------- 1 | #include "proto.h" 2 | #include "ringbuf.h" 3 | #include "../../platform/include/pando_types.h" 4 | 5 | I8 FUNCTION_ATTRIBUTE PROTO_Init(PROTO_PARSER *parser, PROTO_PARSE_CALLBACK *completeCallback, U8 *buf, U16 bufSize) 6 | { 7 | parser->buf = buf; 8 | parser->bufSize = bufSize; 9 | parser->dataLen = 0; 10 | parser->callback = completeCallback; 11 | parser->isEsc = 0; 12 | return 0; 13 | } 14 | 15 | I8 FUNCTION_ATTRIBUTE PROTO_ParseByte(PROTO_PARSER *parser, U8 value) 16 | { 17 | switch(value){ 18 | case 0x7D: 19 | parser->isEsc = 1; 20 | break; 21 | 22 | case 0x7E: 23 | parser->dataLen = 0; 24 | parser->isEsc = 0; 25 | parser->isBegin = 1; 26 | break; 27 | 28 | case 0x7F: 29 | if (parser->callback != NULL) 30 | parser->callback(); 31 | parser->isBegin = 0; 32 | return 0; 33 | break; 34 | 35 | default: 36 | if(parser->isBegin == 0) break; 37 | 38 | if(parser->isEsc){ 39 | value ^= 0x20; 40 | parser->isEsc = 0; 41 | } 42 | 43 | if(parser->dataLen < parser->bufSize) 44 | parser->buf[parser->dataLen++] = value; 45 | 46 | break; 47 | } 48 | return -1; 49 | } 50 | 51 | I8 FUNCTION_ATTRIBUTE PROTO_Parse(PROTO_PARSER *parser, U8 *buf, U16 len) 52 | { 53 | while(len--) 54 | PROTO_ParseByte(parser, *buf++); 55 | 56 | return 0; 57 | } 58 | I16 FUNCTION_ATTRIBUTE PROTO_ParseRb(RINGBUF* rb, U8 *bufOut, U16* len, U16 maxBufLen) 59 | { 60 | U8 c; 61 | 62 | PROTO_PARSER proto; 63 | PROTO_Init(&proto, NULL, bufOut, maxBufLen); 64 | while(RINGBUF_Get(rb, &c) == 0){ 65 | if(PROTO_ParseByte(&proto, c) == 0){ 66 | *len = proto.dataLen; 67 | return 0; 68 | } 69 | } 70 | return -1; 71 | } 72 | I16 FUNCTION_ATTRIBUTE PROTO_Add(U8 *buf, const U8 *packet, I16 bufSize) 73 | { 74 | U16 i = 2; 75 | U16 len = *(U16*) packet; 76 | 77 | if (bufSize < 1) return -1; 78 | 79 | *buf++ = 0x7E; 80 | bufSize--; 81 | 82 | while (len--) { 83 | switch (*packet) { 84 | case 0x7D: 85 | case 0x7E: 86 | case 0x7F: 87 | if (bufSize < 2) return -1; 88 | *buf++ = 0x7D; 89 | *buf++ = *packet++ ^ 0x20; 90 | i += 2; 91 | bufSize -= 2; 92 | break; 93 | default: 94 | if (bufSize < 1) return -1; 95 | *buf++ = *packet++; 96 | i++; 97 | bufSize--; 98 | break; 99 | } 100 | } 101 | 102 | if (bufSize < 1) return -1; 103 | *buf++ = 0x7F; 104 | 105 | return i; 106 | } 107 | 108 | I16 FUNCTION_ATTRIBUTE PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len) 109 | { 110 | U16 i = 2; 111 | if(RINGBUF_Put(rb, 0x7E) == -1) return -1; 112 | while (len--) { 113 | switch (*packet) { 114 | case 0x7D: 115 | case 0x7E: 116 | case 0x7F: 117 | if(RINGBUF_Put(rb, 0x7D) == -1) return -1; 118 | if(RINGBUF_Put(rb, *packet++ ^ 0x20) == -1) return -1; 119 | i += 2; 120 | break; 121 | default: 122 | if(RINGBUF_Put(rb, *packet++) == -1) return -1; 123 | i++; 124 | break; 125 | } 126 | } 127 | if(RINGBUF_Put(rb, 0x7F) == -1) return -1; 128 | 129 | return i; 130 | } 131 | 132 | -------------------------------------------------------------------------------- /example/stm32/util/task.c: -------------------------------------------------------------------------------- 1 | #include "task.h" 2 | #include 3 | 4 | //define the task node structure in the system task scheduler 5 | typedef struct task_node { 6 | task *ptask; 7 | struct task_node *pre; 8 | struct task_node *next; 9 | }task_node; 10 | 11 | //declare the task head in the task queue 12 | task_node *g_task_head = NULL; 13 | 14 | /****************************************************************************** 15 | * FunctionName : new_task 16 | * Description : new a empty task 17 | * Parameters : none 18 | * Returns : the created task 19 | *******************************************************************************/ 20 | task * new_task(void) 21 | { 22 | return (task *)malloc(sizeof(task)); 23 | } 24 | 25 | /****************************************************************************** 26 | * FunctionName : add_task 27 | * Description : add a new task to the system 28 | * Parameters : the task to be added 29 | * Returns : the add operation result 30 | *******************************************************************************/ 31 | int8_t add_task(task *ptask) 32 | { 33 | task_node *cur_task_tail; 34 | task_node *new_task_node; 35 | new_task_node = (task_node *)malloc(sizeof(task_node)); 36 | if(new_task_node == NULL) 37 | { 38 | return -1; 39 | } 40 | 41 | new_task_node->pre = NULL; 42 | new_task_node->next = NULL; 43 | new_task_node->ptask = ptask; 44 | if(g_task_head == NULL) 45 | { 46 | g_task_head = new_task_node; 47 | return 0; 48 | } 49 | 50 | if(g_task_head->next == NULL) 51 | { 52 | cur_task_tail = g_task_head; 53 | } 54 | else 55 | { 56 | cur_task_tail = g_task_head->next; 57 | } 58 | 59 | while(cur_task_tail->next != NULL) 60 | { 61 | cur_task_tail = cur_task_tail->next; 62 | } 63 | 64 | cur_task_tail->next = new_task_node; 65 | new_task_node->pre = cur_task_tail; 66 | new_task_node->next = NULL; 67 | return 0; 68 | } 69 | 70 | /****************************************************************************** 71 | * FunctionName : pop_task 72 | * Description : pop a task from the system 73 | * Parameters : none 74 | * Returns : the task 75 | *******************************************************************************/ 76 | task* pop_task(void) 77 | { 78 | task_node *cur_task_head = g_task_head; 79 | task_node *next_task_node; 80 | task *ptask; 81 | if(cur_task_head == NULL) 82 | { 83 | return NULL; 84 | } 85 | 86 | next_task_node = cur_task_head->next; 87 | if(next_task_node == NULL) 88 | { 89 | ptask = cur_task_head->ptask; 90 | g_task_head = NULL; 91 | free(cur_task_head); 92 | return ptask; 93 | } 94 | 95 | ptask = cur_task_head->ptask; 96 | g_task_head = next_task_node; 97 | g_task_head->pre = NULL; 98 | cur_task_head->next = NULL; 99 | free(cur_task_head); 100 | return ptask; 101 | } 102 | 103 | /****************************************************************************** 104 | * FunctionName : delete_task 105 | * Description : delete a task 106 | * Parameters : the task to be deleted 107 | * Returns : none 108 | *******************************************************************************/ 109 | void delete_task(task *ptask) 110 | { 111 | if(ptask == NULL) 112 | { 113 | return; 114 | } 115 | 116 | if(ptask->pdata != NULL) 117 | { 118 | free(ptask->pdata); 119 | } 120 | 121 | free(ptask); 122 | } 123 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_motor.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_motor.c 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: motor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_motor.h" 13 | 14 | #include "../pando/framework/subdevice/pando_object.h" 15 | #include "peri_rgb_light.h" 16 | 17 | #include "user_interface.h" 18 | #include "driver/pwm.h" 19 | #include "c_types.h" 20 | #include "spi_flash.h" 21 | #include "driver/tisan_gpio.h" 22 | 23 | extern uint8_t FLASH_SEC_NUM ; 24 | 25 | 26 | #define MOTOR_FLASH_PRIV_SAVE FLASH_SEC_NUM 27 | 28 | struct PWM_APP_PARAM motor_forward_param={25000,40,0}; 29 | struct PWM_APP_PARAM motor_backard_param={25000,0,40}; 30 | 31 | /****************************************************************************** 32 | * FunctionName : peri_motor_get. 33 | * Description : get the parameter of the motor status. 34 | * Parameters : none 35 | * Returns : the parameter of the motor status. 36 | *******************************************************************************/ 37 | 38 | struct PWM_APP_PARAM ICACHE_FLASH_ATTR 39 | peri_motor_get(void) 40 | { 41 | struct PWM_APP_PARAM ret; 42 | 43 | spi_flash_read((PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 44 | (uint32 *)&ret, sizeof(struct PWM_APP_PARAM)); 45 | return ret; 46 | } 47 | 48 | 49 | /****************************************************************************** 50 | * FunctionName : peri_motor_set. 51 | * Description : set the parameter of motor status. 52 | * Parameters : struct LIGHT_PARAM motor_param. 53 | * Returns : none 54 | *******************************************************************************/ 55 | 56 | void ICACHE_FLASH_ATTR 57 | peri_motor_set( struct PWM_APP_PARAM motor_param) 58 | { 59 | pwm_set_freq(motor_param.pwm_freq); 60 | pwm_set_duty(motor_param.pwm_duty[0], 0); 61 | pwm_set_duty(motor_param.pwm_duty[1], 1); 62 | pwm_set_duty(motor_param.pwm_duty[2], 2); 63 | 64 | pwm_start(); 65 | 66 | spi_flash_erase_sector(PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE); 67 | spi_flash_write((PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 68 | (uint32 *)&motor_param, sizeof(struct PWM_APP_PARAM)); 69 | } 70 | 71 | /****************************************************************************** 72 | * FunctionName : peri_motor_init 73 | * Description : motor initialize , mainly initialize pwm mode 74 | * Parameters : struct LIGHT_PARAM motor_param,struct LIGHT_INIT motor_init 75 | * Returns : none 76 | *******************************************************************************/ 77 | void ICACHE_FLASH_ATTR 78 | peri_motor_init(struct PWM_APP_PARAM motor_param,struct PWM_INIT motor_init) 79 | { 80 | PRINTF("I am the electronic-motor\n"); 81 | PRINTF("pwm_freq: %d, pwm_duty1: %d, pwm_duty2: %d\n",motor_param.pwm_freq, 82 | (motor_param.pwm_duty)[0], (motor_param.pwm_duty)[1]); 83 | PRINTF("start flash write \n"); 84 | 85 | spi_flash_write((PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 86 | (uint32 *)&motor_param, sizeof(struct PWM_APP_PARAM)); 87 | 88 | PRINTF("finished \n"); 89 | pwm_init(motor_param,motor_init); 90 | pwm_start(); 91 | 92 | } 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/driver/spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 David Ogilvy (MetalPhreak) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef SPI_APP_H 26 | #define SPI_APP_H 27 | 28 | #include "spi_register.h" 29 | #include "ets_sys.h" 30 | #include "osapi.h" 31 | //#include "uart.h" 32 | #include "os_type.h" 33 | 34 | //Define SPI hardware modules 35 | #define SPI 0 36 | #define HSPI 1 37 | 38 | #define SPI_CLK_USE_DIV 0 39 | #define SPI_CLK_80MHZ_NODIV 1 40 | 41 | #define SPI_BYTE_ORDER_HIGH_TO_LOW 1 42 | #define SPI_BYTE_ORDER_LOW_TO_HIGH 0 43 | 44 | #ifndef CPU_CLK_FREQ //Should already be defined in eagle_soc.h 45 | #define CPU_CLK_FREQ 80*1000000 46 | #endif 47 | 48 | //Define some default SPI clock settings 49 | #define SPI_CLK_PREDIV 10 50 | #define SPI_CLK_CNTDIV 2 51 | #define SPI_CLK_FREQ CPU_CLK_FREQ/(SPI_CLK_PREDIV*SPI_CLK_CNTDIV) // 80 / 20 = 4 MHz 52 | 53 | 54 | 55 | 56 | 57 | void spi_init(uint8 spi_no); 58 | void spi_init_gpio(uint8 spi_no, uint8 sysclk_as_spiclk); 59 | void spi_clock(uint8 spi_no, uint16 prediv, uint8 cntdiv); 60 | void spi_tx_byte_order(uint8 spi_no, uint8 byte_order); 61 | void spi_rx_byte_order(uint8 spi_no, uint8 byte_order); 62 | uint32 spi_transaction(uint8 spi_no, uint8 cmd_bits, uint16 cmd_data, uint32 addr_bits, uint32 addr_data, uint32 dout_bits, uint32 dout_data, uint32 din_bits, uint32 dummy_bits); 63 | 64 | //Expansion Macros 65 | #define spi_busy(spi_no) READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR 66 | 67 | #define spi_txd(spi_no, bits, data) spi_transaction(spi_no, 0, 0, 0, 0, bits, (uint32) data, 0, 0) 68 | #define spi_tx8(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 8, (uint32) data, 0, 0) 69 | #define spi_tx7(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 7, (uint32) data, 0, 0) 70 | #define spi_tx9(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 9, (uint32) data, 0, 0) 71 | #define spi_tx16(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 16, (uint32) data, 0, 0) 72 | #define spi_tx32(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 32, (uint32) data, 0, 0) 73 | 74 | #define spi_rxd(spi_no, bits) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, bits, 0) 75 | #define spi_rx8(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 8, 0) 76 | #define spi_rx16(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 16, 0) 77 | #define spi_rx32(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 32, 0) 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /example/esp8266/peripheral/peri_i2c_oled.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_i2c_oled.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is the i2c oled driver. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef APP_PERIPHERAL_PERI_I2C_OLED_H_ 13 | #define APP_PERIPHERAL_PERI_I2C_OLED_H_ 14 | 15 | #include "c_types.h" 16 | 17 | #define OLED_ADDRESS 0x78 // D/C->GND 18 | //#define OLED_ADDRESS 0x7a // D/C->Vcc 19 | 20 | /****************************************************************************** 21 | * FunctionName : peri_i2c_oled_init 22 | * Description : initialize the oled. 23 | * Parameters : none. 24 | * Returns : none. 25 | *******************************************************************************/ 26 | bool ICACHE_FLASH_ATTR 27 | peri_i2c_oled_init(void); 28 | 29 | /****************************************************************************** 30 | * FunctionName : peri_oled_clean_screen. 31 | * Description : clean the screen of the oled. 32 | * Parameters : none. 33 | * Returns : none. 34 | *******************************************************************************/ 35 | void ICACHE_FLASH_ATTR 36 | peri_oled_clean_screen(void); 37 | 38 | /****************************************************************************** 39 | * FunctionName : peri_oled_on. 40 | * Description : turn on the oled. 41 | * Parameters : none. 42 | * Returns : none. 43 | *******************************************************************************/ 44 | void ICACHE_FLASH_ATTR 45 | peri_oled_on(void); 46 | 47 | /****************************************************************************** 48 | * FunctionName : peri_oled_off. 49 | * Description : turn off the oled. 50 | * Parameters : none. 51 | * Returns : none. 52 | *******************************************************************************/ 53 | void ICACHE_FLASH_ATTR 54 | peri_oled_off(void); 55 | 56 | /****************************************************************************** 57 | * FunctionName : peri_oled_show_str. 58 | * Description : print string to the oled. 59 | * Parameters : unsigned char x: the string x position; 60 | * unsigned char y: the string y position; 61 | * unsigned char ch[]: the print string; 62 | * unsigned char len: the length of the string. 63 | * unsigned char text_size: the size of the string. 64 | * Returns : none. 65 | *******************************************************************************/ 66 | void ICACHE_FLASH_ATTR 67 | peri_oled_show_str(unsigned char x, unsigned char y, unsigned char ch[], unsigned char len, unsigned char text_size); 68 | /****************************************************************************** 69 | * FunctionName : peri_oled_draw_bmp. 70 | * Description : print the bmp picture to the oled. 71 | * Parameters : unsigned char x0: the left horizontal position of the bmp picture; 72 | * unsigned char y0: the left vertical position of the bmp picture; 73 | * unsigned char x1: the right horizontal position of the bmp picture; 74 | * unsigned char y1: the left vertical position of the bmp picture; 75 | * unsigned char bmp[]: the bmp picture array; 76 | * Returns : none. 77 | *******************************************************************************/ 78 | void ICACHE_FLASH_ATTR 79 | peri_oled_draw_bmp(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char bmp[]); 80 | #endif /* APP_PERIPHERAL_PERI_I2C_OLED_H_ */ 81 | -------------------------------------------------------------------------------- /example/esp8266/user/object/led.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: led.c 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: the led object 6 | * History: 7 | * 1.Date: Sep 15, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | #include "../../pando/framework/subdevice/pando_object.h" 12 | #include "c_types.h" 13 | #include "user_interface.h" 14 | #include "../../peripheral/peri_rgb_light.h" 15 | #include "mem.h" 16 | 17 | #define LED_OBJECT_NO 1 18 | 19 | struct led { 20 | uint8 red; 21 | uint8 green; 22 | uint8 blue; 23 | }; 24 | 25 | void ICACHE_FLASH_ATTR 26 | led_init() 27 | { 28 | struct PWM_APP_PARAM light_param; 29 | struct PWM_INIT light_init; 30 | light_param.pwm_freq=25000; 31 | light_param.pwm_duty[0]=255; 32 | light_param.pwm_duty[1]=255; 33 | light_param.pwm_duty[2]=255; 34 | 35 | light_init.io_num=3; 36 | light_init.io_id[0]=13; 37 | light_init.io_id[1]=14; 38 | light_init.io_id[2]=15; 39 | 40 | peri_rgb_light_init(light_param,light_init); 41 | } 42 | 43 | void ICACHE_FLASH_ATTR 44 | led_set(struct led* value) 45 | { 46 | struct PWM_APP_PARAM light_value; 47 | light_value.pwm_freq=25000; 48 | light_value.pwm_duty[0] = 255-(value->blue); 49 | light_value.pwm_duty[1] = 255-(value->red); 50 | light_value.pwm_duty[2] = 255-(value->green); 51 | peri_rgb_light_param_set(light_value); 52 | 53 | // PRINTF("pwm_freq: %d, pwm_duty_blue: %d, pwm_duty_red: %d, pwm_duty_green: %d\n", light_value.pwm_freq, 54 | // (light_value.pwm_duty)[0], (light_value.pwm_duty)[1], (light_value.pwm_duty)[2]); 55 | } 56 | 57 | void ICACHE_FLASH_ATTR 58 | led_get(struct led* value) 59 | { 60 | struct PWM_APP_PARAM light_value; 61 | light_value = peri_rgb_light_param_get(); 62 | value->red = 255 -light_value.pwm_duty[0]; 63 | value->green =255 - light_value.pwm_duty[1]; 64 | value->blue = 255 -light_value.pwm_duty[2]; 65 | } 66 | 67 | 68 | struct led* ICACHE_FLASH_ATTR 69 | create_led() 70 | { 71 | struct led* led = (struct led*)os_malloc(sizeof(led)); 72 | return led; 73 | } 74 | 75 | void ICACHE_FLASH_ATTR 76 | delete_led(struct led* led) 77 | { 78 | if(led) 79 | { 80 | os_free(led); 81 | } 82 | } 83 | 84 | void ICACHE_FLASH_ATTR 85 | led_object_pack(PARAMS * params) 86 | { 87 | if(NULL == params) 88 | { 89 | PRINTF("Create first tlv param failed.\n"); 90 | return; 91 | } 92 | 93 | struct led* led = create_led(); 94 | led_get(led); 95 | 96 | if (add_next_uint8(params, led->red)) 97 | { 98 | PRINTF("Add next tlv param failed.\n"); 99 | return; 100 | } 101 | 102 | if (add_next_uint8(params, led->green)) 103 | { 104 | PRINTF("Add next tlv param failed.\n"); 105 | return; 106 | } 107 | 108 | if (add_next_uint8(params, led->blue)) 109 | { 110 | PRINTF("Add next tlv param failed.\n"); 111 | return; 112 | } 113 | 114 | delete_led(led); 115 | } 116 | 117 | void ICACHE_FLASH_ATTR 118 | led_object_unpack(PARAMS* params) 119 | { 120 | struct led* led = create_led(); 121 | 122 | led->red = get_next_uint8(params); 123 | led->green = get_next_uint8(params); 124 | led->blue = get_next_uint8(params); 125 | 126 | led_set(led); 127 | 128 | delete_led(led); 129 | 130 | } 131 | 132 | void ICACHE_FLASH_ATTR 133 | led_object_init() 134 | { 135 | // init here... 136 | led_init(); 137 | 138 | // register the object 139 | pando_object led_object = { 140 | LED_OBJECT_NO, 141 | led_object_pack, 142 | led_object_unpack, 143 | }; 144 | register_pando_object(led_object); 145 | } 146 | --------------------------------------------------------------------------------