add more comments
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_def.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 全局宏定义,常量,及结构体。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_DEF_H__
|
||||
#define __CHRG_DEF_H__
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_eload.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 源载命令数据解析,封装,读写请求。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,6 +17,14 @@
|
||||
#include "chrg_lcd.h"
|
||||
#include "chrg_utils.h"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_read_regs
|
||||
函数描述: 向南向发送读取寄存器
|
||||
输入参数: addr:地址 reg:寄存器起始地址 len:寄存器个数
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_eload_read_regs (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t len)
|
||||
{
|
||||
rt_uint8_t buf[8] = {0};
|
||||
@@ -23,6 +40,14 @@ int chrg_eload_read_regs (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t len)
|
||||
return chrg_south_send(buf, 8);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_write_reg
|
||||
函数描述: 向南向发送写单个寄存器
|
||||
输入参数: addr:地址 reg:寄存器地址 value:写入值
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_eload_write_reg (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t value)
|
||||
{
|
||||
rt_uint8_t buf[8] = {0};
|
||||
@@ -38,6 +63,14 @@ int chrg_eload_write_reg (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t value)
|
||||
return chrg_south_send(buf, 8);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_refresh
|
||||
函数描述: 分段请求读取寄存器表
|
||||
输入参数: addr:地址 part:分段
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: 实际运行过程只需要读取前13个寄存器即可,即分段0
|
||||
*****************************************************************/
|
||||
int chrg_eload_refresh (rt_uint8_t addr, rt_uint8_t part)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -51,6 +84,14 @@ int chrg_eload_refresh (rt_uint8_t addr, rt_uint8_t part)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_parse
|
||||
函数描述: 解析源载返回数据
|
||||
输入参数: idx:通道 pt:分段0 *data:数据区 len:数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16_t len)
|
||||
{
|
||||
if (idx >= TOTAL_SOU_CHS) {
|
||||
@@ -71,26 +112,49 @@ int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16
|
||||
pLOAD->status2 = pP1->status2;
|
||||
pLOAD->fault1 = pP1->fault1;
|
||||
pLOAD->fault2 = (rt_uint8_t)pP1->fault2;
|
||||
pLOAD->eload = (rt_uint8_t)pP1->eload;
|
||||
pLOAD->eload = swap_u16(pP1->eload);
|
||||
pLOAD->work = (rt_uint8_t)pP1->work_cmd;
|
||||
pLOAD->mode = (rt_uint8_t)pP1->work_mode;
|
||||
pLOAD->voltage = pP1->voltage;
|
||||
pLOAD->current = pP1->current;
|
||||
pLOAD->voltage = swap_u32(pP1->voltage);
|
||||
pLOAD->current = swap_u32(pP1->current);
|
||||
pLOAD->temperatue = pP1->temperature;
|
||||
pLOAD->version = pP1->version;
|
||||
pLOAD->address = (rt_uint8_t)pP1->addr;
|
||||
rt_kprintf("vol %d, cur %d\r\n", pLOAD->voltage, pLOAD->current);
|
||||
|
||||
char tmp[36] = {0};
|
||||
snprintf(tmp, 36, "main.CH%d_Volt_Show.val=%d",
|
||||
idx+1, pLOAD->voltage);
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
snprintf(tmp, 36, "status.CH%d_Volt_Sta.txt=\"%d.%03d\"",
|
||||
idx+1, pLOAD->voltage/1000, pLOAD->voltage%1000);
|
||||
chrg_lcd_send(tmp);
|
||||
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
snprintf(tmp, 36, "main.CH%d_Curr_Show.val=%d",
|
||||
idx+1, pLOAD->current);
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
snprintf(tmp, 36, "status.CH%d_Curr_Sta.txt=\"%d.%03d\"",
|
||||
idx+1, pLOAD->current/1000, pLOAD->current%1000);
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
if (pP1->work_cmd == 0x100){
|
||||
if (pP1->work_mode == MODE_CONSTANT_VOLTAGE){
|
||||
snprintf(tmp, 36, "main.CH%d_Status.txt=\"恒压\"", idx+1);
|
||||
} else {
|
||||
snprintf(tmp, 36, "main.CH%d_Status.txt=\"恒流\"", idx+1);
|
||||
}
|
||||
} else {
|
||||
snprintf(tmp, 36, "main.CH%d_Status.txt=\"停止\"", idx+1);
|
||||
}
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_eload.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 源载命令数据解析,封装,读写请求,寄存器定义,数据结构定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_ELOAD_H__
|
||||
#define __CHRG_ELOAD_H__
|
||||
|
||||
@@ -104,6 +113,7 @@ typedef enum {
|
||||
#define SIZE_P1_RD 13 // 读13个寄存器
|
||||
#define SIZE_P2_RD 28 // 读28个寄存器
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct eload_p1_t {
|
||||
rt_uint16_t status1; // reg0
|
||||
rt_uint16_t status2; // reg1
|
||||
@@ -153,13 +163,46 @@ struct chrg_eload_t {
|
||||
rt_uint16_t version; // 版本
|
||||
rt_uint8_t address; // 地址
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_read_regs
|
||||
函数描述: 向南向发送读取寄存器
|
||||
输入参数: addr:地址 reg:寄存器起始地址 len:寄存器个数
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_read_regs (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t len);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_write_reg
|
||||
函数描述: 向南向发送写单个寄存器
|
||||
输入参数: addr:地址 reg:寄存器地址 value:写入值
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_write_reg (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t value);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_refresh
|
||||
函数描述: 分段请求读取寄存器表
|
||||
输入参数: addr:地址 part:分段
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: 实际运行过程只需要读取前13个寄存器即可,即分段0
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_refresh (rt_uint8_t addr, rt_uint8_t part);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_parse
|
||||
函数描述: 解析源载返回数据
|
||||
输入参数: idx:通道 pt:分段0 *data:数据区 len:数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16_t len);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_north_pkg.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据编码、解码。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
@@ -6,6 +14,15 @@
|
||||
#include "chrg_north_pkg.h"
|
||||
#include "chrg_utils.h"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_encode
|
||||
函数描述: 北向数据帧编码
|
||||
输入参数: id: sink/source cmd:指令 *data_in:数据 len_in:数据长度
|
||||
*data_out:数据帧 len_out:数据帧长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_north_pkg_encode (eIDX_ID id, rt_uint8_t cmd, rt_uint8_t *data_in,
|
||||
rt_uint8_t len_in, rt_uint8_t *data_out, rt_uint16_t *len_out)
|
||||
{
|
||||
@@ -33,7 +50,14 @@ int chrg_north_pkg_encode (eIDX_ID id, rt_uint8_t cmd, rt_uint8_t *data_in,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_decode
|
||||
函数描述: 北向数据帧解码
|
||||
输入参数: *data:数据 length:数据长度 *pSW:源载数据结构
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_north_pkg_decode (rt_uint8_t *data, rt_uint16_t length, struct chrg_switch_t *pSW)
|
||||
{
|
||||
if ((RT_NULL == data)||(RT_NULL == pSW)||(length < 5)) {
|
||||
|
||||
@@ -7,9 +7,26 @@
|
||||
#include "chrg_def.h"
|
||||
#include "chrg_north.h"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_encode
|
||||
函数描述: 北向数据帧编码
|
||||
输入参数: id: sink/source cmd:指令 *data_in:数据 len_in:数据长度
|
||||
*data_out:数据帧 len_out:数据帧长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_north_pkg_encode (eIDX_ID id, rt_uint8_t cmd, rt_uint8_t *data_in,
|
||||
rt_uint8_t len_in, rt_uint8_t *data_out, rt_uint16_t *len_out);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_decode
|
||||
函数描述: 北向数据帧解码
|
||||
输入参数: *data:数据 length:数据长度 *pSW:源载数据结构
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_north_pkg_decode (rt_uint8_t *data, rt_uint16_t length, struct chrg_switch_t *pSW);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_sink.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据sink请求数据填充及发送。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "chrg_sink.h"
|
||||
@@ -6,7 +14,14 @@
|
||||
#include "chrg_north_pkg.h"
|
||||
#include "chrg_utils.h"
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: sink_get_vc
|
||||
函数描述: sink电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int sink_get_vc (rt_uint16_t vol, rt_uint16_t cur)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_sink.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据sink请求数据填充及发送,命令字定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_SINK_H__
|
||||
#define __CHRG_SINK_H__
|
||||
|
||||
@@ -142,6 +151,14 @@ struct chrg_sink_t {
|
||||
rt_uint8_t cc_lvl; // 设置CC线电平等级(0-10,默认7)
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: sink_get_vc
|
||||
函数描述: sink电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int sink_get_vc (rt_uint16_t vol, rt_uint16_t cur);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_source.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据source请求数据填充及发送。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "chrg_source.h"
|
||||
@@ -7,7 +15,14 @@
|
||||
#include "chrg_utils.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_vc
|
||||
函数描述: source电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_get_vc (rt_uint16_t vol, rt_uint16_t cur)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
@@ -24,6 +39,14 @@ int source_get_vc (rt_uint16_t vol, rt_uint16_t cur)
|
||||
return chrg_north_send(frame, len);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_pd
|
||||
函数描述: source pd 协议查询请求
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_get_pd (void)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
@@ -34,6 +57,14 @@ int source_get_pd (void)
|
||||
return chrg_north_send(frame, len);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_cc_lvl
|
||||
函数描述: source 设置 cc 等级
|
||||
输入参数: lvl:等级
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_set_cc_lvl (rt_uint8_t lvl)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
@@ -47,6 +78,14 @@ int source_set_cc_lvl (rt_uint8_t lvl)
|
||||
return chrg_north_send(frame, len);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_pd
|
||||
函数描述: source 设置PD协议
|
||||
输入参数: pro:协议 src:源 pps: PPS vmax:最大电压 vmin:最小电压 max_cur:最大电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_set_pd (rt_uint8_t pro, rt_uint8_t src, rt_uint8_t pps,
|
||||
rt_uint16_t vmax, rt_uint16_t vmin, rt_int16_t max_cur)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_source.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据source请求数据填充及发送,命令字定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_SOURCE_H__
|
||||
#define __CHRG_SOURCE_H__
|
||||
|
||||
@@ -128,12 +137,44 @@ struct chrg_src_t {
|
||||
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_vc
|
||||
函数描述: source电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_get_vc (rt_uint16_t vol, rt_uint16_t cur);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_pd
|
||||
函数描述: source pd 协议查询请求
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_get_pd (void);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_cc_lvl
|
||||
函数描述: source 设置 cc 等级
|
||||
输入参数: lvl:等级
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_set_cc_lvl (rt_uint8_t lvl);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_pd
|
||||
函数描述: source 设置PD协议
|
||||
输入参数: pro:协议 src:源 pps: PPS vmax:最大电压 vmin:最小电压 max_cur:最大电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_set_pd (rt_uint8_t pro, rt_uint8_t src, rt_uint8_t pps,
|
||||
rt_uint16_t vmax, rt_uint16_t vmin, rt_int16_t max_cur);
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_utils.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 一些通用数据封装,功能接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
@@ -53,6 +61,14 @@ static const rt_uint8_t aucCRCLo[] = {
|
||||
0x41, 0x81, 0x80, 0x40
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: mb_crc16
|
||||
函数描述: 查表法计算 MODBUS CRC16校验
|
||||
输入参数: *pucFrame:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint16_t mb_crc16 (rt_uint8_t *pucFrame, rt_uint16_t usLen)
|
||||
{
|
||||
rt_uint8_t ucCRCHi = 0xFF;
|
||||
@@ -88,6 +104,14 @@ rt_uint8_t _crc8 (rt_uint8_t res, rt_uint8_t data)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: calc_crc8
|
||||
函数描述: 计算 crc8
|
||||
输入参数: *data:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint8_t calc_crc8 (rt_uint8_t *data, rt_uint8_t length)
|
||||
{
|
||||
rt_uint8_t i = 0, res = 0x55;
|
||||
@@ -99,6 +123,14 @@ rt_uint8_t calc_crc8 (rt_uint8_t *data, rt_uint8_t length)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u16_to_u8v
|
||||
函数描述: u16 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint8_t u16_to_u8v (rt_uint16_t value, rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
@@ -110,6 +142,14 @@ rt_uint8_t u16_to_u8v (rt_uint16_t value, rt_uint8_t *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u16
|
||||
函数描述: 字节流转 u16
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint16_t u8v_to_u16 (rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
@@ -119,14 +159,67 @@ rt_uint16_t u8v_to_u16 (rt_uint8_t *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// rt_uint16_t 高低位互换
|
||||
/*****************************************************************
|
||||
函数名称: u32_to_u8v
|
||||
函数描述: u32 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint8_t u32_to_u8v (rt_uint32_t value, rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
buf[0] = (value>>24)&0xFF;
|
||||
buf[1] = (value>>16)&0xFF;
|
||||
buf[2] = (value>>8)&0xFF;
|
||||
buf[3] = value&0xFF;
|
||||
return 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u32
|
||||
函数描述: 字节流转 u32
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint32_t u8v_to_u32 (rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
return (((rt_uint32_t)buf[0]<<24) + ((rt_uint32_t)buf[1]<<16)
|
||||
+((rt_uint32_t)buf[2]<<8) + buf[3]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: swap_u16
|
||||
函数描述: u16高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint16_t swap_u16 (rt_uint16_t x)
|
||||
{
|
||||
return ((x & 0x00FF) << 8) |
|
||||
((x & 0xFF00) >> 8);
|
||||
}
|
||||
|
||||
// rt_uint32_t 高低位互换
|
||||
/*****************************************************************
|
||||
函数名称: swap_u32
|
||||
函数描述: u32高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint32_t swap_u32 (rt_uint32_t x)
|
||||
{
|
||||
return ((x & 0x000000FF) << 24) |
|
||||
|
||||
@@ -1,18 +1,95 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_utils.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 一些通用数据封装,功能接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_UTILS_H__
|
||||
#define __CHRG_UTILS_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: mb_crc16
|
||||
函数描述: 查表法计算 MODBUS CRC16校验
|
||||
输入参数: *pucFrame:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint16_t mb_crc16 (rt_uint8_t * pucFrame, rt_uint16_t usLen);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: calc_crc8
|
||||
函数描述: 计算 crc8
|
||||
输入参数: *data:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint8_t calc_crc8 (rt_uint8_t *data, rt_uint8_t length);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u16_to_u8v
|
||||
函数描述: u16 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint8_t u16_to_u8v (rt_uint16_t value, rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u16
|
||||
函数描述: 字节流转 u16
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint16_t u8v_to_u16 (rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u32_to_u8v
|
||||
函数描述: u32 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint8_t u32_to_u8v (rt_uint32_t value, rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u32
|
||||
函数描述: 字节流转 u32
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint32_t u8v_to_u32 (rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: swap_u16
|
||||
函数描述: u16高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint16_t swap_u16 (rt_uint16_t x);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: swap_u32
|
||||
函数描述: u32高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint32_t swap_u32 (rt_uint32_t x);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user