Socket
Socket
Sign inDemoInstall

pws-formula

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pws-formula

This is a formula execute the string or buffer format formula libray to get values from string or buffer.


Version published
Weekly downloads
2
decreased by-71.43%
Maintainers
1
Install size
45.8 kB
Created
Weekly downloads
 

Readme

Source

PWS公式系统设计说明

pws_fomular_design_srs

修订记录

序号日期作者说明
12017-12-21thomas.li新建文档

1. 概述

1.1 文档目的

定义PWS数据采集系统的返回串计算公式定义及功能

1.2 项目范围

本产品主要面向中小型机房客户,为机房的基础设施提供环境数据采集检测服务。

1.3 术语

缩略语别名定义
Hex十六进制返回串的数据构成方式,例如0x01030401000036C403
asciiascii码返回串的数据构成方式,例如~132382823434
modbusmodbus数据通信协议
pmbus电总协议数据定义协议
bcd数据格式以16进制表示十进制数,例如0x0326=>326
crcCRC校验算法一种校验算法
sumsum校验算法一种校验算法

1.4 相关文档

序号文档名文档编号
1pws_database_design_srs
2

2. 十六进制公式

###2.1 hx(start,length=2,byte_order=1)

  • 对象:hex

  • 说明:将byte[]转换成十进制整数

  • 返回:整数或者-1(参数错误)

  • start:开始位,从0开始计算,Byte的顺序

  • length:长度,按照Byte计算,默认为2

  • byte_order:1-高位在前,0-高位在后

    string:0x01030401010038CCCC

    hx(6,2)=hx(3,2,1)=int(0x0101,16)=257

###2.2 hb(start,index)

  • 对象:hex

  • 说明:截取byte[]中的bit值

  • 返回:0或1或者-1(参数错误)

  • start:开始位,从0开始计算,以Byte为单位

  • index:bit位,从右向左,依次为0-7

    string:0x010304010100b38CCCC

    hb(3,0)=0b0000 0001的第0索引,即1

###2.3 ht(start,length=2)

  • 对象:hex

  • 说明:将十六进制表示的bcd码转换成十进制整数

  • 编码方式:BCD(0x0101=>整数101)

  • 返回:整数或者 -1(参数错误)

  • start:开始位,从0开始计算,以Byte为单位

  • length位:Byte长度

    string:0x010304010100b38CCCC

    ht(6,2)=101

###2.4 hc(start,length=4)

  • 对象:hex

  • 说明:将十六进制表示的ascii码数字转换成浮点数

  • 返回:整数或者 -1(参数错误) -2:数据错误

  • start:开始位,从0开始计算,以Byte为单位

  • length位:Byte长度

    string:0x01030432322E320030372E310000302D31322E3800

    hc(3,6)=32322E320030=22.2

    hc(9,6)=372E31000030=7.1

    hc(15,6)=2D31322E3800=-12.8

3. ASCII公式

###3.1 ap(start,order=1)

  • 对象:ascii

  • 说明:截取电总协议中的字符串,并转换成浮点数

  • 返回:浮点数,-1-输入错误

  • start:开始位,从0开始计算

  • order:1-高位在后 0-高位在前

    string:~10012A0020680133B35A43000....

    ap(15)=ap(15,1)=218.6999...

###3.2 ax(start,length=2,ascii_order=0)

  • 对象:ascii

  • 说明:把字符串作为十六进制字符串,截取并转换成整数

  • 返回:正整数,-1-输入错误

  • start:开始位,从0开始计算

  • length:默认两位字符凑成一个十六进制数字*length

  • order:1-高位在后 0-高位在前

    string:~10012A0020....

    ax(1)=ap(1,2,0)=int(0x1001)=4097

    ax(1,2,1)=int(0x0110)=272

    ax(1,1)=int(0x10)=16

###3.3 ad(start,length)

  • 对象:ascii

  • 说明:将字符串转换成浮点数

  • 返回:浮点数,-1-输入错误,-2-字符串错误或公式错误

  • start:开始位,从0开始计算

  • length:长度

    string=':F0061A0102090463FFFFFF5100080000E30000000000017A014C04971FQ....'

    ad(9,4)=ad('0209')=209.0

    ad13,4)=ad('0463')=463.0

    ad(5,1)=1

    ad(3,1)=0

    string='(208.4 140.0 208.4 034 59.9 2.05 35.0 00110000'

    ad(28,4)=2.05

###3.4 ac(start,length)

  • 对象:ascii

  • 说明:将bcd字符串转换成浮点数

  • 返回:浮点数,-1-输入错误,-2-字符串错误或公式错误

  • start:开始位,从0开始计算

  • length:长度

    string=01A091023131314D5330312E30342E313331302E34322E3436333830333832333832.....

    ac(50,3)='333830'=380

    ac(18,1)='30'=0

    ac(20,1)=‘31’=1

###3.5 ab(start,index)

  • 对象:ascii

  • 说明:将字符串按照十六进制方式,每次取2位转换成布尔值

  • 返回: 0/1,-1-输入参数错误 -2:字符格式错误

  • start:开始位,从0开始计算

  • index:从右至左,从0-7

    string=':F0061A0102090463FFFFFF5100080000E30000000000017A014C04971FQ'

    ab(33,4)='E3'='1110 0011'=0

    ab(33,5)='E3'='1110 0011'=1​

###3.6 av()

  • 对象:ascii

  • 说明:将字符串直接转换成浮点数(支持负数)

  • 返回:浮点数,-2:格式错误

    string='-32.6'

    av()=-32.6

    string='a'

    av()=-2

    string='3'

    av()=3.0

4. 逻辑判断

###4.1 pif(condition, out_true, out_false)

  • 对象:hex/ascii

  • 说明:如果condition为true,返回out_true,否则为out_false

    例如:

    string= 01A091023131314D5330312E30342E313331302E34322E3436333830333832333832323138323139323230303031313030303630303036303030362B303030322B303030312B3030303135302E3035302E303337373337373337343432352B303030303030303230303031303030312A2A2A2E2A2A2A2A2E2A2A2A2A2E2A2B30302E303030393030353030353039393931303003BF

    'pif(ac(50,3)==380,ac(50,3),0)'

    condition=ac(50,3)='333830'=380 true

    所以返回ac(50,3)=380

    否则 返回0

5. 校验

###5.1 crc(hex)

  • 对象:hex
  • 校验方式:crc

###5.2 sum(hex)

  • 对象:hex
  • 校验方式:和(所有非校验字段的十六进制和&&FF)

###5.3 长度(hex)

  • 对象:hex
  • 校验方式:长度计算

###5.4 长度(ascii)

  • 对象:ascii
  • 校验方式:长度计算(max=0,min=0)

###5.5 lrc(ascii)

  • 对象:ascii
  • 校验方式:lrc校验(非校验字节按照十六进制和取反加一)

5.6 sum(ascii)

  • 对象:ascii
  • 校验方式:和校验(非校验字节按照十六进制和)

5.7 pmbus(ascii)

  • 对象:ascii
  • 校验方式:电总(非校验字节按照十六进制和对FFF取反加一)

6. 工具

###6.1 crc计算

  • 对象:hex

###6.2 sum(hex)计算

  • 对象:hex

6.3 lrc计算

  • 对象:ascii

6.4 sum(ascii)计算

  • 对象:ascii

6.5 电总(ascii)计算

  • 对象:ascii

Keywords

FAQs

Last updated on 22 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc