锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

【Io开发笔记】机智云智能浇花器实战(3)-自动生成代码移植

时间:2022-09-18 19:30:00 b1安全继电器f1w继电器4fb0继电器2af05继电器

第一部分:总体设计/系统功能介绍/智能云自助开发平台-利器开发GAgent等等
点击下载:【Io机智云智能浇花器实战(1)-基础Demo实现

第二篇内容:
继电器实现/功能测试/DHT11驱动代码实现/OLED屏幕显示传感器数据/中文字模制作等
点击下载:智能智能浇花器实战(2)-基础Demo实现


一,BH1750光照传感器原理图



二,BH1750传感器代码

  1. #include "bh1750.h"
  2. #include "delay.h"
  3. uint8_t BUF[8]; //接收数据缓存区
  4. int mcy; ///进位标志
  5. /**开始信号**/
  6. void BH1750_Start()
  7. {
  8. BH1750_SDA_H; ///提高数据线
  9. BH1750_SCL_H; //提高时钟线
  10. Delay_nus(5); //延时
  11. GPIO_ResetBits(BH1750_PORT, BH1750_SDA_PIN); //产生下降边
  12. Delay_nus(5); //延时
  13. GPIO_ResetBits(BH1750_PORT, BH1750_SCL_PIN); //拉低时钟线
  14. }
  15. /***停止信号***/
  16. void BH1750_Stop()
  17. {
  18. BH1750_SDA_L; ///拉低数据线
  19. BH1750_SCL_H; //提高时钟线
  20. Delay_nus(5); //延时
  21. GPIO_SetBits(BH1750_PORT, BH1750_SDA_PIN); //产生上升沿
  22. Delay_nus(5); //延时
  23. }
  24. /******************
  25. 发送响应信号
  26. 入口参数:ack (0:ACK 1:NAK)
  27. ******************/
  28. void BH1750_SendACK(int ack)
  29. {
  30. GPIO_InitTypeDef GPIO_InitStruct;
  31. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_P;  
  32.   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  33.   GPIO_InitStruct.GPIO_Pin = BH1750_SDA_PIN;
  34.   GPIO_Init(BH1750_PORT, &GPIO_InitStruct);  
  35.         
  36.         if(ack == 1)   //写应答信号
  37.                 BH1750_SDA_H;
  38.         else if(ack == 0)
  39.                 BH1750_SDA_L;
  40.         else
  41.                 return;                        
  42.   BH1750_SCL_H;     //拉高时钟线
  43.   Delay_nus(5);                 //延时
  44.   BH1750_SCL_L;      //拉低时钟线
  45.   Delay_nus(5);                //延时
  46. }
  47. /******************
  48. 接收应答信号
  49. ******************/
  50. int BH1750_RecvACK()
  51. {
  52.   GPIO_InitTypeDef GPIO_InitStruct;
  53.         
  54.   GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU;  /*这里一定要设成输入上拉,否则不能读出数据*/
  55.   GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
  56.   GPIO_InitStruct.GPIO_Pin=BH1750_SDA_PIN;
  57.   GPIO_Init(BH1750_PORT,&GPIO_InitStruct);
  58.         
  59.   BH1750_SCL_H;            //拉高时钟线
  60.   Delay_nus(5);                 //延时        
  61.         if(GPIO_ReadInputDataBit(BH1750_PORT,BH1750_SDA_PIN)==1)//读应答信号
  62.     mcy = 1 ;  
  63.   else
  64.     mcy = 0 ;                                
  65.   BH1750_SCL_L;                    //拉低时钟线
  66.   Delay_nus(5);                 //延时
  67.   GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
  68.   GPIO_Init(BH1750_PORT,&GPIO_InitStruct);
  69.         return mcy;
  70. }
  71. /******************
  72. 向IIC总线发送一个字节数据
  73. ******************/
  74. void BH1750_SendByte(uint8_t dat)
  75. {
  76.   uint8_t i;
  77.   for (i=0; i<8; i++)         //8位计数器
  78.   {
  79.                 if( 0X80 & dat )
  80.       GPIO_SetBits(BH1750_PORT,BH1750_SDA_PIN);
  81.     else
  82.       GPIO_ResetBits(BH1750_PORT,BH1750_SDA_PIN);
  83.                 dat <<= 1;
  84.     BH1750_SCL_H;               //拉高时钟线
  85.     Delay_nus(5);             //延时
  86.     BH1750_SCL_L;                //拉低时钟线
  87.     Delay_nus(5);            //延时
  88.   }
  89.   BH1750_RecvACK();
  90. }
  91. uint8_t BH1750_RecvByte()
  92. {
  93.   uint8_t i;
  94.   uint8_t dat = 0;
  95.   uint8_t bit;
  96.         
  97.   GPIO_InitTypeDef GPIO_InitStruct;
  98.         
  99.   GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_IPU;   /*这里一定要设成输入上拉,否则不能读出数据*/
  100.   GPIO_InitStruct.GPIO_Pin   = BH1750_SDA_PIN;
  101.   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  102.   GPIO_Init(BH1750_PORT,&GPIO_InitStruct );
  103.         
  104.   GPIO_SetBits(BH1750_PORT,BH1750_SDA_PIN);          //使能内部上拉,准备读取数据,
  105.   for (i=0; i<8; i++)         //8位计数器
  106.   {
  107.     dat <<= 1;
  108.     BH1750_SCL_H;               //拉高时钟线
  109.     Delay_nus(5);             //延时
  110.                         
  111.                 if( SET == GPIO_ReadInputDataBit(BH1750_PORT,BH1750_SDA_PIN))
  112.       bit = 0X01;
  113.     else
  114.       bit = 0x00;  
  115.                 dat |= bit;             //读数据   
  116.                 BH1750_SCL_L;                //拉低时钟线
  117.     Delay_nus(5);            //延时
  118.   }               
  119.         GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
  120.   GPIO_Init(BH1750_PORT, &GPIO_InitStruct );
  121.   return dat;
  122. }
  123. void Single_Write_BH1750(uint8_t REG_Address)
  124. {
  125.   BH1750_Start();                  //起始信号
  126.   BH1750_SendByte(SlaveAddress);   //发送设备地址+写信号
  127.   BH1750_SendByte(REG_Address);    //内部寄存器地址,请参考中文pdf22页
  128. //  BH1750_SendByte(REG_data);       //内部寄存器数据,请参考中文pdf22页
  129.   BH1750_Stop();                   //发送停止信号
  130. }
  131. //初始化BH1750,根据需要请参考pdf进行修改**
  132. void BH1750_Init()
  133. {
  134.   GPIO_InitTypeDef GPIO_InitStruct;
  135.          /*开启GPIOB的外设时钟*/
  136.   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
  137.   GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;  
  138.   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  139.   GPIO_InitStruct.GPIO_Pin = BH1750_SDA_PIN | BH1750_SCL_PIN ;
  140.   GPIO_Init(BH1750_PORT,&GPIO_InitStruct);
  141.         
  142.   Single_Write_BH1750(0x01);  
  143.   Delay_nms(180);            //延时180ms
  144. }
  145. //连续读出BH1750内部数据
  146. void mread(void)
  147. {   
  148.   uint8_t i;        
  149.   BH1750_Start();                          //起始信号
  150.   BH1750_SendByte(SlaveAddress+1);         //发送设备地址+读信号
  151.         
  152.         for (i=0; i<3; i++)                      //连续读取6个地址数据,存储中BUF
  153.   {
  154.     BUF[i] = BH1750_RecvByte();          //BUF[0]存储0x32地址中的数据
  155.     if (i == 3)
  156.     {
  157.       BH1750_SendACK(1);                //最后一个数据需要回NOACK
  158.     }
  159.     else
  160.     {               
  161.       BH1750_SendACK(0);                //回应ACK
  162.     }
  163.   }
  164.   BH1750_Stop();                          //停止信号
  165.   Delay_nms(5);
  166. }
  167. float Read_BH1750(void)
  168. {
  169.   int dis_data;                       //变量        
  170.         float temp1;
  171.         float temp2;
  172.         Single_Write_BH1750(0x01);   // power on
  173.         Single_Write_BH1750(0x10);   // H- resolution mode
  174.         Delay_nms(180);              //延时180ms
  175.         mread();                     //连续读出数据,存储在BUF中
  176.         dis_data=BUF[0];
  177.         dis_data=(dis_data<<8)+BUF[1]; //合成数据
  178.         temp1=dis_data/1.2;
  179.         temp2=10*dis_data/1.2;        
  180.         temp2=(int)temp2%10;
  181.         return temp1;
  182. }
