JLinkControlPanel.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <html>
  2. <head>
  3. <script language="javascript">
  4. //
  5. // What we do is:
  6. // (1) We request an image from the control panel that we know to always exist
  7. // (2) Via the "onerror" and "onload" callbacks of the image object, we can determine if the image load was successful or not
  8. // (3) We make sure that we append some random data as parameter to the URL, to make sure that the browser does not cache the image, which could lead to incorrect "O.K." indications in case there is no control panel session running
  9. //
  10. /*********************************************************************
  11. *
  12. * Static data
  13. *
  14. **********************************************************************
  15. */
  16. var ObjImg = new Image;
  17. var NumTries = 0;
  18. /*********************************************************************
  19. *
  20. * _getRandomInt()
  21. *
  22. * Function description
  23. * Returns a random integer between 0 and x
  24. *
  25. * Return value
  26. * Integer between 0 and <MaxNum> - 1
  27. */
  28. function _getRandomInt(MaxNum) {
  29. return Math.floor(Math.random() * Math.floor(MaxNum));
  30. }
  31. /*********************************************************************
  32. *
  33. * _OnImgLoadError()
  34. *
  35. * Function description
  36. * Callback which in called in case loading the image from the server fails
  37. */
  38. function _OnImgLoadError(){
  39. _TryLoadImage();
  40. }
  41. /*********************************************************************
  42. *
  43. * _OnImgLoadSuccess()
  44. *
  45. * Function description
  46. * Callback which in called in case loading the image from the server was successful
  47. */
  48. function _OnImgLoadSuccess() {
  49. window.location.href = "http://localhost:19080";
  50. }
  51. /*********************************************************************
  52. *
  53. * _TryLoadImage()
  54. *
  55. * Function description
  56. * Called when page is opened in web browser
  57. */
  58. function _TryLoadImage() {
  59. NumTries += 1;
  60. document.getElementById("PNumTries").innerHTML = "Connect tries: " + NumTries;
  61. ObjImg.onerror=_OnImgLoadError;
  62. ObjImg.onload=_OnImgLoadSuccess;
  63. ObjImg.src="http://localhost:19080/SeggerLogo_200x.png?" + _getRandomInt(1000000); // See (3)
  64. }
  65. </script>
  66. </head>
  67. <body onload="_TryLoadImage();"> <!-- See (1) -->
  68. <p id="WelcomeText">
  69. Connecting to control panel...<br>
  70. This page will automatically refresh, as soon as there is a debug session running.
  71. </p>
  72. <p id="PNumTries"></p>
  73. </body>
  74. </html>