mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-20 18:05:54 +08:00
更新硬件SDK
This commit is contained in:
@@ -0,0 +1,354 @@
|
||||
#ifndef __RTE_DEVICE_H
|
||||
#define __RTE_DEVICE_H
|
||||
|
||||
#include "ec618.h"
|
||||
|
||||
/* Peripheral IO Mode Select, Must Configure First !!!
|
||||
Note, when receiver works in DMA_MODE, interrupt is also enabled to transfer tailing bytes.
|
||||
*/
|
||||
|
||||
#define POLLING_MODE 0x1
|
||||
#define DMA_MODE 0x2
|
||||
#define IRQ_MODE 0x3
|
||||
#define UNILOG_MODE 0x4
|
||||
|
||||
#define RTE_UART0_TX_IO_MODE UNILOG_MODE
|
||||
#define RTE_UART0_RX_IO_MODE IRQ_MODE
|
||||
#define USART0_RX_TRIG_LVL (30)
|
||||
|
||||
#define RTE_UART1_TX_IO_MODE DMA_MODE
|
||||
#define RTE_UART1_RX_IO_MODE DMA_MODE
|
||||
|
||||
#define RTE_UART2_TX_IO_MODE DMA_MODE
|
||||
#define RTE_UART2_RX_IO_MODE DMA_MODE
|
||||
|
||||
#define RTE_SPI0_IO_MODE POLLING_MODE
|
||||
|
||||
#define RTE_SPI1_IO_MODE POLLING_MODE
|
||||
|
||||
#define RTE_I2C0_IO_MODE POLLING_MODE
|
||||
#define RTE_I2C1_IO_MODE POLLING_MODE
|
||||
|
||||
|
||||
// I2C0 (Inter-integrated Circuit Interface) [Driver_I2C0]
|
||||
// Configuration settings for Driver_I2C0 in component ::Drivers:I2C
|
||||
#define RTE_I2C0 1
|
||||
|
||||
// { PAD_PIN13}, // 4 : gpio14 / 2 : I2C0 SCL
|
||||
// { PAD_PIN14}, // 4 : gpio15 / 2 : I2C0 SDA
|
||||
#define RTE_I2C0_SCL_BIT 13 // AUDIO use 13
|
||||
#define RTE_I2C0_SCL_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_I2C0_SDA_BIT 14 // AUDIO use 14
|
||||
#define RTE_I2C0_SDA_FUNC PAD_MUX_ALT2
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C0_DMA_TX_EN 0
|
||||
#define RTE_I2C0_DMA_TX_REQID DMA_REQUEST_I2C0_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C0_DMA_RX_EN 0
|
||||
#define RTE_I2C0_DMA_RX_REQID DMA_REQUEST_I2C0_RX
|
||||
|
||||
// I2C1 (Inter-integrated Circuit Interface) [Driver_I2C1]
|
||||
// Configuration settings for Driver_I2C1 in component ::Drivers:I2C
|
||||
#define RTE_I2C1 1
|
||||
|
||||
// { PAD_PIN20}, // 0 : gpio5 / 2 : I2C1 SCL
|
||||
// { PAD_PIN19}, // 0 : gpio4 / 2 : I2C1 SDA
|
||||
#define RTE_I2C1_SCL_BIT 20
|
||||
#define RTE_I2C1_SCL_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_I2C1_SDA_BIT 19
|
||||
#define RTE_I2C1_SDA_FUNC PAD_MUX_ALT2
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C1_DMA_TX_EN 1
|
||||
#define RTE_I2C1_DMA_TX_REQID DMA_REQUEST_I2C1_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C1_DMA_RX_EN 1
|
||||
#define RTE_I2C1_DMA_RX_REQID DMA_REQUEST_I2C1_RX
|
||||
|
||||
|
||||
// UART0 (Universal asynchronous receiver transmitter) [Driver_USART0]
|
||||
// Configuration settings for Driver_USART0 in component ::Drivers:USART
|
||||
#define RTE_UART0_CTS_PIN_EN 0
|
||||
#define RTE_UART0_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN27}, // 0 : gpio12 / 3 : UART0 RTSn
|
||||
// { PAD_PIN28}, // 0 : gpio13 / 3 : UART0 CTSn
|
||||
// { PAD_PIN29}, // 0 : gpio14 / 3 : UART0 RXD
|
||||
// { PAD_PIN30}, // 0 : gpio15 / 3 : UART0 TXD
|
||||
#define RTE_UART0_RTS_BIT 27
|
||||
#define RTE_UART0_RTS_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_CTS_BIT 28
|
||||
#define RTE_UART0_CTS_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_RX_BIT 29
|
||||
#define RTE_UART0_RX_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_TX_BIT 30
|
||||
#define RTE_UART0_TX_FUNC PAD_MUX_ALT3
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART0_DMA_TX_REQID DMA_REQUEST_USART0_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART0_DMA_RX_REQID DMA_REQUEST_USART0_RX
|
||||
|
||||
// UART1 (Universal asynchronous receiver transmitter) [Driver_USART1]
|
||||
// Configuration settings for Driver_USART1 in component ::Drivers:USART
|
||||
#define RTE_UART1_CTS_PIN_EN 0
|
||||
#define RTE_UART1_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN31}, // 0 : gpio16 / 1 : UART1 RTS
|
||||
// { PAD_PIN32}, // 0 : gpio17 / 1 : UART1 CTS
|
||||
// { PAD_PIN33}, // 0 : gpio18 / 1 : UART1 RXD
|
||||
// { PAD_PIN34}, // 0 : gpio19 / 1 : UART1 TXD
|
||||
#define RTE_UART1_RTS_BIT 31
|
||||
#define RTE_UART1_RTS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_CTS_BIT 32
|
||||
#define RTE_UART1_CTS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_RX_BIT 33
|
||||
#define RTE_UART1_RX_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_TX_BIT 34
|
||||
#define RTE_UART1_TX_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART1_DMA_TX_REQID DMA_REQUEST_USART1_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART1_DMA_RX_REQID DMA_REQUEST_USART1_RX
|
||||
|
||||
// UART2 (Universal asynchronous receiver transmitter) [Driver_USART2]
|
||||
// Configuration settings for Driver_USART2 in component ::Drivers:USART
|
||||
#define RTE_UART2_CTS_PIN_EN 0
|
||||
#define RTE_UART2_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN25}, // 0 : gpio10 / 3 : UART2 RXD
|
||||
// { PAD_PIN26}, // 0 : gpio11 / 3 : UART2 TXD
|
||||
#define RTE_UART2_RX_BIT 25
|
||||
#define RTE_UART2_RX_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART2_TX_BIT 26
|
||||
#define RTE_UART2_TX_FUNC PAD_MUX_ALT3
|
||||
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART2_DMA_TX_REQID DMA_REQUEST_USART2_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART2_DMA_RX_REQID DMA_REQUEST_USART2_RX
|
||||
|
||||
// SPI0 (Serial Peripheral Interface) [Driver_SPI0]
|
||||
// Configuration settings for Driver_SPI0 in component ::Drivers:SPI
|
||||
#define RTE_SPI0 1
|
||||
|
||||
// { PAD_PIN23}, // 0 : gpio8 / 1 : SPI0 SSn
|
||||
// { PAD_PIN24}, // 0 : gpio9 / 1 : SPI0 MOSI
|
||||
// { PAD_PIN25}, // 0 : gpio10 / 1 : SPI0 MISO
|
||||
// { PAD_PIN26}, // 0 : gpio11 / 1 : SPI0 SCLK
|
||||
#define RTE_SPI0_SSN_BIT 0xFF
|
||||
#define RTE_SPI0_SSN_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_MOSI_BIT 24
|
||||
#define RTE_SPI0_MOSI_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_MISO_BIT 25
|
||||
#define RTE_SPI0_MISO_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_SCLK_BIT 26
|
||||
#define RTE_SPI0_SCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_SSN_GPIO_INSTANCE 0
|
||||
#define RTE_SPI0_SSN_GPIO_INDEX 8
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI0_DMA_TX_REQID DMA_REQUEST_SPI0_TX
|
||||
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI0_DMA_RX_REQID DMA_REQUEST_SPI0_RX
|
||||
|
||||
// SPI1 (Serial Peripheral Interface) [Driver_SPI1]
|
||||
// Configuration settings for Driver_SPI1 in component ::Drivers:SPI
|
||||
#define RTE_SPI1 0
|
||||
|
||||
// { PAD_PIN27}, // 0 : gpio12 / 1 : SPI1 SSn
|
||||
// { PAD_PIN28}, // 0 : gpio13 / 1 : SPI1 MOSI
|
||||
// { PAD_PIN29}, // 0 : gpio14 / 1 : SPI1 MISO
|
||||
// { PAD_PIN30}, // 0 : gpio15 / 1 : SPI1 SCLK
|
||||
// { PAD_PIN31}, // 0 : gpio16 / 4 : SPI1 SSn1
|
||||
#define RTE_SPI1_SSN_BIT 27
|
||||
#define RTE_SPI1_SSN_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_MOSI_BIT 28
|
||||
#define RTE_SPI1_MOSI_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_MISO_BIT 29
|
||||
#define RTE_SPI1_MISO_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_SCLK_BIT 30
|
||||
#define RTE_SPI1_SCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_SSN_GPIO_INSTANCE 0
|
||||
#define RTE_SPI1_SSN_GPIO_INDEX 12
|
||||
|
||||
#define RTE_SPI1_SSN1_BIT 31
|
||||
#define RTE_SPI1_SSN1_FUNC PAD_MUX_ALT4
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI1_DMA_TX_REQID DMA_REQUEST_SPI1_TX
|
||||
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI1_DMA_RX_REQID DMA_REQUEST_SPI1_RX
|
||||
|
||||
|
||||
// PWM0 Controller [Driver_PWM0]
|
||||
// Configuration settings for Driver_PWM0 in component ::Drivers:PWM
|
||||
#define RTE_PWM 1
|
||||
|
||||
#define EFUSE_INIT_MODE POLLING_MODE
|
||||
#define L2CTLS_INIT_MODE POLLING_MODE
|
||||
|
||||
#define FLASH_BARE_RW_MODE 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define RTE_UART0 1
|
||||
#define RTE_UART1 1
|
||||
#define RTE_UART2 1
|
||||
/* to enable external thermal */
|
||||
#define EXTERNAL_NTC_EXIST 0
|
||||
|
||||
|
||||
#if (RTE_UART1 == 1)
|
||||
#define UART1_DTR_PAD_INDEX 26 // GPIO11
|
||||
#define UART1_DTR_GPIO_INSTANCE 0
|
||||
#define UART1_DTR_GPIO_PIN 11
|
||||
|
||||
#define UART1_RI_PAD_INDEX 44 // AONIO 4 = GPIO24
|
||||
#define UART1_RI_GPIO_INSTANCE 1
|
||||
#define UART1_RI_GPIO_PIN 8
|
||||
#define UART1_RI_PWM_INSTANCE 1
|
||||
#define UART1_RI_PWM_CLK_ID FCLK_TIMER1
|
||||
#define UART1_RI_PWM_CLK_SEL FCLK_TIMER1_SEL_26M
|
||||
|
||||
#define UART1_DCD_PAD_INDEX 45 // AONIO 5 = GPIO25
|
||||
#define UART1_DCD_GPIO_INSTANCE 1
|
||||
#define UART1_DCD_GPIO_PIN 9
|
||||
#endif
|
||||
|
||||
#if (RTE_UART2 == 1)
|
||||
#define UART2_DTR_PAD_INDEX 25 // GPIO10
|
||||
#define UART2_DTR_GPIO_INSTANCE 0
|
||||
#define UART2_DTR_GPIO_PIN 10
|
||||
|
||||
#define UART2_RI_PAD_INDEX 43 // AONIO 3 = GPIO23
|
||||
#define UART2_RI_GPIO_INSTANCE 1
|
||||
#define UART2_RI_GPIO_PIN 7
|
||||
#define UART2_RI_PWM_INSTANCE 0
|
||||
#define UART2_RI_PWM_CLK_ID FCLK_TIMER0
|
||||
#define UART2_RI_PWM_CLK_SEL FCLK_TIMER0_SEL_26M
|
||||
|
||||
#define UART2_DCD_PAD_INDEX 47 // AONIO 7 = GPIO27
|
||||
#define UART2_DCD_GPIO_INSTANCE 1
|
||||
#define UART2_DCD_GPIO_PIN 11
|
||||
#endif
|
||||
|
||||
|
||||
#define NETLIGHT_PAD_INDEX 46 // AONIO 6 = GPIO26
|
||||
#define NETLIGHT_PAD_ALT_FUNC PAD_MUX_ALT5
|
||||
#define NETLIGHT_PWM_INSTANCE 3
|
||||
|
||||
//USIM1 OPTION1
|
||||
#define USIM1_URST_OP1_PAD_INDEX 19 // GPIO4
|
||||
#define USIM1_URST_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_URST_OP1_GPIO_PIN 4
|
||||
#define USIM1_UCLK_OP1_PAD_INDEX 20 // GPIO5
|
||||
#define USIM1_UCLK_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_UCLK_OP1_GPIO_PIN 5
|
||||
#define USIM1_UIO_OP1_PAD_INDEX 21 // GPIO6
|
||||
#define USIM1_UIO_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_UIO_OP1_GPIO_PIN 6
|
||||
|
||||
//USIM1 OPTION2
|
||||
#define USIM1_UIO_OP2_PAD_INDEX 27 // GPIO12
|
||||
#define USIM1_UIO_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_UIO_OP2_GPIO_PIN 12
|
||||
#define USIM1_URST_OP2_PAD_INDEX 28 // GPIO13
|
||||
#define USIM1_URST_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_URST_OP2_GPIO_PIN 13
|
||||
#define USIM1_UCLK_OP2_PAD_INDEX 29 // GPIO14
|
||||
#define USIM1_UCLK_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_UCLK_OP2_GPIO_PIN 14
|
||||
|
||||
//USIM1 clock latched by AONIO, for example, use AONIO-6 test on EVB
|
||||
#define AONIO_6_PAD_INDEX 46 // AONIO 6 = GPIO26
|
||||
#define AONIO_6_GPIO_INSTANCE 1
|
||||
#define AONIO_6_GPIO_PIN 10
|
||||
|
||||
#define RTE_CSPI0 0
|
||||
|
||||
#define RTE_CSPI0_MCLK_PAD_ADDR 39
|
||||
#define RTE_CSPI0_MCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_PCLK_PAD_ADDR 35
|
||||
#define RTE_CSPI0_PCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_CS_PAD_ADDR 36
|
||||
#define RTE_CSPI0_CS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_SDO0_PAD_ADDR 37
|
||||
#define RTE_CSPI0_SDO0_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_SDO1_PAD_ADDR 38
|
||||
#define RTE_CSPI0_SDO1_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA CSPI0 Request ID
|
||||
#define RTE_CSPI0_DMA_RX_REQID DMA_REQUEST_I2S0_RX
|
||||
|
||||
// CSPI1 Configuration
|
||||
#define RTE_CSPI1 1
|
||||
|
||||
#define RTE_CSPI1_MCLK_PAD_ADDR 18
|
||||
#define RTE_CSPI1_MCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_PCLK_PAD_ADDR 19
|
||||
#define RTE_CSPI1_PCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_CS_PAD_ADDR 20
|
||||
#define RTE_CSPI1_CS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_SDO0_PAD_ADDR 21
|
||||
#define RTE_CSPI1_SDO0_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_SDO1_PAD_ADDR 22
|
||||
#define RTE_CSPI1_SDO1_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA CSPI1 Request ID
|
||||
#define RTE_CSPI1_DMA_RX_REQID DMA_REQUEST_I2S1_RX
|
||||
|
||||
#endif /* __RTE_DEVICE_H */
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef _LBSLOC_H
|
||||
#define _LBSLOC_H
|
||||
|
||||
#include "commontypedef.h"
|
||||
|
||||
#define AM_LOCATION_SERVICE_LOCATION_BCD_LEN 5
|
||||
#define AM_LOCATION_SERVICE_RCV_TIMEOUT 15
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct am_location_service_rsp_data_t
|
||||
{
|
||||
PACK_STRUCT_FLD_8(u8_t result);
|
||||
PACK_STRUCT_FIELD(u8_t latitude[AM_LOCATION_SERVICE_LOCATION_BCD_LEN]);
|
||||
PACK_STRUCT_FIELD(u8_t longitude[AM_LOCATION_SERVICE_LOCATION_BCD_LEN]);
|
||||
PACK_STRUCT_FLD_8(u8_t year);
|
||||
PACK_STRUCT_FLD_8(u8_t month);
|
||||
PACK_STRUCT_FLD_8(u8_t day);
|
||||
PACK_STRUCT_FLD_8(u8_t hour);
|
||||
PACK_STRUCT_FLD_8(u8_t minute);
|
||||
PACK_STRUCT_FLD_8(u8_t second);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void lbsloc_Init(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "common_api.h"
|
||||
#include "luat_debug.h"
|
||||
#include "luat_rtos.h"
|
||||
#include "luat_mobile.h"
|
||||
#include "lbsLoc.h"
|
||||
uint8_t link_UP = 0;
|
||||
static void mobile_event_callback_t(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t status)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case LUAT_MOBILE_EVENT_NETIF:
|
||||
switch (status)
|
||||
{
|
||||
case LUAT_MOBILE_NETIF_LINK_ON:
|
||||
link_UP = 1;
|
||||
LUAT_DEBUG_PRINT("网络注册成功\r\n");
|
||||
break;
|
||||
default:
|
||||
LUAT_DEBUG_PRINT("网络未注册成功\r\n");
|
||||
link_UP = 0;
|
||||
break;
|
||||
}
|
||||
case LUAT_MOBILE_EVENT_SIM:
|
||||
switch (status)
|
||||
{
|
||||
case LUAT_MOBILE_SIM_READY:
|
||||
LUAT_DEBUG_PRINT("SIM卡已插入\r\n");
|
||||
break;
|
||||
case LUAT_MOBILE_NO_SIM:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case LUAT_MOBILE_EVENT_CELL_INFO:
|
||||
switch (status)
|
||||
{
|
||||
case LUAT_MOBILE_CELL_INFO_UPDATE:
|
||||
LUAT_DEBUG_PRINT("周期性搜索小区信息完成一次\r\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lbsloc_demo_task(void *param)
|
||||
{
|
||||
while (!link_UP)
|
||||
{
|
||||
luat_rtos_task_sleep(1000);
|
||||
LUAT_DEBUG_PRINT("等待网络注册");
|
||||
}
|
||||
luat_rtos_task_sleep(15000);
|
||||
while (1)
|
||||
{
|
||||
lbsloc_Init();
|
||||
luat_rtos_task_sleep(30000);
|
||||
}
|
||||
}
|
||||
|
||||
void lbsloc_demo_Init(void)
|
||||
{
|
||||
luat_rtos_task_handle lbsloc_demo_task_handle;
|
||||
luat_rtos_task_create(&lbsloc_demo_task_handle, 4 * 2048, 60, "lbsloc_demo_task", lbsloc_demo_task, NULL, NULL);
|
||||
}
|
||||
void mobile_event_task(void)
|
||||
{
|
||||
luat_mobile_event_register_handler(mobile_event_callback_t);
|
||||
}
|
||||
INIT_HW_EXPORT(mobile_event_task, "0");
|
||||
INIT_TASK_EXPORT(lbsloc_demo_Init,"1");
|
||||
@@ -0,0 +1,347 @@
|
||||
#include "common_api.h"
|
||||
#include "sockets.h"
|
||||
#include "dns.h"
|
||||
#include "lwip/ip4_addr.h"
|
||||
#include "netdb.h"
|
||||
#include "luat_debug.h"
|
||||
#include "luat_rtos.h"
|
||||
#include "luat_mobile.h"
|
||||
#include "lbsLoc.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "luat_wifiscan.h"
|
||||
|
||||
#define DEMO_SERVER_UDP_IP "bs.openluat.com" // 基站定位网址
|
||||
#define DEMO_SERVER_UDP_PORT 12411 // 端口
|
||||
|
||||
#define WIFI_LOC 0 // 是否开启wifi 定位
|
||||
/// @brief 合宙IOT 项目productkey ,必须加上,否则定位失败
|
||||
static uint8_t *productKey = "Rxw9b8iG96P1W2CnSXa15IwmYDFifNt1";
|
||||
|
||||
extern uint8_t link_UP; // 网络状态指示
|
||||
|
||||
static uint8_t imeiToBcd(uint8_t *arr, uint8_t len, uint8_t *outPut)
|
||||
{
|
||||
if (len % 2 != 0)
|
||||
{
|
||||
arr[len] = 0x0f;
|
||||
}
|
||||
|
||||
uint8_t tmp = 0;
|
||||
|
||||
for (uint8_t j = 0; j < len; j = j + 2)
|
||||
{
|
||||
outPut[tmp] = (arr[j] & 0x0f) << 4 | (arr[j + 1] & 0x0f);
|
||||
tmp++;
|
||||
}
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
outPut[i] = (outPut[i] % 0x10) * 0x10 + (outPut[i] - (outPut[i] % 0x10)) / 0x10;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @brief BCD ->> str
|
||||
/// @param pOutBuffer
|
||||
/// @param pInBuffer
|
||||
/// @param nInLen 长度
|
||||
/// @return
|
||||
static uint32_t location_service_bcd_to_str(uint8_t *pOutBuffer, uint8_t *pInBuffer, uint32_t nInLen)
|
||||
{
|
||||
uint32_t len = 0;
|
||||
uint8_t ch;
|
||||
uint8_t *p = pOutBuffer;
|
||||
uint32_t i = 0;
|
||||
|
||||
if (pOutBuffer == NULL || pInBuffer == NULL || nInLen == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < nInLen; i++)
|
||||
{
|
||||
ch = pInBuffer[i] & 0x0F;
|
||||
if (ch == 0x0F)
|
||||
{
|
||||
break;
|
||||
}
|
||||
*pOutBuffer++ = ch + '0';
|
||||
|
||||
ch = (pInBuffer[i] >> 4) & 0x0F;
|
||||
if (ch == 0x0F)
|
||||
{
|
||||
break;
|
||||
}
|
||||
*pOutBuffer++ = ch + '0';
|
||||
}
|
||||
|
||||
len = pOutBuffer - p;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static bool location_service_parse_response(struct am_location_service_rsp_data_t *response, uint8_t *latitude, uint8_t *longitude,
|
||||
uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *minute, uint8_t *second)
|
||||
{
|
||||
uint8_t loc[20] = {0};
|
||||
uint32_t len = 0;
|
||||
|
||||
if (response == NULL || latitude == NULL || longitude == NULL || year == NULL || month == NULL || day == NULL || hour == NULL || minute == NULL || second == NULL)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("location_service_parse_response: invalid parameter\r\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!(response->result == 0 || response->result == 0xFF))
|
||||
{
|
||||
LUAT_DEBUG_PRINT("location_service_parse_response: result fail %d\r\n", response->result);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// latitude
|
||||
len = location_service_bcd_to_str(loc, response->latitude, AM_LOCATION_SERVICE_LOCATION_BCD_LEN);
|
||||
if (len <= 0)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("location_service_parse_response: latitude fail\r\n");
|
||||
return FALSE;
|
||||
}
|
||||
strncat((char *)latitude, (char *)loc, 3);
|
||||
strncat((char *)latitude, ".", 2);
|
||||
strncat((char *)latitude, (char *)(loc + 3), len - 3);
|
||||
len = location_service_bcd_to_str(loc, response->longitude, AM_LOCATION_SERVICE_LOCATION_BCD_LEN);
|
||||
if (len <= 0)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("location_service_parse_response: longitude fail\r\n");
|
||||
return FALSE;
|
||||
}
|
||||
strncat((char *)longitude, (char *)loc, 3);
|
||||
strncat((char *)longitude, (char *)".", 2);
|
||||
strncat((char *)longitude, (char *)(loc + 3), len - 3);
|
||||
*year = response->year + 2000;
|
||||
*month = response->month;
|
||||
*day = response->day;
|
||||
*hour = response->hour;
|
||||
*minute = response->minute;
|
||||
*second = response->second;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void lbsloc_Init_Task(void *param)
|
||||
{
|
||||
ip_addr_t remote_ip;
|
||||
char *txbuf;
|
||||
struct sockaddr_in name;
|
||||
socklen_t sockaddr_t_size = sizeof(name);
|
||||
int ret;
|
||||
struct timeval to;
|
||||
int socket_id = -1;
|
||||
struct hostent dns_result;
|
||||
struct hostent *p_result;
|
||||
int h_errnop, read_len;
|
||||
struct am_location_service_rsp_data_t locationServiceResponse;
|
||||
|
||||
|
||||
uint8_t latitude[20] = {0}; // 经度
|
||||
uint8_t longitude[20] = {0}; // 维度
|
||||
uint16_t year = 0; // 年
|
||||
uint8_t month = 0; // 月
|
||||
uint8_t day = 0; // 日
|
||||
uint8_t hour = 0; // 小时
|
||||
uint8_t minute = 0; // 分钟
|
||||
uint8_t second = 0; // 秒
|
||||
txbuf = malloc(128);
|
||||
ret = lwip_gethostbyname_r(DEMO_SERVER_UDP_IP, &dns_result, txbuf, 128, &p_result, &h_errnop);
|
||||
if (!ret)
|
||||
{
|
||||
remote_ip = *((ip_addr_t *)dns_result.h_addr_list[0]);
|
||||
free(txbuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(txbuf);
|
||||
LUAT_DEBUG_PRINT("dns fail\r\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
socket_id = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
fcntl(socket_id, F_SETFL, O_NONBLOCK);
|
||||
memset(&name, 0, sizeof(name));
|
||||
name.sin_family = AF_INET;
|
||||
name.sin_addr.s_addr = IPADDR_ANY;
|
||||
name.sin_port = 0;
|
||||
bind(socket_id, (const struct sockaddr *)&name, sockaddr_t_size);
|
||||
name.sin_family = AF_INET;
|
||||
name.sin_addr.s_addr = remote_ip.u_addr.ip4.addr;
|
||||
name.sin_port = htons(DEMO_SERVER_UDP_PORT);
|
||||
while (1)
|
||||
{
|
||||
uint8_t lbsLocReqBuf[127] = {0};
|
||||
memset(lbsLocReqBuf, 0, 127);
|
||||
uint8_t sendLen = 0;
|
||||
lbsLocReqBuf[sendLen++] = 32;
|
||||
memcpy(&lbsLocReqBuf[sendLen], (uint8_t*)productKey, 32);
|
||||
sendLen = sendLen + 32;
|
||||
#if WIFI_LOC
|
||||
lbsLocReqBuf[sendLen++] = 0x38;
|
||||
|
||||
#else
|
||||
lbsLocReqBuf[sendLen++] = 0x28;
|
||||
#endif
|
||||
CHAR imeiBuf[16];
|
||||
memset(imeiBuf, 0, sizeof(imeiBuf));
|
||||
luat_mobile_get_imei(0, imeiBuf, 16);
|
||||
uint8_t imeiBcdBuf[8] = {0};
|
||||
imeiToBcd((uint8_t *)imeiBuf, 15, imeiBcdBuf);
|
||||
memcpy(&lbsLocReqBuf[sendLen], (uint8_t*)imeiBcdBuf, 8);
|
||||
sendLen = sendLen + 8;
|
||||
CHAR muidBuf[64];
|
||||
memset(muidBuf, 0, sizeof(muidBuf));
|
||||
luat_mobile_get_muid(muidBuf, sizeof(muidBuf));
|
||||
lbsLocReqBuf[sendLen++] = strlen(muidBuf);
|
||||
memcpy(&lbsLocReqBuf[sendLen], (uint8_t *)muidBuf, strlen(muidBuf));
|
||||
sendLen = sendLen + strlen(muidBuf);
|
||||
luat_mobile_cell_info_t cell_info;
|
||||
memset(&cell_info, 0, sizeof(cell_info));
|
||||
ret=luat_mobile_get_cell_info_async(5);
|
||||
if (ret != 0)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("cell_info_async false\r\n");
|
||||
goto quit;
|
||||
}
|
||||
luat_rtos_task_sleep(5000);
|
||||
ret=luat_mobile_get_last_notify_cell_info(&cell_info);
|
||||
//ret = luat_mobile_get_cell_info(&cell_info);//同步方式获取cell_info
|
||||
if (ret != 0)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("get last notify cell_info false\r\n");
|
||||
goto quit;
|
||||
}
|
||||
lbsLocReqBuf[sendLen++] = 0x01;
|
||||
lbsLocReqBuf[sendLen++] = (cell_info.lte_service_info.tac >> 8) & 0xFF;
|
||||
lbsLocReqBuf[sendLen++] = cell_info.lte_service_info.tac & 0xFF;
|
||||
lbsLocReqBuf[sendLen++] = (cell_info.lte_service_info.mcc >> 8) & 0xFF;
|
||||
lbsLocReqBuf[sendLen++] = cell_info.lte_service_info.mcc & 0XFF;
|
||||
uint8_t mnc = cell_info.lte_service_info.mnc;
|
||||
if (mnc > 10)
|
||||
{
|
||||
CHAR buf[3] = {0};
|
||||
snprintf(buf, 3, "%02x", mnc);
|
||||
int ret1 = atoi(buf);
|
||||
lbsLocReqBuf[sendLen++] = ret1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lbsLocReqBuf[sendLen++] = mnc;
|
||||
}
|
||||
int16_t sRssi;
|
||||
uint8_t retRssi;
|
||||
sRssi = cell_info.lte_service_info.rssi;
|
||||
if (sRssi <= -113)
|
||||
{
|
||||
retRssi = 0;
|
||||
}
|
||||
else if (sRssi < -52)
|
||||
{
|
||||
retRssi = (sRssi + 113) >> 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
retRssi = 31;
|
||||
}
|
||||
lbsLocReqBuf[sendLen++] = retRssi;
|
||||
lbsLocReqBuf[sendLen++] = (cell_info.lte_service_info.cid >> 24) & 0xFF;
|
||||
lbsLocReqBuf[sendLen++] = (cell_info.lte_service_info.cid >> 16) & 0xFF;
|
||||
lbsLocReqBuf[sendLen++] = (cell_info.lte_service_info.cid >> 8) & 0xFF;
|
||||
lbsLocReqBuf[sendLen++] = cell_info.lte_service_info.cid & 0xFF;
|
||||
|
||||
#if WIFI_LOC
|
||||
luat_wifiscan_set_info_t wifiscan_set_info;
|
||||
luat_wifisacn_get_info_t wifiscan_get_info;
|
||||
wifiscan_set_info.maxTimeOut = 10000;
|
||||
wifiscan_set_info.round = 1;
|
||||
wifiscan_set_info.maxBssidNum = LUAT_MAX_WIFI_BSSID_NUM;
|
||||
wifiscan_set_info.scanTimeOut = 5;
|
||||
wifiscan_set_info.wifiPriority = LUAT_WIFISCAN_DATA_PERFERRD;
|
||||
|
||||
ret = luat_get_wifiscan_cell_info(&wifiscan_set_info, &wifiscan_get_info);
|
||||
if (ret!=0)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("get wifiscan cell info false\r\n");
|
||||
goto quit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wifiscan_get_info.bssidNum > 0)
|
||||
{
|
||||
lbsLocReqBuf[sendLen++] = wifiscan_get_info.bssidNum;
|
||||
for (int i = 0; i < wifiscan_get_info.bssidNum; i++)
|
||||
{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{
|
||||
lbsLocReqBuf[sendLen++] = wifiscan_get_info.bssid[i][j];
|
||||
}
|
||||
lbsLocReqBuf[sendLen++] = wifiscan_get_info.rssi[i] + 255;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LUAT_DEBUG_PRINT("get wifiscan cell info wifiscan_get_info.bssidNum %d\r\n",wifiscan_get_info.bssidNum);
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ret = sendto(socket_id, lbsLocReqBuf, sendLen, 0, (const struct sockaddr *)&name, sockaddr_t_size);
|
||||
luat_rtos_task_sleep(5000);
|
||||
if (ret == sendLen)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("lbsLocSendRequest send lbsLoc request success\r\n");
|
||||
ret = recv(socket_id, &locationServiceResponse, sizeof(struct am_location_service_rsp_data_t), 0);
|
||||
LUAT_DEBUG_PRINT("lbSloc_result %d\r\n", locationServiceResponse.result);
|
||||
if ((locationServiceResponse.result==0)|| (locationServiceResponse.result==255))
|
||||
{
|
||||
if (sizeof(struct am_location_service_rsp_data_t) == ret)
|
||||
{
|
||||
if (location_service_parse_response(&locationServiceResponse, latitude, longitude, &year, &month, &day, &hour, &minute, &second) == TRUE)
|
||||
{
|
||||
LUAT_DEBUG_PRINT("latitude:%s,longitude:%s,year:%d,month:%d,day:%d,hour:%d,minute:%d,second:%d\r\n", latitude, longitude, year, month, day, hour, minute, second);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
LUAT_DEBUG_PRINT("location_service_task: rcv response, but process fail\r\n");break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
LUAT_DEBUG_PRINT("lbsLocSendRequest send lbsLoc request fail\r\n");break;
|
||||
}
|
||||
}
|
||||
quit:
|
||||
memset(latitude, 0, 20);
|
||||
memset(longitude, 0, 20);
|
||||
year = 0;
|
||||
month = 0;
|
||||
day = 0;
|
||||
hour = 0;
|
||||
minute = 0;
|
||||
second = 0;
|
||||
LUAT_DEBUG_PRINT("lbsloc init quit\r\n");
|
||||
close(socket_id);
|
||||
socket_id = -1;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void lbsloc_Init(void)
|
||||
{
|
||||
luat_rtos_task_handle lbsloc_Init_handle;
|
||||
luat_rtos_task_create(&lbsloc_Init_handle, 4 * 2048, 80, "lbsloc_Init", lbsloc_Init_Task, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
local TARGET_NAME = "example_lbsLoc"
|
||||
local LIB_DIR = "$(buildir)/".. TARGET_NAME .. "/"
|
||||
local LIB_NAME = "lib" .. TARGET_NAME .. ".a "
|
||||
|
||||
target(TARGET_NAME)
|
||||
set_kind("static")
|
||||
set_targetdir(LIB_DIR)
|
||||
|
||||
--加入代码和头文件
|
||||
add_includedirs("./inc",{public = true})
|
||||
add_files("./src/*.c",{public = true})
|
||||
|
||||
--路径可以随便写,可以加任意路径的代码,下面代码等效上方代码
|
||||
-- add_includedirs(SDK_TOP .. "project/" .. TARGET_NAME .. "/inc",{public = true})
|
||||
-- add_files(SDK_TOP .. "project/" .. TARGET_NAME .. "/src/*.c",{public = true})
|
||||
|
||||
-- 按需链接mbedtls
|
||||
-- add_defines("MBEDTLS_CONFIG_FILE=\"config_ec_ssl_comm.h\"")
|
||||
-- add_files(SDK_TOP .. "PLAT/middleware/thirdparty/mbedtls/library/*.c")
|
||||
-- 按需编译httpclient
|
||||
-- add_files(SDK_TOP .. "PLAT/middleware/thirdparty/httpclient/*.c")
|
||||
|
||||
--可以继续增加add_includedirs和add_files
|
||||
--自动链接
|
||||
LIB_USER = LIB_USER .. SDK_TOP .. LIB_DIR .. LIB_NAME
|
||||
--甚至可以加入自己的库
|
||||
target_end()
|
||||
Reference in New Issue
Block a user