|
各位帮忙看下是什么问题,先谢谢了
移植代码修改后如下gizwits_product.c
/**
****************************************
* @file gizwits_product.c
* @brief Gizwits control protocol processing, and platform-related hardware initialization
* @author Gizwits
* @date 2017-07-19
* @version V03030000
* @copyright Gizwits
*
* @note Gizwits is only for smart hardware
* Gizwits Smart Cloud for Smart Products
* Links | Value Added | Open | Neutral | Safety | Own | Free | Ecology
* www.gizwits.com
*
****************************************/
#include <stdio.h>
#include <string.h>
#include "gizwits_product.h"
#include "usart3.h"
#include "timer.h"
#include "led.h"
#include "STM32f10x.h"
#include "usart.h"
static uint32_t timerMsCount;
/** Current datapoint */
extern dataPoint_t currentDataPoint;
/**@} */
/**@name Gizwits User Interface
* @{
*/
/**
* @brief Event handling interface
* Description:
* 1. Users can customize the changes in WiFi module status
* 2. Users can add data points in the function of event processing logic, such as calling the relevant hardware peripherals operating interface
* @param [in] info: event queue
* @param [in] data: protocol data
* @param [in] len: protocol data length
* @return NULL
* @ref gizwits_protocol.h
*/
int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *gizdata, uint32_t len)
{
uint8_t i = 0;
dataPoint_t *dataPointPtr = (dataPoint_t *)gizdata;
moduleStatusInfo_t *wifiData = (moduleStatusInfo_t *)gizdata;
protocolTime_t *ptime = (protocolTime_t *)gizdata;
#if MODULE_TYPE
gprsInfo_t *gprsInfoData = (gprsInfo_t *)gizdata;
#else
moduleInfo_t *ptModuleInfo = (moduleInfo_t *)gizdata;
#endif
if((NULL == info) || (NULL == gizdata))
{
return -1;
}
for(i=0; i<info->num; i++)
{
switch(info->event)
{
case EVENT_LED:
currentDataPoint.valueLED = dataPointPtr->valueLED;
GIZWITS_LOG("Evt: EVENT_LED %d \n", currentDataPoint.valueLED);
if(0x01 == currentDataPoint.valueLED)
{
//user handle
LED0=1;
}
else
{
//user handle
LED0=0;
}
break;
case WIFI_SOFTAP:
break;
case WIFI_AIRLINK:
break;
case WIFI_STATION:
break;
case WIFI_CON_ROUTER:
break;
case WIFI_DISCON_ROUTER:
break;
case WIFI_CON_M2M:
break;
case WIFI_DISCON_M2M:
break;
case WIFI_RSSI:
GIZWITS_LOG("RSSI %d\n", wifiData->rssi);
break;
case TRANSPARENT_DATA:
GIZWITS_LOG("TRANSPARENT_DATA \n");
//user handle , Fetch data from [data] , size is [len]
break;
case WIFI_NTP:
GIZWITS_LOG("WIFI_NTP : [%d-%d-%d %02d:%02d:%02d][%d] \n",ptime->year,ptime->month,ptime->day,ptime->hour,ptime->minute,ptime->second,ptime->ntp);
break;
case MODULE_INFO:
GIZWITS_LOG("MODULE INFO ...\n");
#if MODULE_TYPE
GIZWITS_LOG("GPRS MODULE ...\n");
//Format By gprsInfo_t
#else
GIZWITS_LOG("WIF MODULE ...\n");
//Format By moduleInfo_t
GIZWITS_LOG("moduleType : [%d] \n",ptModuleInfo->moduleType);
#endif
break;
default:
break;
}
}
return 0;
}
/**
* Data point initialization function
* In the function to complete the initial user-related data
* @param none
* @return none
* @note The developer can add a data point state initialization value within this function
*/
void userInit(void)
{
LED_Init();
uart_init(115200);
memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));
/** Warning !!! DataPoint Variables Init , Must Within The Data Range **/
}
/**
* @brief gizTimerMs
* millisecond timer maintenance function ,Millisecond increment , Overflow to zero
* @param none
* @return none
*/
void gizTimerMs(void)
{
timerMsCount++;
}
/**
* @brief gizGetTimerCount
* Read system time, millisecond timer
* @param none
* @return System time millisecond
*/
uint32_t gizGetTimerCount(void)
{
return timerMsCount;
}
/**
* @brief mcuRestart
* MCU Reset function
* @param none
* @return none
*/
void mcuRestart(void)
{
__set_FAULTMASK(1);//关闭所有中断
NVIC_SystemReset();//复位
}
/**@} */
/**
* @brief TIMER_IRQ_FUN
* Timer Interrupt handler function
* @param none
* @return none
*/
void TIMER_IRQ_FUN(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //¼ÏÔ´
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //
gizTimerMs();
}
}
/**
* @brief UART_IRQ_FUN
* UART Serial interrupt function ,For Module communication
* Used to receive serial port protocol data between WiFi module
* @param none
* @return none
*/
void UART_IRQ_FUN(void)
{
u8 res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)//
{
res =USART_ReceiveData(USART3);
gizPutData(&res, 1);//
}
}
/**
* @brief uartWrite
* Serial write operation, send data to the WiFi module
* @param buf : Data address
* @param len : Data length
*
* @return : Not 0,Serial send success;
* -1,Input Param Illegal
*/
int32_t uartWrite(uint8_t *buf, uint32_t len)
{
uint32_t i = 0;
if(NULL == buf)
{
return -1;
}
#ifdef PROTOCOL_DEBUG
GIZWITS_LOG("MCU2WiFi[%4d:%4d]: ", gizGetTimerCount(), len);
for(i=0; i<len; i++)
{
GIZWITS_LOG("%02x ", buf);
}
GIZWITS_LOG("\n");
#endif
for(i=0; i<len; i++)
{
//USART_SendData(UART, buf);//STM32 test demo
//Serial port to achieve the function, the buf sent to the module
USART_SendData(USART3,buf);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET); //循环发送,直到发送完毕
if(i >=2 && buf == 0xFF)
{
//Serial port to achieve the function, the 0x55 sent to the module
//USART_SendData(UART, 0x55);//STM32 test demo
USART_SendData(USART3,0x55);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET); //循环发送,直到发送完毕
}
}
return len;
}
主函数main.c代码如下
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "timer.h"
#include "gizwits_product.h"
#include "usart3.h"
#include "usart.h"
dataPoint_t currentDataPoint;
//ÐÒé³õʼ»¯
void Gizwits_Init(void)
{
TIM3_Int_Init(9,7199);//1MSϵͳ¶¨Ê±
usart3_init(115200);//WIFI³õʼ»¯
memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));//É豸״̬½á¹¹Ìå³õʼ»¯
gizwitsInit();//»º³åÇø³õʼ»¯
}
//Êý¾Ý²É¼¯
void userHandle(void)
{
//Åжϵ±Ç°LED1¿ª¹ØÁ¿
if(LED1==0)
currentDataPoint.valueLED = 1;
else
currentDataPoint.valueLED = 0;
}
int main(void)
{
delay_init(); //ÑÓʱº¯Êý³õʼ»¯
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// ÉèÖÃÖжÏÓÅÏȼ¶·Ö×é2
LED_Init(); //³õʼ»¯ÓëLEDÁ¬½ÓµÄÓ²¼þ½Ó¿Ú
uart_init(115200);
Gizwits_Init();
while(1)
{
userHandle();
gizwitsHandle((dataPoint_t *)¤tDataPoint);//ÐÒé´¦Àí
gizwitsSetMode(WIFI_AIRLINK_MODE);
LED1=!LED1;
delay_ms(1000);
}
}
|
|