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.

3740 lines
115 KiB

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