ESP8266 Centre + NB
结构体 | 宏定义 | 类型定义 | 枚举 | 函数 | 变量
app_study_room.h 文件参考
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "driver/uart.h"
app_study_room.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

结构体

struct  DeviceController
 云端下发的用电器控制信息 更多...
 
struct  RoomMessage
 室内环境信息结构体 更多...
 
struct  RoomStatus
 室内用电器状态信息结构体 更多...
 

宏定义

#define cn_app_bands   "5,8,20"
 
#define cn_app_plmn   "46011";
 
#define cn_app_apn   "1,\"IP\",\"HUAWEI.COM\""
 
#define HUAWEI_IOT_SERVER   "49.4.85.232"
 
#define HUAWEI_IOT_PORT   "5683"
 
#define Swap16(A)   ((((uint16)(A)&0xff00) >> 8) | (((uint16)(A)&0x00ff) << 8))
 
#define Swap32(A)   ((((uint32)(A)&0xff000000) >> 24) | (((uint32)(A)&0x00ff0000) >> 8) | (((uint32)(A)&0x0000ff00) << 8) | (((uint32)(A)&0x000000ff) << 24))
 

类型定义

typedef unsigned char int8u
 
typedef char int8s
 
typedef unsigned short int16u
 
typedef short int16s
 
typedef unsigned char int24u
 
typedef char int24s
 
typedef int int32s
 
typedef char string
 
typedef char array
 
typedef char varstring
 
typedef char variant
 

枚举

enum  Device { DEVICE_FAN = 0x00, DEVICE_LIGHT = 0x01, DEVICE_CUTRAIN = 0x02, DEVICE_AC = 0x03 }
 用电器类型枚举体 更多...
 
enum  DecodeMessageId {
  MID_SET_FAN = 0x0, MID_SET_LIGHT = 0x1, MID_SET_CURTAIN = 0x2, MID_SET_AC = 0x3,
  MID_report_room_one_message = 0x11, MID_report_room_two_message = 0x12, MID_report_room_three_message = 0x13, MID_report_room_four_message = 0x14,
  MID_report_room_one_status = 0x21, MID_report_room_two_status = 0x22, MID_report_room_three_status = 0x23, MID_report_room_four_status = 0x24
}
 编解码插件messageId枚举体 更多...
 

函数

void StudyRoom_UpdataData (uint8 *msg_string)
 更新本地数据 更多...
 
uint8StudyRoom_GetStatusHex (uint8 room_no)
 将一个房间所有用电器的状态转成 Hex 字符串 更多...
 

变量

short int Lux
 

详细描述


作者
Gump
版本
V0.1
日期
2020-01-29

宏定义说明

#define cn_app_bands   "5,8,20"
#define cn_app_plmn   "46011";
#define cn_app_apn   "1,\"IP\",\"HUAWEI.COM\""
#define HUAWEI_IOT_SERVER   "49.4.85.232"

华为IoT平台服务器地址

#define HUAWEI_IOT_PORT   "5683"

LWM2M(CoAP) 无DTLS形式接入平台的端口

#define Swap16 (   A)    ((((uint16)(A)&0xff00) >> 8) | (((uint16)(A)&0x00ff) << 8))
#define Swap32 (   A)    ((((uint32)(A)&0xff000000) >> 24) | (((uint32)(A)&0x00ff0000) >> 8) | (((uint32)(A)&0x0000ff00) << 8) | (((uint32)(A)&0x000000ff) << 24))

类型定义说明

typedef unsigned char int8u
typedef char int8s
typedef unsigned short int16u
typedef short int16s
typedef unsigned char int24u
typedef char int24s
typedef int int32s
typedef char string
typedef char array
typedef char varstring
typedef char variant

枚举类型说明

enum Device

用电器类型枚举体

枚举值
DEVICE_FAN 

风扇用电器

DEVICE_LIGHT 

电灯用电器

DEVICE_CUTRAIN 

窗帘用电器

DEVICE_AC 

空调用电器

32 {
33  DEVICE_FAN = 0x00,
34  DEVICE_LIGHT = 0x01,
35  DEVICE_CUTRAIN = 0x02,
36  DEVICE_AC = 0x03
37 } Device;
Definition: app_study_room.h:35
Definition: app_study_room.h:36
Device
用电器类型枚举体
Definition: app_study_room.h:31
Definition: app_study_room.h:33
Definition: app_study_room.h:34

编解码插件messageId枚举体

枚举值
MID_SET_FAN 

风扇控制指令

MID_SET_LIGHT 

电灯控制指令

MID_SET_CURTAIN 

窗帘控制指令

MID_SET_AC 

空调控制指令

MID_report_room_one_message 

房间一的环境信息

MID_report_room_two_message 

房间二的环境信息

MID_report_room_three_message 

房间三的环境信息

MID_report_room_four_message 

房间四的环境信息

MID_report_room_one_status 

房间一的用电器状态信息

