How to use read_cmd method in fMBT

Best Python code snippet using fMBT_python

commands.py

Source:commands.py Github

copy

Full Screen

1#!/usr/bin/env python32# vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab3""" commands for dev pioneer4Most commands send a string (fixed for reading, attached data for writing)5while parsing the response works by extracting the needed string part by6regex. Some commands translate the device data into readable values via7lookups.8"""9models = {10 'ALL': ['general.custom_inputnames', 'general.power', 'general.setupmenu', 'general.soundmode', 'general.inputsignal', 'general.inputrate', 'general.inputformat', 'general.inputresolution', 'general.outputresolution', 'general.ecomode',11 'tuner.tunerpreset', 'tuner.tunerpresetup', 'tuner.tunerpresetdown',12 'zone1.control',13 'zone1.settings.sound.general.audioinput', 'zone1.settings.sound.general.cinema_eq', 'zone1.settings.sound.general.hdmiaudioout', 'zone1.settings.sound.general.dynamicrange', 'zone1.settings.sound.general.subwoofertoggle', 'zone1.settings.sound.general.subwoofer', 'zone1.settings.sound.general.subwooferup', 'zone1.settings.sound.general.subwooferdown', 'zone1.settings.sound.general.lfe', 'zone1.settings.sound.general.lfeup', 'zone1.settings.sound.general.lfedown', 'zone1.settings.sound.tone_control',14 'zone1.settings.sound.channel_level.front_left', 'zone1.settings.sound.channel_level.front_right', 'zone1.settings.sound.channel_level.front_height_left', 'zone1.settings.sound.channel_level.front_height_right', 'zone1.settings.sound.channel_level.front_center', 'zone1.settings.sound.channel_level.surround_left', 'zone1.settings.sound.channel_level.surround_right', 'zone1.settings.sound.channel_level.surroundback_left', 'zone1.settings.sound.channel_level.surroundback_right', 'zone1.settings.sound.channel_level.rear_height_left', 'zone1.settings.sound.channel_level.rear_height_right', 'zone1.settings.sound.channel_level.subwoofer',15 'zone2.control', 'zone2.settings.sound.general.hdmiout'],16 'AVR-X6300H': ['zone1.settings.sound.channel_level.subwoofer2', 'zone1.settings.sound.general.speakersetup', 'zone1.settings.sound.general.dialogenhance',17 'zone1.settings.video',18 'zone2.settings.sound.tone_control', 'zone2.settings.sound.channel_level', 'zone2.settings.sound.general.HPF',19 'zone3'],20 'AVR-X4300H': ['zone1.settings.sound.channel_level.subwoofer2', 'zone1.settings.video', 'zone1.settings.sound.general.dialogtoggle', 'zone1.settings.sound.general.dialog', 'zone1.settings.sound.general.dialogup', 'zone1.settings.sound.general.dialogdown', 'zone1.settings.sound.general.speakersetup',21 'zone2.settings.sound.tone_control', 'zone2.settings.sound.channel_level', 'zone2.settings.sound.general.HPF',22 'zone3'],23 'AVR-X3300W': ['tuner.title', 'tuner.genre', 'tuner.artist', 'general.display',24 'zone1.settings.sound.channel_level.subwoofer2', 'zone1.settings.video.aspectratio', 'zone1.settings.video.hdmiresolution', 'zone1.settings.video.videoresolution', 'zone1.settings.video.videoinput', 'zone1.settings.video.pictureenhancer', 'zone1.settings.video.videoprocessingmode',25 'zone1.settings.sound.general.dialogtoggle', 'zone1.settings.sound.general.dialog', 'zone1.settings.sound.general.dialogup', 'zone1.settings.sound.general.dialogdown', 'zone2.settings.sound.tone_control', 'zone2.settings.sound.channel_level', 'zone2.settings.sound.general.HPF'],26 'AVR-X2300W': ['tuner.title', 'tuner.genre', 'tuner.artist', 'general.display',27 'zone1.settings.video', 'zone1.settings.sound.general.dialogtoggle', 'zone1.settings.sound.general.dialog', 'zone1.settings.sound.general.dialogup', 'zone1.settings.sound.general.dialogdown',28 'zone2.settings.sound.channel_level'],29 'AVR-X1300W': ['tuner.title', 'tuner.genre', 'tuner.artist', 'general.display',30 'zone1.settings.sound.general.dialogtoggle', 'zone1.settings.sound.general.dialog', 'zone1.settings.sound.general.dialogup', 'zone1.settings.sound.general.dialogdown']31}32commands = {33 'general': {34 'custom_inputnames': {'read': True, 'write': False, 'read_cmd': 'SSFUN ?', 'item_type': 'dict', 'dev_datatype': 'str', 'reply_pattern': 'SSFUN(.*)', 'item_attrs': {'initial': True, 'item_template': 'custom_inputnames'}},35 'power': {'read': True, 'write': True, 'read_cmd': 'PW?', 'write_cmd': 'PW{VALUE}', 'item_type': 'bool', 'dev_datatype': 'str', 'reply_pattern': 'PW{LOOKUP}', 'lookup': 'POWER'},36 'setupmenu': {'read': True, 'write': True, 'read_cmd': 'MNMEN?', 'write_cmd': 'MNMEN {VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'MNMEN (ON|OFF)'},37 'display': {'read': True, 'write': False, 'read_cmd': 'NSE', 'item_type': 'str', 'dev_datatype': 'DenonDisplay', 'reply_pattern': 'NSE(.*)'},38 'soundmode': {'read': True, 'write': False, 'read_cmd': 'SSSMG ?', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': r'SSSMG {LOOKUP}', 'lookup': 'SOUNDMODE', 'item_attrs': {'initial': True}},39 'inputsignal': {'read': True, 'write': False, 'read_cmd': 'SSINFAISSIG ?', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': r'SSINFAISSIG {LOOKUP}', 'lookup': 'INPUTSIGNAL', 'item_attrs': {'initial': True}},40 'inputrate': {'read': True, 'write': False, 'read_cmd': 'SSINFAISFSV ?', 'item_type': 'num', 'dev_datatype': 'convert0', 'reply_pattern': r'SSINFAISFSV (\d{2,3}|NON)', 'item_attrs': {'initial': True}},41 'inputformat': {'read': True, 'write': False, 'read_cmd': 'SSINFAISFOR ?', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'SSINFAISFOR (.*)', 'item_attrs': {'initial': True}},42 'inputresolution': {'read': True, 'write': False, 'read_cmd': 'SSINFSIGRES ?', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'SSINFSIGRES I(.*)', 'item_attrs': {'initial': True}},43 'outputresolution': {'read': True, 'write': False, 'read_cmd': 'SSINFSIGRES ?', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'SSINFSIGRES O(.*)', 'item_attrs': {'read_group_levels': 0}},44 'ecomode': {'read': True, 'write': True, 'cmd_settings': {'valid_list_ci': ['ON', 'OFF', 'AUTO']}, 'read_cmd': 'ECO?', 'write_cmd': 'ECO{RAW_VALUE_UPPER}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'ECO{VALID_LIST_CI}'},45 },46 'tuner': {47 'title': {'read': True, 'write': False, 'read_cmd': 'NSE', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'NSE1(.*)', 'item_attrs': {'initial': True}},48 'album': {'read': True, 'write': False, 'read_cmd': 'NSE', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'NSE4(.*)', 'item_attrs': {'read_group_levels': 0}},49 'artist': {'read': True, 'write': False, 'read_cmd': 'NSE', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'NSE2(.*)', 'item_attrs': {'read_group_levels': 0}},50 'tunerpreset': {'read': True, 'write': True, 'read_cmd': 'TPAN?', 'item_type': 'num', 'write_cmd': 'TPAN{RAW_VALUE:02}', 'dev_datatype': 'convert0', 'reply_pattern': r'TPAN(\d{2}|OFF)', 'item_attrs': {'initial': True}},51 'tunerpresetup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'TPANUP', 'dev_datatype': 'raw'},52 'tunerpresetdown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'TPANDOWN', 'dev_datatype': 'raw'},53 },54 'zone1': {55 'control': {56 'power': {'read': True, 'write': True, 'read_cmd': 'ZM?', 'write_cmd': 'ZM{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'ZM(ON|OFF)', 'item_attrs': {'initial': True}},57 'mute': {'read': True, 'write': True, 'read_cmd': 'MU?', 'write_cmd': 'MU{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'MU(ON|OFF)', 'item_attrs': {'initial': True}},58 'volume': {'read': True, 'write': True, 'read_cmd': 'MV?', 'write_cmd': 'MV{VALUE}', 'item_type': 'num', 'dev_datatype': 'DenonVol', 'reply_pattern': r'MV(\d{2,3})', 'cmd_settings': {'force_min': 0.0, 'valid_max': 98.0}, 'item_attrs': {'initial': True}},59 'volumeup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'MVUP', 'dev_datatype': 'raw'},60 'volumedown': {'read': False, 'write': True, 'write_cmd': 'MVDOWN', 'item_type': 'bool', 'dev_datatype': 'raw'},61 'volumemax': {'opcode': '{VALUE}', 'read': True, 'write': False, 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': r'MVMAX (\d{2,3})', 'item_attrs': {'initial': True}},62 'input': {'read': True, 'write': True, 'read_cmd': 'SI?', 'write_cmd': 'SI{VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'SI{LOOKUP}', 'lookup': 'INPUT', 'item_attrs': {'item_template': 'input', 'initial': True}},63 'listeningmode': {'read': True, 'write': True, 'cmd_settings': {'valid_list_ci': ['MOVIE', 'MUSIC', 'GAME', 'DIRECT', 'PURE DIRECT', 'STEREO', 'AUTO', 'DOLBY DIGITAL', 'DTS SURROUND', 'AURO3D', 'AURO2DSURR', 'MCH STEREO', 'ROCK ARENA', 'JAZZ CLUB', 'MONO MOVIE', 'MATRIX', 'VIDEO GAME', 'VIRTUAL', 'LEFT', 'RIGHT']}, 'read_cmd': 'MS?', 'write_cmd': 'MS{RAW_VALUE_UPPER}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'MS{VALID_LIST_CI}', 'item_attrs': {'initial': True}},64 'sleep': {'read': True, 'write': True, 'item_type': 'num', 'read_cmd': 'SLP?', 'write_cmd': 'SLP{VALUE}', 'dev_datatype': 'convert0', 'reply_pattern': r'SLP(\d{3}|OFF)', 'cmd_settings': {'force_min': 0, 'force_max': 120}, 'item_attrs': {'initial': True}},65 'standby': {'read': True, 'write': True, 'item_type': 'num', 'read_cmd': 'STBY?', 'write_cmd': 'STBY{VALUE}', 'dev_datatype': 'DenonStandby1', 'reply_pattern': r'STBY(\d{2}M|OFF)', 'cmd_settings': {'valid_list_ci': [0, 15, 30, 60]}, 'item_attrs': {'initial': True}},66 },67 'settings': {68 'sound': {69 'channel_level': {70 'front_left': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVFL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVFL (\d{2,3})'},71 'front_right': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVFR {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVFR (\d{2,3})'},72 'front_height_left': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVFHL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVFHL (\d{2,3})'},73 'front_height_right': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVFHR {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVFHR (\d{2,3})'},74 'front_center': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVC {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVC (\d{2,3})'},75 'surround_left': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVSL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVSL (\d{2,3})'},76 'surround_right': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVSR {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVSR (\d{2,3})'},77 'surroundback_left': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVSBL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVSBL (\d{2,3})'},78 'surroundback_right': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVSBR {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVSBR (\d{2,3})'},79 'rear_height_left': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVRHL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVRHL (\d{2,3})'},80 'rear_height_right': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVRHR {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVRHR (\d{2,3})'},81 'subwoofer': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVSW {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVSW (\d{2,3})'},82 'subwoofer2': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12.0, 'valid_max': 12.0}, 'read_cmd': 'CV?', 'item_type': 'num', 'write_cmd': 'CVSW2 {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'CVSW2 (\d{2,3})'}83 },84 'tone_control': {85 'tone': {'read': True, 'write': True, 'read_cmd': 'PSTONE CTRL ?', 'write_cmd': 'PSTONE CTRL {VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'PSTONE CTRL (ON|OFF)'},86 'treble': {'read': True, 'write': True, 'read_cmd': 'PSTRE ?', 'item_type': 'num', 'cmd_settings': {'force_min': -6, 'force_max': 6}, 'write_cmd': 'PSTRE {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'PSTRE (\d{2})'},87 'trebleup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSTRE UP', 'dev_datatype': 'raw'},88 'trebledown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSTRE DOWN', 'dev_datatype': 'raw'},89 'bass': {'read': True, 'write': True, 'read_cmd': 'PSBAS ?', 'item_type': 'num', 'cmd_settings': {'force_min': -6, 'force_max': 6}, 'write_cmd': 'PSBAS {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'PSBAS (\d{2})'},90 'bassup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSBAS UP', 'dev_datatype': 'raw'},91 'bassdown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSBAS DOWN', 'dev_datatype': 'raw'}92 },93 'general': {94 'cinema_eq': {'read': True, 'write': True, 'read_cmd': 'PSCINEMA EQ. ?', 'write_cmd': 'PSCINEMA EQ.{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'PSCINEMA EQ.(ON|OFF)'},95 'speakersetup': {'read': True, 'write': True, 'cmd_settings': {'valid_list_ci': ['FL', 'HF']}, 'read_cmd': 'PSSP: ?', 'write_cmd': 'PSSP:{RAW_VALUE_UPPER}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'PSSP:{VALID_LIST_CI}'},96 'hdmiaudioout': {'read': True, 'write': True, 'item_type': 'str', 'read_cmd': 'VSAUDIO ?', 'write_cmd': 'VSAUDIO {RAW_VALUE_UPPER}', 'dev_datatype': 'str', 'reply_pattern': 'VSAUDIO {VALID_LIST_CI}', 'cmd_settings': {'valid_list_ci': ['TV', 'AMP']}},97 'dynamicrange': {'read': True, 'write': True, 'read_cmd': 'PSDRC ?', 'item_type': 'num', 'write_cmd': 'PSDRC {VALUE}', 'dev_datatype': 'str', 'reply_pattern': 'PSDRC {LOOKUP}', 'lookup': 'DYNAM'},98 'dialogtoggle': {'read': True, 'write': True, 'read_cmd': 'PSDIL ?', 'write_cmd': 'PSDIL {VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'PSDIL (ON|OFF)'},99 'dialog': {'read': True, 'write': True, 'read_cmd': 'PSDIL ?', 'item_type': 'num', 'cmd_settings': {'force_min': -12, 'force_max': 12}, 'write_cmd': 'PSDIL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'PSDIL (\d{2})'},100 'dialogup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSDIL UP', 'dev_datatype': 'raw'},101 'dialogdown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSDIL DOWN', 'dev_datatype': 'raw'},102 'dialogenhance': {'read': True, 'write': True, 'read_cmd': 'PSDEH ?', 'write_cmd': 'PSDEH {VALUE}', 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': 'PSDEH {LOOKUP}', 'lookup': 'DIALOG'},103 'subwoofertoggle': {'read': True, 'write': True, 'read_cmd': 'PSSWL ?', 'write_cmd': 'PSSWL {VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'PSSWL (ON|OFF)'},104 'subwoofer': {'read': True, 'write': True, 'read_cmd': 'PSSWL ?', 'item_type': 'num', 'cmd_settings': {'force_min': -12, 'valid_max': 12}, 'write_cmd': 'PSSWL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'PSSWL (\d{2})'},105 'subwooferup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSSWL UP', 'dev_datatype': 'raw'},106 'subwooferdown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSSWL DOWN', 'dev_datatype': 'raw'},107 'lfe': {'read': True, 'write': True, 'read_cmd': 'PSLFE ?', 'item_type': 'num', 'cmd_settings': {'force_min': -10, 'valid_max': 3}, 'write_cmd': 'PSLFE {RAW_VALUE:02}', 'dev_datatype': 'int', 'reply_pattern': r'PSLFE (\d{2})'},108 'lfeup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSLFE UP', 'dev_datatype': 'raw'},109 'lfedown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'PSLFE DOWN', 'dev_datatype': 'raw'},110 'audioinput': {'read': True, 'write': True, 'cmd_settings': {'valid_list_ci': ['AUTO', 'HDMI', 'DIGITAL', 'ANALOG']}, 'read_cmd': 'SD?', 'write_cmd': 'SD{RAW_VALUE_UPPER}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'SD{VALID_LIST_CI}'}111 }112 },113 'video': {114 'aspectratio': {'read': True, 'write': True, 'read_cmd': 'VSASP ?', 'write_cmd': 'VSASP{VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'VSASP{LOOKUP}', 'lookup': 'ASPECT'},115 'hdmimonitor': {'read': True, 'write': True, 'cmd_settings': {'force_min': 0, 'force_max': 2}, 'read_cmd': 'VSMONI ?', 'write_cmd': 'VSMONI{VALUE}', 'item_type': 'num', 'dev_datatype': 'convertAuto', 'reply_pattern': 'VSMONI(AUTO|1|2)'},116 'hdmiresolution': {'read': True, 'write': True, 'read_cmd': 'VSSCH ?', 'write_cmd': 'VSSCH{VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'VSSCH{LOOKUP}', 'lookup': 'RESOLUTION'},117 'videoprocessingmode': {'read': True, 'write': True, 'item_type': 'str', 'read_cmd': 'VSVPM ?', 'write_cmd': 'VSVPM{VALUE}', 'dev_datatype': 'str', 'reply_pattern': 'VSVPM{LOOKUP}', 'lookup': 'VIDEOPROCESS'},118 'videoresolution': {'read': True, 'write': True, 'read_cmd': 'VSSC ?', 'write_cmd': 'VSSC{VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'VSSC{LOOKUP}', 'lookup': 'RESOLUTION'},119 'pictureenhancer': {'read': True, 'write': True, 'read_cmd': 'PVENH ?', 'item_type': 'num', 'cmd_settings': {'force_min': 0, 'force_max': 12}, 'write_cmd': 'PVENH {RAW_VALUE:02}', 'dev_datatype': 'int', 'reply_pattern': r'PVENH (\d{2})'},120 'videoinput': {'read': True, 'write': True, 'cmd_settings': {'valid_list_ci': ['DVD', 'BD', 'TV', 'SAT/CBL', 'MPLAY', 'GAME' 'AUX1', 'AUX2', 'CD', 'ON', 'OFF']}, 'read_cmd': 'SV?', 'write_cmd': 'SV{RAW_VALUE_UPPER}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'SV{VALID_LIST_CI}'}121 }122 }123 },124 'zone2': {125 'control': {126 'power': {'read': True, 'write': True, 'read_cmd': 'Z2?', 'write_cmd': 'Z2{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'Z2(ON|OFF)'},127 'mute': {'read': True, 'write': True, 'read_cmd': 'Z2MU?', 'write_cmd': 'Z2MU{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'Z2MU(ON|OFF)'},128 'volume': {'read': True, 'write': True, 'read_cmd': 'Z2?', 'write_cmd': 'Z2{VALUE}', 'item_type': 'num', 'dev_datatype': 'DenonVol', 'reply_pattern': r'Z2(\d{2,3})', 'cmd_settings': {'force_min': 0.0, 'valid_max': 98.0}},129 'volumeup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z2UP', 'dev_datatype': 'raw'},130 'volumedown': {'read': False, 'write': True, 'write_cmd': 'Z2DOWN', 'item_type': 'bool', 'dev_datatype': 'raw'},131 'input': {'read': True, 'write': True, 'read_cmd': 'Z2?', 'write_cmd': 'Z2{VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'Z2{LOOKUP}', 'lookup': 'INPUT', 'item_attrs': {'item_template': 'input'}},132 'sleep': {'read': True, 'write': True, 'item_type': 'num', 'read_cmd': 'Z2SLP?', 'write_cmd': 'Z2SLP{VALUE}', 'dev_datatype': 'convert0', 'reply_pattern': r'Z2SLP(\d{3}|OFF)', 'cmd_settings': {'force_min': 0, 'force_max': 120}},133 'standby': {'read': True, 'write': True, 'item_type': 'num', 'read_cmd': 'Z2STBY?', 'write_cmd': 'Z2STBY{VALUE}', 'dev_datatype': 'DenonStandby', 'reply_pattern': r'Z2STBY(\dH|OFF)', 'cmd_settings': {'valid_list_ci': [0, 2, 4, 8]}},134 },135 'settings': {136 'sound': {137 'channel_level': {138 'front_left': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12, 'valid_max': 12}, 'read_cmd': 'Z2CV?', 'item_type': 'num', 'write_cmd': 'Z2CVFL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z2CVFL (\d{2})'},139 'front_right': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12, 'valid_max': 12}, 'read_cmd': 'Z2CV?', 'item_type': 'num', 'write_cmd': 'Z2CVFR {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z2CVFR (\d{2})'}140 },141 'tone_control': {142 'treble': {'read': True, 'write': True, 'read_cmd': 'Z2PSTRE ?', 'item_type': 'num', 'cmd_settings': {'force_min': -10, 'force_max': 10}, 'write_cmd': 'Z2PSTRE {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z2PSTRE (\d{2})'},143 'trebleup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z2PSTRE UP', 'dev_datatype': 'raw'},144 'trebledown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z2PSTRE DOWN', 'dev_datatype': 'raw'},145 'bass': {'read': True, 'write': True, 'read_cmd': 'Z2PSBAS ?', 'item_type': 'num', 'cmd_settings': {'force_min': -10, 'force_max': 10}, 'write_cmd': 'Z2PSBAS {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z2PSBAS (\d{2})'},146 'bassup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z2PSBAS UP', 'dev_datatype': 'raw'},147 'bassdown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z2PSBAS DOWN', 'dev_datatype': 'raw'}148 },149 'general': {150 'hdmiout': {'read': True, 'write': True, 'item_type': 'str', 'read_cmd': 'Z2HDA?', 'write_cmd': 'Z2HDA {RAW_VALUE_UPPER}', 'dev_datatype': 'str', 'reply_pattern': 'Z2HDA {VALID_LIST_CI}', 'cmd_settings': {'valid_list_ci': ['THR', 'PCM']}},151 'HPF': {'read': True, 'write': True, 'read_cmd': 'Z2HPF?', 'write_cmd': 'Z2HPF{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'Z2HPF(ON|OFF)'}152 }153 }154 }155 },156 'zone3': {157 'control': {158 'power': {'read': True, 'write': True, 'read_cmd': 'Z3?', 'write_cmd': 'Z3{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'Z3(ON|OFF)'},159 'mute': {'read': True, 'write': True, 'read_cmd': 'Z3MU?', 'write_cmd': 'Z3MU{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'Z3MU(ON|OFF)'},160 'volume': {'read': True, 'write': True, 'read_cmd': 'Z3?', 'item_type': 'num', 'dev_datatype': 'DenonVol', 'reply_pattern': r'Z3(\d{2,3})', 'cmd_settings': {'force_min': 0.0, 'valid_max': 98.0}},161 'volumeup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z3UP', 'dev_datatype': 'raw'},162 'volumedown': {'read': False, 'write': True, 'write_cmd': 'Z3DOWN', 'item_type': 'bool', 'dev_datatype': 'raw'},163 'sleep': {'read': True, 'write': True, 'item_type': 'num', 'read_cmd': 'Z3SLP?', 'write_cmd': 'Z3SLP{VALUE}', 'dev_datatype': 'convert0', 'reply_pattern': r'Z3SLP(\d{3}|OFF)', 'cmd_settings': {'force_min': 0, 'valid_max': 120}},164 'standby': {'read': True, 'write': True, 'item_type': 'num', 'read_cmd': 'Z3STBY?', 'write_cmd': 'Z3STBY{VALUE}', 'dev_datatype': 'DenonStandby', 'reply_pattern': r'Z3STBY(\dH|OFF)', 'cmd_settings': {'valid_list_ci': [0, 2, 4, 8]}},165 'input': {'read': True, 'write': True, 'read_cmd': 'Z3?', 'write_cmd': 'Z3{RAW_VALUE_UPPER}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': 'Z3{LOOKUP}', 'lookup': 'INPUT3', 'item_attrs': {'item_template': 'input'}}166 },167 'settings': {168 'sound': {169 'channel_level': {170 'front_left': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12, 'valid_max': 12}, 'read_cmd': 'Z3CV?', 'item_type': 'num', 'write_cmd': 'Z3CVFL {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z3CVFL (\d{2})'},171 'front_right': {'read': True, 'write': True, 'cmd_settings': {'force_min': -12, 'valid_max': 12}, 'read_cmd': 'Z3CV?', 'item_type': 'num', 'write_cmd': 'Z3CVFR {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z3CVFR (\d{2})'}172 },173 'tone_control': {174 'treble': {'read': True, 'write': True, 'read_cmd': 'Z3PSTRE ?', 'item_type': 'num', 'cmd_settings': {'force_min': -10, 'force_max': 10}, 'write_cmd': 'Z3PSTRE {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z3PSTRE (\d{2})'},175 'trebleup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z3PSTRE UP', 'dev_datatype': 'raw'},176 'trebledown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z3PSTRE DOWN', 'dev_datatype': 'raw'},177 'bass': {'read': True, 'write': True, 'read_cmd': 'Z3PSBAS ?', 'item_type': 'num', 'cmd_settings': {'force_min': -10, 'force_max': 10}, 'write_cmd': 'Z3PSBAS {VALUE}', 'dev_datatype': 'remap50to0', 'reply_pattern': r'Z3PSBAS (\d{2})'},178 'bassup': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z3PSBAS UP', 'dev_datatype': 'raw'},179 'bassdown': {'read': False, 'write': True, 'item_type': 'bool', 'write_cmd': 'Z3PSBAS DOWN', 'dev_datatype': 'raw'}180 },181 'general': {182 'HPF': {'read': True, 'write': True, 'read_cmd': 'Z3HPF?', 'write_cmd': 'Z3HPF{VALUE}', 'item_type': 'bool', 'dev_datatype': 'onoff', 'reply_pattern': 'Z3HPF(ON|OFF)'},183 }184 }185 }186 }187}188lookups = {189 'ALL': {190 'INPUTSIGNAL': {191 '01': 'Analog',192 '02': 'PCM',193 '03': 'Dolby Digital',194 '04': 'Dolby TrueHD',195 '05': 'Dolby Atmos',196 '06': 'DTS',197 '07': '07',198 '08': 'DTS-HD Hi Res',199 '09': 'DTS-HD MSTR',200 '10': '10',201 '11': '11',202 '12': 'Unknown',203 '13': 'PCM Zero',204 '14': '14',205 '15': 'MP3',206 '16': '16',207 '17': 'AAC',208 '18': 'FLAC',209 },210 'RESOLUTION': {211 '48P': '480p/576p',212 '10I': '1080i',213 '72P': '720p',214 '10P': '1080p',215 '10P24': '1080p:24Hz',216 '4K': '4K',217 '4KF': '4K(60/50)',218 'AUTO': 'Auto'219 },220 'ASPECT': {221 'NRM': '4:3',222 'FUL': '16:9'223 },224 'POWER': {225 'ON': True,226 'STANDBY': False227 },228 'SOUNDMODE': {229 'MUS': 'MUSIC',230 'MOV': 'MOVIE',231 'GAM': 'GAME',232 'PUR': 'PURE DIRECT'233 },234 'DYNAM': {235 'OFF': 0,236 'LOW': 1,237 'MID': 2,238 'HI': 3,239 'AUTO': 4240 },241 'DIALOG': {242 'OFF': 0,243 'LOW': 1,244 'MED': 2,245 'HIGH': 3,246 'AUTO': 4247 },248 'VIDEOPROCESS': {249 'MOVI': 'Movie',250 'BYP': 'Bypass',251 'GAME': 'Game',252 'AUTO': 'Auto'253 },254 'INPUT': {255 'SOURCE': 'SOURCE',256 'TUNER': 'TUNER',257 'DVD': 'DVD',258 'BD': 'BD',259 'TV': 'TV',260 'SAT/CBL': 'SAT/CBL',261 'MPLAY': 'MPLAY',262 'GAME': 'GAME',263 'HDRADIO': 'HDRADIO',264 'NET': 'NET',265 'AUX1': 'AUX1',266 'BT': 'BT'267 },268 'INPUT3': {269 'SOURCE': 'SOURCE',270 'TUNER': 'TUNER',271 'PHONO': 'PHONO',272 'CD': 'CD',273 'DVD': 'DVD',274 'BD': 'BD',275 'TV': 'TV',276 'SAT/CBL': 'SAT/CBL',277 'MPLAY': 'MPLAY',278 'GAME': 'GAME',279 'NET': 'NET',280 'AUX1': 'AUX1',281 'AUX2': 'AUX2',282 'BT': 'BT',283 'QUICK1': 'QUICK1',284 'QUICK2': 'QUICK2',285 'QUICK3': 'QUICK3',286 'QUICK4': 'QUICK4',287 'QUICK5': 'QUICK5',288 'QUICK1 MEMORY': 'QUICK1 MEMORY',289 'QUICK2 MEMORY': 'QUICK2 MEMORY',290 'QUICK3 MEMORY': 'QUICK3 MEMORY',291 'QUICK4 MEMORY': 'QUICK4 MEMORY',292 'QUICK5 MEMORY': 'QUICK5 MEMORY'293 }294 },295 'AVR-X6300H': {296 'INPUT': {297 'PHONO': 'PHONO',298 'CD': 'CD',299 'AUX2': 'AUX2'300 }301 },302 'AVR-X4300H': {303 'INPUT': {304 'PHONO': 'PHONO',305 'CD': 'CD',306 'AUX2': 'AUX2'307 }308 },309 'AVR-X3300W': {310 'INPUT': {311 'CD': 'CD',312 'AUX2': 'AUX2',313 'IRADIO': 'IRADIO',314 'SERVER': 'SERVER',315 'FAVORITES': 'FAVORITES',316 'USB/IPOD': 'USB/IPOD',317 'USB': 'USB',318 'IPD': 'IPD',319 'IRP': 'IRP',320 'FVP': 'FVP'321 }322 },323 'AVR-X2300W': {324 'INPUT': {325 'CD': 'CD',326 'AUX2': 'AUX2',327 'IRADIO': 'IRADIO',328 'SERVER': 'SERVER',329 'FAVORITES': 'FAVORITES',330 'USB/IPOD': 'USB/IPOD',331 'USB': 'USB',332 'IPD': 'IPD',333 'IRP': 'IRP',334 'FVP': 'FVP'335 }336 },337 'AVR-X1300W': {338 'INPUT': {339 'IRADIO': 'IRADIO',340 'SERVER': 'SERVER',341 'FAVORITES': 'FAVORITES',342 'USB/IPOD': 'USB/IPOD',343 'USB': 'USB',344 'IPD': 'IPD',345 'IRP': 'IRP',346 'FVP': 'FVP'347 }348 }349}350item_templates = {351 'custom_inputnames': {352 'cache': True,353 'reverse': {354 'type': 'dict',355 'eval': '"{v: k for (k, v) in sh...().items()}"',356 'update': {357 'type': 'bool',358 'eval': 'sh...timer(2, {})',359 'eval_trigger': '...'360 }361 }362 },363 'input': {364 'on_change': '.custom_name = sh...custom_inputnames()[value]',365 'custom_name': {366 'type': 'str',367 'on_change': '.. = sh....custom_inputnames.reverse()[value]'368 }369 }...

