1
0

demo.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. //////////////////////////////////////////////////////////////////////////
  9. // To use the managed library, you must:
  10. // 1. Import ANT_NET.dll as a reference
  11. // 2. Reference the ANT_Managed_Library namespace
  12. // 3. Include the following files in the working directory of your application:
  13. // - DSI_CP310xManufacturing_3_1.dll
  14. // - DSI_SiUSBXp_3_1.dll
  15. // - ANT_WrappedLib.dll
  16. // - ANT_NET.dll
  17. //////////////////////////////////////////////////////////////////////////
  18. #define ENABLE_EXTENDED_MESSAGES // Un - coment to enable extended messages
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Text;
  23. using ANT_Managed_Library;
  24. namespace ANT_Console_Demo
  25. {
  26. class demo
  27. {
  28. static readonly byte CHANNEL_TYPE_INVALID = 2;
  29. static readonly byte USER_ANT_CHANNEL = 0; // ANT Channel to use
  30. static readonly ushort USER_DEVICENUM = 14728; // Device number
  31. static readonly byte USER_DEVICETYPE = 120; // Device type
  32. static readonly byte USER_TRANSTYPE = 0; // Transmission type
  33. static readonly byte USER_RADIOFREQ = 57; // RF Frequency + 2400 MHz
  34. static readonly ushort USER_CHANNELPERIOD = 8070; // Channel Period (8192/32768)s period = 4Hz
  35. static readonly byte[] USER_NETWORK_KEY = { 0, 0, 0, 0, 0, 0, 0, 0 };
  36. static readonly byte USER_NETWORK_NUM = 0; // The network key is assigned to this network number
  37. static ANT_Device device0;
  38. static ANT_Channel channel0;
  39. static ANT_ReferenceLibrary.ChannelType channelType;
  40. static byte[] txBuffer = { 0, 0, 0, 0, 0, 0, 0, 0 };
  41. static bool bDone;
  42. static bool bDisplay;
  43. static bool bBroadcasting;
  44. static int iIndex = 0;
  45. ////////////////////////////////////////////////////////////////////////////////
  46. // Main
  47. //
  48. // Usage:
  49. //
  50. // c:\demo_net.exe [channel_type]
  51. //
  52. // ... where
  53. // channel_type: Master = 0, Slave = 1
  54. //
  55. // ... example
  56. //
  57. // c:\demo_net.exe 0
  58. //
  59. // will connect to an ANT USB stick open a Master channel
  60. //
  61. // If optional arguements are not supplied, user will
  62. // be prompted to enter these after the program starts
  63. //
  64. ////////////////////////////////////////////////////////////////////////////////
  65. static void Main(string[] args)
  66. {
  67. byte ucChannelType = 1;
  68. if (args.Length > 0)
  69. {
  70. ucChannelType = byte.Parse(args[0]);
  71. }
  72. try
  73. {
  74. Init();
  75. Start(ucChannelType);
  76. }
  77. catch (Exception ex)
  78. {
  79. Console.WriteLine("Demo failed with exception: \n" + ex.Message);
  80. }
  81. }
  82. ////////////////////////////////////////////////////////////////////////////////
  83. // Init
  84. //
  85. // Initialize demo parameters.
  86. //
  87. ////////////////////////////////////////////////////////////////////////////////
  88. static void Init()
  89. {
  90. try
  91. {
  92. Console.WriteLine("Attempting to connect to an ANT USB device...");
  93. device0 = new ANT_Device(); // Create a device instance using the automatic constructor (automatic detection of USB device number and baud rate)
  94. device0.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse); // Add device response function to receive protocol event messages
  95. channel0 = device0.getChannel(USER_ANT_CHANNEL); // Get channel from ANT device
  96. channel0.channelResponse += new dChannelResponseHandler(ChannelResponse); // Add channel response function to receive channel event messages
  97. Console.WriteLine("Initialization was successful!");
  98. }
  99. catch (Exception ex)
  100. {
  101. if (device0 == null) // Unable to connect to ANT
  102. {
  103. throw new Exception("Could not connect to any device.\n" +
  104. "Details: \n " + ex.Message);
  105. }
  106. else
  107. {
  108. throw new Exception("Error connecting to ANT: " + ex.Message);
  109. }
  110. }
  111. }
  112. ////////////////////////////////////////////////////////////////////////////////
  113. // Start
  114. //
  115. // Start the demo program.
  116. //
  117. // ucChannelType_: ANT Channel Type. 0 = Master, 1 = Slave
  118. // If not specified, 2 is passed in as invalid.
  119. ////////////////////////////////////////////////////////////////////////////////
  120. static void Start(byte ucChannelType_)
  121. {
  122. byte ucChannelType = ucChannelType_;
  123. bDone = false;
  124. bDisplay = true;
  125. bBroadcasting = false;
  126. PrintMenu();
  127. // If a channel type has not been set at the command line,
  128. // prompt the user to specify one now
  129. do
  130. {
  131. if (ucChannelType == CHANNEL_TYPE_INVALID)
  132. {
  133. Console.WriteLine("Channel Type? (Master = 0, Slave = 1)");
  134. try
  135. {
  136. ucChannelType = byte.Parse(Console.ReadLine());
  137. }
  138. catch (Exception)
  139. {
  140. ucChannelType = CHANNEL_TYPE_INVALID;
  141. }
  142. }
  143. if (ucChannelType == 0)
  144. {
  145. channelType = ANT_ReferenceLibrary.ChannelType.BASE_Master_Transmit_0x10;
  146. }
  147. else if (ucChannelType == 1)
  148. {
  149. channelType = ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00;
  150. }
  151. else
  152. {
  153. ucChannelType = CHANNEL_TYPE_INVALID;
  154. Console.WriteLine("Error: Invalid channel type");
  155. }
  156. } while (ucChannelType == CHANNEL_TYPE_INVALID);
  157. try
  158. {
  159. ConfigureANT();
  160. while (!bDone)
  161. {
  162. string command = Console.ReadLine();
  163. switch (command)
  164. {
  165. case "M":
  166. case "m":
  167. {
  168. PrintMenu();
  169. break;
  170. }
  171. case "Q":
  172. case "q":
  173. {
  174. // Quit
  175. Console.WriteLine("Closing Channel");
  176. bBroadcasting = false;
  177. channel0.closeChannel();
  178. break;
  179. }
  180. case "A":
  181. case "a":
  182. {
  183. // Send Acknowledged Data
  184. byte[] myTxBuffer = { 1, 2, 3, 4, 5, 6, 7, 8 };
  185. channel0.sendAcknowledgedData(myTxBuffer);
  186. break;
  187. }
  188. case "B":
  189. case "b":
  190. {
  191. // Send Burst Data (10 packets)
  192. byte[] myTxBuffer = new byte[8 * 10];
  193. for (byte i = 0; i < 8 * 10; i++)
  194. myTxBuffer[i] = i;
  195. channel0.sendBurstTransfer(myTxBuffer);
  196. break;
  197. }
  198. case "R":
  199. case "r":
  200. {
  201. // Reset the system and start over the test
  202. ConfigureANT();
  203. break;
  204. }
  205. case "C":
  206. case "c":
  207. {
  208. // Request capabilities
  209. ANT_DeviceCapabilities devCapab = device0.getDeviceCapabilities(500);
  210. Console.Write(devCapab.printCapabilities() + Environment.NewLine);
  211. break;
  212. }
  213. case "V":
  214. case "v":
  215. {
  216. // Request version
  217. // As this is not available in all ANT parts, we should not wait for a response, so
  218. // we do not specify a timeout
  219. // The response - if available - will be processed in DeviceResponse
  220. device0.requestMessage(ANT_ReferenceLibrary.RequestMessageID.VERSION_0x3E);
  221. break;
  222. }
  223. case "S":
  224. case "s":
  225. {
  226. // Request channel status
  227. ANT_ChannelStatus chStatus = channel0.requestStatus(500);
  228. string[] allStatus = { "STATUS_UNASSIGNED_CHANNEL",
  229. "STATUS_ASSIGNED_CHANNEL",
  230. "STATUS_SEARCHING_CHANNEL",
  231. "STATUS_TRACKING_CHANNEL"};
  232. Console.WriteLine("STATUS: " + allStatus[(int)chStatus.BasicStatus]);
  233. break;
  234. }
  235. case "I":
  236. case "i":
  237. {
  238. // Request channel ID
  239. ANT_Response respChID = device0.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 500);
  240. ushort usDeviceNumber = (ushort) ((respChID.messageContents[2] << 8) + respChID.messageContents[1]);
  241. byte ucDeviceType = respChID.messageContents[3];
  242. byte ucTransmissionType = respChID.messageContents[4];
  243. Console.WriteLine("CHANNEL ID: (" + usDeviceNumber.ToString() + "," + ucDeviceType.ToString() + "," + ucTransmissionType.ToString() + ")");
  244. break;
  245. }
  246. case "D":
  247. case "d":
  248. {
  249. bDisplay = !bDisplay;
  250. break;
  251. }
  252. case "U":
  253. case "u":
  254. {
  255. // Print out information about the device we are connected to
  256. Console.WriteLine("USB Device Description");
  257. // Retrieve info
  258. Console.WriteLine(String.Format(" VID: 0x{0:x}", device0.getDeviceUSBVID()));
  259. Console.WriteLine(String.Format(" PID: 0x{0:x}", device0.getDeviceUSBPID()));
  260. Console.WriteLine(String.Format(" Product Description: {0}", device0.getDeviceUSBInfo().printProductDescription()));
  261. Console.WriteLine(String.Format(" Serial String: {0}", device0.getDeviceUSBInfo().printSerialString()));
  262. break;
  263. }
  264. default:
  265. {
  266. break;
  267. }
  268. }
  269. System.Threading.Thread.Sleep(0);
  270. }
  271. // Clean up ANT
  272. Console.WriteLine("Disconnecting module...");
  273. ANT_Device.shutdownDeviceInstance(ref device0); // Close down the device completely and completely shut down all communication
  274. Console.WriteLine("Demo has completed successfully!");
  275. return;
  276. }
  277. catch (Exception ex)
  278. {
  279. throw new Exception("Demo failed: " + ex.Message + Environment.NewLine);
  280. }
  281. }
  282. ////////////////////////////////////////////////////////////////////////////////
  283. // ConfigureANT
  284. //
  285. // Resets the system, configures the ANT channel and starts the demo
  286. ////////////////////////////////////////////////////////////////////////////////
  287. private static void ConfigureANT()
  288. {
  289. Console.WriteLine("Resetting module...");
  290. device0.ResetSystem(); // Soft reset
  291. System.Threading.Thread.Sleep(500); // Delay 500ms after a reset
  292. // If you call the setup functions specifying a wait time, you can check the return value for success or failure of the command
  293. // This function is blocking - the thread will be blocked while waiting for a response.
  294. // 500ms is usually a safe value to ensure you wait long enough for any response
  295. // If you do not specify a wait time, the command is simply sent, and you have to monitor the protocol events for the response,
  296. Console.WriteLine("Setting network key...");
  297. if (device0.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
  298. Console.WriteLine("Network key set");
  299. else
  300. throw new Exception("Error configuring network key");
  301. Console.WriteLine("Assigning channel...");
  302. if (channel0.assignChannel(channelType, USER_NETWORK_NUM, 500))
  303. Console.WriteLine("Channel assigned");
  304. else
  305. throw new Exception("Error assigning channel");
  306. Console.WriteLine("Setting Channel ID...");
  307. if (channel0.setChannelID(USER_DEVICENUM, false, USER_DEVICETYPE, USER_TRANSTYPE, 500)) // Not using pairing bit
  308. Console.WriteLine("Channel ID set");
  309. else
  310. throw new Exception("Error configuring Channel ID");
  311. Console.WriteLine("Setting Radio Frequency...");
  312. if (channel0.setChannelFreq(USER_RADIOFREQ, 500))
  313. Console.WriteLine("Radio Frequency set");
  314. else
  315. throw new Exception("Error configuring Radio Frequency");
  316. Console.WriteLine("Setting Channel Period...");
  317. if (channel0.setChannelPeriod(USER_CHANNELPERIOD, 500))
  318. Console.WriteLine("Channel Period set");
  319. else
  320. throw new Exception("Error configuring Channel Period");
  321. Console.WriteLine("Opening channel...");
  322. bBroadcasting = true;
  323. if (channel0.openChannel(500))
  324. {
  325. Console.WriteLine("Channel opened");
  326. }
  327. else
  328. {
  329. bBroadcasting = false;
  330. throw new Exception("Error opening channel");
  331. }
  332. #if (ENABLE_EXTENDED_MESSAGES)
  333. // Extended messages are not supported in all ANT devices, so
  334. // we will not wait for the response here, and instead will monitor
  335. // the protocol events
  336. Console.WriteLine("Enabling extended messages...");
  337. device0.enableRxExtendedMessages(true);
  338. #endif
  339. }
  340. ////////////////////////////////////////////////////////////////////////////////
  341. // ChannelResponse
  342. //
  343. // Called whenever a channel event is recieved.
  344. //
  345. // response: ANT message
  346. ////////////////////////////////////////////////////////////////////////////////
  347. static void ChannelResponse(ANT_Response response)
  348. {
  349. try
  350. {
  351. switch ((ANT_ReferenceLibrary.ANTMessageID)response.responseID)
  352. {
  353. case ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40:
  354. {
  355. switch (response.getChannelEventCode())
  356. {
  357. // This event indicates that a message has just been
  358. // sent over the air. We take advantage of this event to set
  359. // up the data for the next message period.
  360. case ANT_ReferenceLibrary.ANTEventID.EVENT_TX_0x03:
  361. {
  362. txBuffer[0]++; // Increment the first byte of the buffer
  363. // Broadcast data will be sent over the air on
  364. // the next message period
  365. if (bBroadcasting)
  366. {
  367. channel0.sendBroadcastData(txBuffer);
  368. if (bDisplay)
  369. {
  370. // Echo what the data will be over the air on the next message period
  371. Console.WriteLine("Tx: (" + response.antChannel.ToString() + ")" + BitConverter.ToString(txBuffer));
  372. }
  373. }
  374. else
  375. {
  376. string[] ac = { "|", "/", "_", "\\" };
  377. Console.Write("Tx: " + ac[iIndex++] + "\r");
  378. iIndex &= 3;
  379. }
  380. break;
  381. }
  382. case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_SEARCH_TIMEOUT_0x01:
  383. {
  384. Console.WriteLine("Search Timeout");
  385. break;
  386. }
  387. case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_0x02:
  388. {
  389. Console.WriteLine("Rx Fail");
  390. break;
  391. }
  392. case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_RX_FAILED_0x04:
  393. {
  394. Console.WriteLine("Burst receive has failed");
  395. break;
  396. }
  397. case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_COMPLETED_0x05:
  398. {
  399. Console.WriteLine("Transfer Completed");
  400. break;
  401. }
  402. case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_FAILED_0x06:
  403. {
  404. Console.WriteLine("Transfer Failed");
  405. break;
  406. }
  407. case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_CLOSED_0x07:
  408. {
  409. // This event should be used to determine that the channel is closed.
  410. Console.WriteLine("Channel Closed");
  411. Console.WriteLine("Unassigning Channel...");
  412. if (channel0.unassignChannel(500))
  413. {
  414. Console.WriteLine("Unassigned Channel");
  415. Console.WriteLine("Press enter to exit");
  416. bDone = true;
  417. }
  418. break;
  419. }
  420. case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_GO_TO_SEARCH_0x08:
  421. {
  422. Console.WriteLine("Go to Search");
  423. break;
  424. }
  425. case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_COLLISION_0x09:
  426. {
  427. Console.WriteLine("Channel Collision");
  428. break;
  429. }
  430. case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_START_0x0A:
  431. {
  432. Console.WriteLine("Burst Started");
  433. break;
  434. }
  435. default:
  436. {
  437. Console.WriteLine("Unhandled Channel Event " + response.getChannelEventCode());
  438. break;
  439. }
  440. }
  441. break;
  442. }
  443. case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E:
  444. case ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F:
  445. case ANT_ReferenceLibrary.ANTMessageID.BURST_DATA_0x50:
  446. case ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D:
  447. case ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E:
  448. case ANT_ReferenceLibrary.ANTMessageID.EXT_BURST_DATA_0x5F:
  449. {
  450. if (bDisplay)
  451. {
  452. if (response.isExtended()) // Check if we are dealing with an extended message
  453. {
  454. ANT_ChannelID chID = response.getDeviceIDfromExt(); // Channel ID of the device we just received a message from
  455. Console.Write("Chan ID(" + chID.deviceNumber.ToString() + "," + chID.deviceTypeID.ToString() + "," + chID.transmissionTypeID.ToString() + ") - ");
  456. }
  457. if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E
  458. || response.responseID == (byte) ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D)
  459. Console.Write("Rx:(" + response.antChannel.ToString() + "): ");
  460. else if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F
  461. || response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E)
  462. Console.Write("Acked Rx:(" + response.antChannel.ToString() + "): ");
  463. else
  464. Console.Write("Burst(" + response.getBurstSequenceNumber().ToString("X2") + ") Rx:(" + response.antChannel.ToString() + "): ");
  465. Console.Write(BitConverter.ToString(response.getDataPayload()) + Environment.NewLine); // Display data payload
  466. }
  467. else
  468. {
  469. string[] ac = { "|", "/", "_", "\\" };
  470. Console.Write("Rx: " + ac[iIndex++] + "\r");
  471. iIndex &= 3;
  472. }
  473. break;
  474. }
  475. default:
  476. {
  477. Console.WriteLine("Unknown Message " + response.responseID);
  478. break;
  479. }
  480. }
  481. }
  482. catch (Exception ex)
  483. {
  484. Console.WriteLine("Channel response processing failed with exception: " + ex.Message);
  485. }
  486. }
  487. ////////////////////////////////////////////////////////////////////////////////
  488. // DeviceResponse
  489. //
  490. // Called whenever a message is received from ANT unless that message is a
  491. // channel event message.
  492. //
  493. // response: ANT message
  494. ////////////////////////////////////////////////////////////////////////////////
  495. static void DeviceResponse(ANT_Response response)
  496. {
  497. switch ((ANT_ReferenceLibrary.ANTMessageID) response.responseID)
  498. {
  499. case ANT_ReferenceLibrary.ANTMessageID.STARTUP_MESG_0x6F:
  500. {
  501. Console.Write("RESET Complete, reason: ");
  502. byte ucReason = response.messageContents[0];
  503. if(ucReason == (byte) ANT_ReferenceLibrary.StartupMessage.RESET_POR_0x00)
  504. Console.WriteLine("RESET_POR");
  505. if(ucReason == (byte) ANT_ReferenceLibrary.StartupMessage.RESET_RST_0x01)
  506. Console.WriteLine("RESET_RST");
  507. if(ucReason == (byte) ANT_ReferenceLibrary.StartupMessage.RESET_WDT_0x02)
  508. Console.WriteLine("RESET_WDT");
  509. if(ucReason == (byte) ANT_ReferenceLibrary.StartupMessage.RESET_CMD_0x20)
  510. Console.WriteLine("RESET_CMD");
  511. if(ucReason == (byte) ANT_ReferenceLibrary.StartupMessage.RESET_SYNC_0x40)
  512. Console.WriteLine("RESET_SYNC");
  513. if(ucReason == (byte) ANT_ReferenceLibrary.StartupMessage.RESET_SUSPEND_0x80)
  514. Console.WriteLine("RESET_SUSPEND");
  515. break;
  516. }
  517. case ANT_ReferenceLibrary.ANTMessageID.VERSION_0x3E:
  518. {
  519. Console.WriteLine("VERSION: " + new ASCIIEncoding().GetString(response.messageContents));
  520. break;
  521. }
  522. case ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40:
  523. {
  524. switch (response.getMessageID())
  525. {
  526. case ANT_ReferenceLibrary.ANTMessageID.CLOSE_CHANNEL_0x4C:
  527. {
  528. if (response.getChannelEventCode() == ANT_ReferenceLibrary.ANTEventID.CHANNEL_IN_WRONG_STATE_0x15)
  529. {
  530. Console.WriteLine("Channel is already closed");
  531. Console.WriteLine("Unassigning Channel...");
  532. if (channel0.unassignChannel(500))
  533. {
  534. Console.WriteLine("Unassigned Channel");
  535. Console.WriteLine("Press enter to exit");
  536. bDone = true;
  537. }
  538. }
  539. break;
  540. }
  541. case ANT_ReferenceLibrary.ANTMessageID.NETWORK_KEY_0x46:
  542. case ANT_ReferenceLibrary.ANTMessageID.ASSIGN_CHANNEL_0x42:
  543. case ANT_ReferenceLibrary.ANTMessageID.CHANNEL_ID_0x51:
  544. case ANT_ReferenceLibrary.ANTMessageID.CHANNEL_RADIO_FREQ_0x45:
  545. case ANT_ReferenceLibrary.ANTMessageID.CHANNEL_MESG_PERIOD_0x43:
  546. case ANT_ReferenceLibrary.ANTMessageID.OPEN_CHANNEL_0x4B:
  547. case ANT_ReferenceLibrary.ANTMessageID.UNASSIGN_CHANNEL_0x41:
  548. {
  549. if (response.getChannelEventCode() != ANT_ReferenceLibrary.ANTEventID.RESPONSE_NO_ERROR_0x00)
  550. {
  551. Console.WriteLine(String.Format("Error {0} configuring {1}", response.getChannelEventCode(), response.getMessageID()));
  552. }
  553. break;
  554. }
  555. case ANT_ReferenceLibrary.ANTMessageID.RX_EXT_MESGS_ENABLE_0x66:
  556. {
  557. if (response.getChannelEventCode() == ANT_ReferenceLibrary.ANTEventID.INVALID_MESSAGE_0x28)
  558. {
  559. Console.WriteLine("Extended messages not supported in this ANT product");
  560. break;
  561. }
  562. else if(response.getChannelEventCode() != ANT_ReferenceLibrary.ANTEventID.RESPONSE_NO_ERROR_0x00)
  563. {
  564. Console.WriteLine(String.Format("Error {0} configuring {1}", response.getChannelEventCode(), response.getMessageID()));
  565. break;
  566. }
  567. Console.WriteLine("Extended messages enabled");
  568. break;
  569. }
  570. case ANT_ReferenceLibrary.ANTMessageID.REQUEST_0x4D:
  571. {
  572. if (response.getChannelEventCode() == ANT_ReferenceLibrary.ANTEventID.INVALID_MESSAGE_0x28)
  573. {
  574. Console.WriteLine("Requested message not supported in this ANT product");
  575. break;
  576. }
  577. break;
  578. }
  579. default:
  580. {
  581. Console.WriteLine("Unhandled response " + response.getChannelEventCode() + " to message " + response.getMessageID()); break;
  582. }
  583. }
  584. break;
  585. }
  586. }
  587. }
  588. ////////////////////////////////////////////////////////////////////////////////
  589. // PrintMenu
  590. //
  591. // Display demo menu
  592. //
  593. ////////////////////////////////////////////////////////////////////////////////
  594. static void PrintMenu()
  595. {
  596. // Print out options
  597. Console.WriteLine("M - Print this menu");
  598. Console.WriteLine("A - Send Acknowledged message");
  599. Console.WriteLine("B - Send Burst message");
  600. Console.WriteLine("R - Reset");
  601. Console.WriteLine("C - Request Capabilites");
  602. Console.WriteLine("V - Request Version");
  603. Console.WriteLine("I - Request Channel ID");
  604. Console.WriteLine("S - Request Status");
  605. Console.WriteLine("U - Request USB Descriptor");
  606. Console.WriteLine("D - Toggle Display");
  607. Console.WriteLine("Q - Quit");
  608. }
  609. }
  610. }