示例#1
0
class VhalPropSimulator(object):
    """
        A class simulates vhal properties by calling each generator in a separate thread. It is
        itself a listener passed to each generator to handle vhal event
    """

    def __init__(self, device, gpxFile,):
        self.vhal = Vhal(c.vhal_types_2_0, device)
        self.gpxFile = gpxFile

    def handle(self, prop, area_id, value, desc=None):
        """
            handle generated VHAL property by injecting through vhal emulator.
        """
        print "Generated property %s with value: %s" % (desc, value)
        self.vhal.setProperty(prop, area_id, value)

    def _startGeneratorThread(self, generator):
        thread = Thread(target=generator.generate, args=(self,))
        thread.daemon = True
        thread.start()

    def run(self, timeout):
        userActionGenerator = user_action_generator.UserActionGenerator(self.vhal)
        drivingInfoGenerator = driving_info_generator.DrivingInfoGenerator(self.gpxFile, self.vhal)
        self._startGeneratorThread(userActionGenerator)
        self._startGeneratorThread(drivingInfoGenerator)
        time.sleep(float(timeout))
示例#2
0
 def __init__(self, device):
     self.vhal = Vhal(c.vhal_types_2_0, device)
     self.liveFrameConfig = self.chat(
         lambda hal: hal.getConfig(c.VEHICLEPROPERTY_OBD2_LIVE_FRAME))
     self.freezeFrameConfig = self.chat(
         lambda hal: hal.getConfig(c.VEHICLEPROPERTY_OBD2_FREEZE_FRAME))
     self.eventTypeData = {
         'live': {
             'builder':
             lambda: DiagnosticEventBuilder(self.liveFrameConfig),
             'property': c.VEHICLEPROPERTY_OBD2_LIVE_FRAME
         },
         'freeze': {
             'builder':
             lambda: DiagnosticEventBuilder(self.freezeFrameConfig),
             'property': c.VEHICLEPROPERTY_OBD2_FREEZE_FRAME
         },
     }
示例#3
0
class DiagnosticHalWrapper(object):
    def __init__(self, device):
        self.vhal = Vhal(c.vhal_types_2_0, device)
        self.liveFrameConfig = self.chat(
            lambda hal: hal.getConfig(c.VEHICLEPROPERTY_OBD2_LIVE_FRAME))
        self.freezeFrameConfig = self.chat(
            lambda hal: hal.getConfig(c.VEHICLEPROPERTY_OBD2_FREEZE_FRAME))
        self.eventTypeData = {
            'live': {
                'builder':
                lambda: DiagnosticEventBuilder(self.liveFrameConfig),
                'property': c.VEHICLEPROPERTY_OBD2_LIVE_FRAME
            },
            'freeze': {
                'builder':
                lambda: DiagnosticEventBuilder(self.freezeFrameConfig),
                'property': c.VEHICLEPROPERTY_OBD2_FREEZE_FRAME
            },
        }

    def chat(self, request):
        request(self.vhal)
        return self.vhal.rxMsg()

    def inject(self, file):
        data = json.load(open(file))
        lastTimestamp = 0
        for event in data:
            currentTimestamp = event['timestamp']
            # time travel isn't supported (yet)
            assert currentTimestamp >= lastTimestamp
            # wait the delta between this event and the previous one
            # before sending it out; but on the first event, send now
            # or we'd wait for a long long long time
            if lastTimestamp != 0:
                # also, timestamps are in nanoseconds, but sleep() uses seconds
                time.sleep((currentTimestamp - lastTimestamp) / 1000000000)
            lastTimestamp = currentTimestamp
            # now build the event
            eventType = event['type'].encode('utf-8')
            eventTypeData = self.eventTypeData[eventType]
            builder = eventTypeData['builder']()
            builder.setStringValue(event.get('stringValue', ''))
            for intValue in event['intValues']:
                builder.addIntSensor(intValue['id'], intValue['value'])
            for floatValue in event['floatValues']:
                builder.addFloatSensor(floatValue['id'], floatValue['value'])
            builtEvent = builder.build()
            print("Sending %s %s..." % (eventType, builtEvent)),
            # and send it
            status = self.chat(lambda hal: hal.setProperty(
                eventTypeData['property'], 0, builtEvent)).status
            if status == 0:
                print("ok!")
            else:
                print("fail: %s" % status)
示例#4
0
def executeCommand(args):
    # Create an instance of vhal class.  Need to pass the vhal_types constants.
    v = Vhal(c.vhal_types_2_0, args.device)

    # Get the property config (if desired)
    # property = args.property;
    print args.property
    #i = c.VEHICLEPROPERTY_EV_CHARGE_PORT_OPEN
    v.getConfig(args.property)

    # Get the response message to getConfig()
    reply = v.rxMsg()
    print(reply)

    value = parseVal(args.value, reply.config[0].value_type)
    v.setProperty(args.property, args.area, value)

    # Get the response message to setProperty()
    reply = v.rxMsg()
    print(reply)
示例#5
0
        gearName = 'reverse'
        vhal.setProperty(c.VEHICLEPROPERTY_GEAR_SELECTION, 0,
                         c.VEHICLEGEAR_GEAR_REVERSE)
    elif slider.value() == 2:
        gearName = 'drive'
        vhal.setProperty(c.VEHICLEPROPERTY_GEAR_SELECTION, 0,
                         c.VEHICLEGEAR_GEAR_DRIVE)
    else:
        gearName = "UNK"
    print "slider " + slider.objectName() + " requested " + str(
        slider.value()) + " = " + gearName
    gearDisplay.setText(gearName)


if __name__ == '__main__':
    print "Starting VHal driver GUI"
    vhal = Vhal(c.vhal_types_2_0)

    # Start a receive thread to consume any replies from the vhal
    print "Starting receiver thread"
    rx = Thread(target=rxThread, args=(vhal, ))
    rx.setDaemon(True)
    rx.start()

    # Put the car in park so we start in a known state (consistent with the GUI default state)
    vhal.setProperty(c.VEHICLEPROPERTY_GEAR_SELECTION, 0,
                     c.VEHICLEGEAR_GEAR_PARK)

    # Start the main UI -- never returns
    window()
示例#6
0
 def __init__(self, device, gpxFile,):
     self.vhal = Vhal(c.vhal_types_2_0, device)
     self.gpxFile = gpxFile