From: Inga Stotland <inga.stotland@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, johan.hedberg@gmail.com,
luiz.dentz@gmail.com, Inga Stotland <inga.stotland@intel.com>
Subject: [PATCH BlueZ 2/2] test: Enable test-mesh to send raw vendor commands
Date: Wed, 17 Apr 2019 23:31:10 -0700 [thread overview]
Message-ID: <20190418063110.22237-2-inga.stotland@intel.com> (raw)
In-Reply-To: <20190418063110.22237-1-inga.stotland@intel.com>
This adds a sample vendor model to the first element of the
mesh node. A new menu entry allows to generate and send a raw
vendor command.
---
test/test-mesh | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/test/test-mesh b/test/test-mesh
index 02f52a269..7201669a8 100755
--- a/test/test-mesh
+++ b/test/test-mesh
@@ -73,6 +73,16 @@
# Set AppKey index to indicate which application key to use
# to encode outgoing messages: up to 3 hex digits
#
+# vendor-send
+# Allows to send an arbitrary endor message.
+# The destination is set based on previously executed "dest"
+# command (if not set, the outbound message will fail).
+# User is prompted to enter hex bytearray payload.
+# The message is originated from the vendor model registered
+# on element 0. For the command to succeed, the AppKey index
+# that is set by executing "app-key" must correspond to the
+# application key to which the Sample Vendor model is bound.
+#
# client-menu
# Enter On/Off client submenu.
#
@@ -155,6 +165,7 @@ INPUT_NONE = 0
INPUT_TOKEN = 1
INPUT_DEST_ADDRESS = 2
INPUT_APP_KEY_INDEX = 3
+INPUT_MESSAGE_PAYLOAD = 4
menus = []
current_menu = None
@@ -542,7 +553,6 @@ class OnOffServer(Model):
def process_message(self, source, key, data):
datalen = len(data)
- print('OnOff Server process message len: ', datalen)
if datalen != 2 and datalen != 3:
# The opcode is not recognized by this model
@@ -737,6 +747,8 @@ class MainMenu(Menu):
self.__cmd_set_dest),
'app-index': MenuItem(' - set AppKey index',
self.__cmd_set_app_idx),
+ 'vendor-send': MenuItem(' - send raw vendor message',
+ self.__cmd_vendor_msg),
'client-menu': MenuItem(' - On/Off client menu',
self.__cmd_client_menu),
'quit': MenuItem(' - exit the test', app_exit)
@@ -772,6 +784,12 @@ class MainMenu(Menu):
user_input = INPUT_APP_KEY_INDEX;
print(set_cyan('Enter app key index (up to 3 digit hex):'))
+ def __cmd_vendor_msg(self):
+ global user_input
+
+ user_input = INPUT_MESSAGE_PAYLOAD;
+ print(set_cyan('Enter message payload (hex):'))
+
def __cmd_join(self):
if agent == None:
print(set_error('Provisioning agent not found'))
@@ -806,6 +824,17 @@ class MainMenu(Menu):
mesh_net.Leave(token, reply_handler=remove_node_cb,
error_handler=generic_error_cb)
+ def __send_vendor_msg(self, str_value):
+ try:
+ msg_data = bytearray.fromhex(str_value)
+ except ValueError:
+ raise_error('Not a valid hexadecimal input')
+ return
+
+ print(set_yellow('Send data: ' + set_green(str_value)))
+ app.elements[0].models[1].send_message(dst_addr, app_idx,
+ msg_data)
+
def process_cmd(self, str_value):
global user_input
global dst_addr
@@ -825,6 +854,8 @@ class MainMenu(Menu):
app_idx = res
print(set_yellow("Application index: ") +
set_green(format(app_idx, '03x')))
+ elif user_input == INPUT_MESSAGE_PAYLOAD:
+ self.__send_vendor_msg(str_value)
if user_input != INPUT_NONE:
user_input = INPUT_NONE
--
2.17.2
next prev parent reply other threads:[~2019-04-18 6:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-18 6:31 [PATCH BlueZ 1/2] test: Drive test-mesh with a string-based menu Inga Stotland
2019-04-18 6:31 ` Inga Stotland [this message]
2019-04-19 16:10 ` Gix, Brian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190418063110.22237-2-inga.stotland@intel.com \
--to=inga.stotland@intel.com \
--cc=brian.gix@intel.com \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).