MID_report_room_two_status 

房间二的用电器状态信息

MID_report_room_three_status 

房间三的用电器状态信息

MID_report_room_four_status 

房间四的用电器状态信息

41 {
42  MID_SET_FAN = 0x0,
43  MID_SET_LIGHT = 0x1,
44  MID_SET_CURTAIN = 0x2,
45  MID_SET_AC = 0x3,
Definition: app_study_room.h:54
Definition: app_study_room.h:42
Definition: app_study_room.h:52
DecodeMessageId
编解码插件messageId枚举体
Definition: app_study_room.h:40
Definition: app_study_room.h:50
Definition: app_study_room.h:49
Definition: app_study_room.h:44
Definition: app_study_room.h:47
Definition: app_study_room.h:43
Definition: app_study_room.h:53
Definition: app_study_room.h:45
Definition: app_study_room.h:55
Definition: app_study_room.h:48

函数说明

void StudyRoom_UpdataData ( uint8 msg_string)

更新本地数据

  • 更新单个房间的环境信息
  • 更新单个房间的单个用电器的状态

单次调用时,环境信息和用电器状态信息不同时更新

  • 由各个房间的client节点发送到本节点的tcp server上,msg_string来自于tcp_server_recv()
参数
[in]msg_string信息指令串
  • 0xFF 作为标志位:室内环境信息
  • 0xFE 作为标志位:用电器状态信息
参见
room_status
room_message
139  {
140 
141  uint8 hexstr[128];
142 
143  if (msg_string[0] == 0xFF)
144  {
145  /* msg_string[1] 房间编号,取值范围[1..4] */
146  os_memcpy((room_message + msg_string[1] - 1), msg_string + 2, 4 );
147 
148  }
149  else if (msg_string[0] == 0xFE)
150  {
151  // StudyRoom_GetStatusHex(msg_string[1], hexstr);
152  // ESP_DEBUG("status str now is: %s, num is %d", hexstr, room_status[0]);
153 
154  /* 位运算 先将目标用电器位置零,再将指令赋值给目标用电器位 */
155  *(room_status + (msg_string[1] - 1)) &= ~(0x01 << (8 * msg_string[2] + msg_string[3]));
156  *(room_status + (msg_string[1] - 1)) |= ((uint32)msg_string[4] << (8 * msg_string[2] + msg_string[3]));
157 
158  // StudyRoom_GetStatusHex(msg_string[1], hexstr);
159  // ESP_DEBUG("status str now is: %s, num is %d", hexstr, room_status[0]);
160  }
161 
162 }
RoomMessage room_message[4]
四个房间的环境信息
Definition: app_study_room.c:59
#define os_memcpy
Definition: osapi.h:36
uint32 room_status[4]
四个房间的用电器状态信息
Definition: app_study_room.c:119
unsigned char uint8
Definition: c_types.h:43
unsigned int uint32
Definition: c_types.h:52
uint8* StudyRoom_GetStatusHex ( uint8  room_no)

将一个房间所有用电器的状态转成 Hex 字符串

注解
数据格式与IoT平台的编解码插件保持一致
参数
[in]room_no需要转换的房间编号
返回
uint8* 转换后的字符串
参见
room_status
174  {
175 
176  uint8 i,j;
177  bool one_status; /* 一个用电器的状态, 只用一个数据位表示开关即可 */
178  static uint8 out_hexstr[128]; /* 转换后的字符串,必须指定成static类型才能return */
179  uint8 *current_pos = out_hexstr; /* 指向当前 out_hexstr 位置的指针 */
180 
181  for (i = DEVICE_FAN; i <= DEVICE_AC; i++) {
182 
183  /* 在每类用电器前面加上该类用电器的数量 */
184  os_sprintf(current_pos, "%02X", DEVICE_QAUNTITY);
185  current_pos += 2;
186 
187  for(j = 0; j < DEVICE_QAUNTITY; j++, current_pos += 2 ) {
188 
189  /* 先定位某个房间某一类用电器的状态,再定位具体的单个用电器状态 */
190  /* 可以结合用电器状态的“数组数据分布”来理解,参阅 room_status[] 的注释 */
191  one_status = (((*(room_status + room_no - 1) >> (8 * i)) & 0x000000ff) >> j) & 0x01;
192  os_sprintf(current_pos, "%02X", one_status);
193  }
194 
195  ESP_DEBUG("out_hexstr = %s", out_hexstr);
196  }
197 
198  return out_hexstr;
199 }
#define os_sprintf
Definition: osapi.h:54
#define DEVICE_QAUNTITY
Definition: app_study_room.c:24
#define ESP_DEBUG(fmt,...)
Definition: driver/uart.h:35
uint32 room_status[4]
四个房间的用电器状态信息
Definition: app_study_room.c:119
Definition: app_study_room.h:36
unsigned char uint8
Definition: c_types.h:43
Definition: app_study_room.h:33

变量说明

short int Lux