Esempio n. 1
0
def piCameraSendFrameHelper(stream, frame):
    ''' do the actual frame processing '''
    global piCameraLastFrameIndex

    try:
        # record index of new frame
        piCameraLastFrameIndex = frame.index

        # get the frame data and display it
        stream.seek(frame.position)
        image = stream.read(frame.frame_size)

        timestamp = time.time()
        message = rdf.newPublishMessage('picam', outTopic, vdefs.DATATYPE,
                                        timestamp)
        message[vdefs.WIDTH] = cameraWidth
        message[vdefs.HEIGHT] = cameraHeight
        message[vdefs.RATE] = cameraRate
        message[vdefs.FORMAT] = 'mjpeg'
        if ManifoldPython.isServiceActive(
                sourcePort) and ManifoldPython.isClearToSend(sourcePort):
            ManifoldPython.sendMulticastData(sourcePort, json.dumps(message),
                                             image, timestamp)
    except:
        print("Send frame error ", sys.exc_info()[0], sys.exc_info()[1])
Esempio n. 2
0
def callback(samples, frame_count, time_info, status):

    timestamp = time.time()
    message = rdf.newPublishMessage('audio', audioTopic, adefs.DATATYPE,
                                    timestamp)
    message[adefs.CHANNELS] = audioChannels
    message[adefs.RATE] = audioRate
    message[adefs.SAMPTYPE] = 'int16'
    message[adefs.FORMAT] = 'pcm'
    if ManifoldPython.isServiceActive(
            sourcePort) and ManifoldPython.isClearToSend(sourcePort):
        ManifoldPython.sendMulticastData(sourcePort, json.dumps(message),
                                         samples, timestamp)

    return (None, pyaudio.paContinue)
Esempio n. 3
0
def readSensors():
    global lastSensorReadTime

    if ((time.time() - lastSensorReadTime) < sampleInterval):
        return
    # call background loops
    if accel.sensorValid:
        accel.background()
    if light.sensorValid:
        light.background()
    if temperature.sensorValid:
        temperature.background()
    if pressure.sensorValid:
        pressure.background()
    if humidity.sensorValid:
        humidity.background()

    # time send send the sensor readings
    lastSensorReadTime = time.time()

    message = rdf.newPublishMessage('sensors', outTopic, sdefs.DATATYPE,
                                    lastSensorReadTime)

    if accel.dataValid:
        accelData = accel.readAccel()
        message[sdefs.ACCEL_DATA] = accelData

    if light.dataValid:
        lightData = light.readLight()
        message[sdefs.LIGHT_DATA] = lightData

    if temperature.dataValid:
        temperatureData = temperature.readTemperature()
        message[sdefs.TEMPERATURE_DATA] = temperatureData

    if pressure.dataValid:
        pressureData = pressure.readPressure()
        message[sdefs.PRESSURE_DATA] = pressureData

    if humidity.dataValid:
        humidityData = humidity.readHumidity()
        message[sdefs.HUMIDITY_DATA] = humidityData

    if ManifoldPython.isServiceActive(
            sourcePort) and ManifoldPython.isClearToSend(sourcePort):
        ManifoldPython.sendMulticastData(sourcePort, json.dumps(message), '',
                                         lastSensorReadTime)
Esempio n. 4
0
ttyInPort = ManifoldPython.addMulticastSource(ttyInTopic)
if (ttyInPort == -1):
    print("Failed to activate multicast source endpoint")
    ManifoldPython.stop()
    sys.exit()

serialPort = serial.Serial(ttyPort, ttyRate, timeout=0)

try:
    while True:
        processReceivedText()

        readBytes = serialPort.read(256)
        if len(readBytes) > 0:
            timestamp = time.time()
            inMessage = rdf.newPublishMessage('tty', ttyInTopic, 'tty',
                                              timestamp)

            if ManifoldPython.isServiceActive(
                    ttyInPort) and ManifoldPython.isClearToSend(ttyInPort):
                ManifoldPython.sendMulticastData(ttyInPort,
                                                 json.dumps(inMessage),
                                                 readBytes, timestamp)

        time.sleep(0.001)
except:
    print("Main loop error", sys.exc_info()[0], sys.exc_info()[1])

# Exiting so clean everything up.

