コード例 #1
0
ファイル: sensing.py プロジェクト: munu2635/raspstart
	def __init__(self, GPIO, allIpPort, raspid, sensordata):
		self.tHCount = 0
		self.GPIO = GPIO
		self.brokerIpPort = allIpPort[0]
		self.cameraIpPort = allIpPort[1]

		self.all_pin = sensordata[0]
		self.adc_pin = sensordata[1]
		self.useSensor = sensordata[2]
		self.ButtonUpDown = sensordata[3]

		self.topic = Topic.Topic(self.brokerIpPort, raspid)
		self.raspid = raspid

		self.reciveControl = False
		self.sensorTimerControl = []
		self.sensorDetectControl = []
		
		self.sensorTimerControlIndex = []
		self.sensorDetectControlIndex = []

		self.sensorMoveControl = []


		self.setInstance(GPIO)
		self.receive = receive.Receive([self.sensorTimerControl, self.sensorDetectControl, self.sensorMoveControl], self.cameraIpPort, self.topic)
コード例 #2
0
def Client(
    listenPort, serverPort, serverAddress
):  # Creates 'Client' function and takes in 'listenPort' that holds the port number to connect to, 'serverPort' that holds the server's port number, and 'serverAddress', that hods the address of the server to connect to
    sock = socket.socket(
        socket.AF_INET, socket.SOCK_STREAM)  # Initializes 'sock' with a socket
    sock.connect(
        (serverAddress, serverPort)
    )  # Connect to the server with address 'serverAddress' over port number 'serverPort'
    receiveThread = receive.Receive(sock)  # Create thread to receive messages
    receiveThread.start()  # Start thread to receive messages
    sock.send(str(listenPort).encode())
    while (receive.hasPort == False):
        i = 1
    receive.filePort = listenPort
    run(sock, listenPort)  # Calls 'run' function
コード例 #3
0
ファイル: app.py プロジェクト: 0x202036/word_api
def api_main():
    try:
        my_json =request.get_json()
        obj_receive = receive.Receive(my_json)
        if obj_receive.stage==3:
            angle11 = (obj_receive.word, '', [], 1)
            angle_send11 = send.Send(3, word=angle11[0], trans=angle11[1], sentence_list=angle11[2], length=angle11[3])
            angle_zhazha11 = dict(angle_send11)
            angle_j11 = json.dumps(obj=angle_zhazha11)
            return angle_j11

        obj_check = check.Check(receive=obj_receive)
        print(4)
        result = obj_check.begin_check()
        angle = (obj_receive.word, '', [['', '', '', '']], 1)
        if result != "safe":
            '''应为result !="safe:
            return jsonify(result)方便测试其他数据'''
            angle_send = send.Send( 2,angle[0],angle[1],angle[2],angle[3])
            angle_zhazha = dict(angle_send)
            angle_j = json.dumps(obj=angle_zhazha)
            return angle_j
        else:
            obj_db_manager = db_manager.Db_Manager(receive=obj_receive)
            obj_get_word_data = obj_db_manager.get_send_data()
            if obj_get_word_data == "NULL":
                Null_angle_send = send.Send(1, angle[0], angle[1], angle[2], angle[3])
                Null_angle_zhazha = dict(Null_angle_send)
                Null_angle_j = json.dumps(obj=Null_angle_zhazha)
                #该单词未录入
                return Null_angle_j
            obj_send = send.Send( 0,obj_get_word_data[0],obj_get_word_data[1],obj_get_word_data[2],obj_get_word_data[3])
            zhazha=dict(obj_send)
            j = json.dumps(obj=zhazha)
            return j

    except Exception as e:
        angle12 =("", '', [], 1)
        angle_send = send.Send( 3,angle12[0],angle12[1],angle12[2],angle12[3])
        angle_zhazha = dict(angle_send)
        angle_j = json.dumps(obj=angle_zhazha)
        print("异常")
        return angle_j
コード例 #4
0
import send
import receive
import gui
import time
import os

if __name__ == "__main__":

    username = "******"
    password = "******"
    labels = [
        '"[Gmail]/All Mail"', 'Inbox', '"[Gmail]/Sent Mail"', '"[Gmail]/Trash"'
    ]

    # initialize smtp (email sending) and imap (email recieving) protocols
    receive = receive.Receive(username, password)
    send = send.Send(username, password)
    # send.send_message(username, "sadasd", "asdasdffasasfdsfa")

    msgs = []
    file_name = 'messages.data'
    # if msg file exists then read from it, else retreive msgs using imap
    if os.path.exists(file_name):
        msgs = gui.read_from_file(file_name)
    else:
        for label in labels:
            msgs.append(receive.get_message(category=label))

    # print inbox category only
    # for msg in msgs:
    #     print("To:\t", msg[1])