Full Screen

Full Screen

function.py

Source:function.py Github

copy

Full Screen

1# encoding='utf-8'2try:3 import os, sys, pytest, allure, time4except Exception as err:5 print('导入CPython内置函数库失败!错误信息如下:')6 print(err)7 sys.exit(0) # 避免程序继续运行造成的异常崩溃,友好退出程序8base_path = os.path.dirname(os.path.abspath(__file__)) # 获取当前项目文件夹9base_path = base_path.replace('\\', '/')10sys.path.insert(0, base_path) # 将当前目录添加到系统环境变量,方便下面导入版本配置等文件11try:12 from case_selabel_cipso_value import index13except Exception as err:14 print(15 '导入基础函数库失败!请检查相关文件是否存在.\n文件位于: ' + str(base_path) + '/common/ 目录下.\n分别为:pcap.py rabbitmq.py ssh.py\n错误信息如下:')16 print(err)17 sys.exit(0) # 避免程序继续运行造成的异常崩溃,友好退出程序18else:19 del sys.path[0] # 及时删除导入的环境变量,避免重复导入造成的异常错误20# import index21# del sys.path[0]22# dir_dir_path=os.path.abspath(os.path.join(os.getcwd()))23sys.path.append(os.getcwd())24# del sys.path[0]25# del sys.path[0]26from common import baseinfo27from common import clr_env28from common import fun29pcap_sip = baseinfo.clientOpeIp30pcap_dip = baseinfo.serverOpeIp31class Test_selabel_cipso_value():32 def setup_method(self):33 clr_env.clear_met_acl()34 def teardown_method(self):35 clr_env.clear_met_acl()36 fun.pid_kill(self.cap_pcap1, 'python', 's')37 fun.pid_kill(self.cap_pcap2, 'python', 's')38 fun.pid_kill(self.cap_pcap3, 'python', 's')39 fun.pid_kill(self.cap_pcap4, 'python', 's')40 fun.pid_kill(self.cap_pcap5, 'python', 's')41 fun.pid_kill(self.cap_pcap6, 'python', 's')42 fun.pid_kill(self.cap_pcap7, 'python', 's')43 fun.pid_kill(self.cap_pcap8, 'python', 's')44 def setup_class(self):45 # 获取参数46 fun.ssh_gw.connect()47 fun.ssh_c.connect()48 fun.ssh_s.connect()49 self.clr_env = clr_env.clear_env50 # self.pre_env=index.pre_env51 self.case1_step = index.case1_step52 self.case2_step = index.case2_step53 self.case3_step = index.case3_step54 self.case4_step = index.case4_step55 self.case5_step = index.case5_step56 self.case6_step = index.case6_step57 self.case7_step = index.case7_step58 self.case8_step = index.case8_step59 self.pkt1_cfg = index.pkt1_cfg60 self.pkt2_cfg = index.pkt2_cfg61 self.pkt3_cfg = index.pkt3_cfg62 self.pkt4_cfg = index.pkt4_cfg63 self.pkt5_cfg = index.pkt5_cfg64 self.pkt6_cfg = index.pkt6_cfg65 self.pkt7_cfg = index.pkt7_cfg66 self.pkt8_cfg = index.pkt8_cfg67 self.cap_pcap1 = self.pkt1_cfg["capture"][3]68 self.cap_pcap2 = self.pkt2_cfg["capture"][3]69 self.cap_pcap3 = self.pkt3_cfg["capture"][3]70 self.cap_pcap4 = self.pkt4_cfg["capture"][3]71 self.cap_pcap5 = self.pkt5_cfg["capture"][3]72 self.cap_pcap6 = self.pkt6_cfg["capture"][3]73 self.cap_pcap7 = self.pkt7_cfg["capture"][3]74 self.cap_pcap8 = self.pkt8_cfg["capture"][3]75 self.read_1 = self.pkt1_cfg["read"][0]76 self.read_2 = self.pkt2_cfg["read"][0]77 self.read_3 = self.pkt3_cfg["read"][0]78 self.read_4 = self.pkt4_cfg["read"][0]79 self.read_5 = self.pkt5_cfg["read"][0]80 self.read_6 = self.pkt6_cfg["read"][0]81 self.read_7 = self.pkt7_cfg["read"][0]82 self.read_8 = self.pkt8_cfg["read"][0]83 clr_env.clear_env()84 # @pytest.mark.skip(reseason="skip")85 @allure.feature('验证value(即协议字段category)的右边界')86 def test_selabel_category_cipso_value_right(self):87 # 下发配置并检查结果88 for key in self.case1_step:89 fun.cmd(self.case1_step[key][0], 'gw')90 re = fun.cmd(self.case1_step[key][1], 'gw')91 assert self.case1_step[key][2] in re92 # 服务端抓取报文93 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt1_cfg['capture'][0], self.pkt1_cfg['capture'][1], \94 self.pkt1_cfg['capture'][2], self.pkt1_cfg['capture'][3]95 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)96 print('pre_cfg:', pre_cfg)97 fun.cmd(pre_cfg, 's', thread=1)98 print('step wait')99 time.sleep(20)100 # 发送报文101 c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg["send"][1], self.pkt1_cfg["send"][2]102 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)103 print('send_cmd:', send_cmd)104 fun.cmd(send_cmd, 'c')105 # 检查报文是否存在106 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt1_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')107 pcap_file = fun.search('/opt/pkt', 'pcap', 's')108 assert cap_pcap in pcap_file109 print('服务端抓到报文:{}'.format(self.read_1))110 # 读包111 read_name, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1]112 read_cmd = fun.pkt_read(read_name, read_id)113 print('read_cmd:', read_cmd)114 read_re = fun.cmd(read_cmd, 's')115 print('read_re:', read_re)116 # 获取期望结果117 exp = self.pkt1_cfg["expect"][0]118 assert exp == read_re119 # @pytest.mark.skip(reseason="skip")120 @allure.feature('验证value(即协议字段category)的左边界')121 def test_selabel_category_cipso_value_left(self):122 # 下发配置并检查结果123 for key in self.case2_step:124 fun.cmd(self.case2_step[key][0], 'gw')125 re = fun.cmd(self.case2_step[key][1], 'gw')126 assert self.case2_step[key][2] in re127 # 服务端抓取报文128 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt2_cfg['capture'][0], self.pkt2_cfg['capture'][1], \129 self.pkt2_cfg['capture'][2], self.pkt2_cfg['capture'][3]130 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)131 print('pre_cfg:', pre_cfg)132 fun.cmd(pre_cfg, 's', thread=1)133 print('step wait')134 time.sleep(20)135 # 发送报文136 c_iface, c_num, c_pcap = self.pkt2_cfg["send"][0], self.pkt2_cfg["send"][1], self.pkt2_cfg["send"][2]137 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)138 print('send_cmd:', send_cmd)139 fun.cmd(send_cmd, 'c')140 # 检查报文是否存在141 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt2_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')142 pcap_file = fun.search('/opt/pkt', 'pcap', 's')143 assert cap_pcap in pcap_file144 print('服务端抓到报文:{}'.format(self.read_2))145 # 读包146 read_name, read_id = self.pkt2_cfg["read"][0], self.pkt2_cfg["read"][1]147 read_cmd = fun.pkt_read(read_name, read_id)148 print('read_cmd', read_cmd)149 read_re = fun.cmd(read_cmd, 's')150 print('read_re:', read_re)151 # 获取期望结果152 exp = self.pkt2_cfg["expect"][0]153 assert exp == read_re154 # @pytest.mark.skip(reseason="skip")155 @allure.feature('验证value(即协议字段category范围为64-191)')156 def test_selabel_category_cipso_value_range1(self):157 # 下发配置并检查结果158 for key in self.case3_step:159 fun.cmd(self.case3_step[key][0], 'gw')160 re = fun.cmd(self.case3_step[key][1], 'gw')161 assert self.case3_step[key][2] in re162 # 服务端抓取报文163 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt3_cfg['capture'][0], self.pkt3_cfg['capture'][1], \164 self.pkt3_cfg['capture'][2], self.pkt3_cfg['capture'][3]165 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)166 print('cfg_cmd:', pre_cfg)167 fun.cmd(pre_cfg, 's', thread=1)168 print('step wait')169 time.sleep(20)170 # 发送报文171 c_iface, c_num, c_pcap = self.pkt3_cfg["send"][0], self.pkt3_cfg["send"][1], self.pkt3_cfg["send"][2]172 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)173 print('send_cmd:', send_cmd)174 fun.cmd(send_cmd, 'c')175 # 检查报文是否存在176 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt3_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')177 pcap_file = fun.search('/opt/pkt', 'pcap', 's')178 assert cap_pcap in pcap_file179 print('服务端抓到报文:{}'.format(self.read_3))180 # 读包181 read_name, read_id = self.pkt3_cfg["read"][0], self.pkt3_cfg["read"][1]182 read_cmd = fun.pkt_read(read_name, read_id)183 print('read_cmd:', read_cmd)184 read_re = fun.cmd(read_cmd, 's')185 print('read_re:', read_re)186 # 获取期望结果187 exp = self.pkt3_cfg["expect"][0]188 assert exp == read_re189 # @pytest.mark.skip(reseason="skip")190 @allure.feature('验证value(即协议字段category范围为64-127,192-239)')191 def test_selabel_category_cipso_value_range2(self):192 # 下发配置并检查结果193 for key in self.case4_step:194 fun.cmd(self.case4_step[key][0], 'gw')195 re = fun.cmd(self.case4_step[key][1], 'gw')196 assert self.case4_step[key][2] in re197 # 服务端抓取报文198 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt4_cfg['capture'][0], self.pkt4_cfg['capture'][1], \199 self.pkt4_cfg['capture'][2], self.pkt4_cfg['capture'][3]200 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)201 print('cfg_cmd:', pre_cfg)202 fun.cmd(pre_cfg, 's', thread=1)203 print('step wait')204 time.sleep(20)205 # 发送报文206 c_iface, c_num, c_pcap = self.pkt4_cfg["send"][0], self.pkt4_cfg["send"][1], self.pkt4_cfg["send"][2]207 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)208 print('send_cmd:', send_cmd)209 fun.cmd(send_cmd, 'c')210 # 检查报文是否存在211 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt4_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')212 pcap_file = fun.search('/opt/pkt', 'pcap', 's')213 assert cap_pcap in pcap_file214 print('服务端抓到报文:{}'.format(self.read_4))215 # 读包216 read_name, read_id = self.pkt4_cfg["read"][0], self.pkt4_cfg["read"][1]217 read_cmd = fun.pkt_read(read_name, read_id)218 print('read_cmd:', read_cmd)219 read_re = fun.cmd(read_cmd, 's')220 print('read_re:', read_re)221 # 获取期望结果222 exp = self.pkt4_cfg["expect"][0]223 assert exp == read_re224 # @pytest.mark.skip(reseason="skip")225 @allure.feature('验证value(即协议字段category范围为0-31,67,128-143,192,193)')226 def test_selabel_category_cipso_value_range3(self):227 # 下发配置并检查结果228 for key in self.case5_step:229 fun.cmd(self.case5_step[key][0], 'gw')230 re = fun.cmd(self.case5_step[key][1], 'gw')231 assert self.case5_step[key][2] in re232 # 服务端抓取报文233 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt5_cfg['capture'][0], self.pkt5_cfg['capture'][1], \234 self.pkt5_cfg['capture'][2], self.pkt5_cfg['capture'][3]235 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)236 print('cfg_cmd:', pre_cfg)237 fun.cmd(pre_cfg, 's', thread=1)238 print('step wait')239 time.sleep(20)240 # 发送报文241 c_iface, c_num, c_pcap = self.pkt5_cfg["send"][0], self.pkt5_cfg["send"][1], self.pkt5_cfg["send"][2]242 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)243 print('send_cmd:', send_cmd)244 fun.cmd(send_cmd, 'c')245 # 检查报文是否存在246 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt5_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')247 pcap_file = fun.search('/opt/pkt', 'pcap', 's')248 assert cap_pcap in pcap_file249 print('服务端抓到报文:{}'.format(self.read_5))250 # 读包251 read_name, read_id = self.pkt5_cfg["read"][0], self.pkt5_cfg["read"][1]252 read_cmd = fun.pkt_read(read_name, read_id)253 print('read_cmd:', read_cmd)254 read_re = fun.cmd(read_cmd, 's')255 print('read_re:', read_re)256 # 获取期望结果257 exp = self.pkt5_cfg["expect"][0]258 assert exp == read_re259 # @pytest.mark.skip(reseason="skip")260 @allure.feature('验证value(即协议字段category范围为0 2 67 128 129 192 193 194 195 196 197 198 199)')261 def test_selabel_category_cipso_value_range4(self):262 # 下发配置并检查结果263 for key in self.case6_step:264 fun.cmd(self.case6_step[key][0], 'gw')265 re = fun.cmd(self.case6_step[key][1], 'gw')266 assert self.case6_step[key][2] in re267 # 服务端抓取报文268 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt6_cfg['capture'][0], self.pkt6_cfg['capture'][1], \269 self.pkt6_cfg['capture'][2], self.pkt6_cfg['capture'][3]270 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)271 print('cfg_cmd:', pre_cfg)272 fun.cmd(pre_cfg, 's', thread=1)273 print('step wait')274 time.sleep(20)275 # 发送报文276 c_iface, c_num, c_pcap = self.pkt6_cfg["send"][0], self.pkt6_cfg["send"][1], self.pkt6_cfg["send"][2]277 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)278 print('send_cmd:', send_cmd)279 fun.cmd(send_cmd, 'c')280 # 检查报文是否存在281 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt6_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')282 pcap_file = fun.search('/opt/pkt', 'pcap', 's')283 assert cap_pcap in pcap_file284 print('服务端抓到报文:{}'.format(self.read_6))285 # 读包286 read_name, read_id = self.pkt6_cfg["read"][0], self.pkt6_cfg["read"][1]287 read_cmd = fun.pkt_read(read_name, read_id)288 print('read_cmd:', read_cmd)289 read_re = fun.cmd(read_cmd, 's')290 print('read_re:', read_re)291 # 获取期望结果292 exp = self.pkt6_cfg["expect"][0]293 assert exp == read_re294 # @pytest.mark.skip(reseason="skip")295 @allure.feature('验证value(即协议字段category范围为0-191)')296 def test_selabel_category_cipso_value_range5(self):297 # 下发配置并检查结果298 for key in self.case7_step:299 fun.cmd(self.case7_step[key][0], 'gw')300 re = fun.cmd(self.case7_step[key][1], 'gw')301 assert self.case7_step[key][2] in re302 # 服务端抓取报文303 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt7_cfg['capture'][0], self.pkt7_cfg['capture'][1], \304 self.pkt7_cfg['capture'][2], self.pkt7_cfg['capture'][3]305 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)306 print('cfg_cmd:', pre_cfg)307 fun.cmd(pre_cfg, 's', thread=1)308 print('step wait')309 time.sleep(20)310 # 发送报文311 c_iface, c_num, c_pcap = self.pkt7_cfg["send"][0], self.pkt7_cfg["send"][1], self.pkt7_cfg["send"][2]312 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)313 print('send_cmd:', send_cmd)314 fun.cmd(send_cmd, 'c')315 # 检查报文是否存在316 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt7_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')317 pcap_file = fun.search('/opt/pkt', 'pcap', 's')318 assert cap_pcap in pcap_file319 print('服务端抓到报文:{}'.format(self.read_7))320 # 读包321 read_name, read_id = self.pkt7_cfg["read"][0], self.pkt7_cfg["read"][1]322 read_cmd = fun.pkt_read(read_name, read_id)323 print('read_cmd:', read_cmd)324 read_re = fun.cmd(read_cmd, 's')325 print('read_re:', read_re)326 # 获取期望结果327 exp = self.pkt7_cfg["expect"][0]328 assert exp == read_re329 # @pytest.mark.skip(reseason="skip")330 @allure.feature('验证value(即协议字段category范围为192-239)')331 def test_selabel_category_cipso_value_range6(self):332 # 下发配置并检查结果333 for key in self.case8_step:334 fun.cmd(self.case8_step[key][0], 'gw')335 re = fun.cmd(self.case8_step[key][1], 'gw')336 assert self.case8_step[key][2] in re337 # 服务端抓取报文338 cap_iface, cap_filter, cap_num, cap_pcap = self.pkt8_cfg['capture'][0], self.pkt8_cfg['capture'][1], \339 self.pkt8_cfg['capture'][2], self.pkt8_cfg['capture'][3]340 pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)341 print('cfg_cmd:', pre_cfg)342 fun.cmd(pre_cfg, 's', thread=1)343 print('step wait')344 time.sleep(20)345 # 发送报文346 c_iface, c_num, c_pcap = self.pkt8_cfg["send"][0], self.pkt8_cfg["send"][1], self.pkt8_cfg["send"][2]347 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)348 print('send_cmd:', send_cmd)349 fun.cmd(send_cmd, 'c')350 # 检查报文是否存在351 # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt8_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')352 pcap_file = fun.search('/opt/pkt', 'pcap', 's')353 assert cap_pcap in pcap_file354 print('服务端抓到报文:{}'.format(self.read_8))355 # 读包356 read_name, read_id = self.pkt8_cfg["read"][0], self.pkt8_cfg["read"][1]357 read_cmd = fun.pkt_read(read_name, read_id)358 print('read_cmd:', read_cmd)359 read_re = fun.cmd(read_cmd, 's')360 print('read_re:', read_re)361 # 获取期望结果362 exp = self.pkt8_cfg["expect"][0]363 assert exp == read_re364 def teardown_class(self):365 # 回收环境366 clr_env.clear_env()367 fun.ssh_gw.close()368 fun.ssh_c.close()...

