import time

from .lcm_patterns import Publisher
from .channels import app_control_t, environmental_t


def create_environ_msg():
    msg = environmental_t()
    msg.timestamp = int(time.time() * 1000000)
    msg.temp = 32.0
    msg.pressure = 101400.5
    return msg

def create_control_msg():
    msg = app_control_t()
    msg.run_flag = True
    return msg

lcm = Publisher()           # instantiate the publisher

environ_msg = create_environ_msg()
control_msg = create_control_msg()

for n in range(10):
    time.sleep(0.25)
    lcm.publish("ENVIRONMENTAL", environ_msg)
    time.sleep(0.25)
    lcm.publish("ENVIRONMENTAL", environ_msg)    
    lcm.publish("APP_CONTROL", control_msg)

time.sleep(1)

control_msg.run_flag = False
lcm.publish("CONTROL", control_msg)
