Exemplo n.º 1
0
class Router:
    network = None
    processor = None
    metadata = ""

    def __init(self, network):
        self.network = network
        self.network.start_server()
        self.metadata = self.network.get_metadata()
        self.processor = Process(self.network)

    def process_data(self, data_to_process):
        self.processor.get_data(data_to_process)
Exemplo n.º 2
0
class Display(Widget):
    # used for the flashing of the rpm
    counter = 0
    shiftIndicator = False
    '''
    ASSIGNING THE DEFUALT VALUES
    MUST BE NUMERICPROPERTY TO WORK WITH KIVY (IDK)
    '''
    rpm = NumericProperty(current_rpm)
    oilPress = NumericProperty(init_oilPress)
    oilTemp = NumericProperty(init_oilTemp)
    coolantTemp = NumericProperty(eng_temperature)
    afr = NumericProperty(init_afr)

    DAQ_Missing = StringProperty("DAQ IS MISSING")

    # This is how to load image file path
    img = StringProperty("green.png")

    glowUp = StringProperty("glow3.jpeg")
    glowDown = StringProperty("glow4.jpeg")
    '''add these for glow later
    Rectangle:
            id: myRect
            size: 760,30
            pos: 20, 500
            source: self.glowUp

        Rectangle:
            id: myRect
            size: 760,25
            pos: 20, 385
            source: self.glowDown    
    '''

    img_size = BoundedNumericProperty(0.9, max=1.0, min=0.1)

    data = {
        'timestamp': 0,
        'interval': 0,
        'battery': 0,
        'accelX': 0,
        'accelY': 0,
        'accelZ': 0,
        'yaw': 0,
        'pitch': 0,
        'roll': 0,
        'rpm': 0,
        'map': 0,
        'tps': 0,
        'oilPressure': 0,
        'afr': 0,
        'coolantTemperature': 0,
        'iat': 0,
        'oilTemperature': 0,
        'gear': 0,
        'speed': 0,
        'frontLeft': 0,
        'frontRight': 0,
        'rearLeft': 0,
        'rearRight': 0,
        'latitude': 0,
        'longitude': 0,
        'injectorPW': 0,
        'fuelTemp': 0,
        'baro': 0,
        'altitude': 0,
        'session': 0,
        'lambda': 0
    }
    processor = None
    last_updated_time = datetime.datetime.now()
    sticky_rpm = 999
    rpm_counter = 0
    sum = 0
    connected = False

    def __init__(self, **kwargs):
        # needed for constructor
        super(Display, self).__init__(**kwargs)
        # these two lines needed to use the keyboard and stuff
        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)
        # timer just like in java, takes in a function and acts as a independent thread
        Clock.schedule_interval(self.update, 0.01)

        try:
            self.processor = Process()
            self.connected = True
        except Exception as e:
            print("Unable to connect to DAQ")
            self.connected = False

    def _keyboard_closed(self):  # also part of the keyboard stuff
        self._keyboard.unbind(on_key_down=self._on_keyboard_down)
        self._keyboard = None

    def _on_keyboard_down(self, keyboard, keycode, text, modeifires):
        if keycode[1] == 'q':
            exit()

    def get_data(self):
        self.data = json.loads(self.processor.get_data().decode('utf-8'))

    def update(self, *args):
        if self.connected:
            self.DAQ_Missing = ""
            self.get_data()
        '''
        UPDATING VALUES
        '''
        self.rpm = self.data["rpm"]
        self.oilPress = round(self.data["oilPressure"], 1)

        self.oilTemp = int(self.data["oilTemperature"])

        if self.data["coolantTemperature"] > 0:
            self.coolantTemp = int(self.data["coolantTemperature"])

        self.afr = round(self.data["afr"], 1)
        '''
        DEBUGGING
        '''
        # print(self.data)
        '''
        SHIFT LIGHTS TURN ON
        '''
        if (self.rpm > 10500):
            # now its time for shifting
            shiftIndicator = True
        else:
            shiftIndicator = False
            self.img = "green.png"
        '''
        FLASHING EFFECT
        '''
        if (shiftIndicator == True):
            if self.counter < 100:
                self.img = "red.jpg"
            else:
                self.img = "blue.jpg"

            # change this to chang the timing of the flashes
            self.counter = self.counter + 20
            if self.counter == 200:
                self.counter = 0
