Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero authored and DigiH committed Feb 26, 2022
1 parent cb8966e commit 32d9adb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 33 deletions.
12 changes: 6 additions & 6 deletions docs/devices/XMTZC04HM.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Xiaomi MiScale V1
# Xiaomi Mi Smart Scale

|Model Id|[XMTZC04HM](https://github.com/theengs/decoder/blob/development/src/devices/XMTZC04HM_json.h)|
|Model Id|[XMTZC01HM/XMTZC04HM](https://github.com/theengs/decoder/blob/development/src/devices/XMTZC04HM_json.h)|
|-|-|
|Brand|Xiaomi|
|Model|MiScale V1|
|Short Description|First version of the scale|
|Model|Mi Smart Scale|
|Short Description|First (MI_SCALE) and second (MI SCALE2) version of the Mi Smart Scale|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power source|3 AAA|
|Exchanged data|unit, weight|
|Power source|4 AA/3 AAA|
|Exchanged data|weighing_mode, unit, weight|
|Encrypted|No|
17 changes: 16 additions & 1 deletion src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,29 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) {
cond_str = condition[i].as<const char*>();
}

if (i < condition.size() && cond_str != nullptr) {
unsigned int cond_size = condition.size();

if (i < cond_size && cond_str != nullptr) {
if (!match && *cond_str == '|') {
i++;
continue;
} else if (match && *cond_str == '&') {
i++;
match = false;
continue;
} else if (match) { // check for AND case before exit
while (i < cond_size && *cond_str != '&') {
if (!condition[++i].is<const char*>()) {
continue;
}
cond_str = condition[++i].as<const char*>();
}

if (i < condition.size() && cond_str != nullptr) {
i++;
match = false;
continue;
}
}
}
break;
Expand Down
43 changes: 30 additions & 13 deletions src/devices/XMTZC04HM_json.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
#include "common_props.h"

// A condition is done on the first character = 2 so as to verify if the weight is stabilized, the decoder doesn't decode weights that are not stabilized

const char* _XMTZC04HM_json = "{\"brand\":\"Xiaomi\",\"model\":\"Miscale_v1\",\"model_id\":\"XMTZC04HM\",\"condition\":[\"uuid\",\"contain\",\"181d\",\"&\",\"servicedata\",\"index\",0,\"2\"],\"properties\":{\"unit\":{\"condition\":[\"servicedata\",1,\"2\"],\"decoder\":[\"static_value\",\"kg\"]},\"weight\":{\"condition\":[\"servicedata\",1,\"2\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",2,4,true,false],\"post_proc\":[\"/\",200]},\"_unit\":{\"condition\":[\"servicedata\",1,\"3\"],\"decoder\":[\"static_value\",\"lb\"]},\"_weight\":{\"condition\":[\"servicedata\",1,\"3\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",2,4,true,false],\"post_proc\":[\"/\",100]}}}";
const char* _XMTZC04HM_json = "{\"brand\":\"Xiaomi\",\"model\":\"Mi_Smart_Scale\",\"model_id\":\"XMTZC01HM/XMTZC04HM\",\"condition\":[\"servicedata\",\"index\",0,\"2\",\"|\",\"servicedata\",\"index\",0,\"a\",\"|\",\"servicedata\",\"index\",0,\"6\",\"|\",\"servicedata\",\"index\",0,\"e\",\"&\",\"uuid\",\"contain\",\"181d\"],\"properties\":{\"weighing_mode\":{\"condition\":[\"servicedata\",0,\"2\",\"|\",\"servicedata\",0,\"a\"],\"decoder\":[\"static_value\",\"person\"]},\"_weighing_mode\":{\"condition\":[\"servicedata\",0,\"6\",\"|\",\"servicedata\",0,\"e\"],\"decoder\":[\"static_value\",\"object\"]},\"unit\":{\"condition\":[\"servicedata\",1,\"2\"],\"decoder\":[\"static_value\",\"kg\"]},\"_unit\":{\"condition\":[\"servicedata\",1,\"3\"],\"decoder\":[\"static_value\",\"lb\"]},\"weight\":{\"condition\":[\"servicedata\",1,\"2\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",2,4,true,false],\"post_proc\":[\"/\",200]},\"_weight\":{\"condition\":[\"servicedata\",1,\"3\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",2,4,true,false],\"post_proc\":[\"/\",100]}}}";
/*R""""(
{
"brand":"Xiaomi",
"model":"Miscale_v1",
"model_id":"XMTZC04HM",
"condition":["uuid", "contain", "181d", "&", "servicedata", "index", 0, "2"],
"model":"Mi_Smart_Scale",
"model_id":"XMTZC01HM/XMTZC04HM",
"condition":["servicedata", "index", 0, "2", "|", "servicedata", "index", 0, "a", "|", "servicedata", "index", 0, "6", "|", "servicedata", "index", 0, "e", "&", "uuid", "contain", "181d"],
"properties":{
"weighing_mode":{
"condition":["servicedata", 0, "2", "|", "servicedata", 0, "a"],
"decoder":["static_value", "person"]
},
"_weighing_mode":{
"condition":["servicedata", 0, "6", "|", "servicedata", 0, "e"],
"decoder":["static_value", "object"]
},
"unit":{
"condition":["servicedata", 1, "2"],
"decoder":["static_value", "kg"]
},
"_unit":{
"condition":["servicedata", 1, "3"],
"decoder":["static_value", "lb"]
},
"weight":{
"condition":["servicedata", 1, "2"],
"decoder":["value_from_hex_data", "servicedata", 2, 4, true, false],
"post_proc":["/", 200]
},
"_unit":{
"condition":["servicedata", 1, "3"],
"decoder":["static_value", "lb"]
},
"_weight":{
"condition":["servicedata", 1, "3"],
"decoder":["value_from_hex_data", "servicedata", 2, 4, true, false],
Expand All @@ -31,4 +35,17 @@ const char* _XMTZC04HM_json = "{\"brand\":\"Xiaomi\",\"model\":\"Miscale_v1\",\"
}
})"""";*/