复制代码

  1. #ifndef __BH1750_H__
  2. #define __BH1750_H__
  3. #include "STM32f10x.h"
  4. /*
  5.         定义器件在IIC总线中的从地址,根据ALT  ADDRESS地址引脚不同修改
  6.         ALT  ADDRESS引脚接地时地址为0x46,   接电源时地址为0xB8
  7. */
  8. #define        SlaveAddress     0x46                     
  9. #define BH1750_PORT      GPIOB
  10. #define BH1750_SCL_PIN   GPIO_Pin_1
  11. #define BH1750_SDA_PIN   GPIO_Pin_0
  12. #define BH1750_SCL_H     GPIO_SetBits(BH1750_PORT,BH1750_SCL_PIN)
  13. #define BH1750_SCL_L     GPIO_ResetBits(BH1750_PORT,BH1750_SCL_PIN)
  14. #define BH1750_SDA_H     GPIO_SetBits(BH1750_PORT,BH1750_SDA_PIN)
  15. #define BH1750_SDA_L     GPIO_ResetBits(BH1750_PORT,BH1750_SDA_PIN)  
  16.                                              
  17.                                                                                                                         
  18. extern uint8_t    BUF[8];                         //接收数据缓存区              
  19. extern int        dis_data;                       //变量               
  20. extern int        mcy;                            //表示进位标志位
  21. void BH1750_Init(void);
  22. void conversion(uint32_t temp_data);
  23. void  Single_Write_BH1750(uint8_t REG_Address);    //单个写入数据
  24. uint8_t Single_Read_BH1750(uint8_t REG_Address);   //单个读取内部寄存器数据
  25. void  mread(void);                                 //连续的读取内部寄存器数据
  26. float Read_BH1750(void);
  27. #endif