コード例 #5
0
ファイル: main.py プロジェクト: zatamite/TYOS
    def __init__(self):
        warnings.filterwarnings("ignore")
        for arg in sys.argv:
            if arg == '--power':
                self.POWER_FONA = True
                print 'Powering FONA on...'
            else:
                self.POWER_FONA = False
            if arg == '--version':
                print 'TYOS VERSION ' + VERSION
                sys.exit()

        self.VERSION = VERSION
        if self.POWER_FONA:
            import power
            power.Power().toggle()
            time.sleep(10)

        #Setup fona
        self.fona = serialport.SerialPort()
        self.fona.connect()

        self.set_audio()

        #Setup some important objects
        self.scope = framebuffer.pyscope()
        self.toolbar = toolbar.Toolbar(self.fona)
        self.apps = apps.App(self.fona)
        self.reciever = receive.Receive(self.fona)

        pygame.init()

        #Setup surface
        self.WINDOWWIDTH = 320
        self.WINDOWHIEGHT = 480
        self.surface = pygame.display.set_mode(
            (self.WINDOWWIDTH, self.WINDOWHIEGHT), pygame.FULLSCREEN)
        pygame.mouse.set_visible(False)

        self.clock = pygame.time.Clock()

        #Colors        R   G   B
        self.BLUE = (0, 0, 255)
        self.WHITE = (255, 255, 255)
        self.BLACK = (0, 0, 0)

        self.surface.fill(self.WHITE)

        self.update = True

        #Setup logo
        self.logo = pygame.image.load('/home/pi/tyos/graphics/logo.png')
        self.logo_rect = self.logo.get_rect()
        self.logo_rect.y = self.surface.get_rect().centery - 50
        self.logo_rect.centerx = self.surface.get_rect().centerx

        #Setup Battery Icon
        self.bat = pygame.image.load('/home/pi/tyos/graphics/bat.png')
        self.bat_rect = self.bat.get_rect()
        self.bat_rect.centery = 15
        self.bat_rect.right = self.WINDOWWIDTH - 10

        #Setup Low Battery Icon
        self.low_bat = pygame.image.load('/home/pi/tyos/graphics/low_bat.png')
        self.low_bat_rect = self.low_bat.get_rect()
        self.low_bat_rect.centery = 380
        self.low_bat_rect.centerx = self.surface.get_rect().centerx

        #Setup App Toolbar
        self.app_toolbar = pygame.Rect(0, 0, 320, 30)

        #Rectangle Dictionary
        self.rectangles = {'rects': [self.app_toolbar], 'colors': [self.BLACK]}
        #Reception Rectangle dictionary
        self.reception_bars = {'rects': [], 'colors': []}
        #Battery Left Text
        self.bat_left = {
            'surface': self.toolbar.bat_left,
            'rects': self.toolbar.bat_left_rect
        }

        #Setup fonts
        self.font = pygame.font.Font('/home/pi/tyos/fonts/arial.ttf', 20)

        #Setup clock Text
        self.clock_text = self.font.render('12:00', True, self.WHITE,
                                           self.BLACK)
        self.clock_text_rect = self.clock_text.get_rect()
        self.clock_text_rect.centerx = self.surface.get_rect().centerx
        self.clock_text_rect.centery = 15

        #Image Dictionary
        self.images = {
            'surfaces': [self.bat],
            'rects': [self.bat_rect, self.clock_text_rect]
        }

        self.blit_logo = True
        self.dead_bat = False
コード例 #6
0
 def rebuild_receive(self, receive, old_msg_type, new_topic):
     receive.unregister()
     del receive
     return receive.Receive(new_topic, old_msg_type, on_received)#怎么把之前的回调函数传进来?传回调函数对象的时候应该在后面实例化的时候。
コード例 #7
0
 def create_receive(self, topic, msg_type, on_received):
     return receive.Receive(topic, msg_type, on_received)
コード例 #8
0
ファイル: ,.py プロジェクト: 0x202036/word_api
#     chaci = yanzheng.get_send_data()
#     finly = send.Send(chaci[0], chaci[1], chaci[2], chaci[3])
#     back_json = send.Send.to_dict(finly)
#     # 将目前对象转换为字典
#     print(back_json)
#     return jsonify(back_json)
# else:return jsonify(fankui)
my_json = {
    "security": {
        "uname": "amy",
        "key": 12323,
        "time": 2321
    },
    "word": "a",
    "option": {
        "level": 1
    }
}
obj_receive = receive.Receive(my_json)
print(obj_receive.option.level)
obj_check = check.Check(receive=obj_receive)
result = obj_check.begin_check()
if result == "safe":
    print(1)
else:
    obj_db_manager = db_manager.Db_Manager(receive=obj_receive)
    obj_get_word_data = obj_db_manager.get_send_data()
    obj_send = send.Send(obj_get_word_data[0], obj_get_word_data[1],
                         obj_get_word_data[2], obj_get_word_data[3])
    print(obj_send)
    # fasong = get_send_json(obj_send)