How to use set_protocol method in autotest

Best Python code snippet using autotest_python

smbus.py

Source:smbus.py Github

copy

Full Screen

...56c_pca9555_cmd_config_0 = 657c_pca9555_cmd_config_1 = 758###############################################################################59# - SMBus functions60def set_protocol(tc, protocol_id, cnt=1, addr=1, data='', cmd='', cmd2='', appLev=1):61 """Returns filled in protocol message62 See i2c_smbus(pkg).vhd for more detailed comments on the SMBus protocol definitions.63 Input:64 - tc = Testcase65 - protocol_id = Protocol ID: STRING66 - cnt = Number of data bytes, or timeout value: INTEGER67 - addr = I2C slave address: BYTE68 - data = I2C write data: list of BYTE69 - cmd = I2C slave command (register)70 - cmd2 = I2C slave command (register) 271 Return:72 - msg = Protocol request message73 """74 def error_len(data, le):75 ret = 076 if len(data)!=le:77 print('Wrong SMBus protocol data length, must be %d bytes.' % le)78 ret = 179 return ret80 # SMBUS protocol identifiers conform i2c_smbus(pkg).vhd81 PROTOCOL_ARRAY = {'PROTOCOL_WRITE_QUICK' :2,82 'PROTOCOL_READ_QUICK' :3,83 'PROTOCOL_SEND_BYTE' :4,84 'PROTOCOL_RECEIVE_BYTE' :5,85 'PROTOCOL_WRITE_BYTE' :6,86 'PROTOCOL_READ_BYTE' :7,87 'PROTOCOL_WRITE_WORD' :8,88 'PROTOCOL_READ_WORD' :9,89 'PROTOCOL_WRITE_BLOCK' :10,90 'PROTOCOL_READ_BLOCK' :11,91 'PROTOCOL_PROCESS_CALL' :12,92 'PROTOCOL_C_WRITE_BLOCK_NO_CNT' :13,93 'PROTOCOL_C_READ_BLOCK_NO_CNT' :14,94 'PROTOCOL_C_SEND_BLOCK' :15,95 'PROTOCOL_C_RECEIVE_BLOCK' :16,96 'PROTOCOL_C_NOP' :17,97 'PROTOCOL_C_WAIT' :18,98 'PROTOCOL_C_END' :19,99 'PROTOCOL_C_UNKNOWN' :20} # To test unknown protocol100 # First message field101 msg = []102 msg.append(PROTOCOL_ARRAY[protocol_id])103 # Additional message fields:104 if protocol_id == 'PROTOCOL_WRITE_QUICK': msg.append(addr)105 elif protocol_id == 'PROTOCOL_READ_QUICK': msg.append(addr)106 elif protocol_id == 'PROTOCOL_SEND_BYTE':107 msg.append(addr)108 msg.extend(data)109 if error_len(data,1)!=0: msg = -1110 elif protocol_id == 'PROTOCOL_RECEIVE_BYTE': msg.append(addr)111 elif protocol_id == 'PROTOCOL_WRITE_BYTE':112 msg.append(addr)113 msg.append(cmd)114 msg.extend(data)115 if error_len(data,1)!=0: msg = -1116 elif protocol_id == 'PROTOCOL_READ_BYTE': msg.append(addr); msg.append(cmd)117 elif protocol_id == 'PROTOCOL_WRITE_WORD':118 msg.append(addr)119 msg.append(cmd)120 msg.extend(data)121 if error_len(data,2)!=0: msg = -1122 elif protocol_id == 'PROTOCOL_READ_WORD': msg.append(addr); msg.append(cmd)123 elif protocol_id == 'PROTOCOL_WRITE_BLOCK': msg.append(addr); msg.append(cmd); msg.append(cnt); msg.extend(data)124 elif protocol_id == 'PROTOCOL_READ_BLOCK': msg.append(addr); msg.append(cmd); msg.append(cnt)125 elif protocol_id == 'PROTOCOL_PROCESS_CALL':126 msg.append(addr)127 msg.append(cmd)128 msg.extend(data)129 if error_len(data,2)!=0: msg = -1130 msg.append(addr); msg.append(cmd2)131 elif protocol_id == 'PROTOCOL_C_WRITE_BLOCK_NO_CNT': msg.append(addr); msg.append(cmd); msg.append(cnt); msg.extend(data)132 elif protocol_id == 'PROTOCOL_C_READ_BLOCK_NO_CNT': msg.append(addr); msg.append(cmd); msg.append(cnt)133 elif protocol_id == 'PROTOCOL_C_SEND_BLOCK': msg.append(addr); msg.append(cnt); msg.extend(data)134 elif protocol_id == 'PROTOCOL_C_RECEIVE_BLOCK': msg.append(addr); msg.append(cnt)135 elif protocol_id == 'PROTOCOL_C_NOP': None136 elif protocol_id == 'PROTOCOL_C_WAIT': msg.extend(rsp.i2bbbb([cnt]))137 elif protocol_id == 'PROTOCOL_C_END': None138 else: tc.appendLog(appLev, 'Unknown SMBus protocol.')139 return msg140def test_protocols(tc):141 """Procedure used to verify set_protocol in a Python shell142 """143 print(set_protocol(tc, 'PROTOCOL_WRITE_QUICK', None, 1, None, None, None))144 print(set_protocol(tc, 'PROTOCOL_READ_QUICK', None, 1, None, None, None))145 print(set_protocol(tc, 'PROTOCOL_SEND_BYTE', None, 1, [5], None, None))146 print(set_protocol(tc, 'PROTOCOL_RECEIVE_BYTE', None, 1, None, None, None))147 print(set_protocol(tc, 'PROTOCOL_WRITE_BYTE', None, 1, [5], 17, None))148 print(set_protocol(tc, 'PROTOCOL_READ_BYTE', None, 1, None, 17, None))149 print(set_protocol(tc, 'PROTOCOL_WRITE_WORD', None, 1, [5, 6], 17, None))150 print(set_protocol(tc, 'PROTOCOL_READ_WORD', None, 1, None, 17, None))151 print(set_protocol(tc, 'PROTOCOL_WRITE_BLOCK', 3, 1, [9, 9, 9], 17, None))152 print(set_protocol(tc, 'PROTOCOL_READ_BLOCK', 3, 1, None, 17, None))153 print(set_protocol(tc, 'PROTOCOL_PROCESS_CALL', None, 1, [5, 6], 17, 18))154 print(set_protocol(tc, 'PROTOCOL_C_WRITE_BLOCK_NO_CNT', 3, 1, [9, 9, 9], 17, None))155 print(set_protocol(tc, 'PROTOCOL_C_READ_BLOCK_NO_CNT', 3, 1, None, 17, None))156 print(set_protocol(tc, 'PROTOCOL_C_SEND_BLOCK', 3, 1, [9, 9, 9], None, None))157 print(set_protocol(tc, 'PROTOCOL_C_RECEIVE_BLOCK', 3, 1, None, None, None))158 print(set_protocol(tc, 'PROTOCOL_C_NOP', None, 1, None, None, None))159 print(set_protocol(tc, 'PROTOCOL_C_WAIT', 1333, 1, None, None, None))160 print(set_protocol(tc, 'PROTOCOL_C_END', None, 1, None, None, None))161 set_protocol( tc, 'PROTOCOL_C_UNKNOWN', None, 1, None, None, None)162def write_protocol_list(tc, msg, smbh, protocol_list, polId=['x', 'y'], blpId=['blp0'], rspId=['rsp0']):163 """Write SMBus protocol list to SMBus handler164 165 Input:166 - tc = Testcase167 - msg = MepMessage168 - smbh = I2C device handler: 'rcuh' or 'tdsh'169 - protocol_list = Protocol list: bytes170 - polId = Polarization: 'x' or 'y' for RCUH, ignored for TDSH171 - blpId = BLP ID: 'blp#' for RCUH, destination defaults to 'rsp' for TDSH172 - rspId = RSP ID: 'rsp#'173 174 Return: void175 """...

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 autotest 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