For DOS Protected Mode version of sensor core software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3736 lines
113 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright ?2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 17/11/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: KERNEL.CPP
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of KERNEL.CPP
  13. //----------------------------------------------------------------------------
  14. #include "StdAfx.h"
  15. #include <errno.h>
  16. #include <mem.h>
  17. #include <bios.h>
  18. #include <dos.h>
  19. #include <dir.h>
  20. #include <io.h>
  21. #include <conio.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "kernel.h"
  25. #include "..\lglib\comm\lgsm.h"
  26. #include "..\lglib\lgbitcod.h"
  27. //#include "..\lglib\version.h"
  28. #include "screen.h"
  29. #include "Camera.h"
  30. #include "CMigPTZ.h"
  31. #include "CMicPTZ.h"
  32. #include "CPG3AD.h"
  33. #include "CTKS576.h"
  34. #include "CVicon.h"
  35. #include "CPelco.h"
  36. #include "CFlir.h"
  37. #include "CHebron.h"
  38. /*!
  39. Flag to disable error repporting
  40. default: \b false
  41. */
  42. extern bool g_bShowErrors;
  43. /*!
  44. Flag to disable fog error repporting
  45. default: \b false
  46. */
  47. extern bool g_bHideFogError;
  48. /*!
  49. Flag to delay error repporting
  50. Skeeps error for first 3 times of arival
  51. default: \b true
  52. */
  53. extern bool g_bDelayErrors;
  54. /*!
  55. Flag to enable working
  56. default: \b false
  57. */
  58. //extern bool m_pBoard->workingEnabled();
  59. /*!
  60. Gets value of BIOS timer counter (1/18 of second)
  61. */
  62. //static DWORD far* g_Timer = (DWORD far*)0x46CL;
  63. //#ifdef INCLUDE_WINDOWS_DEFINITIONS
  64. // #define TIMER() *g_Timer
  65. //#else
  66. // #define TIMER() (GetTickCount() * 10 / 182)
  67. //#endif
  68. //#define TIMER() ( uclock() * 10 / 182 )
  69. /*!
  70. Buffer for Software Version Text Generation
  71. */
  72. CHAR CKernel::s_pSoftwareVersion[MAX_PATH] = "";
  73. /*!
  74. Software Version
  75. */
  76. int16_t CKernel::s_nSoftwareVersion = 0;
  77. // Hidding parameters up to 5 bytes (11 Nibbles)
  78. void CKernel::Reset( bool bFullReset ){
  79. #ifdef COMPILE_AS_GETFILE
  80. return;
  81. #endif
  82. struct ffblk bb;
  83. if( findfirst( "restart", &bb , 0 ) != -1 ) return;
  84. m_Detector[0].Reset( bFullReset );
  85. #if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
  86. m_Detector[1].Reset( bFullReset );
  87. #endif
  88. #if defined( LGS_MIRROR ) && !defined( LGS_MND )
  89. m_Detector[2].Reset( bFullReset );
  90. m_Detector[3].Reset( bFullReset );
  91. #endif
  92. m_GetFile.Reset();
  93. //if (g_UI_Debug){
  94. // if(bFullReset){
  95. // printf("\nSW reset issued [full reset]\n");
  96. // } else {
  97. // printf("\nSW reset issued [soft reset]\n");
  98. // };
  99. //};
  100. #ifdef DEBUG_GRAPH_SCREEN
  101. g_Screen.Clear();
  102. #endif
  103. // reset error timings
  104. memset( m_dwTimeErrorOverflowSST, 0, sizeof(m_dwTimeErrorOverflowSST)*4 );
  105. memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow)*4 );
  106. memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun)*4 );
  107. m_dwTimeErrorDelay_EA = 0UL;
  108. m_dwTimeErrorDelay_IQ = 0UL;
  109. m_dwTimePower = 0UL;
  110. // reset board
  111. if( bFullReset ){
  112. #ifdef _NO_RESTART_
  113. m_pBoard->Reset();
  114. #else
  115. FILE *fd;
  116. fd = fopen( "restart", "w+" );
  117. fprintf( fd, "\n" );
  118. fclose( fd );
  119. m_pBoard->EndService();
  120. m_bRun = false;
  121. #endif
  122. } else {
  123. m_pBoard->Reset();
  124. };
  125. m_Relay.Reset();
  126. // restart Zero Shift Checker
  127. m_bWaitFirstZero = true;
  128. m_nBeforeZeroCounter = 0;
  129. // Reset AutoReset
  130. m_AutoReset.Reset();
  131. m_nInitErrorSkipCounter = 20;
  132. }
  133. //SchedulerItem *ScheduleCC;
  134. void CKernel::OnISR(){
  135. #ifndef COMM_WITHOUT_INTERRUPTS
  136. stopTimerCC();
  137. unsigned char cFlag;
  138. cFlag = 0;
  139. if ( m_pComm485 != NULL ){
  140. if ( m_pComm485->m_bFollowControlTimer ){
  141. if ( !m_pComm485->ValidateRTS() ){
  142. cFlag++; //resetTimerCC();
  143. };// else {
  144. // setTimerCC( 0xffffffUL );
  145. //};
  146. };
  147. };
  148. #ifndef NO_EMBED_CAMERA
  149. if ( m_pCameraComm != NULL ){
  150. if ( m_pCameraComm->m_bFollowControlTimer ){
  151. if( !m_pCameraComm->ValidateRTS() ){
  152. cFlag++;//resetTimerCC();
  153. };// else {
  154. // setTimerCC( 0xffffffUL );
  155. //};
  156. };
  157. };
  158. #endif
  159. switch( cFlag ){
  160. case 0:{
  161. setTimerCC( 0xffffffUL );
  162. break;
  163. };
  164. case 1:
  165. case 2:{
  166. resetTimerCC();
  167. break;
  168. };
  169. };
  170. #endif
  171. }
  172. bool CKernel::Run(){
  173. struct ffblk bb;
  174. uint8_t *pBuffer;
  175. int16_t nCount;
  176. uint8_t nCameraAccessCounter = 0;
  177. uint8_t nMode = LGS::MODE_DETECTOR;
  178. bool bRestart = false;
  179. DWORD nBoardIrq = 0;
  180. DWORD nBoardTimer = TIMER();
  181. bool bBoardNoIrq = false;
  182. #ifndef COMPILE_AS_GETFILE
  183. bool bFastTimerValid = false;
  184. #endif
  185. #ifdef DEBUG_TARGET_SIMULATOR
  186. bFireSimulatedTarget = false;
  187. nSimulatedTargetID = 0;
  188. #endif
  189. bool bSetHzDataInProgress = false;
  190. bool bSetCalibrationTableInProgress = false;
  191. bool bPower, bZero, bSun[2];
  192. uint16_t nRange[2];
  193. bool SSTMode = false;
  194. m_nBeforeZeroCounter = 0;
  195. delay(1000);
  196. #ifdef COMPILE_AS_GETFILE
  197. DWORD dwStartTime = TIME_TO_MSEC( TIMER() );
  198. bool bGetFileRun = false;
  199. // send human readable information
  200. {
  201. CHAR pText[MAX_PATH];
  202. int16_t nText;
  203. ARESET_SETTINGS AutoReset;
  204. BOARD_SETTINGS BoardSettings;
  205. m_pBoard->getSettings( &BoardSettings );
  206. m_AutoReset.getSettings( &AutoReset );
  207. char *tTtTtT;
  208. switch( m_pBoard->getBoardType() ) {
  209. case BT_COREMODULE_4DXE: tTtTtT = _T("PC104_4DXE"); break;
  210. case BT_TRI_M: tTtTtT = _T("TRITRACK_M"); break;
  211. case BT_VORTEX_SX: tTtTtT = _T("VORTEX86SX"); break;
  212. case BT_VORTEX_DX: tTtTtT = _T("VORTEX86MX"); break;
  213. case BT_VORTEX_MX: tTtTtT = _T("VORTEX86DX"); break;
  214. default: tTtTtT = _T("UNKNOWN");
  215. };
  216. nText = sprintf( pText, "BOARD TYPE <%s>\r\n", tTtTtT );
  217. #ifdef DEBUG
  218. printf(pText);
  219. #endif
  220. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  221. nText = sprintf( pText, "SOFTWARE VERSION <%s>\r\n", s_pSoftwareVersion );
  222. #ifdef DEBUG
  223. printf(pText);
  224. #endif
  225. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  226. nText = sprintf( pText, "ADDRESS <%d>\r\n", m_nAddress );
  227. #ifdef DEBUG
  228. printf(pText);
  229. #endif
  230. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  231. nText = sprintf( pText, "SERIAL NUMBER <%s>\r\n", m_pSerialNumber );
  232. #ifdef DEBUG
  233. printf(pText);
  234. #endif
  235. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  236. nText = sprintf( pText, "AUTORESET_ENABLE <%d>\r\n", AutoReset.bEnabled );
  237. #ifdef DEBUG
  238. printf(pText);
  239. #endif
  240. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  241. nText = sprintf( pText, "AUTORESET_INTERLEAVE <%ld>\r\n", AutoReset.dwInterleave );
  242. #ifdef DEBUG
  243. printf(pText);
  244. #endif
  245. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  246. nText = sprintf( pText, "AUTORESET_TIMEOUT <%ld>\r\n", AutoReset.dwTimeout );
  247. #ifdef DEBUG
  248. printf(pText);
  249. #endif
  250. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  251. nText = sprintf( pText, "BOARD_TEMPERATURE <%d>\r\n", (int16_t)(CHAR)BoardSettings.nTemperature );
  252. #ifdef DEBUG
  253. printf(pText);
  254. #endif
  255. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  256. nText = sprintf( pText, "BOARD_ZEROSHIFT <%d>\r\n", BoardSettings.nZeroShift );
  257. #ifdef DEBUG
  258. printf(pText);
  259. #endif
  260. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  261. #ifdef LGS_PLS_1
  262. nText = sprintf( pText, "BOARD_SPEED <%d>\r\n", BoardSettings.nMotorSpeed );
  263. #ifdef DEBUG
  264. printf(pText);
  265. #endif
  266. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  267. #endif
  268. #ifdef LGS_MIRROR
  269. nText = sprintf( pText, "SWITCHER_TABLE <%d,%d,%d>\r\n", SwitcherSettings.pTable[0], SwitcherSettings.pTable[1], SwitcherSettings.pTable[2] );
  270. #ifdef DEBUG
  271. printf(pText);
  272. #endif
  273. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  274. #endif
  275. }
  276. #else // No Get File
  277. m_pBoard->Reset();// ??
  278. #endif
  279. m_pBoard->BeginService();
  280. // update settings
  281. //AUTO_RESET AutoReset;
  282. //BOARD_SETTINGS BoardSettings;
  283. //SWITCHER_SETTINGS SwitcherSettings;
  284. //LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings, m_pComm485, m_pCameraComm );
  285. //SaveUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings, m_pComm485, m_pCameraComm );
  286. m_nInitErrorSkipCounter = 20;
  287. m_bWaitFirstZero = true;
  288. g_dwStartupTime = ( DWORD ) time( NULL );
  289. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  290. if( g_bBoardReceiverMode ) DoSendBoardData( 0 );
  291. #endif
  292. nBoardTimer = TIME_TO_MSEC( TIMER() );
  293. while( m_bRun ){
  294. unsigned long cMilliseconds = TIME_TO_MSEC( TIMER() );
  295. //m_dwGlobalCycles++;
  296. #ifndef INCLUDE_WINDOWS_DEFINITIONS
  297. Sleep(0);
  298. #endif
  299. #ifdef WATCHDOG_ENABLED
  300. // update watchdog timer
  301. if( g_bWatchDogEnable ) m_WatchDog.Update( cMilliseconds );
  302. #endif
  303. #ifdef COMPILE_AS_GETFILE
  304. if( !bGetFileRun ){
  305. if( ( cMilliseconds - dwStartTime ) > LGS_GETFILE_WAIT_TIME ) m_bRun = false;
  306. } else {
  307. dwStartTime = cMilliseconds;
  308. };
  309. #else // !COMPILE_AS_GETFILE
  310. // clear zero flag
  311. bool bInvalidateCamera = false;
  312. // check fast timer
  313. static DWORD dwSlowTime = 0;
  314. if( !bFastTimerValid ){
  315. if( cMilliseconds != dwSlowTime ){
  316. dwSlowTime = cMilliseconds << 1; // was 3
  317. bInvalidateCamera = true;
  318. };
  319. } else bInvalidateCamera = true;
  320. #endif
  321. // perform work depend on work mode
  322. switch( nMode ){
  323. case LGS::MODE_BORDER:
  324. case LGS::MODE_DETECTOR:
  325. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  326. if( m_nBoardNoRespoceCount < 1 ){
  327. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  328. printf("No Responce From Board!!\n");
  329. #endif
  330. m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
  331. // Restart Software
  332. #ifdef RESTART_PC_BY_WATCHDOG
  333. outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
  334. #ifdef WATCHDOG_ENABLED
  335. CWatchDog WatchDog;
  336. WatchDog.Create();
  337. while(1);
  338. #else
  339. delay( 3000 );
  340. //m_bRun = false;
  341. Reset( true );
  342. continue;
  343. #endif
  344. #else
  345. //m_bRun = false;
  346. Reset( true );
  347. continue;
  348. #endif
  349. };
  350. #endif
  351. //#ifndef COMPILE_AS_GETFILE
  352. #ifdef COMPILE_AS_GETFILE______
  353. // check Serial Number
  354. if( !m_pBoard->workingEnabled() ){
  355. // Try ReInit Board
  356. //if( !m_pBoard->Create( NULL ) ){
  357. // outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
  358. //m_bRun = false;
  359. m_pBoard->Reset();
  360. Reset( true );
  361. //};
  362. #ifdef LGS_MIRROR
  363. m_Detector[ 0 ].Reset( true );
  364. #ifndef LGS_MND
  365. m_Detector[ 1 ].Reset( true );
  366. m_Detector[ 2 ].Reset( true );
  367. m_Detector[ 3 ].Reset( true );
  368. #endif
  369. m_Tracker[ 0 ].Reset();
  370. #else
  371. #ifdef LGS_PLS_1
  372. m_Detector[ 0 ].Reset( true );
  373. m_Tracker[ 0 ].Reset();
  374. #else
  375. m_Detector[ 0 ].Reset( true );
  376. m_Detector[ 1 ].Reset( true );
  377. m_Tracker[ 0 ].Reset();
  378. m_Tracker[ 1 ].Reset();
  379. #endif
  380. #endif
  381. m_bWaitFirstZero = true;
  382. m_nBeforeZeroCounter = 0;
  383. bBoardNoIrq = true;
  384. // fast timer is not valid
  385. bFastTimerValid = false;
  386. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  387. if( m_nBoardNoRespoceCount ){
  388. m_nBoardNoRespoceCount--;
  389. };
  390. #else
  391. Reset( true );
  392. #endif
  393. };
  394. #endif // GETFILE
  395. // check IRQ
  396. if( ( cMilliseconds - nBoardTimer ) > NO_IRQ_DETECTION_TIME ){
  397. if( !nBoardIrq ){
  398. #ifndef COMPILE_AS_GETFILE
  399. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  400. printf( "NO IRQ RESET\n" );
  401. #endif
  402. // New - Reboot
  403. //m_bRun = false;
  404. //continue;
  405. // reset board
  406. // fast timer is not valid
  407. bFastTimerValid = false;
  408. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  409. if( m_nBoardNoRespoceCount ) m_nBoardNoRespoceCount--;
  410. #else
  411. Reset( true );
  412. #endif
  413. #endif //GetFILE
  414. };
  415. nBoardTimer = cMilliseconds;
  416. nBoardIrq = 0;
  417. }
  418. if( m_pBoard->workingEnabled() ) {
  419. #ifdef COMPILE_AS_GETFILE
  420. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  421. m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
  422. #endif
  423. nBoardTimer = cMilliseconds;
  424. nBoardIrq++;
  425. #else
  426. // check board
  427. uint8_t RetVal;
  428. while ( (( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ) ){
  429. #ifdef WATCHDOG_ENABLED
  430. if( g_bWatchDogEnable ){ // update watchdog timer
  431. m_WatchDog.Update( cMilliseconds );
  432. };
  433. #endif
  434. if( RetVal == 2 ){
  435. #ifdef ALS_300__
  436. if( m_nBoardNoRespoceCount ){
  437. m_nBoardNoRespoceCount--;
  438. m_pBoard->AsyncReset();
  439. Reset( false );
  440. };
  441. #else
  442. Reset( true );
  443. #endif
  444. continue;
  445. };
  446. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  447. m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
  448. #endif
  449. nBoardTimer = cMilliseconds;
  450. nBoardIrq++;
  451. #ifndef RANGE_16BIT
  452. // perform linearization
  453. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  454. #ifdef LGS_MIRROR // Doublefication of LGS data for LFS
  455. #ifndef LGS_MND
  456. nRange[1] = nRange[0];
  457. //nRange[1] = m_Calibrator[0].Calibrate( nRange[0] );
  458. #endif
  459. #else
  460. #ifndef LGS_PLS_1
  461. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  462. #endif
  463. #endif
  464. #endif //16 bit
  465. // update voltage state
  466. m_Voltage.Invalidate( bPower );
  467. #ifndef COMPILE_AS_GETFILE
  468. // fast timer is valid
  469. bFastTimerValid = true;
  470. #endif
  471. #ifdef DEBUG_BOARD_SET_TEST_BIT
  472. m_pBoard->SetTestBit( true );
  473. #endif
  474. #ifdef LGS_MIRROR
  475. if( m_bWaitFirstZero && bZero ){
  476. m_Detector[ 0 ].ResetAngles();
  477. #ifndef LGS_MND
  478. m_Detector[ 1 ].ResetAngles();
  479. m_Detector[ 2 ].ResetAngles();
  480. m_Detector[ 3 ].ResetAngles();
  481. #endif
  482. m_Tracker[ 0 ].Reset();
  483. //m_nDetector = m_nAngle = 0;
  484. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  485. printf("Before Zero: %d ang. Zero Shift: %d ang.\n", m_nBeforeZeroCounter, m_pBoard->getZeroShift() );
  486. #endif
  487. //if( findfirst( "restart", &bb , 0 ) != -1 )
  488. unlink( "restart" );
  489. m_bWaitFirstZero = false;
  490. };
  491. if( !m_bWaitFirstZero ){ // Accepting Data
  492. if( bZero ){ // If Zero Angle
  493. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  494. printf( "Real Zero: %d D:%d\n", m_nAngle, m_nDetector );
  495. #endif
  496. m_nDetector = m_nAngle = 0;
  497. m_dwGlobalCycles = 0UL;
  498. #ifndef LGS_MND
  499. if( m_Detector[ 3 ].IsSSTPassed() ){
  500. SSTMode = true;
  501. } else {
  502. SSTMode = false;
  503. };
  504. #else
  505. SSTMode = false;
  506. #endif
  507. } else { // If Any Other Angle
  508. #ifndef LGS_MND
  509. #ifdef LGS_REDUCED_PRF
  510. m_nAngle += LGS_PRF_REDUCE_RATIO;
  511. m_dwGlobalCycles += LGS_PRF_REDUCE_RATIO;
  512. if( m_nAngle > ( LGS_MAX_DETECTOR_ANGLES - LGS_PRF_REDUCE_RATIO ) ){ // Change Detector (Mirror)
  513. #else
  514. m_nAngle ++;
  515. m_dwGlobalCycles ++;
  516. if( m_nAngle > ( LGS_MAX_DETECTOR_ANGLES - 1 ) ){ // Change Detector (Mirror)
  517. #endif
  518. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  519. printf( "Virtual Zero: %d D:%d ", m_nAngle, m_nDetector );
  520. #endif
  521. if( m_Detector[ m_nDetector ].IsSSTPassed() ) SSTMode = true;
  522. m_nDetector ++;
  523. if ( m_nDetector > 3 ) m_nDetector = 0;
  524. m_nAngle = 0;
  525. bZero = true;
  526. };
  527. #else
  528. #ifdef LGS_REDUCED_PRF
  529. m_nAngle += LGS_PRF_REDUCE_RATIO;
  530. m_dwGlobalCycles += LGS_PRF_REDUCE_RATIO;
  531. #else
  532. m_nAngle ++;
  533. m_dwGlobalCycles ++;
  534. #endif
  535. #endif
  536. };
  537. } else { // Board Zero Shift Counter
  538. #ifdef LGS_REDUCED_PRF
  539. m_nBeforeZeroCounter += LGS_PRF_REDUCE_RATIO;
  540. #else
  541. m_nBeforeZeroCounter++;
  542. #endif
  543. };
  544. #ifdef DEBUG_NO_TARGET_DELAYING
  545. SSTMode = false;
  546. #endif
  547. if( !m_bWaitFirstZero ){
  548. #ifdef LGS_REDUCED_PRF
  549. m_Tracker[ 0 ].Invalidate();
  550. for( int i = 0; i< LGS_PRF_REDUCE_RATIO; i++ ) {
  551. m_Detector[ m_nDetector ].Invalidate( bZero, bSun[0], nRange[0], true, SSTMode );
  552. if( bZero ) {
  553. bZero = false;
  554. };
  555. };
  556. #else
  557. m_Tracker[ 0 ].Invalidate();
  558. m_Detector[ m_nDetector ].Invalidate( bZero, bSun[0], nRange[0], true, SSTMode );
  559. #endif
  560. };
  561. #else // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  562. #if defined( LGS_PLS_1 ) // PLS
  563. if( m_bWaitFirstZero && bZero ) {
  564. m_bWaitFirstZero = false;
  565. m_Detector[ 0 ].ResetAngles();
  566. m_Tracker[ 0 ].Reset();
  567. //if( findfirst( "restart", &bb , 0 ) != -1 )
  568. unlink( "restart" );
  569. };
  570. if( !m_bWaitFirstZero ){
  571. m_Tracker[0].Invalidate();
  572. #ifdef LGS_REDUCED_PRF
  573. for( int i = 0; i< LGS_PRF_REDUCE_RATIO; i++ ){
  574. m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], true );
  575. bZero = 0;
  576. };
  577. #else
  578. m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], true );
  579. #endif
  580. } else { // Board Zero Shift Counter
  581. #ifdef LGS_REDUCED_PRF
  582. m_nBeforeZeroCounter += LGS_PRF_REDUCE_RATIO;
  583. #else
  584. m_nBeforeZeroCounter++;
  585. #endif
  586. };
  587. #else // ALS
  588. if( m_bWaitFirstZero && bZero ) {
  589. /*if( ( m_nBeforeZeroCounter >0 ) && ( m_nBeforeZeroCounter != m_pBoard->getZeroShift() ) ){ //Check if Zero Shift is Valid
  590. m_pBoard->AsyncReset();
  591. m_nBeforeZeroCounter = 0;
  592. } else {
  593. m_bWaitFirstZero = false;
  594. };*/
  595. #ifdef DEBUG
  596. printf("First Zero Reached!\n");
  597. #endif
  598. m_bWaitFirstZero = false;
  599. m_Detector[ 0 ].ResetAngles();
  600. m_Tracker[ 0 ].Reset();
  601. m_Detector[ 1 ].ResetAngles();
  602. m_Tracker[ 1 ].Reset();
  603. #ifdef ALS_300
  604. m_nSkeepCounter=0;
  605. #endif
  606. if( findfirst( "restart", &bb , 0 ) != -1 ) unlink( "restart" );
  607. };
  608. if( !m_bWaitFirstZero ){
  609. m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], m_Detector[1].IsAllowFlip(), false );
  610. } else { // Board Zero Shift Counter
  611. m_nBeforeZeroCounter++;
  612. };
  613. #ifdef ALS_300
  614. //if( m_nSkeepCounter == 0 )
  615. #endif
  616. m_Tracker[0].Invalidate();
  617. if( !m_bWaitFirstZero ){
  618. m_Detector[1].Invalidate( bZero, bSun[1], nRange[1], m_Detector[0].IsAllowFlip(), false );
  619. };
  620. #ifdef ALS_300
  621. //if( m_nSkeepCounter == 0 )
  622. #endif
  623. m_Tracker[1].Invalidate();
  624. #ifdef ALS_300
  625. m_nSkeepCounter++;
  626. if( m_nSkeepCounter == LGS_BOARDSAMPLE_RATIO ) m_nSkeepCounter = 0;
  627. #endif
  628. #endif // ALS-PLS
  629. #endif // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  630. #ifdef DEBUG_BOARD_SET_TEST_BIT
  631. m_pBoard->SetTestBit( false );
  632. #endif
  633. #ifndef COMPILE_AS_GETFILE
  634. bInvalidateCamera = true;
  635. #endif
  636. if( m_pBoard->getBoardWM()!= WM_DMA_WORK ) break;// From While
  637. };// Get Data While
  638. #endif //!COMPILE_AS_GETFILE
  639. };// m_pBoard->workingEnabled() == true
  640. #ifndef COMPILE_AS_GETFILE
  641. nCameraAccessCounter++;
  642. if( bInvalidateCamera && ( ( nCameraAccessCounter % 123 ) == 6 ) ){
  643. nCameraAccessCounter = 0;
  644. #ifdef COMM_WITHOUT_INTERRUPTS
  645. m_pComm485->Validate();
  646. #ifndef NO_EMBED_CAMERA
  647. m_pCameraComm->Validate();
  648. #endif
  649. #endif
  650. #ifdef DEBUG_BOARD_SET_TEST_BIT_2
  651. m_pBoard->SetTestBit2( true );
  652. #endif
  653. #ifndef NO_EMBED_CAMERA
  654. // process camera commands
  655. m_pCamera->Invalidate( dwSlowTime, m_pBoard->GetTimer(), bFastTimerValid );
  656. #endif
  657. #ifdef DEBUG_BOARD_SET_TEST_BIT_2
  658. m_pBoard->SetTestBit2( false );
  659. #endif
  660. bInvalidateCamera = false;
  661. };
  662. #endif
  663. break;
  664. default:
  665. case LGS::MODE_FILESYSTEM:
  666. case LGS::MODE_GETFILE:
  667. #ifndef COMPILE_AS_GETFILE
  668. if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ){
  669. #ifndef RANGE_16BIT
  670. // perform linearization
  671. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  672. #if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
  673. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  674. #endif
  675. #endif // 16 bit
  676. // update voltage state
  677. m_Voltage.Invalidate( bPower );
  678. #ifndef EMBEDDED_CAMERA_DISABLE
  679. bInvalidateCamera = true;
  680. #endif
  681. nBoardIrq++;
  682. #ifndef COMPILE_AS_GETFILE
  683. // fast timer is valid
  684. bFastTimerValid = true;
  685. #endif
  686. }
  687. #endif // !COMPILE_AS_GETFILE
  688. break;
  689. }
  690. // try to work in windows - disable Board->GetTimer();
  691. #ifndef INCLUDE_WINDOWS_DEFINITIONS
  692. bFastTimerValid = false;
  693. #endif
  694. #ifndef EMBEDDED_CAMERA_DISABLE
  695. #ifndef COMPILE_AS_GETFILE
  696. // process camera commands
  697. if( bInvalidateCamera ){
  698. #ifdef COMM_WITHOUT_INTERRUPTS
  699. m_pComm485->Invalidate();
  700. m_pCameraComm->Invalidate();
  701. #endif
  702. #ifdef DEBUG_BOARD_SET_TEST_BIT_2
  703. m_pBoard->SetTestBit2( true );
  704. #endif
  705. #ifndef NO_EMBED_CAMERA
  706. // process camera commands
  707. m_pCamera->Invalidate( dwSlowTime, m_pBoard->GetTimer(), bFastTimerValid );
  708. #endif
  709. #ifdef DEBUG_BOARD_SET_TEST_BIT_2
  710. m_pBoard->SetTestBit2( false );
  711. #endif
  712. bInvalidateCamera = false;
  713. };
  714. // process relay commands
  715. if ( m_pBoard->workingEnabled() ) m_Relay.Invalidate( m_pBoard->GetTimer(), cMilliseconds );
  716. #else
  717. m_Relay.Invalidate( m_pBoard->GetTimer(), cMilliseconds );
  718. #endif
  719. #endif
  720. //process communication commands
  721. #ifdef COMM_WITHOUT_INTERRUPTS
  722. m_pComm485->Validate();
  723. #ifndef EMBEDDED_CAMERA_DISABLE
  724. #ifndef NO_EMBED_CAMERA
  725. m_pCameraComm->Validate();
  726. #endif
  727. #endif
  728. #endif
  729. // auto reset
  730. if( m_AutoReset.IsNeedToReset() ){
  731. #ifdef INFINITE_SAF_STUDY
  732. m_Detector[0].StartLearningCycle();
  733. #else
  734. nMode = LGS::MODE_DETECTOR;
  735. //Reset( false );
  736. // reset IRQ checking
  737. nBoardIrq = 0;
  738. nBoardTimer = cMilliseconds;
  739. m_nBeforeZeroCounter = 0;
  740. bRestart = true;
  741. //m_bRun = false;
  742. Reset( true );
  743. #endif
  744. };
  745. // check for new commands from host
  746. if( m_Protocol.Read( &pBuffer, &nCount, 0, false ) ){
  747. // check address
  748. uint8_t bAddress = 0;
  749. if( nCount && ( (m_nAddress == *pBuffer) || (LGS_EXCLUSIVE_ADDRESS == *pBuffer) ) )
  750. {
  751. // store address
  752. bAddress = *pBuffer;
  753. // update pointers
  754. nCount--;
  755. pBuffer++;
  756. // check remainig count
  757. if( nCount )
  758. {
  759. uint8_t pSendBuffer[1024];
  760. PBYTE pSendBufferPtr = pSendBuffer;
  761. int16_t nSendCount = 2;
  762. // set address
  763. *pSendBufferPtr++ = bAddress;
  764. uint8_t bHostCommand = *pBuffer++;
  765. // Restart if set hz data was not finished correctly
  766. if( ( bSetHzDataInProgress && bHostCommand != LGS::CMD_SET_HZ_DATA ) ||
  767. ( bSetCalibrationTableInProgress && bHostCommand != LGS::CMD_SET_CALIBRATION_TABLE ) )
  768. {
  769. bRestart = true;
  770. //m_bRun = false;
  771. Reset( true );
  772. }
  773. // get command from buffer
  774. switch( bHostCommand )
  775. {
  776. case LGS::CMD_CAMERA:
  777. // build CMD_MODE command
  778. *pSendBufferPtr++ = LGS::CMD_CAMERA;
  779. // process command
  780. #if !defined(EMBEDDED_CAMERA_DISABLE) && !defined(NO_EMBED_CAMERA)
  781. m_pCamera->OnProtocolLgsCameraCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
  782. #else
  783. LGS::CAMERA_DATA OutData;
  784. // lgs has no camera busy
  785. OutData.nCommand = LGS::CMD_CAMERA_ERROR;
  786. OutData.error.errID = LGS::CAMERA_ERROR_NO_CAMERA;
  787. nSendCount += LGS::BuildEvtCamera( pSendBufferPtr, &OutData );
  788. #endif
  789. // write command
  790. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  791. break;
  792. case LGS::CMD_RELAY:
  793. // build CMD_MODE command
  794. *pSendBufferPtr++ = LGS::CMD_RELAY;
  795. // process command
  796. m_Relay.OnProtocolLgsRelayCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
  797. // write command
  798. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  799. break;
  800. case LGS::CMD_MODE:
  801. {
  802. // get command parameters
  803. bool bSetMode = false;
  804. uint8_t nNewMode = nMode;
  805. LGS::GetMode( pBuffer, &bSetMode, &nNewMode );
  806. // build CMD_MODE command
  807. *pSendBufferPtr++ = LGS::CMD_MODE;
  808. nSendCount += LGS::BuildMode( pSendBufferPtr, false, nMode );
  809. // write command
  810. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  811. // if needs to switch mode
  812. if( bSetMode && nMode != nNewMode )
  813. {
  814. switch( nNewMode )
  815. {
  816. case LGS::MODE_GETFILE:
  817. #ifdef COMPILE_AS_GETFILE
  818. bGetFileRun = true;
  819. #endif
  820. break;
  821. case LGS::MODE_BORDER:
  822. case LGS::MODE_DETECTOR:
  823. case LGS::MODE_FILESYSTEM:
  824. case LGS::MODE_FILESYSTEM_EXT:
  825. m_Detector[0].BorderEnable( nNewMode == LGS::MODE_BORDER );
  826. #if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
  827. m_Detector[1].BorderEnable( nNewMode == LGS::MODE_BORDER );
  828. #endif
  829. #ifdef LGS_MIRROR
  830. #ifndef LGS_MND
  831. m_Detector[2].BorderEnable( nNewMode == LGS::MODE_BORDER );
  832. m_Detector[3].BorderEnable( nNewMode == LGS::MODE_BORDER );
  833. #endif
  834. #endif
  835. #ifdef COMPILE_AS_GETFILE
  836. bGetFileRun = false;
  837. dwStartTime = cMilliseconds;
  838. #endif
  839. break;
  840. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  841. case LGS::MODE_SENDBOARDDATA1:
  842. DoSendBoardData( 0 );
  843. Reset( true );
  844. //m_bRun = false;
  845. continue;
  846. break;
  847. case LGS::MODE_SENDBOARDDATA2:
  848. DoSendBoardData( 1 );
  849. Reset( true );
  850. //m_bRun = false;
  851. continue;
  852. break;
  853. case LGS::MODE_SENDBOARDDATA3:
  854. DoSendBoardData( 2 );
  855. Reset( true );
  856. //m_bRun = false;
  857. continue;
  858. break;
  859. case LGS::MODE_SENDBOARDDATA4:
  860. DoSendBoardData( 3 );
  861. Reset( true );
  862. //m_bRun = false;
  863. continue;
  864. break;
  865. #endif
  866. }
  867. // reset after switching mode
  868. if( nMode != LGS::MODE_BORDER && nMode != LGS::MODE_DETECTOR ) Reset( false );
  869. // store new mode
  870. nMode = nNewMode;
  871. // reset IRQ checking
  872. nBoardIrq = 0;
  873. nBoardTimer = cMilliseconds;
  874. }
  875. }
  876. break;
  877. case LGS::CMD_BORDER:
  878. {
  879. // get command parameters
  880. uint8_t bError;
  881. uint16_t nAngle, nRange0, nRange1;
  882. LGS::GetBorder( pBuffer, &bError, &nAngle, &nRange0, &nRange1 );
  883. // build CMD_BORDER command
  884. *pSendBufferPtr++ = LGS::CMD_BORDER;
  885. if( nMode != LGS::MODE_BORDER ){
  886. nSendCount += LGS::BuildBorder( pSendBufferPtr, LGS::BD_ERRORMODE, 0, 0, 0 );
  887. }else{
  888. #if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
  889. uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ||
  890. (!m_Detector[1].GetBorderRange( nAngle, &nRange1 )) ) ? LGS::BD_NOTREADY : 0;
  891. #else
  892. #ifdef INFINITE_SAF_STUDY
  893. uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0, true )) ||
  894. (!m_Detector[0].GetBorderRange( nAngle, &nRange1, false )) ) ? LGS::BD_NOTREADY : 0;
  895. #else
  896. uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ) ? LGS::BD_NOTREADY : 0;
  897. #endif
  898. #endif
  899. if( bError ){
  900. nSendCount += LGS::BuildBorder( pSendBufferPtr, bError, 0, 0, 0 );
  901. }else
  902. #ifdef RANGE_16BIT
  903. //nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, (uint16_t)ceil(((float)nRange0)/ 11.12f), (uint16_t)ceil(((float)nRange1)/ 11.12f) );
  904. {
  905. uint16_t nR0,nR1;
  906. //nRange0 = nAngle;
  907. //nR0 = (uint16_t)(((float)nRange0)/ 11.12 + 1 );
  908. nR0 = (uint16_t)(( 2048L * nRange0 )/ 22237 + 1 );
  909. nR1 = (uint16_t)(( 2048L * nRange1 )/ 22237 + 1 );
  910. nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nR0, nR1 );
  911. //nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0>>3, nRange1>>3 );
  912. };
  913. #else
  914. nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0 >> 1, nRange1 >> 1 );
  915. #endif
  916. }
  917. // write command
  918. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  919. }
  920. break;
  921. case LGS::CMD_STATE:
  922. {
  923. // build CMD_STATE command
  924. *pSendBufferPtr++ = LGS::CMD_STATE;
  925. if( nMode != LGS::MODE_DETECTOR ){
  926. nSendCount += LGS::BuildError( pSendBufferPtr, 0, LGS::ER_MODE, 0 );
  927. }else{
  928. #ifdef LGS_MIRROR
  929. #ifdef LGS_MND
  930. {
  931. int i = 0;
  932. #else
  933. for( int i = 0; i < 4; i++ ){
  934. #endif
  935. #else
  936. #ifndef LGS_PLS_1
  937. for( int i = 0; i < 2; i++ ){
  938. #else
  939. {
  940. int i = 0;
  941. #endif
  942. #endif
  943. CDetector *pDetector = &m_Detector[i];
  944. CTracker *pTracker = &m_Tracker[i];
  945. uint8_t bDevice = ( i % 2 ) ? LGS::ID_DEVICE1 : LGS::ID_DEVICE0;
  946. // assume that no errors
  947. uint8_t bErrorMask = LGS::ER_NONE;
  948. int16_t nErrorAngle = 0;
  949. // check for tracker overflow
  950. if( ( m_dwTimeErrorOverflow[i] < cMilliseconds ) && pTracker->GetLastErrorOverflow() )
  951. {
  952. m_dwTimeErrorOverflow[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
  953. bErrorMask |= LGS::ER_OVERFLOW;
  954. }
  955. // check for tracker scan to scan overflow
  956. if( ( m_dwTimeErrorOverflowSST[i] < cMilliseconds ) && pTracker->GetLastErrorOverflowSST() )
  957. {
  958. m_dwTimeErrorOverflowSST[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
  959. bErrorMask |= LGS::ER_SSTOVERFLOW;
  960. }
  961. // check for detector sun errors
  962. if( ( m_dwTimeErrorSun[i] < cMilliseconds ) && pDetector->GetLastErrorSun() )
  963. {
  964. m_dwTimeErrorSun[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
  965. bErrorMask |= LGS::ER_SUNBIT;
  966. }
  967. // check for detector angle errors
  968. if( pDetector->GetLastErrorAngle() )
  969. {
  970. nErrorAngle = pDetector->GetLastErrorAngleValue();
  971. if( ( nErrorAngle > 0 && nErrorAngle < LGS_REAL_DETECTOR_ANGLES - 5 ) || g_bDelayErrors == false ){
  972. bErrorMask |= LGS::ER_ANGLE;
  973. nErrorAngle = ( i + 1 ) * 10000 + nErrorAngle;
  974. };
  975. }
  976. // check for kernel error
  977. if( bBoardNoIrq )
  978. {
  979. bErrorMask |= LGS::ER_NOIRQ;
  980. bBoardNoIrq = false;
  981. }
  982. // if error exist
  983. if( bErrorMask ){
  984. nSendCount += LGS::BuildError( pSendBufferPtr, bDevice, bErrorMask, nErrorAngle );
  985. //if( g_UI_Debug ){
  986. // printf("Error Message Issued [%d]\n", bErrorMask );
  987. //};
  988. }
  989. // place target information
  990. CTracker::TARGET target;
  991. while( ( pTracker->GetTarget( &target ) && m_pBoard->workingEnabled()
  992. #ifdef DEBUG_TARGET_SIMULATOR
  993. ) || bFireSimulatedTarget
  994. #else
  995. )
  996. #endif
  997. ){
  998. #ifdef DEBUG_TARGET_SIMULATOR
  999. if( bFireSimulatedTarget ){
  1000. target.bType = LGS::TT_NORMAL;
  1001. target.nRange = 200;
  1002. target.nAngle = ( 3000* nSimulatedTargetID )/360 ;
  1003. target.nWidth = m_dwGlobalCycles;//nSimulatedTargetID;
  1004. bFireSimulatedTarget = false;
  1005. };
  1006. #endif
  1007. #ifdef LGS_MIRROR
  1008. #ifdef LGS_STEPPER
  1009. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1010. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, ( target.nAngle << 1 ) / LGS_PRF_REDUCE_RATIO, target.nRange, target.nWidth );
  1011. #else
  1012. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, ( target.nAngle << 1 ) / LGS_PRF_REDUCE_RATIO, target.nRange );
  1013. #endif
  1014. #else
  1015. #ifdef LGS_MND
  1016. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1017. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 2, target.nRange, target.nWidth << 2 );
  1018. #else
  1019. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 2, target.nRange );
  1020. #endif
  1021. #else
  1022. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1023. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange, target.nWidth );
  1024. #else
  1025. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange );
  1026. #endif
  1027. #endif
  1028. #endif
  1029. #else
  1030. #ifdef LGS_PLS_1
  1031. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1032. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_PRF_REDUCE_RATIO, target.nRange, target.nWidth );
  1033. #else
  1034. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_PRF_REDUCE_RATIO, target.nRange );
  1035. #endif
  1036. #else
  1037. #ifdef ALS_300_Z
  1038. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1039. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_BOARDSAMPLE_RATIO, target.nRange, target.nWidth );
  1040. #else
  1041. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_BOARDSAMPLE_RATIO, target.nRange );
  1042. #endif
  1043. #else
  1044. #ifdef RANGE_16BIT
  1045. uint16_t nR0;
  1046. nR0 = (uint16_t)(( 2048L * target.nRange )/ 22237 + 1 );
  1047. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1048. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, nR0, target.nWidth );
  1049. #else
  1050. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, nR0 );
  1051. #endif
  1052. #else
  1053. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1054. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange, target.nWidth );
  1055. #else
  1056. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange );
  1057. #endif
  1058. #endif
  1059. #endif
  1060. #endif
  1061. #endif
  1062. if( nSendCount >= 20 )
  1063. break;
  1064. }
  1065. if( nSendCount >= 20 )
  1066. break;
  1067. }
  1068. }
  1069. #ifndef EMBEDDED_CAMERA_DISABLE
  1070. #ifndef NO_EMBED_CAMERA
  1071. // add camera tags
  1072. m_pCamera->OnProtocolLgsStateCommand( pSendBufferPtr, nSendCount );
  1073. #endif
  1074. #endif
  1075. // write command
  1076. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1077. }
  1078. break;
  1079. case LGS::CMD_STATE_2:
  1080. // prepare response
  1081. OnCmdState2( pBuffer, nCount, pSendBufferPtr, nSendCount, nMode, bBoardNoIrq );
  1082. // write command
  1083. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1084. break;
  1085. case LGS::CMD_GET_WIDTH_TABLE:
  1086. // prepare response
  1087. OnCmdGetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1088. // write command
  1089. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1090. break;
  1091. case LGS::CMD_SET_WIDTH_TABLE:
  1092. // prepare response
  1093. OnCmdSetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1094. // write command
  1095. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1096. break;
  1097. #ifndef NO_EMBED_CAMERA
  1098. case LGS::CMD_GET_ZOOM_TABLE:
  1099. // prepare response
  1100. OnCmdGetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1101. // write command
  1102. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1103. break;
  1104. case LGS::CMD_SET_ZOOM_TABLE:
  1105. // prepare response
  1106. OnCmdSetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1107. // write command
  1108. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1109. // update camera settings
  1110. m_pCamera->SaveZoomTable();
  1111. // reset after file operation
  1112. //Reset( true );
  1113. // reset IRQ checking
  1114. nBoardIrq = 0;
  1115. nBoardTimer = cMilliseconds;
  1116. break;
  1117. case LGS::CMD_GET_TILT_TABLE:
  1118. // prepare response
  1119. OnCmdGetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1120. // write command
  1121. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1122. break;
  1123. case LGS::CMD_SET_TILT_TABLE:
  1124. // prepare response
  1125. OnCmdSetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1126. // write command
  1127. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1128. // update camera settings
  1129. m_pCamera->SaveTiltTable();
  1130. // reset after file operation
  1131. Reset( true );
  1132. //m_bRun = false;
  1133. // reset IRQ checking
  1134. nBoardIrq = 0;
  1135. nBoardTimer = cMilliseconds;
  1136. break;
  1137. #endif //! NO_EMBED_CAMERA
  1138. case LGS::CMD_GET_LRF_DISABLE:
  1139. // prepare response
  1140. OnCmdGetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1141. // write command
  1142. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1143. break;
  1144. case LGS::CMD_SET_LRF_DISABLE:
  1145. // prepare response
  1146. OnCmdSetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1147. // write command
  1148. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1149. // reset after file operation
  1150. Reset( true );
  1151. //m_bRun = false;
  1152. // reset IRQ checking
  1153. nBoardIrq = 0;
  1154. nBoardTimer = cMilliseconds;
  1155. break;
  1156. case LGS::CMD_GET_HZ_DATA:
  1157. m_pShadow->OnCmdGetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1158. // write command
  1159. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1160. break;
  1161. case LGS::CMD_SET_HZ_DATA:
  1162. {
  1163. bool bPendingSave = m_pShadow->OnCmdSetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1164. // write command
  1165. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1166. // save
  1167. if( bPendingSave )
  1168. {
  1169. // save data
  1170. m_pShadow->Save();
  1171. // reset after file operation
  1172. Reset( true );
  1173. //m_bRun = false;
  1174. // reset IRQ checking
  1175. nBoardIrq = 0;
  1176. nBoardTimer = cMilliseconds;
  1177. #ifdef LGS_MIRROR
  1178. bRestart = true;
  1179. //m_bRun = false;
  1180. Reset( true );
  1181. #endif
  1182. }
  1183. }
  1184. break;
  1185. case LGS::CMD_GET_HZ_ENABLE:
  1186. m_pShadow->OnCmdGetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1187. // write command
  1188. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1189. break;
  1190. case LGS::CMD_SET_HZ_ENABLE:
  1191. {
  1192. bool bPendingSave = m_pShadow->OnCmdSetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1193. // write command
  1194. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1195. // save
  1196. if( bPendingSave )
  1197. {
  1198. // save data
  1199. m_pShadow->Save();
  1200. // reset after file operation
  1201. //Reset( true );
  1202. // reset IRQ checking
  1203. nBoardIrq = 0;
  1204. nBoardTimer = cMilliseconds;
  1205. // set data finished correctly
  1206. bSetHzDataInProgress = false;
  1207. //Restart After Aply Mask
  1208. bRestart = true;
  1209. //m_bRun = false;
  1210. Reset( true );
  1211. //
  1212. }
  1213. else
  1214. bSetHzDataInProgress = true;
  1215. }
  1216. break;
  1217. case LGS::CMD_GET_CALIBRATION_TABLE:
  1218. OnCmdGetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1219. // write command
  1220. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1221. break;
  1222. case LGS::CMD_SET_CALIBRATION_TABLE:
  1223. {
  1224. int16_t nDevice = 0;
  1225. bool bPendingSave = OnCmdSetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount, nDevice );
  1226. // write command
  1227. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1228. #ifndef RANGE_16BIT
  1229. // save
  1230. if( bPendingSave )
  1231. {
  1232. // save data
  1233. switch( nDevice )
  1234. {
  1235. case 0: m_Calibrator[nDevice].Save( "lt0.ini" ); break;
  1236. case 1: m_Calibrator[nDevice].Save( "lt1.ini" ); break;
  1237. }
  1238. // reset after file operation
  1239. Reset( true );
  1240. //m_bRun = false;
  1241. // reset IRQ checking
  1242. nBoardIrq = 0;
  1243. nBoardTimer = cMilliseconds;
  1244. // set data finished correctly
  1245. bSetCalibrationTableInProgress = false;
  1246. }
  1247. else
  1248. bSetCalibrationTableInProgress = true;
  1249. #endif // 16 bit
  1250. }
  1251. break;
  1252. case LGS::CMD_QUIT:
  1253. *pSendBufferPtr++ = LGS::CMD_QUIT;
  1254. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1255. m_bRun = false;
  1256. #ifndef COMPILE_AS_GETFILE
  1257. #ifdef STORE_FIRST_SAF
  1258. if( g_bSAFFileEnable ){
  1259. m_Detector[ 0 ].save_current_SAF();
  1260. };
  1261. #endif
  1262. #endif
  1263. Reset( true );
  1264. break;
  1265. case LGS::CMD_RESTART:
  1266. *pSendBufferPtr++ = LGS::CMD_RESTART;
  1267. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1268. //#ifdef INFINITE_SAF_STUDY
  1269. // m_Detector[0].StartLearningCycle();
  1270. //#else
  1271. //bRestart = true;
  1272. m_bRun = false;
  1273. #ifndef COMPILE_AS_GETFILE
  1274. #ifdef STORE_FIRST_SAF
  1275. if( g_bSAFFileEnable ){
  1276. m_Detector[ 0 ].save_current_SAF();
  1277. };
  1278. #endif
  1279. #endif
  1280. Reset( true );
  1281. //#endif
  1282. break;
  1283. case LGS::CMD_GET_SERIAL_NUMBER:
  1284. // reply command
  1285. *pSendBufferPtr++ = LGS::CMD_GET_SERIAL_NUMBER;
  1286. // reply data
  1287. nSendCount += LGS::BuildSerialNumber( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  1288. // write into port
  1289. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1290. break;
  1291. case LGS::CMD_GET_SOFTWARE_VERSION:
  1292. // reply command
  1293. *pSendBufferPtr++ = LGS::CMD_GET_SOFTWARE_VERSION;
  1294. // reply data
  1295. nSendCount += LGS::BuildSoftwareVersion( pSendBufferPtr, (PBYTE)s_pSoftwareVersion, s_nSoftwareVersion );
  1296. // write into port
  1297. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1298. break;
  1299. case LGS::CMD_GET_VOLTAGE:
  1300. // reply command
  1301. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE;
  1302. // reply data
  1303. nSendCount += LGS::BuildEvtVoltage( pSendBufferPtr, m_Voltage.GetVoltage() );
  1304. // write into port
  1305. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1306. break;
  1307. #ifdef DETECTION_MULTI_PROFILES
  1308. case LGS::CMD_GET_ACTIVE_PROFILE:
  1309. // reply command
  1310. *pSendBufferPtr++ = LGS::CMD_GET_ACTIVE_PROFILE;
  1311. // reply data
  1312. nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
  1313. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1314. break;
  1315. case LGS::CMD_SET_ACTIVE_PROFILE:
  1316. //ToDo ...
  1317. //printf( "Set Active Profile %d\n",(uint8_t)pBuffer[0] );
  1318. if ( setActiveDetectionProfile( pBuffer[0] ) ){
  1319. bRestart = true;
  1320. //m_bRun = false;
  1321. Reset( true );
  1322. };
  1323. *pSendBufferPtr++ = LGS::CMD_SET_ACTIVE_PROFILE;
  1324. //data
  1325. //nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
  1326. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1327. break;
  1328. #endif
  1329. #ifndef EMBEDDED_CAMERA_DISABLE
  1330. #ifndef NO_EMBED_CAMERA
  1331. case LGS::CMD_GET_CAMERA_PARAMETERS:
  1332. {
  1333. // reply command
  1334. *pSendBufferPtr++ = LGS::CMD_GET_CAMERA_PARAMETERS;
  1335. // reply data
  1336. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &m_pCamera->GetParameters() );
  1337. // write into port
  1338. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1339. }
  1340. break;
  1341. case LGS::CMD_SET_CAMERA_PARAMETERS:
  1342. {
  1343. LGS::CAMERA_PARAMETERS cp;
  1344. LGS::GetCameraParameters( pBuffer, &cp );
  1345. // reply command
  1346. *pSendBufferPtr++ = LGS::CMD_SET_CAMERA_PARAMETERS;
  1347. // reply data
  1348. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &cp );
  1349. // write into port
  1350. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1351. // store serial number
  1352. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &cp, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1353. // restart program
  1354. //m_bRun = false;
  1355. Reset( true );
  1356. }
  1357. break;
  1358. #endif
  1359. #endif
  1360. case LGS::CMD_GET_VOLTAGE_PARAMETERS:
  1361. {
  1362. // reply command
  1363. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE_PARAMETERS;
  1364. // reply data
  1365. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &m_Voltage.GetParameters() );
  1366. // write into port
  1367. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1368. }
  1369. break;
  1370. case LGS::CMD_SET_VOLTAGE_PARAMETERS:
  1371. {
  1372. LGS::VOLTAGE_PARAMETERS vp;
  1373. // store voltage parameters
  1374. LGS::GetVoltageParameters( pBuffer, &vp );
  1375. // reply command
  1376. *pSendBufferPtr++ = LGS::CMD_SET_VOLTAGE_PARAMETERS;
  1377. // reply data
  1378. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &vp );
  1379. // write into port
  1380. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1381. // store serial number
  1382. #ifndef NO_EMBED_CAMERA
  1383. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &vp, &m_LRFDisable );
  1384. #else
  1385. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &vp, &m_LRFDisable );
  1386. #endif
  1387. // update voltage prameters
  1388. m_Voltage.SetParameters( &vp );
  1389. // reset after file operation
  1390. Reset( true );
  1391. //m_bRun = false;
  1392. // reset IRQ checking
  1393. nBoardIrq = 0;
  1394. nBoardTimer = cMilliseconds;
  1395. }
  1396. break;
  1397. case LGS::CMD_GET_RELAY_PARAMETERS:
  1398. {
  1399. // reply command
  1400. *pSendBufferPtr++ = LGS::CMD_GET_RELAY_PARAMETERS;
  1401. // reply data
  1402. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &m_Relay.GetParameters() );
  1403. // write into port
  1404. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1405. }
  1406. break;
  1407. case LGS::CMD_SET_RELAY_PARAMETERS:
  1408. {
  1409. LGS::RELAY_PARAMETERS rp;
  1410. LGS::GetRelayParameters( pBuffer, &rp );
  1411. // reply command
  1412. *pSendBufferPtr++ = LGS::CMD_SET_RELAY_PARAMETERS;
  1413. // reply data
  1414. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &rp );
  1415. // write into port
  1416. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1417. // store serial number
  1418. #ifndef NO_EMBED_CAMERA
  1419. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
  1420. #else
  1421. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
  1422. #endif
  1423. // update relay parameters
  1424. m_Relay.SetParameters( &rp );
  1425. // reset after file operation
  1426. //m_bRun = false;
  1427. Reset( true );
  1428. // reset IRQ checking
  1429. nBoardIrq = 0;
  1430. nBoardTimer = cMilliseconds;
  1431. }
  1432. break;
  1433. case LGS::CMD_SET_ADDRESS:
  1434. {
  1435. // reply command
  1436. *pSendBufferPtr++ = LGS::CMD_SET_ADDRESS;
  1437. // parse parameters
  1438. uint8_t pSerialNumber[MAX_PATH];
  1439. uint8_t nAddress, nCount;
  1440. LGS::GetAddress( pBuffer, &nAddress, &nCount, pSerialNumber );
  1441. // only if serial number is equal
  1442. if( (nCount == m_nSerialNumber) && !memcmp( pSerialNumber, m_pSerialNumber, m_nSerialNumber ) )
  1443. {
  1444. // change address
  1445. m_nAddress = nAddress;
  1446. // prepare answer message
  1447. nSendCount += LGS::BuildAddress( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  1448. // send reply
  1449. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1450. // store serial number
  1451. #ifndef NO_EMBED_CAMERA
  1452. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1453. #else
  1454. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1455. #endif
  1456. // reset after file operation
  1457. //m_bRun = false;
  1458. Reset( true );
  1459. // reset IRQ checking
  1460. nBoardIrq = 0;
  1461. nBoardTimer = cMilliseconds;
  1462. }
  1463. }
  1464. break;
  1465. case LGS::CMD_SET_COMM_SPEED:
  1466. {
  1467. // reply command
  1468. *pSendBufferPtr++ = LGS::CMD_SET_COMM_SPEED;
  1469. // parse parameters
  1470. int32_t nSpeed;
  1471. LGS::GetCommSpeed( pBuffer, &nSpeed );
  1472. // prepare answer message
  1473. nSendCount += LGS::BuildCommSpeed( pSendBufferPtr, nSpeed );
  1474. // send reply
  1475. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1476. // reinitialize communication if nessessary
  1477. #ifndef COMPILE_AS_GETFILE
  1478. if( m_pComm485->GetBaudRate() != nSpeed )
  1479. #endif
  1480. {
  1481. if( !m_pComm485->SetParameters( nSpeed, 8L, CComm485::_NOPARITY ) )
  1482. return false;
  1483. // store new comm speed
  1484. FILE *pFile = fopen( "SERIAL.INI", "wt" );
  1485. if( pFile )
  1486. {
  1487. fprintf( pFile, "%ld\n", nSpeed );
  1488. fclose( pFile );
  1489. }
  1490. // reset after file operation
  1491. //m_bRun = false;
  1492. Reset( true );
  1493. // reset IRQ checking
  1494. nBoardIrq = 0;
  1495. nBoardTimer = cMilliseconds;
  1496. }
  1497. }
  1498. break;
  1499. case LGS::CMD_PARAMETERS:
  1500. {
  1501. // reply command
  1502. *pSendBufferPtr++ = LGS::CMD_PARAMETERS;
  1503. // parse input command
  1504. uint8_t bSet, nDevice;
  1505. LGS::LGS_PARAMETERS parameters;
  1506. LGS::GetParameters( pBuffer, &bSet, &nDevice, &parameters );
  1507. // return parameters
  1508. if( bSet )
  1509. {
  1510. #if defined( LGS_PLS_1 ) || defined( LGS_MND )
  1511. if( nDevice == 0 ) m_Detector[ nDevice ].SetParameters( &parameters );
  1512. #else
  1513. #ifdef LGS_MIRROR
  1514. m_Detector[ ( nDevice ) % 4 ].SetParameters( &parameters );
  1515. m_Detector[ ( nDevice + 2 ) % 4 ].SetParameters( &parameters );
  1516. #endif
  1517. m_Detector[ nDevice ].SetParameters( &parameters );
  1518. #endif
  1519. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  1520. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1521. // reset after file operation
  1522. //m_bRun = false;
  1523. Reset( true );
  1524. // reset IRQ checking
  1525. nBoardIrq = 0;
  1526. nBoardTimer = cMilliseconds;
  1527. }
  1528. else
  1529. {
  1530. #if defined( LGS_PLS_1 ) || defined( LGS_MND )
  1531. if( nDevice == 0 ) m_Detector[ nDevice ].GetParameters( &parameters );// Set only as Master Device
  1532. #else
  1533. m_Detector[ nDevice ].GetParameters( &parameters );
  1534. #endif
  1535. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  1536. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1537. }
  1538. }
  1539. break;
  1540. case LGS::CMD_RESET:
  1541. *pSendBufferPtr++ = LGS::CMD_RESET;
  1542. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1543. #ifdef INFINITE_SAF_STUDY
  1544. m_Detector[0].StartLearningCycle();
  1545. #else
  1546. nMode = LGS::MODE_DETECTOR;
  1547. #ifndef COMPILE_AS_GETFILE
  1548. #ifdef STORE_FIRST_SAF
  1549. if( g_bSAFFileEnable ){
  1550. m_Detector[0].save_current_SAF();
  1551. };
  1552. #endif
  1553. #endif
  1554. Reset( false );
  1555. #endif
  1556. m_nBeforeZeroCounter = 0;
  1557. // reset IRQ checking
  1558. nBoardIrq = 0;
  1559. nBoardTimer = cMilliseconds;
  1560. #ifdef LGS_MIRROR
  1561. // bRestart = true;
  1562. m_bRun = false;
  1563. Reset( true );
  1564. #endif
  1565. break;
  1566. case LGS::CMD_FULL_RESET:
  1567. //if( g_dwStartupTime == 0 ) break;
  1568. if( ( g_dwStartupTime - ((DWORD) time( NULL ))) < 3 ) break;
  1569. *pSendBufferPtr++ = LGS::CMD_FULL_RESET;
  1570. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1571. nMode = LGS::MODE_DETECTOR;
  1572. #ifndef COMPILE_AS_GETFILE
  1573. #ifdef STORE_FIRST_SAF
  1574. if( g_bSAFFileEnable ){
  1575. m_Detector[ 0 ].save_current_SAF();
  1576. };
  1577. #endif
  1578. #endif
  1579. m_bRun = false;
  1580. Reset( true );
  1581. // reset IRQ checking
  1582. nBoardIrq = 0;
  1583. nBoardTimer = cMilliseconds;
  1584. #ifdef LGS_MIRROR
  1585. // bRestart = true;
  1586. // m_bRun = false;
  1587. #endif
  1588. break;
  1589. case LGS::CMD_FULL_BORDER:
  1590. {
  1591. *pSendBufferPtr++ = LGS::CMD_FULL_BORDER;
  1592. // read command data
  1593. uint16_t nAngle;
  1594. LGS::GetCmdFullBorder( pBuffer, &nAngle );
  1595. // prepare answer
  1596. uint16_t nRange1 = 0;
  1597. uint16_t nRange2 = 0;
  1598. #ifndef LGS_PLS_1
  1599. #ifdef LGS_MIRROR
  1600. #ifdef LGS_MND
  1601. #ifdef INFINITE_SAF_STUDY
  1602. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1, true ) &&
  1603. m_Detector[0].GetFullBorderRange( nAngle, &nRange2, false );
  1604. #else
  1605. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1606. nRange2 = nRange1;
  1607. #endif
  1608. #else
  1609. uint16_t nRange3 = 0;
  1610. uint16_t nRange4 = 0;
  1611. bool bReady = m_Detector[3].GetFullBorderRange( nAngle, &nRange4 ) &&
  1612. m_Detector[2].GetFullBorderRange( nAngle, &nRange3 ) &&
  1613. m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
  1614. m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1615. if( bReady ){
  1616. if( nRange1 > nRange2 ){
  1617. int16_t TRange;
  1618. TRange = nRange1;
  1619. nRange1 = nRange2;
  1620. nRange2 = TRange;
  1621. };
  1622. if( nRange1 > nRange3 ){
  1623. int16_t TRange;
  1624. TRange = nRange1;
  1625. nRange1 = nRange3;
  1626. nRange3 = TRange;
  1627. };
  1628. if( nRange1 > nRange4 ){
  1629. int16_t TRange;
  1630. TRange = nRange1;
  1631. nRange1 = nRange4;
  1632. nRange4 = TRange;
  1633. };
  1634. if( nRange2 < nRange3 ){
  1635. nRange2 = nRange3;
  1636. };
  1637. if( nRange2 < nRange4 ){
  1638. nRange2 = nRange4;
  1639. };
  1640. };
  1641. #endif
  1642. #else
  1643. bool bReady = m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
  1644. m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1645. #endif
  1646. #else // ndef PLS1
  1647. #ifdef INFINITE_SAF_STUDY
  1648. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1, true ) &&
  1649. m_Detector[0].GetFullBorderRange( nAngle, &nRange2, false );
  1650. #else
  1651. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1652. #endif
  1653. #endif // ndef PLS_1
  1654. if( bReady )
  1655. #ifdef RANGE_16BIT
  1656. //nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1 >> 5 , nRange2 >> 5 );
  1657. //nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1 >> 3 , nRange2 >> 3 );
  1658. //nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, (uint16_t)ceil( ((float)nRange1)/ 11.12f), (uint16_t)ceil( ((float)nRange2)/ 11.12f) );
  1659. {
  1660. uint16_t nR0,nR1;
  1661. //nRange1 = nAngle;
  1662. //nR0 = (uint16_t)(((float)nRange1)/ 11.12 + 1 );
  1663. nR0 = (uint16_t)(( 2048L * nRange1 )/ 22237 + 1 );
  1664. nR1 = (uint16_t)(( 2048L * nRange2 )/ 22237 + 1 );
  1665. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nR0, nR1 );
  1666. }
  1667. #else
  1668. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1, nRange2 );
  1669. #endif
  1670. else
  1671. #ifndef LGS_PLS_1
  1672. #ifdef LGS_MND
  1673. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nAngle, 0, 0 );
  1674. #else
  1675. // use percent from detector 2 because it always comes later
  1676. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nRange2, 0, 0 );
  1677. #endif
  1678. #else
  1679. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nAngle, 0, 0 );
  1680. #endif
  1681. // write back
  1682. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1683. }
  1684. break;
  1685. case LGS::CMD_GETFILE:
  1686. {
  1687. // build CMD_GETFILE command
  1688. *pSendBufferPtr++ = LGS::CMD_GETFILE;
  1689. #ifdef COMPILE_AS_GETFILE
  1690. if( nMode != LGS::MODE_GETFILE ){
  1691. bGetFileRun = true;
  1692. nMode = LGS::MODE_GETFILE;
  1693. };
  1694. {
  1695. #else
  1696. if( nMode != LGS::MODE_GETFILE ){
  1697. nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORMODE, 0, 0, 0 );
  1698. } else {
  1699. #endif
  1700. // get command parameters
  1701. uint8_t bError, bOperation, pData[100];
  1702. int16_t nData;
  1703. LGS::GetGetFile( pBuffer, &bError, &bOperation, pData, &nData );
  1704. // perform command
  1705. if( m_GetFile.OnCommand( bOperation, pData, nData ) )
  1706. nSendCount += LGS::BuildGetFile( pSendBufferPtr, 0, ( bOperation & LGS::GF_OP_INDEX ) | LGS::GF_OP_OK, NULL, 0 );
  1707. else
  1708. nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORFILE, bOperation, NULL, 0 );
  1709. }
  1710. // write answer
  1711. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1712. }
  1713. break;
  1714. #ifndef LGS_DISABLE_FILE_SYSTEM
  1715. case LGS::CMD_FS_SUB_PACKET: {
  1716. if( nMode != LGS::MODE_GETFILE ){
  1717. *pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
  1718. } else {
  1719. bool bAction;
  1720. PFS_DATA tPtr;
  1721. uint16_t tSize;
  1722. *pSendBufferPtr++ = LGS::CMD_FS_SUB_PACKET;
  1723. nSendCount ++;
  1724. m_pFSHelper->consume_data( pBuffer, bAction );
  1725. if( bAction ){
  1726. m_pFSHelper->do_action();
  1727. };
  1728. m_pFSHelper->output_data( tPtr, tSize );
  1729. if( tSize ){
  1730. memcpy( pSendBufferPtr, tPtr, tSize );
  1731. pSendBufferPtr += tSize;
  1732. nSendCount += tSize-1;
  1733. } else {
  1734. LGS::FS_DATA_EX OutFsData;
  1735. OutFsData.nCommand = LGS::FS_CMD_SEND_EVT;
  1736. OutFsData.sendevt.nError = LGS::FS_ERROR_OPERATION;
  1737. OutFsData.sendevt.nOrder = 0;
  1738. nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
  1739. };
  1740. };
  1741. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1742. break;
  1743. }
  1744. #endif
  1745. default:
  1746. //printf("CMD_UNSUPPORTED[0x%02X]\n", bHostCommand );
  1747. *pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
  1748. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1749. break;
  1750. };
  1751. };
  1752. };
  1753. };
  1754. };
  1755. #ifdef COMPILE_AS_GETFILE
  1756. //bRestart;
  1757. return false;
  1758. #else
  1759. return bRestart;
  1760. #endif
  1761. }
  1762. #ifndef COMPILE_3DSCANER
  1763. #ifdef COMPILE_RTSCANER___
  1764. // DoSendBoardData For RealTime Scanner
  1765. bool CKernel::DoSendBoardData( int16_t nDevice ){
  1766. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  1767. return false;
  1768. DWORD nBoardIrq = 0;
  1769. DWORD nBoardTimer = TIMER();
  1770. bool bPower, bZero, bSun[2];
  1771. int16_t nRange[2];
  1772. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
  1773. CLgBitCode Encoder( pData );
  1774. int16_t nPart = 0;
  1775. nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
  1776. while( m_bRun )
  1777. {
  1778. #ifdef WATCHDOG_ENABLED
  1779. // update watchdog timer
  1780. m_WatchDog.Update( TIMER() );
  1781. #endif
  1782. // check timer
  1783. if( ( (TIMER()) - nBoardTimer ) > 18UL )
  1784. {
  1785. if( !nBoardIrq )
  1786. {
  1787. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1788. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  1789. #endif
  1790. // reset board
  1791. m_pBoard->Reset();
  1792. }
  1793. nBoardTimer = TIMER();
  1794. nBoardIrq = 0;
  1795. }
  1796. // get new data
  1797. if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
  1798. {
  1799. // increase IRQ counter
  1800. nBoardIrq++;
  1801. // add next 13 bits of data
  1802. DWORD dwData = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  1803. if( Encoder.Encode24( dwData, 13 ) )
  1804. {
  1805. // increase part number
  1806. nPart++;
  1807. // if numbe rof partes exeed max partes
  1808. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART )
  1809. {
  1810. // prepare check sum in 14th byte of packet
  1811. uint8_t bCheckSum = 0;
  1812. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
  1813. bCheckSum += pData[i];
  1814. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  1815. // write into stream
  1816. m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  1817. delay(1);
  1818. // reset part
  1819. nPart = 0;
  1820. // zero memory
  1821. memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
  1822. }
  1823. // restart encoder
  1824. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  1825. }
  1826. }
  1827. #ifdef COMM_WITHOUT_INTERRUPTS
  1828. m_pComm485->Invalidate();
  1829. //m_pCameraComm->Invalidate();
  1830. #endif
  1831. //DWORD CTimer = m_pBoard->GetTimer();
  1832. //while( CTimer == m_pBoard->GetTimer() ); // delay 1/6000 sec
  1833. }
  1834. return true;
  1835. };
  1836. #else
  1837. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  1838. /* Old Procedure 060512
  1839. bool CKernel::DoSendBoardData( int16_t nDevice ){
  1840. #ifndef LGS_MIRROR
  1841. #ifdef LGS_PLS_1
  1842. nDevice = 0;
  1843. #else
  1844. nDevice = nDevice % 2;
  1845. #endif
  1846. #endif
  1847. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  1848. return false;
  1849. DWORD nBoardIrq = 0;
  1850. DWORD nBoardTimer = TIMER();
  1851. bool bPower, bZero, bSun[2], Reading, Writing;
  1852. DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
  1853. uint16_t CPointer = 0;
  1854. uint16_t OPointer = 0;
  1855. uint16_t CAngle = 0;
  1856. int16_t nRange[2];
  1857. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
  1858. CLgBitCode Encoder( pData );
  1859. int16_t nPart = 0;
  1860. bool WaitFZ;
  1861. Reading = false;
  1862. Writing = false;
  1863. WaitFZ = true;
  1864. //nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
  1865. while( m_bRun ){
  1866. #ifdef WATCHDOG_ENABLED
  1867. // update watchdog timer
  1868. m_WatchDog.Update( TIMER() );
  1869. #endif
  1870. if( ( ( TIMER() ) - nBoardTimer ) > 36UL ){
  1871. if( !nBoardIrq ){
  1872. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1873. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  1874. #endif
  1875. // reset board
  1876. if( g_UI_Debug ){
  1877. printf( "NO IRQ RESET\n" );
  1878. };
  1879. m_pBoard->AsyncReset();
  1880. WaitFZ = true;
  1881. Reading = false;
  1882. Writing = false;
  1883. };
  1884. nBoardTimer = TIMER();
  1885. nBoardIrq = 0;
  1886. }
  1887. // check board
  1888. uint8_t RetVal;
  1889. if( !Writing )
  1890. while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
  1891. if( RetVal == 2 ){
  1892. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1893. printf("DMA Transfers Overlaped\n");
  1894. #endif
  1895. // -----------------------
  1896. m_pBoard->AsyncReset();
  1897. WaitFZ = true;
  1898. Reading = false;
  1899. Writing = false;
  1900. break;
  1901. };
  1902. // perform linearization
  1903. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  1904. #ifdef LGS_MIRROR
  1905. nRange[1] = nRange[0];
  1906. #else
  1907. #ifndef LGS_PLS_1
  1908. nRange[1] = nRange[0];
  1909. #else
  1910. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  1911. #endif
  1912. #endif
  1913. // update voltage state
  1914. m_Voltage.Invalidate( bPower );
  1915. // increase IRQ counter
  1916. nBoardTimer = TIMER();
  1917. nBoardIrq++;
  1918. if( bZero && WaitFZ ){
  1919. WaitFZ = false;
  1920. Writing = false;
  1921. };
  1922. if( !WaitFZ ){
  1923. if( bZero ){
  1924. CPointer = 0;
  1925. CAngle = 0;
  1926. if( !Writing ) Reading = true;
  1927. } else {
  1928. CAngle++;
  1929. };
  1930. };
  1931. if( Reading ){
  1932. if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) ){
  1933. bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
  1934. //nRange[nDevice]
  1935. Buffer[CPointer] = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  1936. CPointer++;
  1937. if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
  1938. Reading = false;
  1939. Writing = true;
  1940. OPointer = 0;
  1941. };
  1942. };
  1943. };
  1944. };
  1945. if( Writing ){
  1946. // increase IRQ counter
  1947. nBoardTimer = TIMER();
  1948. nBoardIrq++;
  1949. // add next 13 bits of data
  1950. DWORD dwData = Buffer[OPointer];//(DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  1951. OPointer++;
  1952. #ifdef LGS_MIRROR
  1953. if( OPointer == 916 ){ //
  1954. #else
  1955. #ifdef LGS_PLS_1
  1956. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  1957. #else
  1958. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){
  1959. #endif
  1960. #endif
  1961. Writing = false;
  1962. //WaitFZ = true;
  1963. continue;
  1964. };
  1965. if( Encoder.Encode24( dwData, 13 ) ){
  1966. // increase part number
  1967. nPart++;
  1968. // if number raw parts meets max parts
  1969. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
  1970. // prepare check sum in 14th byte of packet
  1971. uint8_t bCheckSum = 0;
  1972. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
  1973. bCheckSum += pData[i];
  1974. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  1975. // write into stream
  1976. m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  1977. delay(4);
  1978. // reset part
  1979. nPart = 0;
  1980. // zero memory
  1981. memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
  1982. #ifdef COMM_WITHOUT_INTERRUPTS
  1983. m_pComm485->Invalidate();
  1984. //m_pCameraComm->Invalidate();
  1985. #endif
  1986. }
  1987. // restart encoder
  1988. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  1989. };
  1990. };
  1991. };
  1992. return true;
  1993. } */
  1994. // Regular DoSendBoardData ... PLS LGS ALS LFS
  1995. bool CKernel::DoSendBoardData( int16_t nDevice ){
  1996. #ifndef LGS_MIRROR
  1997. #ifdef LGS_PLS_1
  1998. nDevice = 0;
  1999. #else
  2000. nDevice = nDevice % 2;
  2001. #endif
  2002. #else
  2003. nDevice = nDevice % 4;
  2004. #endif
  2005. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  2006. return false;
  2007. DWORD nBoardIrq = 0;
  2008. DWORD nBoardTimer = TIMER();
  2009. bool bPower, bZero, bSun[2], Reading, Writing;
  2010. uint16_t SentScanCounter = 0;
  2011. //DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
  2012. uint16_t far *Buffer[2];//[LGS_MAX_DETECTOR_ANGLES];
  2013. Buffer[0] = (uint16_t far *) farmalloc( sizeof( uint16_t ) *LGS_MAX_DETECTOR_ANGLES );
  2014. if( Buffer[0] == NULL ) return false;
  2015. Buffer[1] = (uint16_t far *) farmalloc( sizeof( uint16_t ) *LGS_MAX_DETECTOR_ANGLES );
  2016. if( Buffer[0] == NULL ){
  2017. free( Buffer[0] );
  2018. return false;
  2019. };
  2020. uint16_t CPointer = 0;
  2021. uint16_t OPointer = 0;
  2022. uint16_t CAngle = 0;
  2023. uint16_t nRange[2];
  2024. #ifdef LGS_BOARDSAMPLE_RATIO
  2025. int16_t nRBuffer[LGS_BOARDSAMPLE_RATIO][2];
  2026. #endif
  2027. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 ];
  2028. CLgBitCode Encoder( pData );
  2029. int16_t nPart = 0;
  2030. bool WaitFZ;
  2031. bool tbZero;
  2032. bool tbSun;
  2033. char CoBuffer[20];
  2034. DWORD cnt;
  2035. uint8_t bCOutputArray, bCInputArray;
  2036. cnt = 0;
  2037. tbZero = false;
  2038. tbSun = false;
  2039. Reading = false;
  2040. Writing = false;
  2041. WaitFZ = true;
  2042. bCOutputArray = 0;
  2043. bCInputArray = 0;
  2044. //nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 1 );
  2045. //Wait till start
  2046. //cnt = m_pComm485->ReadWithWait( CoBuffer, 2, 36 ); //2 seconds in measurements of 1\18
  2047. //if( strcmp( CoBuffer, "AA" )!= 0 ) m_bRun = false;
  2048. //if( cnt == 0 ) m_bRun = false;
  2049. //delay( 3 );
  2050. // Start Empty Encoder
  2051. memset( pData, 0, ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 );
  2052. Encoder.SetBuffer( pData );
  2053. while( m_bRun ){
  2054. #ifdef WATCHDOG_ENABLED
  2055. if( g_bWatchDogEnable ){
  2056. // update watchdog timer
  2057. m_WatchDog.Update( TIMER() );
  2058. };
  2059. #endif
  2060. #ifdef BOARD_LAZY_INIT
  2061. if( ( ( TIMER() ) - nBoardTimer ) > 300UL ){
  2062. #else
  2063. if( ( ( TIMER() ) - nBoardTimer ) > 136UL ){
  2064. #endif
  2065. if( !nBoardIrq ){
  2066. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2067. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  2068. #endif
  2069. m_pBoard->AsyncReset();
  2070. WaitFZ = true;
  2071. Reading = false;
  2072. Writing = false;
  2073. };
  2074. nBoardTimer = TIMER();
  2075. nBoardIrq = 0;
  2076. }
  2077. // check board
  2078. uint8_t RetVal;
  2079. while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
  2080. if( RetVal == 2 ){
  2081. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2082. printf("DMA Transfers Overlaped\n");
  2083. #endif
  2084. // -----------------------
  2085. m_pBoard->AsyncReset();
  2086. WaitFZ = true;
  2087. Reading = false;
  2088. Writing = false;
  2089. break;
  2090. };
  2091. #ifdef RANGE_16BIT
  2092. #else
  2093. // perform linearization
  2094. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  2095. #ifdef LGS_MIRROR
  2096. nRange[1] = nRange[0];
  2097. #else
  2098. #ifdef LGS_PLS_1
  2099. nRange[1] = nRange[0];
  2100. #else
  2101. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  2102. #endif
  2103. #endif
  2104. #endif //16 bit
  2105. // update voltage state
  2106. m_Voltage.Invalidate( bPower );
  2107. // increase IRQ counter
  2108. nBoardTimer = TIMER();
  2109. nBoardIrq++;
  2110. //if(!Writing ){
  2111. //if( bZero && WaitFZ ){
  2112. // WaitFZ = false;
  2113. //Writing = false;
  2114. //};
  2115. if( !Reading && WaitFZ ){
  2116. if( bZero ){
  2117. CPointer = 0;
  2118. CAngle = 0;
  2119. Reading = true;
  2120. WaitFZ = false;
  2121. };
  2122. };
  2123. if( Reading ){
  2124. CAngle++;
  2125. #ifdef LGS_MIRROR
  2126. if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) )
  2127. #endif
  2128. {
  2129. #ifdef ALS_300
  2130. if( CAngle % 3 == 0 ){
  2131. if( bZero ) tbZero = true; //= ( CAngle == 3 ); // First Measure
  2132. if( bSun[nDevice] ) tbSun = true;
  2133. Buffer[bCInputArray][CPointer] += nRange[nDevice];
  2134. Buffer[bCInputArray][CPointer] = Buffer[bCInputArray][CPointer] / 3;
  2135. Buffer[bCInputArray][CPointer] |= (uint16_t)( ( bSun[nDevice] ? 1 << 11 : 0 ) | ( tbZero ? 1 << 12 : 0 ) );
  2136. CPointer++;
  2137. tbZero = false;
  2138. tbSun = false;
  2139. if( CPointer < LGS_MAX_DETECTOR_ANGLES ){
  2140. Buffer[bCInputArray][CPointer] = 0;
  2141. } else {
  2142. Buffer[bCInputArray][0] = 0;
  2143. };
  2144. } else {
  2145. Buffer[bCInputArray][CPointer] += nRange[nDevice];
  2146. if( bZero ) tbZero = true;
  2147. if( bSun[nDevice] ) tbSun = true;
  2148. continue;
  2149. };
  2150. #else
  2151. bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
  2152. Buffer[bCInputArray][CPointer] = (uint16_t)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  2153. CPointer++;
  2154. #endif
  2155. #if defined( LGS_REDUCED_PRF )
  2156. if( CPointer == (LGS_MAX_DETECTOR_ANGLES / LGS_PRF_REDUCE_RATIO) ){
  2157. #else
  2158. if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
  2159. #endif
  2160. bCInputArray = ( bCInputArray )? 0:1 ;
  2161. if( bCInputArray == bCOutputArray ){
  2162. Reading = false;
  2163. };
  2164. Writing = true;
  2165. CPointer = 0;
  2166. //OPointer = 0;
  2167. };
  2168. };
  2169. };
  2170. //};
  2171. };
  2172. if( Writing ){
  2173. #ifdef LGS_MIRROR
  2174. if( OPointer < 920 ){ //
  2175. #else
  2176. #ifdef LGS_PLS_1
  2177. #ifdef LGS_PLS_200
  2178. if( OPointer < LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2179. #else
  2180. if( OPointer < LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2181. #endif
  2182. #else
  2183. if( OPointer < LGS_MAX_DETECTOR_ANGLES ){
  2184. #endif
  2185. #endif
  2186. // add next 13 bits of data
  2187. #if defined( LGS_REDUCED_PRF )
  2188. DWORD dwData;
  2189. if( LGS_PRF_REDUCE_RATIO > 1 ){
  2190. if( ( Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] & (1<<12) ) && (( OPointer % LGS_PRF_REDUCE_RATIO ) != 0)){
  2191. Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] = Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] & ( ~(1<<12) );
  2192. };
  2193. dwData = Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO )];
  2194. } else {
  2195. dwData = Buffer[bCOutputArray][OPointer];
  2196. };
  2197. #else
  2198. DWORD dwData = (DWORD) Buffer[bCOutputArray][OPointer];
  2199. #endif
  2200. OPointer++;
  2201. if( Encoder.Encode24( dwData, 13 ) ){
  2202. // increase part number
  2203. nPart++;
  2204. // if number raw parts meets max parts
  2205. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
  2206. // prepare check sum in 14th byte of packet
  2207. uint8_t bCheckSum = 0;
  2208. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ ) bCheckSum += pData[i];
  2209. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  2210. // write into stream
  2211. m_pComm485->Write( pData, ( LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  2212. // Wait till all data is sent
  2213. m_pComm485->Flush();
  2214. cnt = 0;
  2215. //long cTT = TIMER();
  2216. //while( cnt==0 && cTT - TIMER() < 180 ){
  2217. // Read 1 Bytes from Line
  2218. // cnt = m_pComm485->ReadWithWait( CoBuffer, 1, 36 ); //2 seconds in measurements of 1\18
  2219. // if( cnt == 0 ) m_bRun = false;
  2220. // if( bCheckSum != CoBuffer[0] ) m_bRun = false;
  2221. //};
  2222. //delay(2);
  2223. // reset part
  2224. nPart = 0;
  2225. // zero memory
  2226. memset( pData, 0, ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 );
  2227. #ifdef COMM_WITHOUT_INTERRUPTS
  2228. m_pComm485->Invalidate();
  2229. //m_pCameraComm->Invalidate();
  2230. #endif
  2231. };
  2232. // restart encoder
  2233. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  2234. };
  2235. } else {
  2236. bCOutputArray = ( bCOutputArray )? 0: 1;
  2237. if( bCOutputArray == bCInputArray ){
  2238. Writing = false;
  2239. WaitFZ = true;
  2240. };
  2241. OPointer = 0;
  2242. SentScanCounter ++;
  2243. #ifndef SENDBOARDDATA_INF
  2244. if( SentScanCounter > 500 ){
  2245. //while(1);
  2246. return true;
  2247. };
  2248. #endif
  2249. };
  2250. };
  2251. };
  2252. return true;
  2253. }
  2254. #endif
  2255. #endif //COMPILE_RTSCANER
  2256. #else //COMPILE_3DSCANER
  2257. // DoSendBoardData For 3D Scanner
  2258. bool CKernel::DoSendBoardData( int16_t nDevice ){
  2259. #ifndef LGS_MIRROR
  2260. #ifdef LGS_PLS_1
  2261. nDevice = 0;
  2262. #else
  2263. nDevice = nDevice % 2;
  2264. #endif
  2265. #else
  2266. nDevice = nDevice % 4;
  2267. #endif
  2268. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  2269. return false;
  2270. DWORD nBoardIrq = 0;
  2271. DWORD nBoardTimer = TIMER();
  2272. bool bPower, bZero, bSun[2], Reading, Writing;
  2273. //DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
  2274. uint16_t Buffer[LGS_MAX_DETECTOR_ANGLES];
  2275. uint16_t CPointer = 0;
  2276. uint16_t OPointer = 0;
  2277. uint16_t CAngle = 0;
  2278. int16_t nRange[2];
  2279. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
  2280. CLgBitCode Encoder( pData );
  2281. int16_t nPart = 0;
  2282. bool WaitFZ;
  2283. Reading = false;
  2284. Writing = false;
  2285. WaitFZ = true;
  2286. //nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
  2287. while( m_bRun ){
  2288. #ifdef WATCHDOG_ENABLED
  2289. if( g_bWatchDogEnable ){
  2290. // update watchdog timer
  2291. m_WatchDog.Update( TIMER() );
  2292. };
  2293. #endif
  2294. if( ( ( TIMER() ) - nBoardTimer ) > 36UL ){
  2295. if( !nBoardIrq ){
  2296. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2297. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  2298. #endif
  2299. // reset board
  2300. m_pBoard->AsyncReset();
  2301. WaitFZ = true;
  2302. Reading = false;
  2303. Writing = false;
  2304. };
  2305. nBoardTimer = TIMER();
  2306. nBoardIrq = 0;
  2307. }
  2308. // check board
  2309. uint8_t RetVal;
  2310. while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
  2311. if( RetVal == 2 ){
  2312. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2313. printf("DMA Transfers Overlaped\n");
  2314. #endif
  2315. // -----------------------
  2316. m_pBoard->AsyncReset();
  2317. WaitFZ = true;
  2318. Reading = false;
  2319. Writing = false;
  2320. break;
  2321. };
  2322. // perform linearization
  2323. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  2324. #ifdef LGS_MIRROR
  2325. nRange[1] = nRange[0];
  2326. #else
  2327. #ifndef LGS_PLS_1
  2328. nRange[1] = nRange[0];
  2329. #else
  2330. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  2331. #endif
  2332. #endif
  2333. // update voltage state
  2334. m_Voltage.Invalidate( bPower );
  2335. // increase IRQ counter
  2336. nBoardTimer = TIMER();
  2337. nBoardIrq++;
  2338. if(!Writing ){
  2339. if( bZero && WaitFZ ){
  2340. WaitFZ = false;
  2341. Writing = false;
  2342. };
  2343. if( !WaitFZ ){
  2344. if( bZero ){
  2345. CPointer = 0;
  2346. CAngle = 0;
  2347. Reading = true;
  2348. } else {
  2349. CAngle++;
  2350. };
  2351. };
  2352. if( Reading ){
  2353. if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) ){
  2354. bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
  2355. //nRange[nDevice]
  2356. //Buffer[CPointer] = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  2357. Buffer[CPointer] = (uint16_t)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  2358. CPointer++;
  2359. if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
  2360. Reading = false;
  2361. Writing = true;
  2362. OPointer = 0;
  2363. };
  2364. };
  2365. };
  2366. };
  2367. };
  2368. if( Writing ){
  2369. // increase IRQ counter
  2370. nBoardTimer = TIMER();
  2371. nBoardIrq++;
  2372. // add next 13 bits of data
  2373. #ifdef LGS_PLS_200
  2374. DWORD dwData;
  2375. if( LGS_PRF_REDUCE_RATIO > 1 ){
  2376. if( ( Buffer[(OPointer >> 1)] & (1<<12) ) && (( OPointer % 2 ) != 0)){
  2377. Buffer[(OPointer >> 1)] = Buffer[(OPointer >> 1)] & ( ~(1<<12) );
  2378. };
  2379. dwData = Buffer[(OPointer >> 1)];
  2380. } else {
  2381. dwData = Buffer[OPointer];
  2382. };
  2383. #else
  2384. DWORD dwData = Buffer[OPointer];
  2385. #endif
  2386. OPointer++;
  2387. #ifdef LGS_MIRROR
  2388. if( OPointer == 916 ){ //
  2389. #else
  2390. #ifdef LGS_PLS_1
  2391. #ifdef LGS_PLS_200
  2392. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2393. #else
  2394. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2395. #endif
  2396. #else
  2397. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){
  2398. #endif
  2399. #endif
  2400. Writing = false;
  2401. //WaitFZ = true;
  2402. continue;
  2403. };
  2404. if( Encoder.Encode24( dwData, 13 ) ){
  2405. // increase part number
  2406. nPart++;
  2407. // if number raw parts meets max parts
  2408. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
  2409. // prepare check sum in 14th byte of packet
  2410. uint8_t bCheckSum = 0;
  2411. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
  2412. bCheckSum += pData[i];
  2413. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  2414. // write into stream
  2415. m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  2416. delay( 2 );
  2417. // reset part
  2418. nPart = 0;
  2419. // zero memory
  2420. memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
  2421. #ifdef COMM_WITHOUT_INTERRUPTS
  2422. m_pComm485->Invalidate();
  2423. //m_pCameraComm->Invalidate();
  2424. #endif
  2425. }
  2426. // restart encoder
  2427. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  2428. };
  2429. };
  2430. };
  2431. return true;
  2432. }
  2433. #endif
  2434. /////////////////////// FILE SYSTEM REQUESTS HANDLERS //////////////////////////
  2435. #ifndef LGS_DISABLE_FILE_SYSTEM
  2436. /*
  2437. LG_FS_RESULT CKernel::DoOpenFile( PLG_FS_PATH pName ){
  2438. if( m_pFSFileHandle != NULL ) fclose( m_pFSFileHandle );
  2439. m_pFSFileHandle = fopen( pName->pBuffer, "rb" );
  2440. if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2441. return LG_FS_RESULT_SUCCESS;
  2442. };
  2443. LG_FS_RESULT CKernel::DoReadFile( PBYTE pRead, uint8_t bSize, PBYTE pBuffer ){
  2444. if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2445. *pRead = fread( pBuffer, 1, bSize, m_pFSFileHandle );
  2446. return LG_FS_RESULT_SUCCESS;
  2447. };
  2448. LG_FS_RESULT CKernel::DoCloseFile( void ){
  2449. if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2450. fclose( m_pFSFileHandle );
  2451. return LG_FS_RESULT_SUCCESS;
  2452. };
  2453. LG_FS_RESULT CKernel::DoGetCurrentDirectory( PLG_FS_PATH pPath ){
  2454. if( getcwd( pPath->pBuffer, 256 )!= NULL ){
  2455. pPath->pBuffer[255]=(char)0;
  2456. // sprintf( pPath->pBuffer, "KOKO256" );
  2457. pPath->nSize = strlen( pPath->pBuffer );
  2458. return LG_FS_RESULT_SUCCESS;
  2459. };
  2460. pPath->pBuffer[0]=(char)0;
  2461. pPath->nSize = 0;
  2462. return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2463. };
  2464. struct ffblk g_ffBlock;
  2465. LG_FS_RESULT CKernel::DoFindFirst( PDWORD pHandle, PLG_FS_PATH pPath, PLG_FS_FIND_DATA pFindData )
  2466. {
  2467. // add termination 0
  2468. TCHAR pPathWithNull[MAX_PATH];
  2469. memcpy( pPathWithNull, pPath->pBuffer, pPath->nSize );
  2470. pPathWithNull[ pPath->nSize ] = 0;
  2471. // open find first
  2472. if( findfirst( pPathWithNull, &g_ffBlock, FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_DIREC | FA_ARCH ) == 0 )
  2473. {
  2474. g_ffBlock.ff_attrib;
  2475. pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
  2476. ( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
  2477. ( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
  2478. ( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
  2479. ( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
  2480. pFindData->dwFileSizeHigh = 0;
  2481. pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
  2482. pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
  2483. memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
  2484. *pHandle = 0;
  2485. return LG_FS_RESULT_SUCCESS;
  2486. }
  2487. *pHandle = LG_FS_INVALID_HANDLE;
  2488. return LG_FS_RESULT_ERROR_NO_MORE_FILES;
  2489. }
  2490. LG_FS_RESULT CKernel::DoFindNext( DWORD dwHandle, PLG_FS_FIND_DATA pFindData )
  2491. {
  2492. dwHandle;
  2493. // open find first
  2494. if( findnext( &g_ffBlock ) == 0 )
  2495. {
  2496. pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
  2497. ( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
  2498. ( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
  2499. ( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
  2500. ( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
  2501. pFindData->dwFileSizeHigh = 0;
  2502. pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
  2503. pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
  2504. memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
  2505. return LG_FS_RESULT_SUCCESS;
  2506. }
  2507. return LG_FS_RESULT_ERROR_NO_MORE_FILES;
  2508. }
  2509. LG_FS_RESULT CKernel::DoFindClose( DWORD dwHandle )
  2510. {
  2511. dwHandle;
  2512. return LG_FS_RESULT_SUCCESS;
  2513. }
  2514. */
  2515. #endif
  2516. void CKernel::OnCmdState2( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount, uint8_t& nMode, bool& bBoardNoIrq )
  2517. {
  2518. // build CMD_STATE_2 command
  2519. *pSendBufferPtr++ = LGS::CMD_STATE_2;
  2520. // if mode is wrong
  2521. if( nMode != LGS::MODE_DETECTOR )
  2522. {
  2523. // build reply
  2524. nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, LGS::S2_ITF_ERROR_MODE );
  2525. return;
  2526. }
  2527. uint8_t bRequestType = LGS::S2_RT_TARGET_POLAR;
  2528. if( nReadCount )
  2529. nReadCount -= LGS::GetCmdState2( pReadBufferPtr, &bRequestType );
  2530. // flags
  2531. uint8_t bFlags = 0;
  2532. #ifndef NO_LIC
  2533. // If Work Disable then ...
  2534. if (! m_pBoard->workingEnabled() ){
  2535. int16_t nErrorAngle = 2222;
  2536. if ( TIMER() - m_dwTimeErrorDelay_EA > MSEC_TO_TIME( 200UL ) ) {
  2537. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2538. m_dwTimeErrorDelay_EA = TIMER();
  2539. };
  2540. if( m_nInitErrorSkipCounter ) m_nInitErrorSkipCounter --;
  2541. };
  2542. #endif
  2543. // check for ANGLE and ZERO MARK errors
  2544. #ifdef LGS_MIRROR
  2545. if( g_bShowErrors ){
  2546. for( int16_t i = 0; i < 4; i++){
  2547. if( m_Detector[i].GetLastErrorAngle() ){
  2548. int16_t nErrorAngle = m_Detector[i].GetLastErrorAngleValue();
  2549. if( ( nErrorAngle == 1111 || nErrorAngle == 387 || nErrorAngle == 1112 || nErrorAngle == 386 ) && m_pBoard->workingEnabled() ){
  2550. // Trying to fixup Certificate trouble
  2551. m_bRun = false; // Error Sending SN to Board -> Restart
  2552. };
  2553. if ( ( ( TIMER() - m_dwTimeErrorDelay_EA ) < MSEC_TO_TIME( 200UL ) ) || !g_bDelayErrors ) {
  2554. if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
  2555. if( nErrorAngle == -1 ){
  2556. bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
  2557. } else {
  2558. if( ( nErrorAngle == 1111 || nErrorAngle == 387 || nErrorAngle == 1112 || nErrorAngle == 386 ) && m_pBoard->workingEnabled() ){
  2559. if( g_bShowErrors ){
  2560. // Because of ZeroShift the ErrorAngle must be corrected to 1111 after getting 387
  2561. nErrorAngle = 1111;
  2562. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2563. };
  2564. //m_bRun = false; // Error Sending SN to Board -> Restart
  2565. } else if( ( nErrorAngle > 0 ) && ( nErrorAngle < ( LGS_REAL_DETECTOR_ANGLES - 5 ) ) ){
  2566. if( g_bShowErrors ){
  2567. nErrorAngle += (i+1)*10000;
  2568. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2569. };
  2570. };
  2571. };
  2572. m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
  2573. } else m_nInitErrorSkipCounter --;
  2574. };
  2575. m_dwTimeErrorDelay_EA = TIMER();
  2576. };
  2577. };
  2578. };
  2579. #else
  2580. if( g_bShowErrors && m_Detector[0].GetLastErrorAngle() ){
  2581. int16_t nErrorAngle = m_Detector[0].GetLastErrorAngleValue();
  2582. if ( ( ( TIMER() - m_dwTimeErrorDelay_EA ) < MSEC_TO_TIME( 200UL ) ) || !g_bDelayErrors ) {
  2583. if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
  2584. if( nErrorAngle == -1 ){
  2585. bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
  2586. } else {
  2587. /* if( ( nErrorAngle == 1111 ) && m_pBoard->workingEnabled() ){
  2588. m_bRun = false; // Error Sending SN to Board -> Restart
  2589. } else */
  2590. if( ( nErrorAngle > 0 ) && ( nErrorAngle < ( LGS_REAL_DETECTOR_ANGLES - 5 ) ) ){
  2591. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2592. };
  2593. };
  2594. m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
  2595. } else m_nInitErrorSkipCounter --;
  2596. };
  2597. m_dwTimeErrorDelay_EA = TIMER();
  2598. };
  2599. #endif
  2600. // check for NO IRQ
  2601. if( g_bShowErrors && bBoardNoIrq ) {
  2602. if ( ( ( TIMER() - m_dwTimeErrorDelay_IQ ) < 200UL ) || !g_bDelayErrors ) {
  2603. if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
  2604. bFlags |= LGS::S2_ITF_ERROR_NO_IRQ;
  2605. m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
  2606. //printf("Error Sent\n");
  2607. } else {
  2608. m_nInitErrorSkipCounter --;
  2609. //printf("Decreased Init Skip Value [%d]\n",m_nInitErrorSkipCounter);
  2610. };
  2611. };
  2612. m_dwTimeErrorDelay_IQ = TIMER();
  2613. // clear no irq flag
  2614. bBoardNoIrq = false;
  2615. };
  2616. // check for POWER changes
  2617. if( g_bShowErrors ) m_Voltage.OnProtocolLgsState2Command( bFlags );
  2618. #ifndef EMBEDDED_CAMERA_DISABLE
  2619. #ifndef NO_EMBED_CAMERA
  2620. // add camera flags
  2621. m_pCamera->OnProtocolLgsState2Command( bFlags );
  2622. #endif
  2623. #endif
  2624. // apply flags
  2625. if( bFlags ) nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, bFlags );
  2626. /* Old Sergey's for( int i = 0; i < 2; i++ )
  2627. {
  2628. CDetector *pDetector = m_Detector + i;
  2629. #ifdef LGS_MIRROR
  2630. CTracker *pTracker = m_Tracker + 0;
  2631. #else
  2632. CTracker *pTracker = m_Tracker + i;
  2633. #endif */
  2634. #ifdef LGS_MIRROR
  2635. for( int i = 0; i < 4; i++ ){
  2636. CDetector *pDetector = &m_Detector[i];
  2637. CTracker *pTracker = &m_Tracker[0];
  2638. #else
  2639. #ifdef LGS_PLS_1
  2640. {
  2641. int i = 0;
  2642. #else
  2643. for( int i = 0; i < 2; i++ ){
  2644. #endif
  2645. CDetector *pDetector = &m_Detector[i];
  2646. CTracker *pTracker = &m_Tracker[i];
  2647. #endif
  2648. // assume that no errors
  2649. uint8_t bDeviceFlags = 0;
  2650. // check for tracker overflow
  2651. if( ( m_dwTimeErrorOverflow[i] < TIMER() ) && pTracker->GetLastErrorOverflow() )
  2652. {
  2653. m_dwTimeErrorOverflow[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2654. bDeviceFlags |= LGS::S2_ITDF_ERROR_OVERFLOW;
  2655. }
  2656. // check for tracker scan to scan overflow
  2657. if( ( m_dwTimeErrorOverflowSST[i] < TIMER() ) && pTracker->GetLastErrorOverflowSST() )
  2658. {
  2659. m_dwTimeErrorOverflowSST[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2660. bDeviceFlags |= LGS::S2_ITDF_ERROR_SST_OVERFLOW;
  2661. }
  2662. // check for detector sun errors
  2663. if( ( m_dwTimeErrorSun[i] < TIMER() ) && pDetector->GetLastErrorSun() )
  2664. {
  2665. m_dwTimeErrorSun[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2666. bDeviceFlags |= LGS::S2_ITDF_ERROR_SUN;
  2667. }
  2668. // apply device flags
  2669. if( g_bShowErrors && bDeviceFlags )
  2670. nSendCount += LGS::BuildEvtState2DeviceFlags( pSendBufferPtr, i, bDeviceFlags );
  2671. // place target information
  2672. CTracker::TARGET target;
  2673. while( ( pTracker->GetTarget( &target )
  2674. #ifndef NO_LIC
  2675. && m_pBoard->workingEnabled()
  2676. #endif
  2677. #ifdef DEBUG_TARGET_SIMULATOR
  2678. ) || bFireSimulatedTarget
  2679. #else
  2680. )
  2681. #endif
  2682. )
  2683. {
  2684. #ifdef DEBUG_TARGET_SIMULATOR
  2685. if( bFireSimulatedTarget ){
  2686. target.bType = LGS::TT_NORMAL;
  2687. target.nRange = 200;
  2688. target.nAngle = ( 3000* nSimulatedTargetID )/360 ;//145; GP2Y0A700K
  2689. target.nWidth = nSimulatedTargetValue;
  2690. bFireSimulatedTarget = false;
  2691. };
  2692. #endif
  2693. uint8_t bType;
  2694. switch( target.bType )
  2695. {
  2696. case LGS::TT_WIDE:
  2697. case LGS::TT_NORMAL:
  2698. bType = ( target.bType == LGS::TT_NORMAL ) ? LGS::S2_ITT_NORMAL : LGS::S2_ITT_WIDE;
  2699. if( ( bRequestType & LGS::S2_RT_TARGET_MASK ) == LGS::S2_RT_TARGET_DEKART )
  2700. {
  2701. #ifdef LGS_MIRROR
  2702. #ifdef LGS_MND
  2703. const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
  2704. double a = ( target.nAngle << 2 ) * a2r;
  2705. #else
  2706. const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
  2707. double a = ( target.nAngle << 1 ) * a2r;
  2708. #endif
  2709. #else
  2710. const double a2r = asin(1.0) * 4.0 / LGS_MAX_DETECTOR_ANGLES;
  2711. double a = ( target.nAngle ) * a2r;
  2712. #endif
  2713. #ifdef ALS_300_BM
  2714. target.nAngle = (((float)target.nAngle ) * (6000.0f / 20000.0f)); //Convert Angle from 20000 to 6000
  2715. #endif
  2716. int16_t x = target.nRange * cos( a );
  2717. int16_t y = target.nRange * sin( a );
  2718. #if defined( LGS_MIRROR ) || defined( LGS_MND )
  2719. #ifdef LGS_MND
  2720. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2721. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth << 2 ) :
  2722. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2723. #else
  2724. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2725. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth ) :
  2726. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2727. #endif
  2728. #else
  2729. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2730. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth )://<< 1 ) :
  2731. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2732. #endif
  2733. } else {
  2734. #ifdef LGS_MIRROR
  2735. #ifdef LGS_MND
  2736. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2737. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange, target.nWidth << 2 ) : // ? Wx2 ??
  2738. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange );
  2739. #else
  2740. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2741. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange, target.nWidth )://<< 1 ) : // ? Wx2 ??
  2742. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange );
  2743. #endif
  2744. #else
  2745. #ifdef LGS_REDUCED_PRF
  2746. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2747. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
  2748. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
  2749. #else
  2750. #ifdef __ALS_300 //(target.nAngle<<2)/5
  2751. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2752. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3, target.nWidth ) :
  2753. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3 );
  2754. #else
  2755. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2756. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
  2757. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
  2758. #endif
  2759. #endif
  2760. #endif
  2761. };
  2762. break;
  2763. case LGS::TT_FLIP:
  2764. nSendCount += LGS::BuildEvtState2Flip( pSendBufferPtr, i, target.nAngle );
  2765. break;
  2766. case LGS::TT_BLIND:
  2767. if( ( target.nAngle < LGS_BLIND_TYPE_FAR_FOG_ENTER ) && ( !g_bShowErrors || g_bHideFogError ) ) break;
  2768. switch( target.nAngle )
  2769. {
  2770. case LGS_BLIND_TYPE_MR_ENTER:
  2771. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_MEDIUM_RANGE );
  2772. break;
  2773. case LGS_BLIND_TYPE_MR_EXIT:
  2774. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_MEDIUM_RANGE );
  2775. break;
  2776. case LGS_BLIND_TYPE_180_DEGRESE_ENTER:
  2777. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_180_DEGREE );
  2778. break;
  2779. case LGS_BLIND_TYPE_180_DEGRESE_EXIT:
  2780. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_180_DEGREE );
  2781. break;
  2782. case LGS_BLIND_TYPE_FS_ENTER:
  2783. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FOG_SPIKES );
  2784. break;
  2785. case LGS_BLIND_TYPE_FS_EXIT:
  2786. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FOG_SPIKES );
  2787. break;
  2788. case LGS_BLIND_TYPE_PD_ENTER:
  2789. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_PD );
  2790. break;
  2791. case LGS_BLIND_TYPE_PD_EXIT:
  2792. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_PD );
  2793. break;
  2794. case LGS_BLIND_TYPE_FAR_FOG_ENTER:
  2795. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FAR_FOG );
  2796. break;
  2797. case LGS_BLIND_TYPE_FAR_FOG_EXIT:
  2798. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FAR_FOG );
  2799. break;
  2800. case LGS_BLIND_TYPE_NEAR_FOG_ENTER:
  2801. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_NEAR_FOG );
  2802. break;
  2803. case LGS_BLIND_TYPE_NEAR_FOG_EXIT:
  2804. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_NEAR_FOG );
  2805. break;
  2806. }
  2807. break;
  2808. // case LGS::TT_CAMERA:
  2809. // break;
  2810. // case LGS::TT_TEST:
  2811. // break;
  2812. }
  2813. if( nSendCount >= 20 )
  2814. break;
  2815. }
  2816. #ifndef LGS_PLS_1
  2817. if( nSendCount >= 20 ) break;
  2818. #endif
  2819. }
  2820. }
  2821. void CKernel::OnCmdGetWidthTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2822. {
  2823. // unused variables
  2824. pReadBufferPtr; nReadCount;
  2825. // build CMD_GET_WIDHT_TABLE command
  2826. *pSendBufferPtr++ = LGS::CMD_GET_WIDTH_TABLE;
  2827. PLONG pNativeTable = m_Detector[0].GetFilterWidth()->GetTable();
  2828. // prepare table
  2829. LGS::WIDTH_TABLE table;
  2830. table.nCount = LGS::WIDTH_TABLE_SIZE;
  2831. for( int16_t i = 0; i < LGS::WIDTH_TABLE_SIZE; i++ )
  2832. table.pTable[i] = ( pNativeTable[i] * 100L ) >> 7;
  2833. // write command
  2834. nSendCount += LGS::BuildEvtGetWidthTable( pSendBufferPtr, &table );
  2835. }
  2836. void CKernel::OnCmdSetWidthTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2837. {
  2838. // build CMD_SET_WIDHT_TABLE command
  2839. *pSendBufferPtr++ = LGS::CMD_SET_WIDTH_TABLE;
  2840. // read table
  2841. LGS::WIDTH_TABLE table;
  2842. nReadCount -= LGS::GetCmdSetWidthTable( pReadBufferPtr, &table );
  2843. FILE *pFile = fopen( "width.ini", "wt" );
  2844. if( pFile )
  2845. {
  2846. for( int16_t i = 0; i < table.nCount; i++ )
  2847. fprintf( pFile, "%d ", table.pTable[i] );
  2848. fclose( pFile );
  2849. }
  2850. // write command
  2851. nSendCount += LGS::BuildEvtSetWidthTable( pSendBufferPtr, &table );
  2852. // restart program
  2853. m_bRun = false;
  2854. }
  2855. void CKernel::OnCmdGetZoomTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2856. {
  2857. // unused variables
  2858. pReadBufferPtr; nReadCount;
  2859. // build CMD_GET_WIDHT_TABLE command
  2860. *pSendBufferPtr++ = LGS::CMD_GET_ZOOM_TABLE;
  2861. #ifndef NO_EMBED_CAMERA
  2862. // write command
  2863. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  2864. #else
  2865. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
  2866. #endif
  2867. }
  2868. void CKernel::OnCmdSetZoomTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2869. {
  2870. // build CMD_SET_WIDHT_TABLE command
  2871. *pSendBufferPtr++ = LGS::CMD_SET_ZOOM_TABLE;
  2872. #ifndef NO_EMBED_CAMERA
  2873. // read table
  2874. nReadCount -= LGS::GetZoomTable( pReadBufferPtr, &m_pCamera->GetZoomTable() );
  2875. // write command
  2876. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  2877. #else
  2878. // write command
  2879. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
  2880. #endif
  2881. }
  2882. void CKernel::OnCmdGetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2883. {
  2884. // unused variables
  2885. pReadBufferPtr; nReadCount;
  2886. // build CMD_GET_WIDHT_TABLE command
  2887. *pSendBufferPtr++ = LGS::CMD_GET_TILT_TABLE;
  2888. #ifndef NO_EMBED_CAMERA
  2889. // write command
  2890. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  2891. #else
  2892. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
  2893. #endif
  2894. }
  2895. void CKernel::OnCmdSetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2896. {
  2897. // build CMD_SET_WIDHT_TABLE command
  2898. *pSendBufferPtr++ = LGS::CMD_SET_TILT_TABLE;
  2899. #ifndef NO_EMBED_CAMERA
  2900. // read table
  2901. nReadCount -= LGS::GetTiltTable( pReadBufferPtr, &m_pCamera->GetTiltTable() );
  2902. // write command
  2903. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  2904. #else
  2905. // write command
  2906. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
  2907. #endif
  2908. }
  2909. void CKernel::OnCmdGetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2910. {
  2911. // read table
  2912. uint8_t nDevice = *pReadBufferPtr++;
  2913. nReadCount --;
  2914. // build CMD_GET_LINEARIZATION_TABLE command
  2915. *pSendBufferPtr++ = LGS::CMD_GET_CALIBRATION_TABLE;
  2916. *pSendBufferPtr++ = nDevice;
  2917. nSendCount++;
  2918. #ifndef RANGE_16BIT
  2919. // process command
  2920. m_Calibrator[nDevice?1:0].OnCmdGetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  2921. #endif // 16 bit
  2922. }
  2923. bool CKernel::OnCmdSetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount, int16_t& nDevice )
  2924. {
  2925. // read table
  2926. nDevice = *pReadBufferPtr++;
  2927. nReadCount --;
  2928. // build CMD_SET_LINEARIZATION_TABLE command
  2929. *pSendBufferPtr++ = LGS::CMD_SET_CALIBRATION_TABLE;
  2930. *pSendBufferPtr++ = nDevice;
  2931. nSendCount++;
  2932. #ifndef RANGE_16BIT
  2933. // process command
  2934. return m_Calibrator[nDevice?1:0].OnCmdSetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  2935. #endif // 16 bit
  2936. }
  2937. void CKernel::OnCmdGetLrfDisable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2938. {
  2939. // unused variables
  2940. pReadBufferPtr; nReadCount;
  2941. // build CMD_GET_LRF_DISABLE command
  2942. *pSendBufferPtr++ = LGS::CMD_GET_LRF_DISABLE;
  2943. // write command
  2944. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  2945. }
  2946. void CKernel::OnCmdSetLrfDisable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2947. {
  2948. // read table
  2949. nReadCount -= LGS::GetLRFDisable( pReadBufferPtr, &m_LRFDisable );
  2950. #ifndef NO_EMBED_CAMERA
  2951. // store serial number
  2952. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  2953. #else
  2954. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  2955. #endif
  2956. // build CMD_SET_LRF_DISABLE command
  2957. *pSendBufferPtr++ = LGS::CMD_SET_LRF_DISABLE;
  2958. // write command
  2959. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  2960. // restart program
  2961. m_bRun = false;
  2962. }
  2963. typedef enum SETTING_TYPE
  2964. {
  2965. ST_NONE = -1,
  2966. ST_SN = 0,
  2967. ST_ADDRESS,
  2968. ST_CAMERA_TYPE,
  2969. ST_CAMERA_SHIFT,
  2970. ST_CAMERA_AUTO,
  2971. ST_CAMERA_DELAY,
  2972. ST_RELAY_NC,
  2973. ST_RELAY_AUTO,
  2974. ST_RELAY_DELAY,
  2975. ST_VOLTAGE_CONTROL,
  2976. ST_MASTER_DISABLED,
  2977. ST_SLAVE_DISABLED,
  2978. ST_AUTORESET_ENABLE,
  2979. ST_AUTORESET_INTERLEAVE,
  2980. ST_AUTORESET_TIMEOUT,
  2981. ST_BOARD_TEMPERATURE,
  2982. ST_BOARD_ZEROSHIFT,
  2983. ST_BOARD_ENCODERSTEPS,
  2984. ST_BOARD_GEARRATIO,
  2985. ST_BOARD_MAXRANGE,
  2986. ST_BOARD_SPEED,
  2987. ST_BOARD_HID,
  2988. ST_SWITCHER_TABLE,
  2989. ST_SWITCHER_REPLY_TIMEOUT,
  2990. ST_SWITCHER_COMMAND_TIMEOUT,
  2991. ST_SWITCHER_AUTO_MODE,
  2992. ST_SWITCHER_AUTO_ENTER_TIMEOUT,
  2993. ST_SWITCHER_AUTO_SWITCH_TIMEOUT,
  2994. ST_NO_BLACK_TARGET_DETECTION,
  2995. ST_JUST_MOVING_TARGETS_DETECTION,
  2996. ST_JUST_MOVING_RADIAL_PARAM,
  2997. ST_JUST_MOVING_DISTANCE_PARAM,
  2998. ST_BLIND_ST_ANGLE,
  2999. ST_BLIND_ED_ANGLE,
  3000. ST_BLIND_ST_RANGE,
  3001. ST_BLIND_ED_RANGE,
  3002. ST_BLIND_WIDTH,
  3003. ST_BLIND_DEPTH,
  3004. ST_BLIND_ANGLE,
  3005. ST_BLIND_RANGE
  3006. #ifdef STORE_FIRST_SAF
  3007. ,ST_FREEZ_FIRST_SAF
  3008. ,ST_SAF_FILE_ENABLE
  3009. #endif
  3010. }SETTING_TYPE;
  3011. LPCTSTR m_pSetting[] =
  3012. {
  3013. { "SN" },
  3014. { "ADDRESS" },
  3015. { "CAMERA_TYPE" },
  3016. { "CAMERA_SHIFT" },
  3017. { "CAMERA_AUTO" },
  3018. { "CAMERA_DELAY" },
  3019. { "RELAY_NC" },
  3020. { "RELAY_AUTO" },
  3021. { "RELAY_DELAY" },
  3022. { "VOLTAGE_CONTROL" },
  3023. { "MASTER_DISABLED" },
  3024. { "SLAVE_DISABLED" },
  3025. { "AUTORESET_ENABLE" },
  3026. { "AUTORESET_INTERLEAVE" },
  3027. { "AUTORESET_TIMEOUT" },
  3028. { "BOARD_TEMPERATURE" },
  3029. { "BOARD_ZEROSHIFT" },
  3030. { "BOARD_ENCODERSTEPS" },
  3031. { "BOARD_GEARRATIO" },
  3032. { "BOARD_MAXRANGE" },
  3033. { "BOARD_SPEED" },
  3034. { "RUN_DIR" },
  3035. { "SWITCHER_TABLE" },
  3036. { "SWITCHER_REPLY_TIMEOUT" },
  3037. { "SWITCHER_COMMAND_TIMEOUT" },
  3038. { "SWITCHER_AUTO_MODE" },
  3039. { "SWITCHER_AUTO_ENTER_TIMEOUT" },
  3040. { "SWITCHER_AUTO_SWITCH_TIMEOUT" },
  3041. { "NO_BLACK_TARGETS" },
  3042. { "JUST_MOVING_TARGETS" },
  3043. { "JUST_MOVING_RADIAL" },
  3044. { "JUST_MOVING_DISTANCE" },
  3045. { "BLIND_ZONE_START_ANGLE" },
  3046. { "BLIND_ZONE_END_ANGLE" },
  3047. { "BLIND_ZONE_START_RANGE" },
  3048. { "BLIND_ZONE_END_RANGE" },
  3049. { "BLIND_ZONE_WIDTH" },
  3050. { "BLIND_ZONE_DEPTH" },
  3051. { "BLIND_ZONE_ANGLE" },
  3052. { "BLIND_ZONE_RANGE" }
  3053. #ifdef STORE_FIRST_SAF
  3054. ,{ "FREEZ_FIRST_TH" }
  3055. ,( "SAVE_FIRST_TH" )
  3056. #endif
  3057. };
  3058. bool CKernel::LoadSettings( LPTSTR pSerialNumber, PBYTE pSerialNumberSize, PBYTE pAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable ){
  3059. // read serial number
  3060. FILE *pFile = fopen( "SN.INI", "rt" );
  3061. if( !pFile )
  3062. {
  3063. // fill with default sn
  3064. *pSerialNumberSize = 14;
  3065. memcpy( pSerialNumber, "NOSERIALNUMBER", *pSerialNumberSize );
  3066. return false;
  3067. }
  3068. CHAR pLine[MAX_PATH];
  3069. while( fgets( pLine, MAX_PATH, pFile ) )
  3070. {
  3071. SETTING_TYPE eType = ST_NONE;
  3072. PCHAR pTemp = NULL;
  3073. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
  3074. {
  3075. pTemp = strstr( pLine, m_pSetting[i] );
  3076. if( pTemp )
  3077. {
  3078. eType = (SETTING_TYPE)i;
  3079. pTemp = strstr( pTemp, "=" );
  3080. if( pTemp )
  3081. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3082. break;
  3083. }
  3084. }
  3085. if( eType == ST_NONE || !pTemp )
  3086. continue;
  3087. switch( eType )
  3088. {
  3089. case ST_SN: *pSerialNumberSize = strlen( pTemp ); memcpy( pSerialNumber, pTemp, *pSerialNumberSize ); break;
  3090. case ST_ADDRESS: *pAddress = atoi( pTemp ); break;
  3091. #ifndef NO_EMBED_CAMERA
  3092. case ST_CAMERA_TYPE: pCameraParameters->eType = (LGS::E_CAMERA_TYPE)atoi( pTemp ); break;
  3093. case ST_CAMERA_SHIFT: pCameraParameters->nShift = (uint16_t)atoi( pTemp ); break;
  3094. case ST_CAMERA_AUTO: pCameraParameters->bAuto = (bool)atoi( pTemp ); break;
  3095. case ST_CAMERA_DELAY: pCameraParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
  3096. #endif
  3097. case ST_RELAY_NC: pRelayParameters->bNormallyClose = (uint16_t)atoi( pTemp ); break;
  3098. case ST_RELAY_AUTO: pRelayParameters->bAuto = (bool)atoi( pTemp ); break;
  3099. case ST_RELAY_DELAY: pRelayParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
  3100. case ST_VOLTAGE_CONTROL: pVoltageParameters->bControl = (bool)atoi( pTemp ); break;
  3101. case ST_MASTER_DISABLED: if( pLRFDisable ) pLRFDisable->bMaster = (bool)atoi( pTemp ); break;
  3102. #ifndef LGS_PLS_1
  3103. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (bool)atoi( pTemp ); break;
  3104. #else
  3105. #ifdef INFINITE_SAF_STUDY
  3106. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (bool)atoi( pTemp ); break;
  3107. #else
  3108. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = true; break;
  3109. #endif
  3110. #endif
  3111. case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (bool)atoi( pTemp ); break;
  3112. case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
  3113. case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
  3114. case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
  3115. case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = atoi( pTemp ); break;
  3116. case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = atoi( pTemp ); break;
  3117. case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = atoi( pTemp ); break;
  3118. case ST_BLIND_ED_RANGE:m_nBZERangeFilter = atoi( pTemp ); break;
  3119. #ifdef STORE_FIRST_SAF
  3120. case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = atoi( pTemp ); break;
  3121. case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = atoi( pTemp ); break;
  3122. #endif
  3123. }
  3124. }
  3125. fclose( pFile );
  3126. return true;
  3127. }
  3128. bool CKernel::SaveSettings( LPCTSTR pSerialNumber, int16_t nAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable ){
  3129. FILE *pFile = fopen( "SN.INI", "wt" );
  3130. if( !pFile )
  3131. return false;
  3132. LPCTSTR pFormatStr = "%s = %s\n";
  3133. LPCTSTR pFormatInt = "%s = %d\n";
  3134. fprintf( pFile, pFormatStr, m_pSetting[ST_SN], pSerialNumber );
  3135. fprintf( pFile, pFormatInt, m_pSetting[ST_ADDRESS], nAddress );
  3136. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_TYPE], pCameraParameters->eType );
  3137. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_SHIFT], pCameraParameters->nShift );
  3138. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_AUTO], pCameraParameters->bAuto );
  3139. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_DELAY], pCameraParameters->nAutoDelay );
  3140. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_AUTO], pRelayParameters->bAuto );
  3141. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_DELAY], pRelayParameters->nAutoDelay );
  3142. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_NC], pRelayParameters->bNormallyClose );
  3143. fprintf( pFile, pFormatInt, m_pSetting[ST_VOLTAGE_CONTROL], pVoltageParameters->bControl );
  3144. if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_MASTER_DISABLED], pLRFDisable->bMaster );
  3145. #ifndef LFS_PLS_1
  3146. if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], pLRFDisable->bSlave );
  3147. #else
  3148. fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], true );
  3149. #endif
  3150. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3151. if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
  3152. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
  3153. } else {
  3154. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
  3155. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
  3156. };
  3157. #ifdef STORE_FIRST_SAF
  3158. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3159. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3160. #endif
  3161. fclose( pFile );
  3162. return true;
  3163. }
  3164. bool CKernel::LoadUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3165. int16_t tWidth = 0;
  3166. int16_t tDepth = 0;
  3167. int16_t tAngle = 0;
  3168. int16_t tRange = 0;
  3169. pSwitcher->pTable[0] = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4;
  3170. pSwitcher->pTable[1] = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4;
  3171. pSwitcher->pTable[2] = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4;
  3172. pSwitcher->nReplyTimeout = 100L;
  3173. pSwitcher->nCommandTimeout = 500L;
  3174. pSwitcher->nAutoMode = 0;
  3175. pSwitcher->nAutoEnterTimeout = 60;
  3176. pSwitcher->nAutoSwitchTimeout = 3;
  3177. pAutoReset->bEnabled = false;
  3178. pAutoReset->dwInterleave = 2000UL;
  3179. pAutoReset->dwTimeout = 60000UL;
  3180. pBoard->nZeroShift = 0;
  3181. pBoard->nTemperature = 1;
  3182. pBoard->nEncoderSteps = 6;
  3183. pBoard->nGearRatio = 61;
  3184. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3185. // Stepping Motor Speed
  3186. // 4280 = 8sps
  3187. // 2140 = 4sps
  3188. // 1070 = 2sps
  3189. // 535 = 1sps
  3190. pBoard->nMotorSpeed = 4;//535;
  3191. #endif
  3192. // pBoard->nMaxRange = 2048;
  3193. m_nMovingRadialFilter = 0;
  3194. m_nMovingDistanceFilter = 0;
  3195. m_nBZSAngleFilter = 0;
  3196. m_nBZEAngleFilter = 0;
  3197. m_nBZSRangeFilter = 0;
  3198. m_nBZERangeFilter = 0;
  3199. // read serial number
  3200. #ifdef LGS_MIRROR
  3201. #if defined( LGS_STEPPER ) || defined( LGS_FOD )
  3202. #ifdef LGS_FOD
  3203. FILE *pFile = fopen( "FOD.INI", "rt" ); // FOD
  3204. #else
  3205. FILE *pFile = fopen( "LFSS.INI", "rt" ); // LFSS
  3206. #endif
  3207. #else
  3208. #ifdef LGS_MND
  3209. FILE *pFile = fopen( "MND.INI", "rt" ); // MND
  3210. #else
  3211. FILE *pFile = fopen( "USER.INI", "rt" ); // LFS
  3212. #endif
  3213. #endif
  3214. #else
  3215. #ifdef LGS_PLS_1
  3216. FILE *pFile = fopen( "PLS.INI", "rt" ); // PLS
  3217. #else
  3218. FILE *pFile = fopen( "USER.INI", "rt" ); // ALS
  3219. #endif
  3220. #endif
  3221. if( !pFile )
  3222. return false;
  3223. CHAR pLine[MAX_PATH];
  3224. while( fgets( pLine, MAX_PATH, pFile ) )
  3225. {
  3226. SETTING_TYPE eType = ST_NONE;
  3227. PCHAR pTemp = NULL;
  3228. //printf( "%s", pLine );
  3229. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
  3230. {
  3231. pTemp = strstr( pLine, m_pSetting[i] );
  3232. if( pTemp )
  3233. {
  3234. eType = (SETTING_TYPE)i;
  3235. pTemp = strstr( pTemp, "=" );
  3236. if( pTemp )
  3237. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3238. break;
  3239. }
  3240. }
  3241. if( eType == ST_NONE || !pTemp )
  3242. continue;
  3243. switch( eType )
  3244. {
  3245. case ST_AUTORESET_ENABLE: pAutoReset->bEnabled = (bool)atoi( pTemp ); break;
  3246. case ST_AUTORESET_INTERLEAVE: pAutoReset->dwInterleave = atol( pTemp ); break;
  3247. case ST_AUTORESET_TIMEOUT: pAutoReset->dwTimeout = atol( pTemp ); break;
  3248. case ST_BOARD_TEMPERATURE: pBoard->nTemperature = atoi( pTemp ); break;
  3249. case ST_BOARD_ZEROSHIFT: pBoard->nZeroShift = atoi( pTemp ); break;
  3250. case ST_BOARD_ENCODERSTEPS: pBoard->nEncoderSteps = atoi( pTemp ); break;
  3251. case ST_BOARD_GEARRATIO: pBoard->nGearRatio = atoi( pTemp ); break;
  3252. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3253. case ST_BOARD_SPEED: pBoard->nMotorSpeed = atoi( pTemp ); break;
  3254. #endif
  3255. // case ST_BOARD_MAXRANGE: pBoard->nMaxRange = atoi( pTemp ); break;
  3256. case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (bool)atoi( pTemp ); break;
  3257. #ifdef STORE_FIRST_SAF
  3258. case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = atoi( pTemp ); break;
  3259. case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = atoi( pTemp ); break;
  3260. #endif
  3261. case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
  3262. case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
  3263. case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
  3264. case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = atoi( pTemp ); break;
  3265. case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = atoi( pTemp ); break;
  3266. case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = atoi( pTemp ); break;
  3267. case ST_BLIND_ED_RANGE:m_nBZERangeFilter = atoi( pTemp ); break;
  3268. case ST_BLIND_WIDTH:tWidth = atoi( pTemp ); break;
  3269. case ST_BLIND_DEPTH:tDepth = atoi( pTemp ); break;
  3270. case ST_BLIND_ANGLE:tAngle = atoi( pTemp ); break;
  3271. case ST_BLIND_RANGE:tRange = atoi( pTemp ); break;
  3272. #ifdef LGS_MIRROR
  3273. case ST_SWITCHER_TABLE: sscanf( pTemp, "%d,%d,%d", pSwitcher->pTable + 0, pSwitcher->pTable + 1, pSwitcher->pTable + 2 );
  3274. case ST_SWITCHER_REPLY_TIMEOUT: pSwitcher->nReplyTimeout = atol( pTemp ); break;
  3275. case ST_SWITCHER_COMMAND_TIMEOUT: pSwitcher->nCommandTimeout = atol( pTemp ); break;
  3276. case ST_SWITCHER_AUTO_MODE: pSwitcher->nAutoMode = atoi( pTemp ); break;
  3277. case ST_SWITCHER_AUTO_ENTER_TIMEOUT: pSwitcher->nAutoEnterTimeout = atoi( pTemp ); break;
  3278. case ST_SWITCHER_AUTO_SWITCH_TIMEOUT: pSwitcher->nAutoSwitchTimeout = atoi( pTemp ); break;
  3279. #endif
  3280. }
  3281. }
  3282. #if defined( LGS_REDUCED_PRF )
  3283. if( pBoard->nMotorSpeed < 1 ) pBoard->nMotorSpeed = 1;
  3284. if( pBoard->nMotorSpeed == 3 ) pBoard->nMotorSpeed = 2;
  3285. #if defined( LGS_STEPPER ) || defined( LGS_MND )
  3286. if( pBoard->nMotorSpeed > 4 ) pBoard->nMotorSpeed = 4;
  3287. #else
  3288. if( pBoard->nMotorSpeed == 5 ) pBoard->nMotorSpeed = 4;
  3289. if( pBoard->nMotorSpeed == 7 ) pBoard->nMotorSpeed = 6;
  3290. if( pBoard->nMotorSpeed == 9 ) pBoard->nMotorSpeed = 8;
  3291. if( pBoard->nMotorSpeed == 10 ) pBoard->nMotorSpeed = 8;
  3292. if( pBoard->nMotorSpeed == 11 ) pBoard->nMotorSpeed = 12;
  3293. if( pBoard->nMotorSpeed > 12 ) pBoard->nMotorSpeed = 12;
  3294. #endif
  3295. #if defined( LGS_MND )
  3296. LGS_PRF_REDUCE_RATIO = 1;
  3297. #else
  3298. if( pBoard->nMotorSpeed > 2 ){
  3299. LGS_PRF_REDUCE_RATIO = pBoard->nMotorSpeed >> 1;
  3300. } else {
  3301. LGS_PRF_REDUCE_RATIO = 1;
  3302. };
  3303. #endif
  3304. #endif
  3305. if( tWidth && tDepth ){
  3306. m_nBZSAngleFilter = tAngle - tWidth/2;
  3307. m_nBZEAngleFilter = ( tAngle + tWidth/2 ) % LGS_MAX_DETECTOR_ANGLES;
  3308. m_nBZSRangeFilter = tRange - tDepth/2;
  3309. m_nBZERangeFilter = tRange + tDepth/2;
  3310. };
  3311. fclose( pFile );
  3312. return true;
  3313. };
  3314. bool CKernel::SaveUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3315. #ifdef LGS_MIRROR
  3316. #if defined( LGS_STEPPER ) || defined( LGS_FOD )
  3317. #ifdef LGS_FOD
  3318. FILE *pFile = fopen( "FOD.INI", "wt" ); // FOD
  3319. #else
  3320. FILE *pFile = fopen( "LFSS.INI", "wt" ); // LFSS
  3321. #endif
  3322. #else
  3323. #ifdef LGS_MND
  3324. FILE *pFile = fopen( "MND.INI", "wt" ); // MND
  3325. #else
  3326. FILE *pFile = fopen( "USER.INI", "wt" ); // LFS
  3327. #endif
  3328. #endif
  3329. #else
  3330. #ifdef LGS_PLS_1
  3331. FILE *pFile = fopen( "PLS.INI", "wt" ); // PLS
  3332. #else
  3333. FILE *pFile = fopen( "USER.INI", "wt" ); // ALS
  3334. #endif
  3335. #endif
  3336. if( !pFile )
  3337. return false;
  3338. LPCTSTR pFormatInt = "%s=%d\n";
  3339. LPCTSTR pFormatDWORD = "%s=%lu\n";
  3340. LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
  3341. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
  3342. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
  3343. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
  3344. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
  3345. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
  3346. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
  3347. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
  3348. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3349. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
  3350. #endif
  3351. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3352. if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
  3353. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
  3354. } else {
  3355. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
  3356. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
  3357. };
  3358. if( m_nBZSAngleFilter != m_nBZEAngleFilter ){
  3359. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_ANGLE], m_nBZSAngleFilter );
  3360. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_ANGLE], m_nBZEAngleFilter );
  3361. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_RANGE], m_nBZSRangeFilter );
  3362. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_RANGE], m_nBZERangeFilter );
  3363. };
  3364. #ifdef LGS_MIRROR
  3365. fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
  3366. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
  3367. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
  3368. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
  3369. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
  3370. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
  3371. #endif
  3372. #ifdef STORE_FIRST_SAF
  3373. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3374. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3375. #endif
  3376. fclose( pFile );
  3377. return true;
  3378. }
  3379. bool CKernel::LoadFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3380. // read serial number
  3381. FILE *pFile = fopen( "PARAMS.INI", "rt" );
  3382. if( !pFile ) return false;
  3383. //printf("PARAMS.ini found reading params\n");
  3384. CHAR pLine[MAX_PATH];
  3385. while( fgets( pLine, MAX_PATH, pFile ) ){
  3386. SETTING_TYPE eType = ST_NONE;
  3387. PCHAR pTemp = NULL;
  3388. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ ){
  3389. pTemp = strstr( pLine, m_pSetting[i] );
  3390. if( pTemp )
  3391. {
  3392. eType = (SETTING_TYPE)i;
  3393. pTemp = strstr( pTemp, "=" );
  3394. if( pTemp )
  3395. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3396. break;
  3397. }
  3398. }
  3399. if( eType == ST_NONE || !pTemp ) continue;
  3400. switch( eType ){
  3401. case ST_BOARD_HID: pBoard->nHID = atoi( pTemp ); break;
  3402. }
  3403. }
  3404. fclose( pFile );
  3405. return true;
  3406. };
  3407. bool CKernel::SaveFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3408. FILE *pFile = fopen( "PARAMS.INI", "wt" );
  3409. if( !pFile )
  3410. return false;
  3411. LPCTSTR pFormatInt = "%s=%d\n";
  3412. LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
  3413. LPCTSTR pFormatDWORD = "%s=%lu\n";
  3414. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
  3415. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
  3416. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
  3417. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
  3418. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
  3419. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
  3420. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
  3421. #ifdef LGS_PLS_1
  3422. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
  3423. #endif
  3424. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_HID], (int16_t)pBoard->nHID );
  3425. fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
  3426. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
  3427. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
  3428. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
  3429. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
  3430. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
  3431. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3432. #ifdef STORE_FIRST_SAF
  3433. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3434. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3435. #endif
  3436. fclose( pFile );
  3437. return true;
  3438. }