MainForm.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2012
  6. All rights reserved.
  7. */
  8. /* The ANT+ simulator was created to aid with the development and testing of ANT+ sensors and display devices.
  9. This is the main class, it controls opening the ANT library, connecting the ANT devices,
  10. creating the appropriate number of ANTChannel classes, adding the channel controls to the form and
  11. handling and forwarding appropriate ANT messages to the respective channels.
  12. */
  13. #pragma once
  14. #include <stdio.h>
  15. #include "stdafx.h"
  16. #include "config.h"
  17. #include "types.h"
  18. #include "antclass.h"
  19. #include "ANTChannel.h"
  20. #include "AboutSim.h"
  21. void UnmanagedSender(UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_);
  22. void UnmanagedEventSender(UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_);
  23. namespace ANTPlusSim {
  24. using namespace System;
  25. using namespace System::ComponentModel;
  26. using namespace System::Collections;
  27. using namespace System::Windows::Forms;
  28. using namespace System::Data;
  29. using namespace System::Drawing;
  30. struct capabilityDefs{
  31. UCHAR ucBitMask;
  32. char* flagDefinition;
  33. };
  34. const short int NUM_BASIC_CAPS =6;
  35. const short int NUM_EXTD_CAPS1 =6;
  36. const short int NUM_EXTD_CAPS2 =7;
  37. /// <summary>
  38. /// Summary for MainForm
  39. ///
  40. /// WARNING: If you change the name of this class, you will need to change the
  41. /// 'Resource File Name' property for the managed resource compiler tool
  42. /// associated with all .resx files this class depends on. Otherwise,
  43. /// the designers will not be able to interact properly with localized
  44. /// resources associated with this form.
  45. /// </summary>
  46. public ref class MainForm : public System::Windows::Forms::Form
  47. {
  48. public:
  49. MainForm(UCHAR ucSimType_);
  50. ~MainForm();
  51. void ProcessChannelEvent(UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_);
  52. void ProcessProtocolEvent(UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_);
  53. private:
  54. array<ANTChannel^> ^channelList;
  55. int numChannels;
  56. System::String^ strTitle;
  57. System::String^ strAbout;
  58. System::String^ strLibVersion;
  59. UCHAR ucSimType;
  60. BOOL bMyArct;
  61. BOOL bMyTimerStarted;
  62. BOOL bMyConnected;
  63. ANTPlatform eMyANTPlatform;
  64. CapabilitiesStruct sMyCapabilities;
  65. private: System::Windows::Forms::Panel^ panel_devicePanel_1;
  66. private: System::Windows::Forms::RichTextBox^ richTextBox_deviceReport_1;
  67. private: System::Windows::Forms::Button^ button_Connect;
  68. private: System::Windows::Forms::Label^ label_DeviceProfile;
  69. private: System::Windows::Forms::ComboBox^ comboBox_DeviceSelect;
  70. private: System::Windows::Forms::FlowLayoutPanel^ flowLayoutPanel_ActiveDeviceList;
  71. private: System::Windows::Forms::TabControl^ tabControl_Channels;
  72. private: System::Windows::Forms::RichTextBox^ richTextBox_MainStatus;
  73. private: System::Windows::Forms::Label^ label_ConnectedDevices;
  74. private: System::Windows::Forms::Label^ label_USBPort;
  75. private: System::Windows::Forms::NumericUpDown^ numericUpDown_USBSelect;
  76. private: System::Windows::Forms::Timer^ timerGeneric;
  77. private: System::Windows::Forms::TextBox^ textBox_baudRate;
  78. private: System::Windows::Forms::Label^ label1;
  79. private: System::Windows::Forms::LinkLabel^ linkLabel_About;
  80. private:
  81. /// <summary>
  82. void CreateDevicePanel();
  83. void RemoveDevicePanel();
  84. void InterpretCapabilities(UCHAR* pcBuffer_);
  85. void CreateChannels();
  86. void Connect();
  87. /// Required designer variable.
  88. /// </summary>
  89. System::ComponentModel::IContainer^ components;
  90. #pragma region Windows Form Designer generated code
  91. /// <summary>
  92. /// Required method for Designer support - do not modify
  93. /// the contents of this method with the code editor.
  94. /// </summary>
  95. void InitializeComponent(void)
  96. {
  97. this->components = (gcnew System::ComponentModel::Container());
  98. System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid));
  99. this->button_Connect = (gcnew System::Windows::Forms::Button());
  100. this->label_DeviceProfile = (gcnew System::Windows::Forms::Label());
  101. this->comboBox_DeviceSelect = (gcnew System::Windows::Forms::ComboBox());
  102. this->flowLayoutPanel_ActiveDeviceList = (gcnew System::Windows::Forms::FlowLayoutPanel());
  103. this->tabControl_Channels = (gcnew System::Windows::Forms::TabControl());
  104. this->richTextBox_MainStatus = (gcnew System::Windows::Forms::RichTextBox());
  105. this->label_ConnectedDevices = (gcnew System::Windows::Forms::Label());
  106. this->label_USBPort = (gcnew System::Windows::Forms::Label());
  107. this->numericUpDown_USBSelect = (gcnew System::Windows::Forms::NumericUpDown());
  108. this->linkLabel_About = (gcnew System::Windows::Forms::LinkLabel());
  109. this->timerGeneric = (gcnew System::Windows::Forms::Timer(this->components));
  110. this->textBox_baudRate = (gcnew System::Windows::Forms::TextBox());
  111. this->label1 = (gcnew System::Windows::Forms::Label());
  112. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown_USBSelect))->BeginInit();
  113. this->SuspendLayout();
  114. //
  115. // button_Connect
  116. //
  117. this->button_Connect->Location = System::Drawing::Point(243, 12);
  118. this->button_Connect->Name = L"button_Connect";
  119. this->button_Connect->Size = System::Drawing::Size(74, 23);
  120. this->button_Connect->TabIndex = 1;
  121. this->button_Connect->Text = L"Connect";
  122. this->button_Connect->UseVisualStyleBackColor = true;
  123. this->button_Connect->Click += gcnew System::EventHandler(this, &MainForm::button_Connect_Click);
  124. //
  125. // label_DeviceProfile
  126. //
  127. this->label_DeviceProfile->AutoSize = true;
  128. this->label_DeviceProfile->Location = System::Drawing::Point(42, 15);
  129. this->label_DeviceProfile->Name = L"label_DeviceProfile";
  130. this->label_DeviceProfile->Size = System::Drawing::Size(44, 13);
  131. this->label_DeviceProfile->TabIndex = 1;
  132. this->label_DeviceProfile->Text = L"Device:";
  133. //
  134. // comboBox_DeviceSelect
  135. //
  136. this->comboBox_DeviceSelect->FormattingEnabled = true;
  137. this->comboBox_DeviceSelect->ImeMode = System::Windows::Forms::ImeMode::Off;
  138. this->comboBox_DeviceSelect->Items->AddRange(gcnew cli::array< System::Object^ >(4) {L"AP2/USB2/AT3", L"C7", L"AP1/USB1",
  139. L"Custom USB"});
  140. this->comboBox_DeviceSelect->Location = System::Drawing::Point(92, 12);
  141. this->comboBox_DeviceSelect->Name = L"comboBox_DeviceSelect";
  142. this->comboBox_DeviceSelect->Size = System::Drawing::Size(145, 21);
  143. this->comboBox_DeviceSelect->TabIndex = 2;
  144. this->comboBox_DeviceSelect->Text = L"AP2/USB2/AT3";
  145. this->comboBox_DeviceSelect->SelectedValueChanged += gcnew System::EventHandler(this, &MainForm::comboBox_DeviceSelect_SelectedValueChanged);
  146. //
  147. // flowLayoutPanel_ActiveDeviceList
  148. //
  149. this->flowLayoutPanel_ActiveDeviceList->AutoScroll = true;
  150. this->flowLayoutPanel_ActiveDeviceList->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
  151. this->flowLayoutPanel_ActiveDeviceList->Location = System::Drawing::Point(377, 26);
  152. this->flowLayoutPanel_ActiveDeviceList->Name = L"flowLayoutPanel_ActiveDeviceList";
  153. this->flowLayoutPanel_ActiveDeviceList->Size = System::Drawing::Size(408, 127);
  154. this->flowLayoutPanel_ActiveDeviceList->TabIndex = 4;
  155. //
  156. // tabControl_Channels
  157. //
  158. this->tabControl_Channels->Location = System::Drawing::Point(45, 170);
  159. this->tabControl_Channels->Name = L"tabControl_Channels";
  160. this->tabControl_Channels->SelectedIndex = 0;
  161. this->tabControl_Channels->Size = System::Drawing::Size(740, 325);
  162. this->tabControl_Channels->TabIndex = 5;
  163. this->tabControl_Channels->TabStop = false;
  164. //
  165. // richTextBox_MainStatus
  166. //
  167. this->richTextBox_MainStatus->BackColor = System::Drawing::SystemColors::Window;
  168. this->richTextBox_MainStatus->HideSelection = false;
  169. this->richTextBox_MainStatus->Location = System::Drawing::Point(45, 63);
  170. this->richTextBox_MainStatus->Name = L"richTextBox_MainStatus";
  171. this->richTextBox_MainStatus->ReadOnly = true;
  172. this->richTextBox_MainStatus->Size = System::Drawing::Size(272, 90);
  173. this->richTextBox_MainStatus->TabIndex = 7;
  174. this->richTextBox_MainStatus->TabStop = false;
  175. this->richTextBox_MainStatus->Text = L"Select device type and press connect to begin...";
  176. //
  177. // label_ConnectedDevices
  178. //
  179. this->label_ConnectedDevices->AutoSize = true;
  180. this->label_ConnectedDevices->Location = System::Drawing::Point(374, 6);
  181. this->label_ConnectedDevices->Name = L"label_ConnectedDevices";
  182. this->label_ConnectedDevices->Size = System::Drawing::Size(104, 13);
  183. this->label_ConnectedDevices->TabIndex = 8;
  184. this->label_ConnectedDevices->Text = L"Connected Devices:";
  185. //
  186. // label_USBPort
  187. //
  188. this->label_USBPort->AutoSize = true;
  189. this->label_USBPort->Location = System::Drawing::Point(42, 42);
  190. this->label_USBPort->Name = L"label_USBPort";
  191. this->label_USBPort->Size = System::Drawing::Size(69, 13);
  192. this->label_USBPort->TabIndex = 9;
  193. this->label_USBPort->Text = L"on USB Port:";
  194. //
  195. // numericUpDown_USBSelect
  196. //
  197. this->numericUpDown_USBSelect->Location = System::Drawing::Point(117, 40);
  198. this->numericUpDown_USBSelect->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {255, 0, 0, 0});
  199. this->numericUpDown_USBSelect->Name = L"numericUpDown_USBSelect";
  200. this->numericUpDown_USBSelect->Size = System::Drawing::Size(50, 20);
  201. this->numericUpDown_USBSelect->TabIndex = 3;
  202. //
  203. // linkLabel_About
  204. //
  205. this->linkLabel_About->AutoSize = true;
  206. this->linkLabel_About->Location = System::Drawing::Point(750, 6);
  207. this->linkLabel_About->Name = L"linkLabel_About";
  208. this->linkLabel_About->Size = System::Drawing::Size(35, 13);
  209. this->linkLabel_About->TabIndex = 10;
  210. this->linkLabel_About->TabStop = true;
  211. this->linkLabel_About->Text = L"About";
  212. this->linkLabel_About->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &MainForm::linkLabel_About_LinkClicked);
  213. //
  214. // textBox_baudRate
  215. //
  216. this->textBox_baudRate->Location = System::Drawing::Point(226, 39);
  217. this->textBox_baudRate->Name = L"textBox_baudRate";
  218. this->textBox_baudRate->ReadOnly = true;
  219. this->textBox_baudRate->Size = System::Drawing::Size(68, 20);
  220. this->textBox_baudRate->TabIndex = 11;
  221. this->textBox_baudRate->Text = L"57600";
  222. //
  223. // label1
  224. //
  225. this->label1->AutoSize = true;
  226. this->label1->Location = System::Drawing::Point(173, 42);
  227. this->label1->Name = L"label1";
  228. this->label1->Size = System::Drawing::Size(47, 13);
  229. this->label1->TabIndex = 12;
  230. this->label1->Text = L"at Baud:";
  231. //
  232. // MainForm
  233. //
  234. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  235. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  236. this->ClientSize = System::Drawing::Size(816, 525);
  237. this->Controls->Add(this->label1);
  238. this->Controls->Add(this->textBox_baudRate);
  239. this->Controls->Add(this->linkLabel_About);
  240. this->Controls->Add(this->numericUpDown_USBSelect);
  241. this->Controls->Add(this->label_USBPort);
  242. this->Controls->Add(this->label_ConnectedDevices);
  243. this->Controls->Add(this->richTextBox_MainStatus);
  244. this->Controls->Add(this->tabControl_Channels);
  245. this->Controls->Add(this->flowLayoutPanel_ActiveDeviceList);
  246. this->Controls->Add(this->comboBox_DeviceSelect);
  247. this->Controls->Add(this->label_DeviceProfile);
  248. this->Controls->Add(this->button_Connect);
  249. this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
  250. this->Name = L"MainForm";
  251. this->Text = L"ANT+ Simulator";
  252. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown_USBSelect))->EndInit();
  253. this->ResumeLayout(false);
  254. this->PerformLayout();
  255. }
  256. #pragma endregion
  257. /**************************************************************************
  258. * System::Void MainForm_FormClosing
  259. *
  260. * Disconnect from ANT when closing the application
  261. *
  262. * returns: N/A
  263. *
  264. **************************************************************************/
  265. private: System::Void MainForm_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
  266. if(bMyConnected)
  267. {
  268. ANTClass::Disconnect();
  269. }
  270. }
  271. /**************************************************************************
  272. * System::Void button_Connect_Click
  273. *
  274. * Connect/disconnect to ANT
  275. *
  276. * returns: N/A
  277. *
  278. **************************************************************************/
  279. private: System::Void button_Connect_Click(System::Object^ sender, System::EventArgs^ e)
  280. {
  281. Connect();
  282. }
  283. /**************************************************************************
  284. * linkLabel_About_LinkClicked
  285. *
  286. * Displays simulator "About" box
  287. *
  288. * returns: N/A
  289. *
  290. **************************************************************************/
  291. private: System::Void linkLabel_About_LinkClicked(System::Object^ sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^ e) {
  292. AboutSim^ formAbout = gcnew AboutSim(strAbout, strLibVersion);
  293. formAbout->Show();
  294. }
  295. private: System::Void comboBox_DeviceSelect_SelectedValueChanged(System::Object^ sender, System::EventArgs^ e) {
  296. if(comboBox_DeviceSelect->SelectedItem->Equals("Custom USB"))
  297. {
  298. this->textBox_baudRate->Text = "57600";
  299. textBox_baudRate->ReadOnly = false;
  300. }
  301. else if(comboBox_DeviceSelect->SelectedItem->Equals("AP2/USB2/AT3") || comboBox_DeviceSelect->SelectedItem->Equals("C7"))
  302. {
  303. this->textBox_baudRate->Text = "57600";
  304. textBox_baudRate->ReadOnly = true;
  305. }
  306. else if(comboBox_DeviceSelect->SelectedItem->Equals("AP1/USB1"))
  307. {
  308. this->textBox_baudRate->Text = "50000";
  309. textBox_baudRate->ReadOnly = true;
  310. }
  311. else
  312. {
  313. this->textBox_baudRate->Text = "?";
  314. textBox_baudRate->ReadOnly = true;
  315. }
  316. }
  317. };
  318. }