Full Screen

Full Screen

core.py

Source:core.py Github

copy

Full Screen

...39 ans = ans.decode()40 ans = ans.strip('\r\n')41 if ans.lower() != 'ok':42 raise Exception('Error: {}'.format(ans))43 def read_cmd(self, cmd):44 MULTILINE_CMDS = ["HELP", "INFO"]45 data = '?{}\r'.format(cmd)46 if cmd in MULTILINE_CMDS:47 lines = self.conn.write_readlines(data.encode())48 ans = []49 # Remove $ character used on multilines commands50 for line in lines[1:-1]:51 line = line.decode()52 ans.append(line.strip('\r\n'))53 else:54 ans = self.conn.write_readline(data.encode())55 ans = ans.decode()56 ans = ans.strip('\r\n')57 if ans == 'ERROR':58 err = self.conn.write_readline(b'?ERR\r')59 err = err.decode()60 raise Exception('Error: {}'.format(err))61 return ans62 # ------------------------------------------------------------------------63 # Attributes64 # ------------------------------------------------------------------------65 def in_beam_conf(self, conf=None):66 if conf is None:67 value = self.read_cmd('INBEAM')68 return value69 cmd = 'INBEAM {0}'.format(conf)70 self.write_cmd(cmd)71 def out_beam_conf(self, conf=None):72 if conf is None:73 value = self.read_cmd('OUTBEAM')74 return value75 cmd = 'OUTBEAM {0}'.format(conf)76 self.write_cmd(cmd)77 def set_point(self, value=None):78 if value is None:79 value = float(self.read_cmd('SETPOINT'))80 return value81 cmd = 'SETPOINT {}'.format(value)82 self.write_cmd(cmd)83 def mode(self, value=None):84 if value is None:85 value = self.read_cmd('MODE')86 return value87 cmd = 'MODE {}'.format(value)88 self.write_cmd(cmd)89 def tau(self, value=None):90 if value is None:91 value = float(self.read_cmd('TAU'))92 return value93 cmd = 'TAU {}'.format(value)94 self.write_cmd(cmd)95 def soft_beam(self, value=None):96 if value is None:97 value = float(self.read_cmd('SOFTBEAM'))98 return value99 cmd = 'SOFTBEAM {0}'.format(float(value))100 self.write_cmd(cmd)101 def operation_flags(self):102 value = self.read_cmd('SET')103 return value104 def beam(self):105 beam = self.read_cmd('BEAM')106 beam_in, beam_out = beam.split()107 beam_in = float(beam_in)108 beam_out = float(beam_out)109 return beam, beam_in, beam_out110 def fbeam(self):111 fbeam = self.read_cmd('FBEAM')112 fbeam_in, fbeam_out = fbeam.split()113 fbeam_in = float(fbeam_in)114 fbeam_out = float(fbeam_out)115 return fbeam, fbeam_in, fbeam_out116 def state(self):117 value = self.read_cmd('STATE')118 return value119 def piezo(self, value=None):120 if value is None:121 value = float(self.read_cmd('PIEZO'))122 return value123 cmd = 'PIEZO {}'.format(value)124 self.write_cmd(cmd)125 def speed(self, values=None):126 if values is None:127 scan_speed, move_speed = self.read_cmd('SPEED').split()128 return float(scan_speed), float(move_speed)129 str_values = ''130 for value in values:131 str_values += '{} '.format(str(value))132 cmd = 'SPEED {}'.format(str_values)133 self.write_cmd(cmd)134 def scan_speed(self, value=None):135 if value is None:136 scan_speed, _ = self.speed()137 return scan_speed138 self.speed([value])139 def move_speed(self, value=None):140 scan_speed, move_speed = self.speed()141 if value is None:142 return move_speed143 self.speed([scan_speed, value])144 def osc_beam_signals(self):145 main_signal, quad_signal = self.read_cmd('OSCBEAM').split()146 main_signal = float(main_signal)147 quad_signal = float(quad_signal)148 return main_signal, quad_signal149 def phase(self, value=None):150 if value is None:151 value = float(self.read_cmd('PHASE'))152 return value153 cmd = 'PHASE {}'.format(value)154 self.write_cmd(cmd)155 def amplitude(self, value=None):156 if value is None:157 value = float(self.read_cmd('AMPLITUDE'))158 return value159 cmd = 'AMPLITUDE {}'.format(value)160 self.write_cmd(cmd)161 def frequency(self, value=None):162 if value is None:163 value = float(self.read_cmd('FREQUENCY'))164 return value165 cmd = 'FREQUENCY {}'.format(value)166 self.write_cmd(cmd)167 def slope(self, value=None):168 if value is None:169 value = float(self.read_cmd('SLOPE'))170 return value171 cmd = 'SLOPE {}'.format(value)172 self.write_cmd(cmd)173 def operation_flags(self):174 value = self.read_cmd('SET').split()175 return value176 def oscil(self, value=None):177 if value is None:178 value = self.read_cmd('OSCIL')179 return value180 cmd = 'OSCIL {}'.format(value)181 self.write_cmd(cmd)182 # ------------------------------------------------------------------------183 # Commands184 # ------------------------------------------------------------------------185 def tune(self):186 self.write_cmd('TUNE')187 def tune_peak(self):188 self.write_cmd('TUNE PEAK')189 def go(self):190 self.write_cmd('GO')191 def stop(self):192 self.write_cmd('STOP')193 def pause(self, arg):194 self.write_cmd('PAUSE {}'.format(arg))195 def set_operation_flags(self, args):196 flags = ' '.join(args)197 cmd = 'SET {}'.format(flags)198 self.write_cmd(cmd)199 def clear_operation_flags(self, args):200 flags = ' '.join(args)201 cmd = 'CLEAR {}'.format(flags)202 self.write_cmd(cmd)203 def info(self):204 value = self.read_cmd('INFO')205 return value206 def reset(self):207 # The reset command do not allow to check the error after...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful