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.

3739 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
​
3 years ago
​
3 years ago
3 years ago
​
3 years ago
​
3 years ago
3 years ago
3 years ago
3 years ago
​
​
​
​
​
​
​
​
​
​
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, true )) ||
  888. (!m_Detector[1].GetBorderRange( nAngle, &nRange1, false )) ) ? 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. // save data
  1179. m_pShadow->Save();
  1180. // reset after file operation
  1181. Reset( false );
  1182. //m_bRun = false;
  1183. // reset IRQ checking
  1184. nBoardIrq = 0;
  1185. nBoardTimer = cMilliseconds;
  1186. #ifdef LGS_MIRROR
  1187. bRestart = true;
  1188. //m_bRun = false;
  1189. Reset( true );
  1190. #endif
  1191. }
  1192. }
  1193. break;
  1194. case LGS::CMD_GET_HZ_ENABLE:
  1195. m_pShadow->OnCmdGetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1196. // write command
  1197. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1198. break;
  1199. case LGS::CMD_SET_HZ_ENABLE:
  1200. {
  1201. bool bPendingSave = m_pShadow->OnCmdSetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1202. // write command
  1203. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1204. // save
  1205. if( bPendingSave )
  1206. {
  1207. // save data
  1208. m_pShadow->Save();
  1209. // reset after file operation
  1210. Reset( false );
  1211. // reset IRQ checking
  1212. nBoardIrq = 0;
  1213. nBoardTimer = cMilliseconds;
  1214. // set data finished correctly
  1215. bSetHzDataInProgress = false;
  1216. #ifdef LGS_MIRROR
  1217. bRestart = true;
  1218. Reset( true );
  1219. #endif
  1220. }
  1221. else
  1222. bSetHzDataInProgress = true;
  1223. }
  1224. break;
  1225. case LGS::CMD_GET_CALIBRATION_TABLE:
  1226. OnCmdGetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  1227. // write command
  1228. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1229. break;
  1230. case LGS::CMD_SET_CALIBRATION_TABLE:
  1231. {
  1232. int16_t nDevice = 0;
  1233. bool bPendingSave = OnCmdSetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount, nDevice );
  1234. // write command
  1235. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1236. #ifndef RANGE_16BIT
  1237. // save
  1238. if( bPendingSave )
  1239. {
  1240. // save data
  1241. switch( nDevice )
  1242. {
  1243. case 0: m_Calibrator[nDevice].Save( "lt0.ini" ); break;
  1244. case 1: m_Calibrator[nDevice].Save( "lt1.ini" ); break;
  1245. }
  1246. // reset after file operation
  1247. Reset( true );
  1248. //m_bRun = false;
  1249. // reset IRQ checking
  1250. nBoardIrq = 0;
  1251. nBoardTimer = cMilliseconds;
  1252. // set data finished correctly
  1253. bSetCalibrationTableInProgress = false;
  1254. }
  1255. else
  1256. bSetCalibrationTableInProgress = true;
  1257. #endif // 16 bit
  1258. }
  1259. break;
  1260. case LGS::CMD_QUIT:
  1261. *pSendBufferPtr++ = LGS::CMD_QUIT;
  1262. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1263. #ifndef COMPILE_AS_GETFILE
  1264. #ifdef STORE_FIRST_SAF
  1265. if( g_bSAFFileEnable ){
  1266. m_Detector[ 0 ].save_current_SAF();
  1267. };
  1268. #endif
  1269. #endif
  1270. Reset( true );
  1271. break;
  1272. case LGS::CMD_RESTART:
  1273. *pSendBufferPtr++ = LGS::CMD_RESTART;
  1274. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1275. //#ifdef INFINITE_SAF_STUDY
  1276. // m_Detector[0].StartLearningCycle();
  1277. //#else
  1278. bRestart = true;
  1279. #ifndef COMPILE_AS_GETFILE
  1280. #ifdef STORE_FIRST_SAF
  1281. if( g_bSAFFileEnable ){
  1282. m_Detector[ 0 ].save_current_SAF();
  1283. };
  1284. #endif
  1285. #endif
  1286. Reset( true );
  1287. //#endif
  1288. break;
  1289. case LGS::CMD_GET_SERIAL_NUMBER:
  1290. // reply command
  1291. *pSendBufferPtr++ = LGS::CMD_GET_SERIAL_NUMBER;
  1292. // reply data
  1293. nSendCount += LGS::BuildSerialNumber( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  1294. // write into port
  1295. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1296. break;
  1297. case LGS::CMD_GET_SOFTWARE_VERSION:
  1298. // reply command
  1299. *pSendBufferPtr++ = LGS::CMD_GET_SOFTWARE_VERSION;
  1300. // reply data
  1301. nSendCount += LGS::BuildSoftwareVersion( pSendBufferPtr, (PBYTE)s_pSoftwareVersion, s_nSoftwareVersion );
  1302. // write into port
  1303. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1304. break;
  1305. case LGS::CMD_GET_VOLTAGE:
  1306. // reply command
  1307. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE;
  1308. // reply data
  1309. nSendCount += LGS::BuildEvtVoltage( pSendBufferPtr, m_Voltage.GetVoltage() );
  1310. // write into port
  1311. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1312. break;
  1313. #ifdef DETECTION_MULTI_PROFILES
  1314. case LGS::CMD_GET_ACTIVE_PROFILE:
  1315. // reply command
  1316. *pSendBufferPtr++ = LGS::CMD_GET_ACTIVE_PROFILE;
  1317. // reply data
  1318. nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
  1319. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1320. break;
  1321. case LGS::CMD_SET_ACTIVE_PROFILE:
  1322. //ToDo ...
  1323. //printf( "Set Active Profile %d\n",(uint8_t)pBuffer[0] );
  1324. if ( setActiveDetectionProfile( pBuffer[0] ) ){
  1325. bRestart = true;
  1326. //m_bRun = false;
  1327. Reset( true );
  1328. };
  1329. *pSendBufferPtr++ = LGS::CMD_SET_ACTIVE_PROFILE;
  1330. //data
  1331. //nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
  1332. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1333. break;
  1334. #endif
  1335. #ifndef EMBEDDED_CAMERA_DISABLE
  1336. #ifndef NO_EMBED_CAMERA
  1337. case LGS::CMD_GET_CAMERA_PARAMETERS:
  1338. {
  1339. // reply command
  1340. *pSendBufferPtr++ = LGS::CMD_GET_CAMERA_PARAMETERS;
  1341. // reply data
  1342. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &m_pCamera->GetParameters() );
  1343. // write into port
  1344. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1345. }
  1346. break;
  1347. case LGS::CMD_SET_CAMERA_PARAMETERS:
  1348. {
  1349. LGS::CAMERA_PARAMETERS cp;
  1350. LGS::GetCameraParameters( pBuffer, &cp );
  1351. // reply command
  1352. *pSendBufferPtr++ = LGS::CMD_SET_CAMERA_PARAMETERS;
  1353. // reply data
  1354. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &cp );
  1355. // write into port
  1356. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1357. // store serial number
  1358. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &cp, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1359. // restart program
  1360. //m_bRun = false;
  1361. Reset( true );
  1362. }
  1363. break;
  1364. #endif
  1365. #endif
  1366. case LGS::CMD_GET_VOLTAGE_PARAMETERS:
  1367. {
  1368. // reply command
  1369. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE_PARAMETERS;
  1370. // reply data
  1371. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &m_Voltage.GetParameters() );
  1372. // write into port
  1373. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1374. }
  1375. break;
  1376. case LGS::CMD_SET_VOLTAGE_PARAMETERS:
  1377. {
  1378. LGS::VOLTAGE_PARAMETERS vp;
  1379. // store voltage parameters
  1380. LGS::GetVoltageParameters( pBuffer, &vp );
  1381. // reply command
  1382. *pSendBufferPtr++ = LGS::CMD_SET_VOLTAGE_PARAMETERS;
  1383. // reply data
  1384. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &vp );
  1385. // write into port
  1386. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1387. // store serial number
  1388. #ifndef NO_EMBED_CAMERA
  1389. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), m_Relay.GetParameters(), &vp, &m_LRFDisable );
  1390. #else
  1391. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, m_Relay.GetParameters(), &vp, &m_LRFDisable );
  1392. #endif
  1393. // update voltage prameters
  1394. m_Voltage.SetParameters( &vp );
  1395. // reset after file operation
  1396. Reset( true );
  1397. //m_bRun = false;
  1398. // reset IRQ checking
  1399. nBoardIrq = 0;
  1400. nBoardTimer = cMilliseconds;
  1401. }
  1402. break;
  1403. case LGS::CMD_GET_RELAY_PARAMETERS:
  1404. {
  1405. // reply command
  1406. *pSendBufferPtr++ = LGS::CMD_GET_RELAY_PARAMETERS;
  1407. // reply data
  1408. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, m_Relay.GetParameters() );
  1409. // write into port
  1410. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1411. }
  1412. break;
  1413. case LGS::CMD_SET_RELAY_PARAMETERS:
  1414. {
  1415. LGS::RELAY_PARAMETERS rp;
  1416. LGS::GetRelayParameters( pBuffer, &rp );
  1417. // reply command
  1418. *pSendBufferPtr++ = LGS::CMD_SET_RELAY_PARAMETERS;
  1419. // reply data
  1420. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &rp );
  1421. // write into port
  1422. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1423. // store serial number
  1424. #ifndef NO_EMBED_CAMERA
  1425. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
  1426. #else
  1427. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
  1428. #endif
  1429. // update relay parameters
  1430. m_Relay.SetParameters( &rp );
  1431. // reset after file operation
  1432. //m_bRun = false;
  1433. Reset( true );
  1434. // reset IRQ checking
  1435. nBoardIrq = 0;
  1436. nBoardTimer = cMilliseconds;
  1437. }
  1438. break;
  1439. case LGS::CMD_SET_ADDRESS:
  1440. {
  1441. // reply command
  1442. *pSendBufferPtr++ = LGS::CMD_SET_ADDRESS;
  1443. // parse parameters
  1444. uint8_t pSerialNumber[MAX_PATH];
  1445. uint8_t nAddress, nCount;
  1446. LGS::GetAddress( pBuffer, &nAddress, &nCount, pSerialNumber );
  1447. // only if serial number is equal
  1448. if( (nCount == m_nSerialNumber) && !memcmp( pSerialNumber, m_pSerialNumber, m_nSerialNumber ) )
  1449. {
  1450. // change address
  1451. m_nAddress = nAddress;
  1452. // prepare answer message
  1453. nSendCount += LGS::BuildAddress( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  1454. // send reply
  1455. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1456. // store serial number
  1457. #ifndef NO_EMBED_CAMERA
  1458. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1459. #else
  1460. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1461. #endif
  1462. // reset after file operation
  1463. //m_bRun = false;
  1464. Reset( true );
  1465. // reset IRQ checking
  1466. nBoardIrq = 0;
  1467. nBoardTimer = cMilliseconds;
  1468. }
  1469. }
  1470. break;
  1471. case LGS::CMD_SET_COMM_SPEED:
  1472. {
  1473. // reply command
  1474. *pSendBufferPtr++ = LGS::CMD_SET_COMM_SPEED;
  1475. // parse parameters
  1476. int32_t nSpeed;
  1477. LGS::GetCommSpeed( pBuffer, &nSpeed );
  1478. // prepare answer message
  1479. nSendCount += LGS::BuildCommSpeed( pSendBufferPtr, nSpeed );
  1480. // send reply
  1481. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1482. // reinitialize communication if nessessary
  1483. #ifndef COMPILE_AS_GETFILE
  1484. if( m_pComm485->GetBaudRate() != nSpeed )
  1485. #endif
  1486. {
  1487. if( !m_pComm485->SetParameters( nSpeed, 8L, CComm485::_NOPARITY ) )
  1488. return false;
  1489. // store new comm speed
  1490. FILE *pFile = fopen( "SERIAL.INI", "wt" );
  1491. if( pFile )
  1492. {
  1493. fprintf( pFile, "%ld\n", nSpeed );
  1494. fclose( pFile );
  1495. }
  1496. // reset after file operation
  1497. //m_bRun = false;
  1498. Reset( true );
  1499. // reset IRQ checking
  1500. nBoardIrq = 0;
  1501. nBoardTimer = cMilliseconds;
  1502. }
  1503. }
  1504. break;
  1505. case LGS::CMD_PARAMETERS:
  1506. {
  1507. // reply command
  1508. *pSendBufferPtr++ = LGS::CMD_PARAMETERS;
  1509. // parse input command
  1510. uint8_t bSet, nDevice;
  1511. LGS::LGS_PARAMETERS parameters;
  1512. LGS::GetParameters( pBuffer, &bSet, &nDevice, &parameters );
  1513. // return parameters
  1514. if( bSet )
  1515. {
  1516. #if defined( LGS_PLS_1 ) || defined( LGS_MND )
  1517. if( nDevice == 0 ) m_Detector[ nDevice ].SetParameters( &parameters );
  1518. #else
  1519. #ifdef LGS_MIRROR
  1520. m_Detector[ ( nDevice ) % 4 ].SetParameters( &parameters );
  1521. m_Detector[ ( nDevice + 2 ) % 4 ].SetParameters( &parameters );
  1522. #endif
  1523. m_Detector[ nDevice ].SetParameters( &parameters );
  1524. #endif
  1525. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  1526. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1527. // reset after file operation
  1528. //m_bRun = false;
  1529. Reset( true );
  1530. // reset IRQ checking
  1531. nBoardIrq = 0;
  1532. nBoardTimer = cMilliseconds;
  1533. }
  1534. else
  1535. {
  1536. #if defined( LGS_PLS_1 ) || defined( LGS_MND )
  1537. if( nDevice == 0 ) m_Detector[ nDevice ].GetParameters( &parameters );// Set only as Master Device
  1538. #else
  1539. m_Detector[ nDevice ].GetParameters( &parameters );
  1540. #endif
  1541. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  1542. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1543. }
  1544. }
  1545. break;
  1546. case LGS::CMD_RESET:
  1547. *pSendBufferPtr++ = LGS::CMD_RESET;
  1548. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1549. #ifdef INFINITE_SAF_STUDY
  1550. m_Detector[0].StartLearningCycle();
  1551. #else
  1552. nMode = LGS::MODE_DETECTOR;
  1553. #ifndef COMPILE_AS_GETFILE
  1554. #ifdef STORE_FIRST_SAF
  1555. if( g_bSAFFileEnable ){
  1556. m_Detector[0].save_current_SAF();
  1557. };
  1558. #endif
  1559. #endif
  1560. Reset( false );
  1561. #endif
  1562. m_nBeforeZeroCounter = 0;
  1563. // reset IRQ checking
  1564. nBoardIrq = 0;
  1565. nBoardTimer = cMilliseconds;
  1566. #ifdef LGS_MIRROR // ??
  1567. bRestart = true;
  1568. Reset( true );
  1569. #endif
  1570. break;
  1571. case LGS::CMD_FULL_RESET:
  1572. //if( g_dwStartupTime == 0 ) break;
  1573. if( ( g_qwStartupTime - cMilliseconds ) < 3000 ) break; // No Reset In First 3 Seconds
  1574. *pSendBufferPtr++ = LGS::CMD_FULL_RESET;
  1575. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1576. nMode = LGS::MODE_DETECTOR;
  1577. #ifndef COMPILE_AS_GETFILE
  1578. #ifdef STORE_FIRST_SAF
  1579. if( g_bSAFFileEnable ){
  1580. m_Detector[ 0 ].save_current_SAF();
  1581. };
  1582. #endif
  1583. #endif
  1584. bRestart = true;
  1585. Reset( true );
  1586. break;
  1587. case LGS::CMD_FULL_BORDER:
  1588. {
  1589. *pSendBufferPtr++ = LGS::CMD_FULL_BORDER;
  1590. // read command data
  1591. uint16_t nAngle;
  1592. LGS::GetCmdFullBorder( pBuffer, &nAngle );
  1593. // prepare answer
  1594. uint16_t nRange1 = 0;
  1595. uint16_t nRange2 = 0;
  1596. #ifndef LGS_PLS_1
  1597. #ifdef LGS_MIRROR
  1598. #ifdef LGS_MND
  1599. #ifdef INFINITE_SAF_STUDY
  1600. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1, true ) &&
  1601. m_Detector[0].GetFullBorderRange( nAngle, &nRange2, false );
  1602. #else
  1603. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1604. nRange2 = nRange1;
  1605. #endif
  1606. #else
  1607. uint16_t nRange3 = 0;
  1608. uint16_t nRange4 = 0;
  1609. bool bReady = m_Detector[3].GetFullBorderRange( nAngle, &nRange4 ) &&
  1610. m_Detector[2].GetFullBorderRange( nAngle, &nRange3 ) &&
  1611. m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
  1612. m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1613. if( bReady ){
  1614. if( nRange1 > nRange2 ){
  1615. int16_t TRange;
  1616. TRange = nRange1;
  1617. nRange1 = nRange2;
  1618. nRange2 = TRange;
  1619. };
  1620. if( nRange1 > nRange3 ){
  1621. int16_t TRange;
  1622. TRange = nRange1;
  1623. nRange1 = nRange3;
  1624. nRange3 = TRange;
  1625. };
  1626. if( nRange1 > nRange4 ){
  1627. int16_t TRange;
  1628. TRange = nRange1;
  1629. nRange1 = nRange4;
  1630. nRange4 = TRange;
  1631. };
  1632. if( nRange2 < nRange3 ){
  1633. nRange2 = nRange3;
  1634. };
  1635. if( nRange2 < nRange4 ){
  1636. nRange2 = nRange4;
  1637. };
  1638. };
  1639. #endif
  1640. #else // ALS
  1641. bool bReady = m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
  1642. m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1643. #endif
  1644. #else // PLS1
  1645. #ifdef INFINITE_SAF_STUDY
  1646. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1, true ) &&
  1647. m_Detector[0].GetFullBorderRange( nAngle, &nRange2, false );
  1648. #else
  1649. bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  1650. #endif
  1651. #endif // ndef PLS_1
  1652. if( bReady )
  1653. #ifdef RANGE_16BIT
  1654. //nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1 >> 5 , nRange2 >> 5 );
  1655. //nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1 >> 3 , nRange2 >> 3 );
  1656. //nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, (uint16_t)ceil( ((float)nRange1)/ 11.12f), (uint16_t)ceil( ((float)nRange2)/ 11.12f) );
  1657. {
  1658. uint16_t nR0,nR1;
  1659. //nRange1 = nAngle;
  1660. //nR0 = (uint16_t)(((float)nRange1)/ 11.12 + 1 );
  1661. nR0 = (uint16_t)(( 2048L * nRange1 )/ 22237 + 1 );
  1662. nR1 = (uint16_t)(( 2048L * nRange2 )/ 22237 + 1 );
  1663. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nR0, nR1 );
  1664. }
  1665. #else
  1666. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1, nRange2 );
  1667. #endif
  1668. else
  1669. #ifndef LGS_PLS_1
  1670. #ifdef LGS_MND
  1671. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nAngle, 0, 0 );
  1672. #else
  1673. // use percent from detector 2 because it always comes later
  1674. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nRange2, 0, 0 );
  1675. #endif
  1676. #else
  1677. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nAngle, 0, 0 );
  1678. #endif
  1679. // write back
  1680. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1681. }
  1682. break;
  1683. case LGS::CMD_GETFILE:
  1684. {
  1685. // build CMD_GETFILE command
  1686. *pSendBufferPtr++ = LGS::CMD_GETFILE;
  1687. #ifdef COMPILE_AS_GETFILE
  1688. if( nMode != LGS::MODE_GETFILE ){
  1689. bGetFileRun = true;
  1690. nMode = LGS::MODE_GETFILE;
  1691. };
  1692. {
  1693. #else
  1694. if( nMode != LGS::MODE_GETFILE ){
  1695. nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORMODE, 0, 0, 0 );
  1696. } else {
  1697. #endif
  1698. // get command parameters
  1699. uint8_t bError, bOperation, pData[100];
  1700. int16_t nData;
  1701. LGS::GetGetFile( pBuffer, &bError, &bOperation, pData, &nData );
  1702. // perform command
  1703. if( m_GetFile.OnCommand( bOperation, pData, nData ) )
  1704. nSendCount += LGS::BuildGetFile( pSendBufferPtr, 0, ( bOperation & LGS::GF_OP_INDEX ) | LGS::GF_OP_OK, NULL, 0 );
  1705. else
  1706. nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORFILE, bOperation, NULL, 0 );
  1707. }
  1708. // write answer
  1709. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1710. }
  1711. break;
  1712. #ifndef LGS_DISABLE_FILE_SYSTEM
  1713. case LGS::CMD_FS_SUB_PACKET: {
  1714. if( nMode != LGS::MODE_GETFILE ){
  1715. *pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
  1716. } else {
  1717. bool bAction;
  1718. PFS_DATA tPtr;
  1719. uint16_t tSize;
  1720. *pSendBufferPtr++ = LGS::CMD_FS_SUB_PACKET;
  1721. nSendCount ++;
  1722. m_pFSHelper->consume_data( pBuffer, bAction );
  1723. if( bAction ){
  1724. m_pFSHelper->do_action();
  1725. };
  1726. m_pFSHelper->output_data( tPtr, tSize );
  1727. if( tSize ){
  1728. memcpy( pSendBufferPtr, tPtr, tSize );
  1729. pSendBufferPtr += tSize;
  1730. nSendCount += tSize-1;
  1731. } else {
  1732. LGS::FS_DATA_EX OutFsData;
  1733. OutFsData.nCommand = LGS::FS_CMD_SEND_EVT;
  1734. OutFsData.sendevt.nError = LGS::FS_ERROR_OPERATION;
  1735. OutFsData.sendevt.nOrder = 0;
  1736. nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
  1737. };
  1738. };
  1739. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1740. break;
  1741. }
  1742. #endif
  1743. default:
  1744. //printf("CMD_UNSUPPORTED[0x%02X]\n", bHostCommand );
  1745. *pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
  1746. m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
  1747. break;
  1748. };
  1749. };
  1750. };
  1751. };
  1752. };
  1753. #ifdef COMPILE_AS_GETFILE
  1754. return false;
  1755. #else
  1756. return bRestart;
  1757. #endif
  1758. }
  1759. #ifndef COMPILE_3DSCANER
  1760. #ifdef COMPILE_RTSCANER___
  1761. // DoSendBoardData For RealTime Scanner
  1762. bool CKernel::DoSendBoardData( int16_t nDevice ){
  1763. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  1764. return false;
  1765. DWORD nBoardIrq = 0;
  1766. DWORD nBoardTimer = TIMER();
  1767. bool bPower, bZero, bSun[2];
  1768. int16_t nRange[2];
  1769. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
  1770. CLgBitCode Encoder( pData );
  1771. int16_t nPart = 0;
  1772. nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
  1773. while( m_bRun )
  1774. {
  1775. #ifdef WATCHDOG_ENABLED
  1776. // update watchdog timer
  1777. m_WatchDog.Update( TIMER() );
  1778. #endif
  1779. // check timer
  1780. if( ( (TIMER()) - nBoardTimer ) > 18UL )
  1781. {
  1782. if( !nBoardIrq )
  1783. {
  1784. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1785. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  1786. #endif
  1787. // reset board
  1788. m_pBoard->Reset();
  1789. }
  1790. nBoardTimer = TIMER();
  1791. nBoardIrq = 0;
  1792. }
  1793. // get new data
  1794. if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
  1795. {
  1796. // increase IRQ counter
  1797. nBoardIrq++;
  1798. // add next 13 bits of data
  1799. DWORD dwData = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  1800. if( Encoder.Encode24( dwData, 13 ) )
  1801. {
  1802. // increase part number
  1803. nPart++;
  1804. // if numbe rof partes exeed max partes
  1805. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART )
  1806. {
  1807. // prepare check sum in 14th byte of packet
  1808. uint8_t bCheckSum = 0;
  1809. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
  1810. bCheckSum += pData[i];
  1811. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  1812. // write into stream
  1813. m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  1814. delay(1);
  1815. // reset part
  1816. nPart = 0;
  1817. // zero memory
  1818. memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
  1819. }
  1820. // restart encoder
  1821. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  1822. }
  1823. }
  1824. #ifdef COMM_WITHOUT_INTERRUPTS
  1825. m_pComm485->Invalidate();
  1826. //m_pCameraComm->Invalidate();
  1827. #endif
  1828. //DWORD CTimer = m_pBoard->GetTimer();
  1829. //while( CTimer == m_pBoard->GetTimer() ); // delay 1/6000 sec
  1830. }
  1831. return true;
  1832. };
  1833. #else
  1834. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  1835. /* Old Procedure 060512
  1836. bool CKernel::DoSendBoardData( int16_t nDevice ){
  1837. #ifndef LGS_MIRROR
  1838. #ifdef LGS_PLS_1
  1839. nDevice = 0;
  1840. #else
  1841. nDevice = nDevice % 2;
  1842. #endif
  1843. #endif
  1844. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  1845. return false;
  1846. DWORD nBoardIrq = 0;
  1847. DWORD nBoardTimer = TIMER();
  1848. bool bPower, bZero, bSun[2], Reading, Writing;
  1849. DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
  1850. uint16_t CPointer = 0;
  1851. uint16_t OPointer = 0;
  1852. uint16_t CAngle = 0;
  1853. int16_t nRange[2];
  1854. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
  1855. CLgBitCode Encoder( pData );
  1856. int16_t nPart = 0;
  1857. bool WaitFZ;
  1858. Reading = false;
  1859. Writing = false;
  1860. WaitFZ = true;
  1861. //nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
  1862. while( m_bRun ){
  1863. #ifdef WATCHDOG_ENABLED
  1864. // update watchdog timer
  1865. m_WatchDog.Update( TIMER() );
  1866. #endif
  1867. if( ( ( TIMER() ) - nBoardTimer ) > 36UL ){
  1868. if( !nBoardIrq ){
  1869. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1870. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  1871. #endif
  1872. // reset board
  1873. if( g_UI_Debug ){
  1874. printf( "NO IRQ RESET\n" );
  1875. };
  1876. m_pBoard->AsyncReset();
  1877. WaitFZ = true;
  1878. Reading = false;
  1879. Writing = false;
  1880. };
  1881. nBoardTimer = TIMER();
  1882. nBoardIrq = 0;
  1883. }
  1884. // check board
  1885. uint8_t RetVal;
  1886. if( !Writing )
  1887. while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
  1888. if( RetVal == 2 ){
  1889. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1890. printf("DMA Transfers Overlaped\n");
  1891. #endif
  1892. // -----------------------
  1893. m_pBoard->AsyncReset();
  1894. WaitFZ = true;
  1895. Reading = false;
  1896. Writing = false;
  1897. break;
  1898. };
  1899. // perform linearization
  1900. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  1901. #ifdef LGS_MIRROR
  1902. nRange[1] = nRange[0];
  1903. #else
  1904. #ifndef LGS_PLS_1
  1905. nRange[1] = nRange[0];
  1906. #else
  1907. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  1908. #endif
  1909. #endif
  1910. // update voltage state
  1911. m_Voltage.Invalidate( bPower );
  1912. // increase IRQ counter
  1913. nBoardTimer = TIMER();
  1914. nBoardIrq++;
  1915. if( bZero && WaitFZ ){
  1916. WaitFZ = false;
  1917. Writing = false;
  1918. };
  1919. if( !WaitFZ ){
  1920. if( bZero ){
  1921. CPointer = 0;
  1922. CAngle = 0;
  1923. if( !Writing ) Reading = true;
  1924. } else {
  1925. CAngle++;
  1926. };
  1927. };
  1928. if( Reading ){
  1929. if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) ){
  1930. bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
  1931. //nRange[nDevice]
  1932. Buffer[CPointer] = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  1933. CPointer++;
  1934. if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
  1935. Reading = false;
  1936. Writing = true;
  1937. OPointer = 0;
  1938. };
  1939. };
  1940. };
  1941. };
  1942. if( Writing ){
  1943. // increase IRQ counter
  1944. nBoardTimer = TIMER();
  1945. nBoardIrq++;
  1946. // add next 13 bits of data
  1947. DWORD dwData = Buffer[OPointer];//(DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  1948. OPointer++;
  1949. #ifdef LGS_MIRROR
  1950. if( OPointer == 916 ){ //
  1951. #else
  1952. #ifdef LGS_PLS_1
  1953. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  1954. #else
  1955. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){
  1956. #endif
  1957. #endif
  1958. Writing = false;
  1959. //WaitFZ = true;
  1960. continue;
  1961. };
  1962. if( Encoder.Encode24( dwData, 13 ) ){
  1963. // increase part number
  1964. nPart++;
  1965. // if number raw parts meets max parts
  1966. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
  1967. // prepare check sum in 14th byte of packet
  1968. uint8_t bCheckSum = 0;
  1969. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
  1970. bCheckSum += pData[i];
  1971. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  1972. // write into stream
  1973. m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  1974. delay(4);
  1975. // reset part
  1976. nPart = 0;
  1977. // zero memory
  1978. memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
  1979. #ifdef COMM_WITHOUT_INTERRUPTS
  1980. m_pComm485->Invalidate();
  1981. //m_pCameraComm->Invalidate();
  1982. #endif
  1983. }
  1984. // restart encoder
  1985. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  1986. };
  1987. };
  1988. };
  1989. return true;
  1990. } */
  1991. // Regular DoSendBoardData ... PLS LGS ALS LFS
  1992. bool CKernel::DoSendBoardData( int16_t nDevice ){
  1993. #ifndef LGS_MIRROR
  1994. #ifdef LGS_PLS_1
  1995. nDevice = 0;
  1996. #else
  1997. nDevice = nDevice % 2;
  1998. #endif
  1999. #else
  2000. nDevice = nDevice % 4;
  2001. #endif
  2002. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  2003. return false;
  2004. DWORD nBoardIrq = 0;
  2005. DWORD nBoardTimer = TIMER();
  2006. bool bPower, bZero, bSun[2], Reading, Writing;
  2007. uint16_t SentScanCounter = 0;
  2008. //DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
  2009. uint16_t far *Buffer[2];//[LGS_MAX_DETECTOR_ANGLES];
  2010. Buffer[0] = (uint16_t far *) farmalloc( sizeof( uint16_t ) *LGS_MAX_DETECTOR_ANGLES );
  2011. if( Buffer[0] == NULL ) return false;
  2012. Buffer[1] = (uint16_t far *) farmalloc( sizeof( uint16_t ) *LGS_MAX_DETECTOR_ANGLES );
  2013. if( Buffer[0] == NULL ){
  2014. free( Buffer[0] );
  2015. return false;
  2016. };
  2017. uint16_t CPointer = 0;
  2018. uint16_t OPointer = 0;
  2019. uint16_t CAngle = 0;
  2020. uint16_t nRange[2];
  2021. #ifdef LGS_BOARDSAMPLE_RATIO
  2022. int16_t nRBuffer[LGS_BOARDSAMPLE_RATIO][2];
  2023. #endif
  2024. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 ];
  2025. CLgBitCode Encoder( pData );
  2026. int16_t nPart = 0;
  2027. bool WaitFZ;
  2028. bool tbZero;
  2029. bool tbSun;
  2030. char CoBuffer[20];
  2031. DWORD cnt;
  2032. uint8_t bCOutputArray, bCInputArray;
  2033. cnt = 0;
  2034. tbZero = false;
  2035. tbSun = false;
  2036. Reading = false;
  2037. Writing = false;
  2038. WaitFZ = true;
  2039. bCOutputArray = 0;
  2040. bCInputArray = 0;
  2041. //nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 1 );
  2042. //Wait till start
  2043. //cnt = m_pComm485->ReadWithWait( CoBuffer, 2, 36 ); //2 seconds in measurements of 1\18
  2044. //if( strcmp( CoBuffer, "AA" )!= 0 ) m_bRun = false;
  2045. //if( cnt == 0 ) m_bRun = false;
  2046. //delay( 3 );
  2047. // Start Empty Encoder
  2048. memset( pData, 0, ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 );
  2049. Encoder.SetBuffer( pData );
  2050. while( m_bRun ){
  2051. #ifdef WATCHDOG_ENABLED
  2052. if( g_bWatchDogEnable ){
  2053. // update watchdog timer
  2054. m_WatchDog.Update( TIMER() );
  2055. };
  2056. #endif
  2057. #ifdef BOARD_LAZY_INIT
  2058. if( ( ( TIMER() ) - nBoardTimer ) > 300UL ){
  2059. #else
  2060. if( ( ( TIMER() ) - nBoardTimer ) > 136UL ){
  2061. #endif
  2062. if( !nBoardIrq ){
  2063. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2064. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  2065. #endif
  2066. m_pBoard->AsyncReset();
  2067. WaitFZ = true;
  2068. Reading = false;
  2069. Writing = false;
  2070. };
  2071. nBoardTimer = TIMER();
  2072. nBoardIrq = 0;
  2073. }
  2074. // check board
  2075. uint8_t RetVal;
  2076. while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
  2077. if( RetVal == 2 ){
  2078. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2079. printf("DMA Transfers Overlaped\n");
  2080. #endif
  2081. // -----------------------
  2082. m_pBoard->AsyncReset();
  2083. WaitFZ = true;
  2084. Reading = false;
  2085. Writing = false;
  2086. break;
  2087. };
  2088. #ifdef RANGE_16BIT
  2089. #else
  2090. // perform linearization
  2091. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  2092. #ifdef LGS_MIRROR
  2093. nRange[1] = nRange[0];
  2094. #else
  2095. #ifdef LGS_PLS_1
  2096. nRange[1] = nRange[0];
  2097. #else
  2098. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  2099. #endif
  2100. #endif
  2101. #endif //16 bit
  2102. // update voltage state
  2103. m_Voltage.Invalidate( bPower );
  2104. // increase IRQ counter
  2105. nBoardTimer = TIMER();
  2106. nBoardIrq++;
  2107. //if(!Writing ){
  2108. //if( bZero && WaitFZ ){
  2109. // WaitFZ = false;
  2110. //Writing = false;
  2111. //};
  2112. if( !Reading && WaitFZ ){
  2113. if( bZero ){
  2114. CPointer = 0;
  2115. CAngle = 0;
  2116. Reading = true;
  2117. WaitFZ = false;
  2118. };
  2119. };
  2120. if( Reading ){
  2121. CAngle++;
  2122. #ifdef LGS_MIRROR
  2123. if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) )
  2124. #endif
  2125. {
  2126. #ifdef ALS_300
  2127. if( CAngle % 3 == 0 ){
  2128. if( bZero ) tbZero = true; //= ( CAngle == 3 ); // First Measure
  2129. if( bSun[nDevice] ) tbSun = true;
  2130. Buffer[bCInputArray][CPointer] += nRange[nDevice];
  2131. Buffer[bCInputArray][CPointer] = Buffer[bCInputArray][CPointer] / 3;
  2132. Buffer[bCInputArray][CPointer] |= (uint16_t)( ( bSun[nDevice] ? 1 << 11 : 0 ) | ( tbZero ? 1 << 12 : 0 ) );
  2133. CPointer++;
  2134. tbZero = false;
  2135. tbSun = false;
  2136. if( CPointer < LGS_MAX_DETECTOR_ANGLES ){
  2137. Buffer[bCInputArray][CPointer] = 0;
  2138. } else {
  2139. Buffer[bCInputArray][0] = 0;
  2140. };
  2141. } else {
  2142. Buffer[bCInputArray][CPointer] += nRange[nDevice];
  2143. if( bZero ) tbZero = true;
  2144. if( bSun[nDevice] ) tbSun = true;
  2145. continue;
  2146. };
  2147. #else
  2148. bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
  2149. Buffer[bCInputArray][CPointer] = (uint16_t)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  2150. CPointer++;
  2151. #endif
  2152. #if defined( LGS_REDUCED_PRF )
  2153. if( CPointer == (LGS_MAX_DETECTOR_ANGLES / LGS_PRF_REDUCE_RATIO) ){
  2154. #else
  2155. if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
  2156. #endif
  2157. bCInputArray = ( bCInputArray )? 0:1 ;
  2158. if( bCInputArray == bCOutputArray ){
  2159. Reading = false;
  2160. };
  2161. Writing = true;
  2162. CPointer = 0;
  2163. //OPointer = 0;
  2164. };
  2165. };
  2166. };
  2167. //};
  2168. };
  2169. if( Writing ){
  2170. #ifdef LGS_MIRROR
  2171. if( OPointer < 920 ){ //
  2172. #else
  2173. #ifdef LGS_PLS_1
  2174. #ifdef LGS_PLS_200
  2175. if( OPointer < LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2176. #else
  2177. if( OPointer < LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2178. #endif
  2179. #else
  2180. if( OPointer < LGS_MAX_DETECTOR_ANGLES ){
  2181. #endif
  2182. #endif
  2183. // add next 13 bits of data
  2184. #if defined( LGS_REDUCED_PRF )
  2185. DWORD dwData;
  2186. if( LGS_PRF_REDUCE_RATIO > 1 ){
  2187. if( ( Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] & (1<<12) ) && (( OPointer % LGS_PRF_REDUCE_RATIO ) != 0)){
  2188. Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] = Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] & ( ~(1<<12) );
  2189. };
  2190. dwData = Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO )];
  2191. } else {
  2192. dwData = Buffer[bCOutputArray][OPointer];
  2193. };
  2194. #else
  2195. DWORD dwData = (DWORD) Buffer[bCOutputArray][OPointer];
  2196. #endif
  2197. OPointer++;
  2198. if( Encoder.Encode24( dwData, 13 ) ){
  2199. // increase part number
  2200. nPart++;
  2201. // if number raw parts meets max parts
  2202. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
  2203. // prepare check sum in 14th byte of packet
  2204. uint8_t bCheckSum = 0;
  2205. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ ) bCheckSum += pData[i];
  2206. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  2207. // write into stream
  2208. m_pComm485->Write( pData, ( LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  2209. // Wait till all data is sent
  2210. m_pComm485->Flush();
  2211. cnt = 0;
  2212. //long cTT = TIMER();
  2213. //while( cnt==0 && cTT - TIMER() < 180 ){
  2214. // Read 1 Bytes from Line
  2215. // cnt = m_pComm485->ReadWithWait( CoBuffer, 1, 36 ); //2 seconds in measurements of 1\18
  2216. // if( cnt == 0 ) m_bRun = false;
  2217. // if( bCheckSum != CoBuffer[0] ) m_bRun = false;
  2218. //};
  2219. //delay(2);
  2220. // reset part
  2221. nPart = 0;
  2222. // zero memory
  2223. memset( pData, 0, ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 );
  2224. #ifdef COMM_WITHOUT_INTERRUPTS
  2225. m_pComm485->Invalidate();
  2226. //m_pCameraComm->Invalidate();
  2227. #endif
  2228. };
  2229. // restart encoder
  2230. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  2231. };
  2232. } else {
  2233. bCOutputArray = ( bCOutputArray )? 0: 1;
  2234. if( bCOutputArray == bCInputArray ){
  2235. Writing = false;
  2236. WaitFZ = true;
  2237. };
  2238. OPointer = 0;
  2239. SentScanCounter ++;
  2240. #ifndef SENDBOARDDATA_INF
  2241. if( SentScanCounter > 500 ){
  2242. //while(1);
  2243. return true;
  2244. };
  2245. #endif
  2246. };
  2247. };
  2248. };
  2249. return true;
  2250. }
  2251. #endif
  2252. #endif //COMPILE_RTSCANER
  2253. #else //COMPILE_3DSCANER
  2254. // DoSendBoardData For 3D Scanner
  2255. bool CKernel::DoSendBoardData( int16_t nDevice ){
  2256. #ifndef LGS_MIRROR
  2257. #ifdef LGS_PLS_1
  2258. nDevice = 0;
  2259. #else
  2260. nDevice = nDevice % 2;
  2261. #endif
  2262. #else
  2263. nDevice = nDevice % 4;
  2264. #endif
  2265. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  2266. return false;
  2267. DWORD nBoardIrq = 0;
  2268. DWORD nBoardTimer = TIMER();
  2269. bool bPower, bZero, bSun[2], Reading, Writing;
  2270. //DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
  2271. uint16_t Buffer[LGS_MAX_DETECTOR_ANGLES];
  2272. uint16_t CPointer = 0;
  2273. uint16_t OPointer = 0;
  2274. uint16_t CAngle = 0;
  2275. int16_t nRange[2];
  2276. uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
  2277. CLgBitCode Encoder( pData );
  2278. int16_t nPart = 0;
  2279. bool WaitFZ;
  2280. Reading = false;
  2281. Writing = false;
  2282. WaitFZ = true;
  2283. //nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
  2284. while( m_bRun ){
  2285. #ifdef WATCHDOG_ENABLED
  2286. if( g_bWatchDogEnable ){
  2287. // update watchdog timer
  2288. m_WatchDog.Update( TIMER() );
  2289. };
  2290. #endif
  2291. if( ( ( TIMER() ) - nBoardTimer ) > 36UL ){
  2292. if( !nBoardIrq ){
  2293. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2294. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  2295. #endif
  2296. // reset board
  2297. m_pBoard->AsyncReset();
  2298. WaitFZ = true;
  2299. Reading = false;
  2300. Writing = false;
  2301. };
  2302. nBoardTimer = TIMER();
  2303. nBoardIrq = 0;
  2304. }
  2305. // check board
  2306. uint8_t RetVal;
  2307. while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
  2308. if( RetVal == 2 ){
  2309. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  2310. printf("DMA Transfers Overlaped\n");
  2311. #endif
  2312. // -----------------------
  2313. m_pBoard->AsyncReset();
  2314. WaitFZ = true;
  2315. Reading = false;
  2316. Writing = false;
  2317. break;
  2318. };
  2319. // perform linearization
  2320. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  2321. #ifdef LGS_MIRROR
  2322. nRange[1] = nRange[0];
  2323. #else
  2324. #ifndef LGS_PLS_1
  2325. nRange[1] = nRange[0];
  2326. #else
  2327. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  2328. #endif
  2329. #endif
  2330. // update voltage state
  2331. m_Voltage.Invalidate( bPower );
  2332. // increase IRQ counter
  2333. nBoardTimer = TIMER();
  2334. nBoardIrq++;
  2335. if(!Writing ){
  2336. if( bZero && WaitFZ ){
  2337. WaitFZ = false;
  2338. Writing = false;
  2339. };
  2340. if( !WaitFZ ){
  2341. if( bZero ){
  2342. CPointer = 0;
  2343. CAngle = 0;
  2344. Reading = true;
  2345. } else {
  2346. CAngle++;
  2347. };
  2348. };
  2349. if( Reading ){
  2350. if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) ){
  2351. bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
  2352. //nRange[nDevice]
  2353. //Buffer[CPointer] = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  2354. Buffer[CPointer] = (uint16_t)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  2355. CPointer++;
  2356. if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
  2357. Reading = false;
  2358. Writing = true;
  2359. OPointer = 0;
  2360. };
  2361. };
  2362. };
  2363. };
  2364. };
  2365. if( Writing ){
  2366. // increase IRQ counter
  2367. nBoardTimer = TIMER();
  2368. nBoardIrq++;
  2369. // add next 13 bits of data
  2370. #ifdef LGS_PLS_200
  2371. DWORD dwData;
  2372. if( LGS_PRF_REDUCE_RATIO > 1 ){
  2373. if( ( Buffer[(OPointer >> 1)] & (1<<12) ) && (( OPointer % 2 ) != 0)){
  2374. Buffer[(OPointer >> 1)] = Buffer[(OPointer >> 1)] & ( ~(1<<12) );
  2375. };
  2376. dwData = Buffer[(OPointer >> 1)];
  2377. } else {
  2378. dwData = Buffer[OPointer];
  2379. };
  2380. #else
  2381. DWORD dwData = Buffer[OPointer];
  2382. #endif
  2383. OPointer++;
  2384. #ifdef LGS_MIRROR
  2385. if( OPointer == 916 ){ //
  2386. #else
  2387. #ifdef LGS_PLS_1
  2388. #ifdef LGS_PLS_200
  2389. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2390. #else
  2391. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
  2392. #endif
  2393. #else
  2394. if( OPointer == LGS_MAX_DETECTOR_ANGLES ){
  2395. #endif
  2396. #endif
  2397. Writing = false;
  2398. //WaitFZ = true;
  2399. continue;
  2400. };
  2401. if( Encoder.Encode24( dwData, 13 ) ){
  2402. // increase part number
  2403. nPart++;
  2404. // if number raw parts meets max parts
  2405. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
  2406. // prepare check sum in 14th byte of packet
  2407. uint8_t bCheckSum = 0;
  2408. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
  2409. bCheckSum += pData[i];
  2410. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  2411. // write into stream
  2412. m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  2413. delay( 2 );
  2414. // reset part
  2415. nPart = 0;
  2416. // zero memory
  2417. memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
  2418. #ifdef COMM_WITHOUT_INTERRUPTS
  2419. m_pComm485->Invalidate();
  2420. //m_pCameraComm->Invalidate();
  2421. #endif
  2422. }
  2423. // restart encoder
  2424. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  2425. };
  2426. };
  2427. };
  2428. return true;
  2429. }
  2430. #endif
  2431. /////////////////////// FILE SYSTEM REQUESTS HANDLERS //////////////////////////
  2432. #ifndef LGS_DISABLE_FILE_SYSTEM
  2433. /*
  2434. LG_FS_RESULT CKernel::DoOpenFile( PLG_FS_PATH pName ){
  2435. if( m_pFSFileHandle != NULL ) fclose( m_pFSFileHandle );
  2436. m_pFSFileHandle = fopen( pName->pBuffer, "rb" );
  2437. if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2438. return LG_FS_RESULT_SUCCESS;
  2439. };
  2440. LG_FS_RESULT CKernel::DoReadFile( PBYTE pRead, uint8_t bSize, PBYTE pBuffer ){
  2441. if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2442. *pRead = fread( pBuffer, 1, bSize, m_pFSFileHandle );
  2443. return LG_FS_RESULT_SUCCESS;
  2444. };
  2445. LG_FS_RESULT CKernel::DoCloseFile( void ){
  2446. if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2447. fclose( m_pFSFileHandle );
  2448. return LG_FS_RESULT_SUCCESS;
  2449. };
  2450. LG_FS_RESULT CKernel::DoGetCurrentDirectory( PLG_FS_PATH pPath ){
  2451. if( getcwd( pPath->pBuffer, 256 )!= NULL ){
  2452. pPath->pBuffer[255]=(char)0;
  2453. // sprintf( pPath->pBuffer, "KOKO256" );
  2454. pPath->nSize = strlen( pPath->pBuffer );
  2455. return LG_FS_RESULT_SUCCESS;
  2456. };
  2457. pPath->pBuffer[0]=(char)0;
  2458. pPath->nSize = 0;
  2459. return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
  2460. };
  2461. struct ffblk g_ffBlock;
  2462. LG_FS_RESULT CKernel::DoFindFirst( PDWORD pHandle, PLG_FS_PATH pPath, PLG_FS_FIND_DATA pFindData )
  2463. {
  2464. // add termination 0
  2465. TCHAR pPathWithNull[MAX_PATH];
  2466. memcpy( pPathWithNull, pPath->pBuffer, pPath->nSize );
  2467. pPathWithNull[ pPath->nSize ] = 0;
  2468. // open find first
  2469. if( findfirst( pPathWithNull, &g_ffBlock, FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_DIREC | FA_ARCH ) == 0 )
  2470. {
  2471. g_ffBlock.ff_attrib;
  2472. pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
  2473. ( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
  2474. ( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
  2475. ( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
  2476. ( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
  2477. pFindData->dwFileSizeHigh = 0;
  2478. pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
  2479. pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
  2480. memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
  2481. *pHandle = 0;
  2482. return LG_FS_RESULT_SUCCESS;
  2483. }
  2484. *pHandle = LG_FS_INVALID_HANDLE;
  2485. return LG_FS_RESULT_ERROR_NO_MORE_FILES;
  2486. }
  2487. LG_FS_RESULT CKernel::DoFindNext( DWORD dwHandle, PLG_FS_FIND_DATA pFindData )
  2488. {
  2489. dwHandle;
  2490. // open find first
  2491. if( findnext( &g_ffBlock ) == 0 )
  2492. {
  2493. pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
  2494. ( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
  2495. ( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
  2496. ( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
  2497. ( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
  2498. pFindData->dwFileSizeHigh = 0;
  2499. pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
  2500. pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
  2501. memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
  2502. return LG_FS_RESULT_SUCCESS;
  2503. }
  2504. return LG_FS_RESULT_ERROR_NO_MORE_FILES;
  2505. }
  2506. LG_FS_RESULT CKernel::DoFindClose( DWORD dwHandle )
  2507. {
  2508. dwHandle;
  2509. return LG_FS_RESULT_SUCCESS;
  2510. }
  2511. */
  2512. #endif
  2513. void CKernel::OnCmdState2( PBYTE &pReadBufferPtr, int16_t &nReadCount, PBYTE &pSendBufferPtr, int16_t &nSendCount, uint8_t &nMode, bool &bBoardNoIrq )
  2514. {
  2515. // build CMD_STATE_2 command
  2516. *pSendBufferPtr++ = LGS::CMD_STATE_2;
  2517. // if mode is wrong
  2518. if( nMode != LGS::MODE_DETECTOR )
  2519. {
  2520. // build reply
  2521. nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, LGS::S2_ITF_ERROR_MODE );
  2522. return;
  2523. }
  2524. uint8_t bRequestType = LGS::S2_RT_TARGET_POLAR;
  2525. if( nReadCount )
  2526. nReadCount -= LGS::GetCmdState2( pReadBufferPtr, &bRequestType );
  2527. // flags
  2528. uint8_t bFlags = 0;
  2529. #ifndef NO_LIC
  2530. // If Work is Disabled then ...
  2531. /*
  2532. if (! m_pBoard->workingEnabled() ){
  2533. int16_t nErrorAngle = 2222;
  2534. if ( ( TIMER() - m_dwTimeErrorDelay_EA ) > MSEC_TO_TIME( 2000UL ) ) {
  2535. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2536. m_dwTimeErrorDelay_EA = TIMER();
  2537. };
  2538. if( m_nInitErrorSkipCounter ) m_nInitErrorSkipCounter --;
  2539. };
  2540. */
  2541. #endif
  2542. // check for ANGLE and ZERO MARK errors
  2543. #ifdef LGS_MIRROR
  2544. if( g_bShowErrors ){
  2545. for( int16_t i = 0; i < 4; i++){
  2546. if( m_Detector[i].GetLastErrorAngle() ){
  2547. int16_t nErrorAngle = m_Detector[i].GetLastErrorAngleValue();
  2548. if( ( nErrorAngle == 1111 || nErrorAngle == 387 || nErrorAngle == 1112 || nErrorAngle == 386 ) && m_pBoard->workingEnabled() ){
  2549. // Trying to fixup Certificate trouble
  2550. m_bRun = false; // Error Sending SN to Board -> Restart
  2551. };
  2552. if ( ( ( TIMER() - m_dwTimeErrorDelay_EA ) < MSEC_TO_TIME( 200UL ) ) || !g_bDelayErrors ) {
  2553. if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
  2554. if( nErrorAngle == -1 ){
  2555. bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
  2556. } else {
  2557. if( ( nErrorAngle == 1111 || nErrorAngle == 387 || nErrorAngle == 1112 || nErrorAngle == 386 ) && m_pBoard->workingEnabled() ){
  2558. if( g_bShowErrors ){
  2559. // Because of ZeroShift the ErrorAngle must be corrected to 1111 after getting 387
  2560. nErrorAngle = 1111;
  2561. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2562. };
  2563. //m_bRun = false; // Error Sending SN to Board -> Restart
  2564. } else if( ( nErrorAngle > 0 ) && ( nErrorAngle < ( LGS_REAL_DETECTOR_ANGLES - 5 ) ) ){
  2565. if( g_bShowErrors ){
  2566. nErrorAngle += (i+1)*10000;
  2567. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2568. };
  2569. };
  2570. };
  2571. m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
  2572. } else m_nInitErrorSkipCounter --;
  2573. };
  2574. m_dwTimeErrorDelay_EA = TIMER();
  2575. };
  2576. };
  2577. };
  2578. #else//!LGS_MIRROR
  2579. if( g_bShowErrors && m_Detector[0].GetLastErrorAngle() ){
  2580. int16_t nErrorAngle = m_Detector[0].GetLastErrorAngleValue();
  2581. if ( ( ( TIMER() - m_dwTimeErrorDelay_EA ) < MSEC_TO_TIME( 200UL ) ) || !g_bDelayErrors ) {
  2582. if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
  2583. if( nErrorAngle == -1 ){
  2584. bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
  2585. } else {
  2586. /* if( ( nErrorAngle == 1111 ) && m_pBoard->workingEnabled() ){
  2587. m_bRun = false; // Error Sending SN to Board -> Restart
  2588. } else */
  2589. if( ( nErrorAngle > 0 ) && ( nErrorAngle < ( LGS_REAL_DETECTOR_ANGLES - 5 ) ) ){
  2590. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  2591. };
  2592. };
  2593. m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
  2594. } else m_nInitErrorSkipCounter --;
  2595. };
  2596. m_dwTimeErrorDelay_EA = TIMER();
  2597. };
  2598. #endif
  2599. // check for NO IRQ
  2600. if( g_bShowErrors && bBoardNoIrq ) {
  2601. //if ( ( ( TIMER() - m_dwTimeErrorDelay_IQ ) < 200UL ) || !g_bDelayErrors ) {
  2602. // if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
  2603. bFlags |= LGS::S2_ITF_ERROR_NO_IRQ;
  2604. //m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
  2605. //printf("Error Sent\n");
  2606. // } else {
  2607. // m_nInitErrorSkipCounter --;
  2608. // //printf("Decreased Init Skip Value [%d]\n",m_nInitErrorSkipCounter);
  2609. // };
  2610. // };
  2611. //m_dwTimeErrorDelay_IQ = TIMER();
  2612. // clear no irq flag
  2613. #ifndef RESTART_ON_NO_IRQ
  2614. bBoardNoIrq = false;
  2615. #endif
  2616. };
  2617. // check for POWER changes
  2618. if( g_bShowErrors ) m_Voltage.OnProtocolLgsState2Command( bFlags );
  2619. #ifndef EMBEDDED_CAMERA_DISABLE
  2620. #ifndef NO_EMBED_CAMERA
  2621. // add camera flags
  2622. m_pCamera->OnProtocolLgsState2Command( bFlags );
  2623. #endif
  2624. #endif
  2625. // apply flags
  2626. if( bFlags ) nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, bFlags );
  2627. /* Old Sergey's for( int i = 0; i < 2; i++ )
  2628. {
  2629. CDetector *pDetector = m_Detector + i;
  2630. #ifdef LGS_MIRROR
  2631. CTracker *pTracker = m_Tracker + 0;
  2632. #else
  2633. CTracker *pTracker = m_Tracker + i;
  2634. #endif */
  2635. #ifdef LGS_MIRROR
  2636. for( int i = 0; i < 4; i++ ){
  2637. CDetector *pDetector = &m_Detector[i];
  2638. CTracker *pTracker = &m_Tracker[0];
  2639. #else //!LGS_MIRROR
  2640. #ifdef LGS_PLS_1
  2641. {
  2642. int i = 0;
  2643. #else
  2644. for( int i = 0; i < 2; i++ ){
  2645. #endif
  2646. CDetector *pDetector = &m_Detector[i];
  2647. CTracker *pTracker = &m_Tracker[i];
  2648. #endif
  2649. // assume that no errors
  2650. uint8_t bDeviceFlags = 0;
  2651. // check for tracker overflow
  2652. if( ( m_dwTimeErrorOverflow[i] < TIMER() ) && pTracker->GetLastErrorOverflow() )
  2653. {
  2654. m_dwTimeErrorOverflow[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2655. bDeviceFlags |= LGS::S2_ITDF_ERROR_OVERFLOW;
  2656. }
  2657. // check for tracker scan to scan overflow
  2658. if( ( m_dwTimeErrorOverflowSST[i] < TIMER() ) && pTracker->GetLastErrorOverflowSST() )
  2659. {
  2660. m_dwTimeErrorOverflowSST[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2661. bDeviceFlags |= LGS::S2_ITDF_ERROR_SST_OVERFLOW;
  2662. }
  2663. // check for detector sun errors
  2664. if( ( m_dwTimeErrorSun[i] < TIMER() ) && pDetector->GetLastErrorSun() )
  2665. {
  2666. m_dwTimeErrorSun[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  2667. bDeviceFlags |= LGS::S2_ITDF_ERROR_SUN;
  2668. }
  2669. // apply device flags
  2670. if( g_bShowErrors && bDeviceFlags )
  2671. nSendCount += LGS::BuildEvtState2DeviceFlags( pSendBufferPtr, i, bDeviceFlags );
  2672. // place target information
  2673. CTracker::TARGET target;
  2674. while( ( pTracker->GetTarget( &target )
  2675. #ifndef NO_LIC
  2676. && m_pBoard->workingEnabled()
  2677. #endif
  2678. #ifdef DEBUG_TARGET_SIMULATOR
  2679. ) || bFireSimulatedTarget
  2680. #else
  2681. )
  2682. #endif
  2683. )
  2684. {
  2685. #ifdef DEBUG_TARGET_SIMULATOR
  2686. if( bFireSimulatedTarget ){
  2687. target.bType = LGS::TT_NORMAL;
  2688. target.nRange = 200;
  2689. target.nAngle = ( 3000* nSimulatedTargetID )/360 ;//145; GP2Y0A700K
  2690. target.nWidth = nSimulatedTargetValue;
  2691. bFireSimulatedTarget = false;
  2692. };
  2693. #endif
  2694. uint8_t bType;
  2695. switch( target.bType )
  2696. {
  2697. case LGS::TT_WIDE:
  2698. case LGS::TT_NORMAL:
  2699. bType = ( target.bType == LGS::TT_NORMAL ) ? LGS::S2_ITT_NORMAL : LGS::S2_ITT_WIDE;
  2700. if( ( bRequestType & LGS::S2_RT_TARGET_MASK ) == LGS::S2_RT_TARGET_DEKART )
  2701. {
  2702. #ifdef LGS_MIRROR
  2703. #ifdef LGS_MND
  2704. const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
  2705. double a = ( target.nAngle << 2 ) * a2r;
  2706. #else
  2707. const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
  2708. double a = ( target.nAngle << 1 ) * a2r;
  2709. #endif
  2710. #else //LGS_MIRROR
  2711. const double a2r = asin(1.0) * 4.0 / LGS_MAX_DETECTOR_ANGLES;
  2712. double a = ( target.nAngle ) * a2r;
  2713. #endif
  2714. #ifdef ALS_300_BM
  2715. target.nAngle = ( int16_t ) (( target.nAngle * 6000.0f ) / 20000.0f ); //Convert Angle from 20000 to 6000
  2716. #endif
  2717. int16_t x = target.nRange * cos( a );
  2718. int16_t y = target.nRange * sin( a );
  2719. #if defined( LGS_MIRROR ) || defined( LGS_MND )
  2720. #ifdef LGS_MND
  2721. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2722. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth << 2 ) :
  2723. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2724. #else
  2725. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2726. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth ) :
  2727. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2728. #endif
  2729. #else
  2730. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2731. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth )://<< 1 ) :
  2732. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  2733. #endif
  2734. } else {
  2735. #ifdef ALS_300_BM
  2736. target.nAngle = ( int16_t ) (( target.nAngle * 6000.0f ) / 20000.0f ); //Convert Angle from 20000 to 6000
  2737. #endif
  2738. #ifdef LGS_MIRROR
  2739. #ifdef LGS_MND
  2740. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2741. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange, target.nWidth << 2 ) : // ? Wx2 ??
  2742. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange );
  2743. #else
  2744. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2745. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange, target.nWidth )://<< 1 ) : // ? Wx2 ??
  2746. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange );
  2747. #endif
  2748. #else // !LGS_MIRROR
  2749. #ifdef LGS_REDUCED_PRF
  2750. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2751. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
  2752. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
  2753. #else
  2754. #ifdef __ALS_300 //(target.nAngle<<2)/5
  2755. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2756. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3, target.nWidth ) :
  2757. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3 );
  2758. #else
  2759. // ALS_300_BM
  2760. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  2761. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
  2762. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
  2763. #endif
  2764. #endif
  2765. #endif
  2766. };
  2767. break;
  2768. case LGS::TT_FLIP:
  2769. nSendCount += LGS::BuildEvtState2Flip( pSendBufferPtr, i, target.nAngle );
  2770. break;
  2771. case LGS::TT_BLIND:
  2772. if( ( target.nAngle < LGS_BLIND_TYPE_FAR_FOG_ENTER ) && ( !g_bShowErrors || g_bHideFogError ) ) break;
  2773. switch( target.nAngle )
  2774. {
  2775. case LGS_BLIND_TYPE_MR_ENTER:
  2776. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_MEDIUM_RANGE );
  2777. break;
  2778. case LGS_BLIND_TYPE_MR_EXIT:
  2779. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_MEDIUM_RANGE );
  2780. break;
  2781. case LGS_BLIND_TYPE_180_DEGRESE_ENTER:
  2782. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_180_DEGREE );
  2783. break;
  2784. case LGS_BLIND_TYPE_180_DEGRESE_EXIT:
  2785. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_180_DEGREE );
  2786. break;
  2787. case LGS_BLIND_TYPE_FS_ENTER:
  2788. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FOG_SPIKES );
  2789. break;
  2790. case LGS_BLIND_TYPE_FS_EXIT:
  2791. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FOG_SPIKES );
  2792. break;
  2793. case LGS_BLIND_TYPE_PD_ENTER:
  2794. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_PD );
  2795. break;
  2796. case LGS_BLIND_TYPE_PD_EXIT:
  2797. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_PD );
  2798. break;
  2799. case LGS_BLIND_TYPE_FAR_FOG_ENTER:
  2800. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FAR_FOG );
  2801. break;
  2802. case LGS_BLIND_TYPE_FAR_FOG_EXIT:
  2803. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FAR_FOG );
  2804. break;
  2805. case LGS_BLIND_TYPE_NEAR_FOG_ENTER:
  2806. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_NEAR_FOG );
  2807. break;
  2808. case LGS_BLIND_TYPE_NEAR_FOG_EXIT:
  2809. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_NEAR_FOG );
  2810. break;
  2811. }
  2812. break;
  2813. // case LGS::TT_CAMERA:
  2814. // break;
  2815. // case LGS::TT_TEST:
  2816. // break;
  2817. }
  2818. if( nSendCount >= 20 )
  2819. break;
  2820. }
  2821. #ifndef LGS_PLS_1
  2822. if( nSendCount >= 20 ) break;
  2823. #endif
  2824. }
  2825. }
  2826. void CKernel::OnCmdGetWidthTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2827. {
  2828. // unused variables
  2829. pReadBufferPtr; nReadCount;
  2830. // build CMD_GET_WIDHT_TABLE command
  2831. *pSendBufferPtr++ = LGS::CMD_GET_WIDTH_TABLE;
  2832. PLONG pNativeTable = m_Detector[0].GetFilterWidth()->GetTable();
  2833. // prepare table
  2834. LGS::WIDTH_TABLE table;
  2835. table.nCount = LGS::WIDTH_TABLE_SIZE;
  2836. for( int16_t i = 0; i < LGS::WIDTH_TABLE_SIZE; i++ )
  2837. table.pTable[i] = ( pNativeTable[i] * 100L ) >> 7;
  2838. // write command
  2839. nSendCount += LGS::BuildEvtGetWidthTable( pSendBufferPtr, &table );
  2840. }
  2841. void CKernel::OnCmdSetWidthTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2842. {
  2843. // build CMD_SET_WIDHT_TABLE command
  2844. *pSendBufferPtr++ = LGS::CMD_SET_WIDTH_TABLE;
  2845. // read table
  2846. LGS::WIDTH_TABLE table;
  2847. nReadCount -= LGS::GetCmdSetWidthTable( pReadBufferPtr, &table );
  2848. FILE *pFile = fopen( "width.ini", "wt" );
  2849. if( pFile )
  2850. {
  2851. for( int16_t i = 0; i < table.nCount; i++ )
  2852. fprintf( pFile, "%d ", table.pTable[i] );
  2853. fclose( pFile );
  2854. }
  2855. // write command
  2856. nSendCount += LGS::BuildEvtSetWidthTable( pSendBufferPtr, &table );
  2857. // restart program
  2858. m_bRun = false;
  2859. }
  2860. void CKernel::OnCmdGetZoomTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2861. {
  2862. // unused variables
  2863. pReadBufferPtr; nReadCount;
  2864. // build CMD_GET_WIDHT_TABLE command
  2865. *pSendBufferPtr++ = LGS::CMD_GET_ZOOM_TABLE;
  2866. #ifndef NO_EMBED_CAMERA
  2867. // write command
  2868. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  2869. #else
  2870. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
  2871. #endif
  2872. }
  2873. void CKernel::OnCmdSetZoomTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2874. {
  2875. // build CMD_SET_WIDHT_TABLE command
  2876. *pSendBufferPtr++ = LGS::CMD_SET_ZOOM_TABLE;
  2877. #ifndef NO_EMBED_CAMERA
  2878. // read table
  2879. nReadCount -= LGS::GetZoomTable( pReadBufferPtr, &m_pCamera->GetZoomTable() );
  2880. // write command
  2881. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  2882. #else
  2883. // write command
  2884. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
  2885. #endif
  2886. }
  2887. void CKernel::OnCmdGetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2888. {
  2889. // unused variables
  2890. pReadBufferPtr; nReadCount;
  2891. // build CMD_GET_WIDHT_TABLE command
  2892. *pSendBufferPtr++ = LGS::CMD_GET_TILT_TABLE;
  2893. #ifndef NO_EMBED_CAMERA
  2894. // write command
  2895. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  2896. #else
  2897. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
  2898. #endif
  2899. }
  2900. void CKernel::OnCmdSetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2901. {
  2902. // build CMD_SET_WIDHT_TABLE command
  2903. *pSendBufferPtr++ = LGS::CMD_SET_TILT_TABLE;
  2904. #ifndef NO_EMBED_CAMERA
  2905. // read table
  2906. nReadCount -= LGS::GetTiltTable( pReadBufferPtr, &m_pCamera->GetTiltTable() );
  2907. // write command
  2908. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  2909. #else
  2910. // write command
  2911. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
  2912. #endif
  2913. }
  2914. void CKernel::OnCmdGetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2915. {
  2916. // read table
  2917. uint8_t nDevice = *pReadBufferPtr++;
  2918. nReadCount --;
  2919. // build CMD_GET_LINEARIZATION_TABLE command
  2920. *pSendBufferPtr++ = LGS::CMD_GET_CALIBRATION_TABLE;
  2921. *pSendBufferPtr++ = nDevice;
  2922. nSendCount++;
  2923. #ifndef RANGE_16BIT
  2924. // process command
  2925. m_Calibrator[nDevice?1:0].OnCmdGetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  2926. #endif // 16 bit
  2927. }
  2928. bool CKernel::OnCmdSetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount, int16_t& nDevice )
  2929. {
  2930. // read table
  2931. nDevice = *pReadBufferPtr++;
  2932. nReadCount --;
  2933. // build CMD_SET_LINEARIZATION_TABLE command
  2934. *pSendBufferPtr++ = LGS::CMD_SET_CALIBRATION_TABLE;
  2935. *pSendBufferPtr++ = nDevice;
  2936. nSendCount++;
  2937. #ifndef RANGE_16BIT
  2938. // process command
  2939. return m_Calibrator[nDevice?1:0].OnCmdSetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  2940. #endif // 16 bit
  2941. }
  2942. void CKernel::OnCmdGetLrfDisable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2943. {
  2944. // unused variables
  2945. pReadBufferPtr; nReadCount;
  2946. // build CMD_GET_LRF_DISABLE command
  2947. *pSendBufferPtr++ = LGS::CMD_GET_LRF_DISABLE;
  2948. // write command
  2949. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  2950. }
  2951. void CKernel::OnCmdSetLrfDisable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
  2952. {
  2953. // read table
  2954. nReadCount -= LGS::GetLRFDisable( pReadBufferPtr, &m_LRFDisable );
  2955. #ifndef NO_EMBED_CAMERA
  2956. // store serial number
  2957. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  2958. #else
  2959. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  2960. #endif
  2961. // build CMD_SET_LRF_DISABLE command
  2962. *pSendBufferPtr++ = LGS::CMD_SET_LRF_DISABLE;
  2963. // write command
  2964. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  2965. // restart program
  2966. m_bRun = false;
  2967. }
  2968. typedef enum E_SETTING_TYPE {
  2969. ST_NONE = -1,
  2970. ST_SN = 0,
  2971. ST_ADDRESS,
  2972. ST_CAMERA_TYPE,
  2973. ST_CAMERA_SHIFT,
  2974. ST_CAMERA_AUTO,
  2975. ST_CAMERA_DELAY,
  2976. ST_RELAY_NC,
  2977. ST_RELAY_AUTO,
  2978. ST_RELAY_DELAY,
  2979. ST_VOLTAGE_CONTROL,
  2980. ST_MASTER_DISABLED,
  2981. ST_SLAVE_DISABLED,
  2982. ST_AUTORESET_ENABLE,
  2983. ST_AUTORESET_INTERLEAVE,
  2984. ST_AUTORESET_TIMEOUT,
  2985. ST_BOARD_TEMPERATURE,
  2986. ST_BOARD_ZEROSHIFT,
  2987. ST_BOARD_ENCODERSTEPS,
  2988. ST_BOARD_GEARRATIO,
  2989. ST_BOARD_MAXRANGE,
  2990. ST_BOARD_SPEED,
  2991. ST_BOARD_HID,
  2992. ST_SWITCHER_TABLE,
  2993. ST_SWITCHER_REPLY_TIMEOUT,
  2994. ST_SWITCHER_COMMAND_TIMEOUT,
  2995. ST_SWITCHER_AUTO_MODE,
  2996. ST_SWITCHER_AUTO_ENTER_TIMEOUT,
  2997. ST_SWITCHER_AUTO_SWITCH_TIMEOUT,
  2998. ST_NO_BLACK_TARGET_DETECTION,
  2999. ST_JUST_MOVING_TARGETS_DETECTION,
  3000. ST_JUST_MOVING_RADIAL_PARAM,
  3001. ST_JUST_MOVING_DISTANCE_PARAM,
  3002. ST_BLIND_ST_ANGLE,
  3003. ST_BLIND_ED_ANGLE,
  3004. ST_BLIND_ST_RANGE,
  3005. ST_BLIND_ED_RANGE,
  3006. ST_BLIND_WIDTH,
  3007. ST_BLIND_DEPTH,
  3008. ST_BLIND_ANGLE,
  3009. ST_BLIND_RANGE,
  3010. #ifdef STORE_FIRST_SAF
  3011. ST_FREEZ_FIRST_SAF,
  3012. ST_SAF_FILE_ENABLE,
  3013. #endif
  3014. ST_SETTING_COUNT
  3015. } SETTING_TYPE;
  3016. LPCTSTR m_pSetting[] =
  3017. {
  3018. { "SN" },
  3019. { "ADDRESS" },
  3020. { "CAMERA_TYPE" },
  3021. { "CAMERA_SHIFT" },
  3022. { "CAMERA_AUTO" },
  3023. { "CAMERA_DELAY" },
  3024. { "RELAY_NC" },
  3025. { "RELAY_AUTO" },
  3026. { "RELAY_DELAY" },
  3027. { "VOLTAGE_CONTROL" },
  3028. { "MASTER_DISABLED" },
  3029. { "SLAVE_DISABLED" },
  3030. { "AUTORESET_ENABLE" },
  3031. { "AUTORESET_INTERLEAVE" },
  3032. { "AUTORESET_TIMEOUT" },
  3033. { "BOARD_TEMPERATURE" },
  3034. { "BOARD_ZEROSHIFT" },
  3035. { "BOARD_ENCODERSTEPS" },
  3036. { "BOARD_GEARRATIO" },
  3037. { "BOARD_MAXRANGE" },
  3038. { "BOARD_SPEED" },
  3039. { "RUN_DIR" },
  3040. { "SWITCHER_TABLE" },
  3041. { "SWITCHER_REPLY_TIMEOUT" },
  3042. { "SWITCHER_COMMAND_TIMEOUT" },
  3043. { "SWITCHER_AUTO_MODE" },
  3044. { "SWITCHER_AUTO_ENTER_TIMEOUT" },
  3045. { "SWITCHER_AUTO_SWITCH_TIMEOUT" },
  3046. { "NO_BLACK_TARGETS" },
  3047. { "JUST_MOVING_TARGETS" },
  3048. { "JUST_MOVING_RADIAL" },
  3049. { "JUST_MOVING_DISTANCE" },
  3050. { "BLIND_ZONE_START_ANGLE" },
  3051. { "BLIND_ZONE_END_ANGLE" },
  3052. { "BLIND_ZONE_START_RANGE" },
  3053. { "BLIND_ZONE_END_RANGE" },
  3054. { "BLIND_ZONE_WIDTH" },
  3055. { "BLIND_ZONE_DEPTH" },
  3056. { "BLIND_ZONE_ANGLE" },
  3057. { "BLIND_ZONE_RANGE" }
  3058. #ifdef STORE_FIRST_SAF
  3059. ,{ "FREEZ_FIRST_TH" }
  3060. ,( "SAVE_FIRST_TH" )
  3061. #endif
  3062. };
  3063. 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 ){
  3064. // read serial number
  3065. FILE *pFile = fopen( "SN.INI", "rt" );
  3066. if( !pFile ) {
  3067. // fill with default sn
  3068. *pSerialNumberSize = 14;
  3069. memcpy( pSerialNumber, "NOSERIALNUMBER", *pSerialNumberSize );
  3070. return false;
  3071. };
  3072. CHAR pLine[MAX_PATH];
  3073. while( fgets( pLine, MAX_PATH, pFile ) ){
  3074. SETTING_TYPE eType = ST_NONE;
  3075. PCHAR pTemp = NULL;
  3076. for( int i = 0; i < ST_SETTING_COUNT; i++ ){
  3077. pTemp = strstr( pLine, m_pSetting[i] );
  3078. if( pTemp ){
  3079. eType = (SETTING_TYPE)i;
  3080. pTemp = strstr( pTemp, "=" );
  3081. if( pTemp ) pTemp = strtok( pTemp + 1, " \t\n\r" );
  3082. break;
  3083. };
  3084. };
  3085. if( eType == ST_NONE || pTemp == NULL ) continue;
  3086. switch( eType ) {
  3087. case ST_SN: *pSerialNumberSize = strlen( pTemp ); memcpy( pSerialNumber, pTemp, *pSerialNumberSize ); break;
  3088. case ST_ADDRESS: *pAddress = (uint8_t)atoi( pTemp ); break;
  3089. #ifndef NO_EMBED_CAMERA
  3090. case ST_CAMERA_TYPE: if( pCameraParameters ) pCameraParameters->eType = (LGS::E_CAMERA_TYPE)atoi( pTemp ); break;
  3091. case ST_CAMERA_SHIFT: if( pCameraParameters ) pCameraParameters->nShift = (uint16_t)atoi( pTemp ); break;
  3092. case ST_CAMERA_AUTO: if( pCameraParameters ) pCameraParameters->bAuto = (uint8_t)atoi( pTemp ); break;
  3093. case ST_CAMERA_DELAY: if( pCameraParameters ) pCameraParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
  3094. #endif
  3095. case ST_RELAY_NC: pRelayParameters->bNormallyClose = (uint8_t)atoi( pTemp ); break;
  3096. case ST_RELAY_AUTO: pRelayParameters->bAuto = (uint8_t)atoi( pTemp ); break;
  3097. case ST_RELAY_DELAY: pRelayParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
  3098. case ST_VOLTAGE_CONTROL: pVoltageParameters->bControl = (uint8_t) atoi( pTemp ); break;
  3099. case ST_MASTER_DISABLED: if( pLRFDisable ) pLRFDisable->bMaster = (uint8_t)atoi( pTemp ); break;
  3100. #ifndef LGS_PLS_1
  3101. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (uint8_t)atoi( pTemp ); break;
  3102. #else
  3103. #ifdef INFINITE_SAF_STUDY
  3104. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (uint8_t)atoi( pTemp ); break;
  3105. #else
  3106. case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = 1; break;
  3107. #endif
  3108. #endif
  3109. case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (uint8_t)atoi( pTemp ); break;
  3110. case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
  3111. case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
  3112. case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
  3113. case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = (int16_t)atoi( pTemp ); break;
  3114. case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = (int16_t)atoi( pTemp ); break;
  3115. case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = (int16_t)atoi( pTemp ); break;
  3116. case ST_BLIND_ED_RANGE:m_nBZERangeFilter = (int16_t)atoi( pTemp ); break;
  3117. #ifdef STORE_FIRST_SAF
  3118. case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = (bool)atoi( pTemp ); break;
  3119. case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = (bool)atoi( pTemp ); break;
  3120. #endif
  3121. }
  3122. }
  3123. fclose( pFile );
  3124. return true;
  3125. }
  3126. bool CKernel::SaveSettings( LPCTSTR pSerialNumber, int16_t nAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable ){
  3127. FILE *pFile = fopen( "SN.INI", "wt" );
  3128. if( !pFile )
  3129. return false;
  3130. LPCTSTR pFormatStr = "%s = %s\n";
  3131. LPCTSTR pFormatInt = "%s = %d\n";
  3132. fprintf( pFile, pFormatStr, m_pSetting[ST_SN], pSerialNumber );
  3133. fprintf( pFile, pFormatInt, m_pSetting[ST_ADDRESS], nAddress );
  3134. #ifndef NO_EMBED_CAMERA
  3135. if( pCameraParameters ) {
  3136. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_TYPE], pCameraParameters->eType );
  3137. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_SHIFT], pCameraParameters->nShift );
  3138. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_AUTO], pCameraParameters->bAuto );
  3139. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_DELAY], pCameraParameters->nAutoDelay );
  3140. };
  3141. #endif
  3142. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_AUTO], pRelayParameters->bAuto );
  3143. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_DELAY], pRelayParameters->nAutoDelay );
  3144. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_NC], pRelayParameters->bNormallyClose );
  3145. fprintf( pFile, pFormatInt, m_pSetting[ST_VOLTAGE_CONTROL], pVoltageParameters->bControl );
  3146. if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_MASTER_DISABLED], pLRFDisable->bMaster );
  3147. #ifndef LFS_PLS_1
  3148. if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], pLRFDisable->bSlave );
  3149. #else
  3150. fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], true );
  3151. #endif
  3152. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3153. if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
  3154. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
  3155. } else {
  3156. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
  3157. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
  3158. };
  3159. #ifdef STORE_FIRST_SAF
  3160. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3161. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3162. #endif
  3163. fclose( pFile );
  3164. return true;
  3165. }
  3166. bool CKernel::LoadUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3167. int16_t tWidth = 0;
  3168. int16_t tDepth = 0;
  3169. int16_t tAngle = 0;
  3170. int16_t tRange = 0;
  3171. pSwitcher->pTable[0] = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4;
  3172. pSwitcher->pTable[1] = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4;
  3173. pSwitcher->pTable[2] = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4;
  3174. pSwitcher->nReplyTimeout = 100L;
  3175. pSwitcher->nCommandTimeout = 500L;
  3176. pSwitcher->nAutoMode = 0;
  3177. pSwitcher->nAutoEnterTimeout = 60;
  3178. pSwitcher->nAutoSwitchTimeout = 3;
  3179. pAutoReset->bEnabled = false;
  3180. pAutoReset->dwInterleave = 2000UL;
  3181. pAutoReset->dwTimeout = 60000UL;
  3182. pBoard->nZeroShift = 0;
  3183. pBoard->nTemperature = 1;
  3184. pBoard->nEncoderSteps = 6;
  3185. pBoard->nGearRatio = 61;
  3186. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3187. // Stepping Motor Speed
  3188. // 4280 = 8sps
  3189. // 2140 = 4sps
  3190. // 1070 = 2sps
  3191. // 535 = 1sps
  3192. pBoard->nMotorSpeed = 4;//535;
  3193. #endif
  3194. // pBoard->nMaxRange = 2048;
  3195. m_nMovingRadialFilter = 0;
  3196. m_nMovingDistanceFilter = 0;
  3197. m_nBZSAngleFilter = 0;
  3198. m_nBZEAngleFilter = 0;
  3199. m_nBZSRangeFilter = 0;
  3200. m_nBZERangeFilter = 0;
  3201. // read serial number
  3202. #ifdef LGS_MIRROR
  3203. #if defined( LGS_STEPPER ) || defined( LGS_FOD )
  3204. #ifdef LGS_FOD
  3205. FILE *pFile = fopen( "FOD.INI", "rt" ); // FOD
  3206. #else
  3207. FILE *pFile = fopen( "LFSS.INI", "rt" ); // LFSS
  3208. #endif
  3209. #else
  3210. #ifdef LGS_MND
  3211. FILE *pFile = fopen( "MND.INI", "rt" ); // MND
  3212. #else
  3213. FILE *pFile = fopen( "USER.INI", "rt" ); // LFS
  3214. #endif
  3215. #endif
  3216. #else
  3217. #ifdef LGS_PLS_1
  3218. FILE *pFile = fopen( "PLS.INI", "rt" ); // PLS
  3219. #else
  3220. FILE *pFile = fopen( "USER.INI", "rt" ); // ALS
  3221. #endif
  3222. #endif
  3223. if( !pFile )
  3224. return false;
  3225. CHAR pLine[MAX_PATH];
  3226. while( fgets( pLine, MAX_PATH, pFile ) )
  3227. {
  3228. SETTING_TYPE eType = ST_NONE;
  3229. PCHAR pTemp = NULL;
  3230. //printf( "%s", pLine );
  3231. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
  3232. {
  3233. pTemp = strstr( pLine, m_pSetting[i] );
  3234. if( pTemp )
  3235. {
  3236. eType = (SETTING_TYPE)i;
  3237. pTemp = strstr( pTemp, "=" );
  3238. if( pTemp )
  3239. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3240. break;
  3241. }
  3242. }
  3243. if( eType == ST_NONE || !pTemp )
  3244. continue;
  3245. switch( eType )
  3246. {
  3247. case ST_AUTORESET_ENABLE: pAutoReset->bEnabled = (bool)atoi( pTemp ); break;
  3248. case ST_AUTORESET_INTERLEAVE: pAutoReset->dwInterleave = atol( pTemp ); break;
  3249. case ST_AUTORESET_TIMEOUT: pAutoReset->dwTimeout = atol( pTemp ); break;
  3250. case ST_BOARD_TEMPERATURE: pBoard->nTemperature = atoi( pTemp ); break;
  3251. case ST_BOARD_ZEROSHIFT: pBoard->nZeroShift = atoi( pTemp ); break;
  3252. case ST_BOARD_ENCODERSTEPS: pBoard->nEncoderSteps = atoi( pTemp ); break;
  3253. case ST_BOARD_GEARRATIO: pBoard->nGearRatio = atoi( pTemp ); break;
  3254. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3255. case ST_BOARD_SPEED: pBoard->nMotorSpeed = atoi( pTemp ); break;
  3256. #endif
  3257. // case ST_BOARD_MAXRANGE: pBoard->nMaxRange = atoi( pTemp ); break;
  3258. case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (bool)atoi( pTemp ); break;
  3259. #ifdef STORE_FIRST_SAF
  3260. case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = atoi( pTemp ); break;
  3261. case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = atoi( pTemp ); break;
  3262. #endif
  3263. case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
  3264. case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
  3265. case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
  3266. case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = atoi( pTemp ); break;
  3267. case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = atoi( pTemp ); break;
  3268. case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = atoi( pTemp ); break;
  3269. case ST_BLIND_ED_RANGE:m_nBZERangeFilter = atoi( pTemp ); break;
  3270. case ST_BLIND_WIDTH:tWidth = atoi( pTemp ); break;
  3271. case ST_BLIND_DEPTH:tDepth = atoi( pTemp ); break;
  3272. case ST_BLIND_ANGLE:tAngle = atoi( pTemp ); break;
  3273. case ST_BLIND_RANGE:tRange = atoi( pTemp ); break;
  3274. #ifdef LGS_MIRROR
  3275. case ST_SWITCHER_TABLE: sscanf( pTemp, "%d,%d,%d", pSwitcher->pTable + 0, pSwitcher->pTable + 1, pSwitcher->pTable + 2 );
  3276. case ST_SWITCHER_REPLY_TIMEOUT: pSwitcher->nReplyTimeout = atol( pTemp ); break;
  3277. case ST_SWITCHER_COMMAND_TIMEOUT: pSwitcher->nCommandTimeout = atol( pTemp ); break;
  3278. case ST_SWITCHER_AUTO_MODE: pSwitcher->nAutoMode = atoi( pTemp ); break;
  3279. case ST_SWITCHER_AUTO_ENTER_TIMEOUT: pSwitcher->nAutoEnterTimeout = atoi( pTemp ); break;
  3280. case ST_SWITCHER_AUTO_SWITCH_TIMEOUT: pSwitcher->nAutoSwitchTimeout = atoi( pTemp ); break;
  3281. #endif
  3282. }
  3283. }
  3284. #if defined( LGS_REDUCED_PRF )
  3285. if( pBoard->nMotorSpeed < 1 ) pBoard->nMotorSpeed = 1;
  3286. if( pBoard->nMotorSpeed == 3 ) pBoard->nMotorSpeed = 2;
  3287. #if defined( LGS_STEPPER ) || defined( LGS_MND )
  3288. if( pBoard->nMotorSpeed > 4 ) pBoard->nMotorSpeed = 4;
  3289. #else
  3290. if( pBoard->nMotorSpeed == 5 ) pBoard->nMotorSpeed = 4;
  3291. if( pBoard->nMotorSpeed == 7 ) pBoard->nMotorSpeed = 6;
  3292. if( pBoard->nMotorSpeed == 9 ) pBoard->nMotorSpeed = 8;
  3293. if( pBoard->nMotorSpeed == 10 ) pBoard->nMotorSpeed = 8;
  3294. if( pBoard->nMotorSpeed == 11 ) pBoard->nMotorSpeed = 12;
  3295. if( pBoard->nMotorSpeed > 12 ) pBoard->nMotorSpeed = 12;
  3296. #endif
  3297. #if defined( LGS_MND )
  3298. LGS_PRF_REDUCE_RATIO = 1;
  3299. #else
  3300. if( pBoard->nMotorSpeed > 2 ){
  3301. LGS_PRF_REDUCE_RATIO = pBoard->nMotorSpeed >> 1;
  3302. } else {
  3303. LGS_PRF_REDUCE_RATIO = 1;
  3304. };
  3305. #endif
  3306. #endif
  3307. if( tWidth && tDepth ){
  3308. m_nBZSAngleFilter = tAngle - tWidth/2;
  3309. m_nBZEAngleFilter = ( tAngle + tWidth/2 ) % LGS_MAX_DETECTOR_ANGLES;
  3310. m_nBZSRangeFilter = tRange - tDepth/2;
  3311. m_nBZERangeFilter = tRange + tDepth/2;
  3312. };
  3313. fclose( pFile );
  3314. return true;
  3315. };
  3316. bool CKernel::SaveUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3317. #ifdef LGS_MIRROR
  3318. #if defined( LGS_STEPPER ) || defined( LGS_FOD )
  3319. #ifdef LGS_FOD
  3320. FILE *pFile = fopen( "FOD.INI", "wt" ); // FOD
  3321. #else
  3322. FILE *pFile = fopen( "LFSS.INI", "wt" ); // LFSS
  3323. #endif
  3324. #else
  3325. #ifdef LGS_MND
  3326. FILE *pFile = fopen( "MND.INI", "wt" ); // MND
  3327. #else
  3328. FILE *pFile = fopen( "USER.INI", "wt" ); // LFS
  3329. #endif
  3330. #endif
  3331. #else
  3332. #ifdef LGS_PLS_1
  3333. FILE *pFile = fopen( "PLS.INI", "wt" ); // PLS
  3334. #else
  3335. FILE *pFile = fopen( "USER.INI", "wt" ); // ALS
  3336. #endif
  3337. #endif
  3338. if( !pFile )
  3339. return false;
  3340. LPCTSTR pFormatInt = "%s=%d\n";
  3341. LPCTSTR pFormatDWORD = "%s=%lu\n";
  3342. LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
  3343. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
  3344. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
  3345. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
  3346. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
  3347. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
  3348. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
  3349. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
  3350. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  3351. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
  3352. #endif
  3353. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3354. if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
  3355. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
  3356. } else {
  3357. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
  3358. fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
  3359. };
  3360. if( m_nBZSAngleFilter != m_nBZEAngleFilter ){
  3361. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_ANGLE], m_nBZSAngleFilter );
  3362. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_ANGLE], m_nBZEAngleFilter );
  3363. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_RANGE], m_nBZSRangeFilter );
  3364. fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_RANGE], m_nBZERangeFilter );
  3365. };
  3366. #ifdef LGS_MIRROR
  3367. fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
  3368. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
  3369. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
  3370. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
  3371. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
  3372. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
  3373. #endif
  3374. #ifdef STORE_FIRST_SAF
  3375. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3376. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3377. #endif
  3378. fclose( pFile );
  3379. return true;
  3380. }
  3381. bool CKernel::LoadFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3382. // read serial number
  3383. FILE *pFile = fopen( "PARAMS.INI", "rt" );
  3384. if( !pFile ) return false;
  3385. //printf("PARAMS.ini found reading params\n");
  3386. CHAR pLine[MAX_PATH];
  3387. while( fgets( pLine, MAX_PATH, pFile ) ){
  3388. SETTING_TYPE eType = ST_NONE;
  3389. PCHAR pTemp = NULL;
  3390. for( int16_t i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ ){
  3391. pTemp = strstr( pLine, m_pSetting[i] );
  3392. if( pTemp )
  3393. {
  3394. eType = (SETTING_TYPE)i;
  3395. pTemp = strstr( pTemp, "=" );
  3396. if( pTemp )
  3397. pTemp = strtok( pTemp + 1, " \t\n\r" );
  3398. break;
  3399. }
  3400. }
  3401. if( eType == ST_NONE || !pTemp ) continue;
  3402. switch( eType ){
  3403. case ST_BOARD_HID: pBoard->nHID = atoi( pTemp ); break;
  3404. }
  3405. }
  3406. fclose( pFile );
  3407. return true;
  3408. };
  3409. bool CKernel::SaveFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
  3410. FILE *pFile = fopen( "PARAMS.INI", "wt" );
  3411. if( !pFile )
  3412. return false;
  3413. LPCTSTR pFormatInt = "%s=%d\n";
  3414. LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
  3415. LPCTSTR pFormatDWORD = "%s=%lu\n";
  3416. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
  3417. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
  3418. fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
  3419. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
  3420. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
  3421. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
  3422. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
  3423. #ifdef LGS_PLS_1
  3424. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
  3425. #endif
  3426. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_HID], (int16_t)pBoard->nHID );
  3427. fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
  3428. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
  3429. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
  3430. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
  3431. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
  3432. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
  3433. fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
  3434. #ifdef STORE_FIRST_SAF
  3435. fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
  3436. fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
  3437. #endif
  3438. fclose( pFile );
  3439. return true;
  3440. }