收藏官网首页
查看: 3194|回复: 1

[求助] 机智云通用平台代码移植,手机无法连接到设备

1

主题

2

帖子

31

积分

新手上路

Rank: 1

积分
31
跳转到指定楼层
楼主
发表于 2019-7-8 10:35:23 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
校园创客福利
各位帮忙看下是什么问题,先谢谢了

移植代码修改后如下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*)&currentDataPoint, 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*)&currentDataPoint, 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 *)&currentDataPoint);//ЭÒé´¦Àí
    gizwitsSetMode(WIFI_AIRLINK_MODE);

                LED1=!LED1;
                delay_ms(1000);                  
        }
}


usart1提示time out.PNG (94.44 KB, 下载次数: 38)

usart1提示time out.PNG
沙发
发表于 2019-7-10 19:49:28 | 只看该作者
不合法的数据太多了
gizwitsSetMode(WIFI_AIRLINK_MODE);
delay_ms(1000);       这种代码放在while是绝对禁止的
发烧友
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

加入Q群 返回顶部

版权与免责声明 © 2006-2024 Gizwits IoT Technology Co., Ltd. ( 粤ICP备11090211号 )

快速回复 返回顶部 返回列表