更新硬件SDK

This commit is contained in:
kerwincui
2023-03-04 03:44:56 +08:00
parent dcdf6e1b7c
commit e39d3d2f03
1900 changed files with 663153 additions and 0 deletions

View File

@@ -0,0 +1,349 @@
#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 POLLING_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_PIN28}, // 0 : gpio13 / 2 : I2C0 SCL
// { PAD_PIN27}, // 0 : gpio12 / 2 : I2C0 SDA
#define RTE_I2C0_SCL_BIT 28 // AUDIO use 28
#define RTE_I2C0_SCL_FUNC PAD_MUX_ALT2
#define RTE_I2C0_SDA_BIT 27 // AUDIO use 27
#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 1
//#define RTE_UART1_RTS_PIN_EN 1
// { 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_PIN21}, // 0 : gpio16 / 1 : UART1 RTS / 2 : SPI0 SSn
// { PAD_PIN22}, // 0 : gpio11 / 1 : UART1 CTS / 2 : SPI0 MOSI
// { PAD_PIN23}, // 0 : gpio14 / 1 : UART1 RXD / 2 : SPI0 MISO
// { PAD_PIN24}, // 0 : gpio15 / 1 : UART1 TXD / 2 : SPI0 SCLK
#define RTE_SPI0_SSN_BIT 21
#define RTE_SPI0_SSN_FUNC PAD_MUX_ALT2
#define RTE_SPI0_MOSI_BIT 22
#define RTE_SPI0_MOSI_FUNC PAD_MUX_ALT2
#define RTE_SPI0_MISO_BIT 23
#define RTE_SPI0_MISO_FUNC PAD_MUX_ALT2
#define RTE_SPI0_SCLK_BIT 24
#define RTE_SPI0_SCLK_FUNC PAD_MUX_ALT2
#define RTE_SPI0_SSN_GPIO_INSTANCE 1
#define RTE_SPI0_SSN_GPIO_INDEX 0
// 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 1
// { PAD_PIN13}, // 0 : gpio2 / 1 : UART0 RTSn / 3 : SPI1 SSn
// { PAD_PIN14}, // 0 : gpio3 / 1 : UART0 CTSn / 3 : SPI1 MOSI
// { PAD_PIN15}, // 0 : gpio4 / 1 : UART0 RXD / 3 : SPI1 MISO
// { PAD_PIN16}, // 0 : gpio5 / 1 : UART0 TXD / 3 : SPI1 SCLK
#define RTE_SPI1_SSN_BIT 13
#define RTE_SPI1_SSN_FUNC PAD_MUX_ALT3
#define RTE_SPI1_MOSI_BIT 14
#define RTE_SPI1_MOSI_FUNC PAD_MUX_ALT3
#define RTE_SPI1_MISO_BIT 15
#define RTE_SPI1_MISO_FUNC PAD_MUX_ALT3
#define RTE_SPI1_SCLK_BIT 16
#define RTE_SPI1_SCLK_FUNC PAD_MUX_ALT3
#define RTE_SPI1_SSN_GPIO_INSTANCE 0
#define RTE_SPI1_SSN_GPIO_INDEX 2
// 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 */

View File

@@ -0,0 +1,22 @@
#pragma once
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-11-23
Description: <20><><EFBFBD><EFBFBD>app <20>Խӿ<D4BD><D3BF><EFBFBD>
**************************************************************************/
//const char* pstrVersion = "0.1";
//const char* pstrUserId = "1";
const char* getFunctionData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage);
const char* getPropertyData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage);
const char* getInformationData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage);
const char* getEventData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage);

View File

@@ -0,0 +1,38 @@
/**
* \file base64.h
*
* \brief RFC 1521 base64 encoding/decoding
*/
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBEDTLS_BASE64_H
#define MBEDTLS_BASE64_H
#ifdef __cplusplus
extern "C" {
#endif
int32_t iBase64Encode(const uint8_t *pcInputData, int32_t iInputLength, uint8_t *pucOutputData);
int32_t iBase64Decode(const uint8_t *pcInputData, int32_t iInputLength, uint8_t *pucOutputData);
#ifdef __cplusplus
}
#endif
#endif /* base64.h */

View File

@@ -0,0 +1,52 @@
#pragma once
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-11-20
Description: <20><><EFBFBD><EFBFBD>csdk <20><>֤
**************************************************************************/
char* getComAuthUser();
char* getComAuthPassword();
char* getComAuthClientId();
char* getComAuthIp();
/*û<>з<EFBFBD><D0B7><EFBFBD>ֵ <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>0 ʧ<><CAA7> 1<>ɹ<EFBFBD>*/
typedef void(*pComAuthResultFunction)(unsigned char );
/*
*Summary:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>ʼ<EFBFBD><CABC>
*Parameters:
* pstrEncryptionMode <20><><EFBFBD><EFBFBD>ģʽ
* pstrProductId <20><>ƷID
* pstrDeviceId <20>豸ID
* pstrUserId <20>û<EFBFBD>ID
* pstrUse <20>û<EFBFBD>
* pstrPassword <20><><EFBFBD><EFBFBD>
* nTimeout <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> <20><>Ϊ<EFBFBD><CEAA>λ
* pstrIp ip
* pstrDeviceAuthorizationCode <20><EFBFBD><E8B1B8>֤code
* pstrProductPassword <20><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
* callback <20>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
*Return:
*/
void ComAuthInit(
const char* pstrEncryptionMode,
const int nProductId,
const char* pstrDeviceId,
const char* pstrUserId,
const char* pstrUser,
const char* pstrPassword,
unsigned int nTimeout,
const char* pstrIp,
const char* pstrDeviceAuthorizationCode,
const char* pstrProductPassword,
void* callback
);

View File

@@ -0,0 +1,84 @@
#pragma once
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-11-19
Description: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
**************************************************************************/
typedef void(*fnCallbackSendData)(const char* pstrTopic, const char* pstrMessage, unsigned char nQs);
typedef const char* (*fnCallbackGetMessage)(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage);
/*
*Summary:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
*Parameters:
* pstrProductId <20><>ƷID
* pstrDeviceNum <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD> IMEI
* callbackSendData <20><><EFBFBD>ݷ<EFBFBD><DDB7>ͺ<EFBFBD><CDBA><EFBFBD>
* callbackPropertyData <20><>Ʒ<EFBFBD><C6B7>ȡ
*Return:
*/
void comInteractionInit(
const int nProductId,
const char* pstrDeviceNum,
void* callbackSendData,
void* callbackPropertyData,
void* callbackFunctionData,
void* callbackEventData,
void* callbackDeviceInformationData);
/*
*Summary:<3A><>ʱ<EFBFBD><CAB1>ʼ<EFBFBD><CABC>
*Parameters:
*Return:
*/
void comInteractionDelayInit();
/*
*Summary:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD>
*Parameters:
* nTime <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1> <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
*Return:
*/
void setPropertyPush(unsigned int nTime);
/*
*Summary:<3A><><EFBFBD>ù<EFBFBD><C3B9>ܷ<EFBFBD><DCB7><EFBFBD>
*Parameters:
* nTime <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1> <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
*Return:
*/
void setFunctionPush(unsigned int nTime);
/*
*Summary:<3A><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
*Parameters:
* nTime <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1> <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
*Return:
*/
void setEventPush(unsigned int nTime);
/*
*Summary:<3A><>ȡҪ<C8A1><D2AA><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*Parameters:
*Return: <20><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ַ<EFBFBD><D6B7><EFBFBD> <20>ѷָ<D1B7><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD>
*/
const char* getSubscriberAll();
/*
*Summary:<3A><><EFBFBD>ݻص<DDBB><D8B5><EFBFBD><EFBFBD><EFBFBD>
*Parameters:
* pstrTopic <20><><EFBFBD><EFBFBD>
* pstrmessage <20><>Ϣ
*Return:
*/
void onRecvData(const char* pstrTopic, const char* pstrmessage);
void triggerPropertyPush();
void triggerFunctionPush();
void triggerEventPush();

View File

@@ -0,0 +1,15 @@
#pragma once
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD>
Date: 2022-11-19
Description: <20><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
**************************************************************************/
#include "common_api.h"
#include "luat_debug.h"
#include "luat_rtos.h"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-11-19
Description: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
**************************************************************************/
#include "luat_gpio.h"
#include "platform_define.h"
void optocouplerInit();
unsigned char getOptocoupler(unsigned char nIndex);

View File

@@ -0,0 +1,35 @@
#pragma once
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-11-19
Description: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD><CCB5><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
**************************************************************************/
#include "luat_gpio.h"
#include "platform_define.h"
/*
*Summary:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
*Parameters:
*Return:
*/
void relayInit();
/*
*Summary:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*Parameters:
* nRelayIndex:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>
* nValue <20><><EFBFBD><EFBFBD>ֵ
*Return: 0 ʧ<><CAA7> 1<>ɹ<EFBFBD>
*/
unsigned char relayControl(unsigned char nRelayIndex, unsigned char nValue);
unsigned char relayGetValue(unsigned char nRelayIndex);

View File

@@ -0,0 +1,18 @@
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-12-01
Description: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
**************************************************************************/
#include "luat_uart.h"
void uartInit();
void uartSend(unsigned char nUartId, unsigned char* pnData, unsigned int nLength);
unsigned char* getUartBuffer(unsigned char nUartId);
unsigned int getUartRxLength(unsigned char nUartId);

View File

@@ -0,0 +1,33 @@
#pragma once
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-11-23
Description: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Led
**************************************************************************/
#include "luat_gpio.h"
#include "platform_define.h"
/*
*Summary:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
*Parameters:
*Return:
*/
void ledInit();
/*
*Summary:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*Parameters:
* nledIndex:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>
* nValue <20><><EFBFBD><EFBFBD>ֵ
*Return: 0 ʧ<><CAA7> 1<>ɹ<EFBFBD>
*/
unsigned char ledControl(unsigned char nledIndex, unsigned char nValue);