复制代码


BH1750传感器代码说明


核心板单独测试程序在PB0PB1管脚是完全正常,不知道是不是核心板的PB2上接了什么暂时还未排查出来问题,如果你是用
开发板或者是自己设计的项目板的话,那么程序是直接可以使用的程序依然按照PB0PB1保留。


三,机智云自助开发平台数据点创建
机智云官方网站:https://www.gizwits.com/
步骤1,创建产品



创建好后就会有基本信息




步骤2,填写机智云产品ProductKey


这两个信息比较重要最好是保存下来

  1. Product Key :9c8a5a8e38344fb4af14b6db0f5b1df7
  2. Product Secret :45c86d8c6a2a4b1dac7d68df54f6e4f0
复制代码



步骤3,定义自己的数据点


只读:就是只允许赋值数据传感器赋值给平台平台只能读取
可写:就是数据可以被修改继电器的开关状态平台可以修改

四,MCU开发


mcu开发注意事项平台选Common其实就是STM32F103x平台



1,生成代码包


2,下载自动生成的代码包

3,机智云Gizwits协议移植




这两个文件夹要添加到自己的工程

这是添加的文件夹以及文件的目录

4,修改gizwits_product.c
 

  1. #include
  2. #include
  3. #include "gizwits_product.h"
  4. #include "usart3.h"
  5. static uint32_t timerMsCount;
  6. uint8_t aRxBuffer;
  7. dataPoint_t currentDataPoint;
  8. uint8_t wifi_flag;
  9. //存放事件处理API接口函数
  10. int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *gizdata, uint32_t len)
  11. {
  12.   uint8_t i = 0;
  13.   dataPoint_t *dataPointPtr = (dataPoint_t *)gizdata;
  14.   moduleStatusInfo_t *wifiData = (moduleStatusInfo_t *)gizdata;
  15.   protocolTime_t *ptime = (protocolTime_t *)gizdata;
  16.   
  17. #if MODULE_TYPE
  18.   gprsInfo_t *gprsInfoData = (gprsInfo_t *)gizdata;
  19. #else
  20.   moduleInfo_t *ptModuleInfo = (moduleInfo_t *)gizdata;
  21. #endif
  22.   if((NULL == info) || (NULL == gizdata))
  23.   {
  24.     return -1;
  25.   }
  26.   for(i=0; inum; i++)
  27.   {
  28.     switch(info->event[i])
  29.     {
  30.       case EVENT_Relay_1:
  31.         currentDataPoint.valueRelay_1 = dataPointPtr->valueRelay_1;
  32.         GIZWITS_LOG("Evt: EVENT_Relay_1 %d \n", currentDataPoint.valueRelay_1);
  33.         if(0x01 == currentDataPoint.valueRelay_1)
  34.         {
  35.             currentDataPoint.valueRelay_1 = 1;
  36.         }
  37.         else
  38.         {
  39.             currentDataPoint.valueRelay_1 = 0;
  40.         }
  41.         break;
  42.       case WIFI_SOFTAP:
  43.         break;
  44.       case WIFI_AIRLINK:
  45.         break;
  46.       case WIFI_STATION:
  47.         break;
  48.       case WIFI_CON_ROUTER:
  49.         break;
  50.       case WIFI_DISCON_ROUTER:
  51.         break;
  52.       case WIFI_CON_M2M:
  53.                wifi_flag = 1; //WiFi连接标志
  54.         break;
  55.       case WIFI_DISCON_M2M:
  56.                wifi_flag = 0; //WiFi断开标志
  57.         break;
  58.       case WIFI_RSSI:
  59.         GIZWITS_LOG("RSSI %d\n", wifiData->rssi);
  60.         break;
  61.       case TRANSPARENT_DATA:
  62.         GIZWITS_LOG("TRANSPARENT_DATA \n");
  63.         //user handle , Fetch data from [data] , size is [len]
  64.         break;
  65.       case WIFI_NTP:
  66.         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);
  67.         break;
  68.       case MODULE_INFO:
  69.             GIZWITS_LOG("MODULE INFO ...\n");
  70.       #if MODULE_TYPE
  71.             GIZWITS_LOG("GPRS MODULE ...\n");
  72.             //Format By gprsInfo_t
  73.       #else
  74.             GIZWITS_LOG("WIF MODULE ...\n");
  75.             //Format By moduleInfo_t
  76.             GIZWITS_LOG("moduleType : [%d] \n",ptModuleInfo->moduleType);
  77.       #endif
  78.     break;
  79.       default:
  80.         break;
  81.     }
  82.   }
  83.   return 0;
  84. }
  85. void userHandle(void)
  86. {
  87. /*
  88.     currentDataPoint.valueTemp = ;//Add Sensor Data Collection
  89.     currentDataPoint.valueHumi = ;//Add Sensor Data Collection
  90.     currentDataPoint.valueLight_Intensity = ;//Add Sensor Data Collection
  91. */
  92. }
  93. void userInit(void)
  94. {
  95.     memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));
  96.                 currentDataPoint.valueRelay_1         = 0;
  97.                 currentDataPoint.valueTemp            = 0;
  98.                 currentDataPoint.valueHumi            = 0;
  99.                 currentDataPoint.valueLight_Intensity = 0;
  100. }
  101. void gizTimerMs(void)
  102. {
  103.     timerMsCount++;
  104. }
  105. uint32_t gizGetTimerCount(void)
  106. {
  107.     return timerMsCount;
  108. }
  109. void mcuRestart(void)
  110. {
  111.         __set_FAULTMASK(1);
  112.         NVIC_SystemReset();
  113. }
  114. void TIMER_IRQ_FUN(void)
  115. {
  116.   gizTimerMs();
  117. }
  118. void UART_IRQ_FUN(void)
  119. {
  120.   uint8_t value = 0;
  121.   gizPutData(&value, 1);
  122. }
  123. int32_t uartWrite(uint8_t *buf, uint32_t len)
  124. {
  125.     uint32_t i = 0;
  126.         
  127.     if(NULL == buf)
  128.     {
  129.         return -1;
  130.     }
  131.    
  132.     for(i=0; i
  133.     {
  134.         USART_SendData(USART3,buf[i]);
  135.         while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET); //循环发送,直到发送完毕
  136.         if(i >=2 && buf[i] == 0xFF)
  137.         {
  138.             USART_SendData(USART3, 0x55);
  139.             while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET); //循环发送,直到发送完毕
  140.         }
  141.     }
  142.     return len;
  143. }
