Skip to content

Instantly share code, notes, and snippets.

@hertzg
Created September 22, 2024 05:46
Show Gist options
  • Save hertzg/b0b2253e6fc70dab7b7f84790b26abf0 to your computer and use it in GitHub Desktop.
Save hertzg/b0b2253e6fc70dab7b7f84790b26abf0 to your computer and use it in GitHub Desktop.
Etekcity Nutrition Scale reverse engineered imhex pattern language file
#pragma endian big
#pragma magic 0xFEEFC0A2
enum Type : u8 {
SET_UNIT = 0xc0,
SET_TARE = 0xc1,
SET_NUTRITION = 0xc2,
SET_AUTO_OFF = 0xc4,
MEASUREMENT = 0xd0,
UNIT_STATE = 0xd1,
TARE_STATE = 0xd3,
AUTO_OFF_STATE = 0xd5,
ERROR_STATE = 0xe0,
ITEM_STATE = 0xe4
};
struct t_u16_state {
u16 state;
};
struct t_u8_state {
u8 state;
};
struct t_bool_state {
bool state;
};
struct t_measurement {
bool isNegative;
u16 weight;
u8 unit;
bool stable;
};
struct t_set_nutrition {
u24 calories;
u24 caloriesFromFat;
u24 totalFat;
u24 stauratedFat;
u24 transFat;
u24 cholesterol;
u24 sodium;
u24 potassium;
u24 totalCarbs;
u24 dietaryFiber;
u24 sugars;
u24 protein;
};
struct t_packet {
char header[4];
Type type;
u8 length;
match(type) {
(Type::SET_UNIT | Type::SET_AUTO_OFF | Type::UNIT_STATE): t_u8_state;
(Type::ITEM_STATE | Type::TARE_STATE | Type::ERROR_STATE): t_bool_state;
(Type::SET_TARE): t_bool_state;
(Type::MEASUREMENT): t_measurement payload;
(Type::SET_NUTRITION): t_set_nutrition;
(_): char payload[length];
}
u8 checksum;
};
t_packet test @ 0x00;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment