public async Task<bool> AcceptNode(string macAddress, ushort newAddress, Security security) { //TODO: check if macAddress exists return await this.SendJoinAcceptResponse(macAddress, newAddress, security); }
private async Task<bool> SendJoinAcceptResponse(string macAddress, ushort newAddress, Security security) { PendingNodeInfo info = this.PendingNodes.FirstOrDefault(n => n.MacAddress == macAddress); if (info == null) { throw new InvalidOperationException("There is no pending node with the specified MAC Address"); } OperationMessage joinAcceptResponse = OperationMessage.JoinAcceptResponse(newAddress, (ushort)security.PanId, (byte)security.Channel, security.SecurityKey, info.TemporalAddress); bool result = await this.SendMessage(joinAcceptResponse); if (result) { Debug.WriteLine(string.Format("JOIN ACCEPTED {0} -> NEW ADDRESS: 0x{1:X2}", macAddress, newAddress)); if (this.NodeJoined != null) NodeJoined(this, macAddress); } else { Debug.WriteLine(string.Format("THE NODE {0} DOESN'T RECEIVE THE JOIN ACCEPT RESPONSE", macAddress)); } this.PendingNodes.Remove(info); return result; }