View File

@@ -0,0 +1,16 @@
#pragma once
#include "header.h"
/**************************************************************************
Copyright: <20><><EFBFBD>˽<EFBFBD>
Author: <20><><EFBFBD>˽<EFBFBD> 1066950103@qq.com
Date: 2022-11-23
Description: mqtt <20><><EFBFBD><EFBFBD>
**************************************************************************/
void wuMeiMqttConnectPool(unsigned char nNetStatus);

View File

@@ -0,0 +1,333 @@
#include "app.h"
#include "cJSON.h"
#include "relay.h"
#include "optocoupler.h"
const char* getFunctionData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage)
{
/*
<09><>Ҫ֧<D2AA><D6A7> һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> һ<><D2BB><EFBFBD>̵<EFBFBD><CCB5><EFBFBD> һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[{
"id": "relay",
"value": "0",
"remark": ""
}, {
"id": "key",
"value": "0",
"remark": ""
}
{
"id": "uart",
"value": "0",
"remark": ""
}
]
*/
/*<2A>Ƚ<EFBFBD><C8BD><EFBFBD> ִ<>ж<EFBFBD><D0B6><EFBFBD>*/
if (pstrRecvMessage != NULL)
{
/*[{"id":"switch","value":"1"}]*/
LUAT_DEBUG_PRINT("pstrRecvMessage= %s", pstrRecvMessage);
cJSON* pjsonRoot = cJSON_Parse(pstrRecvMessage); //<2F><><EFBFBD><EFBFBD>
if (pjsonRoot == NULL)
{
LUAT_DEBUG_PRINT("cJSON_Parse Error");
return 0;
}
LUAT_DEBUG_PRINT("-----1----%d--", cJSON_GetArraySize(pjsonRoot));
cJSON* client_list = pjsonRoot->child;
while (client_list != NULL) {
char* id = cJSON_GetObjectItem(client_list, "id")->valuestring;
char* value = cJSON_GetObjectItem(client_list, "value")->valuestring;
LUAT_DEBUG_PRINT("ip: %s mask: %s", id, value);
if (strcmp(value, "0") == 0)
{
relayControl(0, 0);
}
else if (strcmp(value, "1") == 0)
{
relayControl(0, 1);
}
client_list = client_list->next;
}
cJSON_Delete(pjsonRoot); //ע<><D7A2><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>
}
char szTempBuffer[50] = { 0 };
cJSON* cjsonObj = cJSON_CreateArray(); //<2F><><EFBFBD><EFBFBD>
if (cjsonObj == NULL)
return NULL;
cJSON* cjsonObjSwitch = cJSON_CreateObject();
if (cjsonObjSwitch == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonObjSwitch, "id", "switch") == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjSwitch);
return NULL;
}
snprintf(szTempBuffer, sizeof(szTempBuffer), "%d", relayGetValue(0));
if (cJSON_AddStringToObject(cjsonObjSwitch, "value", szTempBuffer) == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjSwitch);
return NULL;
}
if (cJSON_AddItemToArray(cjsonObj, cjsonObjSwitch) == 0)
LUAT_DEBUG_PRINT("error ");
cJSON* cjsonObjTemperature = cJSON_CreateObject();
if (cjsonObjTemperature == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonObjTemperature, "id", "temperature") == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjTemperature);
return NULL;
}
float fTemp = 2000 / 100;
snprintf(szTempBuffer, sizeof(szTempBuffer), "%f", fTemp);// <20>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD>ֵ
if (cJSON_AddStringToObject(cjsonObjTemperature, "value", szTempBuffer) == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjTemperature);
return NULL;
}
if (cJSON_AddItemToArray(cjsonObj, cjsonObjTemperature) == 0)
LUAT_DEBUG_PRINT("error ");
/* <20><>ӡJSON<4F><4E><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
char* pstrOut = cJSON_PrintUnformatted(cjsonObj);
if (pstrOut == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
snprintf(pGetDataBuffer, nLength, "%s", pstrOut);
LUAT_DEBUG_PRINT("FunctionData= %s", pstrOut);
cJSON_Delete(cjsonObj);
cJSON_free(pstrOut);
return pGetDataBuffer;
}
const char* getPropertyData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage)
{
char szTempBuffer[100] = { 0 };
cJSON* cjsonObj = cJSON_CreateArray(); //<2F><><EFBFBD><EFBFBD>
if (cjsonObj == NULL)
return NULL;
cJSON* cjsonObjRelay = cJSON_CreateObject();
if (cjsonObjRelay == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonObjRelay, "id", "relay") == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjRelay);
return NULL;
}
snprintf(szTempBuffer, sizeof(szTempBuffer), "%d", relayGetValue(0));
if (cJSON_AddStringToObject(cjsonObjRelay, "value", szTempBuffer) == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjRelay);
return NULL;
}
if (cJSON_AddItemToArray(cjsonObj, cjsonObjRelay) == 0)
LUAT_DEBUG_PRINT("error ");
cJSON* cjsonObjKey = cJSON_CreateObject();
if (cjsonObjKey == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonObjKey, "id", "key") == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjKey);
return NULL;
}
snprintf(szTempBuffer, sizeof(szTempBuffer), "%d", getOptocoupler(0));
if (cJSON_AddStringToObject(cjsonObjKey, "value", szTempBuffer) == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjKey);
return NULL;
}
if (cJSON_AddItemToArray(cjsonObj, cjsonObjKey) == 0)
LUAT_DEBUG_PRINT("error ");
cJSON* cjsonObjUart = cJSON_CreateObject();
if (cjsonObjKey == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonObjUart, "id", "uart") == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjUart);
return NULL;
}
snprintf(szTempBuffer, sizeof(szTempBuffer), "%s", "1234567890aabcdefg");
if (cJSON_AddStringToObject(cjsonObjUart, "value", "0") == NULL)
{
cJSON_Delete(cjsonObj);
cJSON_Delete(cjsonObjUart);
return NULL;
}
if (cJSON_AddItemToArray(cjsonObj, cjsonObjUart) == 0)
LUAT_DEBUG_PRINT("error ");
/* <20><>ӡJSON<4F><4E><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
char* pstrOut = cJSON_PrintUnformatted(cjsonObj);
if (pstrOut == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
snprintf(pGetDataBuffer, nLength, "%s", pstrOut);
LUAT_DEBUG_PRINT("FunctionData= %s", pstrOut);
//cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
cJSON_free(pstrOut);
return pGetDataBuffer;
}
const char* getInformationData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage)
{
/*
local jsonData = {
rssi = net.getRssi(),
firmwareVersion = VERSION,
status = 3 ,
userId = m_strUserId ,
longitude = m_strLongitude ,
latitude = m_strLatitude,
summary = {
name= "device",
chip = "air724",
author = "duxingjie",
version=0.1,
create = "2022-08-07"
}
}
*/
cJSON* cjsonObj = cJSON_CreateObject();
if (cjsonObj == NULL)
return NULL;
if (cJSON_AddNumberToObject(cjsonObj, "rssi", -43) == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonObj, "firmwareVersion", "1.2") == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddNumberToObject(cjsonObj, "status", 3) == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonObj, "userId", "1") == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddNumberToObject(cjsonObj, "longitude",0) == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddNumberToObject(cjsonObj, "latitude", 0) == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
cJSON* cjsonSummary = cJSON_CreateObject();
if (cjsonSummary == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonSummary, "name", "wumei-smart") == NULL)
{
cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonSummary, "chip", "wumei-smart") == NULL)
{
cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddStringToObject(cjsonSummary, "author", "wumei-smart") == NULL)
{
cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
return NULL;
}
if (cJSON_AddNumberToObject(cjsonSummary, "version", 1.2) == NULL)
{
cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
return NULL;
}
if(cJSON_AddStringToObject(cjsonSummary, "createTime", "2022-12-09") == NULL)
{
cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
return NULL;
}
if(cJSON_AddItemToObject(cjsonObj, "summary", cjsonSummary) == NULL)
{
cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
return NULL;
}
/* <20><>ӡJSON<4F><4E><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
char* pstrOut = cJSON_PrintUnformatted(cjsonObj);
if (pstrOut == NULL)
{
cJSON_Delete(cjsonObj);
return NULL;
}
snprintf(pGetDataBuffer,nLength,"%s", pstrOut);
LUAT_DEBUG_PRINT("InformationData= %s", pstrOut);
//cJSON_Delete(cjsonSummary);
cJSON_Delete(cjsonObj);
cJSON_free(pstrOut);
return pGetDataBuffer;
}
const char* getEventData(char* pGetDataBuffer, int nLength, const char* pstrRecvMessage)
{
return NULL;
}

View File

@@ -0,0 +1,211 @@
/*
* RFC 1521 base64 encoding/decoding
*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdint.h>
#include "base64.h"
#include "stdio.h"
static const uint8_t base64_enc_map[64] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '+', '/'
};
static const uint8_t base64_dec_map[128] =
{
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 62, 127, 127, 127, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 127, 127,
127, 64, 127, 127, 127, 0, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 127, 127, 127, 127, 127, 127, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 127, 127, 127, 127, 127
};
/*
* Constant flow conditional assignment to unsigned char
*/
static void mbedtls_base64_cond_assign_uchar( uint8_t * dest, const uint8_t * const src, uint8_t condition )
{
/* Generate bitmask from condition, mask will either be 0xFF or 0 */
uint8_t mask = ( condition | -condition );
mask >>= 7;
mask = -mask;
*dest = ( ( *src ) & mask ) | ( ( *dest ) & ~mask );
}
/*
* Constant flow conditional assignment to uint_32
*/
static void mbedtls_base64_cond_assign_uint32( uint32_t * dest, const uint32_t src, uint32_t condition )
{
/* Generate bitmask from condition, mask will either be 0xFFFFFFFF or 0 */
uint32_t mask = ( condition | -condition );
mask >>= 31;
mask = -mask;
*dest = ( src & mask ) | ( ( *dest ) & ~mask );
}
/*
* Constant flow check for equality
*/
static uint8_t mbedtls_base64_eq( uint32_t in_a, uint32_t in_b )
{
uint32_t difference = in_a ^ in_b;
difference |= -difference;
/* cope with the varying size of int per platform */
difference >>= ( sizeof( difference ) * 8 - 1 );
return (uint8_t) ( 1 ^ difference );
}
/*
* Constant flow lookup into table.
*/
static uint8_t mbedtls_base64_table_lookup( const uint8_t * const table, const int32_t table_size, const int32_t table_index )
{
int32_t i = 0;
uint8_t result = 0;
for( i = 0; i < table_size; ++i )
{
mbedtls_base64_cond_assign_uchar( &result, &table[i], mbedtls_base64_eq( i, table_index ) );
}
return result;
}
/*
* Encode a buffer into base64 format
*/
int32_t iBase64Encode(const uint8_t *pcInputData, int32_t iInputLength, uint8_t *pucOutputData)
{
int32_t i = 0, n = 0, iOutputLength = 0, C1 = 0, C2 = 0, C3 = 0;
uint8_t *p = pucOutputData;
if((pucOutputData == NULL) || (pcInputData == NULL) || (iInputLength == 0))
{
return -1;
}
n = ( iInputLength / 3 ) * 3;
for( i = 0; i < n; i += 3 )
{
C1 = *pcInputData++;
C2 = *pcInputData++;
C3 = *pcInputData++;
*p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ), ( ( C1 >> 2 ) & 0x3F ) );
*p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ), ( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) ) & 0x3F ) );
*p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ), ( ( ( ( C2 & 15 ) << 2 ) + ( C3 >> 6 ) ) & 0x3F ) );
*p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ), ( C3 & 0x3F ) );
}
if( i < iInputLength )
{
C1 = *pcInputData++;
C2 = ( ( i + 1 ) < iInputLength ) ? *pcInputData++ : 0;
*p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ), ( ( C1 >> 2 ) & 0x3F ) );
*p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ), ( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) ) & 0x3F ) );
if( ( i + 1 ) < iInputLength )
*p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ), ( ( ( C2 & 15 ) << 2 ) & 0x3F ) );
else
*p++ = '=';
*p++ = '=';
}
iOutputLength = p - pucOutputData;
*p = 0;
return iOutputLength;
}
/*
* Decode a base64-formatted buffer
*/
int32_t iBase64Decode(const uint8_t *pcInputData, int32_t iInputLength, uint8_t *pucOutputData)
{
int32_t i = 0, n = 0, iOutputLength = 0;
uint32_t j = 0, x = 0;
uint8_t dec_map_lookup = 0, *p = pucOutputData;
if((pucOutputData == NULL) || (pcInputData == NULL) || (iInputLength == 0))
{
return -1;
}
for( i = j = 0; i < iInputLength; ++i )
{
if( pcInputData[i] == '=' && ++j > 2 )
return -2;
dec_map_lookup = mbedtls_base64_table_lookup( base64_dec_map, sizeof( base64_dec_map ), pcInputData[i] );
if( pcInputData[i] > 127 || dec_map_lookup == 127 )
return -3;
if( dec_map_lookup < 64 && j != 0 )
return -4;
}
for( j = 3; i > 0; --i)
{
dec_map_lookup = mbedtls_base64_table_lookup( base64_dec_map, sizeof( base64_dec_map ), *pcInputData++ );
mbedtls_base64_cond_assign_uint32( &j, j - 1, mbedtls_base64_eq( dec_map_lookup, 64 ) );
x = ( x << 6 ) | ( dec_map_lookup & 0x3F );
if( ++n == 4 )
{
n = 0;
if( j > 0 ) *p++ = (uint8_t)( x >> 16 );
if( j > 1 ) *p++ = (uint8_t)( x >> 8 );
if( j > 2 ) *p++ = (uint8_t)( x );
}
}
iOutputLength = p - pucOutputData;
return iOutputLength;
}

