Skip to content

Commit

Permalink
Merge pull request #5 from Circuitsoft/master
Browse files Browse the repository at this point in the history
Fix serial comms
Packet queue change already reverted
  • Loading branch information
Circuitsoft authored Oct 12, 2017
2 parents 5f84437 + 51814b7 commit cf114cd
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 153 deletions.
48 changes: 24 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ USE_DFU ?= "no"
# Define relative paths to SDK components
#------------------------------------------------------------------------------

SDK_BASE := /Users/pete/dev/nrf_sdk
ifeq ($(shell uname),Linux)
RFD_LOADER = $(SIMBLEE_BASE)/RFDLoader_linux
ARDUINO_BASE := $(HOME)/.arduino15
SERIAL_PORT := /dev/ttyUSB0
else
RFD_LOADER = $(SIMBLEE_BASE)/RFDLoader_osx
ARDUINO_BASE := $(HOME)/Library/Arduino15
#SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # left
SERIAL_PORT := /dev/cu.usbserial-DN00D34P # right
#SERIAL_PORT := /dev/cu.usbserial-A105RB12
#SERIAL_PORT := /dev/cu.usbserial-FTZ86FTC # tag-connect
#SERIAL_PORT := /dev/cu.usbserial-DO00C2G2 # Breadboard setup
endif

SDK_BASE := ../nRF51_SDK_8.1.0_b6ed55f
COMPONENTS := $(SDK_BASE)/components
TEMPLATE_PATH := $(COMPONENTS)/toolchain/gcc
SIMBLEE_BASE := /Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2
RBC_MESH := rbc_mesh

SIMBLEE_BASE := $(ARDUINO_BASE)/packages/Simblee/hardware/Simblee/1.1.2
RBC_MESH := rbc_mesh

LINKER_SCRIPT := $(SIMBLEE_BASE)/variants/Simblee/linker_scripts/gcc/Simblee.ld
RFD_LOADER := $(SIMBLEE_BASE)/RFDLoader_osx
#SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # left
SERIAL_PORT := /dev/cu.usbserial-DN00D34P # right
#SERIAL_PORT := /dev/cu.usbserial-A105RB12
#SERIAL_PORT := /dev/cu.usbserial-FTZ86FTC # tag-connect
#SERIAL_PORT := /dev/cu.usbserial-DO00C2G2 # Breadboard setup

ifeq ($(USE_RBC_MESH_SERIAL), "yes")
SERIAL_STRING := "_serial"
Expand All @@ -42,9 +49,7 @@ endif

OUTPUT_NAME := rbc_mesh$(SERIAL_STRING)$(DFU_STRING)_$(TARGET_BOARD)


GNU_INSTALL_ROOT := /usr/local
GNU_VERSION := 4.9.3
GNU_INSTALL_ROOT := $(ARDUINO_BASE)/packages/Simblee/tools/arm-none-eabi-gcc/4.8.3-2014q1
GNU_PREFIX := arm-none-eabi

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -72,6 +77,7 @@ endif

# Toolchain commands
CC := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
CXX := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-g++"
AS := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
Expand Down Expand Up @@ -115,7 +121,6 @@ ifeq ($(USE_DFU), "yes")
C_SOURCE_FILES += $(RBC_MESH)/src/nrf_flash.c
endif


C_SOURCE_FILES += $(RBC_MESH)/src/radio_control.c
C_SOURCE_FILES += $(RBC_MESH)/src/rbc_mesh.c
C_SOURCE_FILES += $(RBC_MESH)/src/timer.c
Expand Down Expand Up @@ -146,7 +151,6 @@ vpath %.c $(C_PATHS)

ARDUINO_CORE = arduino_core/core.a


# includes common to all targets

INC_PATHS += -Isrc
Expand Down Expand Up @@ -177,11 +181,11 @@ INC_PATHS += -I$(COMPONENTS)/softdevice/s110/headers
INC_PATHS += -I$(COMPONENTS)/drivers_nrf/hal
INC_PATHS += -I$(COMPONENTS)/drivers_nrf/spi_slave

CXX_INC_PATHS += -I/Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2/cores/arduino
CXX_INC_PATHS += -I/Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2/variants/Simblee
CXX_INC_PATHS += -I/Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2/system/Simblee
CXX_INC_PATHS += -I/Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2/system/Simblee/include
CXX_INC_PATHS += -I/Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2/system/CMSIS/CMSIS/Include
CXX_INC_PATHS += -I$(SIMBLEE_BASE)/cores/arduino
CXX_INC_PATHS += -I$(SIMBLEE_BASE)/variants/Simblee
CXX_INC_PATHS += -I$(SIMBLEE_BASE)/system/Simblee
CXX_INC_PATHS += -I$(SIMBLEE_BASE)/system/Simblee/include
CXX_INC_PATHS += -I$(SIMBLEE_BASE)/system/CMSIS/CMSIS/Include

