aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-10-28 09:10:22 +0200
committerSven Gothel <[email protected]>2023-10-28 09:10:22 +0200
commit1ce1f5f8eb4109a8503fb38212a0d2b62353b921 (patch)
tree3a36ac8c268cd75f7eba3bea2232fb3ef2b1b7c8
parent804136e0f824c6b418a5cf046e06003c6cce30c2 (diff)
Complete LabPad example with full BTGattCmd test validation
-rw-r--r--examples/dbt_labpadclient01.cpp76
-rw-r--r--examples/java/DBTLabPadClient01.java75
2 files changed, 110 insertions, 41 deletions
diff --git a/examples/dbt_labpadclient01.cpp b/examples/dbt_labpadclient01.cpp
index 16e8d22c..f051e61a 100644
--- a/examples/dbt_labpadclient01.cpp
+++ b/examples/dbt_labpadclient01.cpp
@@ -92,10 +92,23 @@ static bool KEEP_CONNECTED = true;
static bool GATT_PING_ENABLED = false;
static bool REMOVE_DEVICE = true;
-// Default from dbt_peripheral00.cpp or DBTPeripheral00.java
-static std::unique_ptr<uuid_t> cmd_uuid = nullptr; // jau::uuid_t::create(std::string("d0ca6bf3-3d52-4760-98e5-fc5883e93712"));
-static std::unique_ptr<uuid_t> cmd_rsp_uuid = nullptr; // jau::uuid_t::create(std::string("d0ca6bf3-3d53-4760-98e5-fc5883e93712"));
-static uint8_t cmd_arg = 0x44;
+// Avalun's LabPad Comman + Event UUID
+static std::unique_ptr<uuid_t> cmd_req_uuid = jau::uuid_t::create(std::string("2c1b2472-4a5f-11e5-9595-0002a5d5c51b"));
+static std::unique_ptr<uuid_t> cmd_rsp_uuid = jau::uuid_t::create(std::string("2c1b2473-4a5f-11e5-9595-0002a5d5c51b"));
+
+static const POctets cmd_data1( { 0x00 /* cmd-idx-0 */,
+ 0x14, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00,
+ 0x01, 0x5E, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
+ 0x9B, 0x23, 0x84 }, endian::little);
+
+static const POctets cmd_data2( { 0x01 /* cmd-idx-1 */,
+ 0xB8 }, endian::little);
+
+static const POctets resp_exp( { 0x00 /* rsp-idx-0 */,
+ 0x14, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00,
+ 0x01, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xf6, 0x64, 0x17,
+ 0x01 /* rsp-idx-1 */, 0xed }, endian::little );
static bool SHOW_UPDATE_EVENTS = false;
static bool QUIET = false;
@@ -470,28 +483,49 @@ static void processReadyDevice(const BTDeviceRef& device) {
td13, td12, td23, td35);
}
- if( nullptr != cmd_uuid ) {
- BTGattCmd cmd = nullptr != cmd_rsp_uuid ? BTGattCmd(*device, "TestCmd", *cmd_uuid, *cmd_rsp_uuid, 256)
- : BTGattCmd(*device, "TestCmd", *cmd_uuid);
+ {
+ const jau::nsize_t response_size = resp_exp.size();
+ int fail_point = 0;
+ BTGattCmd cmd = BTGattCmd(*device, "TestCmd", *cmd_req_uuid, *cmd_rsp_uuid, 256);
cmd.setVerbose(true);
- const bool cmd_resolved = cmd.isResolved();
- fprintf_td(stderr, "Command test: %s, resolved %d\n", cmd.toString().c_str(), cmd_resolved);
- POctets cmd_data(1, endian::little);
- cmd_data.put_uint8_nc(0, cmd_arg);
- const HCIStatusCode cmd_res = cmd.send(true /* prefNoAck */, cmd_data, 3_s);
- if( HCIStatusCode::SUCCESS == cmd_res ) {
- if( cmd.hasResponseSet() ) {
+ HCIStatusCode cmd_res = cmd.isResolved() ? HCIStatusCode::SUCCESS : HCIStatusCode::INTERNAL_FAILURE;
+ if( HCIStatusCode::SUCCESS != cmd_res ) {
+ fail_point = 1;
+ } else {
+ cmd.setResponseMinSize(response_size);
+ cmd.setDataCallback( [](BTGattCharRef, const jau::TROOctets& char_value, const uint64_t) {
+ fprintf_td(stderr, "Received: %s\n", char_value.toString().c_str());
+ });
+ fprintf_td(stderr, "Command test: %s\n", cmd.toString().c_str());
+ cmd_res = cmd.sendOnly(true, cmd_data1);
+ }
+ if( HCIStatusCode::SUCCESS != cmd_res ) {
+ fail_point = 2;
+ } else {
+ cmd_res = cmd.send(true, cmd_data2, 3_s);
+ }
+ if( HCIStatusCode::SUCCESS != cmd_res ) {
+ fail_point = 3;
+ } else {
+ if( !cmd.hasResponseSet() ) {
+ fail_point = 4;
+ } else {
const jau::TROOctets& resp = cmd.getResponse();
- if( 1 == resp.size() && resp.get_uint8_nc(0) == cmd_arg ) {
- fprintf_td(stderr, "Success: %s -> %s (echo response)\n", cmd.toString().c_str(), resp.toString().c_str());
+ if( response_size != resp.size() ) {
+ fail_point = 5;
+ fprintf_td(stderr, "Failure: %s -> %s (response size)\n", cmd.toString().c_str(), resp.toString().c_str());
+ } else if( resp_exp != resp ) {
+ fail_point = 6;
+ fprintf_td(stderr, "Failure: %s (response content)\n", cmd.toString().c_str());
+ fprintf_td(stderr, "- exp %s\n", resp_exp.toString().c_str());
+ fprintf_td(stderr, "- has %s\n", resp.toString().c_str());
} else {
- fprintf_td(stderr, "Success: %s -> %s (different response)\n", cmd.toString().c_str(), resp.toString().c_str());
+ fprintf_td(stderr, "Success: %s -> %s\n", cmd.toString().c_str(), resp.toString().c_str());
}
- } else {
- fprintf_td(stderr, "Success: %s -> no response\n", cmd.toString().c_str());
}
- } else {
- fprintf_td(stderr, "Failure: %s -> %s\n", cmd.toString().c_str(), to_string(cmd_res).c_str());
+ }
+ if( 0 != fail_point ) {
+ fprintf_td(stderr, "Failure: point %u: %s -> %s\n", fail_point, cmd.toString().c_str(), to_string(cmd_res).c_str());
}
}
diff --git a/examples/java/DBTLabPadClient01.java b/examples/java/DBTLabPadClient01.java
index cb6564b7..adae7374 100644
--- a/examples/java/DBTLabPadClient01.java
+++ b/examples/java/DBTLabPadClient01.java
@@ -104,10 +104,23 @@ public class DBTLabPadClient01 {
boolean GATT_PING_ENABLED = false;
boolean REMOVE_DEVICE = true;
- // Default from dbt_peripheral00.cpp or DBTPeripheral00.java
- String cmd_uuid = null; // "d0ca6bf3-3d52-4760-98e5-fc5883e93712";
- String cmd_rsp_uuid = null; // "d0ca6bf3-3d53-4760-98e5-fc5883e93712";
- byte cmd_arg = (byte)0x44;
+ // Avalun's LabPad Comman + Event UUID
+ static String cmd_req_uuid = "2c1b2472-4a5f-11e5-9595-0002a5d5c51b";
+ static String cmd_rsp_uuid = "2c1b2473-4a5f-11e5-9595-0002a5d5c51b";
+
+ static final byte[] cmd_data1 = { 0x00 /* cmd-idx-0 */,
+ 0x14, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00,
+ 0x01, 0x5E, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
+ (byte)0x9B, (byte)0x23, (byte)0x84 };
+
+ static final byte[] cmd_data2 = { 0x01 /* cmd-idx-1 */,
+ (byte)0xB8 };
+
+ static final byte[] resp_exp = { 0x00 /* rsp-idx-0 */,
+ 0x14, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00,
+ 0x01, (byte)0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ (byte)0xf6, 0x64, 0x17,
+ 0x01 /* rsp-idx-1 */, (byte)0xed };
boolean SHOW_UPDATE_EVENTS = false;
boolean QUIET = false;
@@ -503,27 +516,49 @@ public class DBTLabPadClient01 {
"PERF: get-gatt-services " + td35 + " ms,"+System.lineSeparator());
}
- if( null != cmd_uuid ) {
- final BTGattCmd cmd = null != cmd_rsp_uuid ? new BTGattCmd(device, "TestCmd", null /* service_uuid */, cmd_uuid, cmd_rsp_uuid)
- : new BTGattCmd(device, "TestCmd", null /* service_uuid */, cmd_uuid);
+ {
+ final int response_size = resp_exp.length;
+ int fail_point = 0;
+ final BTGattCmd cmd = new BTGattCmd(device, "TestCmd", null /* service_uuid */, cmd_req_uuid, cmd_rsp_uuid);
cmd.setVerbose(true);
- final boolean cmd_resolved = cmd.isResolved();
- PrintUtil.println(System.err, "Command test: "+cmd.toString()+", resolved "+cmd_resolved);
- final byte[] cmd_data = { cmd_arg };
- final HCIStatusCode cmd_res = cmd.send(true /* prefNoAck */, cmd_data, 3000 /* timeoutMS */);
- if( HCIStatusCode.SUCCESS == cmd_res ) {
- if( cmd.hasResponseSet() ) {
+ HCIStatusCode cmd_res = cmd.isResolved() ? HCIStatusCode.SUCCESS : HCIStatusCode.INTERNAL_FAILURE;
+ if( HCIStatusCode.SUCCESS != cmd_res ) {
+ fail_point = 1;
+ } else {
+ cmd.setResponseMinSize(response_size);
+ cmd.setDataCallback( (final BTGattChar charDecl, final byte[] value, final long timestampMS) -> {
+ PrintUtil.fprintf_td(System.err, "Received: size %d, %s\n", value.length, BasicTypes.bytesHexString(value, 0, -1, true));
+ });
+ PrintUtil.println(System.err, "Command test: "+cmd.toString());
+ cmd_res = cmd.sendOnly(true /* prefNoAck */, cmd_data1);
+ }
+ if( HCIStatusCode.SUCCESS != cmd_res ) {
+ fail_point = 2;
+ } else {
+ cmd_res = cmd.send(true /* prefNoAck */, cmd_data2, 3000 /* timeoutMS */);
+ }
+ if( HCIStatusCode.SUCCESS != cmd_res ) {
+ fail_point = 3;
+ } else {
+ if( !cmd.hasResponseSet() ) {
+ fail_point = 4;
+ } else {
final byte[] resp = cmd.getResponse();
- if( 1 == resp.length && resp[0] == cmd_arg ) {
- PrintUtil.fprintf_td(System.err, "Success: %s -> %s (echo response)\n", cmd.toString(), BasicTypes.bytesHexString(resp, 0, resp.length, true /* lsb */));
+ if( response_size != resp.length ) {
+ fail_point = 5;
+ PrintUtil.fprintf_td(System.err, "Success: %s -> %s (response size)\n", cmd.toString(), BasicTypes.bytesHexString(resp, 0, resp.length, true /* lsb */));
+ } else if( !Arrays.equals(resp_exp, resp) ) {
+ fail_point = 6;
+ PrintUtil.fprintf_td(System.err, "Failure: %s (response content)\n", cmd.toString());
+ PrintUtil.fprintf_td(System.err, "- exp %s\n", BasicTypes.bytesHexString(resp_exp, 0, resp_exp.length, true /* lsb */));
+ PrintUtil.fprintf_td(System.err, "- has %s\n", BasicTypes.bytesHexString(resp, 0, resp.length, true /* lsb */));
} else {
- PrintUtil.fprintf_td(System.err, "Success: %s -> %s (different response)\n", cmd.toString(), BasicTypes.bytesHexString(resp, 0, resp.length, true /* lsb */));
+ PrintUtil.fprintf_td(System.err, "Success: %s -> %s\n", cmd.toString(), BasicTypes.bytesHexString(resp, 0, resp.length, true /* lsb */));
}
- } else {
- PrintUtil.fprintf_td(System.err, "Success: %s -> no response\n", cmd.toString());
}
- } else {
- PrintUtil.fprintf_td(System.err, "Failure: %s -> %s\n", cmd.toString(), cmd_res.toString());
+ }
+ if( 0 != fail_point ) {
+ PrintUtil.fprintf_td(System.err, "Failure: point %d: %s -> %s\n", fail_point, cmd.toString(), cmd_res.toString());
}
cmd.close();
}