View File

@@ -0,0 +1,413 @@
#include "comAuth.h"
#include "HTTPClient.h"
#include "cJSON.h"
#include "osasys.h"
#include <time.h>
#include "luat_rtc.h"
#include "luat_crypto.h"
#include "base64.h"
static char* g_pstrEncryptionMode = NULL;
static int g_nProductId = 0;
static char* g_pstrDeviceId = NULL;
static char* g_pstrUserId = NULL;
static char* g_pstrUser = NULL;
static char* g_pstrPassword = NULL;
static unsigned int g_nTimeout = 0;
static char* g_pstrIp = NULL;
static char* g_pstrDeviceAuthorizationCode = NULL;
static char* g_pstrProductPassword = NULL;
static void* g_callback = NULL;
static time_t g_nLocalTime = 0;
/* http ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_RECV_BUF_SIZE (1501)
#define HTTP_HEAD_BUF_SIZE (800)
static HttpClientContext* g_pHttpClient = NULL;
char* getComAuthUser()
{
return g_pstrUser;
}
int wuMeiAes(char* pInData,int nInLength,char* pOutData, int nOutLength,const char* pKey)
{
const char* str = pInData;//"P47254TN6NNBB01L&2001841772&";
const char* key = pKey;//"KL0MKIA2HIAT2346";
uint8_t* temp = NULL;
int ret = 0;
int flags = MBEDTLS_ENCRYPT; //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ģʽ
unsigned char output[32] = { 0 };
size_t input_size = 0;
size_t output_size = 0;
size_t block_size = 0;
mbedtls_cipher_context_t ctx;
mbedtls_cipher_init(&ctx);
const mbedtls_cipher_info_t* _cipher = mbedtls_cipher_info_from_string("AES-128-CBC"); //<2F><><EFBFBD><EFBFBD>һЩ<D2BB><D0A9>Ϣ
if (_cipher == NULL) {
LUAT_DEBUG_PRINT("mbedtls_cipher_info fail %s not support", "AES-128-CBC");
goto _error_exit;
}
ret = mbedtls_cipher_setup(&ctx, _cipher); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (ret)
{
LUAT_DEBUG_PRINT("mbedtls_cipher_setup fail -0x%04x %s", -ret, "AES-128-CBC");
goto _error_exit;
}
ret = mbedtls_cipher_setkey(&ctx, (const unsigned char*)key, 128, MBEDTLS_ENCRYPT);
if (ret)
{
LUAT_DEBUG_PRINT("mbedtls_cipher_setkey fail -0x%04x %s", -ret, "AES-128-CBC");
goto _error_exit;
}
ret = mbedtls_cipher_set_iv(&ctx, (const unsigned char*)"wumei-smart-open", 16);
if (ret)
{
LUAT_DEBUG_PRINT("mbedtls_cipher_set_iv fail -0x%04x %s", -ret, "AES-128-CBC");
goto _error_exit;
}
mbedtls_cipher_reset(&ctx);
mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_PKCS7);
// <20><>ʼע<CABC><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
block_size = mbedtls_cipher_get_block_size(&ctx);
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
int cipher_mode = mbedtls_cipher_info_get_mode(_cipher);
#else
int cipher_mode = _cipher->mode;
#endif
size_t nIndex = 0;
for (size_t i = 0; i < nInLength; i += block_size)
{
input_size = nInLength - i;
if (input_size > block_size)
{
input_size = block_size;
ret = mbedtls_cipher_update(&ctx, (const unsigned char*)(str + i), input_size, output, &output_size);
LUAT_DEBUG_PRINT("input_size=%d i=%d 1", input_size,i);
}
else
{
ret = mbedtls_cipher_update(&ctx, (const unsigned char*)(str + i), input_size, output, &output_size);
LUAT_DEBUG_PRINT("input_size=%d i=%d 3 output_size=%d", input_size, i , output_size);
}
if (ret)
{
LUAT_DEBUG_PRINT("mbedtls_cipher_update fail 0x%04X %s", -ret, "AES-128-CBC");
goto _exit;
}
if (output_size > 0)
{
LUAT_DEBUG_PRINT("output_size= %d", output_size);
if ((output_size + nIndex) <= nOutLength)
{
memcpy(pOutData + nIndex, output, output_size);
nIndex = nIndex + output_size;
}
else
goto _error_exit;
}
output_size = 0;
}
output_size = 0;
ret = mbedtls_cipher_finish(&ctx, (unsigned char*)output, &output_size);
if (ret) {
LUAT_DEBUG_PRINT("mbedtls_cipher_finish fail 0x%04X %s", -ret, "AES-128-CBC");
goto _exit;
}
if ((output_size + nIndex) <= nOutLength)
{
memcpy(pOutData + nIndex, output, output_size);
nIndex = nIndex + output_size;
}
else
goto _error_exit;
_exit:
free(temp);
mbedtls_cipher_free(&ctx);
return nIndex;
_error_exit:
if(temp != NULL)
free(temp);
mbedtls_cipher_free(&ctx);
return 0;
}
static void PrintfHex(char* pData, char nLength)
{
static char tmpBuffer[1024] = { 0 };
tmpBuffer[0] = 0;
for (int i = 0; i < nLength; i++)
{
char tmp[4] = { 0 };
snprintf(tmp, 4," %02x", pData[i]);
strcat(tmpBuffer, tmp);
}
LUAT_DEBUG_PRINT("-------------HEX-------------------");
LUAT_DEBUG_PRINT("PrintfHex()= %s", tmpBuffer);
LUAT_DEBUG_PRINT("-------------HEX-------------------");
}
char* getComAuthPassword()
{
#define getComAuthPasswordINBufferMax 64
static char szAuthPassword[(getComAuthPasswordINBufferMax / 16) * 16] = { 0 }; //<2F>ܱ<EFBFBD><DCB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<31>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (strcmp(g_pstrEncryptionMode, "S") == 0)
{
if(strlen(g_pstrDeviceAuthorizationCode) == 0)
snprintf(szAuthPassword, sizeof(szAuthPassword), "%s", g_pstrPassword);
else
snprintf(szAuthPassword, sizeof(szAuthPassword), "%s&%s", g_pstrPassword, g_pstrDeviceAuthorizationCode);
LUAT_DEBUG_PRINT("getComAuthPassword()= %s", szAuthPassword);
return szAuthPassword;
}
else if (strcmp(g_pstrEncryptionMode, "E") == 0)
{
char* pstrAesSource = szAuthPassword;
char nAesDataLength = 0;
time_t nExpireTime = g_nLocalTime + g_nTimeout;
if(strlen(g_pstrDeviceAuthorizationCode) == 0)
snprintf(pstrAesSource, sizeof(szAuthPassword), "%s&%lld", g_pstrPassword, nExpireTime);
else
snprintf(pstrAesSource, sizeof(szAuthPassword), "%s&%lld&%s", g_pstrPassword, nExpireTime, g_pstrDeviceAuthorizationCode);
char nOutLength = 0;
char nIntLength = strlen(pstrAesSource);
LUAT_DEBUG_PRINT("Instr= %s ln=%d", pstrAesSource, nIntLength);
nIntLength = wuMeiAes(pstrAesSource, nIntLength, pstrAesSource,sizeof(szAuthPassword), g_pstrProductPassword);
static char szAesJson[getComAuthPasswordINBufferMax*5] = { 0 };
//if (luat_crypto_base64_encode(szAesJson, sizeof(szAesJson), &nOutLength, pstrAesSource, nIntLength) != 0)
// return "NULL";
nOutLength = iBase64Encode(pstrAesSource, nIntLength, szAesJson);
LUAT_DEBUG_PRINT("szAesJson= %s nOutLength=%d nIntLength=%d", szAesJson, nOutLength, nIntLength);
return szAesJson;
}
else
return "";
}
char* getComAuthClientId()
{
static char szClientId[100] = {0};
snprintf(szClientId, 99, "%s&%s&%d&%s", g_pstrEncryptionMode, g_pstrDeviceId, g_nProductId, g_pstrUserId);
LUAT_DEBUG_PRINT("getComAuthClientId()= %s" , szClientId);
return szClientId;
}
char* getComAuthIp()
{
LUAT_DEBUG_PRINT("getComAuthIp()= %s", g_pstrIp);
return g_pstrIp;
}
static unsigned int getJson(const char* pstrJson)
{
time_t nDeviceSendTime = 0;
time_t nServerSendTime = 0;
time_t nServerRecvTime = 0;
//cJSON_Minify(pstrJson); //ȥ<><C8A5>һЩ<D2BB><D0A9><EFBFBD><EFBFBD>
cJSON* pjsonRoot = cJSON_Parse(pstrJson); //<2F><><EFBFBD><EFBFBD>
if (pjsonRoot == NULL)
{
LUAT_DEBUG_PRINT("cJSON_Parse Error");
return 0;
}
cJSON* pjsonDeviceSendTime = cJSON_GetObjectItemCaseSensitive(pjsonRoot, "deviceSendTime"); //<2F><><EFBFBD><EFBFBD>key <20><>ȡһ<C8A1><D2BB>item
if (pjsonDeviceSendTime == NULL)
{
cJSON_Delete(pjsonRoot);
return 0;
}
LUAT_DEBUG_PRINT("get deviceSendTime ok");
if (cJSON_IsNumber(pjsonDeviceSendTime))
nDeviceSendTime = pjsonDeviceSendTime->valueint;
cJSON* pjsonServerSendTime = cJSON_GetObjectItemCaseSensitive(pjsonRoot, "serverSendTime");
if (pjsonServerSendTime == NULL)
{
cJSON_Delete(pjsonRoot);
return 0;
}
LUAT_DEBUG_PRINT("get serverSendTime ok");
//if (cJSON_IsNumber(pjsonServerSendTime))
// nServerSendTime = pjsonServerSendTime->valueint;
cJSON_GetLongLong(pjsonRoot, "serverSendTime",&nServerSendTime);
cJSON* pjsonServerRecvTime = cJSON_GetObjectItemCaseSensitive(pjsonRoot, "serverRecvTime");
if (pjsonServerRecvTime == NULL)
{
cJSON_Delete(pjsonRoot);
return 0;
}
LUAT_DEBUG_PRINT("get serverRecvTime ok");
//if (cJSON_IsNumber(pjsonServerRecvTime))
// nServerRecvTime = pjsonServerRecvTime->valueint; //cjson<6F><6E> <20><><EFBFBD><EFBFBD>64λint bug
cJSON_GetLongLong(pjsonRoot, "serverRecvTime", &nServerRecvTime);
cJSON_Delete(pjsonRoot);
//ToDo ע<><D7A2><EFBFBD>ڴ<EFBFBD><DAB4>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>
time_t nDeviceRunTickMs = OsaSystemTimeReadUtc()->UTCms;
time_t nSyncTime = (nServerRecvTime + nServerSendTime)/2 + (nDeviceRunTickMs - nDeviceSendTime) / 2;
g_nLocalTime = nSyncTime;
LUAT_DEBUG_PRINT("--1--nSyncTime=%lld ", nSyncTime);
struct tm* pTime = localtime(&nSyncTime);
LUAT_DEBUG_PRINT("---nServerRecvTime=%lld nServerSendTime=%lld nDeviceSendTime=%d nDeviceRunTickMs=%d", nServerRecvTime, nServerSendTime, nDeviceSendTime, nDeviceRunTickMs);
luat_rtc_set(pTime);
return 1;
}
/**
\fn INT32 httpGetData(CHAR *getUrl, CHAR *buf, UINT32 len)
\brief
\return
*/
static INT32 httpGetData(CHAR* getUrl, CHAR* buf, UINT32 len)
{
HTTPResult result = HTTP_INTERNAL;
HttpClientData clientData = { 0 };
UINT32 count = 0;
uint16_t headerLen = 0;
clientData.headerBuf = malloc(HTTP_HEAD_BUF_SIZE);
clientData.headerBufLen = HTTP_HEAD_BUF_SIZE;
clientData.respBuf = buf;
clientData.respBufLen = len;
result = httpSendRequest(g_pHttpClient, getUrl, HTTP_GET, &clientData);
LUAT_DEBUG_PRINT("-----httpSendRequest =%d\n\r", result);
if (result != HTTP_OK)
goto exit;
do
{
memset(clientData.headerBuf, 0, clientData.headerBufLen);
memset(clientData.respBuf, 0, clientData.respBufLen);
result = httpRecvResponse(g_pHttpClient, &clientData); //ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
if (result == HTTP_OK || result == HTTP_MOREDATA)
{
headerLen = strlen(clientData.headerBuf);
if (headerLen > 0)
{
LUAT_DEBUG_PRINT("total content length=%d", clientData.recvContentLength);
}
if (clientData.blockContentLen > 0)
{
LUAT_DEBUG_PRINT("response content:{%s}", (uint8_t*)clientData.respBuf);
}
count += clientData.blockContentLen;
LUAT_DEBUG_PRINT("has recv=%d", count);
}
} while (result == HTTP_MOREDATA || result == HTTP_CONN);
LUAT_DEBUG_PRINT("result=%d", result);
if (g_pHttpClient->httpResponseCode < 200 || g_pHttpClient->httpResponseCode > 404)
{
LUAT_DEBUG_PRINT("invalid http response code=%d", g_pHttpClient->httpResponseCode);
}
else if (count == 0 || count != clientData.recvContentLength)
{
LUAT_DEBUG_PRINT("data not receive complete");
}
else
{
LUAT_DEBUG_PRINT("receive success"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳɹ<DDB3>
/*
{
"deviceSendTime": 35768,
"serverSendTime": 1668995219357,
"serverRecvTime": 1668995219357
}
*/
result = HTTP_OK;
}
exit:
free(clientData.headerBuf);
return result;
}
static void httpGetOver(unsigned char nResult)
{
((pComAuthResultFunction)g_callback)(nResult);
}
static void comAuthHttpGet(const char* pstrUrl)
{
HTTPResult result = HTTP_INTERNAL;
g_pHttpClient = malloc(sizeof(HttpClientContext));
if (g_pHttpClient == NULL)
{
; //<2F><>ӡ<EFBFBD><EFBFBD><ECB3A3>־
}
memset(g_pHttpClient, 0, sizeof(HttpClientContext));
g_pHttpClient->timeout_s = 5; //<2F><><EFBFBD>ͳ<EFBFBD>ʱ
g_pHttpClient->timeout_r = 30; //<2F><><EFBFBD>ճ<EFBFBD>ʱ
result = httpConnect(g_pHttpClient, pstrUrl);
result = HTTP_OK;
LUAT_DEBUG_PRINT("httpConnect=%d", result);
if (result == HTTP_OK)
{
char* pRecvBuf = malloc(HTTP_RECV_BUF_SIZE);
if (pRecvBuf == NULL)
{
//<2F>ڴ治<DAB4><E6B2BB>
httpGetOver(0);
return;
}
result = httpGetData(pstrUrl, pRecvBuf, HTTP_RECV_BUF_SIZE);
if (result == HTTP_OK)
if(getJson(pRecvBuf) == 1)
httpGetOver(1);
else
httpGetOver(0);
else
httpGetOver(0); //<2F><>ʱ<EFBFBD><CAB1><EFBFBD>سɹ<D8B3>
free(pRecvBuf);
pRecvBuf = NULL;
httpClose(g_pHttpClient);
free(g_pHttpClient);
g_pHttpClient = NULL;
}
else
{
httpClose(g_pHttpClient);
free(g_pHttpClient);
g_pHttpClient = NULL;
httpGetOver(0); //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
}
}
void ComAuthInit(
const char* pstrEncryptionMode,
const int nProductId,
const char* pstrDeviceId,
const char* pstrUserId,
const char* pstrUser,
const char* pstrPassword,
unsigned int nTimeout,
const char* pstrIp,
const char* pstrDeviceAuthorizationCode,
const char* pstrProductPassword,
void* callback
)
{
g_pstrEncryptionMode = pstrEncryptionMode;
g_nProductId = nProductId;
g_pstrDeviceId = pstrDeviceId;
g_pstrUserId = pstrUserId;
g_pstrUser = pstrUser;
g_pstrPassword = pstrPassword;
g_nTimeout = nTimeout;
g_pstrIp = pstrIp;
g_pstrDeviceAuthorizationCode = pstrDeviceAuthorizationCode;
g_pstrProductPassword = pstrProductPassword;
g_callback = callback;
char szUrl[100] = {0};
snprintf(szUrl,99,"http://%s:8080/iot/tool/ntp?deviceSendTime=%d", pstrIp, OsaSystemTimeReadUtc()->UTCms);
//LUAT_DEBUG_PRINT("szUrl 1 =%s ", szUrl);
//LUAT_DEBUG_PRINT("g_pstrDeviceId= %s ", g_pstrDeviceId);
comAuthHttpGet(szUrl);
}

View File

@@ -0,0 +1,311 @@
#include "comInteraction.h"
#include "cJSON.h"
int g_nProductId = NULL;
char* g_pstrDeviceNum = NULL;
void* g_callbackSendData = NULL;
void* g_callbackPropertyData = NULL;
void* g_callbackFunctionData = NULL;
void* g_callbackEventData = NULL;
void* g_callbackDeviceInformationData = NULL;
static luat_rtos_timer_t g_propertyTimerHandle;
static luat_rtos_timer_t g_functionTimerHandle;
static luat_rtos_timer_t g_eventTimerHandle;
static luat_rtos_timer_t g_monitorTimerHandle;
static unsigned int g_monitorCount = 0;
static const char* getSubscriberDeviceInformation()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/info/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getSubscriberDeviceInOta()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/ota/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getSubscriberDeviceProperty()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/property/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getSubscriberDevicePropertyOnline()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/property-online/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getSubscriberDeviceFunction()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/function/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getSubscriberDeviceFunctionOnline()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/function-online/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getSubscriberDeviceMonitor()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/monitor/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getSubscriberDeviceNtp()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/ntp/get", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getPublishDeviceInformation()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/info/post", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getPublishDeviceProperty()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/property/post", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getPublishDeviceFunction()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/function/post", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getPublishDeviceEvent()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/event/post", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getPublishDeviceNtp()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/ntp/post", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static const char* getPublishMonitorProperty()
{
static char szResult[50] = { 0 };
snprintf(szResult, 49, "/%d/%s/monitor/post", g_nProductId, g_pstrDeviceNum);
//LUAT_DEBUG_PRINT("---str=%s", szResult);
return szResult;
}
static void propertyPush(const char* pstrRecvMessage)
{
char* pSendBuffer[300] = { 0 };
char* pstrTopic = getPublishDeviceProperty();
char* pstrMessage = ((fnCallbackGetMessage)g_callbackPropertyData)(pSendBuffer, sizeof(pSendBuffer), pstrRecvMessage);
((fnCallbackSendData)g_callbackSendData)(pstrTopic, pstrMessage, 1);
}
static void functionPush(const char* pstrRecvMessage)
{
char* pSendBuffer[300] = { 0 };
char* pstrTopic = getPublishDeviceFunction();
char* pstrMessage = ((fnCallbackGetMessage)g_callbackFunctionData)(pSendBuffer, sizeof(pSendBuffer), pstrRecvMessage);
//LUAT_DEBUG_PRINT("functionPush Topic=%s Message=%s", pstrTopic, pstrMessage);
((fnCallbackSendData)g_callbackSendData)(pstrTopic, pstrMessage, 1);
}
static void eventPush(const char* pstrRecvMessage)
{
char* pSendBuffer[300] = { 0 };
char* pstrTopic = getPublishDeviceEvent();
char* pstrMessage = ((fnCallbackGetMessage)g_callbackEventData)(pSendBuffer, sizeof(pSendBuffer), pstrRecvMessage);
((fnCallbackSendData)g_callbackSendData)(pstrTopic, pstrMessage, 1);
}
static void monitorPush(const char* pstrRecvMessage)
{
char* pSendBuffer[300] = { 0 };
char* pstrTopic = getPublishMonitorProperty();
char* pstrMessage = ((fnCallbackGetMessage)g_callbackPropertyData)(pSendBuffer, sizeof(pSendBuffer), pstrRecvMessage);
((fnCallbackSendData)g_callbackSendData)(pstrTopic, pstrMessage, 1);
}
static void deviceInformationPush(const char* pstrRecvMessage)
{
char* pSendBuffer[300] = { 0 };
char* pstrTopic = getPublishDeviceInformation();
char* pstrMessage = ((fnCallbackGetMessage)g_callbackDeviceInformationData)(pSendBuffer, sizeof(pSendBuffer), pstrRecvMessage);
((fnCallbackSendData)g_callbackSendData)(pstrTopic, pstrMessage, 1);
}
void comInteractionInit(
const int nProductId,
const char* pstrDeviceNum,
void* callbackSendData,
void* callbackPropertyData,
void* callbackFunctionData,
void* callbackEventData,
void* callbackDeviceInformationData)
{
g_callbackSendData = callbackSendData;
g_callbackPropertyData = callbackPropertyData;
g_callbackFunctionData = callbackFunctionData;
g_callbackEventData = callbackEventData;
g_callbackDeviceInformationData = callbackDeviceInformationData;
g_nProductId = nProductId;
g_pstrDeviceNum = pstrDeviceNum;
luat_rtos_timer_create(&g_propertyTimerHandle);
luat_rtos_timer_create(&g_functionTimerHandle);
luat_rtos_timer_create(&g_eventTimerHandle);
luat_rtos_timer_create(&g_monitorTimerHandle);
}
void comInteractionDelayInit()
{
deviceInformationPush(NULL);
}
static void onTimerPropertyPush(uint32_t arg)
{
propertyPush(NULL);
}
static void onTimerFunctionPush(uint32_t arg)
{
functionPush(NULL);
}
static void onTimerEventPush(uint32_t arg)
{
eventPush(NULL);
}
static void onTimerMonitorPush(uint32_t arg)
{
if (g_monitorCount != 0)
{
g_monitorCount--;
}
if (g_monitorCount == 0)
luat_rtos_timer_stop(g_monitorTimerHandle);
}
void setPropertyPush(unsigned int nTime)
{
if (luat_rtos_timer_is_active(g_propertyTimerHandle) != 0)
luat_rtos_timer_stop(g_propertyTimerHandle);
luat_rtos_timer_start(g_propertyTimerHandle, nTime, 1, onTimerPropertyPush, NULL);
}
void setFunctionPush(unsigned int nTime)
{
if (luat_rtos_timer_is_active(g_functionTimerHandle) != 0)
luat_rtos_timer_stop(g_functionTimerHandle);
luat_rtos_timer_start(g_functionTimerHandle, nTime, 1, onTimerFunctionPush, NULL);
}
void setEventPush(unsigned int nTime)
{
if (luat_rtos_timer_is_active(g_eventTimerHandle) != 0)
luat_rtos_timer_stop(g_eventTimerHandle);
luat_rtos_timer_start(g_eventTimerHandle, nTime, 1, onTimerEventPush, NULL);
}
static void setMonitorPush(unsigned int nTime, unsigned int nNumber)
{
if (luat_rtos_timer_is_active(g_monitorTimerHandle) != 0)
luat_rtos_timer_stop(g_monitorTimerHandle);
luat_rtos_timer_start(g_monitorTimerHandle, nTime, 1, onTimerMonitorPush, NULL);
g_monitorCount = nNumber;
}
const char* getSubscriberAll()
{
//<2F><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD>
static char szSubscriberBuffer[1024] = { 0 };
snprintf(szSubscriberBuffer, sizeof(szSubscriberBuffer) - 1, "%s|%s|%s|%s|%s|%s|%s",
getSubscriberDeviceInformation(), //1
getSubscriberDeviceProperty(), //2
getSubscriberDevicePropertyOnline(), //3
getSubscriberDeviceFunction(), //4
getSubscriberDeviceFunctionOnline(), //5
getSubscriberDeviceMonitor(), //6
getSubscriberDeviceNtp() //7
);
return szSubscriberBuffer;
}
void onRecvData(const char* pstrTopic, const char* pstrMessage)
{
LUAT_DEBUG_PRINT("--onRecvData Topic=%s Message=%s", pstrTopic, pstrMessage);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>json
if (strcmp(pstrTopic, getSubscriberDeviceInformation()) == 0)
deviceInformationPush(pstrMessage);
else if (strcmp(pstrTopic, getSubscriberDeviceProperty()) == 0)
propertyPush(pstrMessage);
else if (strcmp(pstrTopic, getSubscriberDevicePropertyOnline()) == 0)
{
propertyPush(pstrMessage);
//<2F><><EFBFBD>߻<EFBFBD>ȡ
}
else if (strcmp(pstrTopic, getSubscriberDeviceFunction()) == 0)
functionPush(pstrMessage);
else if (strcmp(pstrTopic, getSubscriberDeviceFunctionOnline()) == 0)
{
functionPush(pstrMessage);
}
else if (strcmp(pstrTopic, getSubscriberDeviceMonitor()) == 0)
{
// <20><>ȡ<EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
}
else if (strcmp(pstrTopic, getSubscriberDeviceNtp()) == 0)
{
//ntp ͬ<><CDAC>
}
}
void triggerPropertyPush()
{
propertyPush(NULL);
}
void triggerFunctionPush()
{
functionPush(NULL);
}
void triggerEventPush()
{
eventPush(NULL);
}

View File

@@ -0,0 +1,204 @@
/*
* 物美开发板
*/
#include "common_api.h"
#include "luat_rtos.h"
#include "luat_mobile.h"
#include "luat_mem.h"
#include "luat_debug.h"
#include "wuMeiMqtt.h"
#include "optocoupler.h"
#include "relay.h"
#include "wuMeiLed.h"
static volatile uint8_t g_isLinkUp = 0; // 注意变量多线程竞争 锁
static luat_rtos_semaphore_t net_semaphore_handle;
static void sms_event_cb(uint32_t event, void* param)
{
LUAT_DEBUG_PRINT("短信event%d,%x", event, param);
}
void mobile_event_cb(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t status)
{
if (event == LUAT_MOBILE_EVENT_NETIF)
{
LUAT_DEBUG_PRINT("internet工作状态变更为 %d", status);
switch (status)
{
case LUAT_MOBILE_NETIF_LINK_ON:
LUAT_DEBUG_PRINT("可以上网");
g_isLinkUp = 1;
//luat_rtos_semaphore_release(net_semaphore_handle);
break;
default:
LUAT_DEBUG_PRINT("不能上网");
g_isLinkUp = 0; //不能上网
break;
}
}
}
static void printfImeiMuid()
{
char imei[20] = { 0 };
luat_mobile_get_imei(0, imei, sizeof(imei));
LUAT_DEBUG_PRINT("IMEI %s", imei);
char muid[64] = { 0 };
luat_mobile_get_muid(muid, sizeof(muid));
LUAT_DEBUG_PRINT("MUID %s", muid);
}
static void relayTest()
{
for (int i = 0; i < 9; i++)
{
relayControl(i, 0);
}
for (int i = 0; i < 9; i++)
{
relayControl(i, 1);
luat_rtos_task_sleep(1000);
}
for (int i = 0; i < 9; i++)
{
relayControl(i, 0);
luat_rtos_task_sleep(1000);
}
}
static void OptocouplerPool()
{
static char nPinStatus[8] = { 0 };
for (unsigned char i = 0; i < 8; i++)
{
if (nPinStatus[i] != getOptocoupler(i))
{
nPinStatus[i] = getOptocoupler(i);
LUAT_DEBUG_PRINT("getOptocoupler(%d)=%d", i, nPinStatus[i]);
//triggerPropertyPush();
}
}
}
static void wumei_task(void* param)
{
luat_debug_set_fault_mode(LUAT_DEBUG_FAULT_RESET);
//luat_rtos_semaphore_create(&net_semaphore_handle, 1);
optocouplerInit(); // 光耦初始化
relayInit(); // 继电器初始化
ledInit();
luat_mobile_set_sim_id(0);
printfImeiMuid();
luat_mobile_event_register_handler(mobile_event_cb);
luat_mobile_set_period_work(90000, 10000, 8);
printfImeiMuid();
//relayTest();
//luat_rtos_semaphore_take(net_semaphore_handle, LUAT_WAIT_FOREVER);
extern void DuAesTest();
for (;;)
{
while (g_isLinkUp == 0)
{
/*
没有联网需要计数
超过一定值 开飞行
关飞行 协议栈复位
等有效机制
*/
LUAT_DEBUG_PRINT("当前状态不能上网1");
ledControl(0, 0);
luat_rtos_task_sleep(100);
ledControl(0, 1);
luat_rtos_task_sleep(100);
LUAT_DEBUG_PRINT("当前状态不能上网2");
}
//LUAT_DEBUG_PRINT("B g_isLinkUp=%d", g_isLinkUp);
wuMeiMqttConnectPool(g_isLinkUp);
OptocouplerPool();
ledControl(0, 1);
luat_rtos_task_sleep(20); //根据情况调整这个值 避免太耗用CPU
ledControl(0, 0);
luat_rtos_task_sleep(20); //根据情况调整这个值 避免太耗用CPU
}
}
static void wumei_task_init(void)
{
luat_rtos_task_handle task_handle;
luat_rtos_task_create(&task_handle, 20 * 1024, 80, "wumei", wumei_task, NULL, 0);
}
#include "luat_i2c.h"
#define I2C_ID 0
#define AHT10_ADDRESS_ADR_LOW 0x38
#define AHT10_INIT 0xE1 //初始化命令
#define AHT10_MEASURE 0xAC //触发测量命令
#define AHT10_SOFT_RESET 0xBA
#define AHT10_STATE 0x71 //状态字.
static void hw_test_demo(void)
{
LUAT_DEBUG_PRINT("hw_test_demo entry");
optocouplerInit(); // 光耦初始化
relayInit(); // 继电器初始化
ledInit();
uartInit();
/*char soft_reset[] = { AHT10_SOFT_RESET };
char init_cmd[] = { AHT10_INIT,0x08,0x00 };
char measure_cmd[] = { AHT10_MEASURE, 0x33, 0x00 };
char read_cmd[] = { AHT10_STATE };
char recv_date[7] = { 0 };
luat_i2c_setup(I2C_ID, 1);
luat_rtos_task_sleep(40);
luat_i2c_send(I2C_ID, AHT10_ADDRESS_ADR_LOW, soft_reset, 1, 1);
luat_rtos_task_sleep(20);
luat_i2c_recv(I2C_ID, AHT10_ADDRESS_ADR_LOW, recv_date, 1);
if (recv_date[0] & (1 << 3) == 0)
{
luat_i2c_send(I2C_ID, AHT10_ADDRESS_ADR_LOW, init_cmd, 3, 1);
}*/
LUAT_DEBUG_PRINT("hw Init End");
while (1)
{
ledControl(0, 0);
for (int i = 0; i < 9; i++)
{
relayControl(i, 1);
}
luat_rtos_task_sleep(1000);
//luat_i2c_send(I2C_ID, AHT10_ADDRESS_ADR_LOW, measure_cmd, 3, 1);
ledControl(0, 1);
for (int i = 0; i < 9; i++)
{
relayControl(i, 0);
}
luat_rtos_task_sleep(1000);
/*luat_i2c_send(I2C_ID, AHT10_ADDRESS_ADR_LOW, read_cmd, 1, 1);
luat_i2c_recv(I2C_ID, AHT10_ADDRESS_ADR_LOW, recv_date, 6);
float cur_temp = ((recv_date[3] & 0xf) << 16 | recv_date[4] << 8 | recv_date[5]) * 200.0 / (1 << 20) - 50;
LUAT_DEBUG_PRINT("temp: %f", cur_temp);*/
OptocouplerPool();
uartSend(1,"Uart1",sizeof("Uart1"));
uartSend(2, "Uart2", sizeof("Uart2"));
}
}
static void hw_test_task_init(void)
{
luat_rtos_task_handle flymode_task_handle;
luat_rtos_task_create(&flymode_task_handle, 2048, 20, "hwtest", hw_test_demo, NULL, NULL);
}
INIT_TASK_EXPORT(wumei_task_init, "1");
// 创建硬件测试线程
//INIT_TASK_EXPORT(hw_test_task_init, "1");

View File

@@ -0,0 +1,60 @@
#include "optocoupler.h"
/*
U U U D D D
In0 In1 In2 In3 In4 In5 In6 In7
I28 I4 I5 I30 I31 I23 I25 I12(X)
78 80 81 31 32 99 106 97
*/
#define PIN_0 HAL_GPIO_19
#define PIN_1 HAL_GPIO_29
#define PIN_2 HAL_GPIO_5
#define PIN_3 HAL_GPIO_4
#define PIN_4 HAL_GPIO_28
#define PIN_5 HAL_GPIO_30
#define PIN_6 HAL_GPIO_31
#define PIN_7 HAL_GPIO_23
static inline unsigned char getPin(unsigned char nRelayIndex)
{
unsigned char nResult = PIN_0;
switch (nRelayIndex)
{
case 0: nResult = PIN_0; break;
case 1: nResult = PIN_1; break;
case 2: nResult = PIN_2; break;
case 3: nResult = PIN_3; break;
case 4: nResult = PIN_4; break;
case 5: nResult = PIN_5; break;
case 6: nResult = PIN_6; break;
case 7: nResult = PIN_7; break;
default:
break;
}
return nResult;
}
void optocouplerInit()
{
luat_gpio_cfg_t gpioCfg; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9>
luat_gpio_set_default_cfg(&gpioCfg); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><E1B9B9>
gpioCfg.pull = LUAT_GPIO_PULLUP; //<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
gpioCfg.mode = LUAT_GPIO_INPUT;
for (unsigned char i = 1; i < 8; i++)
{
gpioCfg.pin = getPin(i);
luat_gpio_open(&gpioCfg); //<2F><><EFBFBD><EFBFBD>
luat_gpio_set(gpioCfg.pin, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
}
gpioCfg.pin = getPin(0);
gpioCfg.alt_fun = 4;// <20><><EFBFBD><EFBFBD>4 <20><><EFBFBD><EFBFBD>GPIO19
luat_gpio_open(&gpioCfg); //<2F><><EFBFBD><EFBFBD>
luat_gpio_set(gpioCfg.pin, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
}
unsigned char getOptocoupler(unsigned char nIndex)
{
return luat_gpio_get(getPin(nIndex));
}

View File

@@ -0,0 +1,83 @@
#include "relay.h"
#include "luat_debug.h"
/*
J0 J1 J2 J3 J4 J5 J6 J7
O17 O16 O2 O24 O12 O13 O7 O6 O3
23 22 21 20 58 57 56 55 54
*/
#define RELAY0_PIN HAL_GPIO_17
#define RELAY1_PIN HAL_GPIO_16
#define RELAY2_PIN HAL_GPIO_2
#define RELAY3_PIN HAL_GPIO_24
#define RELAY4_PIN HAL_GPIO_12
#define RELAY5_PIN HAL_GPIO_13
#define RELAY6_PIN HAL_GPIO_7
#define RELAY7_PIN HAL_GPIO_6
#define RELAY8_PIN HAL_GPIO_3
static unsigned char nRelayValue[8] = {0};
static inline unsigned char getPin(unsigned char nRelayIndex)
{
unsigned char nResult = RELAY0_PIN;
switch (nRelayIndex)
{
case 0: nResult = RELAY0_PIN; break;
case 1: nResult = RELAY1_PIN; break;
case 2: nResult = RELAY2_PIN; break;
case 3: nResult = RELAY3_PIN; break;
case 4: nResult = RELAY4_PIN; break;
case 5: nResult = RELAY5_PIN; break;
case 6: nResult = RELAY6_PIN; break;
case 7: nResult = RELAY7_PIN; break;
case 8: nResult = RELAY8_PIN; break;
default:
break;
}
return nResult;
}
/*
*Summary:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
*Parameters:
*Return:
*/
void relayInit()
{
luat_gpio_cfg_t gpioCfg; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9>
luat_gpio_set_default_cfg(&gpioCfg); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><E1B9B9>
gpioCfg.pull = LUAT_GPIO_PULLDOWN; //<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
gpioCfg.mode = LUAT_GPIO_OUTPUT;
gpioCfg.output_level = LUAT_GPIO_LOW;
for (unsigned char i = 0; i < 9; i++)
{
gpioCfg.pin = getPin(i);
luat_gpio_open(&gpioCfg); //<2F><><EFBFBD><EFBFBD>
luat_gpio_set(gpioCfg.pin, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
}
}
/*
*Summary:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*Parameters:
* nRelayIndex:<3A>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>
* nValue <20><><EFBFBD><EFBFBD>ֵ
*Return: 0 ʧ<><CAA7> 1<>ɹ<EFBFBD>
*/
unsigned char relayControl(unsigned char nRelayIndex, unsigned char nValue)
{
if(nValue == 0)
luat_gpio_set(getPin(nRelayIndex), 0);
else
luat_gpio_set(getPin(nRelayIndex), 1);
nRelayValue[nRelayIndex] = nValue;
return 1; //Ĭ<>϶<EFBFBD><CFB6>ɹ<EFBFBD>
}
unsigned char relayGetValue(unsigned char nRelayIndex)
{
return nRelayValue[nRelayIndex];
}

View File

@@ -0,0 +1,127 @@
#include "uart.h"
#include "luat_gpio.h"
#include "platform_define.h"
#define RS485_PIN1 HAL_GPIO_22 //<2F><><EFBFBD><EFBFBD>1
#define RS485_PIN2 HAL_GPIO_25 //<2F><><EFBFBD><EFBFBD>2
static unsigned char uart1RxBuffer[1024];
static unsigned char uart2RxBuffer[1024];
static unsigned int uart1RxLength = 0;
static unsigned int uart2RxLength = 0;
static void uartRecvCb(int uart_id, uint32_t data_len)
{
if (uart_id == 1)
{
luat_uart_read(uart_id, uart1RxBuffer, data_len);
uart1RxLength = data_len;
LUAT_DEBUG_PRINT("luat_uart_cb uart_id:%d data:%s data_len:%d", uart_id, uart1RxBuffer, data_len);
}
if (uart_id == 2)
{
luat_uart_read(uart_id, uart2RxBuffer, data_len);
uart2RxLength = data_len;
LUAT_DEBUG_PRINT("luat_uart_cb uart_id:%d data:%s data_len:%d", uart_id, uart2RxBuffer, data_len);
}
}
static void uart1Init()
{
luat_gpio_cfg_t gpioCfg; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9>
luat_gpio_set_default_cfg(&gpioCfg); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><E1B9B9>
gpioCfg.pull = LUAT_GPIO_PULLDOWN; //<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
gpioCfg.mode = LUAT_GPIO_OUTPUT;
gpioCfg.output_level = LUAT_GPIO_LOW;
gpioCfg.pin = RS485_PIN1;
luat_gpio_open(&gpioCfg); //<2F><><EFBFBD><EFBFBD>
luat_gpio_set(RS485_PIN1, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
luat_uart_t uart = {
.id = 1,
.baud_rate = 9600,
.data_bits = 8,
.stop_bits = 1,
.parity = 0 ,
// .pin485 = RS485_PIN1,
.delay = 50,
.rx_level = 0
};
luat_uart_setup(&uart);
luat_uart_ctrl(1, LUAT_UART_SET_RECV_CALLBACK, uartRecvCb);
}
static void uart2Init()
{
luat_gpio_cfg_t gpioCfg; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9>
luat_gpio_set_default_cfg(&gpioCfg); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><E1B9B9>
gpioCfg.pull = LUAT_GPIO_PULLDOWN; //<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
gpioCfg.mode = LUAT_GPIO_OUTPUT;
gpioCfg.output_level = LUAT_GPIO_LOW;
gpioCfg.pin = RS485_PIN2;
luat_gpio_open(&gpioCfg); //<2F><><EFBFBD><EFBFBD>
luat_gpio_set(RS485_PIN2, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
luat_uart_t uart = {
.id = 2,
.baud_rate = 9600,
.data_bits = 8,
.stop_bits = 1,
.parity = 0 ,
//.pin485 = RS485_PIN2,
.delay = 50,
.rx_level = 0
};
luat_uart_setup(&uart);
luat_uart_ctrl(2, LUAT_UART_SET_RECV_CALLBACK, uartRecvCb);
}
void uartInit()
{
uart1Init();
uart2Init();
}
void uartSend(unsigned char nUartId, unsigned char* pnData, unsigned int nLength)
{
if (nUartId == 1)
{
luat_gpio_set(RS485_PIN1, 1);
luat_rtos_task_sleep(200);
luat_uart_write(1, pnData, nLength);
luat_rtos_task_sleep(200);
luat_gpio_set(RS485_PIN1, 0);
}
else if (nUartId == 2)
{
luat_gpio_set(RS485_PIN2, 1);
luat_rtos_task_sleep(200);
luat_uart_write(2, pnData, nLength);
luat_rtos_task_sleep(200);
luat_gpio_set(RS485_PIN2, 0);
}
}
unsigned char* getUartBuffer(unsigned char nUartId)
{
if(nUartId == 1)
return uart1RxBuffer;
else
return uart2RxBuffer;
}
unsigned int getUartRxLength(unsigned char nUartId)
{
if (nUartId == 1)
return uart1RxLength;
else
return uart2RxLength;
}

View File

@@ -0,0 +1,25 @@
#include "wuMeiLed.h"
#define LED0_PIN HAL_GPIO_26
void ledInit()
{
luat_gpio_cfg_t gpioCfg; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9>
luat_gpio_set_default_cfg(&gpioCfg); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><E1B9B9>
gpioCfg.pull = LUAT_GPIO_PULLDOWN; //<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
gpioCfg.mode = LUAT_GPIO_OUTPUT;
gpioCfg.output_level = LUAT_GPIO_LOW;
gpioCfg.pin = LED0_PIN;
luat_gpio_open(&gpioCfg); //<2F><><EFBFBD><EFBFBD>
luat_gpio_set(gpioCfg.pin, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
}
unsigned char ledControl(unsigned char nledIndex, unsigned char nValue)
{
if (nValue == 0)
luat_gpio_set(LED0_PIN, 0);
else
luat_gpio_set(LED0_PIN, 1);
return 1; //Ĭ<>϶<EFBFBD><CFB6>ɹ<EFBFBD>
}

View File

@@ -0,0 +1,214 @@
#include "luat_mobile.h"
#include "wuMeiMqtt.h"
#include "MQTTClient.h"
#include "luat_debug.h"
#include "comAuth.h"
#include "comInteraction.h"
#include "app.h"
static const char* g_pstrIp = "43.143.82.218"; //mqtt IP
static const int g_nPort = 1883; //Mqtt <20>˿<EFBFBD>
static const char* g_pstrEncryptionMode = "E"; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> S <20>򵥼<EFBFBD><F2B5A5BC><EFBFBD>
static const int g_nProductId = 45; //<2F><>ƷID
static const char* g_pstrUserId = "1"; //<2F>û<EFBFBD>ID
static const char* g_pstrMqttUser = "wumei-smart"; //mqtt <20>û<EFBFBD>
static const char* g_pstrMqttPassword = "P47254TN6NNBB01L"; // mqtt <20><><EFBFBD><EFBFBD>
static const char* g_pstrProductPassword = "KL0MKIA2HIAT2346"; //<2F><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
static const unsigned int g_nMqttAuthenticationTimeout = 24 * 60 * 60 * 1000; // 24Сʱ
static const char* g_pstrDeviceAuthorizationCode = "";// "A25040D2E34B483DA371B5F9A315BB43"; //<2F><EFBFBD><E8B1B8>Ȩ<EFBFBD><C8A8>
static char* g_szDeviceId[16] = { 0 }; //<2F>豸ID IMEI
#define MQTT_SEND_BUFF_LEN (2048)
#define MQTT_RECV_BUFF_LEN (2048)
static MQTTClient g_mqttClient = { 0 };
static Network g_network = { 0 };
unsigned char g_mqttSendbuf[MQTT_SEND_BUFF_LEN] = { 0 };
unsigned char g_mqttReadbuf[MQTT_RECV_BUFF_LEN] = { 0 };
static unsigned char g_nStatus = 0;
static MQTTPacket_connectData g_connectData = MQTTPacket_connectData_initializer;
unsigned char g_mqttReadMessageData[1024] = { 0 };
unsigned char g_mqttReadMessageTopic[200] = { 0 };
static char g_nRecvFlag = 0;
luat_rtos_mutex_t g_mutexMqttRecv;
static void callAuthResultFunction(unsigned char nStatus)
{
LUAT_DEBUG_PRINT("callAuthResultFunction nStatus=%d", nStatus);
if (nStatus == 1)
{
g_nStatus = 2;
LUAT_DEBUG_PRINT("callAuthResultFunction g_nStatus=%d", g_nStatus);
}
else if (nStatus == 0)
{
g_nStatus = 0;
}
}
static void mqttInit(const char* pstrClientId, const char* pstrUserName, const char* pstrPassword, unsigned short nkeepAliveInterval)
{
LUAT_DEBUG_PRINT("mqttInit pstrClientId=%s", pstrClientId);
g_connectData.MQTTVersion = 4;
g_connectData.clientID.cstring = pstrClientId;
g_connectData.username.cstring = pstrUserName;
g_connectData.password.cstring = pstrPassword;
g_connectData.keepAliveInterval = nkeepAliveInterval;//120;
LUAT_DEBUG_PRINT("mqttInit pstrClientId=%s pstrUserName=%s pstrPassword=%s", pstrClientId, pstrUserName, pstrPassword);
}
static void messageArrived(MessageData* data)
{
LUAT_DEBUG_PRINT("mqtt Recv topic %.*s: %.*s", data->topicName->lenstring.len, data->topicName->lenstring.data,
data->message->payloadlen, data->message->payload);
LUAT_DEBUG_PRINT("topic=%d Data=%d", data->topicName->lenstring.len, data->message->payloadlen);
luat_rtos_mutex_lock(g_mutexMqttRecv, 1000);
memcpy(g_mqttReadMessageData, data->message->payload, data->message->payloadlen);
int nTopicLeng = data->topicName->lenstring.len;
if (nTopicLeng > (sizeof(g_mqttReadMessageTopic) - 1))
nTopicLeng = (sizeof(g_mqttReadMessageTopic) - 1);
snprintf(g_mqttReadMessageTopic, nTopicLeng + 1, "%s", data->topicName->lenstring.data);
g_nRecvFlag = 1;
luat_rtos_mutex_unlock(g_mutexMqttRecv);
}
void mqttSendData(const char* pstrTopic, const char* pstrMessage, unsigned char nQs)
{
int nResult = 0;
if (g_nStatus != 3)
{
LUAT_DEBUG_PRINT("mqttSendData error status!=3");
return;
}
LUAT_DEBUG_PRINT("--mqttSendData 2 ");
if (MQTTIsConnected(&g_mqttClient) == 0)
{
g_nStatus = 2;// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LUAT_DEBUG_PRINT("--g_nStatus 2 ");
return;
}
LUAT_DEBUG_PRINT("--mqttSendData 3 ");
//if (MQTTIsConnected(&g_mqttClient) == 0)
// return; //<2F><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>Ӿͷ<D3BE><CDB7><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD>
MQTTMessage message;
LUAT_DEBUG_PRINT("--mqttSendData 4 ");
message.qos = nQs;
message.retained = 0;
message.payload = pstrMessage;
message.payloadlen = strlen(pstrMessage) + 1;
LUAT_DEBUG_PRINT("--mqttSendData 5 l=%d ", message.payloadlen);
if (nResult = MQTTPublish(&g_mqttClient, pstrTopic, &message) != 0)
LUAT_DEBUG_PRINT("MQTTPublish %d\n", nResult);
// <20>ͷ<EFBFBD><CDB7><EFBFBD>
LUAT_DEBUG_PRINT("--mqttSendData Topic=%s Message=%s", pstrTopic, pstrMessage);
}
static void recvDataPool()
{
luat_rtos_mutex_lock(g_mutexMqttRecv, 1000);
if (g_nRecvFlag == 1)
{
LUAT_DEBUG_PRINT("recvDataPool %s %s", g_mqttReadMessageTopic, g_mqttReadMessageData);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
onRecvData(g_mqttReadMessageTopic, g_mqttReadMessageData);
g_nRecvFlag = 0;
}
luat_rtos_mutex_unlock(g_mutexMqttRecv);
}
void wuMeiMqttConnectPool(unsigned char nNetStatus)
{
int nResult = 0;
if (nNetStatus == 1)
{
if (g_nStatus == 0)
{
luat_rtos_mutex_create(&g_mutexMqttRecv);
g_nStatus = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>ڵȴ<DAB5><C8B4><EFBFBD>֤״̬
luat_mobile_get_imei(0, g_szDeviceId, sizeof(g_szDeviceId));
ComAuthInit(
g_pstrEncryptionMode,
g_nProductId,
g_szDeviceId,
g_pstrUserId,
g_pstrMqttUser,
g_pstrMqttPassword,
g_nMqttAuthenticationTimeout,
g_pstrIp,
g_pstrDeviceAuthorizationCode,
g_pstrProductPassword,
callAuthResultFunction
);
comInteractionInit(g_nProductId, g_szDeviceId, mqttSendData, getPropertyData, getFunctionData, getEventData, getInformationData);
}
else if (g_nStatus == 2)
{
mqttInit(getComAuthClientId(), getComAuthUser(), getComAuthPassword(), 120);
//û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
NetworkInit(&g_network);
MQTTClientInit(&g_mqttClient, &g_network, 40000, g_mqttSendbuf, MQTT_SEND_BUFF_LEN, g_mqttReadbuf, MQTT_RECV_BUFF_LEN);
LUAT_DEBUG_PRINT("---start NetworkConnect--");
if ((NetworkConnect(&g_network, g_pstrIp, g_nPort)) != 0)
{
LUAT_DEBUG_PRINT("NetworkConnect fail");
g_mqttClient.keepAliveInterval = g_connectData.keepAliveInterval;
g_mqttClient.ping_outstanding = 1;
goto error;
}
else {
if ((MQTTConnect(&g_mqttClient, &g_connectData)) != 0)
{
g_mqttClient.ping_outstanding = 1;
goto error;
}
else
{
LUAT_DEBUG_PRINT("MQTTStartTask");
#if defined(MQTT_TASK)
if ((MQTTStartTask(&g_mqttClient)) != pdPASS) {
goto error;
}
#endif
}
}
g_nStatus = 3; //<2F><><EFBFBD>ӳɹ<D3B3>
LUAT_DEBUG_PRINT("--start MQTTSubscribe---");
//<2F><><EFBFBD><EFBFBD>
char* pstrSubscriberAll = getSubscriberAll();
for (char* pstr = strtok(pstrSubscriberAll, "|"); pstr != NULL; pstr = strtok(NULL, "|"))
{
if ((nResult = MQTTSubscribe(&g_mqttClient, pstr, 0, messageArrived)) != 0)
{
LUAT_DEBUG_PRINT("---MQTTSubscribe error -%d--", nResult);
break;
}
}
LUAT_DEBUG_PRINT("--end MQTTSubscribe---");
comInteractionDelayInit();
return;
}
else if (g_nStatus == 3)
{
#if !defined(MQTT_TASK)
//if ((nResult = MQTTYield(&g_mqttClient, 2)) != 0)
// LUAT_DEBUG_PRINT("mqtt_demo Return code from yield is %d\n", rc);
#endif
// <20><><EFBFBD>ӳɹ<D3B3><C9B9><EFBFBD> <20>Ϳ<EFBFBD><CDBF><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>
recvDataPool();
return;
}
error:
LUAT_DEBUG_PRINT("--g_nStatus= %d", g_nStatus);
//<2F>ⲿ˯<E2B2BF><CBAF> luat_rtos_task_sleep(200); // ˯<><CBAF>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD>Ƶ<EFBFBD><C6B5>
}
else
{
LUAT_DEBUG_PRINT("--nNetStatus= %d", nNetStatus);
}
}

View File

@@ -0,0 +1,45 @@
local TARGET_NAME = "wu_mei"
local LIB_DIR = "$(buildir)/".. TARGET_NAME .. "/"
local LIB_NAME = "lib" .. TARGET_NAME .. ".a "
target(TARGET_NAME)
set_kind("static")
set_targetdir(LIB_DIR)
add_defines("MQTT_TASK",{public = true})
--add_defines("MAX_MESSAGE_HANDLERS" , 10)
includes(SDK_TOP .. "/thirdparty/mqtt")
add_deps("mqtt")
-- --加入代码和头文件
add_includedirs(SDK_TOP .. "/thirdparty/mqtt/MQTTClient-C/src",{public = true})
add_files(SDK_TOP .. "/thirdparty/mqtt/MQTTClient-C/src/*.c",{public = true})
-- --加入cjson
add_includedirs(SDK_TOP .. "/thirdparty/cJSON")
add_files(SDK_TOP .. "/thirdparty/cJSON/**.c")
--使用第三方的httpclient
includes(SDK_TOP .. "/thirdparty/httpclient")
add_deps("httpclient")
-- --加入加密
add_includedirs(SDK_TOP .. "/thirdparty/mbedtls",{public = true})
add_defines("MBEDTLS_CIPHER_PADDING_PKCS7",{public = true})
add_defines("MBEDTLS_CIPHER_MODE_CBC",{public = true})
--add_defines("MBEDTLS_CONFIG_FILE=\"mbedtls_ec618_config.h\"")
--加入代码和头文件
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})
--可以继续增加add_includedirs和add_files
--自动链接
LIB_USER = LIB_USER .. SDK_TOP .. LIB_DIR .. LIB_NAME .. " "
--甚至可以加入自己的库
target_end()