uint8_t wkpf_propagate_property(uint8_t port_number, uint8_t property_number, int16_t value) { uint16_t component_id; if (!wkpf_get_component_id(port_number, &component_id)) return WKPF_OK; // WuObject isn't used in the application. wkpf_local_wuobject *src_wuobject; uint8_t wkpf_error_code; DEBUGF_WKPF("WKPF: propagate property number %x of component %x on port %x (value %x)\n", property_number, component_id, port_number, value); wkpf_get_wuobject_by_port(port_number, &src_wuobject); for(int i=0; i<number_of_links; i++) { if(links[i].src_component_id == component_id && links[i].src_property_number == property_number) { uint16_t dest_component_id = links[i].dest_component_id; if (dest_component_id > number_of_components) { DEBUGF_WKPF("WKPF: !!!! ERROR !!!! component id out of range %x\n", dest_component_id); return WKPF_ERR_SHOULDNT_HAPPEN; } uint8_t dest_property_number = links[i].dest_property_number; uint8_t dest_port_number = component_to_wuobject_map[dest_component_id].port_number; address_t dest_node_id = component_to_wuobject_map[dest_component_id].node_id; if (dest_node_id == nvmcomm_get_node_id()) { // Local wkpf_local_wuobject *dest_wuobject; wkpf_error_code = wkpf_get_wuobject_by_port(dest_port_number, &dest_wuobject); if (wkpf_error_code == WKPF_OK) { DEBUGF_WKPF("WKPF: propagate_property (local). (%x, %x)->(%x, %x), value %x\n", port_number, property_number, dest_port_number, dest_property_number, value); if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_BOOLEAN) wkpf_error_code = wkpf_external_write_property_boolean(dest_wuobject, dest_property_number, value); else if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_SHORT) wkpf_error_code = wkpf_external_write_property_int16(dest_wuobject, dest_property_number, value); else wkpf_error_code = wkpf_external_write_property_refresh_rate(dest_wuobject, dest_property_number, value); } } else { // Remote DEBUGF_WKPF("WKPF: propagate_property (remote). (%x, %x)->(%x, %x, %x), value %x\n", port_number, property_number, dest_node_id, dest_port_number, dest_property_number, value); if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_BOOLEAN) wkpf_error_code = wkpf_send_set_property_boolean(dest_node_id, dest_port_number, dest_property_number, links[i].dest_wuclass_id, value); else if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_SHORT) wkpf_error_code = wkpf_send_set_property_int16(dest_node_id, dest_port_number, dest_property_number, links[i].dest_wuclass_id, value); else wkpf_error_code = wkpf_send_set_property_refresh_rate(dest_node_id, dest_port_number, dest_property_number, links[i].dest_wuclass_id, value); } if (wkpf_error_code != WKPF_OK) return wkpf_error_code; } } return WKPF_OK; }
uint8_t wkpf_propagate_property(wuobject_t *wuobject, uint8_t property_number, void *value) { uint8_t port_number = wuobject->port_number; uint16_t component_id; if (!wkpf_get_component_id(port_number, &component_id)) return WKPF_OK; // WuObject isn't used in the application. wuobject_t *src_wuobject; uint8_t wkpf_error_code; DEBUG_LOG(DBG_WKPF, "WKPF: propagate property number %x of component %x on port %x (value %x)\n", property_number, component_id, port_number, *((uint16_t *)value)); // TODONR: values other than 16 bit values wkpf_get_wuobject_by_port(port_number, &src_wuobject); for(int i=0; i<wkpf_number_of_links; i++) { wkpf_link_t *link = wkpf_get_link(i); if(link->src_component_id == component_id && link->src_property_number == property_number) { uint16_t dest_component_id = link->dest_component_id; uint8_t dest_property_number = link->dest_property_number; uint8_t dest_port_number = wkpf_leader_for_component(dest_component_id).port_number; address_t dest_node_id = wkpf_leader_for_component(dest_component_id).node_id; if (dest_node_id == wkcomm_get_node_id()) { // Local wuobject_t *dest_wuobject; wkpf_error_code = wkpf_get_wuobject_by_port(dest_port_number, &dest_wuobject); if (wkpf_error_code == WKPF_OK) { DEBUG_LOG(DBG_WKPF, "WKPF: propagate_property (local). (%x, %x)->(%x, %x), value %x\n", port_number, property_number, dest_port_number, dest_property_number, *((uint16_t *)value)); // TODONR: values other than 16 bit values if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_BOOLEAN) wkpf_error_code = wkpf_external_write_property_boolean(dest_wuobject, dest_property_number, *((bool *)value)); else if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_SHORT) wkpf_error_code = wkpf_external_write_property_int16(dest_wuobject, dest_property_number, *((uint16_t *)value)); else wkpf_error_code = wkpf_external_write_property_refresh_rate(dest_wuobject, dest_property_number, *((uint16_t *)value)); } } else { // Remote DEBUG_LOG(DBG_WKPF, "WKPF: propagate_property (remote). (%x, %x)->(%x, %x, %x), value %x\n", port_number, property_number, dest_node_id, dest_port_number, dest_property_number, *((uint16_t *)value)); // TODONR: values other than 16 bit values if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_BOOLEAN) wkpf_error_code = wkpf_send_set_property_boolean(dest_node_id, dest_port_number, dest_property_number, link->dest_wuclass_id, *((bool *)value)); else if (WKPF_GET_PROPERTY_DATATYPE(src_wuobject->wuclass->properties[property_number]) == WKPF_PROPERTY_TYPE_SHORT) wkpf_error_code = wkpf_send_set_property_int16(dest_node_id, dest_port_number, dest_property_number, link->dest_wuclass_id, *((uint16_t *)value)); else wkpf_error_code = wkpf_send_set_property_refresh_rate(dest_node_id, dest_port_number, dest_property_number, link->dest_wuclass_id, *((uint16_t *)value)); } if (wkpf_error_code != WKPF_OK) return wkpf_error_code; } } return WKPF_OK; }
bool wkpf_does_property_need_initialisation_pull(uint8_t port_number, uint8_t property_number) { uint16_t component_id; wkpf_get_component_id(port_number, &component_id); for(int i=0; i<number_of_links; i++) { if (links[i].dest_component_id == component_id && links[i].dest_property_number == property_number) { if (component_to_wuobject_map[links[i].src_component_id].node_id != nvmcomm_get_node_id()) return true; // There is a link to this property, coming from another node. We need to ask it for the initial value else return false; } } return false; }
uint8_t wkpf_pull_property(uint8_t port_number, uint8_t property_number) { uint16_t component_id; wkpf_get_component_id(port_number, &component_id); for(int i=0; i<wkpf_number_of_links; i++) { wkpf_link_t *link = wkpf_get_link(i); if(link->dest_component_id == component_id && link->dest_property_number == property_number) { uint16_t src_component_id = link->src_component_id; wkpf_endpoint_t src_endpoint = wkpf_leader_for_component(src_component_id); uint8_t src_property_number = link->src_property_number; if (src_endpoint.node_id != wkcomm_get_node_id()) { // Properties with local sources will be initialised eventually, so we only need to send a message // to ask for initial values coming from remote nodes return wkpf_send_request_property_init(src_endpoint.node_id, src_endpoint.port_number, src_property_number); } } } return WKPF_ERR_SHOULDNT_HAPPEN; }
uint8_t wkpf_send_set_property_boolean(wkcomm_address_t dest_node_id, uint8_t port_number, uint8_t property_number, uint16_t wuclass_id, bool value, uint16_t src_component_id) { uint8_t message_buffer[6 + WKPF_MAX_NUM_OF_TOKENS * 2 +5]; uint16_t dest_component_id; if (port_number >= DEVICE_NATIVE_ZWAVE_SWITCH) { return wkpf_call_adaptor(dest_node_id, wuclass_id, property_number, value? 255:0); } else { message_buffer[0] = port_number; message_buffer[1] = (uint8_t)(wuclass_id >> 8); message_buffer[2] = (uint8_t)(wuclass_id); message_buffer[3] = property_number; message_buffer[4] = WKPF_PROPERTY_TYPE_BOOLEAN; message_buffer[5] = (uint8_t)(value); int piggy_message_length = 0; uint8_t* data = (uint8_t*)(message_buffer + 6); wkpf_get_component_id(port_number, &dest_component_id); wkpf_generate_piggyback_token(src_component_id, dest_component_id, data, &piggy_message_length); return send_message(dest_node_id, WKPF_COMM_CMD_WRITE_PROPERTY, message_buffer, 6 + piggy_message_length); } }
bool wkpf_does_property_need_initialisation_pull(uint8_t port_number, uint8_t property_number) { uint16_t component_id; wkpf_get_component_id(port_number, &component_id); for(int i=0; i<wkpf_number_of_links; i++) { wkpf_link_t *link = wkpf_get_link(i); if (link->dest_component_id == component_id && link->dest_property_number == property_number) { // The property is the destination of this link. If the source is remote, we need to ask for an initial value if (wkpf_node_is_leader(link->src_component_id, wkcomm_get_node_id())) { DEBUG_LOG(DBG_WKPF, "%x, %x doesn't need pull: source is a local property\n", port_number, property_number); return false; // Source link is local, so no need to pull initial value as it will come automatically. } else { DEBUG_LOG(DBG_WKPF, "%x, %x needs initialisation pull\n", port_number, property_number); return true; // There is a link to this property, coming from another node. We need to ask it for the initial value. } } } DEBUG_LOG(DBG_WKPF, "%x, %x doesn't need pull: not a destination property\n", port_number, property_number); return false; // This wuobject isn't used in the application. }
uint8_t wkpf_send_set_property_refresh_rate(wkcomm_address_t dest_node_id, uint8_t port_number, uint8_t property_number, uint16_t wuclass_id, wkpf_refresh_rate_t value, uint16_t src_component_id) { uint8_t message_buffer[7 + WKPF_MAX_NUM_OF_TOKENS * 2 +5]; uint16_t dest_component_id; if (port_number >= DEVICE_NATIVE_ZWAVE_SWITCH) { return WKPF_COMM_CMD_ERROR_R; } else { message_buffer[0] = port_number; message_buffer[1] = (uint8_t)(wuclass_id >> 8); message_buffer[2] = (uint8_t)(wuclass_id); message_buffer[3] = property_number; message_buffer[4] = WKPF_PROPERTY_TYPE_REFRESH_RATE; message_buffer[5] = (uint8_t)(value >> 8); message_buffer[6] = (uint8_t)(value); int piggy_message_length = 0; uint8_t* data = (uint8_t*)(message_buffer + 7); wkpf_get_component_id(port_number, &dest_component_id); wkpf_generate_piggyback_token(src_component_id, dest_component_id, data, &piggy_message_length); return send_message(dest_node_id, WKPF_COMM_CMD_WRITE_PROPERTY, message_buffer, 7 + piggy_message_length); } }
uint8_t wkpf_pull_property(uint8_t port_number, uint8_t property_number) { uint16_t component_id; wkpf_get_component_id(port_number, &component_id); for(int i=0; i<number_of_links; i++) { if(links[i].dest_component_id == component_id && links[i].dest_property_number == property_number) { uint16_t src_component_id = links[i].src_component_id; if (src_component_id > number_of_components) { DEBUGF_WKPF("WKPF: !!!! ERROR !!!! component id out of range %x\n", src_component_id); return WKPF_ERR_SHOULDNT_HAPPEN; } uint8_t src_property_number = links[i].src_property_number; uint8_t src_port_number = component_to_wuobject_map[src_component_id].port_number; address_t src_node_id = component_to_wuobject_map[src_component_id].node_id; if (src_node_id != nvmcomm_get_node_id()) { // Properties with local sources will be initialised eventually, so we only need to send a message // to ask for initial values coming from remote nodes return wkpf_send_request_property_init(src_node_id, src_port_number, src_property_number); } } } return WKPF_ERR_SHOULDNT_HAPPEN; }