Exemplo n.º 3
0
import json
from time import sleep

from Process import Process

if __name__ == '__main__':
    processor = Process()
    while True:
        data = processor.get_data()
        print(data)
Exemplo n.º 4
0
class Network:
    # DAQ DATA
    metadata = ""
    data = []

    # Routing Class
    process = None

    # Server Configs
    listen_address = "0.0.0.0"
    listen_port = 8080

    def __init__(self):
        self.process = Process()

    def start_server(self):
        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # this is for easy starting/killing the app
        soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        print('Socket created')

        try:
            soc.bind((self.listen_address, self.listen_port))
            print('Socket bind complete')
        except socket.error as msg:
            import sys
            print('Bind failed. Error : ' + str(sys.exc_info()))
            print(msg)
            sys.exit()

        #Start listening on socket
        soc.listen(10)
        print('Socket now listening')

        # this will make an infinite loop needed for
        # not reseting server for every client
        while True:
            conn, addr = soc.accept()
            ip, port = str(addr[0]), str(addr[1])
            print('Accepting connection from ' + ip + ':' + port)
            try:
                Thread(target=self.client_thread,
                       args=(conn, ip, port)).start()
            except:
                print("Terrible error!")
                import traceback
                traceback.print_exc()
        soc.close()

    def client_thread(self, conn, ip, port, MAX_BUFFER_SIZE=4096):
        # the input is in bytes, so decode it
        input_from_client_bytes = conn.recv(MAX_BUFFER_SIZE)

        # MAX_BUFFER_SIZE is how big the message can be
        # this is test if it's sufficiently big
        import sys
        siz = sys.getsizeof(input_from_client_bytes)
        if siz >= MAX_BUFFER_SIZE:
            print("The length of input is probably too long: {}".format(siz))

        # decode input and strip the end of line
        input_from_client = input_from_client_bytes.decode("utf8")

        res = do_some_stuffs_with_input(input_from_client)
        print("Result of processing {} is: {}".format(input_from_client, res))

        vysl = res.encode("utf8")  # encode the result string
        conn.sendall(vysl)  # send it to client

        #        self.authenticate_daq(conn, ip, port, MAX_BUFFER_SIZE)
        self.process_metadata_from_daq(conn, ip, port, MAX_BUFFER_SIZE)
        while True:
            # the input is in bytes, so decode it
            input_from_daq_bytes = conn.recv(MAX_BUFFER_SIZE)
            import sys
            siz = sys.getsizeof(input_from_daq_bytes)
            if siz >= MAX_BUFFER_SIZE:
                print(
                    "The length of input is probably too long: {}".format(siz))
            # decode input
            input_from_daq = input_from_daq_bytes.decode("utf8")
            print(input_from_daq)
            self.process.get_data(input_from_daq)

    def authenticate_daq(self, conn, ip, port, max_buffer_size):
        # On first input, ignore it
        input_from_client_bytes = conn.recv(max_buffer_size)
        print("Inside Auth: " + input_from_client_bytes.decode("utf8"))
        import sys
        siz = sys.getsizeof(input_from_client_bytes)
        if siz >= max_buffer_size:
            print("The length of input is probably too long: {}".format(siz))

        input_from_client = input_from_client_bytes.decode("utf8")

        # Send authentication string back to DAQ (dw we the REAL Podium Connect)
        import time
        millis = str(int(round(time.time() * 1000)))
        auth = '{"status":"ok", "utc":' + millis + '}'
        auth_encoded = auth.encode("utf8")  # encode the result string
        conn.sendall(auth_encoded)  # send it to client

    def process_metadata_from_daq(self, conn, ip, port, max_buffer_size):
        print("Im trying to process metadata")
        statement = '{"getMeta":null}\r\n'
        while True:
            conn.sendall(statement.encode("utf-8"))
            meta = conn.recv(max_buffer_size).decode("utf-8")
            print("inside meta: " + meta)
            if meta is not None and b'{"meta"' in meta:
                try:
                    raw_data = string_me(meta)
                    self.metadata = raw_data
                except Exception as e:
                    print(e)
                finally:
                    print("Updated Channel Metadata")
                    break

    def get_metadata(self):
        return self.metadata