| | |
| | | import uuid |
| | | from enum import Enum |
| | | |
| | | from sqlalchemy.orm import sessionmaker, scoped_session |
| | | |
| | |
| | | "combPkt": 12, |
| | | "const": 15, |
| | | "length": 17, |
| | | "enum": 26, |
| | | "enum": 18, |
| | | "sendFlag": 26, |
| | | "checkSum": 20, |
| | | "insUnit": 4, |
| | | "insUnitList": 11, |
| | | "input": 19, |
| | | "pktSeqCnt": 25, |
| | | "variableLength": 14 |
| | | } |
| | | |
| | | |
| | | class BinaryType(Enum): |
| | | Integer = 0 # 整型 |
| | | Float = 1 # 浮点型 |
| | | Ascii = 2 # ASCII |
| | | |
| | | |
| | | class NumberDataType(Enum): |
| | | Unsigned = 0 # 无符号整型 |
| | | SignInteger = 1 # 有符号整型 |
| | | Phy = 2 # 物理量 |
| | | Bytes = 3 # 多字节码 |
| | | |
| | | |
| | | class InputFormat(Enum): |
| | | Binary = 0 # 二进制 |
| | | Decimal = 1 # 十进制 |
| | | Hex = 2 # 十六进制 |
| | | |
| | | |
| | | class ProcessMethod(Enum): |
| | | Dirct = 0 # 直读 |
| | | Equivalent = 1 # 当量 |
| | | Formula = 2 # 公式 |
| | | Script = 3 # 脚本 |
| | | |
| | | |
| | | class ExpressionType(Enum): |
| | | Count = 0 # 个数计算 |
| | | Formula = 1 # 数值计算 |
| | | |
| | | |
| | | class EnumType(Enum): |
| | | NameValue = 0 # 名值对枚举 |
| | | Range = 1 # 范围枚举 |
| | | Classify = 2 # 多级分类 |
| | | InsCategory = 3 # 指令类别枚举 |
| | | InsUnit = 4 # 指令单元枚举 |
| | | InsFormat = 5 # 指令格式枚举 |
| | | |
| | | |
| | | def make_attr(field: dict): |
| | | """ |
| | | 获取字段定义的ATTR。 |
| | | |
| | | 位掩码,用于标识节点类型。 |
| | | 类型:0~2 BinaryType; |
| | | 3~5 DataType; |
| | | 6~8: InputFormat; |
| | | 9 : IsSubPackage; |
| | | 10: IsSendFlag; |
| | | 11~13: ProcessMethod; |
| | | 14~16: ExpressionType; |
| | | 17~19: EnumType |
| | | |
| | | :param field: 字段信息 |
| | | :return: |
| | | """ |
| | | attr = 0 |
| | | # 即时输入,无符号整数,十进制,直读 |
| | | if field['type'] == ins_ty['input']: |
| | | attr |= (NumberDataType.Unsigned.value << 3) | (InputFormat.Decimal.value << 6) | (ProcessMethod.Dirct.value << 11) |
| | | # 是否是子包 |
| | | attr |= (1 << 9) if field['type']==ins_ty['subPkt'] else 0 |
| | | # 是否是发送标记 |
| | | attr |= (1 << 10) if field['type']==ins_ty['sendFlag'] else 0 |
| | | # 计算类型 |
| | | # 枚举类型 |
| | | |
| | | return attr |
| | | |
| | | def create_ins_format(proj_pk: str, parent_pk: str, info: dict) -> TInsFormat: |
| | | ins_format = TInsFormat( |
| | |
| | | C_CODE=info['code'] if 'code' in info else '', |
| | | C_TYPE=ins_ty[info['type']] if 'type' in info else 0, |
| | | C_DEF=info['def'] if 'def' in info else None, |
| | | C_BIT_WIDTH=info['bitWidth'] if 'bitWidth' in info else 0, |
| | | C_BIT_WIDTH=info['bitWidth'] if 'bitWidth' in info else None, |
| | | C_BIT_ORDER=info['bitOrder'] if 'bitOrder' in info else 0, |
| | | C_ATTR=info['attr'] if 'attr' in info else 0, |
| | | C_RANGE=info['range'] if 'range' in info else None, |