OBJECT_DIRECTORY = _build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
Expand Down Expand Up @@ -213,17 +217,13 @@ CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin


# -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin -MMD -mcpu=cortex-m0
# -DF_CPU=16000000 -DARDUINO=10801 -D__PROJECT__="ledtest.ino" -mthumb -D__Simblee__

CXXFLAGS += -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti
CXXFLAGS += -fno-exceptions -fno-builtin -MMD -mcpu=cortex-m0 -DF_CPU=16000000
CXXFLAGS += -DARDUINO=10801 -mthumb -D__Simblee__

#CXX := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-g++"
CXX := "/Users/pete/Library/Arduino15/packages/Simblee/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++"

LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_NAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
Expand Down
85 changes: 50 additions & 35 deletions pyaci/aci/AciCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def __init__(self, OpCode, data=[], length = 1):
self.OpCode = OpCode
self.Data = data
if length != (len(self.Data) + 1):
logging.error("Length: %d, must be equal to the number of data items: %s plus 1 (for the opcode)",self.Len, str(self.Data))
logging.error("Length: %d, must be equal to the number of data items:" \
+ " %s plus 1 (for the opcode)", self.Len, str(self.Data))

def serialize(self):
pkt = [self.Len]
Expand All @@ -48,131 +49,145 @@ def serialize(self):
return pkt

def __repr__(self):
return str.format("I am %s and my Length is %d, OpCode is 0x%02x and Data is %s" %(self.__class__.__name__, self.Len, self.OpCode, self.Data))
return "I am %s and my Length is %d, OpCode is 0x%02x and Data is %s" % (
self.__class__.__name__, self.Len, self.OpCode, self.Data)

class AciEcho(AciCommandPkt):
OpCode = 0x02
MAX_ECHO_LENGTH = 30
def __init__(self, data=[], length=1):
if length > self.MAX_ECHO_LENGTH:
logging.error("ECHO command can have a maximum of %d byte packet size (including the opcode), not %d",MAX_ECHO_LENGTH,length)
logging.error("ECHO command can have a maximum of %d byte packet size" \
+ " (including the opcode), not %d", MAX_ECHO_LENGTH, length)
else:
super(AciEcho, self).__init__(length=length,OpCode=self.OpCode, data = data)
super(AciEcho, self).__init__(length=length, OpCode=self.OpCode, data=data)

class AciRadioReset(AciCommandPkt):
OpCode = 0x0E
Length = 1
def __init__(self):
super(AciRadioReset, self).__init__(length=self.Length,OpCode=self.OpCode)
super(AciRadioReset, self).__init__(length=self.Length, OpCode=self.OpCode)

class AciAppCommand(AciCommandPkt):
OpCode = 0x1A
MAX_CMD_LENGTH = 28
def __init__(self, data=[], length=1):
if length > self.MAX_CMD_LENGTH:
logging.error("App commands can have a maximum of %d byte packet size (including the opcode), not %d",MAX_CMD_LENGTH,length)
logging.error("App commands can have a maximum of %d byte packet size " \
+ "(including the opcode), not %d", MAX_CMD_LENGTH, length)
else:
super(AciAppCommand, self).__init__(length=length,OpCode=self.OpCode, data = data)
super(AciAppCommand, self).__init__(length=length, OpCode=self.OpCode,
data=data)

class AciInit(AciCommandPkt):
OpCode = 0x70
Length = 10
def __init__(self, access_address, min_interval, channel):
payload = valueToByteArray(access_address,4)
payload.extend(valueToByteArray(min_interval,4))
payload.extend(valueToByteArray(channel,1))
super(AciInit, self).__init__(length=self.Length,OpCode=self.OpCode, data=payload)
payload = valueToByteArray(access_address, 4)
payload.extend(valueToByteArray(min_interval, 4))
payload.extend(valueToByteArray(channel, 1))
super(AciInit, self).__init__(length=self.Length, OpCode=self.OpCode,
data=payload)

class AciValueSet(AciCommandPkt):
OpCode = 0x71
MAX_VAL_LENGTH = 26
def __init__(self, handle, data, length=3):
if length > self.MAX_VAL_LENGTH:
logging.error("VALUE_SET command can have a maximum of %d byte packet size (including the opcode), not %d",MAX_VAL_LENGTH,length)
logging.error("VALUE_SET command can have a maximum of %d byte packet size" \
+ " (including the opcode), not %d", MAX_VAL_LENGTH, length)
else:
payload = valueToByteArray(handle,2)
payload = valueToByteArray(handle, 2)
payload.extend(data)
super(AciValueSet, self).__init__(length=length, OpCode=self.OpCode, data=payload)
super(AciValueSet, self).__init__(length=length, OpCode=self.OpCode,
data=payload)

