/// <summary> /// Sends z camera offset /// </summary> /// <param name="module"></param> /// <param name="action"></param> /// <param name="camInfo"></param> /// <returns></returns> public bool sendCommand(byte module, byte action, ServerMessages.DroneCamInfo camInfo) { byte[] data_bytes = new byte[31]; // { (byte)'A', module, action, data.id, data.order, data.position }; data_bytes[0] = (byte)'A'; data_bytes[1] = module; data_bytes[2] = action; byte[] converted = BitConverter.GetBytes(camInfo.camPos.x); for (int i = 0; i < 4; i++) { data_bytes[i + 4] = converted[i]; } converted = BitConverter.GetBytes(camInfo.camPos.y); for (int i = 0; i < 4; i++) { data_bytes[i + 8] = converted[i]; } converted = BitConverter.GetBytes(camInfo.camPos.z); for (int i = 0; i < 4; i++) { data_bytes[i + 12] = converted[i]; } NetMQMessage req_msg = new NetMQMessage(); req_msg.Append(data_bytes); NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg(); // it will be filled when receiving the response reqSrv = new ReliableExternalClient( GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3); if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg)) { UnityEngine.Debug.Log("Client: server not respoding"); return(false); } // Just after the request the atreyu server must respond with a notification // (ACK, UNKNOWN_MODULE, or UNDEFINED_MODULE) through the same 'requests' socket. if (StdMessage.isStdNotification(ref resp_msg) && StdMessage.getMessageAction(ref resp_msg) != (byte)NotificationType.ACK) { if (module == (byte)Modules.STD_COMMANDS_MODULE) { UnityEngine.Debug.Log( String.Format("Client: STD command was not accepted {0}", new StdMessage(module, action).to_string())); } else if (module == (byte)Modules.POSITIONING_MODULE) { UnityEngine.Debug.Log( String.Format("Client: POSITIONING_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string())); } else if (module == (byte)Modules.POINTCLOUD_MODULE) { UnityEngine.Debug.Log( String.Format("Client: POINTCLOUD_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string())); } return(false); } return(true); }
// Confirm tag config button listener void ConfirmTagConfiguration() { if ((clientUnity != null) && (clientUnity.client != null) && (clientUnity.client.isConnected)) { if (swValue >= 0 && nwValue >= 0 && neValue >= 0 && seValue >= 0 && widthValue >= 0 && heightValue >= 0) { state = TagsConfigState.ConfigurationSent; confirmButton.GetComponent <Button>().interactable = false; ServerMessages.DroneCamInfo camInfo = new ServerMessages.DroneCamInfo(camDistValueX, camDistValueY, camDistValueZ); ServerMessages.IPSDroneTag tagData = new ServerMessages.IPSDroneTag(swValue, nwValue, neValue, seValue, widthValue, heightValue, (int)camDistValueY); clientUnity.client.sendCommand((byte)Modules.POSITIONING_MODULE, (byte)PositioningCommandType.IPS_DRONETAGS_MANUAL_CONFIG, tagData); clientUnity.client.sendCommand((byte)Modules.DRONE_MODULE, (byte)DroneCommandType.DRONE_SET_ZCAMERA_OFFSET, camInfo); clientUnity.client.sendSetDroneFilter((byte)Modules.POSITIONING_MODULE, (byte)PositioningCommandType.IPS_SET_DRONEFILTER, 0, PozyxModule.updatePeriod, PozyxModule.movementFreedom); } else { UnityEngine.Debug.Log("Some invalid values"); PozyxModule.errorMsg = "Some invald values"; state = TagsConfigState.ErrorReceived; } } }