Support building fetch position packets
This commit is contained in:
@@ -12,7 +12,8 @@ public:
|
|||||||
void buildUpPacket(uint8_t *buffer, uint16_t shadeID);
|
void buildUpPacket(uint8_t *buffer, uint16_t shadeID);
|
||||||
void buildDownPacket(uint8_t *buffer, uint16_t shadeID);
|
void buildDownPacket(uint8_t *buffer, uint16_t shadeID);
|
||||||
void buildStopPacket(uint8_t *buffer, uint16_t shadeID);
|
void buildStopPacket(uint8_t *buffer, uint16_t shadeID);
|
||||||
void buildPositionPacket(uint8_t *buffer, uint16_t shadeID, float percentage);
|
void buildSetPositionPacket(uint8_t *buffer, uint16_t shadeID, float percentage);
|
||||||
|
void buildFetchPositionPacket(uint8_t *buffer, uint16_t shadeID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t address;
|
uint16_t address;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void PacketBuilder::buildStopPacket(uint8_t *buffer, uint16_t shadeID)
|
|||||||
incrementRollingCodes();
|
incrementRollingCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketBuilder::buildPositionPacket(uint8_t *buffer, uint16_t shadeID, float percentage)
|
void PacketBuilder::buildSetPositionPacket(uint8_t *buffer, uint16_t shadeID, float percentage)
|
||||||
{
|
{
|
||||||
setPacketSize(buffer, 0x15);
|
setPacketSize(buffer, 0x15);
|
||||||
setConstants(buffer);
|
setConstants(buffer);
|
||||||
@@ -75,12 +75,12 @@ void PacketBuilder::buildPositionPacket(uint8_t *buffer, uint16_t shadeID, float
|
|||||||
setDestinationAddress(buffer, shadeID);
|
setDestinationAddress(buffer, shadeID);
|
||||||
setRollingCodes(buffer);
|
setRollingCodes(buffer);
|
||||||
|
|
||||||
buffer[16] = 0x3F; // Command
|
buffer[16] = 0x3F; // Field command
|
||||||
buffer[17] = 0x5A; // Empty?
|
buffer[17] = 0x5A; // Constant
|
||||||
|
|
||||||
buffer[18] = 0x04; // Constant in this size packet?
|
buffer[18] = 0x04; // Field of 4 bytes
|
||||||
buffer[19] = 0x40; // Constant in this size packet?
|
buffer[19] = 0x40; // Field type (0x40 is set)
|
||||||
buffer[20] = 0x50; // Constant in this size packet?
|
buffer[20] = 0x50; // ID of position field
|
||||||
|
|
||||||
uint16_t position = (uint16_t)(0xFFFF * percentage);
|
uint16_t position = (uint16_t)(0xFFFF * percentage);
|
||||||
|
|
||||||
@@ -92,6 +92,26 @@ void PacketBuilder::buildPositionPacket(uint8_t *buffer, uint16_t shadeID, float
|
|||||||
incrementRollingCodes();
|
incrementRollingCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PacketBuilder::buildFetchPositionPacket(uint8_t *buffer, uint16_t shadeID) {
|
||||||
|
setPacketSize(buffer, 0x13);
|
||||||
|
setConstants(buffer);
|
||||||
|
setProtocolVersion(buffer, protocolVersion);
|
||||||
|
setSourceAddress(buffer, address);
|
||||||
|
setDestinationAddress(buffer, shadeID);
|
||||||
|
setRollingCodes(buffer);
|
||||||
|
|
||||||
|
buffer[16] = 0x3F; // Field command
|
||||||
|
buffer[17] = 0x5A; // Constant
|
||||||
|
|
||||||
|
buffer[18] = 0x02; // Field of 2 bytes
|
||||||
|
buffer[19] = 0x3F; // Field type (0x3F is fetch)
|
||||||
|
buffer[20] = 0x50; // ID of position field
|
||||||
|
|
||||||
|
calculateCRC(buffer);
|
||||||
|
|
||||||
|
incrementRollingCodes();
|
||||||
|
}
|
||||||
|
|
||||||
void PacketBuilder::setPacketSize(uint8_t *buffer, uint8_t length) {
|
void PacketBuilder::setPacketSize(uint8_t *buffer, uint8_t length) {
|
||||||
buffer[1] = length; // Packet size
|
buffer[1] = length; // Packet size
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ void onConnectionEstablished() {
|
|||||||
client.subscribe("hotdog/test_mqtt_blind/set_position", [] (const String &payload) {
|
client.subscribe("hotdog/test_mqtt_blind/set_position", [] (const String &payload) {
|
||||||
uint16_t shadeID = 0x4EF1;
|
uint16_t shadeID = 0x4EF1;
|
||||||
float percentage = payload.toInt() / 100.0f;
|
float percentage = payload.toInt() / 100.0f;
|
||||||
hubPacketBuilder.buildPositionPacket(buffer, shadeID, percentage);
|
hubPacketBuilder.buildSetPositionPacket(buffer, shadeID, percentage);
|
||||||
sendCommand(buffer);
|
sendCommand(buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user