How to use sendType method in fMBT

Best Python code snippet using fMBT_python

device.py

Source:device.py Github

copy

Full Screen

1import threading2import time3class Device(threading.Thread):4 def __init__(self, app, deviceData):5 self.__app=app6 threading.Thread.__init__(self)7 self.name=deviceData["name"]8 self.type=deviceData["class"]9 self.isNear=False10 self.stream = False11 self.streamingUser = ""12 self.sendType=''13 self.arguments=[]14 self.data={}15 self.adcvalue=016 self.i2cvalue=None17 self.nfc=''18 self.customParams = {}19 self.text = ''20 def run(self):21 self.__app.getPinConfig("src/iot/"+self.name+"/pinout.json")22 self.__app.getConfig("src/iot/"+self.name+"/config.json")23 self.customParams = self.__app.config["custom"]24 #datap_old=025 disc=False26 self.newImg()27 while(self.__app.isAlive()):28 if (self.stream and self.isNear):29 if(self.sendType=="image"):30 self.data=self.__app.sendImg_and_recvData()31 self.sendType=""32 disc=True33 elif(self.sendType=="neopixel"):34 self.__app.setNeopixel(self.arguments[0],self.arguments[1])35 self.arguments=[]36 self.sendType=""37 elif(self.sendType=="outpin"):38 #self.data=self.__app.recvData()39 self.__app.setOutPin(self.arguments[0],self.arguments[1])40 self.arguments=[]41 self.sendType=""42 #self.data = self.__app.recvData()43 elif(self.sendType=="inpin"):44 self.__app.setInPin(self.arguments[0])45 self.arguments=[]46 self.sendType=""47 elif(self.sendType=="pwm"):48 self.__app.setPwm(self.arguments[0],self.arguments[1], self.arguments[2])49 self.arguments=[]50 self.sendType=""51 elif(self.sendType=="adc"):52 self.adcvalue=self.__app.readAdc(self.arguments[0],self.arguments[1])53 self.sendType=""54 elif(self.sendType=="i2c"):55 self.i2cvalue = self.__app.readI2C(self.arguments[0],self.arguments[1])56 self.sendType=""57 elif(self.sendType=="setdisplay"):58 self.__app.setDisplay(self.arguments[0],self.arguments[1], self.arguments[2], self.arguments[3], self.arguments[4])59 self.arguments=[]60 self.sendType=""61 else:62 self.data=self.__app.recvData()63 64 #self.nfc=self.__app.readNFC()65 66 else:67 if(disc):68 disc=False69 self.sendType=""70 self.__app.newImg()71 self.__app.sendImg()72 self.nfc=self.__app.readNFC()73 #TODO: check nfc tag 74 if self.nfc != '0':75 self.isNear = True76 #print(self.data) 77 """if (self.data['PROXIMITY']!=datap_old):78 datap_old=self.data['PROXIMITY']79 if(datap_old):80 self.isNear=not self.isNear"""81 self.stream=False82 83 def resumeConnection(self, so):84 self.__app.changeSocket(so)85 self.__app.getPinConfig("src/iot/"+self.name+"/pinout.json")86 print("resumed")87 def sendImg(self):88 self.sendType="image"89 while( self.sendType=="image" and (self.stream and self.isNear) ):90 pass91 def recvData(self):92 return self.data93 94 def sendImg_and_recvData(self):95 self.sendType="image"96 while( self.sendType=="image" and (self.stream and self.isNear) ):97 pass98 return self.data99 def setNeopixel(self, status, pin=-1):100 self.sendType="neopixel"101 self.arguments.append(status)102 self.arguments.append(pin)103 while( self.sendType=="neopixel" and (self.stream and self.isNear)):104 pass105 def setOutPin(self, pin, value):106 self.sendType="outpin"107 self.arguments.append(pin)108 self.arguments.append(value)109 while( self.sendType=="outpin" and (self.stream and self.isNear)):110 pass111 112 def getOutPins(self):113 return self.__app.outPins114 def getInPins(self):115 return self.__app.inPins116 117 def setInPin(self, pin):118 self.sendType="inpin"119 self.arguments.append(pin)120 while( self.sendType=="inpin" and (self.stream and self.isNear)):121 pass122 def setPwm(self, pin, freq, duty):123 self.sendType="pwm"124 self.arguments.append(pin)125 self.arguments.append(freq)126 self.arguments.append(duty)127 while( self.sendType=="pwm" and (self.stream and self.isNear)):128 pass129 def readAdc(self, pin, resolution=1024):130 self.sendType="adc"131 self.arguments.append(pin)132 self.arguments.append(resolution)133 while( self.sendType=="adc" and (self.stream and self.isNear)):134 pass135 return self.adcvalue136 def readI2C(self, addr, nbytes):137 self.sendType="i2c"138 self.arguments.append(addr)139 self.arguments.append(nbytes)140 while( self.sendType=="i2c" and (self.stream and self.isNear)):141 pass142 return self.i2cvalue143 def setDisplay(self, sda, scl, heigth, width, dispType):144 self.sendType="setdisplay"145 self.arguments.append(sda)146 self.arguments.append(scl)147 self.arguments.append(heigth)148 self.arguments.append(width)149 self.arguments.append(dispType)150 while( self.sendType=="setdisplay" and (self.stream and self.isNear)):151 pass152 def newImg(self):153 self.__app.newImg()154 155 def setImg(self, img):156 self.__app.setImg(img)157 def fillImg(self, img_color):158 self.__app.fillImg(img_color)159 def addFont(self, font, font_size):160 self.__app.addFont(font, font_size)161 def getFonts(self):162 return self.__app.getFonts()163 def setRotation(self, rotation):164 self.__app.setRotation(rotation)165 def setContrast(self, contrast):166 self.__app.setContrast(contrast)167 def setCustomParams(self, customParams):168 self.__app.setCustomParams(customParams)169 170 def getCustomParams(self):171 return self.__app.getCustomParams()172 def setText(self,pos,txt, txt_color, txt_font):173 self.__app.setText(pos, txt, txt_color, txt_font)174 def setNeoPin(self, pin):175 self.__app.setNeoPin(pin)176 177 def resetStreamingUser(self):178 self.streamingUser=""179 self.stream = False180 self.isNear=False181 182 def setStreamingUser(self, user):183 self.streamingUser=user184 self.stream = True185 def getStreamingUser(self):186 return self.streamingUser187 def getDeviceName(self):188 return self.name189 def getDeviceType(self):190 return self.type191 192 def getNFC(self):...