复制代码

5,修改

  1. #ifndef _GIZWITS_PRODUCT_H
  2. #define _GIZWITS_PRODUCT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include
  7. //#include "stm32f1xx.h"
  8. #include "gizwits_protocol.h"
  9. /**
  10. * MCU software version
  11. */
  12. #define SOFTWARE_VERSION "03030000"
  13. /**
  14. * MCU hardware version
  15. */
  16. #define HARDWARE_VERSION "03010100"
  17. /**
  18. * Communication module model
  19. */
  20. #define MODULE_TYPE 0 //0,WIFI ;1,GPRS
  21. /**@name TIM3 related macro definition
  22. * @{
  23. */
  24. #define TIMER                                             TIM3
  25. #define TIMER_IRQ                                   TIM3_IRQn
  26. #define TIMER_RCC                                   RCC_APB1Periph_TIM3
  27. #define TIMER_IRQ_FUN                         TIM3_IRQHandler
  28. /**@} */
  29. /**@name USART related macro definition
  30. * @{
  31. */
  32. #define UART_BAUDRATE                         9600
  33. #define UART_PORT                             2
  34. #define UART                                  USART2
  35. #define UART_IRQ                              USART2_IRQn
  36. #define UART_IRQ_FUN                          USART2_IRQHandler
  37. #if (UART_PORT == 1)
  38. #define UART_GPIO_Cmd          RCC_APB2PeriphClockCmd
  39. #define UART_GPIO_CLK          RCC_APB2Periph_GPIOA
  40. #define UART_AFIO_Cmd          RCC_APB2PeriphClockCmd
  41. #define UART_AFIO_CLK          RCC_APB2Periph_AFIO
  42. #define UART_CLK_Cmd           RCC_APB2PeriphClockCmd
  43. #define UART_CLK               RCC_APB2Periph_USART1
  44. #define UART_GPIO_PORT         GPIOA
  45. #define UART_RxPin             GPIO_Pin_10
  46. #define UART_TxPin             GPIO_Pin_9
  47. #endif
  48. #if (UART_PORT == 2)
  49. #define UART_GPIO_Cmd          RCC_APB2PeriphClockCmd
  50. #define UART_GPIO_CLK          RCC_APB2Periph_GPIOA
  51. #define UART_AFIO_Cmd          RCC_APB2PeriphClockCmd
  52. #define UART_AFIO_CLK          RCC_APB2Periph_AFIO
  53. #define UART_CLK_Cmd           RCC_APB1PeriphClockCmd
  54. #define UART_CLK               RCC_APB1Periph_USART2
  55. #define UART_GPIO_PORT         GPIOA
  56. #define UART_RxPin             GPIO_Pin_3
  57. #define UART_TxPin             GPIO_Pin_2
  58. #endif
  59. #if (UART_PORT == 3)
  60. #define UART_GPIO_Cmd          RCC_APB2PeriphClockCmd
  61. #define UART_GPIO_CLK          RCC_APB2Periph_GPIOC
  62. #define UART_AFIO_Cmd          RCC_APB2PeriphClockCmd
  63. #define UART_AFIO_CLK          RCC_APB2Periph_AFIO
  64. #define UART_CLK_Cmd           RCC_APB1PeriphClockCmd
  65. #define UART_CLK               RCC_APB1Periph_USART3
  66. #define UART_GPIO_PORT         GPIOC
  67. #define UART_RxPin             GPIO_Pin_11
  68. #define UART_TxPin             GPIO_Pin_10
  69. #endif
  70. /**@} */
  71. /** User area the current device state structure*/
  72. extern dataPoint_t currentDataPoint;
  73. void gizTimerMs(void);
  74. uint32_t gizGetTimerCount(void);
  75. void timerInit(void);
  76. void uartInit(void);
  77. void userInit(void);
  78. void userHandle(void);
  79. void mcuRestart(void);
  80. int32_t uartWrite(uint8_t *buf, uint32_t len);
  81. int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *data, uint32_t len);
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif
复制代码


