UNPKG

pws-formula

Version:

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

321 lines (200 loc) 7.14 kB
# PWS公式系统设计说明 > **pws_fomular_design_srs** ## 修订记录 | 序号 | 日期 | 作者 | 说明 | | :--: | :--------: | :-------: | ---- | | 1 | 2017-12-21 | thomas.li | 新建文档 | ## 1. **概述** ### 1.1 **文档目的** 定义PWS数据采集系统的返回串计算公式定义及功能 ### 1.2 **项目范围** 本产品主要面向中小型机房客户,为机房的基础设施提供环境数据采集检测服务。 ### 1.3 **术语** | 缩略语 | 别名 | 定义 | | :----: | :-----: | --------------------------------- | | Hex | 十六进制 | 返回串的数据构成方式,例如0x01030401000036C403 | | ascii | ascii码 | 返回串的数据构成方式,例如~132382823434 | | modbus | modbus | 数据通信协议 | | pmbus | 电总协议 | 数据定义协议 | | bcd | 数据格式 | 以16进制表示十进制数,例如0x0326=>326 | | crc | CRC校验算法 | 一种校验算法 | | sum | sum校验算法 | 一种校验算法 | ### 1.4 **相关文档** | 序号 | 文档名 | 文档编号 | | :--: | ----------------------- | ---- | | 1 | pws_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=':F0061A01**02090463**FFFFFF5100080000E30000000000017A014C04971FQ....' > >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=01A091023131314D53**30**312E30342E313331302E34322E3436**333830**333832333832..... > >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=':F0061A0102090463FFFFFF5100080000**E3**0000000000017A014C04971FQ' > >ab(33,4)='E3'='111**0** 0011'=0 > >ab(33,5)='E3'='11**1**0 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