Skip to content

Commit

Permalink
Set mesh control
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed Jun 7, 2017
1 parent e79593c commit e2ab237
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
19 changes: 19 additions & 0 deletions pyaci/interactive_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from queue import *
import time
import sensei_cmd
import struct

class Interactive(object):
def __init__(self, acidev):
Expand Down Expand Up @@ -91,6 +92,24 @@ def setTime(self):
def setConfig(self, sensor_id, serial_enabled, mesh_channel, sleep_enabled):
self.runCommand(sensei_cmd.SetConfig(sensor_id, serial_enabled, mesh_channel, sleep_enabled))

def setMeshControl(self, wake_interval, tx_power, ble_enabled):
power_levels = {
0: 0x00,
4: 0x04,
-30: 0xD8,
-20: 0xEC,
-16: 0xF0,
-12: 0xF4,
-8: 0xF8,
-4: 0xFC
}
power_code = power_levels.get(tx_power)
if tx_power == None:
raise Exception("Bad tx power level specified: %s" % tx_power)

data = struct.pack("<HBB", wake_interval, power_code, ble_enabled)
self.ValueSet(sensei_cmd.MESH_HANDLE_MESH_CONTROL, data)

def getConfig(self):
self.runCommand(sensei_cmd.GetConfig())

Expand Down
3 changes: 2 additions & 1 deletion pyaci/sensei_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time
import struct

MESH_HANDLE_MESH_CONTROL = 0x0201

class SetTime(object):
OpCode = 0x02

Expand All @@ -25,7 +27,6 @@ def __init__(self, sensor_id=0, serial_enabled=False, mesh_channel=38, sleep_ena
self.mesh_channel = mesh_channel
self.sleep_enabled = sleep_enabled


def serialize(self):
return struct.pack("BBBBB", self.OpCode, self.sensor_id, self.serial_enabled, self.mesh_channel, self.sleep_enabled)

Expand Down
6 changes: 0 additions & 6 deletions pyaci/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class Uploader(object):
TIME_SYNC_INTERVAL=60
NO_DATA_TIMEOUT=35

MESH_HANDLE_MESH_CONTROL = 0x0201

def __init__(self, sensei_config, options):
self.sensei_config = sensei_config
self.options = options
Expand Down Expand Up @@ -64,10 +62,6 @@ def sync_time(self):
def get_config(self):
return self.run_app_command(sensei_cmd.GetConfig())

def set_mesh_control(self, wake_interval):
data = struct.pack("<HB", wake_interval, 0)
self.aci.ValueSet(MESH_HANDLE_MESH_CONTROL, data)

def radio_obs_from_update(self, update):
if not update.is_valid:
return []
Expand Down

0 comments on commit e2ab237

Please sign in to comment.