Full Screen

Full Screen

rlMessage.py

Source:rlMessage.py Github

copy

Full Screen

1import requests2import time3from login.Utils import Utils4# 获取当前日期,格式为 2021-8-225def getNowDate():6 return time.strftime("%Y-%m-%d", time.localtime(time.time()))7# 获取当前时间,格式为 12:00:008def getNowTime():9 return time.strftime("%H:%M:%S", time.localtime(time.time()))10# 若离消息通知类11class RlMessage:12 # 初始化类13 def __init__(self, sendKey, apiUrl, msgKey, sendType):14 self.sendKey = sendKey15 self.apiUrl = apiUrl16 self.msgKey = msgKey17 self.sendType = sendType18 # 发送邮件消息19 def sendMail(self, status, msg):20 # 若离邮件api, 将会存储消息到数据库,并保存1周以供查看,请勿乱用,谢谢合作21 if self.sendKey == '':22 return '邮箱为空,已取消发送邮件!'23 if self.apiUrl == '':24 return '邮件API为空,设置邮件API后才能发送邮件'25 params = {26 'reciever': self.sendKey,27 'title': f'[{status}]今日校园通知',28 'content': f'[{Utils.getAsiaDate()} {Utils.getAsiaTime()}]{msg}'29 }30 res = requests.post(url=self.apiUrl, params=params).json()31 return res['message']32 # qmsg推送33 def sendQmsg(self, status, msg):34 if self.sendKey == '':35 return 'QQ为空,已取消发送邮件!'36 if self.msgKey == '':37 return 'QmsgKey为空,设置QmsgKey后才能发送QQ推送'38 params = {39 'msg': f'[{Utils.getAsiaDate()} {Utils.getAsiaTime()}]{msg}',40 'qq': self.sendKey41 }42 res = requests.post(f'https://qmsg.zendee.cn/send/{self.msgKey}', params).json()43 return res['reason']44 # pushplus推送45 def sendPushplus(self, status, msg):46 if self.sendKey == '':47 return 'sendKey为空,已取消发送邮件!'48 params = {49 'token': self.sendKey,50 'title': f'[{status}]今日校园通知',51 'content': f'[{Utils.getAsiaDate()} {Utils.getAsiaTime()}]{msg}',52 }53 headers = {54 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0'55 }56 res = requests.post("https://pushplus.hxtrip.com/send", headers=headers, params=params)57 if res.status_code == 200:58 return "发送成功"59 else:60 return "发送失败"61 # 统一发送接口名62 def send(self, status, msg):63 print(Utils.getAsiaTime() + ' 正在发送邮件通知')64 if self.sendType == 0:65 return self.sendMail(status, msg)66 elif self.sendType == 1:67 time.sleep(2)68 return self.sendQmsg(status, msg)69 elif self.sendType == 2:...

Full Screen

Full Screen

ImgDecode.py

Source:ImgDecode.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Tencent is pleased to support the open source community by making GameAISDK available.4This source code file is licensed under the GNU General Public License Version 3.5For full details, please refer to the file "LICENSE.txt" which is provided as part of this source code package.6Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.7"""8import logging9import base6410import cv211import numpy as np12from common.Define import RAW_IMG_SEND_TYPE, BINARY_IMG_SEND_TYPE, CV2_EN_DECODE_IMG_SEND_TYPE, \13 BASE_64_DECODE_IMG_SEND_TYPE14LOG = logging.getLogger('IOService')15def ImgDecode(imgData, sendType):16 """17 decode img data based on sendType18 :param imgData: img data(bytes)19 :param sendType: send type enum:20 RAW_IMG_SEND_TYPE21 BINARY_IMG_SEND_TYPE22 CV2_EN_DECODE_IMG_SEND_TYPE23 BASE_64_DECODE_IMG_SEND_TYPE24 :return:25 """26 img = imgData27 if sendType == RAW_IMG_SEND_TYPE:28 pass29 elif sendType == BINARY_IMG_SEND_TYPE:30 try:31 nparr = np.asarray(bytearray(imgData), dtype=np.uint8)32 img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)33 except RuntimeError as err:34 LOG.error('img decode err:%s', err)35 LOG.error('sendType:%s', sendType)36 img = None37 elif sendType == CV2_EN_DECODE_IMG_SEND_TYPE:38 try:39 nparr = np.fromstring(imgData, np.uint8)40 img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)41 except RuntimeError as err:42 LOG.error('img decode err:%s', err)43 LOG.error('sendType:%s', sendType)44 img = None45 elif sendType == BASE_64_DECODE_IMG_SEND_TYPE:46 try:47 imgByte = base64.b64decode(imgData)48 nparr = np.fromstring(imgByte, np.uint8)49 img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)50 except RuntimeError as err:51 LOG.error('img decode err:%s', err)52 LOG.error('sendType:%s', sendType)53 img = None...

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