常用的应用层整型编解码函数
来源:互联网 发布:嘉兴nit软件培训 编辑:程序博客网 时间:2024/05/29 17:41
int encode_unsigned16(
uint8_t * apdu,
uint16_t value)
{
apdu[0] = (uint8_t) ((value & 0xff00) >> 8);
apdu[1] = (uint8_t) (value & 0x00ff);
return 2;
}
int decode_unsigned16(
uint8_t * apdu,
uint16_t * value)
{
if (value) {
*value = (uint16_t) ((((uint16_t) apdu[0]) << 8) & 0xff00);
*value |= ((uint16_t) (((uint16_t) apdu[1]) & 0x00ff));
}
return 2;
}
int encode_unsigned24(
uint8_t * apdu,
uint32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff0000) >> 16);
apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t) (value & 0x0000ff);
return 3;
}
int decode_unsigned24(
uint8_t * apdu,
uint32_t * value)
{
if (value) {
*value = ((uint32_t) ((((uint32_t) apdu[0]) << 16) & 0x00ff0000));
*value |= (uint32_t) ((((uint32_t) apdu[1]) << 8) & 0x0000ff00);
*value |= ((uint32_t) (((uint32_t) apdu[2]) & 0x000000ff));
}
return 3;
}
int encode_unsigned32(
uint8_t * apdu,
uint32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff000000) >> 24);
apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16);
apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t) (value & 0x000000ff);
return 4;
}
int decode_unsigned32(
uint8_t * apdu,
uint32_t * value)
{
if (value) {
*value = ((uint32_t) ((((uint32_t) apdu[0]) << 24) & 0xff000000));
*value |= ((uint32_t) ((((uint32_t) apdu[1]) << 16) & 0x00ff0000));
*value |= ((uint32_t) ((((uint32_t) apdu[2]) << 8) & 0x0000ff00));
*value |= ((uint32_t) (((uint32_t) apdu[3]) & 0x000000ff));
}
return 4;
}
#if BACNET_USE_SIGNED
int encode_signed8(
uint8_t * apdu,
int8_t value)
{
apdu[0] = (uint8_t) value;
return 1;
}
int decode_signed8(
uint8_t * apdu,
int32_t * value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80)
*value = 0xFFFFFF00;
else
*value = 0;
*value |= ((int32_t) (((int32_t) apdu[0]) & 0x000000ff));
}
return 1;
}
int encode_signed16(
uint8_t * apdu,
int16_t value)
{
apdu[0] = (uint8_t) ((value & 0xff00) >> 8);
apdu[1] = (uint8_t) (value & 0x00ff);
return 2;
}
int decode_signed16(
uint8_t * apdu,
int32_t * value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80)
*value = 0xFFFF0000;
else
*value = 0;
*value |= ((int32_t) ((((int32_t) apdu[0]) << 8) & 0x0000ff00));
*value |= ((int32_t) (((int32_t) apdu[1]) & 0x000000ff));
}
return 2;
}
int encode_signed24(
uint8_t * apdu,
int32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff0000) >> 16);
apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t) (value & 0x0000ff);
return 3;
}
int decode_signed24(
uint8_t * apdu,
int32_t * value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80)
*value = 0xFF000000;
else
*value = 0;
*value |= ((int32_t) ((((int32_t) apdu[0]) << 16) & 0x00ff0000));
*value |= ((int32_t) ((((int32_t) apdu[1]) << 8) & 0x0000ff00));
*value |= ((int32_t) (((int32_t) apdu[2]) & 0x000000ff));
}
return 3;
}
int encode_signed32(
uint8_t * apdu,
int32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff000000) >> 24);
apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16);
apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t) (value & 0x000000ff);
return 4;
}
int decode_signed32(
uint8_t * apdu,
int32_t * value)
{
if (value) {
*value = ((int32_t) ((((int32_t) apdu[0]) << 24) & 0xff000000));
*value |= ((int32_t) ((((int32_t) apdu[1]) << 16) & 0x00ff0000));
*value |= ((int32_t) ((((int32_t) apdu[2]) << 8) & 0x0000ff00));
*value |= ((int32_t) (((int32_t) apdu[3]) & 0x000000ff));
}
return 4;
}
uint8_t * apdu,
uint16_t value)
{
apdu[0] = (uint8_t) ((value & 0xff00) >> 8);
apdu[1] = (uint8_t) (value & 0x00ff);
return 2;
}
int decode_unsigned16(
uint8_t * apdu,
uint16_t * value)
{
if (value) {
*value = (uint16_t) ((((uint16_t) apdu[0]) << 8) & 0xff00);
*value |= ((uint16_t) (((uint16_t) apdu[1]) & 0x00ff));
}
return 2;
}
int encode_unsigned24(
uint8_t * apdu,
uint32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff0000) >> 16);
apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t) (value & 0x0000ff);
return 3;
}
int decode_unsigned24(
uint8_t * apdu,
uint32_t * value)
{
if (value) {
*value = ((uint32_t) ((((uint32_t) apdu[0]) << 16) & 0x00ff0000));
*value |= (uint32_t) ((((uint32_t) apdu[1]) << 8) & 0x0000ff00);
*value |= ((uint32_t) (((uint32_t) apdu[2]) & 0x000000ff));
}
return 3;
}
int encode_unsigned32(
uint8_t * apdu,
uint32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff000000) >> 24);
apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16);
apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t) (value & 0x000000ff);
return 4;
}
int decode_unsigned32(
uint8_t * apdu,
uint32_t * value)
{
if (value) {
*value = ((uint32_t) ((((uint32_t) apdu[0]) << 24) & 0xff000000));
*value |= ((uint32_t) ((((uint32_t) apdu[1]) << 16) & 0x00ff0000));
*value |= ((uint32_t) ((((uint32_t) apdu[2]) << 8) & 0x0000ff00));
*value |= ((uint32_t) (((uint32_t) apdu[3]) & 0x000000ff));
}
return 4;
}
#if BACNET_USE_SIGNED
int encode_signed8(
uint8_t * apdu,
int8_t value)
{
apdu[0] = (uint8_t) value;
return 1;
}
int decode_signed8(
uint8_t * apdu,
int32_t * value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80)
*value = 0xFFFFFF00;
else
*value = 0;
*value |= ((int32_t) (((int32_t) apdu[0]) & 0x000000ff));
}
return 1;
}
int encode_signed16(
uint8_t * apdu,
int16_t value)
{
apdu[0] = (uint8_t) ((value & 0xff00) >> 8);
apdu[1] = (uint8_t) (value & 0x00ff);
return 2;
}
int decode_signed16(
uint8_t * apdu,
int32_t * value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80)
*value = 0xFFFF0000;
else
*value = 0;
*value |= ((int32_t) ((((int32_t) apdu[0]) << 8) & 0x0000ff00));
*value |= ((int32_t) (((int32_t) apdu[1]) & 0x000000ff));
}
return 2;
}
int encode_signed24(
uint8_t * apdu,
int32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff0000) >> 16);
apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t) (value & 0x0000ff);
return 3;
}
int decode_signed24(
uint8_t * apdu,
int32_t * value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80)
*value = 0xFF000000;
else
*value = 0;
*value |= ((int32_t) ((((int32_t) apdu[0]) << 16) & 0x00ff0000));
*value |= ((int32_t) ((((int32_t) apdu[1]) << 8) & 0x0000ff00));
*value |= ((int32_t) (((int32_t) apdu[2]) & 0x000000ff));
}
return 3;
}
int encode_signed32(
uint8_t * apdu,
int32_t value)
{
apdu[0] = (uint8_t) ((value & 0xff000000) >> 24);
apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16);
apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t) (value & 0x000000ff);
return 4;
}
int decode_signed32(
uint8_t * apdu,
int32_t * value)
{
if (value) {
*value = ((int32_t) ((((int32_t) apdu[0]) << 24) & 0xff000000));
*value |= ((int32_t) ((((int32_t) apdu[1]) << 16) & 0x00ff0000));
*value |= ((int32_t) ((((int32_t) apdu[2]) << 8) & 0x0000ff00));
*value |= ((int32_t) (((int32_t) apdu[3]) & 0x000000ff));
}
return 4;
}
- 常用的应用层整型编解码函数
- base64的编解码函数
- 常用编解码介绍(网上的资料)
- 常用编解码介绍(网上的资料)
- js URL编解码的应用说明
- 常用编解码介绍
- FFmpeg编解码常用函数ffmpeg av_parser_parse2()函数
- ffmpeg编解码应用
- ffmpeg编解码应用
- URL编解码函数
- ffmpeg编解码函数
- [网摘]常用编解码介绍
- [网摘]常用编解码介绍
- [网摘]常用编解码介绍
- 常用音频视频编解码介绍
- JAVA常用编解码方法
- 常用语音编解码介绍
- Java的编解码
- 二叉查找树(二叉排序树)的详细实现 .
- MVC设计web网址 ---- 为数据建模
- linux常用命令100个用法
- 无限级分类Asp.net Mvc实现
- Redis源码学习-NoSql复杂类型对象的hash管理(二:List)
- 常用的应用层整型编解码函数
- wxPython Demo 学习
- 第十三周-求出并输出Fibnacci序列的第20个数(递归方式)
- jQuery写日历
- Word2010邮件合并(附带照片)
- 备份一下FFT帖子
- BP 神经网络
- 我是不是被“小三”了?
- where 条件并不是越多越好