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.

3909 lines
192 KiB

4 years ago
​
​
​
​
​
4 years ago
3 years ago
​
4 years ago
3 years ago
3 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
4 years ago
​
4 years ago
​
4 years ago
4 years ago
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
​
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
3 years ago
​
​
​
​
4 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
3 years ago
​
​
​
​
​
4 years ago
4 years ago
3 years ago
​
4 years ago
​
3 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
3 years ago
​
4 years ago
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
3 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
3 years ago
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
4 years ago
​
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
3 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
3 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
4 years ago
​
4 years ago
​
​
​
4 years ago
4 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
​
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
4 years ago
​
4 years ago
​
4 years ago
​
4 years ago
​
4 years ago
​
4 years ago
​
4 years ago
​
4 years ago
​
4 years ago
​
3 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
​
4 years ago
​
4 years ago
​
​
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
4 years ago
4 years ago
​
​
4 years ago
​
4 years ago
4 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
​
​
4 years ago
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
​
​
4 years ago
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
3 years ago
4 years ago
​
​
4 years ago
​
​
​
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
3 years ago
4 years ago
4 years ago
3 years ago
​
4 years ago
​
​
4 years ago
​
​
​
4 years ago
​
3 years ago
4 years ago
4 years ago
​
​
​
3 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
​
4 years ago
​
​
4 years ago
​
4 years ago
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
​
4 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
4 years ago
​
4 years ago
​
​
4 years ago
​
​
4 years ago
4 years ago
4 years ago
4 years ago
​
​
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
4 years ago
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
4 years ago
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
3 years ago
4 years ago
3 years ago
​
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
​
4 years ago
​
4 years ago
​
​
3 years ago
4 years ago
​
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
​
4 years ago
​
4 years ago
4 years ago
4 years ago
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
​
​
​
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
4 years ago
​
​
​
3 years ago
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
4 years ago
​
​
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
4 years ago
4 years ago
​
​
4 years ago
​
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
3 years ago
  1. #include "deviceNode2D.h"
  2. #include "hardwareResourceSerialProvider.h"
  3. #include "kernelPrototype.h"
  4. #include "hardwareManager.h"
  5. #define LGS_MAX_DETECTOR_RANGE 2047
  6. //#define DEBUG_EXTRA
  7. #undef LOG
  8. #undef LOG_ERROR
  9. #define LOG( X ) deviceNode::m_pLog->Log( "NODE2D", this, X )
  10. #ifdef DEBUG
  11. #define LOG_ERROR( X ) {\
  12. char _tBfrErrMSG2w34[256];\
  13. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  14. deviceNode::m_pLog->Log( "NODE2D", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  15. }
  16. #else
  17. #define LOG_ERROR( X ) deviceNode::m_pLog->Log( "NODE2D", this, _LOG_ERROR, X );
  18. #endif
  19. #define DELAY_10MSW( X ) { for( uint8_t iii = X; iii && ( m_bThreadStatus < TH_ENDED ) && ( LRF_WS_WAIT == getStage() ); iii-- ) SLEEP( 10 ); }
  20. device2DSensor::device2DSensor( uint32_t id ):deviceNodeSensor( id ), protocolLGS_2D(){
  21. m_pPort = NULL;
  22. m_bPortType = 0;
  23. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT;
  24. m_nProcessingCmdId = 0;
  25. m_bDeviceIsSynced = false;
  26. m_bForceSync = false; // To Skip Settings and FS readout
  27. memset( m_vDrawRanges, 0, sizeof( m_vDrawRanges ));
  28. memset( &m_sShadowHelper, 0 , sizeof(SHADOW_IO_HELPER));
  29. memset( &m_sShadow, 0 , sizeof(SHADOW));
  30. cleanupDeviceStructures();
  31. if( m_sLRF_DATA.uart_id ) {
  32. DBC_UART_DATA *tUART = NULL;
  33. tUART = m_pDBC->getUartData( m_sLRF_DATA.uart_id );
  34. if( tUART!= NULL ) {
  35. m_bPortType = tUART->type;
  36. free( tUART );
  37. };
  38. };
  39. };
  40. void device2DSensor::cleanupDeviceStructures( void ){
  41. //setWM( LRF_WM_NONE );
  42. //setWM( LRF_WM_NONE ); // To prevent OWM keeping prev value
  43. m_bActualDeviceWM = MODE_NONE;
  44. m_bRequestedDeviceWM = MODE_NONE;
  45. //m_bSupportedFS = false;
  46. m_bDeviceIsSynced = false;
  47. m_nSleepTime = LGS_DEFAULT_SLEEP_TIME;
  48. #ifdef DEBUG_EXTRA
  49. LOG("Clean Basic Structures!");
  50. #endif
  51. //m_eCurrentSequence = NO_SEQUENCE;
  52. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  53. m_bInitialFlips = LGS_INITIAL_FLIPS;
  54. m_nCurrentAngle = 0;
  55. m_bDrawType = 0;
  56. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT;
  57. memset( m_tSN, 0, 33 );
  58. memset( m_tSV, 0, 65 );
  59. cleanShadowStructs();
  60. if( m_sGetFileTransfers.helpers.size() ){
  61. for( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx < m_sGetFileTransfers.helpers.end(); idx++ ) {
  62. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  63. free( (*idx) );
  64. };
  65. m_sGetFileTransfers.helpers.clear();
  66. };
  67. m_sGetFileTransfers.current = 0;
  68. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  69. //memset( m_pFsPackageBuffer, 0, MAX_PATH );
  70. //m_bCurrentOperationFS = 0;
  71. //memset( &m_sInFSData, 0, sizeof(FS_DATA_EX));
  72. //memset( &m_sOutFSData, 0, sizeof(FS_DATA_EX));
  73. //if( m_pFSHelper ) m_pFSHelper->resetFS(); //ctrl_iteration()
  74. #ifdef DEBUG_EXTRA
  75. LOG("cleanupDeviceStructures DONE");
  76. #endif
  77. };
  78. void device2DSensor::cleanShadowStructs(){
  79. #ifdef DEBUG_EXTRA
  80. LOG("Clean Shadow Structures!");
  81. #endif
  82. if ( m_sShadow.pPolygones ) {
  83. for (int i = 0; i < m_sShadow.m_nPolygonCount; i++) if (m_sShadow.pPolygones[i].pPoint) free( m_sShadow.pPolygones[i].pPoint );
  84. free(m_sShadow.pPolygones);
  85. };
  86. for (int i = 0; i < 360; i++) if (m_sShadow.ray_lines[i].rays ) free(m_sShadow.ray_lines[i].rays );
  87. m_bDeviceIsSynced = false;
  88. //SetWM twice to clean OWM status
  89. //setWM( LRF_WM_INIT );
  90. //setWM( LRF_WM_INIT );
  91. m_bActualDeviceWM = MODE_NONE;
  92. m_bRequestedDeviceWM = MODE_NONE;
  93. m_bSerialStringValid = false;
  94. m_bVersionStringValid = false;
  95. memset(&m_sShadow, 0, sizeof(SHADOW));
  96. memset(&m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER));
  97. #ifdef DEBUG_EXTRA
  98. LOG("cleanShadowStructs DONE");
  99. #endif
  100. };
  101. device2DSensor::~device2DSensor(){
  102. #ifdef DEBUG
  103. LOG("Stoping Service");
  104. #endif
  105. stopService();
  106. #ifdef DEBUG
  107. LOG("Service is Stoped");
  108. LOG("Node Destructor Ends!");
  109. #endif
  110. //if( m_pFSHelper ) delete ( m_pFSHelper );
  111. };
  112. void device2DSensor::updateDataStatus( uint8_t ds, uint8_t nodestatus ){
  113. if ( m_pDBC == NULL ) return;
  114. if ( m_sNodeData.node_id ) {
  115. if( ds < ARGUS_DS_CONNECTING ) {
  116. m_pDBC->setNodeOffline( m_sNodeData.node_id );
  117. } else {
  118. m_pDBC->setNodeOnline( m_sNodeData.node_id, nodestatus );
  119. };
  120. };
  121. if ( m_sLRF_DATA.id ) {
  122. m_sLRF_DATA.data_status = ds;
  123. m_pDBC->setLRFDataStatus( m_sLRF_DATA.id, ds );
  124. };
  125. };
  126. bool device2DSensor::startService() {
  127. if( m_sLRF_DATA.id == 0 ){
  128. LOG_ERROR("No DATA From Database!");
  129. return false;
  130. };
  131. if( setDeviceID( m_sLRF_DATA.device_id ) ){
  132. if( !create() ){
  133. LOG_ERROR("Protocol <<< Create >>> Failure!");
  134. return false;
  135. };
  136. };
  137. if( m_sLRF_DATA.filter_id > 0 ) {
  138. #ifdef DEBUG
  139. LOG("DEFINED FILTER");
  140. #endif
  141. kernelPrototype *AK = kernelPrototype::getInstance();
  142. if( AK==NULL ){
  143. LOG_ERROR("KERNEL <<< GRAB >>> Failure!");
  144. return false;
  145. };
  146. m_pTargetFilter = AK->getFilter( m_sLRF_DATA.filter_id );
  147. };
  148. updateDataStatus( ARGUS_DS_DISCONNECTED );
  149. //m_pFSHelper = new FS_IO_HELPER();
  150. return init();
  151. };
  152. bool device2DSensor::stopService() {
  153. LOG( "Kiling Thread");
  154. waitThreadEnd( true );
  155. LOG( "Thread is Dead!");
  156. updateDataStatus( ARGUS_DS_DISCONNECTED );
  157. //m_pDBC->setNodeOffline( m_sNodeData.node_id );
  158. LOG( "Start Clenup Structs!");
  159. cleanupDeviceStructures();
  160. LOG( "Clenup Structs Done!");
  161. return true;
  162. };
  163. bool device2DSensor::validate(){
  164. if( m_pDBC == NULL ) return false;
  165. // Check Settings
  166. if( !deviceNodeSensor::validate() ) return false;
  167. return true;
  168. };
  169. void device2DSensor::connectMode(){
  170. #ifdef DEBUG_EXTRA
  171. LOG("Connect MODE");
  172. #endif
  173. // Reset State
  174. if( initWModeFunction( LRF_WM_CONNECTION ) ) broadcastDisconnected();
  175. switch( getPPStatus() ){
  176. case STG_PUSH:
  177. LOG("Push");
  178. switch( getStage() ){
  179. case LRF_WS_INIT:{
  180. updateDataStatus( ARGUS_DS_DISCONNECTED );
  181. m_pDBC->setNodeOffline( m_sNodeData.node_id );
  182. m_bInitialFlips = LGS_INITIAL_FLIPS;
  183. hardwareManager *tHM = hardwareManager::getInstance();
  184. if( tHM != NULL ) {
  185. hardwareResource *tRES = tHM->requestResource( HARDWARE_PROVIDER_SERIAL, m_sLRF_DATA.uart_id );
  186. if( tRES != NULL ) {
  187. #ifdef DEBUG_EXTRA
  188. LOG("Have Res!");
  189. #endif
  190. if( tRES->isValid() ) {
  191. m_pPort = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  192. #ifdef DEBUG_EXTRA
  193. //Bind To Proto
  194. char tB[64];
  195. sprintf( tB, "PortOBJ: %p", m_pPort );
  196. LOG( tB );
  197. #endif
  198. if( !setTransport( m_pPort, false )){
  199. LOG_ERROR("Binding Port Failure!");
  200. } else {
  201. #ifdef DEBUG_EXTRA
  202. LOG("Port Bind Sucessfully Done");
  203. #endif
  204. updateDataStatus( ARGUS_DS_CONNECTING );
  205. m_bActualDeviceWM = MODE_NONE;
  206. m_bRequestedDeviceWM = MODE_NONE;
  207. transactionSetResult( TRANSACTION_RESULT_OK );
  208. break;
  209. };
  210. #ifdef DEBUG_EXTRA
  211. } else {
  212. LOG("Res is INVALID?!");
  213. #endif
  214. };
  215. #ifdef DEBUG_EXTRA
  216. } else {
  217. char tB[256];
  218. sprintf( tB, "HWM Has No UART PORT[%d]!", m_sLRF_DATA.uart_id );
  219. LOG( tB );
  220. #endif
  221. };
  222. } else {
  223. LOG_ERROR("Can not access Hardware Manager");
  224. };
  225. setTransport( NULL, false );
  226. DELAY_10MS( 500 ); // 500 ms
  227. break;
  228. };
  229. case LRF_WS_STAGE_1:{
  230. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  231. cleanupDeviceStructures();
  232. m_bRequestedDeviceWM = MODE_DETECTOR;
  233. if( !setMode( MODE_DETECTOR ) ) {
  234. LOG_ERROR("Fall Back to Disconnected!");
  235. updateDataStatus( ARGUS_DS_DISCONNECTED );
  236. setStage( LRF_WS_INIT );
  237. } else transactionWaitResult();
  238. break;
  239. };
  240. case LRF_WS_STAGE_2: setWM( LRF_WM_HANDSHAKE ); break;
  241. default: setStage( LRF_WS_INIT ); break;
  242. };
  243. break;
  244. case STG_WAIT: waitStateFunction( LRF_WS_STAGE_1 ); break;
  245. case STG_POOL: poolStateFunction(); break;
  246. };
  247. };
  248. void device2DSensor::handshakeMode(){
  249. #ifdef DEBUG_EXTRA
  250. LOG("Handshake MODE");
  251. #endif
  252. // Reset State
  253. if( initWModeFunction( LRF_WM_HANDSHAKE ) ) {
  254. updateDataStatus( ARGUS_DS_GET_INFO );
  255. broadcastConnected();
  256. };
  257. switch( getPPStatus() ){
  258. case STG_PUSH:{
  259. switch( getStage() ) {
  260. case LRF_WS_INIT:{
  261. if( m_bActualDeviceWM != MODE_DETECTOR ){
  262. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  263. m_bRequestedDeviceWM = MODE_DETECTOR;
  264. if( !setMode( MODE_DETECTOR ) ) {
  265. m_pDBC->setNodeOffline( m_sNodeData.node_id );
  266. LOG_ERROR("Fall Back to Disconnected!");
  267. setWM( LRF_WM_CONNECTION );
  268. } else transactionWaitResult();
  269. } else transactionSetResult( TRANSACTION_RESULT_OK );
  270. break;
  271. };
  272. case LRF_WS_STAGE_1:{
  273. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  274. if( !getSerialNumber() ) {
  275. LOG_ERROR("Fall Back to Disconnected!");
  276. setWM( LRF_WM_CONNECTION );
  277. } else transactionWaitResult();
  278. break;
  279. };
  280. case LRF_WS_STAGE_2:{
  281. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  282. if( !getVersionString() ) {
  283. LOG_ERROR("Fall Back to Disconnected!");
  284. setWM( LRF_WM_CONNECTION );
  285. } else transactionWaitResult();
  286. break;
  287. };
  288. case LRF_WS_STAGE_3:
  289. if( m_bDeviceIsSynced ){
  290. updateDataStatus( ARGUS_DS_READY );
  291. setWM( LRF_WM_IDLE );
  292. } else {
  293. setWM( LRF_WM_SYNC_UP );
  294. };
  295. break;
  296. };
  297. break;
  298. };
  299. case STG_WAIT: waitStateFunction(); break;
  300. case STG_POOL: poolStateFunction(); break;
  301. };
  302. };
  303. bool device2DSensor::initWModeFunction( uint8_t wm ){
  304. if( getOWM() != wm ) {
  305. setWM( wm );
  306. setWM( wm );
  307. setStage( LRF_WS_INIT );
  308. transactionResetResult();
  309. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT;
  310. return true;
  311. };
  312. return false;
  313. };
  314. void device2DSensor::readMode(){
  315. #ifdef DEBUG_EXTRA
  316. LOG("READ");
  317. #endif
  318. // Reset State
  319. initWModeFunction( LRF_WM_SYNC_UP );
  320. switch( getPPStatus() ){
  321. case STG_PUSH:{
  322. switch( getStage() ) {
  323. case LRF_WS_INIT:{
  324. LOG("TryP");
  325. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  326. if( !getDetectionProfile() ) {
  327. LOG_ERROR("Fall Back to Disconnected!");
  328. setWM( LRF_WM_CONNECTION );
  329. } else transactionWaitResult();
  330. break;
  331. };
  332. case LRF_WS_STAGE_1:{
  333. LOG("Get PM");
  334. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  335. if( !getParameters( true ) ) {
  336. LOG_ERROR("Fall Back to Disconnected!");
  337. setWM( LRF_WM_CONNECTION );
  338. } else transactionWaitResult();
  339. break;
  340. };
  341. case LRF_WS_STAGE_2:{
  342. LOG("Get PS");
  343. if( m_sNodeData.type == ARGUS_ALS_SENSOR ) { // Read Slave Just for ALS series
  344. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  345. if( !getParameters( false ) ) {
  346. LOG_ERROR("Fall Back to Disconnected!");
  347. setWM( LRF_WM_CONNECTION );
  348. } else transactionWaitResult();
  349. } else transactionSetResult( TRANSACTION_RESULT_OK );
  350. break;
  351. };
  352. case LRF_WS_STAGE_3:{
  353. LOG("Get SHIFU");
  354. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  355. if( !getShadowInfo( m_sShadowHelper.m_bSequence ) ) {
  356. LOG_ERROR("Fall Back to Disconnected!");
  357. setWM( LRF_WM_CONNECTION );
  358. } else transactionWaitResult();
  359. break;
  360. };
  361. case LRF_WS_STAGE_4:{
  362. LOG("Get POLY");
  363. // Have Info -> If No Poly - Skeep to go get DC
  364. if( m_sShadow.pPolygones ){
  365. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  366. if( !getShadowPoly( m_sShadowHelper.m_bSequence, m_sShadowHelper.m_nCurrentPolygon ) ){
  367. LOG_ERROR("Fall Back to Disconnected!");
  368. setWM( LRF_WM_CONNECTION );
  369. } else transactionWaitResult();
  370. } else transactionSetResult( TRANSACTION_RESULT_OK );
  371. break;
  372. };
  373. case LRF_WS_STAGE_5:{
  374. LOG("Get POPO");
  375. if ( m_sShadow.pPolygones ) {
  376. if (m_sShadowHelper.m_nCurrentPoint < m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount) {
  377. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  378. if( !getShadowPolyPoint( m_sShadowHelper.m_bSequence, m_sShadowHelper.m_nCurrentPolygon, m_sShadowHelper.m_nCurrentPoint ) ) {
  379. LOG_ERROR("Fall Back to Disconnected!");
  380. setWM( LRF_WM_CONNECTION );
  381. } else transactionWaitResult();
  382. } else {
  383. if ( m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ) {
  384. m_sShadowHelper.m_nCurrentPolygon++;
  385. setStage( LRF_WS_STAGE_4 ); // Recheck next Poly
  386. } else transactionSetResult( TRANSACTION_RESULT_OK );
  387. };
  388. } else transactionSetResult( TRANSACTION_RESULT_OK );
  389. break;
  390. };
  391. case LRF_WS_STAGE_6:{
  392. LOG("Get RELAY");
  393. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  394. if( !getRelayParameters() ) {
  395. LOG_ERROR("Fall Back to Disconnected!");
  396. setWM( LRF_WM_CONNECTION );
  397. } else transactionWaitResult();
  398. break;
  399. };
  400. case LRF_WS_STAGE_7: setWM( LRF_WM_IDLE ); break;
  401. default: setStage( LRF_WS_INIT ); break;
  402. };
  403. break;
  404. };
  405. case STG_WAIT: waitStateFunction(); break;
  406. case STG_POOL: poolStateFunction(); break;
  407. };
  408. };
  409. void device2DSensor::syncMode(){
  410. #ifdef DEBUG_EXTRA
  411. LOG("SYNC");
  412. #endif
  413. // Reset State
  414. if( initWModeFunction( LRF_WM_SYNC_DOWN ) ){
  415. updateDataStatus( ARGUS_DS_BUSY );
  416. memset( m_pTGENFILENAMES[0], 0, 33 );
  417. memset( m_pTGENFILENAMES[1], 0, 33 );
  418. memset( m_pTGENFILENAMES[2], 0, 33 );
  419. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT;
  420. m_bTGENFILECNT = 0;
  421. m_bTGENFILE = 0;
  422. m_sGetFileTransfers.current = 0;
  423. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  424. if ( m_sGetFileTransfers.helpers.size() ) {
  425. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  426. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  427. free( (*idx) );
  428. };
  429. m_sGetFileTransfers.helpers.clear();
  430. };
  431. };
  432. switch( getPPStatus() ){
  433. case STG_PUSH:{
  434. switch( getStage() ) {
  435. case LRF_WS_INIT:{
  436. if( m_bTGENFILECNT == 0 ){
  437. // Generate INI file and Send via GETFILE
  438. if( generateIniFile( m_bTGENFILE ) ){
  439. GETFILE_IO_HELPER *tH = NULL;
  440. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  441. if ( tH ) {
  442. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  443. if ( strcasestr( m_tSV, "LFSS" ) != NULL ) {
  444. #ifdef DEBUG
  445. LOG("Generating LFSS config");
  446. #endif
  447. strncpy( tH->destName, "LFSS.ini", 16 );
  448. } else {
  449. if ( strcasestr( m_tSV, "PLS" ) != NULL ) {
  450. #ifdef DEBUG
  451. LOG("Generating PLS config");
  452. #endif
  453. strncpy( tH->destName, "PLS.ini", 16 );
  454. } else {
  455. if ( strcasestr( m_tSV, "MND" ) != NULL ) {
  456. #ifdef DEBUG
  457. LOG("Generating MND config");
  458. #endif
  459. strncpy( tH->destName, "MND.ini", 16 );
  460. } else {
  461. if ( strcasestr( m_tSV, "FOD" ) != NULL ) {
  462. #ifdef DEBUG
  463. LOG("Generating FOD config");
  464. #endif
  465. strncpy( tH->destName, "FOD.ini", 16 );
  466. } else {
  467. #ifdef DEBUG
  468. LOG("Generating ALS/LFS (USER.ini) config");
  469. #endif
  470. strncpy( tH->destName, "USER.ini", 16 );
  471. };
  472. };
  473. };
  474. };
  475. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  476. struct stat st;
  477. char tB[256];
  478. sprintf( tB, "data/uploads/%s", tH->sourceName );
  479. stat( tB, &st );
  480. tH->fileSize = st.st_size;
  481. tH->state = GF_OP_OK;
  482. tH->db_id = 0;
  483. tH->index = 0x04;
  484. m_sGetFileTransfers.helpers.push_back( tH );
  485. m_bTGENFILE++;
  486. m_bTGENFILECNT++;
  487. };
  488. } else {
  489. LOG("Gen File 1 Failure!");
  490. };
  491. if( generateRestartFile( m_bTGENFILE ) ){
  492. GETFILE_IO_HELPER *tH = NULL;
  493. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  494. if ( tH ) {
  495. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  496. strncpy( tH->destName, "updateMZ.bat", 16 );
  497. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  498. struct stat st;
  499. char tB[256];
  500. sprintf( tB, "data/uploads/%s", tH->sourceName );
  501. stat( tB, &st );
  502. tH->fileSize = st.st_size;
  503. tH->state = GF_OP_OK;
  504. tH->db_id = 0;
  505. tH->index = 0x04;
  506. m_sGetFileTransfers.helpers.push_back( tH );
  507. m_bTGENFILE++;
  508. m_bTGENFILECNT++;
  509. };
  510. } else {
  511. LOG("Gen File 2 Failure!");
  512. };
  513. };
  514. cleanShadowStructs();
  515. if( m_pDBC->fillShadow2D( m_sNodeData.aux_id, m_sShadow ) ){
  516. LOG("Loadded From DB");
  517. if( rasterizeShadow() ){
  518. LOG("Mask is Rasterized");
  519. if ( m_bActualDeviceWM != MODE_MASK ) {
  520. LOG("Set Mask Mode");
  521. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  522. m_bRequestedDeviceWM = MODE_MASK;
  523. if( !setMode( MODE_MASK ) ) {
  524. LOG_ERROR("Fall Back to Disconnected!");
  525. setWM( LRF_WM_CONNECTION );
  526. } else transactionWaitResult();
  527. } else {
  528. transactionSetResult( TRANSACTION_RESULT_OK );
  529. };
  530. } else {
  531. setStage( LRF_WS_STAGE_7 );
  532. };
  533. } else {
  534. setStage( LRF_WS_STAGE_7 );
  535. };
  536. break;
  537. };
  538. case LRF_WS_STAGE_1:{
  539. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  540. if( m_bActualDeviceWM != MODE_MASK ) {
  541. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  542. m_bRequestedDeviceWM = MODE_MASK;
  543. if( !setMode( MODE_MASK ) ) {
  544. LOG_ERROR("Fall Back to Disconnected!");
  545. setWM( LRF_WM_CONNECTION );
  546. } else transactionWaitResult();
  547. } else {
  548. setStage( LRF_WS_STAGE_1 );
  549. };
  550. break;
  551. };
  552. case LRF_WS_STAGE_2:{
  553. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  554. if (!setShadowInfo( m_sShadowHelper.m_bSequence, m_sShadow )) {
  555. LOG_ERROR("Fall Back to Disconnected!");
  556. setWM( LRF_WM_CONNECTION );
  557. } else transactionWaitResult();
  558. break;
  559. };
  560. case LRF_WS_STAGE_3:{
  561. if( m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ){
  562. m_sShadowHelper.m_nCurrentPoint = 0;
  563. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  564. if(!setShadowPoly( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentPolygon)){
  565. LOG_ERROR("Fall Back to Disconnected!");
  566. setWM( LRF_WM_CONNECTION );
  567. } else transactionWaitResult();
  568. } else {
  569. m_sShadowHelper.m_nCurrentRayLine = 0;
  570. //skip all empty angles of binary shadow
  571. while( ( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount == 0 ) && m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  572. m_sShadowHelper.m_nCurrentRayLine++;
  573. };
  574. if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  575. //if we have an shadows -> transfer else skeep
  576. setStage( LRF_WS_STAGE_5 );
  577. } else {
  578. setStage( LRF_WS_STAGE_7 );
  579. };
  580. };
  581. break;
  582. };
  583. case LRF_WS_STAGE_4:{
  584. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  585. #ifdef DEBUG_EXTRA
  586. char tBuff[128];
  587. sprintf( tBuff,"Send Point %d of %d", (m_sShadowHelper.m_nCurrentPoint + 1), m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount );
  588. LOG( tBuff );
  589. #endif
  590. if( m_sShadowHelper.m_nCurrentPoint < m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount ){
  591. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  592. if( !setShadowPolyPoint( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentPolygon, m_sShadowHelper.m_nCurrentPoint) ){
  593. LOG_ERROR("Fall Back to Disconnected!");
  594. setWM( LRF_WM_CONNECTION );
  595. } else transactionWaitResult();
  596. } else {
  597. m_sShadowHelper.m_nCurrentPolygon ++;
  598. setStage( LRF_WS_STAGE_3 );
  599. };
  600. break;
  601. };
  602. case LRF_WS_STAGE_5:{
  603. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  604. #ifdef DEBUG_EXTRA
  605. char tBuff[128];
  606. sprintf( tBuff,"Send Shadow for angle %d [%d rays]", m_sShadowHelper.m_nCurrentRayLine, m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount );
  607. LOG( tBuff );
  608. #endif
  609. if( !setShadowRay( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentRayLine ) ){
  610. LOG_ERROR("Fall Back to Disconnected!");
  611. setWM( LRF_WM_CONNECTION );
  612. } else transactionWaitResult();
  613. break;
  614. };
  615. case LRF_WS_STAGE_6:{
  616. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  617. #ifdef DEBUG_EXTRA
  618. char tBuff[128];
  619. sprintf( tBuff,"Send Shadow RayLine %d for andle %d", m_sShadowHelper.m_nCurrentRay, m_sShadowHelper.m_nCurrentRayLine );
  620. LOG( tBuff );
  621. #endif
  622. if( m_sShadowHelper.m_nCurrentRay < m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount ) {
  623. if( !setShadowRayLine( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentRayLine, m_sShadowHelper.m_nCurrentRay ) ){
  624. LOG_ERROR("Fall Back to Disconnected!");
  625. setWM( LRF_WM_CONNECTION );
  626. } else transactionWaitResult();
  627. } else {
  628. do {
  629. m_sShadowHelper.m_nCurrentRayLine++;
  630. } while ( ( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount == 0 ) && m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES );
  631. if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  632. setStage( LRF_WS_STAGE_5 );
  633. } else {
  634. // If not found -> finish upload shadow
  635. transactionSetResult( TRANSACTION_RESULT_OK );
  636. };
  637. };
  638. break;
  639. };
  640. case LRF_WS_STAGE_7:{
  641. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  642. if (!setShadowDone( m_sShadowHelper.m_bSequence )) {
  643. LOG_ERROR("Fall Back to Disconnected!");
  644. setWM( LRF_WM_CONNECTION );
  645. } else transactionWaitResult();
  646. break;
  647. };
  648. case LRF_WS_STAGE_8:{
  649. LOG("Send Master Profile!");
  650. //ANODE_WM_2D_SET_MASTER_PARAM
  651. PLGS_2D_PARAMETERS tData = m_pDBC->getLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, true );
  652. if ( tData ) {
  653. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER << 2;
  654. if (!setParameters( tData, true, m_nActiveDetectionProfile)) {
  655. LOG_ERROR("Fall Back to Disconnected!");
  656. setWM( LRF_WM_CONNECTION );
  657. } else transactionWaitResult();
  658. free( tData );
  659. } else transactionSetResult( TRANSACTION_RESULT_OK );
  660. break;
  661. };
  662. case LRF_WS_STAGE_9:{
  663. LOG("Send Slave Profile!");
  664. //ANODE_WM_2D_SET_SLAVE_PARAM
  665. PLGS_2D_PARAMETERS tData = m_pDBC->getLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, false );
  666. if ( tData ) {
  667. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER << 2;
  668. if (!setParameters( tData, false, m_nActiveDetectionProfile)) {
  669. LOG_ERROR("Fall Back to Disconnected!");
  670. setWM( LRF_WM_CONNECTION );
  671. } else transactionWaitResult();
  672. free( tData );
  673. } else transactionSetResult( TRANSACTION_RESULT_OK );
  674. break;
  675. };
  676. case LRF_WS_STAGE_10:{
  677. //ANODE_WM_2D_SET_GETFILE_MODE
  678. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  679. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  680. m_bRequestedDeviceWM = MODE_GETFILE;
  681. if( !setMode( MODE_GETFILE ) ) {
  682. LOG_ERROR("Fall Back to Disconnected!");
  683. setWM( LRF_WM_CONNECTION );
  684. } else transactionWaitResult();
  685. } else {
  686. transactionSetResult( TRANSACTION_RESULT_OK );
  687. };
  688. break;
  689. };
  690. case LRF_WS_STAGE_11:{
  691. if( m_sGetFileTransfers.helpers.size() ){
  692. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  693. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  694. case GF_OP_CLOSE:{
  695. // After Sending check if have other file to send
  696. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  697. m_sGetFileTransfers.current++;
  698. } else {
  699. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  700. // case GF_EM_ISSUE_RESET:{
  701. // break;
  702. // };
  703. // case GF_EM_ISSUE_SAVE_FW:{
  704. // break;
  705. // }
  706. // default: setStage( LRF_WS_STAGE_7 );
  707. //};
  708. transactionSetResult( TRANSACTION_RESULT_OK );
  709. return;
  710. };
  711. };
  712. case GF_OP_OK:{
  713. // INIT Sending File
  714. char tB[256];
  715. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  716. #ifdef DEBUG
  717. LOG(tB);
  718. #endif
  719. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  720. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  721. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  722. #ifdef DEBUG_EXTRA
  723. LOG("OPEN -> Send Info");
  724. #endif
  725. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  726. memcpy(
  727. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  728. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  729. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  730. );
  731. } else {
  732. #ifdef DEBUG_EXTRA
  733. LOG("NOPEN -> Cancel");
  734. #endif
  735. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  736. transactionSetResult( TRANSACTION_RESULT_OK );
  737. return;
  738. };
  739. break;
  740. };
  741. case GF_OP_OPEN:{
  742. #ifdef DEBUG_EXTRA
  743. LOG("Info -> Data");
  744. #endif
  745. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  746. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  747. 1,
  748. 48,
  749. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  750. );
  751. #ifdef DEBUG_EXTRA
  752. char tB[64];
  753. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  754. LOG( tB );
  755. #endif
  756. break;
  757. };
  758. case GF_OP_DATA:{
  759. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  760. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  761. #ifdef DEBUG
  762. char tB[64];
  763. if ( pos != EOF ){
  764. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  765. LOG( tB );
  766. } else {
  767. LOG("File Ended!");
  768. };
  769. #endif
  770. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  771. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  772. }
  773. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  774. 1,
  775. 48,
  776. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  777. );
  778. #ifdef DEBUG
  779. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  780. LOG( tB );
  781. #endif
  782. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  783. #ifdef DEBUG
  784. LOG("Change to Close");
  785. #endif
  786. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  787. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  788. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  789. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  790. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  791. };
  792. };
  793. break;
  794. };
  795. };
  796. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  797. if( !sendGF_package(
  798. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  799. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  800. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  801. )
  802. ){
  803. LOG_ERROR("Fall Back to Disconnected!");
  804. setWM( LRF_WM_CONNECTION );
  805. } else transactionWaitResult();
  806. } else {
  807. // Exit From GetFile Mode --> No need --> Reset Device
  808. transactionSetResult( TRANSACTION_RESULT_OK );
  809. };
  810. break;
  811. };
  812. case LRF_WS_STAGE_12:{
  813. // Remove Generated Files
  814. if( m_bTGENFILECNT ){
  815. for( uint8_t idx = 0; idx < m_bTGENFILECNT; idx++){
  816. char tName[256];
  817. sprintf( tName, "data/uploads/%s", m_pTGENFILENAMES[idx]);
  818. unlink( tName );
  819. };
  820. };
  821. transactionSetResult( TRANSACTION_RESULT_OK );
  822. break;
  823. };
  824. case LRF_WS_STAGE_13:{
  825. //Issue Full Reset
  826. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  827. if ( !doFullReset() ) {
  828. LOG_ERROR("Fall Back to Disconnected!");
  829. setWM( LRF_WM_CONNECTION );
  830. } else transactionWaitResult();
  831. break;
  832. };
  833. case LRF_WS_STAGE_14: setWM( LRF_WM_IDLE ); break;
  834. default: setStage( LRF_WS_INIT ); break;
  835. };
  836. break;
  837. };
  838. case STG_WAIT: waitStateFunction(); break;
  839. case STG_POOL: poolStateFunction(); break;
  840. };
  841. };
  842. void device2DSensor::save_ini(){
  843. #ifdef DEBUG_EXTRA
  844. LOG("Save HW ini");
  845. #endif
  846. // Reset State
  847. if( initWModeFunction( LRF_WM_SAVE_HW ) ){
  848. updateDataStatus( ARGUS_DS_BUSY );
  849. memset( m_pTGENFILENAMES[0], 0, 33 );
  850. memset( m_pTGENFILENAMES[1], 0, 33 );
  851. memset( m_pTGENFILENAMES[2], 0, 33 );
  852. m_bTGENFILECNT = 0;
  853. m_bTGENFILE = 0;
  854. m_sGetFileTransfers.current = 0;
  855. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  856. if ( m_sGetFileTransfers.helpers.size() ) {
  857. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  858. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  859. free( (*idx) );
  860. };
  861. m_sGetFileTransfers.helpers.clear();
  862. };
  863. };
  864. switch( getPPStatus() ){
  865. case STG_PUSH:{
  866. switch( getStage() ) {
  867. case LRF_WS_INIT:{
  868. if( m_bTGENFILECNT == 0 ){
  869. // Generate INI file and Send via GETFILE
  870. LOG("Gen III");
  871. if( generateIniFile( m_bTGENFILE ) ){
  872. GETFILE_IO_HELPER *tH = NULL;
  873. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  874. if ( tH ) {
  875. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  876. if ( strcasestr( m_tSV, "LFSS" ) != NULL ) {
  877. #ifdef DEBUG
  878. LOG("Generating LFSS config");
  879. #endif
  880. strncpy( tH->destName, "LFSS.ini", 16 );
  881. } else {
  882. if ( strcasestr( m_tSV, "PLS" ) != NULL ) {
  883. #ifdef DEBUG
  884. LOG("Generating PLS config");
  885. #endif
  886. strncpy( tH->destName, "PLS.ini", 16 );
  887. } else {
  888. if ( strcasestr( m_tSV, "MND" ) != NULL ) {
  889. #ifdef DEBUG
  890. LOG("Generating MND config");
  891. #endif
  892. strncpy( tH->destName, "MND.ini", 16 );
  893. } else {
  894. if ( strcasestr( m_tSV, "FOD" ) != NULL ) {
  895. #ifdef DEBUG
  896. LOG("Generating FOD config");
  897. #endif
  898. strncpy( tH->destName, "FOD.ini", 16 );
  899. } else {
  900. #ifdef DEBUG
  901. LOG("Generating ALS/LFS (USER.ini) config");
  902. #endif
  903. strncpy( tH->destName, "USER.ini", 16 );
  904. };
  905. };
  906. };
  907. };
  908. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  909. struct stat st;
  910. char tB[256];
  911. sprintf( tB, "data/uploads/%s", tH->sourceName );
  912. stat( tB, &st );
  913. tH->fileSize = st.st_size;
  914. tH->state = GF_OP_OK;
  915. tH->db_id = 0;
  916. tH->index = 0x04;
  917. m_sGetFileTransfers.helpers.push_back( tH );
  918. m_bTGENFILE++;
  919. m_bTGENFILECNT++;
  920. };
  921. } else {
  922. LOG_ERROR("Gen File 1 Failure!");
  923. };
  924. if( generateRestartFile( m_bTGENFILE ) ){
  925. GETFILE_IO_HELPER *tH = NULL;
  926. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  927. if ( tH ) {
  928. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  929. strncpy( tH->destName, "updateMZ.bat", 16 );
  930. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  931. struct stat st;
  932. char tB[256];
  933. sprintf( tB, "data/uploads/%s", tH->sourceName );
  934. stat( tB, &st );
  935. tH->fileSize = st.st_size;
  936. tH->state = GF_OP_OK;
  937. tH->db_id = 0;
  938. tH->index = 0x04;
  939. m_sGetFileTransfers.helpers.push_back( tH );
  940. m_bTGENFILE++;
  941. m_bTGENFILECNT++;
  942. };
  943. } else {
  944. LOG_ERROR("Gen File 2 Failure!");
  945. };
  946. };
  947. transactionSetResult( TRANSACTION_RESULT_OK );
  948. break;
  949. };
  950. case LRF_WS_STAGE_1:{
  951. //ANODE_WM_2D_SET_GETFILE_MODE
  952. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  953. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  954. m_bRequestedDeviceWM = MODE_GETFILE;
  955. if( !setMode( MODE_GETFILE ) ) {
  956. LOG_ERROR("Fall Back to Disconnected!");
  957. setWM( LRF_WM_CONNECTION );
  958. } else transactionWaitResult();
  959. } else {
  960. transactionSetResult( TRANSACTION_RESULT_OK );
  961. };
  962. break;
  963. };
  964. case LRF_WS_STAGE_2:{
  965. if( m_sGetFileTransfers.helpers.size() ){
  966. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  967. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  968. case GF_OP_CLOSE:{
  969. // After Sending check if have other file to send
  970. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  971. m_sGetFileTransfers.current++;
  972. } else {
  973. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  974. // case GF_EM_ISSUE_RESET:{
  975. // break;
  976. // };
  977. // case GF_EM_ISSUE_SAVE_FW:{
  978. // break;
  979. // }
  980. // default: setStage( LRF_WS_STAGE_7 );
  981. //};
  982. transactionSetResult( TRANSACTION_RESULT_OK );
  983. return;
  984. };
  985. };
  986. case GF_OP_OK:{
  987. // INIT Sending File
  988. char tB[256];
  989. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  990. #ifdef DEBUG
  991. LOG(tB);
  992. #endif
  993. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  994. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  995. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  996. #ifdef DEBUG_EXTRA
  997. LOG("OPEN -> Send Info");
  998. #endif
  999. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  1000. memcpy(
  1001. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1002. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  1003. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  1004. );
  1005. } else {
  1006. #ifdef DEBUG_EXTRA
  1007. LOG("NOPEN -> Cancel");
  1008. #endif
  1009. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  1010. transactionSetResult( TRANSACTION_RESULT_OK );
  1011. return;
  1012. };
  1013. break;
  1014. };
  1015. case GF_OP_OPEN:{
  1016. #ifdef DEBUG_EXTRA
  1017. LOG("Info -> Data");
  1018. #endif
  1019. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  1020. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1021. 1,
  1022. 48,
  1023. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1024. );
  1025. #ifdef DEBUG_EXTRA
  1026. char tB[64];
  1027. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  1028. LOG( tB );
  1029. #endif
  1030. break;
  1031. };
  1032. case GF_OP_DATA:{
  1033. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1034. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  1035. #ifdef DEBUG
  1036. char tB[64];
  1037. if ( pos != EOF ){
  1038. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  1039. LOG( tB );
  1040. } else {
  1041. LOG("File Ended!");
  1042. };
  1043. #endif
  1044. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1045. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  1046. }
  1047. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1048. 1,
  1049. 48,
  1050. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1051. );
  1052. #ifdef DEBUG
  1053. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  1054. LOG( tB );
  1055. #endif
  1056. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  1057. #ifdef DEBUG
  1058. LOG("Change to Close");
  1059. #endif
  1060. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  1061. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1062. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  1063. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1064. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  1065. };
  1066. };
  1067. break;
  1068. };
  1069. };
  1070. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1071. if( !sendGF_package(
  1072. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  1073. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  1074. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  1075. )
  1076. ){
  1077. LOG_ERROR("Fall Back to Disconnected!");
  1078. setWM( LRF_WM_CONNECTION );
  1079. } else transactionWaitResult();
  1080. } else {
  1081. // Exit From GetFile Mode --> No need --> Reset Device
  1082. transactionSetResult( TRANSACTION_RESULT_OK );
  1083. };
  1084. break;
  1085. };
  1086. case LRF_WS_STAGE_3:{
  1087. // Remove Generated Files
  1088. if( m_bTGENFILECNT ){
  1089. for( uint8_t idx = 0; idx < m_bTGENFILECNT; idx++){
  1090. char tName[256];
  1091. sprintf( tName, "data/uploads/%s", m_pTGENFILENAMES[idx]);
  1092. unlink( tName );
  1093. };
  1094. };
  1095. transactionSetResult( TRANSACTION_RESULT_OK );
  1096. break;
  1097. };
  1098. case LRF_WS_STAGE_4:{
  1099. //Issue Full Reset
  1100. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1101. if ( !doFullReset() ) {
  1102. LOG_ERROR("Fall Back to Disconnected!");
  1103. setWM( LRF_WM_CONNECTION );
  1104. } else transactionWaitResult();
  1105. break;
  1106. };
  1107. case LRF_WS_STAGE_13: setWM( LRF_WM_IDLE ); break;
  1108. default: setStage( LRF_WS_INIT ); break;
  1109. };
  1110. break;
  1111. };
  1112. case STG_WAIT: waitStateFunction(); break;
  1113. case STG_POOL: poolStateFunction(); break;
  1114. };
  1115. };
  1116. void device2DSensor::save_detection(){
  1117. #ifdef DEBUG_EXTRA
  1118. LOG("SAVE DETECTION");
  1119. #endif
  1120. if( initWModeFunction( LRF_WM_SAVE_DETECTION ) ){
  1121. updateDataStatus( ARGUS_DS_BUSY );
  1122. memset( m_pTGENFILENAMES[0], 0, 33 );
  1123. memset( m_pTGENFILENAMES[1], 0, 33 );
  1124. memset( m_pTGENFILENAMES[2], 0, 33 );
  1125. m_bTGENFILECNT = 0;
  1126. m_bTGENFILE = 0;
  1127. m_sGetFileTransfers.current = 0;
  1128. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  1129. if ( m_sGetFileTransfers.helpers.size() ) {
  1130. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  1131. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  1132. free( (*idx) );
  1133. };
  1134. m_sGetFileTransfers.helpers.clear();
  1135. };
  1136. };
  1137. switch( getPPStatus() ){
  1138. case STG_PUSH:{
  1139. switch( getStage() ) {
  1140. case LRF_WS_INIT:{
  1141. if( m_bTGENFILECNT == 0 ){
  1142. if( generateRestartFile( m_bTGENFILE ) ){
  1143. GETFILE_IO_HELPER *tH = NULL;
  1144. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  1145. if ( tH ) {
  1146. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  1147. strncpy( tH->destName, "updateMZ.bat", 16 );
  1148. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  1149. struct stat st;
  1150. char tB[256];
  1151. sprintf( tB, "data/uploads/%s", tH->sourceName );
  1152. stat( tB, &st );
  1153. tH->fileSize = st.st_size;
  1154. tH->state = GF_OP_OK;
  1155. tH->db_id = 0;
  1156. tH->index = 0x04;
  1157. m_sGetFileTransfers.helpers.push_back( tH );
  1158. m_bTGENFILE++;
  1159. m_bTGENFILECNT++;
  1160. };
  1161. } else {
  1162. LOG_ERROR("Gen UpdateMZ Failure!");
  1163. };
  1164. };
  1165. // reread settings from DB
  1166. transactionSetResult( TRANSACTION_RESULT_OK );
  1167. break;
  1168. };
  1169. case LRF_WS_STAGE_1:{
  1170. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  1171. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1172. m_bRequestedDeviceWM = MODE_GETFILE;
  1173. if( !setMode( MODE_GETFILE ) ) {
  1174. LOG_ERROR("Fall Back to Disconnected!");
  1175. setWM( LRF_WM_CONNECTION );
  1176. } else transactionWaitResult();
  1177. } else {
  1178. transactionSetResult( TRANSACTION_RESULT_OK );
  1179. };
  1180. break;
  1181. };
  1182. case LRF_WS_STAGE_2:{
  1183. if( m_sGetFileTransfers.helpers.size() ){
  1184. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  1185. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  1186. case GF_OP_CLOSE:{
  1187. // After Sending check if have other file to send
  1188. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  1189. m_sGetFileTransfers.current++;
  1190. } else {
  1191. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  1192. // case GF_EM_ISSUE_RESET:{
  1193. // break;
  1194. // };
  1195. // case GF_EM_ISSUE_SAVE_FW:{
  1196. // break;
  1197. // }
  1198. // default: setStage( LRF_WS_STAGE_7 );
  1199. //};
  1200. transactionSetResult( TRANSACTION_RESULT_OK );
  1201. return;
  1202. };
  1203. };
  1204. case GF_OP_OK:{
  1205. // INIT Sending File
  1206. char tB[256];
  1207. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  1208. #ifdef DEBUG
  1209. LOG(tB);
  1210. #endif
  1211. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  1212. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  1213. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  1214. #ifdef DEBUG_EXTRA
  1215. LOG("OPEN -> Send Info");
  1216. #endif
  1217. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  1218. memcpy(
  1219. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1220. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  1221. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  1222. );
  1223. } else {
  1224. #ifdef DEBUG_EXTRA
  1225. LOG("NOPEN -> Cancel");
  1226. #endif
  1227. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  1228. transactionSetResult( TRANSACTION_RESULT_OK );
  1229. return;
  1230. };
  1231. break;
  1232. };
  1233. case GF_OP_OPEN:{
  1234. #ifdef DEBUG_EXTRA
  1235. LOG("Info -> Data");
  1236. #endif
  1237. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  1238. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1239. 1,
  1240. 48,
  1241. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1242. );
  1243. #ifdef DEBUG_EXTRA
  1244. char tB[64];
  1245. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  1246. LOG( tB );
  1247. #endif
  1248. break;
  1249. };
  1250. case GF_OP_DATA:{
  1251. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1252. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  1253. #ifdef DEBUG_EXTRA
  1254. char tB[64];
  1255. if ( pos != EOF ){
  1256. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  1257. LOG( tB );
  1258. } else {
  1259. LOG("File Ended!");
  1260. };
  1261. #endif
  1262. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1263. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  1264. }
  1265. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1266. 1,
  1267. 48,
  1268. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1269. );
  1270. #ifdef DEBUG_EXTRA
  1271. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  1272. LOG( tB );
  1273. #endif
  1274. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  1275. #ifdef DEBUG_EXTRA
  1276. LOG("Change to Close");
  1277. #endif
  1278. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  1279. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1280. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  1281. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1282. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  1283. };
  1284. };
  1285. break;
  1286. };
  1287. };
  1288. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1289. if( !sendGF_package(
  1290. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  1291. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  1292. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  1293. )
  1294. ){
  1295. LOG_ERROR("Fall Back to Disconnected!");
  1296. setWM( LRF_WM_CONNECTION );
  1297. } else transactionWaitResult();
  1298. } else {
  1299. // Exit From GetFile Mode --> No need --> Reset Device
  1300. transactionSetResult( TRANSACTION_RESULT_OK );
  1301. };
  1302. break;
  1303. };
  1304. case LRF_WS_STAGE_3:{
  1305. // Remove Generated Files
  1306. if( m_bTGENFILECNT ){
  1307. for( uint8_t idx = 0; idx < m_bTGENFILECNT; idx++){
  1308. char tName[256];
  1309. sprintf( tName, "data/uploads/%s", m_pTGENFILENAMES[idx]);
  1310. unlink( tName );
  1311. };
  1312. };
  1313. transactionSetResult( TRANSACTION_RESULT_OK );
  1314. break;
  1315. };
  1316. case LRF_WS_STAGE_4:{
  1317. LOG("Send Master Profile!");
  1318. //ANODE_WM_2D_SET_MASTER_PARAM
  1319. PLGS_2D_PARAMETERS tData = m_pDBC->getLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, true );
  1320. if ( tData ) {
  1321. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1322. if (!setParameters( tData, true, m_nActiveDetectionProfile)) {
  1323. LOG_ERROR("Fall Back to Disconnected!");
  1324. setWM( LRF_WM_CONNECTION );
  1325. } else transactionWaitResult();
  1326. free( tData );
  1327. } else transactionSetResult( TRANSACTION_RESULT_OK );
  1328. break;
  1329. };
  1330. case LRF_WS_STAGE_5:{
  1331. LOG("Send Slave Profile!");
  1332. //ANODE_WM_2D_SET_SLAVE_PARAM
  1333. PLGS_2D_PARAMETERS tData = m_pDBC->getLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, false );
  1334. if ( tData ) {
  1335. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1336. if (!setParameters( tData, false, m_nActiveDetectionProfile)) {
  1337. LOG_ERROR("Fall Back to Disconnected!");
  1338. setWM( LRF_WM_CONNECTION );
  1339. } else transactionWaitResult();
  1340. free( tData );
  1341. } else transactionSetResult( TRANSACTION_RESULT_OK );
  1342. break;
  1343. };
  1344. case LRF_WS_STAGE_6:{
  1345. //Issue Full Reset
  1346. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1347. if ( !doFullReset() ) {
  1348. LOG_ERROR("Fall Back to Disconnected!");
  1349. setWM( LRF_WM_CONNECTION );
  1350. } else transactionWaitResult();
  1351. break;
  1352. };
  1353. case LRF_WS_STAGE_7: setWM( LRF_WM_IDLE ); break;
  1354. default: setStage( LRF_WS_INIT ); break;
  1355. };
  1356. break;
  1357. };
  1358. case STG_WAIT: waitStateFunction(); break;
  1359. case STG_POOL: poolStateFunction(); break;
  1360. };
  1361. };
  1362. void device2DSensor::save_masks(){
  1363. #ifdef DEBUG_EXTRA
  1364. LOG("SAVE MASKS");
  1365. #endif
  1366. // Reset State
  1367. if( initWModeFunction( LRF_WM_SAVE_MASKS ) ){
  1368. updateDataStatus( ARGUS_DS_BUSY );
  1369. memset( m_pTGENFILENAMES[0], 0, 33 );
  1370. memset( m_pTGENFILENAMES[1], 0, 33 );
  1371. memset( m_pTGENFILENAMES[2], 0, 33 );
  1372. m_bTGENFILECNT = 0;
  1373. m_bTGENFILE = 0;
  1374. m_sGetFileTransfers.current = 0;
  1375. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  1376. if ( m_sGetFileTransfers.helpers.size() ) {
  1377. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  1378. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  1379. free( (*idx) );
  1380. };
  1381. m_sGetFileTransfers.helpers.clear();
  1382. };
  1383. };
  1384. switch( getPPStatus() ){
  1385. case STG_PUSH:{
  1386. switch( getStage() ) {
  1387. case LRF_WS_INIT:{
  1388. if( m_bTGENFILECNT == 0 ){
  1389. if( generateRestartFile( m_bTGENFILE ) ){
  1390. GETFILE_IO_HELPER *tH = NULL;
  1391. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  1392. if ( tH ) {
  1393. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  1394. strncpy( tH->destName, "updateMZ.bat", 16 );
  1395. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  1396. struct stat st;
  1397. char tB[256];
  1398. sprintf( tB, "data/uploads/%s", tH->sourceName );
  1399. stat( tB, &st );
  1400. tH->fileSize = st.st_size;
  1401. tH->state = GF_OP_OK;
  1402. tH->db_id = 0;
  1403. tH->index = 0x04;
  1404. m_sGetFileTransfers.helpers.push_back( tH );
  1405. m_bTGENFILE++;
  1406. m_bTGENFILECNT++;
  1407. };
  1408. } else {
  1409. LOG_ERROR("Gen UpdateMZ Failure!");
  1410. };
  1411. };
  1412. cleanShadowStructs();
  1413. if( m_pDBC->fillShadow2D( m_sLRF_DATA.id, m_sShadow ) ){
  1414. if( rasterizeShadow() ){
  1415. #ifdef DEBUG_EXTRA
  1416. makeShadowPic("data/shadow.png");
  1417. #endif
  1418. transactionSetResult( TRANSACTION_RESULT_OK );
  1419. } else {
  1420. setStage( LRF_WS_STAGE_11 );
  1421. };
  1422. } else {
  1423. setStage( LRF_WS_STAGE_11 );
  1424. };
  1425. break;
  1426. };
  1427. case LRF_WS_STAGE_1:{
  1428. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  1429. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1430. m_bRequestedDeviceWM = MODE_GETFILE;
  1431. if( !setMode( MODE_GETFILE ) ) {
  1432. LOG_ERROR("Fall Back to Disconnected!");
  1433. setWM( LRF_WM_CONNECTION );
  1434. } else transactionWaitResult();
  1435. } else {
  1436. transactionSetResult( TRANSACTION_RESULT_OK );
  1437. };
  1438. break;
  1439. };
  1440. case LRF_WS_STAGE_2:{
  1441. if( m_sGetFileTransfers.helpers.size() ){
  1442. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  1443. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  1444. case GF_OP_CLOSE:{
  1445. // After Sending check if have other file to send
  1446. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  1447. m_sGetFileTransfers.current++;
  1448. } else {
  1449. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  1450. // case GF_EM_ISSUE_RESET:{
  1451. // break;
  1452. // };
  1453. // case GF_EM_ISSUE_SAVE_FW:{
  1454. // break;
  1455. // }
  1456. // default: setStage( LRF_WS_STAGE_7 );
  1457. //};
  1458. transactionSetResult( TRANSACTION_RESULT_OK );
  1459. return;
  1460. };
  1461. };
  1462. case GF_OP_OK:{
  1463. // INIT Sending File
  1464. char tB[256];
  1465. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  1466. #ifdef DEBUG
  1467. LOG(tB);
  1468. #endif
  1469. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  1470. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  1471. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  1472. #ifdef DEBUG_EXTRA
  1473. LOG("OPEN -> Send Info");
  1474. #endif
  1475. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  1476. memcpy(
  1477. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1478. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  1479. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  1480. );
  1481. } else {
  1482. #ifdef DEBUG_EXTRA
  1483. LOG("NOPEN -> Cancel");
  1484. #endif
  1485. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  1486. transactionSetResult( TRANSACTION_RESULT_OK );
  1487. return;
  1488. };
  1489. break;
  1490. };
  1491. case GF_OP_OPEN:{
  1492. #ifdef DEBUG_EXTRA
  1493. LOG("Info -> Data");
  1494. #endif
  1495. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  1496. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1497. 1,
  1498. 48,
  1499. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1500. );
  1501. #ifdef DEBUG_EXTRA
  1502. char tB[64];
  1503. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  1504. LOG( tB );
  1505. #endif
  1506. break;
  1507. };
  1508. case GF_OP_DATA:{
  1509. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1510. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  1511. #ifdef DEBUG_EXTRA
  1512. char tB[64];
  1513. if ( pos != EOF ){
  1514. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  1515. LOG( tB );
  1516. } else {
  1517. LOG("File Ended!");
  1518. };
  1519. #endif
  1520. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1521. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  1522. }
  1523. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1524. 1,
  1525. 48,
  1526. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1527. );
  1528. #ifdef DEBUG_EXTRA
  1529. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  1530. LOG( tB );
  1531. #endif
  1532. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  1533. #ifdef DEBUG_EXTRA
  1534. LOG("Change to Close");
  1535. #endif
  1536. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  1537. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1538. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  1539. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1540. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  1541. };
  1542. };
  1543. break;
  1544. };
  1545. };
  1546. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1547. if( !sendGF_package(
  1548. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  1549. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  1550. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  1551. )
  1552. ){
  1553. LOG_ERROR("Fall Back to Disconnected!");
  1554. setWM( LRF_WM_CONNECTION );
  1555. } else transactionWaitResult();
  1556. } else {
  1557. // Exit From GetFile Mode --> No need --> Reset Device
  1558. transactionSetResult( TRANSACTION_RESULT_OK );
  1559. };
  1560. break;
  1561. };
  1562. case LRF_WS_STAGE_3:{
  1563. // Remove Generated Files
  1564. if( m_bTGENFILECNT ){
  1565. for( uint8_t idx = 0; idx < m_bTGENFILECNT; idx++){
  1566. char tName[256];
  1567. sprintf( tName, "data/uploads/%s", m_pTGENFILENAMES[idx]);
  1568. unlink( tName );
  1569. };
  1570. };
  1571. transactionSetResult( TRANSACTION_RESULT_OK );
  1572. break;
  1573. };
  1574. case LRF_WS_STAGE_4:{
  1575. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1576. if( m_bActualDeviceWM != MODE_MASK ) {
  1577. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1578. m_bRequestedDeviceWM = MODE_MASK;
  1579. if( !setMode( MODE_MASK ) ) {
  1580. LOG_ERROR("Fall Back to Disconnected!");
  1581. setWM( LRF_WM_CONNECTION );
  1582. } else transactionWaitResult();
  1583. } else {
  1584. transactionSetResult( TRANSACTION_RESULT_OK );
  1585. };
  1586. break;
  1587. };
  1588. case LRF_WS_STAGE_5:{
  1589. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1590. if (!setShadowInfo( m_sShadowHelper.m_bSequence, m_sShadow )) {
  1591. LOG_ERROR("Fall Back to Disconnected!");
  1592. setWM( LRF_WM_CONNECTION );
  1593. } else transactionWaitResult();
  1594. break;
  1595. };
  1596. case LRF_WS_STAGE_6:{
  1597. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1598. if( m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ){
  1599. m_sShadowHelper.m_nCurrentPoint = 0;
  1600. if(!setShadowPoly( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentPolygon)){
  1601. LOG_ERROR("Fall Back to Disconnected!");
  1602. setWM( LRF_WM_CONNECTION );
  1603. } else transactionWaitResult();
  1604. } else {
  1605. #ifdef DEBUG_EXTRA
  1606. LOG("Start Send Rays!");
  1607. #endif
  1608. m_sShadowHelper.m_nCurrentRayLine = 0;
  1609. //skip all empty angles of binary shadow
  1610. while( ( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount == 0 ) && m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  1611. m_sShadowHelper.m_nCurrentRayLine++;
  1612. };
  1613. if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  1614. //if we have an shadows -> transfer else skeep
  1615. setStage( LRF_WS_STAGE_8 );
  1616. } else {
  1617. #ifdef DEBUG_EXTRA
  1618. LOG("Skip Uploading Rays");
  1619. #endif
  1620. setStage( LRF_WS_STAGE_10 );
  1621. };
  1622. };
  1623. break;
  1624. };
  1625. case LRF_WS_STAGE_7:{
  1626. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1627. #ifdef DEBUG_EXTRA
  1628. char tBuff[128];
  1629. sprintf( tBuff,"Send Point %d of %d", (m_sShadowHelper.m_nCurrentPoint + 1), m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount );
  1630. LOG( tBuff );
  1631. #endif
  1632. if( m_sShadowHelper.m_nCurrentPoint < m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount ){
  1633. if( !setShadowPolyPoint( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentPolygon, m_sShadowHelper.m_nCurrentPoint) ){
  1634. LOG_ERROR("Fall Back to Disconnected!");
  1635. setWM( LRF_WM_CONNECTION );
  1636. } else transactionWaitResult();
  1637. } else {
  1638. m_sShadowHelper.m_nCurrentPolygon ++;
  1639. setStage( LRF_WS_STAGE_6 );
  1640. };
  1641. break;
  1642. };
  1643. case LRF_WS_STAGE_8:{
  1644. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1645. #ifdef DEBUG_EXTRA
  1646. char tBuff[128];
  1647. sprintf( tBuff,"Send Shadow for angle %d [%d rays]", m_sShadowHelper.m_nCurrentRayLine, m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount );
  1648. LOG( tBuff );
  1649. #endif
  1650. if( !setShadowRay( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentRayLine ) ){
  1651. LOG_ERROR("Fall Back to Disconnected!");
  1652. setWM( LRF_WM_CONNECTION );
  1653. } else transactionWaitResult();
  1654. break;
  1655. };
  1656. case LRF_WS_STAGE_9:{
  1657. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1658. #ifdef DEBUG_EXTRA
  1659. char tBuff[128];
  1660. sprintf( tBuff,"Send Shadow RayLine %d for andle %d", m_sShadowHelper.m_nCurrentRay, m_sShadowHelper.m_nCurrentRayLine );
  1661. LOG( tBuff );
  1662. #endif
  1663. if( m_sShadowHelper.m_nCurrentRay < m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount ) {
  1664. if( !setShadowRayLine( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentRayLine, m_sShadowHelper.m_nCurrentRay ) ){
  1665. LOG_ERROR("Fall Back to Disconnected!");
  1666. setWM( LRF_WM_CONNECTION );
  1667. } else transactionWaitResult();
  1668. } else {
  1669. // search next not empty angle
  1670. do {
  1671. m_sShadowHelper.m_nCurrentRayLine++;
  1672. } while ( ( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount == 0 ) && m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES );
  1673. if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  1674. setStage( LRF_WS_STAGE_8 );
  1675. } else {
  1676. // If not found -> finish upload shadow
  1677. transactionSetResult( TRANSACTION_RESULT_OK );
  1678. };
  1679. };
  1680. break;
  1681. };
  1682. case LRF_WS_STAGE_10:{
  1683. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1684. if (!setShadowDone( m_sShadowHelper.m_bSequence )) {
  1685. LOG_ERROR("Fall Back to Disconnected!");
  1686. setWM( LRF_WM_CONNECTION );
  1687. } else transactionWaitResult();
  1688. break;
  1689. };
  1690. case LRF_WS_STAGE_11: setWM( LRF_WM_IDLE ); break;
  1691. default: setStage( LRF_WS_INIT ); break;
  1692. };
  1693. break;
  1694. };
  1695. case STG_WAIT: waitStateFunction(); break;
  1696. case STG_POOL: poolStateFunction(); break;
  1697. };
  1698. };
  1699. void device2DSensor::save_eprom(){
  1700. };
  1701. void device2DSensor::getfileMode(){
  1702. #ifdef DEBUG_EXTRA
  1703. LOG("GETFILE");
  1704. #endif
  1705. // Reset State
  1706. initWModeFunction( LRF_WM_FILE );
  1707. switch( getPPStatus() ){
  1708. case STG_PUSH:{
  1709. switch( getStage() ) {
  1710. case LRF_WS_INIT:{
  1711. m_nCurrentAngle = 0;
  1712. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  1713. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1714. m_bRequestedDeviceWM = MODE_GETFILE;
  1715. if( !setMode( MODE_GETFILE ) ) {
  1716. LOG_ERROR("Fall Back to Disconnected!");
  1717. setWM( LRF_WM_CONNECTION );
  1718. } else transactionWaitResult();
  1719. } else {
  1720. transactionSetResult( TRANSACTION_RESULT_OK );
  1721. };
  1722. break;
  1723. };
  1724. case LRF_WS_STAGE_1:{
  1725. if( m_sGetFileTransfers.helpers.size() ){
  1726. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  1727. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  1728. case GF_OP_CLOSE:{
  1729. // After Sending check if have other file to send
  1730. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  1731. m_sGetFileTransfers.current++;
  1732. } else {
  1733. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  1734. // case GF_EM_ISSUE_RESET:{
  1735. // break;
  1736. // };
  1737. // case GF_EM_ISSUE_SAVE_FW:{
  1738. // break;
  1739. // }
  1740. // default: setStage( LRF_WS_STAGE_7 );
  1741. //};
  1742. transactionSetResult( TRANSACTION_RESULT_OK );
  1743. return;
  1744. };
  1745. };
  1746. case GF_OP_OK:{
  1747. // INIT Sending File
  1748. char tB[256];
  1749. #ifdef DEBUG_EXTRA
  1750. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  1751. LOG(tB);
  1752. #endif
  1753. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  1754. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  1755. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  1756. #ifdef DEBUG_EXTRA
  1757. LOG("OPEN -> Send Info");
  1758. #endif
  1759. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  1760. memcpy(
  1761. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1762. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  1763. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  1764. );
  1765. } else {
  1766. #ifdef DEBUG_EXTRA
  1767. LOG("NOPEN -> Cancel");
  1768. #endif
  1769. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  1770. transactionSetResult( TRANSACTION_RESULT_OK );
  1771. return;
  1772. };
  1773. break;
  1774. };
  1775. case GF_OP_OPEN:{
  1776. #ifdef DEBUG_EXTRA
  1777. LOG("Info -> Data");
  1778. #endif
  1779. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  1780. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1781. 1,
  1782. 48,
  1783. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1784. );
  1785. #ifdef DEBUG_EXTRA
  1786. char tB[64];
  1787. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  1788. LOG( tB );
  1789. #endif
  1790. break;
  1791. };
  1792. case GF_OP_DATA:{
  1793. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1794. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  1795. #ifdef DEBUG_EXTRA
  1796. char tB[64];
  1797. if ( pos != EOF ){
  1798. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  1799. LOG( tB );
  1800. } else {
  1801. LOG("File Ended!");
  1802. };
  1803. #endif
  1804. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1805. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  1806. }
  1807. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1808. 1,
  1809. 48,
  1810. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1811. );
  1812. #ifdef DEBUG_EXTRA
  1813. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  1814. LOG( tB );
  1815. #endif
  1816. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  1817. #ifdef DEBUG_EXTRA
  1818. LOG("Change to Close");
  1819. #endif
  1820. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  1821. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1822. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  1823. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1824. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  1825. };
  1826. };
  1827. break;
  1828. };
  1829. };
  1830. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1831. if( !sendGF_package(
  1832. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  1833. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  1834. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  1835. )
  1836. ){
  1837. LOG_ERROR("Fall Back to Disconnected!");
  1838. setWM( LRF_WM_CONNECTION );
  1839. } else transactionWaitResult();
  1840. } else {
  1841. // Exit From GetFile Mode
  1842. transactionSetResult( TRANSACTION_RESULT_OK );
  1843. };
  1844. break;
  1845. };
  1846. case LRF_WS_STAGE_2:
  1847. updateDataStatus( ARGUS_DS_READY );
  1848. setWM( LRF_WM_IDLE );
  1849. break;
  1850. };
  1851. break;
  1852. };
  1853. case STG_WAIT: waitStateFunction(); break;
  1854. case STG_POOL: poolStateFunction(); break;
  1855. };
  1856. };
  1857. void device2DSensor::drawMode(){
  1858. #ifdef DEBUG_EXTRA
  1859. LOG("DRAW");
  1860. #endif
  1861. // Reset State
  1862. if( initWModeFunction( LRF_WM_BORDER ) ){
  1863. m_nCurrentAngle = 0;
  1864. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT << 1;
  1865. };
  1866. switch( getPPStatus() ){
  1867. case STG_PUSH:{
  1868. switch( getStage() ) {
  1869. case LRF_WS_INIT:{
  1870. if ( m_bActualDeviceWM != MODE_BORDER ) {
  1871. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1872. m_bRequestedDeviceWM = MODE_BORDER;
  1873. if( !setMode( MODE_BORDER ) ) {
  1874. LOG_ERROR("Fall Back to Disconnected!");
  1875. setWM( LRF_WM_CONNECTION );
  1876. } else transactionWaitResult();
  1877. } else {
  1878. transactionSetResult( TRANSACTION_RESULT_OK );
  1879. };
  1880. break;
  1881. };
  1882. case LRF_WS_STAGE_1:{
  1883. transactionSetResult( TRANSACTION_RESULT_OK );
  1884. break;
  1885. };
  1886. case LRF_WS_STAGE_2:{
  1887. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1888. if( !getFastDraw( m_nCurrentAngle ) ) {
  1889. LOG_ERROR("Fall Back to Disconnected!");
  1890. setWM( LRF_WM_CONNECTION );
  1891. } else transactionWaitResult();
  1892. break;
  1893. };
  1894. case LRF_WS_STAGE_3:{
  1895. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1896. if ( !setMode( MODE_DETECTOR ) ) {
  1897. LOG_ERROR("Fall Back to Disconnected!");
  1898. setWM( LRF_WM_CONNECTION );
  1899. } else transactionWaitResult();
  1900. break;
  1901. };
  1902. case LRF_WS_STAGE_4:{
  1903. updateDataStatus( ARGUS_DS_READY );
  1904. setWM( LRF_WM_IDLE );
  1905. break;
  1906. };
  1907. };
  1908. break;
  1909. };
  1910. case STG_WAIT: waitStateFunction(); break;
  1911. case STG_POOL: poolStateFunction(); break;
  1912. };
  1913. };
  1914. void device2DSensor::maskMode(){
  1915. #ifdef DEBUG_EXTRA
  1916. LOG("MASKOP-ShortSet+MZ");
  1917. #endif
  1918. if( initWModeFunction( LRF_WM_STATUS_MASK ) ){
  1919. //m_bCurShadowMask = m_pDBC->getLRFMasksStatus( m_sLRF_DATA.id );
  1920. #ifdef DEBUG_EXTRA
  1921. char tBuf[64];
  1922. sprintf( tBuf, "CMask: 0x%02X", m_bCurShadowMask );
  1923. LOG( tBuf );
  1924. #endif
  1925. updateDataStatus( ARGUS_DS_BUSY );
  1926. memset( m_pTGENFILENAMES[0], 0, 33 );
  1927. memset( m_pTGENFILENAMES[1], 0, 33 );
  1928. memset( m_pTGENFILENAMES[2], 0, 33 );
  1929. m_bTGENFILECNT = 0;
  1930. m_bTGENFILE = 0;
  1931. m_sGetFileTransfers.current = 0;
  1932. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  1933. if ( m_sGetFileTransfers.helpers.size() ) {
  1934. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  1935. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  1936. free( (*idx) );
  1937. };
  1938. m_sGetFileTransfers.helpers.clear();
  1939. };
  1940. };
  1941. switch( getPPStatus() ){
  1942. case STG_PUSH:{
  1943. switch( getStage() ) {
  1944. case LRF_WS_INIT:{
  1945. if( m_bTGENFILECNT == 0 ){
  1946. if( generateRestartFile( m_bTGENFILE ) ){
  1947. GETFILE_IO_HELPER *tH = NULL;
  1948. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  1949. if ( tH ) {
  1950. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  1951. strncpy( tH->destName, "updateMZ.bat", 16 );
  1952. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  1953. struct stat st;
  1954. char tB[256];
  1955. sprintf( tB, "data/uploads/%s", tH->sourceName );
  1956. stat( tB, &st );
  1957. tH->fileSize = st.st_size;
  1958. tH->state = GF_OP_OK;
  1959. tH->db_id = 0;
  1960. tH->index = 0x04;
  1961. m_sGetFileTransfers.helpers.push_back( tH );
  1962. m_bTGENFILE++;
  1963. m_bTGENFILECNT++;
  1964. };
  1965. } else {
  1966. LOG_ERROR("Gen UpdateMZ Failure!");
  1967. };
  1968. };
  1969. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1970. uint8_t cm = m_pDBC->getLRFMasksStatus( m_sLRF_DATA.id );
  1971. EVENT_CONTAINER * bEVT = NULL;
  1972. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  1973. if( m_bCurShadowMask < cm ){
  1974. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_OP_ON_MASK, NULL, NULL, tData);
  1975. } else {
  1976. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_OP_OFF_MASK, NULL, NULL, tData);
  1977. };
  1978. if( bEVT != NULL ) {
  1979. m_pEventHeap->broadcast( bEVT );
  1980. } else {
  1981. free( tData );
  1982. };
  1983. m_bCurShadowMask = cm;
  1984. if ( !setShadowStatus( m_bCurShadowMask ) ) {
  1985. LOG_ERROR("Fall Back to Disconnected!");
  1986. setWM( LRF_WM_CONNECTION );
  1987. } else transactionWaitResult();
  1988. break;
  1989. };
  1990. case LRF_WS_STAGE_1:{
  1991. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1992. #ifdef DEBUG_EXTRA
  1993. LOG("Sending Update MZ!");
  1994. #endif
  1995. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  1996. m_bRequestedDeviceWM = MODE_GETFILE;
  1997. if( !setMode( MODE_GETFILE ) ) {
  1998. LOG_ERROR("Fall Back to Disconnected!");
  1999. setWM( LRF_WM_CONNECTION );
  2000. } else transactionWaitResult();
  2001. } else {
  2002. transactionSetResult( TRANSACTION_RESULT_OK );
  2003. };
  2004. break;
  2005. };
  2006. case LRF_WS_STAGE_2:{
  2007. if( m_sGetFileTransfers.helpers.size() ){
  2008. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  2009. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  2010. case GF_OP_CLOSE:{
  2011. // After Sending check if have other file to send
  2012. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  2013. m_sGetFileTransfers.current++;
  2014. } else {
  2015. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  2016. // case GF_EM_ISSUE_RESET:{
  2017. // break;
  2018. // };
  2019. // case GF_EM_ISSUE_SAVE_FW:{
  2020. // break;
  2021. // }
  2022. // default: setStage( LRF_WS_STAGE_7 );
  2023. //};
  2024. transactionSetResult( TRANSACTION_RESULT_OK );
  2025. return;
  2026. };
  2027. };
  2028. case GF_OP_OK:{
  2029. // INIT Sending File
  2030. char tB[256];
  2031. #ifdef DEBUG_EXTRA
  2032. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  2033. LOG(tB);
  2034. #endif
  2035. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  2036. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  2037. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  2038. #ifdef DEBUG_EXTRA
  2039. LOG("OPEN -> Send Info");
  2040. #endif
  2041. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  2042. memcpy(
  2043. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  2044. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  2045. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  2046. );
  2047. } else {
  2048. #ifdef DEBUG_EXTRA
  2049. LOG("NOPEN -> Cancel");
  2050. #endif
  2051. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  2052. transactionSetResult( TRANSACTION_RESULT_OK );
  2053. return;
  2054. };
  2055. break;
  2056. };
  2057. case GF_OP_OPEN:{
  2058. #ifdef DEBUG_EXTRA
  2059. LOG("Info -> Data");
  2060. #endif
  2061. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  2062. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  2063. 1,
  2064. 48,
  2065. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  2066. );
  2067. #ifdef DEBUG_EXTRA
  2068. char tB[64];
  2069. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  2070. LOG( tB );
  2071. #endif
  2072. break;
  2073. };
  2074. case GF_OP_DATA:{
  2075. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  2076. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  2077. #ifdef DEBUG_EXTRA
  2078. char tB[64];
  2079. if ( pos != EOF ){
  2080. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  2081. LOG( tB );
  2082. } else {
  2083. LOG("File Ended!");
  2084. };
  2085. #endif
  2086. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  2087. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  2088. }
  2089. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  2090. 1,
  2091. 48,
  2092. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  2093. );
  2094. #ifdef DEBUG_EXTRA
  2095. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  2096. LOG( tB );
  2097. #endif
  2098. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  2099. #ifdef DEBUG_EXTRA
  2100. LOG("Change to Close");
  2101. #endif
  2102. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  2103. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  2104. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  2105. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  2106. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  2107. };
  2108. };
  2109. break;
  2110. };
  2111. };
  2112. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2113. if( !sendGF_package(
  2114. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  2115. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  2116. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  2117. )
  2118. ){
  2119. LOG_ERROR("Fall Back to Disconnected!");
  2120. setWM( LRF_WM_CONNECTION );
  2121. } else transactionWaitResult();
  2122. } else {
  2123. // Exit From GetFile Mode --> No need --> Reset Device
  2124. transactionSetResult( TRANSACTION_RESULT_OK );
  2125. };
  2126. break;
  2127. };
  2128. case LRF_WS_STAGE_3:{
  2129. // Remove Generated Files
  2130. if( m_bTGENFILECNT ){
  2131. for( uint8_t idx = 0; idx < m_bTGENFILECNT; idx++){
  2132. char tName[256];
  2133. sprintf( tName, "data/uploads/%s", m_pTGENFILENAMES[idx]);
  2134. unlink( tName );
  2135. };
  2136. };
  2137. transactionSetResult( TRANSACTION_RESULT_OK );
  2138. break;
  2139. };
  2140. case LRF_WS_STAGE_4:{
  2141. //Issue Full Reset
  2142. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2143. if ( !doFullReset() ) {
  2144. LOG_ERROR("Fall Back to Disconnected!");
  2145. setWM( LRF_WM_CONNECTION );
  2146. } else transactionWaitResult();
  2147. break;
  2148. };
  2149. case LRF_WS_STAGE_5:{
  2150. //setWM( LRF_WM_HANDSHAKE );
  2151. setWM( LRF_WM_IDLE );
  2152. break;
  2153. };
  2154. default: setStage( LRF_WS_INIT ); break;
  2155. };
  2156. break;
  2157. };
  2158. case STG_WAIT: waitStateFunction(); break;
  2159. case STG_POOL: poolStateFunction(); break;
  2160. };
  2161. };
  2162. void device2DSensor::alarmMode(){
  2163. #ifdef DEBUG_EXTRA
  2164. LOG("ALRM");
  2165. #endif
  2166. //Reset State
  2167. if( initWModeFunction( LRF_WM_ALARM ) ) if( m_sLRF_DATA.data_status!= ARGUS_DS_ALARMED ) updateDataStatus( ARGUS_DS_ALARMED );
  2168. switch( getPPStatus() ){
  2169. case STG_PUSH:
  2170. switch( getStage() ) {
  2171. case LRF_WS_INIT:{
  2172. if ( m_bActualDeviceWM != MODE_DETECTOR ) {
  2173. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2174. m_bRequestedDeviceWM = MODE_DETECTOR;
  2175. if( !setMode( MODE_DETECTOR ) ) {
  2176. LOG_ERROR("Fall Back to Disconnected!");
  2177. setWM( LRF_WM_CONNECTION );
  2178. } else transactionWaitResult();
  2179. } else {
  2180. transactionSetResult( TRANSACTION_RESULT_OK );
  2181. };
  2182. break;
  2183. };
  2184. case LRF_WS_STAGE_1:{
  2185. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2186. if( !getState2() ) {
  2187. LOG_ERROR("Fall Back to Disconnected!");
  2188. setWM( LRF_WM_CONNECTION );
  2189. } else transactionWaitResult();
  2190. break;
  2191. };
  2192. case LRF_WS_STAGE_2:{
  2193. setStage( LRF_WS_STAGE_1 );
  2194. break;
  2195. };
  2196. default: setStage( LRF_WS_INIT ); break;
  2197. };
  2198. break;
  2199. case STG_WAIT: waitStateFunction(); break;
  2200. case STG_POOL: poolStateFunction(); break;
  2201. };
  2202. };
  2203. void device2DSensor::idleMode(){
  2204. #ifdef DEBUG_EXTRA
  2205. LOG("IDLE");
  2206. #endif
  2207. //Reset State
  2208. initWModeFunction( LRF_WM_IDLE );
  2209. switch( getPPStatus() ){
  2210. case STG_PUSH:
  2211. switch( getStage() ) {
  2212. case LRF_WS_INIT:{
  2213. if ( m_bActualDeviceWM != MODE_DETECTOR ) {
  2214. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2215. m_bRequestedDeviceWM = MODE_DETECTOR;
  2216. if( !setMode( MODE_DETECTOR ) ) {
  2217. LOG_ERROR("Fall Back to Disconnected!");
  2218. setWM( LRF_WM_CONNECTION );
  2219. } else transactionWaitResult();
  2220. } else {
  2221. transactionSetResult( TRANSACTION_RESULT_OK );
  2222. };
  2223. break;
  2224. };
  2225. case LRF_WS_STAGE_1:{
  2226. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2227. if( !getState2() ) {
  2228. LOG_ERROR("Fall Back to Disconnected!");
  2229. setWM( LRF_WM_CONNECTION );
  2230. } else transactionWaitResult();
  2231. break;
  2232. };
  2233. case LRF_WS_STAGE_2:{
  2234. setStage( LRF_WS_STAGE_1 );
  2235. DELAY_10MS( 10 ); // 100 ms
  2236. break;
  2237. };
  2238. default: setStage( LRF_WS_INIT ); break;
  2239. };
  2240. break;
  2241. case STG_WAIT: waitStateFunction(); break;
  2242. case STG_POOL: poolStateFunction(); break;
  2243. };
  2244. };
  2245. void device2DSensor::proceedDBCommands(){
  2246. if( DBC_PUSHED_CMD *tCMD = m_pDBC->getNodePushedCMD( m_sNodeData.node_id ) ) {
  2247. m_nProcessingCmdId = tCMD->id;
  2248. m_pDBC->updateNodePushedCMD( m_nProcessingCmdId, DBC_CMD_STARTED );
  2249. switch( tCMD->CMD ) {
  2250. case ARGUS_LRF_PCMD_FULL_RESET:{
  2251. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2252. DELAY_10MS(10); // 100 ms
  2253. if( !doFullReset()) {
  2254. LOG_ERROR("Fall Back to Disconnected!");
  2255. setWM( LRF_WM_CONNECTION );
  2256. } else {
  2257. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2258. updateDataStatus( ARGUS_DS_BUSY );
  2259. transactionWaitResult();
  2260. };
  2261. #ifdef DEBUG_EXTRA
  2262. } else {
  2263. LOG("Wrong Mode! Not DETECTOR!");
  2264. #endif
  2265. };
  2266. break;
  2267. };
  2268. case ARGUS_LRF_PCMD_RESET:{
  2269. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2270. DELAY_10MS(10); // 100 ms
  2271. if( !doReset()) {
  2272. LOG_ERROR("Fall Back to Disconnected!");
  2273. setWM( LRF_WM_CONNECTION );
  2274. } else {
  2275. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2276. updateDataStatus( ARGUS_DS_STUDY );
  2277. transactionWaitResult();
  2278. };
  2279. #ifdef DEBUG_EXTRA
  2280. } else {
  2281. LOG("Wrong Mode! Not DETECTOR!");
  2282. #endif
  2283. };
  2284. break;
  2285. };
  2286. case ARGUS_LRF_PCMD_UPLOAD_FILE:{
  2287. #ifdef DEBUG_EXTRA
  2288. LOG( "CMD UPLOAD" );
  2289. #endif
  2290. DBC_INT_LIST *pUploads = m_pDBC->listLRFUploads( m_sLRF_DATA.id );
  2291. m_sGetFileTransfers.current = 0;
  2292. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  2293. if ( m_sGetFileTransfers.helpers.size() ) {
  2294. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  2295. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  2296. free( (*idx) );
  2297. };
  2298. m_sGetFileTransfers.helpers.clear();
  2299. };
  2300. if (pUploads != NULL) {
  2301. for( DBC_INT_LIST::iterator idx = pUploads->begin(); idx < pUploads->end(); idx++ ){
  2302. DBC_LRF_UPLOAD_DATA *tData = m_pDBC->getLRFUploadData((*idx));
  2303. if ( tData ) {
  2304. GETFILE_IO_HELPER *tH = NULL;
  2305. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  2306. if ( tH ) {
  2307. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  2308. strncpy( tH->destName, tData->fname, 16 );
  2309. strncpy( tH->sourceName, tData->md5, 32 );
  2310. struct stat st;
  2311. char tB[256];
  2312. sprintf( tB, "data/uploads/%s", tH->sourceName );
  2313. stat( tB, &st );
  2314. tH->fileSize = st.st_size;
  2315. tH->state = GF_OP_OK;
  2316. tH->db_id = (*idx);
  2317. tH->index = 0x04;
  2318. if( tData->transfer_mode > m_sGetFileTransfers.transfer_ending_mode ) m_sGetFileTransfers.transfer_ending_mode = tData->transfer_mode;
  2319. m_sGetFileTransfers.helpers.push_back(tH);
  2320. };
  2321. //m_pDBC->updateLRFUpload( (*idx), 1 );
  2322. } else {
  2323. LOG_ERROR( "No Upload Data Fetched From DB!" );
  2324. };
  2325. };
  2326. pUploads->clear();
  2327. delete( pUploads );
  2328. updateDataStatus( ARGUS_DS_BUSY );
  2329. setWM( LRF_WM_FILE );
  2330. };
  2331. break;
  2332. };
  2333. case ARGUS_LRF_PCMD_DRAW:{
  2334. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2335. if( m_sLRF_DATA.data_status == ARGUS_DS_READY ){
  2336. setWM( LRF_WM_BORDER );
  2337. updateDataStatus( ARGUS_DS_BUSY );
  2338. };
  2339. #ifdef DEBUG_EXTRA
  2340. } else {
  2341. LOG("Wrong Mode! Not DETECTOR!");
  2342. #endif
  2343. };
  2344. break;
  2345. };
  2346. //Masks Deletion
  2347. case 75:
  2348. case 76:
  2349. case 77:
  2350. case 78:
  2351. case 79:{
  2352. EVENT_CONTAINER * bEVT = NULL;
  2353. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  2354. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_OP_OFF_MASK, NULL, NULL, tData );
  2355. if( bEVT != NULL ) {
  2356. m_pEventHeap->broadcast( bEVT );
  2357. } else {
  2358. free( tData );
  2359. };
  2360. setWM( LRF_WM_SAVE_MASKS );
  2361. break;
  2362. };
  2363. case 80:{
  2364. EVENT_CONTAINER * bEVT = NULL;
  2365. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  2366. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_OP_NACK_MASK, NULL, NULL, tData );
  2367. if( bEVT != NULL ) {
  2368. m_pEventHeap->broadcast( bEVT );
  2369. } else {
  2370. free( tData );
  2371. };
  2372. setWM( LRF_WM_SAVE_MASKS );
  2373. break;
  2374. };
  2375. case 81:{
  2376. EVENT_CONTAINER * bEVT = NULL;
  2377. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  2378. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_OP_ACK_MASK, NULL, NULL, tData );
  2379. if( bEVT != NULL ) {
  2380. m_pEventHeap->broadcast( bEVT );
  2381. } else {
  2382. free( tData );
  2383. };
  2384. setWM( LRF_WM_SAVE_MASKS );
  2385. break;
  2386. };
  2387. case ARGUS_LRF_PCMD_READ_ALL:{
  2388. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2389. setWM( LRF_WM_SYNC_UP );
  2390. updateDataStatus( ARGUS_DS_BUSY );
  2391. #ifdef DEBUG_EXTRA
  2392. } else {
  2393. LOG("Wrong Mode! Not DETECTOR!");
  2394. #endif
  2395. };
  2396. break;
  2397. };
  2398. case ARGUS_LRF_PCMD_SAVE_SETTINGS_0:{
  2399. setWM( LRF_WM_SAVE_HW );
  2400. break;
  2401. };
  2402. case ARGUS_LRF_PCMD_SAVE_SETTINGS_1:{
  2403. setWM( LRF_WM_SAVE_DETECTION );
  2404. break;
  2405. };
  2406. case ARGUS_LRF_PCMD_SAVE_SETTINGS_2:{
  2407. setWM( LRF_WM_SAVE_MASKS );
  2408. break;
  2409. };
  2410. case ARGUS_LRF_PCMD_SAVE_SETTINGS_3:{
  2411. setWM( LRF_WM_SAVE_EPROM );
  2412. break;
  2413. };
  2414. case ARGUS_LRF_PCMD_MASK_STATUS_SET:{
  2415. setWM( LRF_WM_STATUS_MASK );
  2416. break;
  2417. };
  2418. case ARGUS_LRF_PCMD_SAVE_ALL:
  2419. case ARGUS_LRF_PCMD_UPDATE_ALL:{
  2420. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2421. setWM( LRF_WM_SYNC_DOWN );
  2422. updateDataStatus( ARGUS_DS_BUSY );
  2423. #ifdef DEBUG_EXTRA
  2424. } else {
  2425. LOG("Wrong Mode! Not DETECTOR!");
  2426. #endif
  2427. };
  2428. break;
  2429. };
  2430. /*
  2431. case ARGUS_LRF_PCMD_SET_DP_0:{
  2432. if( tCMD->db_cmd ) m_nProcessingCmdId = tCMD->db_cmd; else m_nProcessingCmdId = 0;
  2433. m_nActiveDetectionProfile = 0;
  2434. setWM( ANODE_WM_2D_SET_MASTER_PARAM );
  2435. updateDataStatus( ARGUS_DS_BUSY );
  2436. break;
  2437. };
  2438. */
  2439. case ARGUS_LRF_ROI_ACTIVATION:{
  2440. uint16_t sz = strlen(tCMD->PARAM);
  2441. if( sz ){
  2442. uint16_t AZ, RANGE, WIDTH;
  2443. uint8_t LRFID = 0;
  2444. AZ = atoi(strstr(tCMD->PARAM, ":") + 1) - m_sLRF_DATA.base_shift;
  2445. RANGE = atoi( tCMD->PARAM );
  2446. WIDTH = 8888;
  2447. #ifdef DEBUG_EXTRA
  2448. char tBuff[128];
  2449. sprintf( tBuff, "ROI AZ: %d RANGE: %d WIDTH: %d", AZ, RANGE, WIDTH );
  2450. LOG( tBuff );
  2451. #endif
  2452. EVENT_CONTAINER * bEVT = NULL;
  2453. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH, LRFID );
  2454. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ROI_ACTIVE, NULL, NULL, tData );
  2455. if( bEVT != NULL ) {
  2456. m_pEventHeap->broadcast( bEVT );
  2457. } else {
  2458. free( tData );
  2459. };
  2460. };
  2461. break;
  2462. };
  2463. default:
  2464. char KKK[256];
  2465. sprintf( KKK, "Unknown DBC command[%d]",tCMD->CMD );
  2466. LOG( KKK );
  2467. m_pDBC->updateNodePushedCMD( m_nProcessingCmdId, DBC_CMD_FINISHED );
  2468. };
  2469. free( tCMD );
  2470. };
  2471. };
  2472. bool device2DSensor::validateCommunicationRessource(){
  2473. if( getConnectionStatus() != CS_CONNECTED ){
  2474. #ifdef DEBUG_EXTRA
  2475. LOG("Connection ->Disconnected!");
  2476. #endif
  2477. updateDataStatus( ARGUS_DS_DISCONNECTED );
  2478. setWM( LRF_WM_CONNECTION );
  2479. return false;
  2480. };
  2481. return true;
  2482. };
  2483. //bool device2DSensor::runSequence( COMMAND_SEQUENCE_TYPE SequenceID ){
  2484. // if ( m_eCurrentSequence!= NO_SEQUENCE ) return false;
  2485. // m_bSequenceStep = 0;
  2486. // m_eCurrentSequence = SequenceID;
  2487. // return true;
  2488. //};
  2489. #define SIZE_IDX 1
  2490. #define DEV_ID_IDX 2
  2491. #define CMD_IDX 3
  2492. #define SUB_CMD_IDX 4
  2493. #define DATA_BEGIN_IDX 5
  2494. #define PRINTOUT {for( int z=0; z < Package->m_nSize; z++ ) { \
  2495. sprintf( tBuff, "P[%d]:0x%02X", z, Package->m_pData[z]); \
  2496. LOG( tBuff ); \
  2497. };}
  2498. bool device2DSensor::packetHandler( protocolPackage *Package ){
  2499. uint8_t bCWM = getWM();
  2500. uint8_t bOWM = getOWM();
  2501. LRF_WORK_STAGE ePSTG = getPrevStage();
  2502. uint8_t cDeviceID = Package->m_pData[DEV_ID_IDX];
  2503. if( ( cDeviceID == m_sLRF_DATA.device_id ) || ( m_sLRF_DATA.device_id == 0 ) ) {
  2504. #ifdef DEBUG
  2505. char tBuff[256];
  2506. #ifdef DEBUG_EXTRA
  2507. sprintf( tBuff, "DEV-> Code 0x%02X",Package->m_pData[CMD_IDX] );
  2508. LOG( tBuff );
  2509. #endif
  2510. #endif
  2511. // Have Some Replay from device -> Reset Timeouts
  2512. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT;
  2513. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2514. switch( Package->m_pData[CMD_IDX] ) {
  2515. case CMD_STATE: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2516. case CMD_QUIT: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2517. case CMD_RESET: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2518. case CMD_BORDER:{
  2519. if ((Package->m_pData[SUB_CMD_IDX] & BD_ERRORMASK) == 0x00) {
  2520. uint16_t AZ;
  2521. uint16_t RANGE_A;
  2522. uint16_t RANGE_B;
  2523. AZ = ( ( ( Package->m_pData[SUB_CMD_IDX] & 0x10 ) >> 4 ) << 8 ) | Package->m_pData[5];
  2524. RANGE_A = ( ( ( Package->m_pData[SUB_CMD_IDX] & 0x0C ) >> 2 ) << 8 ) | Package->m_pData[6];
  2525. RANGE_B = ( ( Package->m_pData[SUB_CMD_IDX] & 0x03 ) << 8 ) | Package->m_pData[7];
  2526. if( AZ < 359 ) {
  2527. m_vDrawRanges[m_nCurrentAngle]=( RANGE_A << 16 ) | RANGE_B;
  2528. m_nCurrentAngle = AZ+1;
  2529. if( m_nProcessingCmdId ){
  2530. m_pDBC->updateNodePushedCMD( m_nProcessingCmdId, (( ( 100 * AZ ) / 360 ) - 1 ) | 1 );
  2531. m_nProcessingCmdId = 0;
  2532. };
  2533. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  2534. } else {
  2535. m_nCurrentAngle = 0;
  2536. handleDeviceDraw( 0, (void *)m_vDrawRanges, 360 * sizeof(uint32_t) );
  2537. if( m_nProcessingCmdId ){
  2538. m_pDBC->updateNodePushedCMD(m_nProcessingCmdId, 100 );
  2539. m_nProcessingCmdId = 0;
  2540. };
  2541. transactionSetResult( TRANSACTION_RESULT_OK );
  2542. };
  2543. } else {
  2544. switch((Package->m_pData[SUB_CMD_IDX] & BD_ERRORMASK)){
  2545. case BD_NOTREADY: {
  2546. #ifdef DEBUG_EXTRA
  2547. LOG_ERROR("DNR");
  2548. #endif
  2549. m_nCurrentAngle = 0;
  2550. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  2551. break;
  2552. };
  2553. case BD_ERRORANGLE:{
  2554. #ifdef DEBUG_EXTRA
  2555. LOG_ERROR("EAN");
  2556. #endif
  2557. transactionSetResult( TRANSACTION_RESULT_OK );
  2558. break;
  2559. };
  2560. case BD_ERRORMODE:{
  2561. #ifdef DEBUG_EXTRA
  2562. LOG_ERROR("EMO");
  2563. #endif
  2564. transactionSetResult( TRANSACTION_RESULT_OK );
  2565. break;
  2566. };
  2567. };
  2568. };
  2569. break;
  2570. };
  2571. case CMD_MODE:{
  2572. m_bActualDeviceWM = (E_MODES) Package->m_pData[SUB_CMD_IDX];
  2573. #ifdef DEBUG_EXTRA
  2574. sprintf( tBuff, "Requested Mode:0x%02X Device Mode:0x%02X", m_bRequestedDeviceWM, m_bActualDeviceWM );
  2575. LOG( tBuff );
  2576. #endif
  2577. transactionSetResult( m_bRequestedDeviceWM == m_bActualDeviceWM );
  2578. break;
  2579. };
  2580. case CMD_GETFILE:{
  2581. #ifdef DEBUG_EXTRA
  2582. LOG("GF PKG");
  2583. #endif
  2584. // Sync mode Only
  2585. if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORMASK ) != 0 ){
  2586. if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORMODE ) != 0 ){
  2587. LOG_ERROR("Error: GF-Wrong WM!");
  2588. } else {
  2589. if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORFILE ) != 0 ){
  2590. LOG_ERROR("Error: GF-File Error!");
  2591. } else {
  2592. LOG_ERROR("Error: GF-File gen Error!");
  2593. };
  2594. };
  2595. transactionSetResult( TRANSACTION_RESULT_OK );
  2596. } else {
  2597. if ( ( Package->m_pData[SUB_CMD_IDX] & GF_OP_INDEX ) == m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ) {
  2598. if(( Package->m_pData[SUB_CMD_IDX] & GF_OP_MASK ) == GF_OP_OK ){
  2599. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  2600. } else {
  2601. LOG_ERROR("Error: GF-File Error(index)!");
  2602. transactionSetResult( TRANSACTION_RESULT_OK );
  2603. };
  2604. } else {
  2605. LOG_ERROR("Error: GF-File Error(operation)!");
  2606. transactionSetResult( TRANSACTION_RESULT_OK );
  2607. };
  2608. };
  2609. break;
  2610. };
  2611. case CMD_RESTART: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2612. case CMD_PARAMETERS:{
  2613. #ifdef DEBUG_EXTRA
  2614. LOG("PARAMETERS");
  2615. sprintf(tBuff, " Stage:\t%d", bCWM );
  2616. LOG(tBuff);
  2617. #endif
  2618. if( bCWM == LRF_WM_SYNC_DOWN ) {
  2619. if( Package->m_pData[SUB_CMD_IDX] == 0x80 ){
  2620. LOG("CMD MASTER PARAMETERS ACK");
  2621. //setStage( LRF_WS_STAGE_8 );
  2622. } else {
  2623. LOG("CMD SLAVE PARAMETERS ACK");
  2624. //setStage( LRF_WS_DELAY );
  2625. };
  2626. } else {
  2627. LOG("READ PARAMS FROM DEVICE");
  2628. LGS_2D_PARAMETERS tParams;
  2629. bool bMaster = true;
  2630. //RaspberyPi - not Intel - cannot copy
  2631. //memcpy( &tParams, Package->m_pData + DATA_BEGIN_IDX, sizeof( LGS_2D_PARAMETERS ) );
  2632. tParams.nOrder = ( Package->m_pData[5] << 8 ) | Package->m_pData[6];
  2633. tParams.nOffset = ( Package->m_pData[7] << 8 ) | Package->m_pData[8];
  2634. tParams.nDelta = ( Package->m_pData[9] << 8 ) | Package->m_pData[10];
  2635. tParams.nWidth = ( Package->m_pData[11] << 8 ) | Package->m_pData[12];
  2636. tParams.nFlip = ( Package->m_pData[13] << 8 ) | Package->m_pData[14];
  2637. tParams.nSun = ( Package->m_pData[15] << 8 ) | Package->m_pData[16];
  2638. tParams.bSST = Package->m_pData[17];
  2639. if( Package->m_pData[SUB_CMD_IDX] != 0x80 ) bMaster = false;
  2640. #ifdef DEBUG
  2641. if( bMaster ) LOG("CMD MASTER PARAMETERS"); else LOG("CMD SLAVE PARAMETERS");
  2642. sprintf(tBuff, " SST:\t%d", tParams.bSST );
  2643. LOG(tBuff);
  2644. sprintf(tBuff, " DELTA:\t%d", tParams.nDelta );
  2645. LOG(tBuff);
  2646. sprintf(tBuff, " Flip:\t%d", tParams.nFlip );
  2647. LOG(tBuff);
  2648. sprintf(tBuff, " OFFSET:\t%d", tParams.nOffset );
  2649. LOG(tBuff);
  2650. sprintf(tBuff, " ORDER:\t%d", tParams.nOrder );
  2651. LOG(tBuff);
  2652. sprintf(tBuff, " SUN:\t%d", tParams.nSun );
  2653. LOG(tBuff);
  2654. sprintf(tBuff, " WIDTH:\t%d", tParams.nWidth );
  2655. LOG(tBuff);
  2656. #endif
  2657. if( m_sLRF_DATA.force_settings ){
  2658. #ifdef DEBUG_EXTRA
  2659. LOG("Force Settings!");
  2660. #endif
  2661. // Check if Settings Are Equal
  2662. PLGS_2D_PARAMETERS chDATA = m_pDBC->getLRFDetectionProfile( m_sLRF_DATA.id, m_nActiveDetectionProfile, bMaster );
  2663. if ( chDATA == NULL ) {
  2664. LOG("No DB Profile!");
  2665. // No Profile in DB -> Set Once!
  2666. m_pDBC->updateLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, bMaster, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
  2667. if( bMaster && m_sNodeData.type == ARGUS_ALS_SENSOR ){
  2668. LOG("Go Get Slave!");
  2669. //setStage( LRF_WS_STAGE_2 );
  2670. } else {
  2671. LOG("Go Get HZ!");
  2672. //setStage( LRF_WS_STAGE_3 );
  2673. };
  2674. } else {
  2675. LOG("Have Settings Go Idle Mode??!");
  2676. //setWM( LRF_WM_IDLE );
  2677. LOG("Go Get HZ!");
  2678. //setStage( LRF_WS_STAGE_3 );
  2679. free( chDATA );
  2680. };
  2681. } else {
  2682. m_pDBC->updateLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, bMaster, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
  2683. if( bMaster && m_sNodeData.type == ARGUS_ALS_SENSOR ){
  2684. LOG("Go Get Slave!");
  2685. //setStage( LRF_WS_STAGE_2 );
  2686. } else {
  2687. LOG("Go Get HZ!");
  2688. //setStage( LRF_WS_STAGE_3 );
  2689. };
  2690. };
  2691. };
  2692. transactionSetResult( TRANSACTION_RESULT_OK );
  2693. break;
  2694. };
  2695. case CMD_GET_RELAY_PARAMETERS:{
  2696. LOG("R-Params!");
  2697. transactionSetResult( TRANSACTION_RESULT_OK );
  2698. break;
  2699. };
  2700. case CMD_GET_SERIAL_NUMBER:{
  2701. uint8_t tSize = Package->m_pData[SUB_CMD_IDX + 1];
  2702. memcpy( m_tSN, Package->m_pData + SUB_CMD_IDX + 2, tSize );
  2703. m_tSN[tSize] = (char)0;
  2704. #ifdef DEBUG_EXTRA
  2705. LOG("CMD_GET_SERIAL_NUMBER");
  2706. LOG( m_tSN );
  2707. #endif
  2708. //Checking SN of actual connected device with one stored in database
  2709. //in case there is new device -> the SN in database will be updated
  2710. if( strncmp( m_sLRF_DATA.serial, m_tSN, tSize ) == 0 ) {
  2711. // Equal
  2712. #ifdef DEBUG_EXTRA
  2713. LOG("SN is OK");
  2714. #endif
  2715. m_bSerialStringValid = true;
  2716. } else {
  2717. LOG_ERROR( m_sLRF_DATA.serial );
  2718. LOG_ERROR("SN is INVALID!");
  2719. LOG_ERROR( m_tSN );
  2720. m_bSerialStringValid = false;
  2721. };
  2722. transactionSetResult( TRANSACTION_RESULT_OK );
  2723. break;
  2724. };
  2725. case CMD_GET_SOFTWARE_VERSION:{
  2726. if ( bCWM == LRF_WM_HANDSHAKE ) {
  2727. uint8_t tSize = Package->m_pData[SUB_CMD_IDX];
  2728. memcpy( m_tSV, Package->m_pData + SUB_CMD_IDX + 1, tSize );
  2729. m_tSV[tSize] = (char)0;
  2730. #ifdef DEBUG_EXTRA
  2731. LOG("CMD_GET_SOFTWARE_VERSION");
  2732. LOG( m_tSV );
  2733. #endif
  2734. if ( strstr(m_tSV,"FD") != NULL ) {
  2735. #ifdef DEBUG_EXTRA
  2736. LOG("Freeze Disabled!");
  2737. #endif
  2738. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, false, false );
  2739. } else {
  2740. if ( strstr(m_tSV,"FF") != NULL ) {
  2741. #ifdef DEBUG_EXTRA
  2742. LOG("TH is Frozen!");
  2743. #endif
  2744. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, true, true );
  2745. } else {
  2746. if ( strstr(m_tSV,"FS") != NULL ) {
  2747. #ifdef DEBUG_EXTRA
  2748. LOG("TH is Study!");
  2749. #endif
  2750. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, true, true );
  2751. } else {
  2752. #ifdef DEBUG_EXTRA
  2753. LOG("No Frost Version!");
  2754. #endif
  2755. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, false, false );
  2756. };
  2757. };
  2758. };
  2759. if (strncmp(m_sLRF_DATA.version, m_tSV, tSize) == 0) {
  2760. #ifdef DEBUG_EXTRA
  2761. LOG("Version is OK");
  2762. #endif
  2763. m_bVersionStringValid = true;
  2764. } else {
  2765. LOG_ERROR( m_sLRF_DATA.version );
  2766. LOG_ERROR("Version is INVALID!");
  2767. LOG_ERROR( m_tSV );
  2768. m_bVersionStringValid = false;
  2769. };
  2770. if( m_bVersionStringValid && m_bSerialStringValid ) {
  2771. // The Device is OK
  2772. m_pDBC->setNodeOnline( m_sNodeData.node_id, NODE_STATUS_WORK );
  2773. if ( m_bForceSync ) {
  2774. m_bDeviceIsSynced = false; // Do we need it here ?
  2775. //setWM( LRF_WM_SYNC_UP );
  2776. } else {
  2777. m_bDeviceIsSynced = true;
  2778. //setStage( LRF_WS_STAGE_3 ); // Read Mask Statuses
  2779. };
  2780. } else {
  2781. // Will Work even if SN different
  2782. m_bDeviceIsSynced = false;
  2783. //m_bVersionStringValid = true;
  2784. //m_bSerialStringValid = true;
  2785. //m_pDBC->updateLRFSerial( m_sLRF_DATA.id, m_tSN );
  2786. //m_pDBC->updateLRFVerison( m_sLRF_DATA.id, m_tSV );
  2787. m_pDBC->setNodeOnline( m_sNodeData.node_id, NODE_STATUS_WORK );
  2788. //proceed to next stage
  2789. //setWM( LRF_WM_SYNC_UP );
  2790. };
  2791. m_bVersionStringValid = true;
  2792. m_bSerialStringValid = true;
  2793. m_pDBC->updateLRFSerial( m_sLRF_DATA.id, m_tSN );
  2794. m_pDBC->updateLRFVerison( m_sLRF_DATA.id, m_tSV );
  2795. transactionSetResult( TRANSACTION_RESULT_OK );
  2796. }
  2797. break;
  2798. };
  2799. case CMD_UNSUPPORTED:{
  2800. #ifdef DEBUG_EXTRA
  2801. LOG("CMD_UNSUPPORTED!!");
  2802. #endif
  2803. transactionSetResult( TRANSACTION_RESULT_OK );
  2804. break;
  2805. };
  2806. case CMD_FULL_RESET:{
  2807. #ifdef DEBUG_EXTRA
  2808. LOG("Full Reset ACK");
  2809. #endif
  2810. transactionSetResult( TRANSACTION_RESULT_OK );
  2811. break;
  2812. };
  2813. case CMD_STATE_2:{
  2814. // Throw <<Tail>> Package on Wrong Mode
  2815. if ( !( bCWM == LRF_WM_ALARM || bCWM == LRF_WM_IDLE ) ) break;
  2816. #ifdef DEBUG_EXTRA
  2817. //LOG("CMD State 2");
  2818. #endif
  2819. //Parsning sub commagds
  2820. uint8_t cIDX = SUB_CMD_IDX;
  2821. #ifdef DEBUG_EXTRA
  2822. //if( Package->m_nSize > 8 ) {
  2823. // sprintf( tBuff, "Pack Size: %d", Package->m_nSize );
  2824. // LOG( tBuff );
  2825. // PRINTOUT;
  2826. //};
  2827. #endif
  2828. m_bDeviceIsSynced = true; // At this point all data structs must be synced?!
  2829. //setStage( LRF_WS_STAGE_2 );
  2830. while( Package->m_nSize > ( cIDX + 2 ) ) {
  2831. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2832. switch( Package->m_pData[cIDX+1] ) {
  2833. case 0x00:{
  2834. #ifdef DEBUG_EXTRA
  2835. LOG("SUB PACKAGE - Intruder detected");
  2836. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2837. LOG( tBuff );
  2838. #endif
  2839. uint16_t AZ, RANGE;
  2840. uint32_t WIDTH;
  2841. uint8_t LRFID = 0;
  2842. AZ = (( Package->m_pData[cIDX + 3] >> 3 ) << 8 ) | Package->m_pData[cIDX + 4];
  2843. RANGE = (( Package->m_pData[cIDX + 3] & 0x07 ) << 8 ) | Package->m_pData[cIDX + 5];
  2844. WIDTH = 8888;
  2845. #ifdef DEBUG_EXTRA
  2846. sprintf( tBuff, "AZ: %d RANGE: %d WIDTH: %d", AZ, RANGE, WIDTH );
  2847. LOG( tBuff );
  2848. #endif
  2849. EVENT_CONTAINER * bEVT = NULL;
  2850. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH, LRFID );
  2851. if( m_pTargetFilter != NULL ) {
  2852. if( m_pTargetFilter->validateTarget( m_sNodeData.node_id, tData ) ){
  2853. free( tData );
  2854. //Proceed Statuss of target
  2855. if ( LRF_WM_ALARM != getWM()) {
  2856. setWM(LRF_WM_ALARM);
  2857. };
  2858. cIDX += 6;
  2859. break;
  2860. };
  2861. };
  2862. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_TARGET_2D_WHITE, NULL, NULL, tData );
  2863. if( bEVT != NULL ) {
  2864. m_pEventHeap->broadcast(bEVT);
  2865. } else {
  2866. free( tData );
  2867. };
  2868. if ( LRF_WM_ALARM != getWM()) {
  2869. setWM(LRF_WM_ALARM);
  2870. };
  2871. cIDX += 6;
  2872. break;
  2873. };
  2874. case 0x02:{
  2875. #ifdef DEBUG_EXTRA
  2876. LOG("SUB PACKAGE - Maintenance notification");
  2877. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2878. LOG( tBuff );
  2879. #endif
  2880. EVENT_CONTAINER *bEVT = NULL;
  2881. if ( ( Package->m_pData[cIDX+2] & 0x02 ) == 0x02 ) {
  2882. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_NO_IRQ, NULL, NULL, NULL );
  2883. } else if ( ( Package->m_pData[cIDX+2] & 0x02 ) == 0x04 ) {
  2884. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_NO_ZERO, NULL, NULL, NULL );
  2885. } else if ( ( Package->m_pData[cIDX+2] & 0x02 ) == 0x10 ) {
  2886. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_VOLTAGE, NULL, NULL, NULL );
  2887. };
  2888. if( bEVT != NULL ) {
  2889. m_pEventHeap->broadcast(bEVT);
  2890. };
  2891. cIDX += 3;
  2892. break;
  2893. };
  2894. case 0x03:{
  2895. #ifdef DEBUG_EXTRA
  2896. LOG("SUB PACKAGE - LRF problems notification");
  2897. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2898. LOG( tBuff );
  2899. #endif
  2900. EVENT_CONTAINER *bEVT = NULL;
  2901. if ( ( Package->m_pData[cIDX+3] & 0x01 ) == 0x01 ) {
  2902. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_BROKEN, NULL, NULL, NULL);
  2903. } else if( ( Package->m_pData[cIDX+3] & 0x02 ) == 0x02 ){
  2904. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_ERR_OVERFLOW, NULL, NULL, NULL);
  2905. } else if( ( Package->m_pData[cIDX+3] & 0x04 ) == 0x04 ){
  2906. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_SST_OVERFLOW, NULL, NULL, NULL);
  2907. };
  2908. if( bEVT != NULL ) {
  2909. m_pEventHeap->broadcast(bEVT);
  2910. };
  2911. cIDX += 4;
  2912. break;
  2913. };
  2914. case 0x04:{
  2915. #ifdef DEBUG_EXTRA
  2916. LOG("SUB PACKAGE - Error Angle notification");
  2917. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2918. LOG( tBuff );
  2919. #endif
  2920. EVENT_CONTAINER *bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_ANGLE, NULL, NULL, NULL );
  2921. if( bEVT != NULL ) {
  2922. m_pEventHeap->broadcast(bEVT);
  2923. };
  2924. cIDX += 4;
  2925. break;
  2926. };
  2927. case 0x05:{
  2928. #ifdef DEBUG_EXTRA
  2929. LOG("SUB PACKAGE - Flip Complete notification");
  2930. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2931. LOG( tBuff );
  2932. #endif
  2933. // Evt Broadcasting
  2934. broadcastFlip( 0 );
  2935. if( m_sLRF_DATA.data_status != ARGUS_DS_READY ) updateDataStatus( ARGUS_DS_READY );
  2936. if( bCWM == LRF_WM_ALARM ){
  2937. // Clear Alarm Mode to Idle
  2938. bCWM = LRF_WM_IDLE;
  2939. setWM( LRF_WM_IDLE );
  2940. };
  2941. if( m_bInitialFlips ){
  2942. m_bInitialFlips--;
  2943. } else {
  2944. #ifdef DEBUG_EXTRA
  2945. LOG("INITIAL FLIPS ARE DONE!");
  2946. #endif
  2947. if( bCWM == LRF_WM_IDLE ){
  2948. // If not in Allert Mode
  2949. if ( m_sLRF_DATA.auto_draw > 0 ) {
  2950. #ifdef DEBUG_EXTRA
  2951. LOG("Start AutoDraw!");
  2952. #endif
  2953. m_bInitialFlips = m_sLRF_DATA.auto_draw;
  2954. setWM( LRF_WM_BORDER );
  2955. } else {
  2956. #ifdef DEBUG_EXTRA
  2957. LOG("No AutoDraw Defined!");
  2958. #endif
  2959. };
  2960. #ifdef DEBUG_EXTRA
  2961. } else {
  2962. LOG_ERROR("Wrong WM Mode! (possible error in init process)");
  2963. #endif
  2964. };
  2965. };
  2966. cIDX += 5;
  2967. break;
  2968. };
  2969. case 0x06:{
  2970. #ifdef DEBUG_EXTRA
  2971. LOG("SUB PACKAGE - System visibility changes");
  2972. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2973. LOG( tBuff );
  2974. #endif
  2975. EVENT_CONTAINER *bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_LRF_VIS_CHANGED, NULL, NULL, NULL );
  2976. if( bEVT != NULL ) {
  2977. m_pEventHeap->broadcast(bEVT);
  2978. };
  2979. cIDX += 4;
  2980. break;
  2981. };
  2982. case 0x07:{
  2983. #ifdef DEBUG_EXTRA
  2984. LOG("SUB PACKAGE - Intruder with Width detected");
  2985. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2986. LOG( tBuff );
  2987. #endif
  2988. uint16_t AZ, RANGE;
  2989. uint32_t WIDTH;
  2990. AZ = (( Package->m_pData[cIDX + 3] >> 3 ) << 8 ) | Package->m_pData[cIDX + 4];
  2991. RANGE = (( Package->m_pData[cIDX + 3] & 0x07 ) << 8 ) | Package->m_pData[cIDX + 5];
  2992. WIDTH = ( Package->m_pData[cIDX + 6] << 24 ) | ( Package->m_pData[cIDX + 7] << 16 ) | ( Package->m_pData[cIDX + 8] << 8 ) | Package->m_pData[cIDX + 9];
  2993. #ifdef DEBUG_EXTRA
  2994. sprintf( tBuff, "AZ: %d RANGE: %d WIDTH: %d", AZ, RANGE, WIDTH );
  2995. LOG( tBuff );
  2996. #endif
  2997. EVENT_CONTAINER * bEVT = NULL;
  2998. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH );
  2999. if( m_pTargetFilter != NULL ) {
  3000. if( m_pTargetFilter->validateTarget( m_sNodeData.node_id, tData ) ){
  3001. free( tData );
  3002. if( m_sLRF_DATA.data_status!= ARGUS_DS_ALARMED ) updateDataStatus( ARGUS_DS_ALARMED );
  3003. //Proceed Statuses Of Target
  3004. //if ( !m_bSessionStarted ) startSession();
  3005. //m_nSleepTime = LGS_ALERT_SLEEP_TIME;
  3006. if ( LRF_WM_ALARM != getWM()) {
  3007. setWM(LRF_WM_ALARM);
  3008. };
  3009. cIDX += 10;
  3010. break;
  3011. };
  3012. };
  3013. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_TARGET_2D_WHITE, NULL, NULL, tData );
  3014. if( bEVT != NULL ) {
  3015. m_pEventHeap->broadcast( bEVT );
  3016. } else {
  3017. free( tData );
  3018. };
  3019. if( m_sLRF_DATA.data_status!= ARGUS_DS_ALARMED ) updateDataStatus( ARGUS_DS_ALARMED );
  3020. //m_nSleepTime = LGS_ALERT_SLEEP_TIME;
  3021. if ( LRF_WM_ALARM != getWM()) {
  3022. setWM(LRF_WM_ALARM);
  3023. };
  3024. cIDX += 10;
  3025. break;
  3026. };
  3027. default:{
  3028. #ifdef DEBUG_EXTRA
  3029. LOG("SUB PACKAGE - Unhandled One!");
  3030. sprintf( tBuff, "Code: %d Sub Size: %d", Package->m_pData[cIDX+1], Package->m_pData[cIDX] );
  3031. LOG( tBuff );
  3032. #endif
  3033. cIDX += Package->m_pData[cIDX] + 3;
  3034. break;
  3035. };
  3036. };
  3037. };
  3038. //setStage( LRF_WS_STAGE_1 );
  3039. transactionSetResult( TRANSACTION_RESULT_OK );
  3040. break;
  3041. };
  3042. case CMD_GET_HZ_DATA:{
  3043. //HZ_PACKET tPack = (PHZ_PACKET) Package->m_pData + SUB_CMD_IDX;
  3044. switch( Package->m_pData[DATA_BEGIN_IDX] ) {
  3045. case HZIT_EVT_GET_HEADER:{
  3046. HZ_EVT_GET_HEADER pC;
  3047. pC.bSubSize = Package->m_pData[SUB_CMD_IDX];
  3048. pC.bType = Package->m_pData[DATA_BEGIN_IDX];
  3049. pC.bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3050. pC.wPolygonCount = Package->m_pData[DATA_BEGIN_IDX+3];
  3051. pC.wPolygonCount = ( pC.wPolygonCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+2];
  3052. pC.wRayCount = Package->m_pData[DATA_BEGIN_IDX+5];
  3053. pC.wRayCount = ( pC.wRayCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+4];
  3054. pC.dwTypeOn = Package->m_pData[DATA_BEGIN_IDX+9];
  3055. pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+8];
  3056. pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+7];
  3057. pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+6];
  3058. #ifdef DEBUG_EXTRA
  3059. sprintf( tBuff, "Poly Cnt: %d Ray Cnt: %d Status: 0x%08X", pC.wPolygonCount, pC.wRayCount, pC.dwTypeOn );
  3060. LOG( tBuff );
  3061. #endif
  3062. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3063. cleanShadowStructs();
  3064. if( pC.wPolygonCount ){
  3065. m_sShadow.m_nEnabled = pC.dwTypeOn;
  3066. // Set Statuses of Masks ?? Now ??? ->
  3067. for( uint8_t MaskLayer=0; MaskLayer < 5; MaskLayer++ ) {
  3068. uint32_t tMaskID = m_pDBC->getLRFMaskID( m_sLRF_DATA.id , 0, MaskLayer );
  3069. if ( tMaskID ) {
  3070. m_pDBC->setLRFMaskStatus( tMaskID, ( m_sShadow.m_nEnabled & (1<<MaskLayer) ) );
  3071. };
  3072. };
  3073. m_sShadow.pPolygones = (SHADOW_POLY *) calloc(pC.wPolygonCount,sizeof(SHADOW_POLY));
  3074. if ( m_sShadow.pPolygones ) {
  3075. memset( m_sShadow.pPolygones, 0, pC.wPolygonCount*sizeof(SHADOW_POLY) );
  3076. m_sShadow.m_nPolygonCount = pC.wPolygonCount;
  3077. //setStage( LRF_WS_STAGE_4 );
  3078. //setWM(ANODE_WM_2D_GET_SHADOW_POLY_INFO);
  3079. } else {
  3080. LOG_ERROR("Error Alocation Memory foe Shadow!");
  3081. //setWM( LRF_WM_IDLE );
  3082. //updateDataStatus( ARGUS_DS_STUDY );
  3083. };
  3084. } else cleanShadowInDB();
  3085. transactionSetResult( TRANSACTION_RESULT_OK );
  3086. break;
  3087. };
  3088. case HZIT_EVT_GET_POLYGON:{
  3089. uint16_t wPointCount = Package->m_pData[DATA_BEGIN_IDX+4];
  3090. wPointCount = ( wPointCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+3];
  3091. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3092. #ifdef DEBUG_EXTRA
  3093. sprintf( tBuff, "Poly[%d] Info: Points %d type: %d",
  3094. m_sShadowHelper.m_nCurrentPolygon,
  3095. wPointCount, Package->m_pData[DATA_BEGIN_IDX+2]
  3096. );
  3097. LOG( tBuff );
  3098. #endif
  3099. if ( wPointCount ) {
  3100. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].bType = Package->m_pData[DATA_BEGIN_IDX+2];
  3101. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint = (HZ_POINT*)calloc( wPointCount, sizeof(HZ_POINT));
  3102. if ( m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint ) {
  3103. memset(m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint, 0, wPointCount*sizeof(HZ_POINT));
  3104. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount = wPointCount;
  3105. m_sShadowHelper.m_nCurrentPoint = 0;
  3106. //setWM( ANODE_WM_2D_GET_SHADOW_POLY_POINT );
  3107. } else LOG_ERROR("Error Alloc Memory for Polygone points!");
  3108. //setWM( LRF_WM_IDLE ); cant quit now - mat be need read DC
  3109. //};
  3110. //Start Point Transfers or Skeep to Relay Settings
  3111. transactionSetResult( TRANSACTION_RESULT_OK );
  3112. } else {
  3113. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint = NULL;
  3114. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount = 0;
  3115. if( m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ) {
  3116. m_sShadowHelper.m_nCurrentPolygon++;
  3117. // Request next polygone
  3118. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3119. } else {
  3120. // Proceed Read of the points (no points -> Skeep )
  3121. transactionSetResult( TRANSACTION_RESULT_OK );
  3122. };
  3123. };
  3124. break;
  3125. };
  3126. case HZIT_EVT_GET_POLYGON_POINT:{
  3127. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX = Package->m_pData[DATA_BEGIN_IDX+3];
  3128. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX = (m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX << 8 ) | Package->m_pData[DATA_BEGIN_IDX+2];
  3129. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY = Package->m_pData[DATA_BEGIN_IDX+5];
  3130. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY = (m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY << 8 ) | Package->m_pData[DATA_BEGIN_IDX+4];
  3131. #ifdef DEBUG_EXTRA
  3132. sprintf( tBuff, "PolyPoint[%d] of %d X: %d Y: %d",
  3133. m_sShadowHelper.m_nCurrentPoint,
  3134. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount,
  3135. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX,
  3136. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY
  3137. );
  3138. LOG( tBuff );
  3139. #endif
  3140. m_sShadowHelper.m_nCurrentPoint++;
  3141. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3142. if( m_sShadowHelper.m_nCurrentPoint < m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount ) {
  3143. //LOG("Back To Read Nex Poly Point!");
  3144. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3145. //setStage( LRF_WS_STAGE_5 );
  3146. //setWM( ANODE_WM_2D_GET_SHADOW_POLY_POINT );
  3147. } else {
  3148. #ifdef DEBUG_EXTRA
  3149. LOG("Done Load Poly Points");
  3150. #endif
  3151. transactionSetResult( TRANSACTION_RESULT_OK );
  3152. m_sShadowHelper.m_nCurrentPolygon++;
  3153. if(m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ) {
  3154. //setStage( LRF_WS_STAGE_4 );
  3155. //setWM( ANODE_WM_2D_GET_SHADOW_POLY_INFO );
  3156. transactionSetResult( TRANSACTION_RESULT_OK );
  3157. } else {
  3158. saveShadowToDB();
  3159. #ifdef DEBUG_EXTRA
  3160. //rasterizeShadow();
  3161. //makeShadowPic("shadow.png");
  3162. #endif
  3163. setWM( LRF_WM_IDLE );
  3164. updateDataStatus( ARGUS_DS_READY );
  3165. };
  3166. };
  3167. break;
  3168. };
  3169. case HZIT_EVT_GET_RAY:{
  3170. HZ_EVT_GET_RAY pC;
  3171. LOG("RAY!");
  3172. setWM( LRF_WM_IDLE );
  3173. break;
  3174. };
  3175. case HZIT_EVT_GET_RAY_LINE:{
  3176. HZ_EVT_GET_RAY_LINE pC;
  3177. LOG("RAY LINE!");
  3178. setWM( LRF_WM_IDLE );
  3179. break;
  3180. };
  3181. case HZIT_EVT_ERROR:{
  3182. HZ_EVT_ERROR pC;
  3183. LOG("ERROR GET SHADOW PING_PONG!");
  3184. setWM( LRF_WM_IDLE );
  3185. break;
  3186. };
  3187. };
  3188. break;
  3189. };
  3190. case CMD_SET_HZ_DATA:{
  3191. #ifdef DEBUG_EXTRA
  3192. sprintf( tBuff,"Replay Set HZ Code: 0x%02X", Package->m_pData[DATA_BEGIN_IDX] );
  3193. LOG( tBuff );
  3194. #endif
  3195. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3196. switch( Package->m_pData[DATA_BEGIN_IDX] ) {
  3197. case HZIT_EVT_SET_HEADER:
  3198. #ifdef DEBUG_EXTRA
  3199. LOG("Header OK");
  3200. #endif
  3201. transactionSetResult( TRANSACTION_RESULT_OK );
  3202. break;
  3203. case HZIT_EVT_SET_POLYGON:
  3204. #ifdef DEBUG_EXTRA
  3205. LOG("Poligon Added OK");
  3206. #endif
  3207. transactionSetResult( TRANSACTION_RESULT_OK );
  3208. break;
  3209. case HZIT_EVT_SET_POLYGON_POINT:
  3210. #ifdef DEBUG_EXTRA
  3211. LOG("PolyPoint Added OK");
  3212. #endif
  3213. m_sShadowHelper.m_nCurrentPoint++;
  3214. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3215. break;
  3216. case HZIT_EVT_SET_RAY:
  3217. m_sShadowHelper.m_nCurrentRay = 0;
  3218. #ifdef DEBUG_EXTRA
  3219. LOG("Rey Added OK");
  3220. #endif
  3221. transactionSetResult( TRANSACTION_RESULT_OK );
  3222. break;
  3223. case HZIT_EVT_SET_RAY_LINE:
  3224. #ifdef DEBUG_EXTRA
  3225. LOG("Ray Line Added OK");
  3226. #endif
  3227. m_sShadowHelper.m_nCurrentRay++;
  3228. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3229. break;
  3230. case HZIT_EVT_SET_DONE:
  3231. #ifdef DEBUG_EXTRA
  3232. LOG("Cleanup!");
  3233. #endif
  3234. memset( &m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER) );
  3235. m_bOpRetryCnt = 128;
  3236. updateDataStatus( ARGUS_DS_READY );
  3237. transactionSetResult( TRANSACTION_RESULT_OK );
  3238. break;
  3239. case HZIT_EVT_ERROR:{
  3240. HZ_EVT_ERROR pC;
  3241. #ifdef DEBUG_EXTRA
  3242. LOG_ERROR("ERROR SET SHADOW PING_PONG!");
  3243. #endif
  3244. //setWM( ANODE_WM_2D_PING );
  3245. memset( &m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER) );
  3246. //setStage( LRF_WS_STAGE_7 );
  3247. updateDataStatus( ARGUS_DS_READY );
  3248. transactionSetResult( TRANSACTION_RESULT_OK );
  3249. break;
  3250. };
  3251. };
  3252. break;
  3253. };
  3254. case CMD_SET_HZ_ENABLE:{
  3255. transactionSetResult( TRANSACTION_RESULT_OK );
  3256. break;
  3257. };
  3258. case CMD_GET_ACTIVE_PROFILE:{
  3259. //if ( ePSTG == LRF_WS_INIT ) {
  3260. //m_bMultiProfileSupported = true;
  3261. m_nActiveDetectionProfile = 0;
  3262. //setStage( LRF_WS_STAGE_1 );
  3263. //};
  3264. transactionSetResult( TRANSACTION_RESULT_OK );
  3265. break;
  3266. };
  3267. };
  3268. return true;
  3269. #ifdef DEBUG_EXTRA
  3270. } else {
  3271. LOG("Not Mine Package!");
  3272. #endif
  3273. };
  3274. return false;
  3275. };
  3276. #undef PRINTOUT
  3277. /*
  3278. bool device2DSensor::downloadFile( CSTR fname ){
  3279. if( fname == NULL ) return false;
  3280. uint8_t len = strlen( fname );
  3281. if( len == 0 ) return false;
  3282. if( m_bSupportedFS ) {
  3283. m_sOutFSData.nCommand = FS_CMD_SEND_CMD;
  3284. m_sOutFSData.sendcmd.nOrder = 0;
  3285. m_sOutFSData.sendcmd.nLast = 1;
  3286. m_sOutFSData.sendcmd.nPosition = 0;
  3287. m_sOutFSData.sendcmd.nSubSize = len + 4; // Size of FS_PACK
  3288. //Header
  3289. m_sOutFSData.sendcmd.pSubBuffer[0] = LG_FS_OP_OPEN_FILE;
  3290. m_sOutFSData.sendcmd.pSubBuffer[1] = len + 1; //Size of FS_PATH
  3291. m_sOutFSData.sendcmd.pSubBuffer[2] = 0x00;
  3292. // FS_PATH Begins here
  3293. m_sOutFSData.sendcmd.pSubBuffer[3] = len;
  3294. memcpy( &m_sOutFSData.sendcmd.pSubBuffer[4], fname, len );
  3295. if( sendFS_package( &m_sOutFSData ) ){
  3296. return true;
  3297. };
  3298. };
  3299. return false;
  3300. };
  3301. */
  3302. TARGET_DATA *device2DSensor::prepareTargetData( uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID ){
  3303. TARGET_DATA* tVal = NULL;
  3304. systemAnchor* tSystem = systemAnchor::getInstance();
  3305. if( tSystem != NULL ) {
  3306. tVal = (TARGET_DATA*)malloc(sizeof(TARGET_DATA));
  3307. if (tVal != NULL) {
  3308. uint16_t cX, cY;
  3309. memset( tVal, 0, sizeof(TARGET_DATA) );
  3310. tVal->source_position.lat = m_oPosition.getLat();
  3311. tVal->source_position.lon = m_oPosition.getLon();
  3312. tVal->source_position.alt = m_oPosition.getAlt();
  3313. tVal->local_target.r = m_sLRF_DATA.max_range / 2048.0f * (float)RANGE;
  3314. AZ = ( AZ + m_sLRF_DATA.base_shift ) % 6000;
  3315. //tVal->local_target.fi = 360.0f - (360.0f / 6000.0f) * (float) AZ;
  3316. tVal->local_target.tetta = 90.0f;
  3317. tVal->local_target.fi = (360.0f / 6000.0f) * (float) AZ;
  3318. tVal->area = WIDTH;
  3319. tVal->lrf_id = LRFID;//0; // Always Master?
  3320. tVal->digital = RANGE;
  3321. // local - C3D_SPH_DEGREES
  3322. // system - C3D_DECART
  3323. // global - C3D_WGS84_LOC
  3324. tSystem->convertToSystem( &m_oPosition, tVal->local_target, tVal->system_target );
  3325. if ( tSystem->beLocal() ) {
  3326. tVal->global_target.lat = tVal->system_target.y;
  3327. tVal->global_target.lon = tVal->system_target.x;
  3328. tVal->global_target.alt = tVal->system_target.z;
  3329. } else {
  3330. //ToDo: Fix Convert!
  3331. tSystem->convertToGlobal(&m_oPosition, tVal->local_target, tVal->global_target);
  3332. //tSystem->convertToGlobal( &m_oPosition, tVal->system_target, tVal->global_target );
  3333. };
  3334. #ifdef DEBUG_EXTRA
  3335. char tB[128];
  3336. sprintf(tB, "tCords Local: %0.3f %0.3f %0.3f", tVal->local_target.r, tVal->local_target.fi, tVal->local_target.tetta );
  3337. LOG( tB );
  3338. sprintf(tB, "tCords System: %0.3f %0.3f %0.3f", tVal->system_target.x, tVal->system_target.y, tVal->system_target.z );
  3339. LOG( tB );
  3340. sprintf(tB, "tCords Global: %0.3f %0.3f %0.3f", tVal->global_target.lat, tVal->global_target.lon, tVal->global_target.alt );
  3341. LOG( tB );
  3342. #endif
  3343. };
  3344. };
  3345. return tVal;
  3346. };
  3347. void device2DSensor::simulateTarget( void ){
  3348. uint16_t AZ, RANGE;
  3349. uint32_t WIDTH;
  3350. AZ = uint16_t ( rand() * ( 6000.0f /(float) RAND_MAX ));
  3351. RANGE = uint16_t ( rand() * ( 2048.0f /(float) RAND_MAX ));
  3352. WIDTH = 4000;
  3353. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH );
  3354. if( tData != NULL ){
  3355. if( m_pTargetFilter != NULL ) {
  3356. if( !m_pTargetFilter->validateTarget( m_sNodeData.node_id, tData ) ){
  3357. free( tData );
  3358. return;
  3359. };
  3360. };
  3361. EVENT_CONTAINER * bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_TARGET_2D_WHITE, NULL, NULL, tData );
  3362. if (bEVT != NULL) {
  3363. m_pEventHeap->broadcast( bEVT );
  3364. };
  3365. };
  3366. };
  3367. /*
  3368. void device2DSensor::saveRawDrawData( uint16_t alngles ){
  3369. CSTR tID = getUniqID_MD5();
  3370. if( tID!= NULL ) {
  3371. char cPATH[256];
  3372. FILE *fp;
  3373. sprintf( cPATH, "data/device_draws/%s.raw", tID );
  3374. fp = fopen( cPATH, "wb");
  3375. if( fp != NULL ) {
  3376. uint32_t tVal = alngles;
  3377. fwrite( &tVal, 4, 1, fp );
  3378. fwrite( m_vDrawRanges, 4, alngles, fp );
  3379. fclose( fp );
  3380. m_pDBC->addLRFDraw( m_sNodeData.node_id, alngles, tID );
  3381. } else {
  3382. LOG_ERROR("Cannot open DRAW file!");
  3383. }
  3384. free( tID );
  3385. };
  3386. };
  3387. */
  3388. inline int DBL_CMP( const double& a, const double& b, const double quality = 1e-10 ){
  3389. if( fabs(a - b) <= fabs(quality) ) return 0;
  3390. if( a > b ) return 1;
  3391. return -1;
  3392. };
  3393. typedef struct S_VERTEX{
  3394. double x, y, r;
  3395. BOOL f;
  3396. int n;
  3397. }VERTEX, *PVERTEX;
  3398. typedef struct S_SEGMENT{
  3399. int pPoints[2];
  3400. int nIndex;
  3401. }SEGMENT, *PSEGMENT;
  3402. typedef struct S_SEGMENTS{
  3403. PVERTEX pPoints;
  3404. int nCount;
  3405. }SEGMENTS, *PSEGMENTS;
  3406. BOOL CrossProduct( PVERTEX ln0, PVERTEX ln1, PVERTEX pCross, bool fCheck0 = true, bool fCheck1 = true ){
  3407. #undef B0
  3408. double A0, A1, B0, B1, X, Y;
  3409. if( DBL_CMP(ln0[0].x, ln0[1].x) == 0 ){
  3410. A0 = DBL_MAX;
  3411. B0 = ln0[0].x;
  3412. } else {
  3413. A0 = (ln0[0].y - ln0[1].y) / (ln0[0].x - ln0[1].x);
  3414. B0 = ln0[0].y - A0 * ln0[0].x;
  3415. };
  3416. if(DBL_CMP(ln1[0].x , ln1[1].x) == 0){
  3417. A1 = DBL_MAX;
  3418. B1 = ln1[0].x;
  3419. } else {
  3420. A1 = (ln1[0].y - ln1[1].y) / (ln1[0].x - ln1[1].x);
  3421. B1 = ln1[0].y - A1 * ln1[0].x;
  3422. };
  3423. if(A0 == DBL_MAX){
  3424. if(A1 == DBL_MAX) return FALSE;
  3425. X = B0;
  3426. Y = A1 * X + B1;
  3427. } else {
  3428. if(A1 == DBL_MAX) X = B1;
  3429. else {
  3430. if(DBL_CMP( A1, A0 ) != 0) X = (B0 - B1) / (A1 - A0); else return FALSE;
  3431. };
  3432. Y = A0 * X + B0;
  3433. };
  3434. double y = Y, x = X;
  3435. if( fCheck0 ){
  3436. double x0 = ln0[0].x, x1 = ln0[1].x;
  3437. double y0 = ln0[0].y, y1 = ln0[1].y;
  3438. if(DBL_CMP(y0, y1) == -1 && (DBL_CMP(y0, y) == 1 || DBL_CMP(y, y1) == 1)) return FALSE;
  3439. if(DBL_CMP(y0, y1) == 1 && (DBL_CMP(y0, y) == -1 || DBL_CMP(y, y1) == -1)) return FALSE;
  3440. if(DBL_CMP(x0, x1) == -1 && (DBL_CMP(x0, x) == 1 || DBL_CMP(x, x1) == 1)) return FALSE;
  3441. if(DBL_CMP(x0, x1) == 1 && (DBL_CMP(x0, x) == -1 || DBL_CMP(x, x1) == -1)) return FALSE;
  3442. };
  3443. if( fCheck1 ){
  3444. double x0 = ln1[0].x, x1 = ln1[1].x;
  3445. double y0 = ln1[0].y, y1 = ln1[1].y;
  3446. if(DBL_CMP(y0, y1) == -1 && (DBL_CMP(y0, y) == 1 || DBL_CMP(y, y1) == 1)) return FALSE;
  3447. if(DBL_CMP(y0, y1) == 1 && (DBL_CMP(y0, y) == -1 || DBL_CMP(y, y1) == -1)) return FALSE;
  3448. if(DBL_CMP(x0, x1) == -1 && (DBL_CMP(x0, x) == 1 || DBL_CMP(x, x1) == 1)) return FALSE;
  3449. if(DBL_CMP(x0, x1) == 1 && (DBL_CMP(x0, x) == -1 || DBL_CMP(x, x1) == -1)) return FALSE;
  3450. };
  3451. pCross->x = X;
  3452. pCross->y = Y;
  3453. return TRUE;
  3454. };
  3455. BOOL PtInLine( PVERTEX ln, VERTEX& p ){
  3456. double A, B;
  3457. if(DBL_CMP(ln[0].x, ln[1].x) == 0){
  3458. A = DBL_MAX;
  3459. B = ln[0].x;
  3460. } else {
  3461. A = (ln[0].y - ln[1].y) / (ln[0].x - ln[1].x);
  3462. B = ln[0].y - A * ln[0].x;
  3463. };
  3464. if(A == DBL_MAX) {
  3465. if( DBL_CMP(p.x, B) == 0) return TRUE;
  3466. } else {
  3467. if(DBL_CMP(p.x * A + B, p.y) == 0) return TRUE;
  3468. };
  3469. return FALSE;
  3470. };
  3471. int comparePoints( const void *arg1, const void *arg2 ){
  3472. if(((PVERTEX)arg1)->r > ((PVERTEX)arg2)->r) return +1;
  3473. if(((PVERTEX)arg1)->r < ((PVERTEX)arg2)->r) return -1;
  3474. return 0;
  3475. };
  3476. void AddPointToSegment( PSEGMENTS pSegments, int nIndex, PVERTEX pPoint){
  3477. PVERTEX pNew = new VERTEX[pSegments[nIndex].nCount + 1];
  3478. memcpy( pNew, pSegments[nIndex].pPoints, sizeof(VERTEX) * pSegments[nIndex].nCount );
  3479. memcpy( pNew + pSegments[nIndex].nCount, pPoint, sizeof(VERTEX));
  3480. if(pSegments[nIndex].pPoints) delete pSegments[nIndex].pPoints;
  3481. pSegments[nIndex].pPoints = pNew;
  3482. pSegments[nIndex].nCount++;
  3483. };
  3484. void StickSegments( PSEGMENTS pSegments, int nIndex ){
  3485. if( pSegments[nIndex].nCount ){
  3486. qsort( pSegments[nIndex].pPoints, pSegments[nIndex].nCount, sizeof(VERTEX), comparePoints );
  3487. PVERTEX pTemp = new VERTEX[pSegments[nIndex].nCount];
  3488. PVERTEX pPoints = pSegments[nIndex].pPoints;
  3489. int f, nT = 0;
  3490. pTemp[nT++] = pPoints[0];
  3491. f = pPoints[0].f;
  3492. for(int i = 1; i < pSegments[nIndex].nCount;){
  3493. f += pPoints[i].f;
  3494. if(f == 0){
  3495. pTemp[nT++] = pPoints[i++];
  3496. if(i < pSegments[nIndex].nCount){
  3497. pTemp[nT++] = pPoints[i];
  3498. f = pPoints[i++].f;
  3499. };
  3500. } else i++;
  3501. };
  3502. if(pSegments[nIndex].pPoints) delete[] pSegments[nIndex].pPoints;
  3503. pSegments[nIndex].pPoints = new VERTEX[nT];
  3504. memcpy( pSegments[nIndex].pPoints, pTemp, sizeof(VERTEX) * nT );
  3505. pSegments[nIndex].nCount = nT;
  3506. if(pTemp) delete[] pTemp;
  3507. };
  3508. };
  3509. int compareSegments(const void *arg1, const void *arg2){
  3510. if(((PSEGMENT)arg1)->nIndex > ((PSEGMENT)arg2)->nIndex) return +1;
  3511. if(((PSEGMENT)arg1)->nIndex < ((PSEGMENT)arg2)->nIndex) return -1;
  3512. if(((PSEGMENT)arg1)->pPoints[0] > ((PSEGMENT)arg2)->pPoints[0]) return +1;
  3513. if(((PSEGMENT)arg1)->pPoints[0] < ((PSEGMENT)arg2)->pPoints[0]) return -1;
  3514. return 0;
  3515. };
  3516. bool pnpoly( uint16_t nvert, float *vertx, float *verty, float testx, float testy ){
  3517. bool c = false;
  3518. for( uint16_t i = 0, j = nvert-1; i < nvert; j = i++ ) if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) c = !c;
  3519. return c;
  3520. };
  3521. bool device2DSensor::PtInPolygons( TEST_POINT& point, uint8_t F ){
  3522. for( uint16_t i = 0; i < m_sShadow.m_nPolygonCount; i++)
  3523. if( F == m_sShadow.pPolygones[i].bType )
  3524. if ( PtInPolygon( m_sShadow.pPolygones[i], point ) ) return true;
  3525. return false;
  3526. };
  3527. bool device2DSensor::PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point ){
  3528. if( Poly.wCount < 3 ) return false;
  3529. float *vertx = (float *) calloc( Poly.wCount, sizeof(float));
  3530. float *verty = (float *) calloc( Poly.wCount, sizeof(float));
  3531. for( int z =0; z < Poly.wCount; z++ ) {
  3532. vertx[z] = (float)Poly.pPoint[z].wX;
  3533. verty[z] = (float)Poly.pPoint[z].wY;
  3534. };
  3535. if ( pnpoly( Poly.wCount, vertx, verty, point.x, point.y )){
  3536. free(vertx);
  3537. free(verty);
  3538. return true;
  3539. };
  3540. free(vertx);
  3541. free(verty);
  3542. return false;
  3543. };
  3544. bool device2DSensor::rasterizeShadow(){
  3545. const double TWO_PI = 6.2831853071796;
  3546. const double ONE_PI = 3.1415926535898;
  3547. bool masked[6] = {0};
  3548. uint16_t cMin[6] = {0};
  3549. uint16_t cMax[6] = {0};
  3550. double k = TWO_PI /((double)MAX_2D_SHADOW_RAY_LINES );
  3551. double z_shift = 2.0 * k * ((double)m_sLRF_DATA.base_shift );
  3552. for( uint16_t i=0; i < MAX_2D_SHADOW_RAY_LINES; i++ ) {
  3553. double ca = TWO_PI - ( k * i + z_shift ); // must be checked sign!!
  3554. double sin_val = sin( ca );
  3555. double cos_val = cos( ca );
  3556. memset( &masked, 0, 5*sizeof( bool ) );
  3557. memset( &cMin, 0, 5*sizeof( uint16_t ) );
  3558. memset( &cMax, 0, 5*sizeof( uint16_t ) );
  3559. // 1 - to close polygones that going outside
  3560. for( uint16_t range_digital = 0; range_digital < 2047; range_digital++ ) {
  3561. TEST_POINT TP;
  3562. TP.x = (float)(cos_val*((double)range_digital));
  3563. TP.y = (float)(sin_val*((double)range_digital));
  3564. for( uint8_t z=0; z < 6; z++ ){ // Mask ID
  3565. if( masked[z] ) {
  3566. if(!PtInPolygons( TP, z )){
  3567. masked[z] = false;
  3568. cMax[z] = range_digital;
  3569. if( cMin[z] != cMax[z] ) { //Filter Null Masks
  3570. m_sShadow.ray_lines[i].rays = (SHADOW_RAY *)reallocarray(m_sShadow.ray_lines[i].rays, m_sShadow.ray_lines[i].nCount + 1, sizeof(SHADOW_RAY));
  3571. if ( m_sShadow.ray_lines[i].rays == NULL ) {
  3572. LOG_ERROR("Ray realloc failure!");
  3573. m_sShadow.ray_lines[i].nCount = 0;
  3574. return false;
  3575. };
  3576. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMin = cMin[z];
  3577. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMax = cMax[z];
  3578. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].bType = z;
  3579. m_sShadow.ray_lines[i].nCount++;
  3580. #ifdef DEBUG_EXTRA
  3581. char tB[128];
  3582. sprintf( tB ,"New Ray: Mask[%d] angle(line)[%d] min[%d] max[%d] cnt[%d]", z, i, cMin[z], cMax[z], m_sShadow.ray_lines[i].nCount );
  3583. LOG(tB);
  3584. #endif
  3585. }
  3586. };
  3587. } else {
  3588. if(PtInPolygons( TP, z )){
  3589. masked[z] = true;
  3590. cMin[z] = range_digital;
  3591. };
  3592. };
  3593. };
  3594. };
  3595. // to clode poligones that goed outside
  3596. for( uint8_t z=0; z < 5; z++ ){
  3597. if ( masked[z] ) {
  3598. masked[z] = false;
  3599. m_sShadow.ray_lines[i].rays = (SHADOW_RAY *) reallocarray( m_sShadow.ray_lines[i].rays, m_sShadow.ray_lines[i].nCount+1, sizeof(SHADOW_RAY) );
  3600. if ( m_sShadow.ray_lines[i].rays == NULL ) {
  3601. LOG_ERROR("Ray realloc failure!");
  3602. m_sShadow.ray_lines[i].nCount = 0;
  3603. return false;
  3604. };
  3605. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMin = cMin[z];
  3606. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMax = 2047;
  3607. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].bType = z;
  3608. m_sShadow.ray_lines[i].nCount++;
  3609. #ifdef DEBUG_EXTRA
  3610. char tB[128];
  3611. sprintf( tB ,"Ray: Mask[%d] angle[%d] min[%d] max[%d]", z, i, cMin[z], 2047 );
  3612. LOG(tB);
  3613. #endif
  3614. };
  3615. };
  3616. };
  3617. return true;
  3618. };
  3619. bool device2DSensor::cleanShadowInDB( void ){
  3620. for( uint8_t MaskLayer=0; MaskLayer < 5; MaskLayer++ ) {
  3621. if( uint32_t tMaskID = m_pDBC->getLRFMaskID( m_sLRF_DATA.id , 0, MaskLayer ) ) m_pDBC->cleanLRFMask( tMaskID, true );
  3622. };
  3623. };
  3624. bool device2DSensor::loadShadowFromDB( void ){
  3625. };
  3626. bool device2DSensor::saveShadowToDB( void ){
  3627. for( uint8_t MaskLayer=0; MaskLayer < 5; MaskLayer++ ) {
  3628. #ifdef DEBUG_EXTRA
  3629. LOG( "Adding Layer To DATABASE");
  3630. #endif
  3631. uint32_t tMaskID = m_pDBC->getLRFMaskID( m_sLRF_DATA.id , 0, MaskLayer );
  3632. if( tMaskID ) {
  3633. #ifdef DEBUG_EXTRA
  3634. LOG("Have Old Mask -> Delete Old!");
  3635. #endif
  3636. m_pDBC->cleanLRFMask( tMaskID, true );
  3637. tMaskID = 0;
  3638. };
  3639. for( uint8_t i = 0; i < m_sShadow.m_nPolygonCount; i++ ){
  3640. if( m_sShadow.pPolygones[i].bType == MaskLayer ){
  3641. if( m_sShadow.pPolygones[i].pPoint ){
  3642. if( tMaskID == 0 ) {
  3643. #ifdef DEBUG_EXTRA
  3644. LOG("No Mask -> Create One!");
  3645. #endif
  3646. tMaskID = m_pDBC->addLRFMask( m_sLRF_DATA.id, 0, MaskLayer );
  3647. };
  3648. if( tMaskID ) {
  3649. uint32_t tPolyID = 0;
  3650. #ifdef DEBUG_EXTRA
  3651. LOG("Creating New Polygone!");
  3652. #endif
  3653. switch( MaskLayer ) {
  3654. case 0: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 255, 0, 255); break;
  3655. case 1: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 255, 255, 0); break;
  3656. case 2: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 255, 255); break;
  3657. case 3: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 255, 0); break;
  3658. case 4: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 0, 255); break;
  3659. default: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 0, 0 ); break;
  3660. };
  3661. if ( tPolyID ) {
  3662. #ifdef DEBUG_EXTRA
  3663. LOG("Add Points to a created Polygone!");
  3664. #endif
  3665. for ( uint16_t k=0;k < m_sShadow.pPolygones[i].wCount; k++ ) {
  3666. m_pDBC->addLRFMaskPolygonePoint(
  3667. tPolyID,
  3668. m_sShadow.pPolygones[i].pPoint[k].wX,
  3669. m_sShadow.pPolygones[i].pPoint[k].wY
  3670. );
  3671. };
  3672. } else LOG("No Polygone Created !!!!");
  3673. } else LOG("No Mask Created !!!!");
  3674. };
  3675. };
  3676. };
  3677. if ( tMaskID ) {
  3678. m_pDBC->setLRFMaskStatus( tMaskID, ( m_sShadow.m_nEnabled & (1<<MaskLayer) ) );
  3679. };
  3680. };
  3681. };
  3682. #ifdef DEBUG
  3683. void device2DSensor::makeShadowPic( CSTR picname ){
  3684. cv::Scalar zone_colors[6] = { cv::Scalar(0, 0, 255),
  3685. cv::Scalar(255, 20, 255),
  3686. cv::Scalar(0, 255, 255),
  3687. cv::Scalar(0, 255, 0),
  3688. cv::Scalar(255, 0, 0),
  3689. cv::Scalar(120, 120, 120)
  3690. };
  3691. const double TWO_PI = 6.2831853071796;
  3692. double k = TWO_PI /((double)MAX_2D_SHADOW_RAY_LINES );
  3693. double z_shift = k * ((double)m_sLRF_DATA.base_shift );
  3694. cv::Mat tPic(512, 512, CV_8UC3, cv::Scalar(20, 20, 20));
  3695. double cx = 256.0;
  3696. double cy = 256.0;
  3697. double r = 255.0/2048.0;
  3698. for ( int i = 0; i < 360; i++ ) {
  3699. double ca = k * i + z_shift; // must be checked sign!!
  3700. double sin_val = sin( ca );
  3701. double cos_val = cos( ca );
  3702. cv::line( tPic, cv::Point( cx, cy ), cv::Point( cx+cos_val*256, cy+sin_val*256 ), zone_colors[5], 1, cv::LINE_AA );
  3703. if( m_sShadow.ray_lines[i].nCount ){
  3704. for ( int z=0; z < m_sShadow.ray_lines[i].nCount; z++ ) {
  3705. int r1 = m_sShadow.ray_lines[i].rays[z].nMin;
  3706. int r2 = m_sShadow.ray_lines[i].rays[z].nMax;
  3707. cv::Scalar color = zone_colors[m_sShadow.ray_lines[i].rays[z].bType];
  3708. int x1 = cx+(cos_val*r1*r);
  3709. int y1 = cy+(sin_val*r1*r);
  3710. int x2 = cx+(cos_val*r2*r);
  3711. int y2 = cy+(sin_val*r2*r);
  3712. cv::line(tPic, cv::Point(x1, y1), cv::Point( x2, y2), color, 1, cv::LINE_AA);
  3713. };
  3714. };
  3715. };
  3716. vector<int> compression_params;
  3717. compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
  3718. compression_params.push_back(9);
  3719. //compression_params.push_back( cv::IMWRITE_JPEG_QUALITY );
  3720. //compression_params.push_back( m_sEmbedVideoData.compression_quality );
  3721. vector<uchar> buf;
  3722. cv::imencode( ".png", tPic, buf, compression_params );
  3723. FILE *fd;
  3724. fd = fopen( picname, "wb");
  3725. if ( fd ) {
  3726. fwrite( buf.data(), 1, buf.size(), fd );
  3727. fclose( fd );
  3728. };
  3729. buf.clear();
  3730. };
  3731. #endif
  3732. void device2DSensor::waitStateFunction( LRF_WORK_STAGE boboStage ){
  3733. if( m_bTimeOutCounter ){
  3734. m_bTimeOutCounter--;
  3735. DELAY_10MS( LGS_DEFAULT_WS_TIME );
  3736. } else {
  3737. if( m_bOpRetryCnt ){
  3738. #ifdef DEBUG_EXTRA
  3739. LOG("COM ATTEMPT RECOVER");
  3740. #endif
  3741. m_bOpRetryCnt--;
  3742. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  3743. registerCommError( false );
  3744. LRF_WORK_STAGE pS = getPrevStage();
  3745. if ( pS != LRF_WS_INIT ) {
  3746. setStage( pS, false );
  3747. } else {
  3748. if ( boboStage != LRF_WS_INIT ) {
  3749. setStage( boboStage, false );
  3750. } else {
  3751. setWM( LRF_WM_CONNECTION );
  3752. return;
  3753. };
  3754. };
  3755. } else {
  3756. LOG_ERROR("Communication Wait State TO!");
  3757. registerCommError( true );
  3758. //setStage( boboStage );
  3759. setWM( LRF_WM_CONNECTION );
  3760. return;
  3761. };
  3762. DELAY_10MS( LGS_DEFAULT_WS_TIME );
  3763. transactionResetResult();
  3764. };
  3765. };
  3766. void device2DSensor::poolStateFunction(){
  3767. goNextStage();
  3768. transactionResetResult();
  3769. };
  3770. #undef SIZE_IDX
  3771. #undef DEV_ID_IDX
  3772. #undef CMD_IDX
  3773. #undef SUB_CMD_IDX
  3774. #undef DATA_BEGIN_IDX
  3775. #undef LOG
  3776. #undef LOG_ERROR
  3777. #undef DEBUG_EXTRA