5,修改gizwits_product.h
Listitem
Listitem
Listitem
Listitem
Listitem

  1. /**
  2. ***************************
  3. * @file         gizwits_protocol.c
  4. * @brief        Corresponding gizwits_product.c header file (including product hardware and software version definition)
  5. * @author       Gizwits
  6. * @date         2017-07-19
  7. * @version      V03030000
  8. * @copyright    Gizwits
  9. *
  10. * @note         机智云.只为智能硬件而生
  11. *               Gizwits Smart Cloud  for Smart Products
  12. *               链接|增值ֵ|开放|中立|安全|自有|自由|生态
  13. *               www.gizwits.com
  14. *
  15. ***************************/
  16. //#include "ringBuffer.h"
  17. //#include "gizwits_product.h"
  18. //#include "dataPointTools.h"
  19. #include "delay.h"
  20. /** Protocol global variables **/
  21. //gizwitsProtocol_t gizwitsProtocol;
  22. //extern dataPoint_t currentDataPoint;
  23. //extern uint8_t wifi_flag;
  24. /**@name The serial port receives the ring buffer implementation
  25. * @{
  26. */
  27. rb_t pRb;                                               ///< Ring buffer structure variable
  28. static uint8_t rbBuf[RB_MAX_LEN];                       ///< Ring buffer data cache buffer
  29. /**@} */
  30. /**
  31. * @brief Write data to the ring buffer
  32. * @param [in] buf        : buf adress
  33. * @param [in] len        : byte length
  34. * @return   correct : Returns the length of the written data
  35.             failure : -1
  36. */
  37. int32_t gizPutData(uint8_t *buf, uint32_t len)
  38. {
  39.     int32_t count = 0;
  40.     if(NULL == buf)
  41.     {
  42.         GIZWITS_LOG("ERR: gizPutData buf is empty \n");
  43.         return -1;
  44.     }
  45.     count = rbWrite(&pRb, buf, len);
  46.     if(count != len)
  47.     {
  48.         GIZWITS_LOG("ERR: Failed to rbWrite \n");
  49.         return -1;
  50.     }
  51.     return count;
  52. }
  53. /**
  54. * @brief Protocol header initialization
  55. *
  56. * @param [out] head         : Protocol header pointer
  57. *
  58. * @return 0, success; other, failure   
  59. */
  60. static int8_t gizProtocolHeadInit(protocolHead_t *head)
  61. {
  62.     if(NULL == head)
  63.     {
  64.         GIZWITS_LOG("ERR: gizProtocolHeadInit head is empty \n");
  65.         return -1;
  66.     }
  67.     memset((uint8_t *)head, 0, sizeof(protocolHead_t));
  68.     head->head[0] = 0xFF;
  69.     head->head[1] = 0xFF;
  70.     return 0;
  71. }
  72. /**
  73. * @brief Protocol ACK check processing function
  74. *
  75. * @param [in] data            : data adress
  76. * @param [in] len             : data length
  77. *
  78. * @return 0, suceess; other, failure
  79. */
  80. static int8_t gizProtocolWaitAck(uint8_t *gizdata, uint32_t len)
  81. {
  82.     if(NULL == gizdata)
  83.     {
  84.         GIZWITS_LOG("ERR: data is empty \n");
  85.         return -1;
  86.     }
  87.     memset((uint8_t *)&gizwitsProtocol.waitAck, 0, sizeof(protocolWaitAck_t));
  88.     memcpy((uint8_t *)gizwitsProtocol.waitAck.buf, gizdata, len);
  89.     gizwitsProtocol.waitAck.dataLen = (uint16_t)len;
  90.    
  91.     gizwitsProtocol.waitAck.flag = 1;
  92.     gizwitsProtocol.waitAck.sendTime = gizGetTimerCount();
  93.     return 0;
  94. }
  95. /**
  96. * @brief generates "controlled events" according to protocol
  97. * @param [in] issuedData: Controlled data
  98. * @param [out] info: event queue
  99. * @param [out] dataPoints: data point data
  100. * @return 0, the implementation of success, non-0, failed
  101. */
  102. static int8_t ICACHE_FLASH_ATTR gizDataPoint2Event(gizwitsIssued_t *issuedData, eventInfo_t *info, dataPoint_t *dataPoints)
  103. {
  104.     if((NULL == issuedData) || (NULL == info) ||(NULL == dataPoints))
  105.     {
  106.         GIZWITS_LOG("gizDataPoint2Event Error , Illegal Param\n");
  107.         return -1;
  108.     }
  109.    
  110.     /** Greater than 1 byte to do bit conversion **/
  111.     if(sizeof(issuedData->attrFlags) > 1)
  112.     {
  113.         if(-1 == gizByteOrderExchange((uint8_t *)&issuedData-&

相关文章