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.

3744 lines
114 KiB

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