const char* _XMTZC04HM_json_props = _common_weight_props;
const char* _XMTZC04HM_json_props = "{\"properties\":{\"weighing_mode\":{\"unit\":\"string\",\"name\":\"weighing_mode\"},\"weight\":{\"unit\":\"kg\",\"name\":\"weight\"}}}";
/*R""""(
{
"properties":{
"weighing_mode":{
"unit":"string",
"name":"weighing_mode"
},
"weight":{
"unit":"kg",
"name":"weight"
}
}
})"""";*/
11 changes: 0 additions & 11 deletions src/devices/common_props.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,4 @@ const char* _common_BVTH_props = "{\"properties\":{\"batt\":{\"unit\":\"%\",\"na
}
})"""";*/

const char* _common_weight_props = "{\"properties\":{\"weight\":{\"unit\":\"kg\",\"name\":\"weight\"}}}";
/*R""""(
{
"properties":{
"weight":{
"unit":"kg",
"name":"weight"
}
}
})"""";*/

#endif
13 changes: 11 additions & 2 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ const char* expected_mfg[] = {

const char* expected_uuid[] = {
"{\"brand\":\"Xiaomi\",\"model\":\"Miband\",\"model_id\":\"MiBand\",\"steps\":7842}",
"{\"brand\":\"Xiaomi\",\"model\":\"Miscale_v1\",\"model_id\":\"XMTZC04HM\",\"unit\":\"kg\",\"weight\":61.75}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi_Smart_Scale\",\"model_id\":\"XMTZC01HM/XMTZC04HM\",\"weighing_mode\":\"person\",\"unit\":\"kg\",\"weight\":61.75}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi_Smart_Scale\",\"model_id\":\"XMTZC01HM/XMTZC04HM\",\"weighing_mode\":\"object\",\"unit\":\"kg\",\"weight\":9.55}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi_Smart_Scale\",\"model_id\":\"XMTZC01HM/XMTZC04HM\",\"weighing_mode\":\"person\",\"unit\":\"kg\",\"weight\":61.75}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi_Smart_Scale\",\"model_id\":\"XMTZC01HM/XMTZC04HM\",\"weighing_mode\":\"object\",\"unit\":\"kg\",\"weight\":9.55}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi_Body_Composition_Scale\",\"model_id\":\"XMTZC02HM/XMTZC05HM\",\"weighing_mode\":\"person\",\"unit\":\"kg\",\"weight\":72.45,\"impedance\":503}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi_Body_Composition_Scale\",\"model_id\":\"XMTZC02HM/XMTZC05HM\",\"weighing_mode\":\"person\",\"unit\":\"kg\",\"weight\":72.45}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi_Body_Composition_Scale\",\"model_id\":\"XMTZC02HM/XMTZC05HM\",\"weighing_mode\":\"object\",\"unit\":\"kg\",\"weight\":5.1}",
Expand Down Expand Up @@ -222,7 +225,10 @@ TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
// uuid test input [test name] [uuid] [data source] [data]
const char* test_uuid[][4] = {
{"MiBand", "fee0", "servicedata", "a21e0000"},
{"Miscale", "0x181d", "servicedata", "223e30b207010708031f"},
{"Mi_Smart_Scale", "0x181d", "servicedata", "223e30e607020e10293a"},
{"Mi_Smart_Scale", "0x181d", "servicedata", "627607e607020e10293a"},
{"Mi_Smart_Scale", "0x181d", "servicedata", "a23e30e607020e10293a"},
{"Mi_Smart_Scale", "0x181d", "servicedata", "e27607e607020e10293a"},
{"Mi_Body_Scale_2", "0x181b", "servicedata", "0226e607020e10293af7019a38"},
{"Mi_Body_Scale_2", "0x181b", "servicedata", "0224e607020e10293a00009a38"},
{"Mi_Body_Scale_2", "0x181b", "servicedata", "0624e607020e10293a0000fc03"},
Expand All @@ -243,6 +249,9 @@ const char* test_uuid[][4] = {
TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
TheengsDecoder::BLE_ID_NUM::MIBAND,
TheengsDecoder::BLE_ID_NUM::XMTZC04HM,
TheengsDecoder::BLE_ID_NUM::XMTZC04HM,
TheengsDecoder::BLE_ID_NUM::XMTZC04HM,
TheengsDecoder::BLE_ID_NUM::XMTZC04HM,
TheengsDecoder::BLE_ID_NUM::XMTZC05HM,
TheengsDecoder::BLE_ID_NUM::XMTZC05HM,
TheengsDecoder::BLE_ID_NUM::XMTZC05HM,
Expand Down

0 comments on commit 32d9adb

Please sign in to comment.