ManifoldPython.removeService(ttyInPort)
ManifoldPython.removeService(ttyOutPort)
Esempio n. 5
0
while (True):
    try:
        # give other things a chance
        time.sleep(0.02)
        # get a frame from the camera
        ret, frame, jpeg, width, height, rate = ManifoldPython.vidCapGetFrame(
            cameraIndex)
        if (ret):
            # and display it
            if (jpeg):
                ManifoldPython.displayJpegImage(frame, "")
            else:
                ManifoldPython.displayImage(frame, width, height, "")

            timestamp = time.time()
            message = rdf.newPublishMessage('uvccam', outTopic, vdefs.DATATYPE,
                                            timestamp)
            message[vdefs.WIDTH] = width
            message[vdefs.HEIGHT] = height
            message[vdefs.RATE] = rate
            if jpeg:
                message[vdefs.FORMAT] = 'mjpeg'
            else:
                message[vdefs.FORMAT] = 'raw'
            if ManifoldPython.isServiceActive(
                    sourcePort) and ManifoldPython.isClearToSend(sourcePort):
                ManifoldPython.sendMulticastData(sourcePort,
                                                 json.dumps(message), frame,
                                                 timestamp)

    except:
        print("Main loop error ", sys.exc_info()[0], sys.exc_info()[1])
Esempio n. 6
0
ManifoldPython.startConsoleInput()

print("Type characters to send:")

try:
    while True:
        time.sleep(0.001)
        processReceivedText()

        c = ManifoldPython.getConsoleInput()
        if c is None:
            continue

        timestamp = time.time()
        inMessage = rdf.newPublishMessage('ttytest', ttyOutTopic,
                                          'ttydatatype', timestamp)

        if ManifoldPython.isServiceActive(ttyOutPort):
            ManifoldPython.sendE2EData(ttyOutPort, json.dumps(inMessage),
                                       str(chr(c)), timestamp)

except:
    print("Main loop error", sys.exc_info()[0], sys.exc_info()[1])

# Exiting so clean everything up.

ManifoldPython.removeService(ttyInPort)
ManifoldPython.removeService(ttyOutPort)
ManifoldPython.stop()

print("Exiting")
Esempio n. 7
0
clientPort = ManifoldPython.addE2EClient(textTopic)
if (clientPort == -1):
    print("Failed to activate E2E client endpoint")
    ManifoldPython.stop()
    sys.exit()

# Activate the sink endpoint
sinkPort = ManifoldPython.addMulticastSink(completionTopic)
if (sinkPort == -1):
    print("Failed to activate multicast sink endpoint")
    ManifoldPython.stop()
    sys.exit()

lastSendTime = time.time()

textMessage = rdf.newPublishMessage('tts', textTopic, ttsdefs.DATATYPE, time.time())
textMessage[ttsdefs.TEXT] = testText

try:
    while(True):
        # main loop
        
        processCompletion()
        
        if gotCompletion:
            try:
                jsonObj = json.loads(completionToProcess)
                finished = jsonObj[ttscompletedefs.COMPLETE]
                print('Completion status: ' + str(finished))
                if finished:
                    waitForComplete = False
Esempio n. 8
0
imu.setCompassEnable(True)

if (not pressure.pressureInit()):
    print("Pressure sensor Init Failed")
else:
    print("Pressure sensor Init Succeeded")

if (not humidity.humidityInit()):
    print("Humidity sensor Init Failed")
else:
    print("Humidity sensor Init Succeeded")

poll_interval = imu.IMUGetPollInterval()
print("Recommended Poll Interval: %dmS\n" % poll_interval)

while True:
    time.sleep(poll_interval*1.0/1000.0)
    if imu.IMURead():
        timestamp = time.time()
        message = rdf.newPublishMessage('imu', outTopic, idefs.DATATYPE, timestamp)
        data = imu.getIMUData()
        (data["pressureValid"], data["pressure"], data["pressureTemperatureValid"], data["pressureTemperature"]) = pressure.pressureRead()
        (data["humidityValid"], data["humidity"], data["humidityTemperatureValid"], data["humidityTemperature"]) = humidity.humidityRead()
        message[idefs.DATA] = data
        if ManifoldPython.isServiceActive(outPort) and ManifoldPython.isClearToSend(outPort):
            ManifoldPython.sendMulticastData(outPort, json.dumps(message), '', timestamp)


ManifoldPython.removeService(outPort)
ManifoldPython.stop()