Changeset - d1142fbbace4
[Not reviewed]
default
0 0 3
matthewreed - 10 years ago 2016-02-28 18:42:47

first commit
3 files changed with 76 insertions and 0 deletions:
0 comments (0 inline, 0 general)
hydrobot.py
Show inline comments
 
new file 100644
 
import sys
 
from phant import Phant
 
from canard import can, bus
 
from canard.hw import socketcan
 
from canard.file import jsondb
 

	
 
p = Phant(jsonPath='keys_m3KwkGKYoxsrqoxpDePxhj8660L.json')
 

	
 
parser = jsondb.JsonDbParser()
 
b = parser.parse('hydrobot_can.json')
 
temp_msg = b.get_message("AirTemp")
 

	
 
dev = socketcan.SocketCanDev("can0")
 
dev.start()
 

	
 
while True:
 
    frame = dev.recv()
 
    print(frame)
 
    
 
    signals = b.parse_frame(frame)
 
    if signals:
 
        for s in signals:
 
            print(s)
 
            print(s.value)
 
    
 
    temp = temp_msg.get_signal("Temperature").value
 
    humid = temp_msg.get_signal("Humidity").value
 
    press = temp_msg.get_signal("Pressure").value
 
    
 
    p.log(humid, press, temp)
 
    print(p.remaining_bytes, p.cap)
 

	
hydrobot_can.json
Show inline comments
 
new file 100644
 

	
 
{
 
    "messages": [
 
        {
 
        "name": "AirTemp",
 
        "id": "0x100",
 
        "signals": {"0": {"name": "Temperature", "bit_length": 16, "factor": 0.1, "offset": -40, "unit": "C"},
 
                    "16": {"name": "Humidity", "bit_length": 16, "factor": 0.01, "offset": 0, "unit": "%"},
 
                    "32": {"name": "Pressure", "bit_length": 16, "factor": 0.1, "offset": 0, "unit": "kPa"}
 
                   }
 
        }
 
    ]
 
}
hydrobot_sensor_sim.py
Show inline comments
 
new file 100644
 
import time
 
import random
 
from canard import can, bus
 
from canard.hw import socketcan
 
from canard.file import jsondb
 

	
 
parser = jsondb.JsonDbParser()
 
b = parser.parse('hydrobot_can.json')
 

	
 
dev = socketcan.SocketCanDev("can1")
 
dev.start()
 

	
 
temp = 65.5
 
humid = 0.90
 
press = 100
 

	
 
while True:
 
    
 
    temp = max(0x00, min(0xFF, random.randint(-1, 1)/2 + temp))
 
    humid = max(0x00, min(0xFF, random.randint(-1, 1)/100 + humid))
 
    press = max(0x00, min(0xFF, random.randint(-1, 1) + press))
 
    
 
    message = b.get_message("AirTemp")
 
    message.get_signal("Temperature").value = temp
 
    message.get_signal("Humidity").value = humid
 
    message.get_signal("Pressure").value = press
 
    
 
    frame = b.build_frame("AirTemp")
 
    dev.send(frame)
 
    
 
    time.sleep(1)
0 comments (0 inline, 0 general)