资源简介
OneNET平台EDP协议C语言SDK 使用教程:https://blog.csdn.net/m0_37738838/article/details/86366208
代码片段和文件信息
#include
#include
#include
#define CONNREQ 0x10
#define CONNRESP 0x20
#define PUSHDATA 0x30
#define SAVEDATA 0x80
#define SAVEACK 0x90
#define CMDREQ 0xA0
#define CMDRESP 0xB0
#define PINGREQ 0xC0
#define PINGRESP 0xD0
#define ENCRYPTREQ 0xE0
#define ENCRYPTRESP 0xF0
#define MAX_LEN 200
#define PROTOCOL_NAME “EDP“
#define PROTOCOL_VERSION 1
typedef unsigned char uint8;
typedef char int8;
typedef unsigned int uint16;
typedef int int16;
typedef unsigned long uint32;
typedef long int32;
typedef struct
{
uint8 data[MAX_LEN];
int16 len;
int16 read_p;
} edp_pkt;
/*
* packetCreate
* 鍒涘缓涓?涓狤DP鍖呯紦瀛樼┖闂?
*/
edp_pkt *packetCreate(void)
{
edp_pkt *p;
if((p = (edp_pkt *)malloc(sizeof(edp_pkt))) != NULL)
memset(p 0 sizeof(edp_pkt));
return p;
}
/*
* writeRemainlen
* 鍚慐DP鍖呬腑鍐欏叆鍓╀綑闀垮害瀛楁
* len_val: 鍓╀綑闀垮害鐨勫??
*/
int8 writeRemainlen(edp_pkt* pkt int16 len_val)
{
int8 remaining_count = 0;
int8 tmp = 0;
do {
tmp = len_val % 128;
len_val = len_val / 128;
/* If there are more digits to encode set the top bit of this digit */
if (len_val > 0) {
tmp = tmp | 0x80;
}
pkt->data[pkt->len++] = tmp;
remaining_count++;
} while (len_val > 0 && remaining_count < 5);
return remaining_count;
}
/*
* writeByte
* 鍚慐DP鍖呬腑鍐欏叆涓?涓瓧鑺?
*/
int16 writeByte(edp_pkt* pkt int8 byte)
{
pkt->data[pkt->len++] = byte;
return 0;
}
/*
* writeBytes
* 鍚慐DP鍖呬腑鍐欏叆澶氫釜瀛楄妭
*/
int16 writeBytes(edp_pkt* pkt const void* bytes int16 count)
{
memcpy(pkt->data + pkt->len bytes count);
pkt->len += count;
return 0;
}
/*
* writeStr
* 鍚慐DP鍖呬腑鍐欏叆瀛楃涓插瓧娈?
* 棣栧厛鍐欏叆涓や釜瀛楄妭鐨勯暱搴︼紝闅忓悗绱ц窡瀛楃涓插唴瀹?
*/
int16 writeStr(edp_pkt* pkt const int8* str)
{
short len = strlen(str);
writeByte(pkt len >> 8);
writeByte(pkt len & 0x00ff);
memcpy(pkt->data + pkt->len str len);
pkt->len += len;
return 0;
}
/*---------------------------------------------------------------------------*/
/*
* readUint8
* 浠嶦DP鍖呬腑璇诲嚭涓?涓瓧鑺?
*/
uint8 readUint8(edp_pkt* pkt)
{
return pkt->data[pkt->read_p++];
}
/*
* readUint16
* 浠嶦DP鍖呬腑璇诲嚭16bit鐨勫瓧娈?
*/
uint16 readUint16(edp_pkt* pkt)
{
uint16 tmp;
uint8 msb lsb;
msb = readUint8(pkt);
lsb = readUint8(pkt);
tmp = (msb<<8) | lsb;
return tmp;
}
/*
* readUint32
* 浠嶦DP鍖呬腑璇诲嚭4涓瓧鑺傜殑瀛楁
*/
uint32 readUint32(edp_pkt* pkt)
{
uint32 tmp = 0;
int i = 4;
while (--i >= 0)
{
tmp <<= 8;
tmp |= readUint8(pkt);
}
return tmp;
}
/*
* readStr
* 鏍规嵁闀垮害锛屼粠EDP鍖呬腑璇诲嚭瀛楃涓叉暟鎹?
* len : 瀛楃涓茬殑闀垮害
*/
void readStr(edp_pkt* pkt char* str uint16 len)
{
memcpy(str pkt->data + pkt->read_p len);
pkt->read_p += len;
}
/*
* readRemainlen
* 浠嶦DP鍖呬腑璇诲嚭鍓╀綑闀垮害
*/
int32 readRemainlen(edp_pkt* pkt)
{
uint32 multiplier = 1;
uint32 len_len = 0;
uint8 oneby
- 上一篇:迷宫的生成与自动寻路
- 下一篇:bmp280的读取C语言
相关资源
- OneNET_EDP调试发送与接收
- dht11.h库文件
- arduino GCode_Interpreterdc G代码解释器 也
- ADXL345 加速度计 arduino代码
- arduino循迹小车
- 《爱上Arduino(第3版)》pdf 高清版
- arduino library for proteus
- arduino读取温湿度传感器程序
- Arduino从基础到实践
- ARDUINO一试就上手.第2版
- Gravity: BMI160 6轴惯性运动传 感器
- arduino学习笔记.doc(212页)
- arduino 舵机控制 串口通信 超声波传感
- 《Arduino程序设计基础》(第2版)带目
- arduino看门狗
- Arduino程序设计基础.pdf
评论
共有 条评论