class AciValueEnable(AciCommandPkt):
OpCode = 0x72
Length = 3
def __init__(self, handle):
payload = valueToByteArray(handle,2)
super(AciValueEnable, self).__init__(length=self.Length, OpCode=self.OpCode, data=payload)
payload = valueToByteArray(handle, 2)
super(AciValueEnable, self).__init__(length=self.Length, OpCode=self.OpCode,
data=payload)

class AciValueDisable(AciCommandPkt):
OpCode = 0x73
Length = 3
def __init__(self, handle):
payload = valueToByteArray(handle,2)
super(AciValueDisable, self).__init__(length=self.Length, OpCode=self.OpCode, data=payload)
payload = valueToByteArray(handle, 2)
super(AciValueDisable, self).__init__(length=self.Length, OpCode=self.OpCode,
data=payload)

class AciStart(AciCommandPkt):
OpCode = 0x74
Length = 1
def __init__(self):
super(AciStart, self).__init__(length=self.Length,OpCode=self.OpCode)
super(AciStart, self).__init__(length=self.Length, OpCode=self.OpCode)

class AciStop(AciCommandPkt):
OpCode = 0x75
Length = 1
def __init__(self):
super(AciStop, self).__init__(length=self.Length,OpCode=self.OpCode)
super(AciStop, self).__init__(length=self.Length, OpCode=self.OpCode)

class AciFlagSet(AciCommandPkt):
OpCode = 0x76
Length = 5
def __init__(self, handle, flag_index, flag_value):
payload = valueToByteArray(handle,2)
payload.extend(valueToByteArray(flag_index,1))
payload.extend(valueToByteArray(flag_value,1))
super(AciFlagSet, self).__init__(length=self.Length,OpCode=self.OpCode, data=payload)
payload = valueToByteArray(handle, 2)
payload.extend(valueToByteArray(flag_index, 1))
payload.extend(valueToByteArray(flag_value, 1))
super(AciFlagSet, self).__init__(length=self.Length, OpCode=self.OpCode,
data=payload)

class AciFlagGet(AciCommandPkt):
OpCode = 0x77
Length = 4
def __init__(self, handle, flag_index):
payload = valueToByteArray(handle,2)
payload.extend(valueToByteArray(flag_index,1))
super(AciFlagGet, self).__init__(length=self.Length,OpCode=self.OpCode, data=payload)
payload = valueToByteArray(handle, 2)
payload.extend(valueToByteArray(flag_index, 1))
super(AciFlagGet, self).__init__(length=self.Length, OpCode=self.OpCode,
data=payload)

class AciDfuData(AciCommandPkt):
OpCode = 0x78
MAX_DFU_LENGTH = 26
def __init__(self, data=[], length=1):
if length > self.MAX_DFU_LENGTH:
logging.error("DFU_DATA command can have a maximum of %d byte packet size (including the opcode), not %d",MAX_DFU_LENGTH,length)
logging.error("DFU_DATA command can have a maximum of %d byte packet size " \
+ "(including the opcode), not %d", MAX_DFU_LENGTH, length)
else:
super(AciDfuData, self).__init__(length=length,OpCode=self.OpCode, data = data)
super(AciDfuData, self).__init__(length=length, OpCode=self.OpCode,
data=data)

class AciValueGet(AciCommandPkt):
OpCode = 0x7A
Length = 3
def __init__(self, handle):
payload = valueToByteArray(handle,2)
super(AciValueGet, self).__init__(length=self.Length, OpCode=self.OpCode, data=payload)
payload = valueToByteArray(handle, 2)
super(AciValueGet, self).__init__(length=self.Length, OpCode=self.OpCode,
data=payload)

class AciBuildVersionGet(AciCommandPkt):
OpCode = 0x7B
Length = 1
def __init__(self):
super(AciBuildVersionGet, self).__init__(length=self.Length,OpCode=self.OpCode)
super(AciBuildVersionGet, self).__init__(length=self.Length, OpCode=self.OpCode)

class AciAccessAddressGet(AciCommandPkt):
OpCode = 0x7C
Length = 1
def __init__(self):
super(AciAccessAddressGet, self).__init__(length=self.Length,OpCode=self.OpCode)
super(AciAccessAddressGet, self).__init__(length=self.Length, OpCode=self.OpCode)

class AciChannelGet(AciCommandPkt):
OpCode = 0x7D
Length = 1
def __init__(self):
super(AciChannelGet, self).__init__(length=self.Length,OpCode=self.OpCode)
super(AciChannelGet, self).__init__(length=self.Length, OpCode=self.OpCode)

class AciIntervalMinMsGet(AciCommandPkt):
OpCode = 0x7F
Length = 1
def __init__(self):
super(AciIntervalMinMsGet, self).__init__(length=self.Length,OpCode=self.OpCode)
super(AciIntervalMinMsGet, self).__init__(length=self.Length, OpCode=self.OpCode)
Loading

0 comments on commit cf114cd

Please sign in to comment.