8 const uint8_t
START_PACKET[5] = {0x00, 0xff, 0x00, 0x00, 0x9a};
13 for (
int i = 0; i <
len; i++)
14 sprintf(&buf[i * 2],
"%02x", data[i]);
15 std::string ret = buf;
21 return this->
encode_(0xA2, &data, 1);
26 return this->
encode_(0xAA, &data, 1);
31 return this->
encode_(CMD_GET_POSITION, &data, 1);
36 data[0] = (pin & 0xFF00) >> 8;
38 return this->
encode_(CMD_SEND_PIN, data, 2);
43 return this->
encode_(CMD_SET_STATE, &data, 1);
48 return this->
encode_(CMD_SET_STATE, &data, 1);
53 return this->
encode_(CMD_SET_STATE, &data, 1);
57 return this->
encode_(CMD_SET_POSITION, &position, 1);
65 this->packet_.data[i] = checksum ^ 0xff;
66 this->packet_.length++;
80 #define VERIFY_MIN_LENGTH(x) \ 85 this->has_battery_level_ =
false;
86 this->has_light_level_ =
false;
87 this->has_set_position_response_ =
false;
88 this->has_set_state_response_ =
false;
89 this->has_position_ =
false;
90 this->has_pin_response_ =
false;
91 ESP_LOGV(
"am43",
"DEC(%d): 0x%s", length,
pkt_to_hex(data, length).c_str());
93 if (length < 2 || data[0] != 0x9a)
96 case CMD_GET_BATTERY_LEVEL: {
98 this->battery_level_ = data[7];
99 this->has_battery_level_ =
true;
102 case CMD_GET_LIGHT_LEVEL: {
103 VERIFY_MIN_LENGTH(5);
104 this->light_level_ = 100 * ((float) data[4] / 9);
105 this->has_light_level_ =
true;
108 case CMD_GET_POSITION: {
109 VERIFY_MIN_LENGTH(6);
110 this->position_ = data[5];
111 this->has_position_ =
true;
114 case CMD_NOTIFY_POSITION: {
115 VERIFY_MIN_LENGTH(5);
116 this->position_ = data[4];
117 this->has_position_ =
true;
121 VERIFY_MIN_LENGTH(4);
122 this->pin_ok_ = data[3] == RESPONSE_ACK;
123 this->has_pin_response_ =
true;
126 case CMD_SET_POSITION: {
127 VERIFY_MIN_LENGTH(4);
128 this->set_position_ok_ = data[3] == RESPONSE_ACK;
129 this->has_set_position_response_ =
true;
132 case CMD_SET_STATE: {
133 VERIFY_MIN_LENGTH(4);
134 this->set_state_ok_ = data[3] == RESPONSE_ACK;
135 this->has_set_state_response_ =
true;
Am43Packet * encode_(uint8_t command, uint8_t *data, uint8_t length)
Am43Packet * get_battery_level_request()
const uint8_t START_PACKET[5]
Am43Packet * get_light_level_request()
Am43Packet * get_set_position_request(uint8_t position)
Am43Packet * get_position_request()
Am43Packet * get_stop_request()
Am43Packet * get_open_request()
std::string pkt_to_hex(const uint8_t *data, uint16_t len)
Am43Packet * get_send_pin_request(uint16_t pin)
void decode(const uint8_t *data, uint16_t length)
Am43Packet * get_close_request()
Implementation of SPI Controller mode.