public void GivenAConnectAction_WhenAnAgentIsFound_ThenRespondsByDialingTheAgentsPhoneNumber() { var mockRepository = new Mock <IAgentRepository>(); mockRepository.Setup(r => r.FindByExtension(It.IsAny <string>())) .Returns(new Agent { Id = 1, PhoneNumber = "+12025550142" }); var controller = new ExtensionController(mockRepository.Object) { Url = Url }; var result = controller.Connect("2"); result.ExecuteResult(MockControllerContext.Object); var document = LoadXml(Result.ToString()); Assert.That(document.SelectSingleNode("Response/Dial").Attributes["action"].Value, Is.EqualTo("/Agent/Call?agentId=1")); Assert.That(document.SelectSingleNode("Response/Dial/Number").Attributes["url"].Value, Is.EqualTo("/Agent/ScreenCall")); Assert.That(document.SelectSingleNode("Response/Dial/Number").InnerText, Is.EqualTo("+12025550142")); }
/// \brief Attempts to activate the Wii Motion Plus. /// \sa RequestIdentifyWiiMotionPlus(), wmp_attached /// \return If the activation request was successfully sent to the Wii Remote. /// /// When the Wii Remote reports that the Wii Motion Plus has been activated, current_ext will be updated to ExtensionController::MOTIONPLUS /// If there is no Wii Motion Plus connected, undefined behavior may occur on the Wii Remote. public bool ActivateWiiMotionPlus() { //if (!wmp_attached) //Debug.LogWarning("There is a request to activate the Wii Motion Plus even though it has not been confirmed to exist! Trying anyway."); // Initialize the Wii Motion Plus by writing 0x55 to register 0xA600F0 int res = SendRegisterWriteRequest(RegisterType.CONTROL, 0xA600F0, new byte[] { 0x55 }); if (res < 0) { return(false); } // Activate the Wii Motion Plus as the active extension by writing 0x04 to register 0xA600FE // This does 3 things: // 1. A status report (0x20) will be sent, which indicates that an extension has been // plugged in - IF there is no extension plugged into the passthrough port. // 2. The standard extension identifier at 0xA400FA now reads 00 00 A4 20 04 05 // 3. Extension reports now contain Wii Motion Plus data. res = SendRegisterWriteRequest(RegisterType.CONTROL, 0xA600FE, new byte[] { 0x04 }); if (res < 0) { return(false); } _current_ext = ExtensionController.MOTIONPLUS; if (_Extension == null || _Extension.GetType() != typeof(MotionPlusData)) { _Extension = new MotionPlusData(this); } ExpectingWiiMotionPlusSwitch = true; return(true); }
private void InitControllers() { sysController = new SystemController(this); extController = new ExtensionController(this); AddController(0, sysController); AddController(1, extController); }
// Identifies if the extension in the wiimote is a Nunchuck or not // Will not recognise any othe extension private void RespondIdentifyExtension(byte[] data) { if (data.Length != 6) { return; } byte[] resized = new byte[8]; for (int x = 0; x < 6; x++) { resized[x] = data[5 - x]; } long val = BitConverter.ToInt64(resized, 0); if (val == ID_Nunchuck || val == ID_Nunchuck2) { _current_ext = ExtensionController.NUNCHUCK; if (_Extension == null || _Extension.GetType() != typeof(CS_NunchuckData)) { _Extension = new CS_NunchuckData(this); } } else { _current_ext = ExtensionController.NONE; _Extension = null; } }
private void InitControllers() { this.sysController = new SystemController(this); this.extController = new ExtensionController(this); this.sysProtoBufController = new SystemProtoBufController(this); this.AddController(0, this.sysController); this.AddController(1, this.extController); this.AddController(2, this.sysProtoBufController); }
private FolderWatcher(Monitor monitor, string directoryToMonitor) { _directoryPath = directoryToMonitor; _monitor = monitor; _extensionCtrl = new ExtensionController(); _watcher.Path = _directoryPath; _watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size; _watcher.IncludeSubdirectories = true; }
static void Main(string[] args) { Console.WriteLine("Press any key to begin."); Console.ReadKey(); Console.WriteLine("Starting..."); for (var i = 0; i < 10; i++) { Console.WriteLine("Looking for a file to process"); var file = MoveAFile(); while (file == null) { System.Threading.Thread.Sleep(60000); file = MoveAFile(); } Console.WriteLine("File moved up to Azure storage."); AddFileToQueue(file); //next we need to check the status up the item var status = StatusController.GetCurrentStatus(file.FileId, "61e8b5db-d076-44c3-914d-05e37cef4abd"); while (status.Finished == false) { System.Threading.Thread.Sleep(10000); status = StatusController.GetCurrentStatus(file.FileId, "61e8b5db-d076-44c3-914d-05e37cef4abd"); } Console.WriteLine("File done processing, obtaining results."); var extensionOutput = ExtensionController.GetExtension(file.FileId); //next step is to save the results in the database. ProcessResult(extensionOutput, file); Console.WriteLine("Results done processing, Time to sleep."); System.Threading.Thread.Sleep(60000); } Console.WriteLine("Done..."); Console.ReadKey(); }
public void GivenAConnectAction_WhenAnAgentIsNotFound_ThenRespondsRedirectingToMainMenu() { var mockRepository = new Mock <IAgentRepository>(); mockRepository.Setup(r => r.FindByExtension(It.IsAny <string>())); var controller = new ExtensionController(mockRepository.Object) { Url = Url }; var result = controller.Connect("*"); result.ExecuteResult(MockControllerContext.Object); var document = LoadXml(Result.ToString()); Assert.That(document.SelectSingleNode("Response/Redirect").InnerText, Is.EqualTo("/IVR/Welcome")); }
/// \brief Reads and interprets data reported by the Wii Remote. /// \return On success, > 0, < 0 on failure, 0 if nothing has been recieved. /// /// Wii Remote reads function similarly to a Queue, in FIFO (first in, first out) order. /// For example, if two reports were sent since the last \c ReadWiimoteData() call, /// this call will only read and interpret the first of those two (and "pop" it off /// of the queue). So, in order to make sure you don't fall behind the Wiimote's update /// frequency, you can do something like this (in a game loop for example): /// /// \code /// Wii Remote wiimote; /// int ret; /// do /// { /// ret = wiimote.ReadWiimoteData(); /// } while (ret > 0); /// \endcode public int ReadWiimoteData() { byte[] buf = new byte[22]; int status = WiimoteManager.RecieveRaw(hidapi_handle, buf); if (status <= 0) { return(status); // Either there is some sort of error or we haven't recieved anything } int typesize = GetInputDataTypeSize((InputDataType)buf[0]); byte[] data = new byte[typesize]; for (int x = 0; x < data.Length; x++) { data[x] = buf[x + 1]; } if (WiimoteManager.Debug_Messages) { Debug.Log("Recieved: [" + buf[0].ToString("X").PadLeft(2, '0') + "] " + BitConverter.ToString(data)); } // Variable names used throughout the switch/case block byte[] buttons; byte[] accel; byte[] ext = null; byte[] ir; switch ((InputDataType)buf[0]) // buf[0] is the output ID byte { case InputDataType.STATUS_INFO: // done. buttons = new byte[] { data[0], data[1] }; byte flags = data[2]; byte battery_level = data[5]; Button.InterpretData(buttons); bool old_ext_connected = Status.ext_connected; byte[] total = new byte[] { flags, battery_level }; Status.InterpretData(total); if (expecting_status_report) { expecting_status_report = false; } else // We haven't requested any data report type, meaning a controller has connected. { SendDataReportMode(last_report_type); // If we don't update the data report mode, no updates will be sent } if (Status.ext_connected != old_ext_connected && Type != WiimoteType.PROCONTROLLER) { if (Status.ext_connected) // The Wii Remote doesn't allow reading from the extension identifier { // when nothing is connected. Debug.Log("An extension has been connected."); if (current_ext != ExtensionController.MOTIONPLUS) { ActivateExtension(); RequestIdentifyExtension(); // Identify what extension was connected. } else { ExpectingWiiMotionPlusSwitch = false; } } else { if (!ExpectingWiiMotionPlusSwitch) { _current_ext = ExtensionController.NONE; } Debug.Log("An extension has been disconnected."); } } break; case InputDataType.READ_MEMORY_REGISTERS: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); if (CurrentReadData == null) { Debug.LogWarning("Recived Register Read Report when none was expected. Ignoring."); return(status); } byte size = (byte)((data[2] >> 4) + 0x01); byte error = (byte)(data[2] & 0x0f); // Error 0x07 means reading from a write-only register // Offset 0xa600fa is for the Wii Motion Plus. This error code can be expected behavior in this case. if (error == 0x07) { if (CurrentReadData.Offset != 0xa600fa) { Debug.LogError("Wiimote reports Read Register error 7: Attempting to read from a write-only register (" + CurrentReadData.Offset.ToString("x") + "). Aborting read."); } CurrentReadData = null; return(status); } // lowOffset is reversed because the Wii Remote reports are in Big Endian order ushort lowOffset = BitConverter.ToUInt16(new byte[] { data[4], data[3] }, 0); ushort expected = (ushort)CurrentReadData.ExpectedOffset; if (expected != lowOffset) { Debug.LogWarning("Expected Register Read Offset (" + expected + ") does not match reported offset from Wii Remote (" + lowOffset + ")"); } byte[] read = new byte[size]; for (int x = 0; x < size; x++) { read[x] = data[x + 5]; } CurrentReadData.AppendData(read); if (CurrentReadData.ExpectedOffset >= CurrentReadData.Offset + CurrentReadData.Size) { CurrentReadData = null; } break; case InputDataType.ACKNOWLEDGE_OUTPUT_REPORT: buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); // TODO: doesn't do any actual error handling, or do any special code about acknowledging the output report. break; case InputDataType.REPORT_BUTTONS: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); break; case InputDataType.REPORT_BUTTONS_ACCEL: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); break; case InputDataType.REPORT_BUTTONS_EXT8: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ext = new byte[8]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x + 2]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_ACCEL_IR12: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ir = new byte[12]; for (int x = 0; x < 12; x++) { ir[x] = data[x + 5]; } Ir.InterpretData(ir); break; case InputDataType.REPORT_BUTTONS_EXT19: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ext = new byte[19]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x + 2]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_ACCEL_EXT16: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ext = new byte[16]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x + 5]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_IR10_EXT9: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ir = new byte[10]; for (int x = 0; x < 10; x++) { ir[x] = data[x + 2]; } Ir.InterpretData(ir); ext = new byte[9]; for (int x = 0; x < 9; x++) { ext[x] = data[x + 12]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_ACCEL_IR10_EXT6: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ir = new byte[10]; for (int x = 0; x < 10; x++) { ir[x] = data[x + 5]; } Ir.InterpretData(ir); ext = new byte[6]; for (int x = 0; x < 6; x++) { ext[x] = data[x + 15]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_EXT21: // done. ext = new byte[21]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_INTERLEAVED: if (!ExpectingSecondInterleavedPacket) { ExpectingSecondInterleavedPacket = true; InterleavedDataBuffer = data; } else if (WiimoteManager.Debug_Messages) { Debug.LogWarning( "Recieved two REPORT_INTERLEAVED (" + InputDataType.REPORT_INTERLEAVED.ToString("x") + ") reports in a row! " + "Expected REPORT_INTERLEAVED_ALT (" + InputDataType.REPORT_INTERLEAVED_ALT.ToString("x") + "). Ignoring!" ); } break; case InputDataType.REPORT_INTERLEAVED_ALT: if (ExpectingSecondInterleavedPacket) { ExpectingSecondInterleavedPacket = false; buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); byte[] ir1 = new byte[18]; byte[] ir2 = new byte[18]; for (int x = 0; x < 18; x++) { ir1[x] = InterleavedDataBuffer[x + 3]; ir2[x] = data[x + 3]; } Ir.InterpretDataInterleaved(ir1, ir2); Accel.InterpretDataInterleaved(InterleavedDataBuffer, data); } else if (WiimoteManager.Debug_Messages) { Debug.LogWarning( "Recieved two REPORT_INTERLEAVED_ALT (" + InputDataType.REPORT_INTERLEAVED_ALT.ToString("x") + ") reports in a row! " + "Expected REPORT_INTERLEAVED (" + InputDataType.REPORT_INTERLEAVED.ToString("x") + "). Ignoring!" ); } break; } if (ext == null) { _RawExtension = null; } else { _RawExtension = new ReadOnlyArray <byte>(ext); } return(status); }
private void RespondIdentifyExtension(byte[] data) { if (data.Length != 6) { return; } byte[] resized = new byte[8]; for (int x = 0; x < 6; x++) { resized[x] = data[5 - x]; } long val = BitConverter.ToInt64(resized, 0); // Disregard bytes 0 and 5 - see RespondIdentifyWiiMotionPlus() if ((val | 0xff000000ff00) == (ID_ActiveMotionPlus | 0xff000000ff00)) { _current_ext = ExtensionController.MOTIONPLUS; if (_Extension == null || _Extension.GetType() != typeof(MotionPlusData)) { _Extension = new MotionPlusData(this); } } else if (val == ID_ActiveMotionPlus_Nunchuck) { _current_ext = ExtensionController.MOTIONPLUS_NUNCHUCK; _Extension = null; } else if (val == ID_ActiveMotionPlus_Classic) { _current_ext = ExtensionController.MOTIONPLUS_CLASSIC; _Extension = null; } else if (val == ID_ClassicPro) { _current_ext = ExtensionController.CLASSIC_PRO; _Extension = null; } else if (val == ID_Nunchuck) { _current_ext = ExtensionController.NUNCHUCK; if (_Extension == null || _Extension.GetType() != typeof(NunchuckData)) { _Extension = new NunchuckData(this); } } else if (val == ID_Classic) { _current_ext = ExtensionController.CLASSIC; if (_Extension == null || _Extension.GetType() != typeof(ClassicControllerData)) { _Extension = new ClassicControllerData(this); } } else if (val == ID_WiiUPro) { _current_ext = ExtensionController.WIIU_PRO; _Type = WiimoteType.PROCONTROLLER; if (_Extension == null || _Extension.GetType() != typeof(WiiUProData)) { _Extension = new WiiUProData(this); } } else { _current_ext = ExtensionController.NONE; _Extension = null; } }
private void WorkerThreadFunc() { while (!_shutdownEvent.WaitOne(0)) { var errorBuffer = 0; while (errorBuffer < 10) { try { // Replace the Sleep() call with the work you need to do var file = MoveAFile(); while (file == null) { Thread.Sleep(5000); file = MoveAFile(); } //Console.WriteLine("File moved up to Azure storage."); AddFileToQueue(file); //next we need to check the status up the item var status = StatusController.GetCurrentStatus(file.FileId, "61e8b5db-d076-44c3-914d-05e37cef4abd"); while (status.Finished == false) { Thread.Sleep(10000); status = StatusController.GetCurrentStatus(file.FileId, "61e8b5db-d076-44c3-914d-05e37cef4abd"); } //Console.WriteLine("File done processing, obtaining results."); var extensionOutput = ExtensionController.GetExtension(file.FileId); //next step is to save the results in the database. ProcessResult(extensionOutput, file); //Console.WriteLine("Results done processing, Time to sleep."); errorBuffer = 0; } catch (Exception ex) { errorBuffer++; if (ex.InnerException != null) { WriteError(ex.InnerException.Message); } else { WriteError(ex.Message); } if (errorBuffer > 10) { throw; } } Thread.Sleep(5000); } } }
/// \brief Reads and interprets data reported by the Wii Remote. /// \return On success, > 0, < 0 on failure, 0 if nothing has been recieved. /// /// Wii Remote reads function similarly to a Queue, in FIFO (first in, first out) order. /// For example, if two reports were sent since the last \c ReadWiimoteData() call, /// this call will only read and interpret the first of those two (and "pop" it off /// of the queue). So, in order to make sure you don't fall behind the Wiimote's update /// frequency, you can do something like this (in a game loop for example): /// /// \code /// Wii Remote wiimote; /// int ret; /// do /// { /// ret = wiimote.ReadWiimoteData(); /// } while (ret > 0); /// \endcode public int ReadWiimoteData() { byte[] buf = new byte[22]; int status = WiimoteManager.RecieveRaw(hidapi_handle, buf); if (status <= 0) return status; // Either there is some sort of error or we haven't recieved anything int typesize = GetInputDataTypeSize((InputDataType)buf[0]); byte[] data = new byte[typesize]; for (int x = 0; x < data.Length; x++) data[x] = buf[x + 1]; if (WiimoteManager.Debug_Messages) Debug.Log("Recieved: [" + buf[0].ToString("X").PadLeft(2, '0') + "] " + BitConverter.ToString(data)); // Variable names used throughout the switch/case block byte[] buttons; byte[] accel; byte[] ext = null; byte[] ir; switch ((InputDataType)buf[0]) // buf[0] is the output ID byte { case InputDataType.STATUS_INFO: // done. buttons = new byte[] { data[0], data[1] }; byte flags = data[2]; byte battery_level = data[5]; Button.InterpretData(buttons); bool old_ext_connected = Status.ext_connected; byte[] total = new byte[] { flags, battery_level }; Status.InterpretData(total); if (expecting_status_report) { expecting_status_report = false; } else // We haven't requested any data report type, meaning a controller has connected. { SendDataReportMode(last_report_type); // If we don't update the data report mode, no updates will be sent } if (Status.ext_connected != old_ext_connected && Type != WiimoteType.PROCONTROLLER) { if (Status.ext_connected) // The Wii Remote doesn't allow reading from the extension identifier { // when nothing is connected. Debug.Log("An extension has been connected."); if (current_ext != ExtensionController.MOTIONPLUS) { ActivateExtension(); RequestIdentifyExtension(); // Identify what extension was connected. } else ExpectingWiiMotionPlusSwitch = false; } else { if (!ExpectingWiiMotionPlusSwitch) _current_ext = ExtensionController.NONE; Debug.Log("An extension has been disconnected."); } } break; case InputDataType.READ_MEMORY_REGISTERS: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); if (CurrentReadData == null) { Debug.LogWarning("Recived Register Read Report when none was expected. Ignoring."); return status; } byte size = (byte)((data[2] >> 4) + 0x01); byte error = (byte)(data[2] & 0x0f); // Error 0x07 means reading from a write-only register // Offset 0xa600fa is for the Wii Motion Plus. This error code can be expected behavior in this case. if (error == 0x07) { if(CurrentReadData.Offset != 0xa600fa) Debug.LogError("Wiimote reports Read Register error 7: Attempting to read from a write-only register ("+CurrentReadData.Offset.ToString("x")+"). Aborting read."); CurrentReadData = null; return status; } // lowOffset is reversed because the Wii Remote reports are in Big Endian order ushort lowOffset = BitConverter.ToUInt16(new byte[] { data[4], data[3] }, 0); ushort expected = (ushort)CurrentReadData.ExpectedOffset; if (expected != lowOffset) Debug.LogWarning("Expected Register Read Offset (" + expected + ") does not match reported offset from Wii Remote (" + lowOffset + ")"); byte[] read = new byte[size]; for (int x = 0; x < size; x++) read[x] = data[x + 5]; CurrentReadData.AppendData(read); if (CurrentReadData.ExpectedOffset >= CurrentReadData.Offset + CurrentReadData.Size) CurrentReadData = null; break; case InputDataType.ACKNOWLEDGE_OUTPUT_REPORT: buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); // TODO: doesn't do any actual error handling, or do any special code about acknowledging the output report. break; case InputDataType.REPORT_BUTTONS: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); break; case InputDataType.REPORT_BUTTONS_ACCEL: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); break; case InputDataType.REPORT_BUTTONS_EXT8: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ext = new byte[8]; for (int x = 0; x < ext.Length; x++) ext[x] = data[x + 2]; if (_Extension != null) _Extension.InterpretData(ext); break; case InputDataType.REPORT_BUTTONS_ACCEL_IR12: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ir = new byte[12]; for (int x = 0; x < 12; x++) ir[x] = data[x + 5]; Ir.InterpretData(ir); break; case InputDataType.REPORT_BUTTONS_EXT19: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ext = new byte[19]; for (int x = 0; x < ext.Length; x++) ext[x] = data[x + 2]; if (_Extension != null) _Extension.InterpretData(ext); break; case InputDataType.REPORT_BUTTONS_ACCEL_EXT16: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ext = new byte[16]; for (int x = 0; x < ext.Length; x++) ext[x] = data[x + 5]; if (_Extension != null) _Extension.InterpretData(ext); break; case InputDataType.REPORT_BUTTONS_IR10_EXT9: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ir = new byte[10]; for (int x = 0; x < 10; x++) ir[x] = data[x + 2]; Ir.InterpretData(ir); ext = new byte[9]; for (int x = 0; x < 9; x++) ext[x] = data[x + 12]; if (_Extension != null) _Extension.InterpretData(ext); break; case InputDataType.REPORT_BUTTONS_ACCEL_IR10_EXT6: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ir = new byte[10]; for (int x = 0; x < 10; x++) ir[x] = data[x + 5]; Ir.InterpretData(ir); ext = new byte[6]; for (int x = 0; x < 6; x++) ext[x] = data[x + 15]; if (_Extension != null) _Extension.InterpretData(ext); break; case InputDataType.REPORT_EXT21: // done. ext = new byte[21]; for (int x = 0; x < ext.Length; x++) ext[x] = data[x]; if (_Extension != null) _Extension.InterpretData(ext); break; case InputDataType.REPORT_INTERLEAVED: if (!ExpectingSecondInterleavedPacket) { ExpectingSecondInterleavedPacket = true; InterleavedDataBuffer = data; } else if(WiimoteManager.Debug_Messages) { Debug.LogWarning( "Recieved two REPORT_INTERLEAVED ("+InputDataType.REPORT_INTERLEAVED.ToString("x")+") reports in a row! " + "Expected REPORT_INTERLEAVED_ALT ("+InputDataType.REPORT_INTERLEAVED_ALT.ToString("x")+"). Ignoring!" ); } break; case InputDataType.REPORT_INTERLEAVED_ALT: if (ExpectingSecondInterleavedPacket) { ExpectingSecondInterleavedPacket = false; buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); byte[] ir1 = new byte[18]; byte[] ir2 = new byte[18]; for (int x = 0; x < 18; x++) { ir1[x] = InterleavedDataBuffer[x + 3]; ir2[x] = data[x + 3]; } Ir.InterpretDataInterleaved(ir1, ir2); Accel.InterpretDataInterleaved(InterleavedDataBuffer, data); } else if(WiimoteManager.Debug_Messages) { Debug.LogWarning( "Recieved two REPORT_INTERLEAVED_ALT ("+InputDataType.REPORT_INTERLEAVED_ALT.ToString("x")+") reports in a row! " + "Expected REPORT_INTERLEAVED ("+InputDataType.REPORT_INTERLEAVED.ToString("x")+"). Ignoring!" ); } break; } if(ext == null) _RawExtension = null; else _RawExtension = new ReadOnlyArray<byte>(ext); return status; }
/// \brief Attempts to activate the Wii Motion Plus. /// \sa RequestIdentifyWiiMotionPlus(), wmp_attached /// \return If the activation request was successfully sent to the Wii Remote. /// /// When the Wii Remote reports that the Wii Motion Plus has been activated, current_ext will be updated to ExtensionController::MOTIONPLUS /// If there is no Wii Motion Plus connected, undefined behavior may occur on the Wii Remote. public bool ActivateWiiMotionPlus() { if (!wmp_attached) Debug.LogWarning("There is a request to activate the Wii Motion Plus even though it has not been confirmed to exist! Trying anyway."); // Initialize the Wii Motion Plus by writing 0x55 to register 0xA600F0 int res = SendRegisterWriteRequest(RegisterType.CONTROL, 0xA600F0, new byte[] { 0x55 }); if (res < 0) return false; // Activate the Wii Motion Plus as the active extension by writing 0x04 to register 0xA600FE // This does 3 things: // 1. A status report (0x20) will be sent, which indicates that an extension has been // plugged in - IF there is no extension plugged into the passthrough port. // 2. The standard extension identifier at 0xA400FA now reads 00 00 A4 20 04 05 // 3. Extension reports now contain Wii Motion Plus data. res = SendRegisterWriteRequest(RegisterType.CONTROL, 0xA600FE, new byte[] { 0x04 }); if (res < 0) return false; _current_ext = ExtensionController.MOTIONPLUS; if (_Extension == null || _Extension.GetType() != typeof(MotionPlusData)) _Extension = new MotionPlusData(this); ExpectingWiiMotionPlusSwitch = true; return true; }
private void RespondIdentifyExtension(byte[] data) { if (data.Length != 6) return; byte[] resized = new byte[8]; for (int x = 0; x < 6; x++) resized[x] = data[5-x]; long val = BitConverter.ToInt64(resized, 0); // Disregard bytes 0 and 5 - see RespondIdentifyWiiMotionPlus() if ((val | 0xff000000ff00) == (ID_ActiveMotionPlus | 0xff000000ff00)) { _current_ext = ExtensionController.MOTIONPLUS; if(_Extension == null || _Extension.GetType() != typeof(MotionPlusData)) _Extension = new MotionPlusData(this); } else if (val == ID_ActiveMotionPlus_Nunchuck) { _current_ext = ExtensionController.MOTIONPLUS_NUNCHUCK; _Extension = null; } else if (val == ID_ActiveMotionPlus_Classic) { _current_ext = ExtensionController.MOTIONPLUS_CLASSIC; _Extension = null; } else if (val == ID_ClassicPro) { _current_ext = ExtensionController.CLASSIC_PRO; _Extension = null; } else if (val == ID_Nunchuck || val == ID_Nunchuck2) { _current_ext = ExtensionController.NUNCHUCK; if (_Extension == null || _Extension.GetType() != typeof(NunchuckData)) _Extension = new NunchuckData(this); } else if (val == ID_Classic) { _current_ext = ExtensionController.CLASSIC; if (_Extension == null || _Extension.GetType() != typeof(ClassicControllerData)) _Extension = new ClassicControllerData(this); } else if (val == ID_WiiUPro) { _current_ext = ExtensionController.WIIU_PRO; _Type = WiimoteType.PROCONTROLLER; if (_Extension == null || _Extension.GetType() != typeof(WiiUProData)) _Extension = new WiiUProData(this); } else if (val == ID_Guitar) { _current_ext = ExtensionController.GUITAR; if (_Extension == null || _Extension.GetType() != typeof(GuitarData)) _Extension = new GuitarData(this); } else { _current_ext = ExtensionController.NONE; _Extension = null; } }
private static void Process(UploadQueue itemToProcess) { var p = new Package(); var error = false; try { //Trace.WriteLine("Found an item to process", "Information"); Messages.LogMessage(itemToProcess, MessageList.Start); //move the file to local server storage var tempFile = FileHelpers.MoveBlobToTempStorage(itemToProcess.FileLocation); Messages.LogMessage(itemToProcess, MessageList.LocalStorage); //build a new 'package' object p.Path = tempFile; if (p.Messages == null) { p.Messages = new List <VerificationMessage>(); } //unzip the package var fz = new FastZip(); var shortpath = Environment.GetEnvironmentVariable("ShortRootPath") ?? Path.GetTempPath(); var tempPath = Path.Combine(shortpath, Guid.NewGuid().ToString()); //Trace.WriteLine("Package location: " + tempPath); Directory.CreateDirectory(tempPath); p.ExtractedPath = tempPath; try { using (var stm = new FileStream(p.Path, FileMode.Open)) { fz.ExtractZip(stm, tempPath, FastZip.Overwrite.Always, null, null, null, true, true); } } catch (Exception exc) { error = true; Trace.TraceError("Error while extracting file."); Trace.TraceError(exc.Message); if (exc.InnerException != null) { Trace.TraceError(exc.InnerException.Message); } p.Messages.Add(new VerificationMessage { Message = "Problem encountered while attempting to extract uploaded file.", MessageId = new Guid("9ac011fa-08dd-4e26-91ba-0af7d5daf482"), MessageType = MessageTypes.SystemError, Rule = "Extraction" }); goto Cleanup; } Messages.LogMessage(itemToProcess, MessageList.UnZipped); Messages.LogMessage(itemToProcess, MessageList.Processing); p.Messages.AddRange(new PackageExists().ApplyRule(p)); p.Messages.AddRange(new MinPackageSize().ApplyRule(p)); p.Messages.AddRange(new ManifestFileExists().ApplyRule(p)); p.Messages.AddRange(new ManifestIsXML().ApplyRule(p)); foreach (var manifest in p.DNNManifests) { p.Messages.AddRange(new CorrectTypeAndVersion().ApplyRule(p, manifest)); switch (manifest.ManifestType) { case ManifestTypes.Package: p.Messages.AddRange(new PackageNodeAndChildren().ApplyRule(p, manifest)); p.Messages.AddRange(new PackageOwner().ApplyRule(p, manifest)); p.Messages.AddRange(new AssemblyNode().ApplyRule(p, manifest)); p.Messages.AddRange(new AuthenticationSystemNode().ApplyRule(p, manifest)); p.Messages.AddRange(new DashboardControlNode().ApplyRule(p, manifest)); p.Messages.AddRange(new CleanupNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ConfigNode().ApplyRule(p, manifest)); p.Messages.AddRange(new FileNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ModuleNode().ApplyRule(p, manifest)); p.Messages.AddRange(new SkinNode().ApplyRule(p, manifest)); p.Messages.AddRange(new SkinObjectNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ContainerNode().ApplyRule(p, manifest)); p.Messages.AddRange(new CoreLanguageNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ExtensionLanguageNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ResourceFileNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ScriptNode().ApplyRule(p, manifest)); p.Messages.AddRange(new WidgetNode().ApplyRule(p, manifest)); break; case ManifestTypes.Module: p.Messages.AddRange(new FolderNodeAndChildren().ApplyRule(p, manifest)); p.Messages.AddRange(new FileNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ModuleNode().ApplyRule(p, manifest)); p.Messages.AddRange(new ProcessScripts().ApplyRule(p, manifest)); break; } Messages.LogMessage(itemToProcess, MessageList.TwoWayFileChecker); //Trace.WriteLine("Running two-way file checker.", "Information"); p.Messages.AddRange(new TwoWayFileChecker().ApplyRule(p, manifest)); Messages.LogMessage(itemToProcess, MessageList.AssemblyChecker); //Trace.WriteLine("Running assembly checker.", "Information"); const string assemblyInfoFile = @"collection.xml"; p.MinDotNetVersion = ProcessAssembly.GetMinDotNetFramework(p.Assemblies).VersionName; p.MinDotNetNukeVersion = ProcessAssembly.GetMinDotNetNukeVersion(p.Assemblies, assemblyInfoFile).Name; Messages.LogMessage(itemToProcess, MessageList.SQLChecker); //Trace.WriteLine("Running SQL scanner.", "Information"); p.Messages.AddRange(new SQLTestRunner().ApplyRule(p, manifest)); } p.Messages.AddRange(new FileEncodingChecker().ApplyRule(p)); p.Messages.AddRange(new DependencyChecker().ApplyRule(p)); Messages.LogMessage(itemToProcess, MessageList.BuildingOutput); //Let's process the SQL output if there is any. if (p.SQLOutputPath != null) { var tempPathForZip = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPathForZip); var filename = itemToProcess.FileID + ".zip"; var destination = tempPathForZip + "\\" + filename; var zipInputStream = File.Create(destination); using (zipInputStream) { fz.CreateZip(zipInputStream, p.SQLOutputPath, true, "", ""); } var zipStream = File.Open(destination, FileMode.Open); using (zipStream) { var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(Constants.ConfigurationSectionKey)); var blobClient = storageAccount.CreateCloudBlobClient(); var container = blobClient.GetContainerReference(Constants.ContainerNameScripts); container.CreateIfNotExists(); var file = container.GetBlockBlobReference(filename); file.UploadFromStream(zipStream); } try { File.Delete(destination); } catch (Exception exc) { error = true; Trace.TraceError("Error while deleting temp SQL output files."); Trace.TraceError(exc.Message); if (exc.InnerException != null) { Trace.TraceError(exc.InnerException.Message); } } } //clean up Cleanup: try { File.Delete(tempFile); //remove the temp file from the server. DeleteDirectory(p.ExtractedPath); //remove the extracted folder from the server. if (p.SQLOutputPath != null) { DeleteDirectory(p.SQLOutputPath); } } catch (Exception exc) { error = true; Trace.TraceError("Error while deleting temp files."); Trace.TraceError(exc.Message); if (exc.InnerException != null) { Trace.TraceError(exc.InnerException.Message); } } } catch (Exception exc) { error = true; Trace.TraceError("Error while processing extension."); Trace.TraceError(exc.Message); Trace.TraceError(exc.StackTrace); if (exc.InnerException != null) { Trace.TraceError(exc.InnerException.Message); } } finally { UploadQueueController.RemoveItemFromQueue(itemToProcess); //remove the item from the queue. if (itemToProcess.UserKey != "44eb5af6-2205-488e-9985-f7204c268820") { FileHelpers.RemoveBlob(itemToProcess.FileLocation); //this will remove the file from blob storage. } var extension = new Extension(itemToProcess); ExtensionController.AddExtension(extension); ProcessResults(p, extension.ExtensionID, error); //report to the status service that this file has finished processing. Messages.LogMessage(itemToProcess, MessageList.Finish); } }
public Map() { extensionController = new ExtensionController(this); mapElements = new List <MapElement <T> >(); }
// Reads and interprets data reported by the Wii Remote. // On success, > 0, < 0 on failure, 0 if nothing has been recieved. public int ReadWiimoteData() { byte[] buf = new byte[22]; int iStatus = CS_WiiMoteManager.RecieveRaw(hidapi_handle, buf); if (iStatus <= 0) { return(iStatus); // Either there is an error or nothings been received } int iTypeSize = GetInputDataTypeSize((InputDataType)buf[0]); byte[] data = new byte[iTypeSize]; for (int x = 0; x < data.Length; x++) { data[x] = buf[x + 1]; } if (CS_WiiMoteManager.bDebugMessages) { Debug.Log("Recieved: [" + buf[0].ToString("X").PadLeft(2, '0') + "] " + BitConverter.ToString(data)); } byte[] ext = null; switch ((InputDataType)buf[0]) // buf[0] is the output ID byte { case InputDataType.STATUS_INFO: Debug.Log("Status"); byte flags = data[2]; byte battery_level = data[5]; bool bOld_Ext_Connected = Status.ext_connected; byte[] total = new byte[] { flags, battery_level }; Status.InterpretData(total); if (Status.ext_connected != bOld_Ext_Connected) { if (Status.ext_connected) //Only reads the extensions if the Nunchuck is connected { Debug.Log("An extension has been connected."); ActivateExtension(); RequestIdentifyExtension(); // Identifies if the extension was a Nunchuck or not } else { _current_ext = ExtensionController.NONE; Debug.Log("An extension has been disconnected."); } } break; case InputDataType.READ_MEMORY_REGISTERS: if (CurrentReadData == null) { Debug.LogWarning("Recived Register Read Report when none was expected. Ignoring."); return(iStatus); } byte size = (byte)((data[2] >> 4) + 0x01); byte error = (byte)(data[2] & 0x0f); // Error 0x07 means reading from a write-only register if (error == 0x07) { CurrentReadData = null; return(iStatus); } // uLowOffset is reversed because the Wii Remote reports are in Big Endian order ushort uLowOffset = BitConverter.ToUInt16(new byte[] { data[4], data[3] }, 0); ushort uExpected = (ushort)CurrentReadData.ExpectedOffset; if (uExpected != uLowOffset) { Debug.LogWarning("Expected Register Read Offset (" + uExpected + ") does not match reported offset from Wii Remote (" + uLowOffset + ")"); } byte[] read = new byte[size]; for (int x = 0; x < size; x++) { read[x] = data[x + 5]; } CurrentReadData.AppendData(read); if (CurrentReadData.ExpectedOffset >= CurrentReadData.Offset + CurrentReadData.Size) { CurrentReadData = null; } break; case InputDataType.REPORT_BUTTONS_IR10_EXT9: ext = new byte[9]; for (int x = 0; x < 9; x++) { ext[x] = data[x + 12]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_ACCEL_IR10_EXT6: ext = new byte[6]; for (int x = 0; x < 6; x++) { ext[x] = data[x + 15]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; } if (ext == null) { _RawExtension = null; } else { _RawExtension = new CS_ReadOnlyArray <byte>(ext); } return(iStatus); }