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.

3741 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright ?2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 17/11/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: KERNEL.CPP
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of KERNEL.CPP
  13. //----------------------------------------------------------------------------
  14. #include "StdAfx.h"
  15. #include <errno.h>
  16. #include <mem.h>
  17. #include <bios.h>
  18. #include <dos.h>
  19. #include <dir.h>
  20. #include <io.h>
  21. #include <conio.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "kernel.h"
  25. #include "..\lglib\comm\lgsm.h"
  26. #include "..\lglib\lgbitcod.h"
  27. //#include "..\lglib\version.h"
  28. #include "screen.h"
  29. #include "Camera.h"
  30. #include "CMigPTZ.h"
  31. #include "CMicPTZ.h"
  32. #include "CPG3AD.h"
  33. #include "CTKS576.h"
  34. #include "CVicon.h"
  35. #include "CPelco.h"
  36. #include "CFlir.h"
  37. #include "CHebron.h"
  38. /*!
  39. Flag to disable error repporting
  40. default: \b false
  41. */
  42. extern bool g_bShowErrors;
  43. /*!
  44. Flag to disable fog error repporting
  45. default: \b false
  46. */
  47. extern bool g_bHideFogError;
  48. /*!
  49. Flag to delay error repporting
  50. Skeeps error for first 3 times of arival
  51. default: \b true
  52. */
  53. extern bool g_bDelayErrors;
  54. /*!
  55. Flag to enable working
  56. default: \b false
  57. */
  58. //extern bool m_pBoard->workingEnabled();
  59. /*!
  60. Gets value of BIOS timer counter (1/18 of second)
  61. */
  62. //static DWORD far* g_Timer = (DWORD far*)0x46CL;
  63. //#ifdef INCLUDE_WINDOWS_DEFINITIONS
  64. // #define TIMER() *g_Timer
  65. //#else
  66. // #define TIMER() (GetTickCount() * 10 / 182)
  67. //#endif
  68. //#define TIMER() ( uclock() * 10 / 182 )
  69. /*!
  70. Buffer for Software Version Text Generation
  71. */
  72. CHAR CKernel::s_pSoftwareVersion[MAX_PATH] = "";
  73. /*!
  74. Software Version
  75. */
  76. int16_t CKernel::s_nSoftwareVersion = 0;
  77. // Hidding parameters up to 5 bytes (11 Nibbles)
  78. void CKernel::Reset( bool bFullReset ){
  79. #ifdef COMPILE_AS_GETFILE
  80. return;
  81. #endif
  82. struct ffblk bb;
  83. if( findfirst( "restart", &bb , 0 ) != -1 ) return;
  84. m_Detector[0].Reset( bFullReset );
  85. #if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
  86. m_Detector[1].Reset( bFullReset );
  87. #endif
  88. #if defined( LGS_MIRROR ) && !defined( LGS_MND )
  89. m_Detector[2].Reset( bFullReset );
  90. m_Detector[3].Reset( bFullReset );
  91. #endif
  92. m_GetFile.Reset();
  93. //if (g_UI_Debug){
  94. // if(bFullReset){
  95. // printf("\nSW reset issued [full reset]\n");
  96. // } else {
  97. // printf("\nSW reset issued [soft reset]\n");
  98. // };
  99. //};
  100. #ifdef DEBUG_GRAPH_SCREEN
  101. g_Screen.Clear();
  102. #endif
  103. // reset error timings
  104. memset( m_dwTimeErrorOverflowSST, 0, sizeof(m_dwTimeErrorOverflowSST)*4 );
  105. memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow)*4 );
  106. memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun)*4 );
  107. m_dwTimeErrorDelay_EA = 0UL;
  108. m_dwTimeErrorDelay_IQ = 0UL;
  109. m_dwTimePower = 0UL;
  110. // reset board
  111. if( bFullReset ){
  112. #ifdef _NO_RESTART_
  113. m_pBoard->Reset();
  114. #else
  115. FILE *fd;
  116. fd = fopen( "restart", "w+" );
  117. fprintf( fd, "\n" );
  118. fclose( fd );
  119. m_pBoard->EndService();
  120. m_bRun = false;
  121. #endif
  122. } else {
  123. m_pBoard->Reset();
  124. };
  125. m_Relay.Reset();
  126. // restart Zero Shift Checker
  127. m_bWaitFirstZero = true;
  128. m_nBeforeZeroCounter = 0;
  129. // Reset AutoReset
  130. m_AutoReset.Reset();
  131. m_nInitErrorSkipCounter = 20;
  132. }
  133. //SchedulerItem *ScheduleCC;
  134. void CKernel::OnISR(){
  135. #ifndef COMM_WITHOUT_INTERRUPTS
  136. stopTimerCC();
  137. unsigned char cFlag;
  138. cFlag = 0;
  139. if ( m_pComm485 != NULL ){
  140. if ( m_pComm485->m_bFollowControlTimer ){
  141. if ( !m_pComm485->ValidateRTS() ){
  142. cFlag++; //resetTimerCC();
  143. };// else {
  144. // setTimerCC( 0xffffffUL );
  145. //};
  146. };
  147. };
  148. #ifndef NO_EMBED_CAMERA
  149. if ( m_pCameraComm != NULL ){
  150. if ( m_pCameraComm->m_bFollowControlTimer ){
  151. if( !m_pCameraComm->ValidateRTS() ){
  152. cFlag++;//resetTimerCC();
  153. };// else {
  154. // setTimerCC( 0xffffffUL );
  155. //};
  156. };
  157. };
  158. #endif
  159. switch( cFlag ){
  160. case 0:{
  161. setTimerCC( 0xffffffUL );
  162. break;
  163. };
  164. case 1:
  165. case 2:{
  166. resetTimerCC();
  167. break;
  168. };
  169. };
  170. #endif
  171. }
  172. bool CKernel::Run(){
  173. struct ffblk bb;
  174. uint8_t *pBuffer;
  175. int16_t nCount;
  176. uint8_t nCameraAccessCounter = 0;
  177. uint8_t nMode = LGS::MODE_DETECTOR;
  178. bool bRestart = false;
  179. DWORD nBoardIrq = 0;
  180. DWORD nBoardTimer = TIMER();
  181. bool bBoardNoIrq = false;
  182. #ifndef COMPILE_AS_GETFILE
  183. bool bFastTimerValid = false;
  184. #endif
  185. #ifdef DEBUG_TARGET_SIMULATOR
  186. bFireSimulatedTarget = false;
  187. nSimulatedTargetID = 0;
  188. #endif
  189. bool bSetHzDataInProgress = false;
  190. bool bSetCalibrationTableInProgress = false;
  191. bool bPower, bZero, bSun[2];
  192. uint16_t nRange[2];
  193. bool SSTMode = false;
  194. m_nBeforeZeroCounter = 0;
  195. delay(1000);
  196. #ifdef COMPILE_AS_GETFILE
  197. DWORD dwStartTime = TIME_TO_MSEC( TIMER() );
  198. bool bGetFileRun = false;
  199. // send human readable information
  200. {
  201. CHAR pText[MAX_PATH];
  202. int16_t nText;
  203. ARESET_SETTINGS AutoReset;
  204. BOARD_SETTINGS BoardSettings;
  205. m_pBoard->getSettings( &BoardSettings );
  206. m_AutoReset.getSettings( &AutoReset );
  207. char *tTtTtT;
  208. switch( m_pBoard->getBoardType() ) {
  209. case BT_COREMODULE_4DXE: tTtTtT = _T("PC104_4DXE"); break;
  210. case BT_TRI_M: tTtTtT = _T("TRITRACK_M"); break;
  211. case BT_VORTEX_SX: tTtTtT = _T("VORTEX86SX"); break;
  212. case BT_VORTEX_DX: tTtTtT = _T("VORTEX86MX"); break;
  213. case BT_VORTEX_MX: tTtTtT = _T("VORTEX86DX"); break;
  214. default: tTtTtT = _T("UNKNOWN");
  215. };
  216. nText = sprintf( pText, "BOARD TYPE <%s>\r\n", tTtTtT );
  217. #ifdef DEBUG
  218. printf(pText);
  219. #endif
  220. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  221. nText = sprintf( pText, "SOFTWARE VERSION <%s>\r\n", s_pSoftwareVersion );
  222. #ifdef DEBUG
  223. printf(pText);
  224. #endif
  225. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  226. nText = sprintf( pText, "ADDRESS <%d>\r\n", m_nAddress );
  227. #ifdef DEBUG
  228. printf(pText);
  229. #endif
  230. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  231. nText = sprintf( pText, "SERIAL NUMBER <%s>\r\n", m_pSerialNumber );
  232. #ifdef DEBUG
  233. printf(pText);
  234. #endif
  235. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  236. nText = sprintf( pText, "AUTORESET_ENABLE <%d>\r\n", AutoReset.bEnabled );
  237. #ifdef DEBUG
  238. printf(pText);
  239. #endif
  240. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  241. nText = sprintf( pText, "AUTORESET_INTERLEAVE <%ld>\r\n", AutoReset.dwInterleave );
  242. #ifdef DEBUG
  243. printf(pText);
  244. #endif
  245. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  246. nText = sprintf( pText, "AUTORESET_TIMEOUT <%ld>\r\n", AutoReset.dwTimeout );
  247. #ifdef DEBUG
  248. printf(pText);
  249. #endif
  250. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  251. nText = sprintf( pText, "BOARD_TEMPERATURE <%d>\r\n", (int16_t)(CHAR)BoardSettings.nTemperature );
  252. #ifdef DEBUG
  253. printf(pText);
  254. #endif
  255. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  256. nText = sprintf( pText, "BOARD_ZEROSHIFT <%d>\r\n", BoardSettings.nZeroShift );
  257. #ifdef DEBUG
  258. printf(pText);
  259. #endif
  260. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  261. #ifdef LGS_PLS_1
  262. nText = sprintf( pText, "BOARD_SPEED <%d>\r\n", BoardSettings.nMotorSpeed );
  263. #ifdef DEBUG
  264. printf(pText);
  265. #endif
  266. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  267. #endif
  268. #ifdef LGS_MIRROR
  269. nText = sprintf( pText, "SWITCHER_TABLE <%d,%d,%d>\r\n", SwitcherSettings.pTable[0], SwitcherSettings.pTable[1], SwitcherSettings.pTable[2] );
  270. #ifdef DEBUG
  271. printf(pText);
  272. #endif
  273. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  274. #endif
  275. }
  276. #else // No Get File
  277. m_pBoard->Reset();// ??
  278. #endif
  279. m_pBoard->BeginService();
  280. // update settings
  281. //AUTO_RESET AutoReset;
  282. //BOARD_SETTINGS BoardSettings;
  283. //SWITCHER_SETTINGS SwitcherSettings;
  284. //LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings, m_pComm485, m_pCameraComm );
  285. //SaveUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings, m_pComm485, m_pCameraComm );
  286. m_nInitErrorSkipCounter = 20;
  287. m_bWaitFirstZero = true;
  288. g_dwStartupTime = ( DWORD ) time( NULL );
  289. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  290. if( g_bBoardReceiverMode ) DoSendBoardData( 0 );
  291. #endif
  292. nBoardTimer = TIME_TO_MSEC( TIMER() );
  293. while( m_bRun ){
  294. unsigned long cMilliseconds = TIME_TO_MSEC( TIMER() );
  295. //m_dwGlobalCycles++;
  296. #ifndef INCLUDE_WINDOWS_DEFINITIONS
  297. Sleep(0);
  298. #endif
  299. #ifdef WATCHDOG_ENABLED
  300. // update watchdog timer
  301. if( g_bWatchDogEnable ) m_WatchDog.Update( cMilliseconds );
  302. #endif
  303. #ifdef COMPILE_AS_GETFILE
  304. if( !bGetFileRun ){
  305. if( ( cMilliseconds - dwStartTime ) > LGS_GETFILE_WAIT_TIME ) m_bRun = false;
  306. } else {
  307. dwStartTime = cMilliseconds;
  308. };
  309. #else // !COMPILE_AS_GETFILE
  310. // clear zero flag
  311. #ifndef NO_EMBED_CAMERA
  312. bool bInvalidateCamera = false;
  313. #endif
  314. // check fast timer
  315. static DWORD dwSlowTime = 0;
  316. if( !bFastTimerValid ){
  317. if( cMilliseconds != dwSlowTime ){
  318. dwSlowTime = cMilliseconds << 1; // was 3
  319. #ifndef NO_EMBED_CAMERA
  320. bInvalidateCamera = true;
  321. #endif
  322. };
  323. }
  324. #ifndef NO_EMBED_CAMERA
  325. else bInvalidateCamera = true;
  326. #endif
  327. #endif
  328. // perform work depend on work mode
  329. switch( nMode ){
  330. case LGS::MODE_BORDER:
  331. case LGS::MODE_DETECTOR:
  332. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  333. if( m_nBoardNoRespoceCount < 1 ){
  334. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  335. printf("No Responce From Board!!\n");
  336. #endif
  337. m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
  338. // Restart Software
  339. #ifdef RESTART_PC_BY_WATCHDOG
  340. outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
  341. #ifdef WATCHDOG_ENABLED
  342. CWatchDog WatchDog;
  343. WatchDog.Create();
  344. while(1);
  345. #else
  346. delay( 3000 );
  347. //m_bRun = false;
  348. Reset( true );
  349. continue;
  350. #endif
  351. #else
  352. //m_bRun = false;
  353. Reset( true );
  354. continue;
  355. #endif
  356. };
  357. #endif
  358. //#ifndef COMPILE_AS_GETFILE
  359. #ifdef COMPILE_AS_GETFILE______
  360. k;qkw;ekq
  361. // check Serial Number
  362. if( !m_pBoard->workingEnabled() ){
  363. // Try ReInit Board
  364. //if( !m_pBoard->Create( NULL ) ){
  365. // outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
  366. //m_bRun = false;
  367. m_pBoard->Reset();
  368. Reset( true );
  369. //};
  370. #ifdef LGS_MIRROR
  371. m_Detector[ 0 ].Reset( true );
  372. #ifndef LGS_MND
  373. m_Detector[ 1 ].Reset( true );
  374. m_Detector[ 2 ].Reset( true );
  375. m_Detector[ 3 ].Reset( true );
  376. #endif
  377. m_Tracker[ 0 ].Reset();
  378. #else
  379. #ifdef LGS_PLS_1
  380. m_Detector[ 0 ].Reset( true );
  381. m_Tracker[ 0 ].Reset();
  382. #else
  383. m_Detector[ 0 ].Reset( true );
  384. m_Detector[ 1 ].Reset( true );
  385. m_Tracker[ 0 ].Reset();
  386. m_Tracker[ 1 ].Reset();
  387. #endif
  388. #endif
  389. m_bWaitFirstZero = true;
  390. m_nBeforeZeroCounter = 0;
  391. bBoardNoIrq = true;
  392. // fast timer is not valid
  393. bFastTimerValid = false;
  394. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  395. if( m_nBoardNoRespoceCount ){
  396. m_nBoardNoRespoceCount--;
  397. };
  398. #else
  399. Reset( true );
  400. #endif
  401. };
  402. #endif // GETFILE
  403. // check IRQ
  404. if( ( cMilliseconds - nBoardTimer ) > NO_IRQ_DETECTION_TIME ){
  405. if( !nBoardIrq ){
  406. #ifndef COMPILE_AS_GETFILE
  407. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  408. printf( "NO IRQ RESET\n" );
  409. #endif
  410. // New - Reboot
  411. //m_bRun = false;
  412. //continue;
  413. // reset board
  414. // fast timer is not valid
  415. bFastTimerValid = false;
  416. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  417. if( m_nBoardNoRespoceCount ) m_nBoardNoRespoceCount--;
  418. #else
  419. Reset( true );
  420. #endif
  421. #endif //GetFILE
  422. bBoardNoIrq = true;
  423. };
  424. nBoardTimer = cMilliseconds;
  425. nBoardIrq = 0;
  426. };
  427. if( m_pBoard->workingEnabled() ) {
  428. #ifdef COMPILE_AS_GETFILE
  429. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  430. m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
  431. #endif
  432. nBoardTimer = cMilliseconds;
  433. nBoardIrq++;
  434. #else
  435. // check board
  436. uint8_t RetVal;
  437. while ( (( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ) ){
  438. #ifdef WATCHDOG_ENABLED
  439. if( g_bWatchDogEnable ) m_WatchDog.Update( cMilliseconds );
  440. #endif
  441. if( RetVal == 2 ){
  442. #ifdef ALS_300__
  443. if( m_nBoardNoRespoceCount ){
  444. m_nBoardNoRespoceCount--;
  445. m_pBoard->AsyncReset();
  446. Reset( false );
  447. };
  448. #else
  449. Reset( true );
  450. #endif
  451. continue;
  452. };
  453. #ifdef BOARD_NO_RESPONCE_COUNT_INIT
  454. m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
  455. #endif
  456. nBoardTimer = cMilliseconds;
  457. nBoardIrq++;
  458. #ifndef RANGE_16BIT
  459. // perform linearization
  460. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  461. #ifdef LGS_MIRROR // Doublefication of LGS data for LFS
  462. #ifndef LGS_MND
  463. nRange[1] = nRange[0];
  464. //nRange[1] = m_Calibrator[0].Calibrate( nRange[0] );
  465. #endif
  466. #else
  467. #ifndef LGS_PLS_1
  468. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  469. #endif
  470. #endif
  471. #endif //16 bit
  472. // update voltage state
  473. m_Voltage.Invalidate( bPower );
  474. // fast timer is valid
  475. bFastTimerValid = true;
  476. #ifdef DEBUG_BOARD_SET_TEST_BIT
  477. m_pBoard->SetTestBit( true );
  478. #endif
  479. #ifdef LGS_MIRROR
  480. if( m_bWaitFirstZero && bZero ){
  481. m_Detector[ 0 ].ResetAngles();
  482. #ifndef LGS_MND
  483. m_Detector[ 1 ].ResetAngles();
  484. m_Detector[ 2 ].ResetAngles();
  485. m_Detector[ 3 ].ResetAngles();
  486. #endif
  487. m_Tracker[ 0 ].Reset();
  488. //m_nDetector = m_nAngle = 0;
  489. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  490. printf("Before Zero: %d ang. Zero Shift: %d ang.\n", m_nBeforeZeroCounter, m_pBoard->getZeroShift() );
  491. #endif
  492. //if( findfirst( "restart", &bb , 0 ) != -1 )
  493. unlink( "restart" );
  494. m_bWaitFirstZero = false;
  495. };
  496. if( !m_bWaitFirstZero ){ // Accepting Data
  497. if( bZero ){ // If Zero Angle
  498. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  499. printf( "Real Zero: %d D:%d\n", m_nAngle, m_nDetector );
  500. #endif
  501. m_nDetector = m_nAngle = 0;
  502. m_dwGlobalCycles = 0UL;
  503. #ifndef LGS_MND
  504. if( m_Detector[ 3 ].IsSSTPassed() ){
  505. SSTMode = true;
  506. } else {
  507. SSTMode = false;
  508. };
  509. #else
  510. SSTMode = false;
  511. #endif
  512. } else { // If Any Other Angle
  513. #ifndef LGS_MND
  514. #ifdef LGS_REDUCED_PRF
  515. m_nAngle += LGS_PRF_REDUCE_RATIO;
  516. m_dwGlobalCycles += LGS_PRF_REDUCE_RATIO;
  517. if( m_nAngle > ( LGS_MAX_DETECTOR_ANGLES - LGS_PRF_REDUCE_RATIO ) ){ // Change Detector (Mirror)
  518. #else
  519. m_nAngle ++;
  520. m_dwGlobalCycles ++;
  521. if( m_nAngle > ( LGS_MAX_DETECTOR_ANGLES - 1 ) ){ // Change Detector (Mirror)
  522. #endif
  523. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  524. printf( "Virtual Zero: %d D:%d ", m_nAngle, m_nDetector );
  525. #endif
  526. if( m_Detector[ m_nDetector ].IsSSTPassed() ) SSTMode = true;
  527. m_nDetector ++;
  528. if ( m_nDetector > 3 ) m_nDetector = 0;
  529. m_nAngle = 0;
  530. bZero = true;
  531. };
  532. #else
  533. #ifdef LGS_REDUCED_PRF
  534. m_nAngle += LGS_PRF_REDUCE_RATIO;
  535. m_dwGlobalCycles += LGS_PRF_REDUCE_RATIO;
  536. #else
  537. m_nAngle ++;
  538. m_dwGlobalCycles ++;
  539. #endif
  540. #endif
  541. };
  542. } else { // Board Zero Shift Counter
  543. #ifdef LGS_REDUCED_PRF
  544. m_nBeforeZeroCounter += LGS_PRF_REDUCE_RATIO;
  545. #else
  546. m_nBeforeZeroCounter++;
  547. #endif
  548. };
  549. #ifdef DEBUG_NO_TARGET_DELAYING
  550. SSTMode = false;
  551. #endif
  552. if( !m_bWaitFirstZero ){
  553. #ifdef LGS_REDUCED_PRF
  554. m_Tracker[ 0 ].Invalidate();
  555. for( int i = 0; i< LGS_PRF_REDUCE_RATIO; i++ ) {
  556. m_Detector[ m_nDetector ].Invalidate( bZero, bSun[0], nRange[0], true, SSTMode );
  557. if( bZero ) {
  558. bZero = false;
  559. };
  560. };
  561. #else
  562. m_Tracker[ 0 ].Invalidate();
  563. m_Detector[ m_nDetector ].Invalidate( bZero, bSun[0], nRange[0], true, SSTMode );
  564. #endif
  565. };
  566. #else // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  567. #if defined( LGS_PLS_1 ) // PLS
  568. if( m_bWaitFirstZero && bZero ) {
  569. m_bWaitFirstZero = false;
  570. m_Detector[ 0 ].ResetAngles();
  571. m_Tracker[ 0 ].Reset();
  572. //if( findfirst( "restart", &bb , 0 ) != -1 )
  573. unlink( "restart" );
  574. };
  575. if( !m_bWaitFirstZero ){
  576. m_Tracker[0].Invalidate();
  577. #ifdef LGS_REDUCED_PRF
  578. for( int i = 0; i< LGS_PRF_REDUCE_RATIO; i++ ){
  579. m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], true );
  580. bZero = 0;
  581. };
  582. #else
  583. m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], true );
  584. #endif
  585. } else { // Board Zero Shift Counter
  586. #ifdef LGS_REDUCED_PRF
  587. m_nBeforeZeroCounter += LGS_PRF_REDUCE_RATIO;
  588. #else
  589. m_nBeforeZeroCounter++;
  590. #endif
  591. };
  592. #else // ALS
  593. if( m_bWaitFirstZero && bZero ) {
  594. /*if( ( m_nBeforeZeroCounter >0 ) && ( m_nBeforeZeroCounter != m_pBoard->getZeroShift() ) ){ //Check if Zero Shift is Valid
  595. m_pBoard->AsyncReset();
  596. m_nBeforeZeroCounter = 0;
  597. } else {
  598. m_bWaitFirstZero = false;
  599. };*/
  600. #ifdef DEBUG
  601. printf("First Zero Reached!\n");
  602. #endif
  603. m_bWaitFirstZero = false;
  604. m_Detector[ 0 ].ResetAngles();
  605. m_Tracker[ 0 ].Reset();
  606. m_Detector[ 1 ].ResetAngles();
  607. m_Tracker[ 1 ].Reset();
  608. #ifdef ALS_300
  609. m_nSkeepCounter=0;
  610. #endif
  611. if( findfirst( "restart", &bb , 0 ) != -1 ) unlink( "restart" );
  612. };
  613. if( !m_bWaitFirstZero ){
  614. m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], m_Detector[1].IsAllowFlip(), false );
  615. } else { // Board Zero Shift Counter
  616. m_nBeforeZeroCounter++;
  617. };
  618. #ifdef ALS_300
  619. //if( m_nSkeepCounter == 0 )
  620. #endif
  621. m_Tracker[0].Invalidate();
  622. if( !m_bWaitFirstZero ){
  623. m_Detector[1].Invalidate( bZero, bSun[1], nRange[1], m_Detector[0].IsAllowFlip(), false );
  624. };
  625. #ifdef ALS_300
  626. //if( m_nSkeepCounter == 0 )
  627. #endif
  628. m_Tracker[1].Invalidate();
  629. #ifdef ALS_300
  630. m_nSkeepCounter++;
  631. if( m_nSkeepCounter == LGS_BOARDSAMPLE_RATIO ) m_nSkeepCounter = 0;
  632. #endif
  633. #endif // ALS-PLS
  634. #endif // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  635. #ifndef NO_EMBED_CAMERA
  636. bInvalidateCamera = true;
  637. #endif
  638. if( m_pBoard->getBoardWM()!= WM_DMA_WORK ) break;// From While
  639. };// Get Data While
  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. //m_bRun = false;
  738. Reset( true );
  739. #endif
  740. };
  741. // check for new commands from host
  742. if( m_Protocol.Read( &pBuffer, &nCount, 0, false ) ){
  743. // check address
  744. uint8_t bAddress = 0;
  745. if( nCount && ( (m_nAddress == *pBuffer) || (LGS_EXCLUSIVE_ADDRESS == *pBuffer) ) )
  746. {
  747. // store address
  748. bAddress = *pBuffer;
  749. // update pointers
  750. nCount--;
  751. pBuffer++;
  752. // check remainig count
  753. if( nCount )
  754. {
  755. uint8_t pSendBuffer[1024];
  756. PBYTE pSendBufferPtr = pSendBuffer;
  757. int16_t nSendCount = 2;
  758. // set address
  759. *pSendBufferPtr++ = bAddress;
  760. uint8_t bHostCommand = *pBuffer++;
  761. // Restart if set hz data was not finished correctly
  762. if( ( bSetHzDataInProgress && bHostCommand != LGS::CMD_SET_HZ_DATA ) ||
  763. ( bSetCalibrationTableInProgress && bHostCommand != LGS::CMD_SET_CALIBRATION_TABLE ) )
  764. {
  765. bRestart = true;
  766. //m_bRun = false;
  767. Reset( true );
  768. }
  769. // get command from buffer
  770. switch( bHostCommand )
  771. {
  772. case LGS::CMD_CAMERA:
  773. // build CMD_MODE command
  774. *pSendBufferPtr++ = LGS::CMD_CAMERA;
  775. // process command
  776. #if !defined(EMBEDDED_CAMERA_DISABLE) && !defined(NO_EMBED_CAMERA)
  777. m_pCamera->OnProtocolLgsCameraCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
  778. #else
  779. LGS::CAMERA_DATA OutData;
  780. // lgs has no camera busy
  781. OutData.nCommand = LGS::CMD_CAMERA_ERROR;
  782. OutData.error.errID = LGS::CAMERA_ERROR_NO_CAMERA;
  783. nSendCount += LGS::BuildEvtCamera( pSendBufferPtr, &OutData );
  784. #endif
  785. // write command
  786. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  787. break;
  788. case LGS::CMD_RELAY:
  789. // build CMD_MODE command
  790. *pSendBufferPtr++ = LGS::CMD_RELAY;
  791. // process command
  792. m_Relay.OnProtocolLgsRelayCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
  793. // write command
  794. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  795. break;
  796. case LGS::CMD_MODE:
  797. {
  798. // get command parameters
  799. bool bSetMode = false;
  800. uint8_t nNewMode = nMode;
  801. LGS::GetMode( pBuffer, &bSetMode, &nNewMode );
  802. // build CMD_MODE command
  803. *pSendBufferPtr++ = LGS::CMD_MODE;
  804. nSendCount += LGS::BuildMode( pSendBufferPtr, false, nMode );
  805. // write command
  806. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  807. // if needs to switch mode
  808. if( bSetMode && nMode != nNewMode )
  809. {
  810. switch( nNewMode )
  811. {
  812. case LGS::MODE_GETFILE:
  813. #ifdef COMPILE_AS_GETFILE
  814. bGetFileRun = true;
  815. #endif
  816. break;
  817. case LGS::MODE_BORDER:
  818. case LGS::MODE_DETECTOR:
  819. case LGS::MODE_FILESYSTEM:
  820. case LGS::MODE_FILESYSTEM_EXT:
  821. m_Detector[0].BorderEnable( nNewMode == LGS::MODE_BORDER );
  822. #if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
  823. m_Detector[1].BorderEnable( nNewMode == LGS::MODE_BORDER );
  824. #endif
  825. #ifdef LGS_MIRROR
  826. #ifndef LGS_MND
  827. m_Detector[2].BorderEnable( nNewMode == LGS::MODE_BORDER );
  828. m_Detector[3].BorderEnable( nNewMode == LGS::MODE_BORDER );
  829. #endif
  830. #endif
  831. #ifdef COMPILE_AS_GETFILE
  832. bGetFileRun = false;
  833. dwStartTime = cMilliseconds;
  834. #endif
  835. break;
  836. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  837. case LGS::MODE_SENDBOARDDATA1:
  838. DoSendBoardData( 0 );
  839. Reset( true );
  840. //m_bRun = false;
  841. continue;
  842. break;
  843. case LGS::MODE_SENDBOARDDATA2:
  844. DoSendBoardData( 1 );
  845. Reset( true );
  846. //m_bRun = false;
  847. continue;
  848. break;
  849. case LGS::MODE_SENDBOARDDATA3:
  850. DoSendBoardData( 2 );
  851. Reset( true );
  852. //m_bRun = false;
  853. continue;
  854. break;
  855. case LGS::MODE_SENDBOARDDATA4:
  856. DoSendBoardData( 3 );
  857. Reset( true );
  858. //m_bRun = false;
  859. continue;
  860. break;
  861. #endif
  862. }
  863. // reset after switching mode
  864. if( nMode != LGS::MODE_BORDER && nMode != LGS::MODE_DETECTOR ) Reset( false );
  865. // store new mode
  866. nMode = nNewMode;
  867. // reset IRQ checking
  868. nBoardIrq = 0;
  869. nBoardTimer = cMilliseconds;
  870. }
  871. }
  872. break;
  873. case LGS::CMD_BORDER:
  874. {
  875. // get command parameters
  876. uint8_t bError;
  877. uint16_t nAngle, nRange0, nRange1;
  878. LGS::GetBorder( pBuffer, &bError, &nAngle, &nRange0, &nRange1 );
  879. // build CMD_BORDER command
  880. *pSendBufferPtr++ = LGS::CMD_BORDER;
  881. if( nMode != LGS::MODE_BORDER ){
  882. nSendCount += LGS::BuildBorder( pSendBufferPtr, LGS::BD_ERRORMODE, 0, 0, 0 );
  883. }else{
  884. #if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
  885. uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ||
  886. (!m_Detector[1].GetBorderRange( nAngle, &nRange1 )) ) ? LGS::BD_NOTREADY : 0;
  887. #else
  888. #ifdef INFINITE_SAF_STUDY
  889. uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0, true )) ||
  890. (!m_Detector[0].GetBorderRange( nAngle, &nRange1, false )) ) ? LGS::BD_NOTREADY : 0;
  891. #else
  892. uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ) ? LGS::BD_NOTREADY : 0;
  893. #endif
  894. #endif
  895. if( bError ){
  896. nSendCount += LGS::BuildBorder( pSendBufferPtr, bError, 0, 0, 0 );
  897. }else
  898. #ifdef RANGE_16BIT
  899. //nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, (uint16_t)ceil(((float)nRange0)/ 11.12f), (uint16_t)ceil(((float)nRange1)/ 11.12f) );
  900. {
  901. uint16_t nR0,nR1;
  902. //nRange0 = nAngle;
  903. //nR0 = (uint16_t)(((float)nRange0)/ 11.12 + 1 );
  904. nR0 = (uint16_t)(( 2048L * nRange0 )/ 22237 + 1 );
  905. nR1 = (uint16_t)(( 2048L * nRange1 )/ 22237 + 1 );
  906. nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nR0, nR1 );
  907. //nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0>>3, nRange1>>3 );
  908. };
  909. #else
  910. nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0 >> 1, nRange1 >> 1 );
  911. #endif
  912. }
  913. // write command
  914. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  915. }
  916. break;
  917. case LGS::CMD_STATE:
  918. {
  919. // build CMD_STATE command
  920. *pSendBufferPtr++ = LGS::CMD_STATE;
  921. if( nMode != LGS::MODE_DETECTOR ){
  922. nSendCount += LGS::BuildError( pSendBufferPtr, 0, LGS::ER_MODE, 0 );
  923. }else{
  924. #ifdef LGS_MIRROR
  925. #ifdef LGS_MND
  926. {
  927. int i = 0;
  928. #else
  929. for( int i = 0; i < 4; i++ ){
  930. #endif
  931. #else
  932. #ifndef LGS_PLS_1
  933. for( int i = 0; i < 2; i++ ){
  934. #else
  935. {
  936. int i = 0;
  937. #endif
  938. #endif
  939. CDetector *pDetector = &m_Detector[i];
  940. CTracker *pTracker = &m_Tracker[i];
  941. uint8_t bDevice = ( i % 2 ) ? LGS::ID_DEVICE1 : LGS::ID_DEVICE0;
  942. // assume that no errors
  943. uint8_t bErrorMask = LGS::ER_NONE;
  944. int16_t nErrorAngle = 0;
  945. // check for tracker overflow
  946. if( ( m_dwTimeErrorOverflow[i] < cMilliseconds ) && pTracker->GetLastErrorOverflow() )
  947. {
  948. m_dwTimeErrorOverflow[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
  949. bErrorMask |= LGS::ER_OVERFLOW;
  950. }
  951. // check for tracker scan to scan overflow
  952. if( ( m_dwTimeErrorOverflowSST[i] < cMilliseconds ) && pTracker->GetLastErrorOverflowSST() )
  953. {
  954. m_dwTimeErrorOverflowSST[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
  955. bErrorMask |= LGS::ER_SSTOVERFLOW;
  956. }
  957. // check for detector sun errors
  958. if( ( m_dwTimeErrorSun[i] < cMilliseconds ) && pDetector->GetLastErrorSun() )
  959. {
  960. m_dwTimeErrorSun[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
  961. bErrorMask |= LGS::ER_SUNBIT;
  962. }
  963. // check for detector angle errors
  964. if( pDetector->GetLastErrorAngle() )
  965. {
  966. nErrorAngle = pDetector->GetLastErrorAngleValue();
  967. if( ( nErrorAngle > 0 && nErrorAngle < LGS_REAL_DETECTOR_ANGLES - 5 ) || g_bDelayErrors == false ){
  968. bErrorMask |= LGS::ER_ANGLE;
  969. nErrorAngle = ( i + 1 ) * 10000 + nErrorAngle;
  970. };
  971. }
  972. // check for kernel error
  973. if( bBoardNoIrq )
  974. {
  975. bErrorMask |= LGS::ER_NOIRQ;
  976. bBoardNoIrq = false;
  977. }
  978. // if error exist
  979. if( bErrorMask ){
  980. nSendCount += LGS::BuildError( pSendBufferPtr, bDevice, bErrorMask, nErrorAngle );
  981. //if( g_UI_Debug ){
  982. // printf("Error Message Issued [%d]\n", bErrorMask );
  983. //};
  984. }
  985. // place target information
  986. CTracker::TARGET target;
  987. while( ( pTracker->GetTarget( &target ) && m_pBoard->workingEnabled()
  988. #ifdef DEBUG_TARGET_SIMULATOR
  989. ) || bFireSimulatedTarget
  990. #else
  991. )
  992. #endif
  993. ){
  994. #ifdef DEBUG_TARGET_SIMULATOR
  995. if( bFireSimulatedTarget ){
  996. target.bType = LGS::TT_NORMAL;
  997. target.nRange = 200;
  998. target.nAngle = ( 3000* nSimulatedTargetID )/360 ;
  999. target.nWidth = m_dwGlobalCycles;//nSimulatedTargetID;
  1000. bFireSimulatedTarget = false;
  1001. };
  1002. #endif
  1003. #ifdef LGS_MIRROR
  1004. #ifdef LGS_STEPPER
  1005. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1006. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, ( target.nAngle << 1 ) / LGS_PRF_REDUCE_RATIO, target.nRange, target.nWidth );
  1007. #else
  1008. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, ( target.nAngle << 1 ) / LGS_PRF_REDUCE_RATIO, target.nRange );
  1009. #endif
  1010. #else
  1011. #ifdef LGS_MND
  1012. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1013. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 2, target.nRange, target.nWidth << 2 );
  1014. #else
  1015. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 2, target.nRange );
  1016. #endif
  1017. #else
  1018. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1019. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange, target.nWidth );
  1020. #else
  1021. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange );
  1022. #endif
  1023. #endif
  1024. #endif
  1025. #else
  1026. #ifdef LGS_PLS_1
  1027. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1028. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_PRF_REDUCE_RATIO, target.nRange, target.nWidth );
  1029. #else
  1030. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_PRF_REDUCE_RATIO, target.nRange );
  1031. #endif
  1032. #else
  1033. #ifdef ALS_300_Z
  1034. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1035. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_BOARDSAMPLE_RATIO, target.nRange, target.nWidth );
  1036. #else
  1037. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_BOARDSAMPLE_RATIO, target.nRange );
  1038. #endif
  1039. #else
  1040. #ifdef RANGE_16BIT
  1041. uint16_t nR0;
  1042. nR0 = (uint16_t)(( 2048L * target.nRange )/ 22237 + 1 );
  1043. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1044. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, nR0, target.nWidth );
  1045. #else
  1046. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, nR0 );
  1047. #endif
  1048. #else
  1049. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  1050. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange, target.nWidth );
  1051. #else
  1052. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange );
  1053. #endif
  1054. #endif
  1055. #endif
  1056. #endif
  1057. #endif
  1058. if( nSendCount >= 20 )
  1059. break;
  1060. }
  1061. if( nSendCount >= 20 )
  1062. break;
  1063. }
  1064. }
  1065. #ifndef EMBEDDED_CAMERA_DISABLE
  1066. #ifndef NO_EMBED_CAMERA
  1067. // add camera tags
  1068. m_pCamera->OnProtocolLgsStateCommand( pSendBufferPtr, nSendCount );
  1069. #endif
  1070. #endif
  1071. // write command
  1072. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1073. }
  1074. break;
  1075. case LGS::CMD_STATE_2:
  1076. // prepare response
  1077. OnCmdState2( pBuffer, nCount, pSendBufferPtr, nSendCount, nMode, bBoardNoIrq );
  1078. // write command
  1079. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1080. break;
  1081. case LGS::CMD_GET_WIDTH_TABLE:
  1082. // prepare response
  1083. OnCmdGetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1084. // write command
  1085. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1086. break;
  1087. case LGS::CMD_SET_WIDTH_TABLE:
  1088. // prepare response
  1089. OnCmdSetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1090. // write command
  1091. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1092. break;
  1093. #ifndef NO_EMBED_CAMERA
  1094. case LGS::CMD_GET_ZOOM_TABLE:
  1095. // prepare response
  1096. OnCmdGetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1097. // write command
  1098. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1099. break;
  1100. case LGS::CMD_SET_ZOOM_TABLE:
  1101. // prepare response
  1102. OnCmdSetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1103. // write command
  1104. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1105. // update camera settings
  1106. m_pCamera->SaveZoomTable();
  1107. // reset after file operation
  1108. //Reset( true );
  1109. // reset IRQ checking
  1110. nBoardIrq = 0;
  1111. nBoardTimer = cMilliseconds;
  1112. break;
  1113. case LGS::CMD_GET_TILT_TABLE:
  1114. // prepare response
  1115. OnCmdGetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1116. // write command
  1117. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1118. break;
  1119. case LGS::CMD_SET_TILT_TABLE:
  1120. // prepare response
  1121. OnCmdSetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1122. // write command
  1123. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1124. // update camera settings
  1125. m_pCamera->SaveTiltTable();
  1126. // reset after file operation
  1127. Reset( true );
  1128. //m_bRun = false;
  1129. // reset IRQ checking
  1130. nBoardIrq = 0;
  1131. nBoardTimer = cMilliseconds;
  1132. break;
  1133. #endif //! NO_EMBED_CAMERA
  1134. case LGS::CMD_GET_LRF_DISABLE:
  1135. // prepare response
  1136. OnCmdGetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1137. // write command
  1138. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1139. break;
  1140. case LGS::CMD_SET_LRF_DISABLE:
  1141. // prepare response
  1142. OnCmdSetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1143. // write command
  1144. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1145. // reset after file operation
  1146. Reset( true );
  1147. //m_bRun = false;
  1148. // reset IRQ checking
  1149. nBoardIrq = 0;
  1150. nBoardTimer = cMilliseconds;
  1151. break;
  1152. case LGS::CMD_GET_HZ_DATA:
  1153. m_pShadow->OnCmdGetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1154. // write command
  1155. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1156. break;
  1157. case LGS::CMD_SET_HZ_DATA:
  1158. {
  1159. bool bPendingSave = m_pShadow->OnCmdSetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1160. // write command
  1161. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1162. // save
  1163. if( bPendingSave )
  1164. {
  1165. // save data
  1166. m_pShadow->Save();
  1167. // reset after file operation
  1168. Reset( true );
  1169. //m_bRun = false;
  1170. // reset IRQ checking
  1171. nBoardIrq = 0;
  1172. nBoardTimer = cMilliseconds;
  1173. #ifdef LGS_MIRROR
  1174. bRestart = true;
  1175. //m_bRun = false;
  1176. Reset( true );
  1177. #endif
  1178. }
  1179. }
  1180. break;
  1181. case LGS::CMD_GET_HZ_ENABLE:
  1182. m_pShadow->OnCmdGetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1183. // write command
  1184. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1185. break;
  1186. case LGS::CMD_SET_HZ_ENABLE:
  1187. {
  1188. bool bPendingSave = m_pShadow->OnCmdSetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1189. // write command
  1190. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1191. // save
  1192. if( bPendingSave )
  1193. {
  1194. // save data
  1195. m_pShadow->Save();
  1196. // reset after file operation
  1197. //Reset( true );
  1198. // reset IRQ checking
  1199. nBoardIrq = 0;
  1200. nBoardTimer = cMilliseconds;
  1201. // set data finished correctly
  1202. bSetHzDataInProgress = false;
  1203. //Restart After Aply Mask
  1204. bRestart = true;
  1205. //m_bRun = false;
  1206. Reset( true );
  1207. //
  1208. }
  1209. else
  1210. bSetHzDataInProgress = true;
  1211. }
  1212. break;
  1213. case LGS::CMD_GET_CALIBRATION_TABLE:
  1214. OnCmdGetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1215. // write command
  1216. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1217. break;
  1218. case LGS::CMD_SET_CALIBRATION_TABLE:
  1219. {
  1220. int16_t nDevice = 0;
  1221. bool bPendingSave = OnCmdSetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount, nDevice );
  1222. // write command
  1223. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1224. #ifndef RANGE_16BIT
  1225. // save
  1226. if( bPendingSave )
  1227. {
  1228. // save data
  1229. switch( nDevice )
  1230. {
  1231. case 0: m_Calibrator[nDevice].Save( "lt0.ini" ); break;
  1232. case 1: m_Calibrator[nDevice].Save( "lt1.ini" ); break;
  1233. }
  1234. // reset after file operation
  1235. Reset( true );
  1236. //m_bRun = false;
  1237. // reset IRQ checking
  1238. nBoardIrq = 0;
  1239. nBoardTimer = cMilliseconds;
  1240. // set data finished correctly
  1241. bSetCalibrationTableInProgress = false;
  1242. }
  1243. else
  1244. bSetCalibrationTableInProgress = true;
  1245. #endif // 16 bit
  1246. }
  1247. break;
  1248. case LGS::CMD_QUIT:
  1249. *pSendBufferPtr++ = LGS::CMD_QUIT;
  1250. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1251. m_bRun = false;
  1252. #ifndef COMPILE_AS_GETFILE
  1253. #ifdef STORE_FIRST_SAF
  1254. if( g_bSAFFileEnable ){
  1255. m_Detector[ 0 ].save_current_SAF();
  1256. };
  1257. #endif
  1258. #endif
  1259. Reset( true );
  1260. break;
  1261. case LGS::CMD_RESTART:
  1262. *pSendBufferPtr++ = LGS::CMD_RESTART;
  1263. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1264. //#ifdef INFINITE_SAF_STUDY
  1265. // m_Detector[0].StartLearningCycle();
  1266. //#else
  1267. //bRestart = true;
  1268. m_bRun = false;
  1269. #ifndef COMPILE_AS_GETFILE
  1270. #ifdef STORE_FIRST_SAF
  1271. if( g_bSAFFileEnable ){
  1272. m_Detector[ 0 ].save_current_SAF();
  1273. };
  1274. #endif
  1275. #endif
  1276. Reset( true );
  1277. //#endif
  1278. break;
  1279. case LGS::CMD_GET_SERIAL_NUMBER:
  1280. // reply command
  1281. *pSendBufferPtr++ = LGS::CMD_GET_SERIAL_NUMBER;
  1282. // reply data
  1283. nSendCount += LGS::BuildSerialNumber( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  1284. // write into port
  1285. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1286. break;
  1287. case LGS::CMD_GET_SOFTWARE_VERSION:
  1288. // reply command
  1289. *pSendBufferPtr++ = LGS::CMD_GET_SOFTWARE_VERSION;
  1290. // reply data
  1291. nSendCount += LGS::BuildSoftwareVersion( pSendBufferPtr, (PBYTE)s_pSoftwareVersion, s_nSoftwareVersion );
  1292. // write into port
  1293. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1294. break;
  1295. case LGS::CMD_GET_VOLTAGE:
  1296. // reply command
  1297. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE;
  1298. // reply data
  1299. nSendCount += LGS::BuildEvtVoltage( pSendBufferPtr, m_Voltage.GetVoltage() );
  1300. // write into port
  1301. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1302. break;
  1303. #ifdef DETECTION_MULTI_PROFILES
  1304. case LGS::CMD_GET_ACTIVE_PROFILE:
  1305. // reply command
  1306. *pSendBufferPtr++ = LGS::CMD_GET_ACTIVE_PROFILE;
  1307. // reply data
  1308. nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
  1309. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1310. break;
  1311. case LGS::CMD_SET_ACTIVE_PROFILE:
  1312. //ToDo ...
  1313. //printf( "Set Active Profile %d\n",(uint8_t)pBuffer[0] );
  1314. if ( setActiveDetectionProfile( pBuffer[0] ) ){
  1315. bRestart = true;
  1316. //m_bRun = false;
  1317. Reset( true );
  1318. };
  1319. *pSendBufferPtr++ = LGS::CMD_SET_ACTIVE_PROFILE;
  1320. //data
  1321. //nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
  1322. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1323. break;
  1324. #endif
  1325. #ifndef EMBEDDED_CAMERA_DISABLE
  1326. #ifndef NO_EMBED_CAMERA
  1327. case LGS::CMD_GET_CAMERA_PARAMETERS:
  1328. {
  1329. // reply command
  1330. *pSendBufferPtr++ = LGS::CMD_GET_CAMERA_PARAMETERS;
  1331. // reply data
  1332. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &m_pCamera->GetParameters() );
  1333. // write into port
  1334. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1335. }
  1336. break;
  1337. case LGS::CMD_SET_CAMERA_PARAMETERS:
  1338. {
  1339. LGS::CAMERA_PARAMETERS cp;
  1340. LGS::GetCameraParameters( pBuffer, &cp );
  1341. // reply command
  1342. *pSendBufferPtr++ = LGS::CMD_SET_CAMERA_PARAMETERS;
  1343. // reply data
  1344. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &cp );
  1345. // write into port
  1346. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1347. // store serial number
  1348. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &cp, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1349. // restart program
  1350. //m_bRun = false;
  1351. Reset( true );
  1352. }
  1353. break;
  1354. #endif
  1355. #endif
  1356. case LGS::CMD_GET_VOLTAGE_PARAMETERS:
  1357. {
  1358. // reply command
  1359. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE_PARAMETERS;
  1360. // reply data
  1361. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &m_Voltage.GetParameters() );
  1362. // write into port
  1363. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1364. }
  1365. break;
  1366. case LGS::CMD_SET_VOLTAGE_PARAMETERS:
  1367. {
  1368. LGS::VOLTAGE_PARAMETERS vp;
  1369. // store voltage parameters
  1370. LGS::GetVoltageParameters( pBuffer, &vp );
  1371. // reply command
  1372. *pSendBufferPtr++ = LGS::CMD_SET_VOLTAGE_PARAMETERS;
  1373. // reply data
  1374. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &vp );
  1375. // write into port
  1376. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1377. // store serial number
  1378. #ifndef NO_EMBED_CAMERA
  1379. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &vp, &m_LRFDisable );
  1380. #else
  1381. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &vp, &m_LRFDisable );
  1382. #endif
  1383. // update voltage prameters
  1384. m_Voltage.SetParameters( &vp );
  1385. // reset after file operation
  1386. Reset( true );
  1387. //m_bRun = false;
  1388. // reset IRQ checking
  1389. nBoardIrq = 0;
  1390. nBoardTimer = cMilliseconds;
  1391. }
  1392. break;
  1393. case LGS::CMD_GET_RELAY_PARAMETERS:
  1394. {
  1395. // reply command
  1396. *pSendBufferPtr++ = LGS::CMD_GET_RELAY_PARAMETERS;
  1397. // reply data
  1398. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &m_Relay.GetParameters() );
  1399. // write into port
  1400. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1401. }
  1402. break;
  1403. case LGS::CMD_SET_RELAY_PARAMETERS:
  1404. {
  1405. LGS::RELAY_PARAMETERS rp;
  1406. LGS::GetRelayParameters( pBuffer, &rp );
  1407. // reply command
  1408. *pSendBufferPtr++ = LGS::CMD_SET_RELAY_PARAMETERS;
  1409. // reply data
  1410. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &rp );
  1411. // write into port
  1412. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1413. // store serial number
  1414. #ifndef NO_EMBED_CAMERA
  1415. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
  1416. #else
  1417. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
  1418. #endif
  1419. // update relay parameters
  1420. m_Relay.SetParameters( &rp );
  1421. // reset after file operation
  1422. //m_bRun = false;
  1423. Reset( true );
  1424. // reset IRQ checking
  1425. nBoardIrq = 0;
  1426. nBoardTimer = cMilliseconds;
  1427. }
  1428. break;
  1429. case LGS::CMD_SET_ADDRESS:
  1430. {
  1431. // reply command
  1432. *pSendBufferPtr++ = LGS::CMD_SET_ADDRESS;
  1433. // parse parameters
  1434. uint8_t pSerialNumber[MAX_PATH];
  1435. uint8_t nAddress, nCount;
  1436. LGS::GetAddress( pBuffer, &nAddress, &nCount, pSerialNumber );
  1437. // only if serial number is equal
  1438. if( (nCount == m_nSerialNumber) && !memcmp( pSerialNumber, m_pSerialNumber, m_nSerialNumber ) )
  1439. {
  1440. // change address
  1441. m_nAddress = nAddress;
  1442. // prepare answer message
  1443. nSendCount += LGS::BuildAddress( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  1444. // send reply
  1445. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1446. // store serial number
  1447. #ifndef NO_EMBED_CAMERA
  1448. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1449. #else
  1450. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1451. #endif
  1452. // reset after file operation
  1453. //m_bRun = false;
  1454. Reset( true );
  1455. // reset IRQ checking
  1456. nBoardIrq = 0;
  1457. nBoardTimer = cMilliseconds;
  1458. }
  1459. }
  1460. break;
  1461. case LGS::CMD_SET_COMM_SPEED:
  1462. {
  1463. // reply command
  1464. *pSendBufferPtr++ = LGS::CMD_SET_COMM_SPEED;
  1465. // parse parameters
  1466. int32_t nSpeed;
  1467. LGS::GetCommSpeed( pBuffer, &nSpeed );
  1468. // prepare answer message
  1469. nSendCount += LGS::BuildCommSpeed( pSendBufferPtr, nSpeed );
  1470. // send reply
  1471. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1472. // reinitialize communication if nessessary
  1473. #ifndef COMPILE_AS_GETFILE
  1474. if( m_pComm485->GetBaudRate() != nSpeed )
  1475. #endif
  1476. {
  1477. if( !m_pComm485->SetParameters( nSpeed, 8L, CComm485::_NOPARITY ) )
  1478. return false;
  1479. // store new comm speed
  1480. FILE *pFile = fopen( "SERIAL.INI", "wt" );
  1481. if( pFile )
  1482. {
  1483. fprintf( pFile, "%ld\n", nSpeed );
  1484. fclose( pFile );
  1485. }
  1486. // reset after file operation
  1487. //m_bRun = false;
  1488. Reset( true );
  1489. // reset IRQ checking
  1490. nBoardIrq = 0;
  1491. nBoardTimer = cMilliseconds;
  1492. }
  1493. }
  1494. break;
  1495. case LGS::CMD_PARAMETERS:
  1496. {
  1497. // reply command
  1498. *pSendBufferPtr++ = LGS::CMD_PARAMETERS;
  1499. // parse input command
  1500. uint8_t bSet, nDevice;
  1501. LGS::LGS_PARAMETERS parameters;
  1502. LGS::GetParameters( pBuffer, &bSet, &nDevice, &parameters );
  1503. // return parameters
  1504. if( bSet )
  1505. {
  1506. #if defined( LGS_PLS_1 ) || defined( LGS_MND )
  1507. if( nDevice == 0 ) m_Detector[ nDevice ].SetParameters( &parameters );
  1508. #else
  1509. #ifdef LGS_MIRROR
  1510. m_Detector[ ( nDevice ) % 4 ].SetParameters( &parameters );
  1511. m_Detector[ ( nDevice + 2 ) % 4 ].SetParameters( &parameters );
  1512. #endif
  1513. m_Detector[ nDevice ].SetParameters( &parameters );
  1514. #endif
  1515. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  1516. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1517. // reset after file operation
  1518. //m_bRun = false;
  1519. Reset( true );
  1520. // reset IRQ checking
  1521. nBoardIrq = 0;
  1522. nBoardTimer = cMilliseconds;
  1523. }
  1524. else
  1525. {
  1526. #if defined( LGS_PLS_1 ) || defined( LGS_MND )
  1527. if( nDevice == 0 ) m_Detector[ nDevice ].GetParameters( &parameters );// Set only as Master Device
  1528. #else
  1529. m_Detector[ nDevice ].GetParameters( &parameters );
  1530. #endif
  1531. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  1532. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1533. }
  1534. }
  1535. break;
  1536. case LGS::CMD_RESET:
  1537. *pSendBufferPtr++ = LGS::CMD_RESET;
  1538. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1539. #ifdef INFINITE_SAF_STUDY
  1540. m_Detector[0].StartLearningCycle();
  1541. #else
  1542. nMode = LGS::MODE_DETECTOR;
  1543. #ifndef COMPILE_AS_GETFILE
  1544. #ifdef STORE_FIRST_SAF
  1545. if( g_bSAFFileEnable ){
  1546. m_Detector[0].save_current_SAF();
  1547. };
  1548. #endif
  1549. #endif
  1550. Reset( false );
  1551. #endif
  1552. m_nBeforeZeroCounter = 0;
  1553. // reset IRQ checking
  1554. nBoardIrq = 0;
  1555. nBoardTimer = cMilliseconds;
  1556. #ifdef LGS_MIRROR
  1557. // bRestart = true;
  1558. m_bRun = false;
  1559. Reset( true );
  1560. #endif
  1561. break;
  1562. case LGS::CMD_FULL_RESET:
  1563. //if( g_dwStartupTime == 0 ) break;
  1564. if( ( g_dwStartupTime - ((DWORD) time( NULL ))) < 3 ) break;
  1565. *pSendBufferPtr++ = LGS::CMD_FULL_RESET;
  1566. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1567. nMode = LGS::MODE_DETECTOR;
  1568. #ifndef COMPILE_AS_GETFILE
  1569. #ifdef STORE_FIRST_SAF
  1570. if( g_bSAFFileEnable ){
  1571. m_Detector[ 0 ].save_current_SAF();
  1572. };
  1573. #endif
  1574. #endif
  1575. m_bRun = false;
  1576. Reset( true );
  1577. // reset IRQ checking
  1578. nBoardIrq = 0;
  1579. nBoardTimer = cMilliseconds;
  1580. #ifdef LGS_MIRROR
  1581. // bRestart = true;
  1582. // m_bRun = false;
  1583. #endif
  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. bBoardNoIrq = false;
  2613. };
  2614. // check for POWER changes
  2615. if( g_bShowErrors ) m_Voltage.OnProtocolLgsState2Command( bFlags );
  2616. #ifndef EMBEDDED_CAMERA_DISABLE
  2617. #ifndef NO_EMBED_CAMERA
  2618. // add camera flags
  2619. m_pCamera->OnProtocolLgsState2Command( bFlags );
  2620. #endif
  2621. #endif
  2622. // apply flags
  2623. if( bFlags ) nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, bFlags );
  2624. /* Old Sergey's for( int i = 0; i < 2; i++ )
  2625. {
  2626. CDetector *pDetector = m_Detector + i;
  2627. #ifdef LGS_MIRROR
  2628. CTracker *pTracker = m_Tracker + 0;
  2629. #else
  2630. CTracker *pTracker = m_Tracker + i;
  2631. #endif */
  2632. #ifdef LGS_MIRROR
  2633. for( int i = 0; i < 4; i++ ){
  2634. CDetector *pDetector = &m_Detector[i];
  2635. CTracker *pTracker = &m_Tracker[0];
  2636. #else //!LGS_MIRROR
  2637. #ifdef LGS_PLS_1
  2638. {
  2639. int i = 0;
  2640. #else
  2641. for( int i = 0; i < 2; i++ ){
  2642. #endif
  2643. CDetector *pDetector = &m_Detector[i];
  2644. CTracker *pTracker = &m_Tracker[i];
  2645. #endif
  2646. // assume that no errors
  2647. uint8_t bDeviceFlags = 0;
  2648. // check for tracker overflow
  2649. if( ( m_dwTimeErrorOverflow[i] < TIMER() ) && pTracker->GetLastErrorOverflow() )
  2650. {
  2651. m_dwTimeErrorOverflow[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2652. bDeviceFlags |= LGS::S2_ITDF_ERROR_OVERFLOW;
  2653. }
  2654. // check for tracker scan to scan overflow
  2655. if( ( m_dwTimeErrorOverflowSST[i] < TIMER() ) && pTracker->GetLastErrorOverflowSST() )
  2656. {
  2657. m_dwTimeErrorOverflowSST[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2658. bDeviceFlags |= LGS::S2_ITDF_ERROR_SST_OVERFLOW;
  2659. }
  2660. // check for detector sun errors
  2661. if( ( m_dwTimeErrorSun[i] < TIMER() ) && pDetector->GetLastErrorSun() )
  2662. {
  2663. m_dwTimeErrorSun[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2664. bDeviceFlags |= LGS::S2_ITDF_ERROR_SUN;
  2665. }
  2666. // apply device flags
  2667. if( g_bShowErrors && bDeviceFlags )
  2668. nSendCount += LGS::BuildEvtState2DeviceFlags( pSendBufferPtr, i, bDeviceFlags );
  2669. // place target information
  2670. CTracker::TARGET target;
  2671. while( ( pTracker->GetTarget( &target )
  2672. #ifndef NO_LIC
  2673. && m_pBoard->workingEnabled()
  2674. #endif
  2675. #ifdef DEBUG_TARGET_SIMULATOR
  2676. ) || bFireSimulatedTarget
  2677. #else
  2678. )
  2679. #endif
  2680. )
  2681. {
  2682. #ifdef DEBUG_TARGET_SIMULATOR
  2683. if( bFireSimulatedTarget ){
  2684. target.bType = LGS::TT_NORMAL;
  2685. target.nRange = 200;
  2686. target.nAngle = ( 3000* nSimulatedTargetID )/360 ;//145; GP2Y0A700K
  2687. target.nWidth = nSimulatedTargetValue;
  2688. bFireSimulatedTarget = false;
  2689. };
  2690. #endif
  2691. uint8_t bType;
  2692. switch( target.bType )
  2693. {
  2694. case LGS::TT_WIDE:
  2695. case LGS::TT_NORMAL:
  2696. bType = ( target.bType == LGS::TT_NORMAL ) ? LGS::S2_ITT_NORMAL : LGS::S2_ITT_WIDE;
  2697. if( ( bRequestType & LGS::S2_RT_TARGET_MASK ) == LGS::S2_RT_TARGET_DEKART )
  2698. {
  2699. #ifdef LGS_MIRROR
  2700. #ifdef LGS_MND
  2701. const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
  2702. double a = ( target.nAngle << 2 ) * a2r;
  2703. #else
  2704. const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
  2705. double a = ( target.nAngle << 1 ) * a2r;
  2706. #endif
  2707. #else //LGS_MIRROR
  2708. const double a2r = asin(1.0) * 4.0 / LGS_MAX_DETECTOR_ANGLES;
  2709. double a = ( target.nAngle ) * a2r;
  2710. #endif
  2711. #ifdef ALS_300_BM
  2712. target.nAngle = ( int16_t ) (( target.nAngle * 6000.0f ) / 20000.0f ); //Convert Angle from 20000 to 6000
  2713. #endif
  2714. int16_t x = target.nRange * cos( a );
  2715. int16_t y = target.nRange * sin( a );
  2716. #if defined( LGS_MIRROR ) || defined( LGS_MND )
  2717. #ifdef LGS_MND
  2718. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2719. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth << 2 ) :
  2720. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2721. #else
  2722. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2723. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth ) :
  2724. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2725. #endif
  2726. #else
  2727. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2728. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth )://<< 1 ) :
  2729. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2730. #endif
  2731. } else {
  2732. #ifdef ALS_300_BM
  2733. target.nAngle = ( int16_t ) (( target.nAngle * 6000.0f ) / 20000.0f ); //Convert Angle from 20000 to 6000
  2734. #endif
  2735. #ifdef LGS_MIRROR
  2736. #ifdef LGS_MND
  2737. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2738. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange, target.nWidth << 2 ) : // ? Wx2 ??
  2739. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange );
  2740. #else
  2741. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2742. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange, target.nWidth )://<< 1 ) : // ? Wx2 ??
  2743. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange );
  2744. #endif
  2745. #else // !LGS_MIRROR
  2746. #ifdef LGS_REDUCED_PRF
  2747. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2748. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
  2749. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
  2750. #else
  2751. #ifdef __ALS_300 //(target.nAngle<<2)/5
  2752. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2753. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3, target.nWidth ) :
  2754. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3 );
  2755. #else
  2756. // ALS_300_BM
  2757. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2758. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
  2759. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
  2760. #endif
  2761. #endif
  2762. #endif
  2763. };
  2764. break;
  2765. case LGS::TT_FLIP:
  2766. nSendCount += LGS::BuildEvtState2Flip( pSendBufferPtr, i, target.nAngle );
  2767. break;
  2768. case LGS::TT_BLIND:
  2769. if( ( target.nAngle < LGS_BLIND_TYPE_FAR_FOG_ENTER ) && ( !g_bShowErrors || g_bHideFogError ) ) break;
  2770. switch( target.nAngle )
  2771. {
  2772. case LGS_BLIND_TYPE_MR_ENTER:
  2773. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_MEDIUM_RANGE );
  2774. break;
  2775. case LGS_BLIND_TYPE_MR_EXIT:
  2776. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_MEDIUM_RANGE );
  2777. break;
  2778. case LGS_BLIND_TYPE_180_DEGRESE_ENTER:
  2779. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_180_DEGREE );
  2780. break;
  2781. case LGS_BLIND_TYPE_180_DEGRESE_EXIT:
  2782. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_180_DEGREE );
  2783. break;
  2784. case LGS_BLIND_TYPE_FS_ENTER:
  2785. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FOG_SPIKES );
  2786. break;
  2787. case LGS_BLIND_TYPE_FS_EXIT:
  2788. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FOG_SPIKES );
  2789. break;
  2790. case LGS_BLIND_TYPE_PD_ENTER:
  2791. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_PD );
  2792. break;
  2793. case LGS_BLIND_TYPE_PD_EXIT:
  2794. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_PD );
  2795. break;
  2796. case LGS_BLIND_TYPE_FAR_FOG_ENTER:
  2797. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FAR_FOG );
  2798. break;
  2799. case LGS_BLIND_TYPE_FAR_FOG_EXIT:
  2800. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FAR_FOG );
  2801. break;
  2802. case LGS_BLIND_TYPE_NEAR_FOG_ENTER:
  2803. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_NEAR_FOG );
  2804. break;
  2805. case LGS_BLIND_TYPE_NEAR_FOG_EXIT:
  2806. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_NEAR_FOG );
  2807. break;
  2808. }
  2809. break;
  2810. // case LGS::TT_CAMERA:
  2811. // break;
  2812. // case LGS::TT_TEST:
  2813. // break;
  2814. }
  2815. if( nSendCount >= 20 )
  2816. break;
  2817. }
  2818. #ifndef LGS_PLS_1
  2819. if( nSendCount >= 20 ) break;
  2820. #endif
  2821. }
  2822. }
  2823. void CKernel::OnCmdGetWidthTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2824. {
  2825. // unused variables
  2826. pReadBufferPtr; nReadCount;
  2827. // build CMD_GET_WIDHT_TABLE command
  2828. *pSendBufferPtr++ = LGS::CMD_GET_WIDTH_TABLE;
  2829. PLONG pNativeTable = m_Detector[0].GetFilterWidth()->GetTable();
  2830. // prepare table
  2831. LGS::WIDTH_TABLE table;
  2832. table.nCount = LGS::WIDTH_TABLE_SIZE;
  2833. for( int16_t i = 0; i < LGS::WIDTH_TABLE_SIZE; i++ )
  2834. table.pTable[i] = ( pNativeTable[i] * 100L ) >> 7;
  2835. // write command
  2836. nSendCount += LGS::BuildEvtGetWidthTable( pSendBufferPtr, &table );
  2837. }
  2838. void CKernel::OnCmdSetWidthTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2839. {
  2840. // build CMD_SET_WIDHT_TABLE command
  2841. *pSendBufferPtr++ = LGS::CMD_SET_WIDTH_TABLE;
  2842. // read table
  2843. LGS::WIDTH_TABLE table;
  2844. nReadCount -= LGS::GetCmdSetWidthTable( pReadBufferPtr, &table );
  2845. FILE *pFile = fopen( "width.ini", "wt" );
  2846. if( pFile )
  2847. {
  2848. for( int16_t i = 0; i < table.nCount; i++ )
  2849. fprintf( pFile, "%d ", table.pTable[i] );
  2850. fclose( pFile );
  2851. }
  2852. // write command
  2853. nSendCount += LGS::BuildEvtSetWidthTable( pSendBufferPtr, &table );
  2854. // restart program
  2855. m_bRun = false;
  2856. }
  2857. void CKernel::OnCmdGetZoomTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2858. {
  2859. // unused variables
  2860. pReadBufferPtr; nReadCount;
  2861. // build CMD_GET_WIDHT_TABLE command
  2862. *pSendBufferPtr++ = LGS::CMD_GET_ZOOM_TABLE;
  2863. #ifndef NO_EMBED_CAMERA
  2864. // write command
  2865. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  2866. #else
  2867. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
  2868. #endif
  2869. }
  2870. void CKernel::OnCmdSetZoomTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2871. {
  2872. // build CMD_SET_WIDHT_TABLE command
  2873. *pSendBufferPtr++ = LGS::CMD_SET_ZOOM_TABLE;
  2874. #ifndef NO_EMBED_CAMERA
  2875. // read table
  2876. nReadCount -= LGS::GetZoomTable( pReadBufferPtr, &m_pCamera->GetZoomTable() );
  2877. // write command
  2878. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  2879. #else
  2880. // write command
  2881. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
  2882. #endif
  2883. }
  2884. void CKernel::OnCmdGetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2885. {
  2886. // unused variables
  2887. pReadBufferPtr; nReadCount;
  2888. // build CMD_GET_WIDHT_TABLE command
  2889. *pSendBufferPtr++ = LGS::CMD_GET_TILT_TABLE;
  2890. #ifndef NO_EMBED_CAMERA
  2891. // write command
  2892. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  2893. #else
  2894. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
  2895. #endif
  2896. }
  2897. void CKernel::OnCmdSetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2898. {
  2899. // build CMD_SET_WIDHT_TABLE command
  2900. *pSendBufferPtr++ = LGS::CMD_SET_TILT_TABLE;
  2901. #ifndef NO_EMBED_CAMERA
  2902. // read table
  2903. nReadCount -= LGS::GetTiltTable( pReadBufferPtr, &m_pCamera->GetTiltTable() );
  2904. // write command
  2905. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  2906. #else
  2907. // write command
  2908. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
  2909. #endif
  2910. }
  2911. void CKernel::OnCmdGetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2912. {
  2913. // read table
  2914. uint8_t nDevice = *pReadBufferPtr++;
  2915. nReadCount --;
  2916. // build CMD_GET_LINEARIZATION_TABLE command
  2917. *pSendBufferPtr++ = LGS::CMD_GET_CALIBRATION_TABLE;
  2918. *pSendBufferPtr++ = nDevice;
  2919. nSendCount++;
  2920. #ifndef RANGE_16BIT
  2921. // process command
  2922. m_Calibrator[nDevice?1:0].OnCmdGetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  2923. #endif // 16 bit
  2924. }
  2925. bool CKernel::OnCmdSetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount, int16_t& nDevice )
  2926. {
  2927. // read table
  2928. nDevice = *pReadBufferPtr++;
  2929. nReadCount --;
  2930. // build CMD_SET_LINEARIZATION_TABLE command
  2931. *pSendBufferPtr++ = LGS::CMD_SET_CALIBRATION_TABLE;
  2932. *pSendBufferPtr++ = nDevice;
  2933. nSendCount++;
  2934. #ifndef RANGE_16BIT
  2935. // process command
  2936. return m_Calibrator[nDevice?1:0].OnCmdSetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  2937. #endif // 16 bit
  2938. }
  2939. void CKernel::OnCmdGetLrfDisable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2940. {
  2941. // unused variables
  2942. pReadBufferPtr; nReadCount;
  2943. // build CMD_GET_LRF_DISABLE command
  2944. *pSendBufferPtr++ = LGS::CMD_GET_LRF_DISABLE;
  2945. // write command
  2946. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  2947. }
  2948. void CKernel::OnCmdSetLrfDisable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2949. {
  2950. // read table
  2951. nReadCount -= LGS::GetLRFDisable( pReadBufferPtr, &m_LRFDisable );
  2952. #ifndef NO_EMBED_CAMERA
  2953. // store serial number
  2954. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  2955. #else
  2956. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  2957. #endif
  2958. // build CMD_SET_LRF_DISABLE command
  2959. *pSendBufferPtr++ = LGS::CMD_SET_LRF_DISABLE;
  2960. // write command
  2961. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  2962. // restart program
  2963. m_bRun = false;
  2964. }
  2965. typedef enum SETTING_TYPE
  2966. {
  2967. ST_NONE = -1,
  2968. ST_SN = 0,
  2969. ST_ADDRESS,
  2970. ST_CAMERA_TYPE,
  2971. ST_CAMERA_SHIFT,
  2972. ST_CAMERA_AUTO,
  2973. ST_CAMERA_DELAY,
  2974. ST_RELAY_NC,
  2975. ST_RELAY_AUTO,
  2976. ST_RELAY_DELAY,
  2977. ST_VOLTAGE_CONTROL,
  2978. ST_MASTER_DISABLED,
  2979. ST_SLAVE_DISABLED,
  2980. ST_AUTORESET_ENABLE,
  2981. ST_AUTORESET_INTERLEAVE,
  2982. ST_AUTORESET_TIMEOUT,
  2983. ST_BOARD_TEMPERATURE,
  2984. ST_BOARD_ZEROSHIFT,
  2985. ST_BOARD_ENCODERSTEPS,
  2986. ST_BOARD_GEARRATIO,
  2987. ST_BOARD_MAXRANGE,
  2988. ST_BOARD_SPEED,
  2989. ST_BOARD_HID,
  2990. ST_SWITCHER_TABLE,
  2991. ST_SWITCHER_REPLY_TIMEOUT,
  2992. ST_SWITCHER_COMMAND_TIMEOUT,
  2993. ST_SWITCHER_AUTO_MODE,
  2994. ST_SWITCHER_AUTO_ENTER_TIMEOUT,
  2995. ST_SWITCHER_AUTO_SWITCH_TIMEOUT,
  2996. ST_NO_BLACK_TARGET_DETECTION,
  2997. ST_JUST_MOVING_TARGETS_DETECTION,
  2998. ST_JUST_MOVING_RADIAL_PARAM,
  2999. ST_JUST_MOVING_DISTANCE_PARAM,
  3000. ST_BLIND_ST_ANGLE,
  3001. ST_BLIND_ED_ANGLE,
  3002. ST_BLIND_ST_RANGE,
  3003. ST_BLIND_ED_RANGE,
  3004. ST_BLIND_WIDTH,
  3005. ST_BLIND_DEPTH,
  3006. ST_BLIND_ANGLE,
  3007. ST_BLIND_RANGE
  3008. #ifdef STORE_FIRST_SAF
  3009. ,ST_FREEZ_FIRST_SAF
  3010. ,ST_SAF_FILE_ENABLE
  3011. #endif
  3012. }SETTING_TYPE;
  3013. LPCTSTR m_pSetting[] =
  3014. {
  3015. { "SN" },
  3016. { "ADDRESS" },
  3017. { "CAMERA_TYPE" },
  3018. { "CAMERA_SHIFT" },
  3019. { "CAMERA_AUTO" },
  3020. { "CAMERA_DELAY" },
  3021. { "RELAY_NC" },
  3022. { "RELAY_AUTO" },
  3023. { "RELAY_DELAY" },
  3024. { "VOLTAGE_CONTROL" },
  3025. { "MASTER_DISABLED" },
  3026. { "SLAVE_DISABLED" },
  3027. { "AUTORESET_ENABLE" },
  3028. { "AUTORESET_INTERLEAVE" },
  3029. { "AUTORESET_TIMEOUT" },
  3030. { "BOARD_TEMPERATURE" },
  3031. { "BOARD_ZEROSHIFT" },
  3032. { "BOARD_ENCODERSTEPS" },
  3033. { "BOARD_GEARRATIO" },
  3034. { "BOARD_MAXRANGE" },
  3035. { "BOARD_SPEED" },
  3036. { "RUN_DIR" },
  3037. { "SWITCHER_TABLE" },
  3038. { "SWITCHER_REPLY_TIMEOUT" },
  3039. { "SWITCHER_COMMAND_TIMEOUT" },
  3040. { "SWITCHER_AUTO_MODE" },
  3041. { "SWITCHER_AUTO_ENTER_TIMEOUT" },
  3042. { "SWITCHER_AUTO_SWITCH_TIMEOUT" },
  3043. { "NO_BLACK_TARGETS" },
  3044. { "JUST_MOVING_TARGETS" },
  3045. { "JUST_MOVING_RADIAL" },
  3046. { "JUST_MOVING_DISTANCE" },
  3047. { "BLIND_ZONE_START_ANGLE" },
  3048. { "BLIND_ZONE_END_ANGLE" },
  3049. { "BLIND_ZONE_START_RANGE" },
  3050. { "BLIND_ZONE_END_RANGE" },
  3051. { "BLIND_ZONE_WIDTH" },
  3052. { "BLIND_ZONE_DEPTH" },
  3053. { "BLIND_ZONE_ANGLE" },
  3054. { "BLIND_ZONE_RANGE" }
  3055. #ifdef STORE_FIRST_SAF
  3056. ,{ "FREEZ_FIRST_TH" }
  3057. ,( "SAVE_FIRST_TH" )
  3058. #endif
  3059. };
  3060. 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 ){
  3061. // read serial number
  3062. FILE *pFile = fopen( "SN.INI", "rt" );
  3063. if( !pFile )
  3064. {
  3065. // fill with default sn
  3066. *pSerialNumberSize = 14;
  3067. memcpy( pSerialNumber, "NOSERIALNUMBER", *pSerialNumberSize );
  3068. return false;
  3069. }
  3070. CHAR pLine[MAX_PATH];
  3071. while( fgets( pLine, MAX_PATH, pFile ) )
  3072. {
  3073. SETTING_TYPE eType = ST_NONE;
  3074. PCHAR pTemp = NULL;
  3075. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
  3076. {
  3077. pTemp = strstr( pLine, m_pSetting[i] );
  3078. if( pTemp )
  3079. {
  3080. eType = (SETTING_TYPE)i;
  3081. pTemp = strstr( pTemp, "=" );
  3082. if( pTemp )
  3083. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3084. break;
  3085. }
  3086. }
  3087. if( eType == ST_NONE || !pTemp )
  3088. continue;
  3089. switch( eType )
  3090. {
  3091. case ST_SN: *pSerialNumberSize = strlen( pTemp ); memcpy( pSerialNumber, pTemp, *pSerialNumberSize ); break;
  3092. case ST_ADDRESS: *pAddress = atoi( pTemp ); break;
  3093. #ifndef NO_EMBED_CAMERA
  3094. case ST_CAMERA_TYPE: pCameraParameters->eType = (LGS::E_CAMERA_TYPE)atoi( pTemp ); break;
  3095. case ST_CAMERA_SHIFT: pCameraParameters->nShift = (uint16_t)atoi( pTemp ); break;
  3096. case ST_CAMERA_AUTO: pCameraParameters->bAuto = (bool)atoi( pTemp ); break;
  3097. case ST_CAMERA_DELAY: pCameraParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
  3098. #endif
  3099. case ST_RELAY_NC: pRelayParameters->bNormallyClose = (uint16_t)atoi( pTemp ); break;
  3100. case ST_RELAY_AUTO: pRelayParameters->bAuto = (bool)atoi( pTemp ); break;
  3101. case ST_RELAY_DELAY: pRelayParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
  3102. case ST_VOLTAGE_CONTROL: pVoltageParameters->bControl = (bool)atoi( pTemp ); break;
  3103. case ST_MASTER_DISABLED: if( pLRFDisable ) pLRFDisable->bMaster = (bool)atoi( pTemp ); break;
  3104. #ifndef LGS_PLS_1
  3105. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (bool)atoi( pTemp ); break;
  3106. #else
  3107. #ifdef INFINITE_SAF_STUDY
  3108. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (bool)atoi( pTemp ); break;
  3109. #else
  3110. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = true; break;
  3111. #endif
  3112. #endif
  3113. case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (bool)atoi( pTemp ); break;
  3114. case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
  3115. case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
  3116. case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
  3117. case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = atoi( pTemp ); break;
  3118. case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = atoi( pTemp ); break;
  3119. case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = atoi( pTemp ); break;
  3120. case ST_BLIND_ED_RANGE:m_nBZERangeFilter = atoi( pTemp ); break;
  3121. #ifdef STORE_FIRST_SAF
  3122. case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = atoi( pTemp ); break;
  3123. case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = atoi( pTemp ); break;
  3124. #endif
  3125. }
  3126. }
  3127. fclose( pFile );
  3128. return true;
  3129. }
  3130. bool CKernel::SaveSettings( LPCTSTR pSerialNumber, int16_t nAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable ){
  3131. FILE *pFile = fopen( "SN.INI", "wt" );
  3132. if( !pFile )
  3133. return false;
  3134. LPCTSTR pFormatStr = "%s = %s\n";
  3135. LPCTSTR pFormatInt = "%s = %d\n";
  3136. fprintf( pFile, pFormatStr, m_pSetting[ST_SN], pSerialNumber );
  3137. fprintf( pFile, pFormatInt, m_pSetting[ST_ADDRESS], nAddress );
  3138. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_TYPE], pCameraParameters->eType );
  3139. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_SHIFT], pCameraParameters->nShift );
  3140. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_AUTO], pCameraParameters->bAuto );
  3141. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_DELAY], pCameraParameters->nAutoDelay );
  3142. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_AUTO], pRelayParameters->bAuto );
  3143. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_DELAY], pRelayParameters->nAutoDelay );
  3144. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_NC], pRelayParameters->bNormallyClose );
  3145. fprintf( pFile, pFormatInt, m_pSetting[ST_VOLTAGE_CONTROL], pVoltageParameters->bControl );
  3146. if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_MASTER_DISABLED], pLRFDisable->bMaster );
  3147. #ifndef LFS_PLS_1
  3148. if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], pLRFDisable->bSlave );
  3149. #else
  3150. fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], true );
  3151. #endif
  3152. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3153. if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
  3154. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
  3155. } else {
  3156. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
  3157. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
  3158. };
  3159. #ifdef STORE_FIRST_SAF
  3160. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3161. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3162. #endif
  3163. fclose( pFile );
  3164. return true;
  3165. }
  3166. bool CKernel::LoadUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3167. int16_t tWidth = 0;
  3168. int16_t tDepth = 0;
  3169. int16_t tAngle = 0;
  3170. int16_t tRange = 0;
  3171. pSwitcher->pTable[0] = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4;
  3172. pSwitcher->pTable[1] = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4;
  3173. pSwitcher->pTable[2] = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4;
  3174. pSwitcher->nReplyTimeout = 100L;
  3175. pSwitcher->nCommandTimeout = 500L;
  3176. pSwitcher->nAutoMode = 0;
  3177. pSwitcher->nAutoEnterTimeout = 60;
  3178. pSwitcher->nAutoSwitchTimeout = 3;
  3179. pAutoReset->bEnabled = false;
  3180. pAutoReset->dwInterleave = 2000UL;
  3181. pAutoReset->dwTimeout = 60000UL;
  3182. pBoard->nZeroShift = 0;
  3183. pBoard->nTemperature = 1;
  3184. pBoard->nEncoderSteps = 6;
  3185. pBoard->nGearRatio = 61;
  3186. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3187. // Stepping Motor Speed
  3188. // 4280 = 8sps
  3189. // 2140 = 4sps
  3190. // 1070 = 2sps
  3191. // 535 = 1sps
  3192. pBoard->nMotorSpeed = 4;//535;
  3193. #endif
  3194. // pBoard->nMaxRange = 2048;
  3195. m_nMovingRadialFilter = 0;
  3196. m_nMovingDistanceFilter = 0;
  3197. m_nBZSAngleFilter = 0;
  3198. m_nBZEAngleFilter = 0;
  3199. m_nBZSRangeFilter = 0;
  3200. m_nBZERangeFilter = 0;
  3201. // read serial number
  3202. #ifdef LGS_MIRROR
  3203. #if defined( LGS_STEPPER ) || defined( LGS_FOD )
  3204. #ifdef LGS_FOD
  3205. FILE *pFile = fopen( "FOD.INI", "rt" ); // FOD
  3206. #else
  3207. FILE *pFile = fopen( "LFSS.INI", "rt" ); // LFSS
  3208. #endif
  3209. #else
  3210. #ifdef LGS_MND
  3211. FILE *pFile = fopen( "MND.INI", "rt" ); // MND
  3212. #else
  3213. FILE *pFile = fopen( "USER.INI", "rt" ); // LFS
  3214. #endif
  3215. #endif
  3216. #else
  3217. #ifdef LGS_PLS_1
  3218. FILE *pFile = fopen( "PLS.INI", "rt" ); // PLS
  3219. #else
  3220. FILE *pFile = fopen( "USER.INI", "rt" ); // ALS
  3221. #endif
  3222. #endif
  3223. if( !pFile )
  3224. return false;
  3225. CHAR pLine[MAX_PATH];
  3226. while( fgets( pLine, MAX_PATH, pFile ) )
  3227. {
  3228. SETTING_TYPE eType = ST_NONE;
  3229. PCHAR pTemp = NULL;
  3230. //printf( "%s", pLine );
  3231. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
  3232. {
  3233. pTemp = strstr( pLine, m_pSetting[i] );
  3234. if( pTemp )
  3235. {
  3236. eType = (SETTING_TYPE)i;
  3237. pTemp = strstr( pTemp, "=" );
  3238. if( pTemp )
  3239. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3240. break;
  3241. }
  3242. }
  3243. if( eType == ST_NONE || !pTemp )
  3244. continue;
  3245. switch( eType )
  3246. {
  3247. case ST_AUTORESET_ENABLE: pAutoReset->bEnabled = (bool)atoi( pTemp ); break;
  3248. case ST_AUTORESET_INTERLEAVE: pAutoReset->dwInterleave = atol( pTemp ); break;
  3249. case ST_AUTORESET_TIMEOUT: pAutoReset->dwTimeout = atol( pTemp ); break;
  3250. case ST_BOARD_TEMPERATURE: pBoard->nTemperature = atoi( pTemp ); break;
  3251. case ST_BOARD_ZEROSHIFT: pBoard->nZeroShift = atoi( pTemp ); break;
  3252. case ST_BOARD_ENCODERSTEPS: pBoard->nEncoderSteps = atoi( pTemp ); break;
  3253. case ST_BOARD_GEARRATIO: pBoard->nGearRatio = atoi( pTemp ); break;
  3254. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3255. case ST_BOARD_SPEED: pBoard->nMotorSpeed = atoi( pTemp ); break;
  3256. #endif
  3257. // case ST_BOARD_MAXRANGE: pBoard->nMaxRange = atoi( pTemp ); break;
  3258. case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (bool)atoi( pTemp ); break;
  3259. #ifdef STORE_FIRST_SAF
  3260. case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = atoi( pTemp ); break;
  3261. case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = atoi( pTemp ); break;
  3262. #endif
  3263. case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
  3264. case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
  3265. case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
  3266. case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = atoi( pTemp ); break;
  3267. case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = atoi( pTemp ); break;
  3268. case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = atoi( pTemp ); break;
  3269. case ST_BLIND_ED_RANGE:m_nBZERangeFilter = atoi( pTemp ); break;
  3270. case ST_BLIND_WIDTH:tWidth = atoi( pTemp ); break;
  3271. case ST_BLIND_DEPTH:tDepth = atoi( pTemp ); break;
  3272. case ST_BLIND_ANGLE:tAngle = atoi( pTemp ); break;
  3273. case ST_BLIND_RANGE:tRange = atoi( pTemp ); break;
  3274. #ifdef LGS_MIRROR
  3275. case ST_SWITCHER_TABLE: sscanf( pTemp, "%d,%d,%d", pSwitcher->pTable + 0, pSwitcher->pTable + 1, pSwitcher->pTable + 2 );
  3276. case ST_SWITCHER_REPLY_TIMEOUT: pSwitcher->nReplyTimeout = atol( pTemp ); break;
  3277. case ST_SWITCHER_COMMAND_TIMEOUT: pSwitcher->nCommandTimeout = atol( pTemp ); break;
  3278. case ST_SWITCHER_AUTO_MODE: pSwitcher->nAutoMode = atoi( pTemp ); break;
  3279. case ST_SWITCHER_AUTO_ENTER_TIMEOUT: pSwitcher->nAutoEnterTimeout = atoi( pTemp ); break;
  3280. case ST_SWITCHER_AUTO_SWITCH_TIMEOUT: pSwitcher->nAutoSwitchTimeout = atoi( pTemp ); break;
  3281. #endif
  3282. }
  3283. }
  3284. #if defined( LGS_REDUCED_PRF )
  3285. if( pBoard->nMotorSpeed < 1 ) pBoard->nMotorSpeed = 1;
  3286. if( pBoard->nMotorSpeed == 3 ) pBoard->nMotorSpeed = 2;
  3287. #if defined( LGS_STEPPER ) || defined( LGS_MND )
  3288. if( pBoard->nMotorSpeed > 4 ) pBoard->nMotorSpeed = 4;
  3289. #else
  3290. if( pBoard->nMotorSpeed == 5 ) pBoard->nMotorSpeed = 4;
  3291. if( pBoard->nMotorSpeed == 7 ) pBoard->nMotorSpeed = 6;
  3292. if( pBoard->nMotorSpeed == 9 ) pBoard->nMotorSpeed = 8;
  3293. if( pBoard->nMotorSpeed == 10 ) pBoard->nMotorSpeed = 8;
  3294. if( pBoard->nMotorSpeed == 11 ) pBoard->nMotorSpeed = 12;
  3295. if( pBoard->nMotorSpeed > 12 ) pBoard->nMotorSpeed = 12;
  3296. #endif
  3297. #if defined( LGS_MND )
  3298. LGS_PRF_REDUCE_RATIO = 1;
  3299. #else
  3300. if( pBoard->nMotorSpeed > 2 ){
  3301. LGS_PRF_REDUCE_RATIO = pBoard->nMotorSpeed >> 1;
  3302. } else {
  3303. LGS_PRF_REDUCE_RATIO = 1;
  3304. };
  3305. #endif
  3306. #endif
  3307. if( tWidth && tDepth ){
  3308. m_nBZSAngleFilter = tAngle - tWidth/2;
  3309. m_nBZEAngleFilter = ( tAngle + tWidth/2 ) % LGS_MAX_DETECTOR_ANGLES;
  3310. m_nBZSRangeFilter = tRange - tDepth/2;
  3311. m_nBZERangeFilter = tRange + tDepth/2;
  3312. };
  3313. fclose( pFile );
  3314. return true;
  3315. };
  3316. bool CKernel::SaveUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3317. #ifdef LGS_MIRROR
  3318. #if defined( LGS_STEPPER ) || defined( LGS_FOD )
  3319. #ifdef LGS_FOD
  3320. FILE *pFile = fopen( "FOD.INI", "wt" ); // FOD
  3321. #else
  3322. FILE *pFile = fopen( "LFSS.INI", "wt" ); // LFSS
  3323. #endif
  3324. #else
  3325. #ifdef LGS_MND
  3326. FILE *pFile = fopen( "MND.INI", "wt" ); // MND
  3327. #else
  3328. FILE *pFile = fopen( "USER.INI", "wt" ); // LFS
  3329. #endif
  3330. #endif
  3331. #else
  3332. #ifdef LGS_PLS_1
  3333. FILE *pFile = fopen( "PLS.INI", "wt" ); // PLS
  3334. #else
  3335. FILE *pFile = fopen( "USER.INI", "wt" ); // ALS
  3336. #endif
  3337. #endif
  3338. if( !pFile )
  3339. return false;
  3340. LPCTSTR pFormatInt = "%s=%d\n";
  3341. LPCTSTR pFormatDWORD = "%s=%lu\n";
  3342. LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
  3343. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
  3344. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
  3345. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
  3346. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
  3347. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
  3348. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
  3349. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
  3350. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3351. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
  3352. #endif
  3353. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3354. if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
  3355. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
  3356. } else {
  3357. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
  3358. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
  3359. };
  3360. if( m_nBZSAngleFilter != m_nBZEAngleFilter ){
  3361. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_ANGLE], m_nBZSAngleFilter );
  3362. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_ANGLE], m_nBZEAngleFilter );
  3363. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_RANGE], m_nBZSRangeFilter );
  3364. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_RANGE], m_nBZERangeFilter );
  3365. };
  3366. #ifdef LGS_MIRROR
  3367. fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
  3368. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
  3369. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
  3370. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
  3371. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
  3372. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
  3373. #endif
  3374. #ifdef STORE_FIRST_SAF
  3375. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3376. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3377. #endif
  3378. fclose( pFile );
  3379. return true;
  3380. }
  3381. bool CKernel::LoadFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3382. // read serial number
  3383. FILE *pFile = fopen( "PARAMS.INI", "rt" );
  3384. if( !pFile ) return false;
  3385. //printf("PARAMS.ini found reading params\n");
  3386. CHAR pLine[MAX_PATH];
  3387. while( fgets( pLine, MAX_PATH, pFile ) ){
  3388. SETTING_TYPE eType = ST_NONE;
  3389. PCHAR pTemp = NULL;
  3390. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ ){
  3391. pTemp = strstr( pLine, m_pSetting[i] );
  3392. if( pTemp )
  3393. {
  3394. eType = (SETTING_TYPE)i;
  3395. pTemp = strstr( pTemp, "=" );
  3396. if( pTemp )
  3397. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3398. break;
  3399. }
  3400. }
  3401. if( eType == ST_NONE || !pTemp ) continue;
  3402. switch( eType ){
  3403. case ST_BOARD_HID: pBoard->nHID = atoi( pTemp ); break;
  3404. }
  3405. }
  3406. fclose( pFile );
  3407. return true;
  3408. };
  3409. bool CKernel::SaveFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3410. FILE *pFile = fopen( "PARAMS.INI", "wt" );
  3411. if( !pFile )
  3412. return false;
  3413. LPCTSTR pFormatInt = "%s=%d\n";
  3414. LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
  3415. LPCTSTR pFormatDWORD = "%s=%lu\n";
  3416. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
  3417. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
  3418. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
  3419. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
  3420. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
  3421. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
  3422. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
  3423. #ifdef LGS_PLS_1
  3424. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
  3425. #endif
  3426. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_HID], (int16_t)pBoard->nHID );
  3427. fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
  3428. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
  3429. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
  3430. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
  3431. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
  3432. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
  3433. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3434. #ifdef STORE_FIRST_SAF
  3435. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3436. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3437. #endif
  3438. fclose( pFile );
  3439. return true;
  3440. }