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.

3911 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 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. if( m_sNodeData.type == ARGUS_ALS_SENSOR || m_sNodeData.type == ARGUS_LFS_SENSOR ) {
  1332. LOG("Send Slave Profile!");
  1333. //ANODE_WM_2D_SET_SLAVE_PARAM
  1334. PLGS_2D_PARAMETERS tData = m_pDBC->getLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, false );
  1335. if ( tData ) {
  1336. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1337. if (!setParameters( tData, false, m_nActiveDetectionProfile)) {
  1338. LOG_ERROR("Fall Back to Disconnected!");
  1339. setWM( LRF_WM_CONNECTION );
  1340. } else transactionWaitResult();
  1341. free( tData );
  1342. } else transactionSetResult( TRANSACTION_RESULT_OK );
  1343. } else transactionSetResult( TRANSACTION_RESULT_OK );
  1344. break;
  1345. };
  1346. case LRF_WS_STAGE_6:{
  1347. //Issue Full Reset
  1348. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1349. if ( !doFullReset() ) {
  1350. LOG_ERROR("Fall Back to Disconnected!");
  1351. setWM( LRF_WM_CONNECTION );
  1352. } else transactionWaitResult();
  1353. break;
  1354. };
  1355. case LRF_WS_STAGE_7: setWM( LRF_WM_IDLE ); break;
  1356. default: setStage( LRF_WS_INIT ); break;
  1357. };
  1358. break;
  1359. };
  1360. case STG_WAIT: waitStateFunction(); break;
  1361. case STG_POOL: poolStateFunction(); break;
  1362. };
  1363. };
  1364. void device2DSensor::save_masks(){
  1365. #ifdef DEBUG_EXTRA
  1366. LOG("SAVE MASKS");
  1367. #endif
  1368. // Reset State
  1369. if( initWModeFunction( LRF_WM_SAVE_MASKS ) ){
  1370. updateDataStatus( ARGUS_DS_BUSY );
  1371. memset( m_pTGENFILENAMES[0], 0, 33 );
  1372. memset( m_pTGENFILENAMES[1], 0, 33 );
  1373. memset( m_pTGENFILENAMES[2], 0, 33 );
  1374. m_bTGENFILECNT = 0;
  1375. m_bTGENFILE = 0;
  1376. m_sGetFileTransfers.current = 0;
  1377. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  1378. if ( m_sGetFileTransfers.helpers.size() ) {
  1379. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  1380. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  1381. free( (*idx) );
  1382. };
  1383. m_sGetFileTransfers.helpers.clear();
  1384. };
  1385. };
  1386. switch( getPPStatus() ){
  1387. case STG_PUSH:{
  1388. switch( getStage() ) {
  1389. case LRF_WS_INIT:{
  1390. if( m_bTGENFILECNT == 0 ){
  1391. if( generateRestartFile( m_bTGENFILE ) ){
  1392. GETFILE_IO_HELPER *tH = NULL;
  1393. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  1394. if ( tH ) {
  1395. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  1396. strncpy( tH->destName, "updateMZ.bat", 16 );
  1397. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  1398. struct stat st;
  1399. char tB[256];
  1400. sprintf( tB, "data/uploads/%s", tH->sourceName );
  1401. stat( tB, &st );
  1402. tH->fileSize = st.st_size;
  1403. tH->state = GF_OP_OK;
  1404. tH->db_id = 0;
  1405. tH->index = 0x04;
  1406. m_sGetFileTransfers.helpers.push_back( tH );
  1407. m_bTGENFILE++;
  1408. m_bTGENFILECNT++;
  1409. };
  1410. } else {
  1411. LOG_ERROR("Gen UpdateMZ Failure!");
  1412. };
  1413. };
  1414. cleanShadowStructs();
  1415. if( m_pDBC->fillShadow2D( m_sLRF_DATA.id, m_sShadow ) ){
  1416. if( rasterizeShadow() ){
  1417. #ifdef DEBUG_EXTRA
  1418. makeShadowPic("data/shadow.png");
  1419. #endif
  1420. transactionSetResult( TRANSACTION_RESULT_OK );
  1421. } else {
  1422. setStage( LRF_WS_STAGE_11 );
  1423. };
  1424. } else {
  1425. setStage( LRF_WS_STAGE_11 );
  1426. };
  1427. break;
  1428. };
  1429. case LRF_WS_STAGE_1:{
  1430. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  1431. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1432. m_bRequestedDeviceWM = MODE_GETFILE;
  1433. if( !setMode( MODE_GETFILE ) ) {
  1434. LOG_ERROR("Fall Back to Disconnected!");
  1435. setWM( LRF_WM_CONNECTION );
  1436. } else transactionWaitResult();
  1437. } else {
  1438. transactionSetResult( TRANSACTION_RESULT_OK );
  1439. };
  1440. break;
  1441. };
  1442. case LRF_WS_STAGE_2:{
  1443. if( m_sGetFileTransfers.helpers.size() ){
  1444. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  1445. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  1446. case GF_OP_CLOSE:{
  1447. // After Sending check if have other file to send
  1448. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  1449. m_sGetFileTransfers.current++;
  1450. } else {
  1451. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  1452. // case GF_EM_ISSUE_RESET:{
  1453. // break;
  1454. // };
  1455. // case GF_EM_ISSUE_SAVE_FW:{
  1456. // break;
  1457. // }
  1458. // default: setStage( LRF_WS_STAGE_7 );
  1459. //};
  1460. transactionSetResult( TRANSACTION_RESULT_OK );
  1461. return;
  1462. };
  1463. };
  1464. case GF_OP_OK:{
  1465. // INIT Sending File
  1466. char tB[256];
  1467. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  1468. #ifdef DEBUG
  1469. LOG(tB);
  1470. #endif
  1471. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  1472. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  1473. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  1474. #ifdef DEBUG_EXTRA
  1475. LOG("OPEN -> Send Info");
  1476. #endif
  1477. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  1478. memcpy(
  1479. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1480. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  1481. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  1482. );
  1483. } else {
  1484. #ifdef DEBUG_EXTRA
  1485. LOG("NOPEN -> Cancel");
  1486. #endif
  1487. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  1488. transactionSetResult( TRANSACTION_RESULT_OK );
  1489. return;
  1490. };
  1491. break;
  1492. };
  1493. case GF_OP_OPEN:{
  1494. #ifdef DEBUG_EXTRA
  1495. LOG("Info -> Data");
  1496. #endif
  1497. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  1498. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1499. 1,
  1500. 48,
  1501. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1502. );
  1503. #ifdef DEBUG_EXTRA
  1504. char tB[64];
  1505. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  1506. LOG( tB );
  1507. #endif
  1508. break;
  1509. };
  1510. case GF_OP_DATA:{
  1511. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1512. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  1513. #ifdef DEBUG_EXTRA
  1514. char tB[64];
  1515. if ( pos != EOF ){
  1516. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  1517. LOG( tB );
  1518. } else {
  1519. LOG("File Ended!");
  1520. };
  1521. #endif
  1522. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1523. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  1524. }
  1525. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1526. 1,
  1527. 48,
  1528. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1529. );
  1530. #ifdef DEBUG_EXTRA
  1531. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  1532. LOG( tB );
  1533. #endif
  1534. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  1535. #ifdef DEBUG_EXTRA
  1536. LOG("Change to Close");
  1537. #endif
  1538. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  1539. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1540. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  1541. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1542. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  1543. };
  1544. };
  1545. break;
  1546. };
  1547. };
  1548. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1549. if( !sendGF_package(
  1550. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  1551. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  1552. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  1553. )
  1554. ){
  1555. LOG_ERROR("Fall Back to Disconnected!");
  1556. setWM( LRF_WM_CONNECTION );
  1557. } else transactionWaitResult();
  1558. } else {
  1559. // Exit From GetFile Mode --> No need --> Reset Device
  1560. transactionSetResult( TRANSACTION_RESULT_OK );
  1561. };
  1562. break;
  1563. };
  1564. case LRF_WS_STAGE_3:{
  1565. // Remove Generated Files
  1566. if( m_bTGENFILECNT ){
  1567. for( uint8_t idx = 0; idx < m_bTGENFILECNT; idx++){
  1568. char tName[256];
  1569. sprintf( tName, "data/uploads/%s", m_pTGENFILENAMES[idx]);
  1570. unlink( tName );
  1571. };
  1572. };
  1573. transactionSetResult( TRANSACTION_RESULT_OK );
  1574. break;
  1575. };
  1576. case LRF_WS_STAGE_4:{
  1577. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1578. if( m_bActualDeviceWM != MODE_MASK ) {
  1579. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1580. m_bRequestedDeviceWM = MODE_MASK;
  1581. if( !setMode( MODE_MASK ) ) {
  1582. LOG_ERROR("Fall Back to Disconnected!");
  1583. setWM( LRF_WM_CONNECTION );
  1584. } else transactionWaitResult();
  1585. } else {
  1586. transactionSetResult( TRANSACTION_RESULT_OK );
  1587. };
  1588. break;
  1589. };
  1590. case LRF_WS_STAGE_5:{
  1591. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1592. if (!setShadowInfo( m_sShadowHelper.m_bSequence, m_sShadow )) {
  1593. LOG_ERROR("Fall Back to Disconnected!");
  1594. setWM( LRF_WM_CONNECTION );
  1595. } else transactionWaitResult();
  1596. break;
  1597. };
  1598. case LRF_WS_STAGE_6:{
  1599. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1600. if( m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ){
  1601. m_sShadowHelper.m_nCurrentPoint = 0;
  1602. if(!setShadowPoly( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentPolygon)){
  1603. LOG_ERROR("Fall Back to Disconnected!");
  1604. setWM( LRF_WM_CONNECTION );
  1605. } else transactionWaitResult();
  1606. } else {
  1607. #ifdef DEBUG_EXTRA
  1608. LOG("Start Send Rays!");
  1609. #endif
  1610. m_sShadowHelper.m_nCurrentRayLine = 0;
  1611. //skip all empty angles of binary shadow
  1612. while( ( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount == 0 ) && m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  1613. m_sShadowHelper.m_nCurrentRayLine++;
  1614. };
  1615. if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  1616. //if we have an shadows -> transfer else skeep
  1617. setStage( LRF_WS_STAGE_8 );
  1618. } else {
  1619. #ifdef DEBUG_EXTRA
  1620. LOG("Skip Uploading Rays");
  1621. #endif
  1622. setStage( LRF_WS_STAGE_10 );
  1623. };
  1624. };
  1625. break;
  1626. };
  1627. case LRF_WS_STAGE_7:{
  1628. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1629. #ifdef DEBUG_EXTRA
  1630. char tBuff[128];
  1631. sprintf( tBuff,"Send Point %d of %d", (m_sShadowHelper.m_nCurrentPoint + 1), m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount );
  1632. LOG( tBuff );
  1633. #endif
  1634. if( m_sShadowHelper.m_nCurrentPoint < m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount ){
  1635. if( !setShadowPolyPoint( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentPolygon, m_sShadowHelper.m_nCurrentPoint) ){
  1636. LOG_ERROR("Fall Back to Disconnected!");
  1637. setWM( LRF_WM_CONNECTION );
  1638. } else transactionWaitResult();
  1639. } else {
  1640. m_sShadowHelper.m_nCurrentPolygon ++;
  1641. setStage( LRF_WS_STAGE_6 );
  1642. };
  1643. break;
  1644. };
  1645. case LRF_WS_STAGE_8:{
  1646. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1647. #ifdef DEBUG_EXTRA
  1648. char tBuff[128];
  1649. sprintf( tBuff,"Send Shadow for angle %d [%d rays]", m_sShadowHelper.m_nCurrentRayLine, m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount );
  1650. LOG( tBuff );
  1651. #endif
  1652. if( !setShadowRay( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentRayLine ) ){
  1653. LOG_ERROR("Fall Back to Disconnected!");
  1654. setWM( LRF_WM_CONNECTION );
  1655. } else transactionWaitResult();
  1656. break;
  1657. };
  1658. case LRF_WS_STAGE_9:{
  1659. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1660. #ifdef DEBUG_EXTRA
  1661. char tBuff[128];
  1662. sprintf( tBuff,"Send Shadow RayLine %d for andle %d", m_sShadowHelper.m_nCurrentRay, m_sShadowHelper.m_nCurrentRayLine );
  1663. LOG( tBuff );
  1664. #endif
  1665. if( m_sShadowHelper.m_nCurrentRay < m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount ) {
  1666. if( !setShadowRayLine( m_sShadowHelper.m_bSequence, m_sShadow, m_sShadowHelper.m_nCurrentRayLine, m_sShadowHelper.m_nCurrentRay ) ){
  1667. LOG_ERROR("Fall Back to Disconnected!");
  1668. setWM( LRF_WM_CONNECTION );
  1669. } else transactionWaitResult();
  1670. } else {
  1671. // search next not empty angle
  1672. do {
  1673. m_sShadowHelper.m_nCurrentRayLine++;
  1674. } while ( ( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount == 0 ) && m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES );
  1675. if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
  1676. setStage( LRF_WS_STAGE_8 );
  1677. } else {
  1678. // If not found -> finish upload shadow
  1679. transactionSetResult( TRANSACTION_RESULT_OK );
  1680. };
  1681. };
  1682. break;
  1683. };
  1684. case LRF_WS_STAGE_10:{
  1685. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1686. if (!setShadowDone( m_sShadowHelper.m_bSequence )) {
  1687. LOG_ERROR("Fall Back to Disconnected!");
  1688. setWM( LRF_WM_CONNECTION );
  1689. } else transactionWaitResult();
  1690. break;
  1691. };
  1692. case LRF_WS_STAGE_11: setWM( LRF_WM_IDLE ); break;
  1693. default: setStage( LRF_WS_INIT ); break;
  1694. };
  1695. break;
  1696. };
  1697. case STG_WAIT: waitStateFunction(); break;
  1698. case STG_POOL: poolStateFunction(); break;
  1699. };
  1700. };
  1701. void device2DSensor::save_eprom(){
  1702. };
  1703. void device2DSensor::getfileMode(){
  1704. #ifdef DEBUG_EXTRA
  1705. LOG("GETFILE");
  1706. #endif
  1707. // Reset State
  1708. initWModeFunction( LRF_WM_FILE );
  1709. switch( getPPStatus() ){
  1710. case STG_PUSH:{
  1711. switch( getStage() ) {
  1712. case LRF_WS_INIT:{
  1713. m_nCurrentAngle = 0;
  1714. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  1715. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1716. m_bRequestedDeviceWM = MODE_GETFILE;
  1717. if( !setMode( MODE_GETFILE ) ) {
  1718. LOG_ERROR("Fall Back to Disconnected!");
  1719. setWM( LRF_WM_CONNECTION );
  1720. } else transactionWaitResult();
  1721. } else {
  1722. transactionSetResult( TRANSACTION_RESULT_OK );
  1723. };
  1724. break;
  1725. };
  1726. case LRF_WS_STAGE_1:{
  1727. if( m_sGetFileTransfers.helpers.size() ){
  1728. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  1729. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  1730. case GF_OP_CLOSE:{
  1731. // After Sending check if have other file to send
  1732. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  1733. m_sGetFileTransfers.current++;
  1734. } else {
  1735. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  1736. // case GF_EM_ISSUE_RESET:{
  1737. // break;
  1738. // };
  1739. // case GF_EM_ISSUE_SAVE_FW:{
  1740. // break;
  1741. // }
  1742. // default: setStage( LRF_WS_STAGE_7 );
  1743. //};
  1744. transactionSetResult( TRANSACTION_RESULT_OK );
  1745. return;
  1746. };
  1747. };
  1748. case GF_OP_OK:{
  1749. // INIT Sending File
  1750. char tB[256];
  1751. #ifdef DEBUG_EXTRA
  1752. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  1753. LOG(tB);
  1754. #endif
  1755. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  1756. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  1757. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  1758. #ifdef DEBUG_EXTRA
  1759. LOG("OPEN -> Send Info");
  1760. #endif
  1761. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  1762. memcpy(
  1763. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1764. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  1765. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  1766. );
  1767. } else {
  1768. #ifdef DEBUG_EXTRA
  1769. LOG("NOPEN -> Cancel");
  1770. #endif
  1771. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  1772. transactionSetResult( TRANSACTION_RESULT_OK );
  1773. return;
  1774. };
  1775. break;
  1776. };
  1777. case GF_OP_OPEN:{
  1778. #ifdef DEBUG_EXTRA
  1779. LOG("Info -> Data");
  1780. #endif
  1781. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  1782. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1783. 1,
  1784. 48,
  1785. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1786. );
  1787. #ifdef DEBUG_EXTRA
  1788. char tB[64];
  1789. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  1790. LOG( tB );
  1791. #endif
  1792. break;
  1793. };
  1794. case GF_OP_DATA:{
  1795. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1796. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  1797. #ifdef DEBUG_EXTRA
  1798. char tB[64];
  1799. if ( pos != EOF ){
  1800. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  1801. LOG( tB );
  1802. } else {
  1803. LOG("File Ended!");
  1804. };
  1805. #endif
  1806. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1807. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  1808. }
  1809. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  1810. 1,
  1811. 48,
  1812. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  1813. );
  1814. #ifdef DEBUG_EXTRA
  1815. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  1816. LOG( tB );
  1817. #endif
  1818. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  1819. #ifdef DEBUG_EXTRA
  1820. LOG("Change to Close");
  1821. #endif
  1822. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  1823. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  1824. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  1825. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  1826. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  1827. };
  1828. };
  1829. break;
  1830. };
  1831. };
  1832. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1833. if( !sendGF_package(
  1834. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  1835. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  1836. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  1837. )
  1838. ){
  1839. LOG_ERROR("Fall Back to Disconnected!");
  1840. setWM( LRF_WM_CONNECTION );
  1841. } else transactionWaitResult();
  1842. } else {
  1843. // Exit From GetFile Mode
  1844. transactionSetResult( TRANSACTION_RESULT_OK );
  1845. };
  1846. break;
  1847. };
  1848. case LRF_WS_STAGE_2:
  1849. updateDataStatus( ARGUS_DS_READY );
  1850. setWM( LRF_WM_IDLE );
  1851. break;
  1852. };
  1853. break;
  1854. };
  1855. case STG_WAIT: waitStateFunction(); break;
  1856. case STG_POOL: poolStateFunction(); break;
  1857. };
  1858. };
  1859. void device2DSensor::drawMode(){
  1860. #ifdef DEBUG_EXTRA
  1861. LOG("DRAW");
  1862. #endif
  1863. // Reset State
  1864. if( initWModeFunction( LRF_WM_BORDER ) ){
  1865. m_nCurrentAngle = 0;
  1866. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT << 1;
  1867. };
  1868. switch( getPPStatus() ){
  1869. case STG_PUSH:{
  1870. switch( getStage() ) {
  1871. case LRF_WS_INIT:{
  1872. if ( m_bActualDeviceWM != MODE_BORDER ) {
  1873. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1874. m_bRequestedDeviceWM = MODE_BORDER;
  1875. if( !setMode( MODE_BORDER ) ) {
  1876. LOG_ERROR("Fall Back to Disconnected!");
  1877. setWM( LRF_WM_CONNECTION );
  1878. } else transactionWaitResult();
  1879. } else {
  1880. transactionSetResult( TRANSACTION_RESULT_OK );
  1881. };
  1882. break;
  1883. };
  1884. case LRF_WS_STAGE_1:{
  1885. transactionSetResult( TRANSACTION_RESULT_OK );
  1886. break;
  1887. };
  1888. case LRF_WS_STAGE_2:{
  1889. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1890. if( !getFastDraw( m_nCurrentAngle ) ) {
  1891. LOG_ERROR("Fall Back to Disconnected!");
  1892. setWM( LRF_WM_CONNECTION );
  1893. } else transactionWaitResult();
  1894. break;
  1895. };
  1896. case LRF_WS_STAGE_3:{
  1897. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1898. if ( !setMode( MODE_DETECTOR ) ) {
  1899. LOG_ERROR("Fall Back to Disconnected!");
  1900. setWM( LRF_WM_CONNECTION );
  1901. } else transactionWaitResult();
  1902. break;
  1903. };
  1904. case LRF_WS_STAGE_4:{
  1905. updateDataStatus( ARGUS_DS_READY );
  1906. setWM( LRF_WM_IDLE );
  1907. break;
  1908. };
  1909. };
  1910. break;
  1911. };
  1912. case STG_WAIT: waitStateFunction(); break;
  1913. case STG_POOL: poolStateFunction(); break;
  1914. };
  1915. };
  1916. void device2DSensor::maskMode(){
  1917. #ifdef DEBUG_EXTRA
  1918. LOG("MASKOP-ShortSet+MZ");
  1919. #endif
  1920. if( initWModeFunction( LRF_WM_STATUS_MASK ) ){
  1921. //m_bCurShadowMask = m_pDBC->getLRFMasksStatus( m_sLRF_DATA.id );
  1922. #ifdef DEBUG_EXTRA
  1923. char tBuf[64];
  1924. sprintf( tBuf, "CMask: 0x%02X", m_bCurShadowMask );
  1925. LOG( tBuf );
  1926. #endif
  1927. updateDataStatus( ARGUS_DS_BUSY );
  1928. memset( m_pTGENFILENAMES[0], 0, 33 );
  1929. memset( m_pTGENFILENAMES[1], 0, 33 );
  1930. memset( m_pTGENFILENAMES[2], 0, 33 );
  1931. m_bTGENFILECNT = 0;
  1932. m_bTGENFILE = 0;
  1933. m_sGetFileTransfers.current = 0;
  1934. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  1935. if ( m_sGetFileTransfers.helpers.size() ) {
  1936. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  1937. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  1938. free( (*idx) );
  1939. };
  1940. m_sGetFileTransfers.helpers.clear();
  1941. };
  1942. };
  1943. switch( getPPStatus() ){
  1944. case STG_PUSH:{
  1945. switch( getStage() ) {
  1946. case LRF_WS_INIT:{
  1947. if( m_bTGENFILECNT == 0 ){
  1948. if( generateRestartFile( m_bTGENFILE ) ){
  1949. GETFILE_IO_HELPER *tH = NULL;
  1950. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  1951. if ( tH ) {
  1952. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  1953. strncpy( tH->destName, "updateMZ.bat", 16 );
  1954. strncpy( tH->sourceName, m_pTGENFILENAMES[m_bTGENFILE], 32 );
  1955. struct stat st;
  1956. char tB[256];
  1957. sprintf( tB, "data/uploads/%s", tH->sourceName );
  1958. stat( tB, &st );
  1959. tH->fileSize = st.st_size;
  1960. tH->state = GF_OP_OK;
  1961. tH->db_id = 0;
  1962. tH->index = 0x04;
  1963. m_sGetFileTransfers.helpers.push_back( tH );
  1964. m_bTGENFILE++;
  1965. m_bTGENFILECNT++;
  1966. };
  1967. } else {
  1968. LOG_ERROR("Gen UpdateMZ Failure!");
  1969. };
  1970. };
  1971. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1972. uint8_t cm = m_pDBC->getLRFMasksStatus( m_sLRF_DATA.id );
  1973. EVENT_CONTAINER * bEVT = NULL;
  1974. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  1975. if( m_bCurShadowMask < cm ){
  1976. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_OP_ON_MASK, NULL, NULL, tData);
  1977. } else {
  1978. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_OP_OFF_MASK, NULL, NULL, tData);
  1979. };
  1980. if( bEVT != NULL ) {
  1981. m_pEventHeap->broadcast( bEVT );
  1982. } else {
  1983. free( tData );
  1984. };
  1985. m_bCurShadowMask = cm;
  1986. if ( !setShadowStatus( m_bCurShadowMask ) ) {
  1987. LOG_ERROR("Fall Back to Disconnected!");
  1988. setWM( LRF_WM_CONNECTION );
  1989. } else transactionWaitResult();
  1990. break;
  1991. };
  1992. case LRF_WS_STAGE_1:{
  1993. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  1994. #ifdef DEBUG_EXTRA
  1995. LOG("Sending Update MZ!");
  1996. #endif
  1997. if ( m_bActualDeviceWM != MODE_GETFILE ) {
  1998. m_bRequestedDeviceWM = MODE_GETFILE;
  1999. if( !setMode( MODE_GETFILE ) ) {
  2000. LOG_ERROR("Fall Back to Disconnected!");
  2001. setWM( LRF_WM_CONNECTION );
  2002. } else transactionWaitResult();
  2003. } else {
  2004. transactionSetResult( TRANSACTION_RESULT_OK );
  2005. };
  2006. break;
  2007. };
  2008. case LRF_WS_STAGE_2:{
  2009. if( m_sGetFileTransfers.helpers.size() ){
  2010. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index = ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index + 0x04) % GF_OP_INDEX;
  2011. switch( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state ) {
  2012. case GF_OP_CLOSE:{
  2013. // After Sending check if have other file to send
  2014. if( m_sGetFileTransfers.current < ( m_sGetFileTransfers.helpers.size() - 1 ) ) {
  2015. m_sGetFileTransfers.current++;
  2016. } else {
  2017. //switch( m_sGetFileTransfers.transfer_ending_mode ) {
  2018. // case GF_EM_ISSUE_RESET:{
  2019. // break;
  2020. // };
  2021. // case GF_EM_ISSUE_SAVE_FW:{
  2022. // break;
  2023. // }
  2024. // default: setStage( LRF_WS_STAGE_7 );
  2025. //};
  2026. transactionSetResult( TRANSACTION_RESULT_OK );
  2027. return;
  2028. };
  2029. };
  2030. case GF_OP_OK:{
  2031. // INIT Sending File
  2032. char tB[256];
  2033. #ifdef DEBUG_EXTRA
  2034. sprintf( tB, "data/uploads/%s", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->sourceName );
  2035. LOG(tB);
  2036. #endif
  2037. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = fopen( tB, "rb" );
  2038. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd ) {
  2039. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_OPEN;
  2040. #ifdef DEBUG_EXTRA
  2041. LOG("OPEN -> Send Info");
  2042. #endif
  2043. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = strlen( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName );
  2044. memcpy(
  2045. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  2046. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->destName,
  2047. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size
  2048. );
  2049. } else {
  2050. #ifdef DEBUG_EXTRA
  2051. LOG("NOPEN -> Cancel");
  2052. #endif
  2053. //memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
  2054. transactionSetResult( TRANSACTION_RESULT_OK );
  2055. return;
  2056. };
  2057. break;
  2058. };
  2059. case GF_OP_OPEN:{
  2060. #ifdef DEBUG_EXTRA
  2061. LOG("Info -> Data");
  2062. #endif
  2063. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_DATA;
  2064. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  2065. 1,
  2066. 48,
  2067. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  2068. );
  2069. #ifdef DEBUG_EXTRA
  2070. char tB[64];
  2071. sprintf( tB,"%d of %d bytes", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize );
  2072. LOG( tB );
  2073. #endif
  2074. break;
  2075. };
  2076. case GF_OP_DATA:{
  2077. long int pos = ftell( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  2078. uint8_t CP = (uint8_t)((((float)pos)*100.0f)/((float)m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize));
  2079. #ifdef DEBUG_EXTRA
  2080. char tB[64];
  2081. if ( pos != EOF ){
  2082. sprintf( tB, "%d of %d bytes %d%%", pos, m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fileSize, CP );
  2083. LOG( tB );
  2084. } else {
  2085. LOG("File Ended!");
  2086. };
  2087. #endif
  2088. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  2089. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, CP);
  2090. }
  2091. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size = fread( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data,
  2092. 1,
  2093. 48,
  2094. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd
  2095. );
  2096. #ifdef DEBUG_EXTRA
  2097. sprintf( tB,"File Reads %d bytes.", m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size );
  2098. LOG( tB );
  2099. #endif
  2100. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size == 0 ) {
  2101. #ifdef DEBUG_EXTRA
  2102. LOG("Change to Close");
  2103. #endif
  2104. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state = GF_OP_CLOSE;
  2105. fclose( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd );
  2106. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->fd = NULL;
  2107. if ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id ) {
  2108. m_pDBC->updateLRFUpload(m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->db_id, 200);
  2109. };
  2110. };
  2111. break;
  2112. };
  2113. };
  2114. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2115. if( !sendGF_package(
  2116. ( m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->state | m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ),
  2117. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data_size,
  2118. m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->data
  2119. )
  2120. ){
  2121. LOG_ERROR("Fall Back to Disconnected!");
  2122. setWM( LRF_WM_CONNECTION );
  2123. } else transactionWaitResult();
  2124. } else {
  2125. // Exit From GetFile Mode --> No need --> Reset Device
  2126. transactionSetResult( TRANSACTION_RESULT_OK );
  2127. };
  2128. break;
  2129. };
  2130. case LRF_WS_STAGE_3:{
  2131. // Remove Generated Files
  2132. if( m_bTGENFILECNT ){
  2133. for( uint8_t idx = 0; idx < m_bTGENFILECNT; idx++){
  2134. char tName[256];
  2135. sprintf( tName, "data/uploads/%s", m_pTGENFILENAMES[idx]);
  2136. unlink( tName );
  2137. };
  2138. };
  2139. transactionSetResult( TRANSACTION_RESULT_OK );
  2140. break;
  2141. };
  2142. case LRF_WS_STAGE_4:{
  2143. //Issue Full Reset
  2144. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2145. if ( !doFullReset() ) {
  2146. LOG_ERROR("Fall Back to Disconnected!");
  2147. setWM( LRF_WM_CONNECTION );
  2148. } else transactionWaitResult();
  2149. break;
  2150. };
  2151. case LRF_WS_STAGE_5:{
  2152. //setWM( LRF_WM_HANDSHAKE );
  2153. setWM( LRF_WM_IDLE );
  2154. break;
  2155. };
  2156. default: setStage( LRF_WS_INIT ); break;
  2157. };
  2158. break;
  2159. };
  2160. case STG_WAIT: waitStateFunction(); break;
  2161. case STG_POOL: poolStateFunction(); break;
  2162. };
  2163. };
  2164. void device2DSensor::alarmMode(){
  2165. #ifdef DEBUG_EXTRA
  2166. LOG("ALRM");
  2167. #endif
  2168. //Reset State
  2169. if( initWModeFunction( LRF_WM_ALARM ) ) if( m_sLRF_DATA.data_status!= ARGUS_DS_ALARMED ) updateDataStatus( ARGUS_DS_ALARMED );
  2170. switch( getPPStatus() ){
  2171. case STG_PUSH:
  2172. switch( getStage() ) {
  2173. case LRF_WS_INIT:{
  2174. if ( m_bActualDeviceWM != MODE_DETECTOR ) {
  2175. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2176. m_bRequestedDeviceWM = MODE_DETECTOR;
  2177. if( !setMode( MODE_DETECTOR ) ) {
  2178. LOG_ERROR("Fall Back to Disconnected!");
  2179. setWM( LRF_WM_CONNECTION );
  2180. } else transactionWaitResult();
  2181. } else {
  2182. transactionSetResult( TRANSACTION_RESULT_OK );
  2183. };
  2184. break;
  2185. };
  2186. case LRF_WS_STAGE_1:{
  2187. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2188. if( !getState2() ) {
  2189. LOG_ERROR("Fall Back to Disconnected!");
  2190. setWM( LRF_WM_CONNECTION );
  2191. } else transactionWaitResult();
  2192. break;
  2193. };
  2194. case LRF_WS_STAGE_2:{
  2195. setStage( LRF_WS_STAGE_1 );
  2196. break;
  2197. };
  2198. default: setStage( LRF_WS_INIT ); break;
  2199. };
  2200. break;
  2201. case STG_WAIT: waitStateFunction(); break;
  2202. case STG_POOL: poolStateFunction(); break;
  2203. };
  2204. };
  2205. void device2DSensor::idleMode(){
  2206. #ifdef DEBUG_EXTRA
  2207. LOG("IDLE");
  2208. #endif
  2209. //Reset State
  2210. initWModeFunction( LRF_WM_IDLE );
  2211. switch( getPPStatus() ){
  2212. case STG_PUSH:
  2213. switch( getStage() ) {
  2214. case LRF_WS_INIT:{
  2215. if ( m_bActualDeviceWM != MODE_DETECTOR ) {
  2216. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2217. m_bRequestedDeviceWM = MODE_DETECTOR;
  2218. if( !setMode( MODE_DETECTOR ) ) {
  2219. LOG_ERROR("Fall Back to Disconnected!");
  2220. setWM( LRF_WM_CONNECTION );
  2221. } else transactionWaitResult();
  2222. } else {
  2223. transactionSetResult( TRANSACTION_RESULT_OK );
  2224. };
  2225. break;
  2226. };
  2227. case LRF_WS_STAGE_1:{
  2228. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2229. if( !getState2() ) {
  2230. LOG_ERROR("Fall Back to Disconnected!");
  2231. setWM( LRF_WM_CONNECTION );
  2232. } else transactionWaitResult();
  2233. break;
  2234. };
  2235. case LRF_WS_STAGE_2:{
  2236. setStage( LRF_WS_STAGE_1 );
  2237. DELAY_10MS( 10 ); // 100 ms
  2238. break;
  2239. };
  2240. default: setStage( LRF_WS_INIT ); break;
  2241. };
  2242. break;
  2243. case STG_WAIT: waitStateFunction(); break;
  2244. case STG_POOL: poolStateFunction(); break;
  2245. };
  2246. };
  2247. void device2DSensor::proceedDBCommands(){
  2248. if( DBC_PUSHED_CMD *tCMD = m_pDBC->getNodePushedCMD( m_sNodeData.node_id ) ) {
  2249. m_nProcessingCmdId = tCMD->id;
  2250. m_pDBC->updateNodePushedCMD( m_nProcessingCmdId, DBC_CMD_STARTED );
  2251. switch( tCMD->CMD ) {
  2252. case ARGUS_LRF_PCMD_FULL_RESET:{
  2253. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2254. DELAY_10MS(10); // 100 ms
  2255. if( !doFullReset()) {
  2256. LOG_ERROR("Fall Back to Disconnected!");
  2257. setWM( LRF_WM_CONNECTION );
  2258. } else {
  2259. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2260. updateDataStatus( ARGUS_DS_BUSY );
  2261. transactionWaitResult();
  2262. };
  2263. #ifdef DEBUG_EXTRA
  2264. } else {
  2265. LOG("Wrong Mode! Not DETECTOR!");
  2266. #endif
  2267. };
  2268. break;
  2269. };
  2270. case ARGUS_LRF_PCMD_RESET:{
  2271. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2272. DELAY_10MS(10); // 100 ms
  2273. if( !doReset()) {
  2274. LOG_ERROR("Fall Back to Disconnected!");
  2275. setWM( LRF_WM_CONNECTION );
  2276. } else {
  2277. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2278. updateDataStatus( ARGUS_DS_STUDY );
  2279. transactionWaitResult();
  2280. };
  2281. #ifdef DEBUG_EXTRA
  2282. } else {
  2283. LOG("Wrong Mode! Not DETECTOR!");
  2284. #endif
  2285. };
  2286. break;
  2287. };
  2288. case ARGUS_LRF_PCMD_UPLOAD_FILE:{
  2289. #ifdef DEBUG_EXTRA
  2290. LOG( "CMD UPLOAD" );
  2291. #endif
  2292. DBC_INT_LIST *pUploads = m_pDBC->listLRFUploads( m_sLRF_DATA.id );
  2293. m_sGetFileTransfers.current = 0;
  2294. m_sGetFileTransfers.transfer_ending_mode = GF_EM_DO_NOTHING;
  2295. if ( m_sGetFileTransfers.helpers.size() ) {
  2296. for ( VECTOR_GF_HELPERS::iterator idx = m_sGetFileTransfers.helpers.begin(); idx< m_sGetFileTransfers.helpers.end(); idx++ ){
  2297. if ( (*idx)->fd != NULL ) fclose( (*idx)->fd );
  2298. free( (*idx) );
  2299. };
  2300. m_sGetFileTransfers.helpers.clear();
  2301. };
  2302. if (pUploads != NULL) {
  2303. for( DBC_INT_LIST::iterator idx = pUploads->begin(); idx < pUploads->end(); idx++ ){
  2304. DBC_LRF_UPLOAD_DATA *tData = m_pDBC->getLRFUploadData((*idx));
  2305. if ( tData ) {
  2306. GETFILE_IO_HELPER *tH = NULL;
  2307. tH = (GETFILE_IO_HELPER *) malloc(sizeof(GETFILE_IO_HELPER));
  2308. if ( tH ) {
  2309. memset( tH, 0, sizeof(GETFILE_IO_HELPER) );
  2310. strncpy( tH->destName, tData->fname, 16 );
  2311. strncpy( tH->sourceName, tData->md5, 32 );
  2312. struct stat st;
  2313. char tB[256];
  2314. sprintf( tB, "data/uploads/%s", tH->sourceName );
  2315. stat( tB, &st );
  2316. tH->fileSize = st.st_size;
  2317. tH->state = GF_OP_OK;
  2318. tH->db_id = (*idx);
  2319. tH->index = 0x04;
  2320. if( tData->transfer_mode > m_sGetFileTransfers.transfer_ending_mode ) m_sGetFileTransfers.transfer_ending_mode = tData->transfer_mode;
  2321. m_sGetFileTransfers.helpers.push_back(tH);
  2322. };
  2323. //m_pDBC->updateLRFUpload( (*idx), 1 );
  2324. } else {
  2325. LOG_ERROR( "No Upload Data Fetched From DB!" );
  2326. };
  2327. };
  2328. pUploads->clear();
  2329. delete( pUploads );
  2330. updateDataStatus( ARGUS_DS_BUSY );
  2331. setWM( LRF_WM_FILE );
  2332. };
  2333. break;
  2334. };
  2335. case ARGUS_LRF_PCMD_DRAW:{
  2336. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2337. if( m_sLRF_DATA.data_status == ARGUS_DS_READY ){
  2338. setWM( LRF_WM_BORDER );
  2339. updateDataStatus( ARGUS_DS_BUSY );
  2340. };
  2341. #ifdef DEBUG_EXTRA
  2342. } else {
  2343. LOG("Wrong Mode! Not DETECTOR!");
  2344. #endif
  2345. };
  2346. break;
  2347. };
  2348. //Masks Deletion
  2349. case 75:
  2350. case 76:
  2351. case 77:
  2352. case 78:
  2353. case 79:{
  2354. EVENT_CONTAINER * bEVT = NULL;
  2355. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  2356. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_OP_OFF_MASK, NULL, NULL, tData );
  2357. if( bEVT != NULL ) {
  2358. m_pEventHeap->broadcast( bEVT );
  2359. } else {
  2360. free( tData );
  2361. };
  2362. setWM( LRF_WM_SAVE_MASKS );
  2363. break;
  2364. };
  2365. case 80:{
  2366. EVENT_CONTAINER * bEVT = NULL;
  2367. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  2368. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_OP_NACK_MASK, NULL, NULL, tData );
  2369. if( bEVT != NULL ) {
  2370. m_pEventHeap->broadcast( bEVT );
  2371. } else {
  2372. free( tData );
  2373. };
  2374. setWM( LRF_WM_SAVE_MASKS );
  2375. break;
  2376. };
  2377. case 81:{
  2378. EVENT_CONTAINER * bEVT = NULL;
  2379. TARGET_DATA * tData = prepareTargetData( 0, 0, 0, 0 );
  2380. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_OP_ACK_MASK, NULL, NULL, tData );
  2381. if( bEVT != NULL ) {
  2382. m_pEventHeap->broadcast( bEVT );
  2383. } else {
  2384. free( tData );
  2385. };
  2386. setWM( LRF_WM_SAVE_MASKS );
  2387. break;
  2388. };
  2389. case ARGUS_LRF_PCMD_READ_ALL:{
  2390. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2391. setWM( LRF_WM_SYNC_UP );
  2392. updateDataStatus( ARGUS_DS_BUSY );
  2393. #ifdef DEBUG_EXTRA
  2394. } else {
  2395. LOG("Wrong Mode! Not DETECTOR!");
  2396. #endif
  2397. };
  2398. break;
  2399. };
  2400. case ARGUS_LRF_PCMD_SAVE_SETTINGS_0:{
  2401. setWM( LRF_WM_SAVE_HW );
  2402. break;
  2403. };
  2404. case ARGUS_LRF_PCMD_SAVE_SETTINGS_1:{
  2405. setWM( LRF_WM_SAVE_DETECTION );
  2406. break;
  2407. };
  2408. case ARGUS_LRF_PCMD_SAVE_SETTINGS_2:{
  2409. setWM( LRF_WM_SAVE_MASKS );
  2410. break;
  2411. };
  2412. case ARGUS_LRF_PCMD_SAVE_SETTINGS_3:{
  2413. setWM( LRF_WM_SAVE_EPROM );
  2414. break;
  2415. };
  2416. case ARGUS_LRF_PCMD_MASK_STATUS_SET:{
  2417. setWM( LRF_WM_STATUS_MASK );
  2418. break;
  2419. };
  2420. case ARGUS_LRF_PCMD_SAVE_ALL:
  2421. case ARGUS_LRF_PCMD_UPDATE_ALL:{
  2422. if ( m_bActualDeviceWM == MODE_DETECTOR ) {
  2423. setWM( LRF_WM_SYNC_DOWN );
  2424. updateDataStatus( ARGUS_DS_BUSY );
  2425. #ifdef DEBUG_EXTRA
  2426. } else {
  2427. LOG("Wrong Mode! Not DETECTOR!");
  2428. #endif
  2429. };
  2430. break;
  2431. };
  2432. /*
  2433. case ARGUS_LRF_PCMD_SET_DP_0:{
  2434. if( tCMD->db_cmd ) m_nProcessingCmdId = tCMD->db_cmd; else m_nProcessingCmdId = 0;
  2435. m_nActiveDetectionProfile = 0;
  2436. setWM( ANODE_WM_2D_SET_MASTER_PARAM );
  2437. updateDataStatus( ARGUS_DS_BUSY );
  2438. break;
  2439. };
  2440. */
  2441. case ARGUS_LRF_ROI_ACTIVATION:{
  2442. uint16_t sz = strlen(tCMD->PARAM);
  2443. if( sz ){
  2444. uint16_t AZ, RANGE, WIDTH;
  2445. uint8_t LRFID = 0;
  2446. AZ = atoi(strstr(tCMD->PARAM, ":") + 1) - m_sLRF_DATA.base_shift;
  2447. RANGE = atoi( tCMD->PARAM );
  2448. WIDTH = 8888;
  2449. #ifdef DEBUG_EXTRA
  2450. char tBuff[128];
  2451. sprintf( tBuff, "ROI AZ: %d RANGE: %d WIDTH: %d", AZ, RANGE, WIDTH );
  2452. LOG( tBuff );
  2453. #endif
  2454. EVENT_CONTAINER * bEVT = NULL;
  2455. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH, LRFID );
  2456. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ROI_ACTIVE, NULL, NULL, tData );
  2457. if( bEVT != NULL ) {
  2458. m_pEventHeap->broadcast( bEVT );
  2459. } else {
  2460. free( tData );
  2461. };
  2462. };
  2463. break;
  2464. };
  2465. default:
  2466. char KKK[256];
  2467. sprintf( KKK, "Unknown DBC command[%d]",tCMD->CMD );
  2468. LOG( KKK );
  2469. m_pDBC->updateNodePushedCMD( m_nProcessingCmdId, DBC_CMD_FINISHED );
  2470. };
  2471. free( tCMD );
  2472. };
  2473. };
  2474. bool device2DSensor::validateCommunicationRessource(){
  2475. if( getConnectionStatus() != CS_CONNECTED ){
  2476. #ifdef DEBUG_EXTRA
  2477. LOG("Connection ->Disconnected!");
  2478. #endif
  2479. updateDataStatus( ARGUS_DS_DISCONNECTED );
  2480. setWM( LRF_WM_CONNECTION );
  2481. return false;
  2482. };
  2483. return true;
  2484. };
  2485. //bool device2DSensor::runSequence( COMMAND_SEQUENCE_TYPE SequenceID ){
  2486. // if ( m_eCurrentSequence!= NO_SEQUENCE ) return false;
  2487. // m_bSequenceStep = 0;
  2488. // m_eCurrentSequence = SequenceID;
  2489. // return true;
  2490. //};
  2491. #define SIZE_IDX 1
  2492. #define DEV_ID_IDX 2
  2493. #define CMD_IDX 3
  2494. #define SUB_CMD_IDX 4
  2495. #define DATA_BEGIN_IDX 5
  2496. #define PRINTOUT {for( int z=0; z < Package->m_nSize; z++ ) { \
  2497. sprintf( tBuff, "P[%d]:0x%02X", z, Package->m_pData[z]); \
  2498. LOG( tBuff ); \
  2499. };}
  2500. bool device2DSensor::packetHandler( protocolPackage *Package ){
  2501. uint8_t bCWM = getWM();
  2502. uint8_t bOWM = getOWM();
  2503. LRF_WORK_STAGE ePSTG = getPrevStage();
  2504. uint8_t cDeviceID = Package->m_pData[DEV_ID_IDX];
  2505. if( ( cDeviceID == m_sLRF_DATA.device_id ) || ( m_sLRF_DATA.device_id == 0 ) ) {
  2506. #ifdef DEBUG
  2507. char tBuff[256];
  2508. #ifdef DEBUG_EXTRA
  2509. sprintf( tBuff, "DEV-> Code 0x%02X",Package->m_pData[CMD_IDX] );
  2510. LOG( tBuff );
  2511. #endif
  2512. #endif
  2513. // Have Some Replay from device -> Reset Timeouts
  2514. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT;
  2515. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2516. switch( Package->m_pData[CMD_IDX] ) {
  2517. case CMD_STATE: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2518. case CMD_QUIT: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2519. case CMD_RESET: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2520. case CMD_BORDER:{
  2521. if ((Package->m_pData[SUB_CMD_IDX] & BD_ERRORMASK) == 0x00) {
  2522. uint16_t AZ;
  2523. uint16_t RANGE_A;
  2524. uint16_t RANGE_B;
  2525. AZ = ( ( ( Package->m_pData[SUB_CMD_IDX] & 0x10 ) >> 4 ) << 8 ) | Package->m_pData[5];
  2526. RANGE_A = ( ( ( Package->m_pData[SUB_CMD_IDX] & 0x0C ) >> 2 ) << 8 ) | Package->m_pData[6];
  2527. RANGE_B = ( ( Package->m_pData[SUB_CMD_IDX] & 0x03 ) << 8 ) | Package->m_pData[7];
  2528. if( AZ < 359 ) {
  2529. m_vDrawRanges[m_nCurrentAngle]=( RANGE_A << 16 ) | RANGE_B;
  2530. m_nCurrentAngle = AZ+1;
  2531. if( m_nProcessingCmdId ){
  2532. m_pDBC->updateNodePushedCMD( m_nProcessingCmdId, (( ( 100 * AZ ) / 360 ) - 1 ) | 1 );
  2533. m_nProcessingCmdId = 0;
  2534. };
  2535. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  2536. } else {
  2537. m_nCurrentAngle = 0;
  2538. handleDeviceDraw( 0, (void *)m_vDrawRanges, 360 * sizeof(uint32_t) );
  2539. if( m_nProcessingCmdId ){
  2540. m_pDBC->updateNodePushedCMD(m_nProcessingCmdId, 100 );
  2541. m_nProcessingCmdId = 0;
  2542. };
  2543. transactionSetResult( TRANSACTION_RESULT_OK );
  2544. };
  2545. } else {
  2546. switch((Package->m_pData[SUB_CMD_IDX] & BD_ERRORMASK)){
  2547. case BD_NOTREADY: {
  2548. #ifdef DEBUG_EXTRA
  2549. LOG_ERROR("DNR");
  2550. #endif
  2551. m_nCurrentAngle = 0;
  2552. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  2553. break;
  2554. };
  2555. case BD_ERRORANGLE:{
  2556. #ifdef DEBUG_EXTRA
  2557. LOG_ERROR("EAN");
  2558. #endif
  2559. transactionSetResult( TRANSACTION_RESULT_OK );
  2560. break;
  2561. };
  2562. case BD_ERRORMODE:{
  2563. #ifdef DEBUG_EXTRA
  2564. LOG_ERROR("EMO");
  2565. #endif
  2566. transactionSetResult( TRANSACTION_RESULT_OK );
  2567. break;
  2568. };
  2569. };
  2570. };
  2571. break;
  2572. };
  2573. case CMD_MODE:{
  2574. m_bActualDeviceWM = (E_MODES) Package->m_pData[SUB_CMD_IDX];
  2575. #ifdef DEBUG_EXTRA
  2576. sprintf( tBuff, "Requested Mode:0x%02X Device Mode:0x%02X", m_bRequestedDeviceWM, m_bActualDeviceWM );
  2577. LOG( tBuff );
  2578. #endif
  2579. transactionSetResult( m_bRequestedDeviceWM == m_bActualDeviceWM );
  2580. break;
  2581. };
  2582. case CMD_GETFILE:{
  2583. #ifdef DEBUG_EXTRA
  2584. LOG("GF PKG");
  2585. #endif
  2586. // Sync mode Only
  2587. if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORMASK ) != 0 ){
  2588. if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORMODE ) != 0 ){
  2589. LOG_ERROR("Error: GF-Wrong WM!");
  2590. } else {
  2591. if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORFILE ) != 0 ){
  2592. LOG_ERROR("Error: GF-File Error!");
  2593. } else {
  2594. LOG_ERROR("Error: GF-File gen Error!");
  2595. };
  2596. };
  2597. transactionSetResult( TRANSACTION_RESULT_OK );
  2598. } else {
  2599. if ( ( Package->m_pData[SUB_CMD_IDX] & GF_OP_INDEX ) == m_sGetFileTransfers.helpers[m_sGetFileTransfers.current]->index ) {
  2600. if(( Package->m_pData[SUB_CMD_IDX] & GF_OP_MASK ) == GF_OP_OK ){
  2601. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  2602. } else {
  2603. LOG_ERROR("Error: GF-File Error(index)!");
  2604. transactionSetResult( TRANSACTION_RESULT_OK );
  2605. };
  2606. } else {
  2607. LOG_ERROR("Error: GF-File Error(operation)!");
  2608. transactionSetResult( TRANSACTION_RESULT_OK );
  2609. };
  2610. };
  2611. break;
  2612. };
  2613. case CMD_RESTART: transactionSetResult( TRANSACTION_RESULT_OK ); break;
  2614. case CMD_PARAMETERS:{
  2615. #ifdef DEBUG_EXTRA
  2616. LOG("PARAMETERS");
  2617. sprintf(tBuff, " Stage:\t%d", bCWM );
  2618. LOG(tBuff);
  2619. #endif
  2620. if( bCWM == LRF_WM_SYNC_DOWN ) {
  2621. if( Package->m_pData[SUB_CMD_IDX] == 0x80 ){
  2622. LOG("CMD MASTER PARAMETERS ACK");
  2623. //setStage( LRF_WS_STAGE_8 );
  2624. } else {
  2625. LOG("CMD SLAVE PARAMETERS ACK");
  2626. //setStage( LRF_WS_DELAY );
  2627. };
  2628. } else {
  2629. LOG("READ PARAMS FROM DEVICE");
  2630. LGS_2D_PARAMETERS tParams;
  2631. bool bMaster = true;
  2632. //RaspberyPi - not Intel - cannot copy
  2633. //memcpy( &tParams, Package->m_pData + DATA_BEGIN_IDX, sizeof( LGS_2D_PARAMETERS ) );
  2634. tParams.nOrder = ( Package->m_pData[5] << 8 ) | Package->m_pData[6];
  2635. tParams.nOffset = ( Package->m_pData[7] << 8 ) | Package->m_pData[8];
  2636. tParams.nDelta = ( Package->m_pData[9] << 8 ) | Package->m_pData[10];
  2637. tParams.nWidth = ( Package->m_pData[11] << 8 ) | Package->m_pData[12];
  2638. tParams.nFlip = ( Package->m_pData[13] << 8 ) | Package->m_pData[14];
  2639. tParams.nSun = ( Package->m_pData[15] << 8 ) | Package->m_pData[16];
  2640. tParams.bSST = Package->m_pData[17];
  2641. if( Package->m_pData[SUB_CMD_IDX] != 0x80 ) bMaster = false;
  2642. #ifdef DEBUG
  2643. if( bMaster ) LOG("CMD MASTER PARAMETERS"); else LOG("CMD SLAVE PARAMETERS");
  2644. sprintf(tBuff, " SST:\t%d", tParams.bSST );
  2645. LOG(tBuff);
  2646. sprintf(tBuff, " DELTA:\t%d", tParams.nDelta );
  2647. LOG(tBuff);
  2648. sprintf(tBuff, " Flip:\t%d", tParams.nFlip );
  2649. LOG(tBuff);
  2650. sprintf(tBuff, " OFFSET:\t%d", tParams.nOffset );
  2651. LOG(tBuff);
  2652. sprintf(tBuff, " ORDER:\t%d", tParams.nOrder );
  2653. LOG(tBuff);
  2654. sprintf(tBuff, " SUN:\t%d", tParams.nSun );
  2655. LOG(tBuff);
  2656. sprintf(tBuff, " WIDTH:\t%d", tParams.nWidth );
  2657. LOG(tBuff);
  2658. #endif
  2659. if( m_sLRF_DATA.force_settings ){
  2660. #ifdef DEBUG_EXTRA
  2661. LOG("Force Settings!");
  2662. #endif
  2663. // Check if Settings Are Equal
  2664. PLGS_2D_PARAMETERS chDATA = m_pDBC->getLRFDetectionProfile( m_sLRF_DATA.id, m_nActiveDetectionProfile, bMaster );
  2665. if ( chDATA == NULL ) {
  2666. LOG("No DB Profile!");
  2667. // No Profile in DB -> Set Once!
  2668. m_pDBC->updateLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, bMaster, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
  2669. if( bMaster && m_sNodeData.type == ARGUS_ALS_SENSOR ){
  2670. LOG("Go Get Slave!");
  2671. //setStage( LRF_WS_STAGE_2 );
  2672. } else {
  2673. LOG("Go Get HZ!");
  2674. //setStage( LRF_WS_STAGE_3 );
  2675. };
  2676. } else {
  2677. LOG("Have Settings Go Idle Mode??!");
  2678. //setWM( LRF_WM_IDLE );
  2679. LOG("Go Get HZ!");
  2680. //setStage( LRF_WS_STAGE_3 );
  2681. free( chDATA );
  2682. };
  2683. } else {
  2684. m_pDBC->updateLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, bMaster, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
  2685. if( bMaster && m_sNodeData.type == ARGUS_ALS_SENSOR ){
  2686. LOG("Go Get Slave!");
  2687. //setStage( LRF_WS_STAGE_2 );
  2688. } else {
  2689. LOG("Go Get HZ!");
  2690. //setStage( LRF_WS_STAGE_3 );
  2691. };
  2692. };
  2693. };
  2694. transactionSetResult( TRANSACTION_RESULT_OK );
  2695. break;
  2696. };
  2697. case CMD_GET_RELAY_PARAMETERS:{
  2698. LOG("R-Params!");
  2699. transactionSetResult( TRANSACTION_RESULT_OK );
  2700. break;
  2701. };
  2702. case CMD_GET_SERIAL_NUMBER:{
  2703. uint8_t tSize = Package->m_pData[SUB_CMD_IDX + 1];
  2704. memcpy( m_tSN, Package->m_pData + SUB_CMD_IDX + 2, tSize );
  2705. m_tSN[tSize] = (char)0;
  2706. #ifdef DEBUG_EXTRA
  2707. LOG("CMD_GET_SERIAL_NUMBER");
  2708. LOG( m_tSN );
  2709. #endif
  2710. //Checking SN of actual connected device with one stored in database
  2711. //in case there is new device -> the SN in database will be updated
  2712. if( strncmp( m_sLRF_DATA.serial, m_tSN, tSize ) == 0 ) {
  2713. // Equal
  2714. #ifdef DEBUG_EXTRA
  2715. LOG("SN is OK");
  2716. #endif
  2717. m_bSerialStringValid = true;
  2718. } else {
  2719. LOG_ERROR( m_sLRF_DATA.serial );
  2720. LOG_ERROR("SN is INVALID!");
  2721. LOG_ERROR( m_tSN );
  2722. m_bSerialStringValid = false;
  2723. };
  2724. transactionSetResult( TRANSACTION_RESULT_OK );
  2725. break;
  2726. };
  2727. case CMD_GET_SOFTWARE_VERSION:{
  2728. if ( bCWM == LRF_WM_HANDSHAKE ) {
  2729. uint8_t tSize = Package->m_pData[SUB_CMD_IDX];
  2730. memcpy( m_tSV, Package->m_pData + SUB_CMD_IDX + 1, tSize );
  2731. m_tSV[tSize] = (char)0;
  2732. #ifdef DEBUG_EXTRA
  2733. LOG("CMD_GET_SOFTWARE_VERSION");
  2734. LOG( m_tSV );
  2735. #endif
  2736. if ( strstr(m_tSV,"FD") != NULL ) {
  2737. #ifdef DEBUG_EXTRA
  2738. LOG("Freeze Disabled!");
  2739. #endif
  2740. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, false, false );
  2741. } else {
  2742. if ( strstr(m_tSV,"FF") != NULL ) {
  2743. #ifdef DEBUG_EXTRA
  2744. LOG("TH is Frozen!");
  2745. #endif
  2746. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, true, true );
  2747. } else {
  2748. if ( strstr(m_tSV,"FS") != NULL ) {
  2749. #ifdef DEBUG_EXTRA
  2750. LOG("TH is Study!");
  2751. #endif
  2752. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, true, true );
  2753. } else {
  2754. #ifdef DEBUG_EXTRA
  2755. LOG("No Frost Version!");
  2756. #endif
  2757. m_pDBC->updateLRFFrozenStatus( m_sLRF_DATA.id, false, false );
  2758. };
  2759. };
  2760. };
  2761. if (strncmp(m_sLRF_DATA.version, m_tSV, tSize) == 0) {
  2762. #ifdef DEBUG_EXTRA
  2763. LOG("Version is OK");
  2764. #endif
  2765. m_bVersionStringValid = true;
  2766. } else {
  2767. LOG_ERROR( m_sLRF_DATA.version );
  2768. LOG_ERROR("Version is INVALID!");
  2769. LOG_ERROR( m_tSV );
  2770. m_bVersionStringValid = false;
  2771. };
  2772. if( m_bVersionStringValid && m_bSerialStringValid ) {
  2773. // The Device is OK
  2774. m_pDBC->setNodeOnline( m_sNodeData.node_id, NODE_STATUS_WORK );
  2775. if ( m_bForceSync ) {
  2776. m_bDeviceIsSynced = false; // Do we need it here ?
  2777. //setWM( LRF_WM_SYNC_UP );
  2778. } else {
  2779. m_bDeviceIsSynced = true;
  2780. //setStage( LRF_WS_STAGE_3 ); // Read Mask Statuses
  2781. };
  2782. } else {
  2783. // Will Work even if SN different
  2784. m_bDeviceIsSynced = false;
  2785. //m_bVersionStringValid = true;
  2786. //m_bSerialStringValid = true;
  2787. //m_pDBC->updateLRFSerial( m_sLRF_DATA.id, m_tSN );
  2788. //m_pDBC->updateLRFVerison( m_sLRF_DATA.id, m_tSV );
  2789. m_pDBC->setNodeOnline( m_sNodeData.node_id, NODE_STATUS_WORK );
  2790. //proceed to next stage
  2791. //setWM( LRF_WM_SYNC_UP );
  2792. };
  2793. m_bVersionStringValid = true;
  2794. m_bSerialStringValid = true;
  2795. m_pDBC->updateLRFSerial( m_sLRF_DATA.id, m_tSN );
  2796. m_pDBC->updateLRFVerison( m_sLRF_DATA.id, m_tSV );
  2797. transactionSetResult( TRANSACTION_RESULT_OK );
  2798. }
  2799. break;
  2800. };
  2801. case CMD_UNSUPPORTED:{
  2802. #ifdef DEBUG_EXTRA
  2803. LOG("CMD_UNSUPPORTED!!");
  2804. #endif
  2805. transactionSetResult( TRANSACTION_RESULT_OK );
  2806. break;
  2807. };
  2808. case CMD_FULL_RESET:{
  2809. #ifdef DEBUG_EXTRA
  2810. LOG("Full Reset ACK");
  2811. #endif
  2812. transactionSetResult( TRANSACTION_RESULT_OK );
  2813. break;
  2814. };
  2815. case CMD_STATE_2:{
  2816. // Throw <<Tail>> Package on Wrong Mode
  2817. if ( !( bCWM == LRF_WM_ALARM || bCWM == LRF_WM_IDLE ) ) break;
  2818. #ifdef DEBUG_EXTRA
  2819. //LOG("CMD State 2");
  2820. #endif
  2821. //Parsning sub commagds
  2822. uint8_t cIDX = SUB_CMD_IDX;
  2823. #ifdef DEBUG_EXTRA
  2824. //if( Package->m_nSize > 8 ) {
  2825. // sprintf( tBuff, "Pack Size: %d", Package->m_nSize );
  2826. // LOG( tBuff );
  2827. // PRINTOUT;
  2828. //};
  2829. #endif
  2830. m_bDeviceIsSynced = true; // At this point all data structs must be synced?!
  2831. //setStage( LRF_WS_STAGE_2 );
  2832. while( Package->m_nSize > ( cIDX + 2 ) ) {
  2833. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  2834. switch( Package->m_pData[cIDX+1] ) {
  2835. case 0x00:{
  2836. #ifdef DEBUG_EXTRA
  2837. LOG("SUB PACKAGE - Intruder detected");
  2838. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2839. LOG( tBuff );
  2840. #endif
  2841. uint16_t AZ, RANGE;
  2842. uint32_t WIDTH;
  2843. uint8_t LRFID = 0;
  2844. AZ = (( Package->m_pData[cIDX + 3] >> 3 ) << 8 ) | Package->m_pData[cIDX + 4];
  2845. RANGE = (( Package->m_pData[cIDX + 3] & 0x07 ) << 8 ) | Package->m_pData[cIDX + 5];
  2846. WIDTH = 8888;
  2847. #ifdef DEBUG_EXTRA
  2848. sprintf( tBuff, "AZ: %d RANGE: %d WIDTH: %d", AZ, RANGE, WIDTH );
  2849. LOG( tBuff );
  2850. #endif
  2851. EVENT_CONTAINER * bEVT = NULL;
  2852. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH, LRFID );
  2853. if( m_pTargetFilter != NULL ) {
  2854. if( m_pTargetFilter->validateTarget( m_sNodeData.node_id, tData ) ){
  2855. free( tData );
  2856. //Proceed Statuss of target
  2857. if ( LRF_WM_ALARM != getWM()) {
  2858. setWM(LRF_WM_ALARM);
  2859. };
  2860. cIDX += 6;
  2861. break;
  2862. };
  2863. };
  2864. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_TARGET_2D_WHITE, NULL, NULL, tData );
  2865. if( bEVT != NULL ) {
  2866. m_pEventHeap->broadcast(bEVT);
  2867. } else {
  2868. free( tData );
  2869. };
  2870. if ( LRF_WM_ALARM != getWM()) {
  2871. setWM(LRF_WM_ALARM);
  2872. };
  2873. cIDX += 6;
  2874. break;
  2875. };
  2876. case 0x02:{
  2877. #ifdef DEBUG_EXTRA
  2878. LOG("SUB PACKAGE - Maintenance notification");
  2879. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2880. LOG( tBuff );
  2881. #endif
  2882. EVENT_CONTAINER *bEVT = NULL;
  2883. if ( ( Package->m_pData[cIDX+2] & 0x02 ) == 0x02 ) {
  2884. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_NO_IRQ, NULL, NULL, NULL );
  2885. } else if ( ( Package->m_pData[cIDX+2] & 0x02 ) == 0x04 ) {
  2886. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_NO_ZERO, NULL, NULL, NULL );
  2887. } else if ( ( Package->m_pData[cIDX+2] & 0x02 ) == 0x10 ) {
  2888. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_VOLTAGE, NULL, NULL, NULL );
  2889. };
  2890. if( bEVT != NULL ) {
  2891. m_pEventHeap->broadcast(bEVT);
  2892. };
  2893. cIDX += 3;
  2894. break;
  2895. };
  2896. case 0x03:{
  2897. #ifdef DEBUG_EXTRA
  2898. LOG("SUB PACKAGE - LRF problems notification");
  2899. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2900. LOG( tBuff );
  2901. #endif
  2902. EVENT_CONTAINER *bEVT = NULL;
  2903. if ( ( Package->m_pData[cIDX+3] & 0x01 ) == 0x01 ) {
  2904. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_BROKEN, NULL, NULL, NULL);
  2905. } else if( ( Package->m_pData[cIDX+3] & 0x02 ) == 0x02 ){
  2906. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_ERR_OVERFLOW, NULL, NULL, NULL);
  2907. } else if( ( Package->m_pData[cIDX+3] & 0x04 ) == 0x04 ){
  2908. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_SST_OVERFLOW, NULL, NULL, NULL);
  2909. };
  2910. if( bEVT != NULL ) {
  2911. m_pEventHeap->broadcast(bEVT);
  2912. };
  2913. cIDX += 4;
  2914. break;
  2915. };
  2916. case 0x04:{
  2917. #ifdef DEBUG_EXTRA
  2918. LOG("SUB PACKAGE - Error Angle notification");
  2919. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2920. LOG( tBuff );
  2921. #endif
  2922. EVENT_CONTAINER *bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_ERR_LRF_ANGLE, NULL, NULL, NULL );
  2923. if( bEVT != NULL ) {
  2924. m_pEventHeap->broadcast(bEVT);
  2925. };
  2926. cIDX += 4;
  2927. break;
  2928. };
  2929. case 0x05:{
  2930. #ifdef DEBUG_EXTRA
  2931. LOG("SUB PACKAGE - Flip Complete notification");
  2932. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2933. LOG( tBuff );
  2934. #endif
  2935. // Evt Broadcasting
  2936. broadcastFlip( 0 );
  2937. if( m_sLRF_DATA.data_status != ARGUS_DS_READY ) updateDataStatus( ARGUS_DS_READY );
  2938. if( bCWM == LRF_WM_ALARM ){
  2939. // Clear Alarm Mode to Idle
  2940. bCWM = LRF_WM_IDLE;
  2941. setWM( LRF_WM_IDLE );
  2942. };
  2943. if( m_bInitialFlips ){
  2944. m_bInitialFlips--;
  2945. } else {
  2946. #ifdef DEBUG_EXTRA
  2947. LOG("INITIAL FLIPS ARE DONE!");
  2948. #endif
  2949. if( bCWM == LRF_WM_IDLE ){
  2950. // If not in Allert Mode
  2951. if ( m_sLRF_DATA.auto_draw > 0 ) {
  2952. #ifdef DEBUG_EXTRA
  2953. LOG("Start AutoDraw!");
  2954. #endif
  2955. m_bInitialFlips = m_sLRF_DATA.auto_draw;
  2956. setWM( LRF_WM_BORDER );
  2957. } else {
  2958. #ifdef DEBUG_EXTRA
  2959. LOG("No AutoDraw Defined!");
  2960. #endif
  2961. };
  2962. #ifdef DEBUG_EXTRA
  2963. } else {
  2964. LOG_ERROR("Wrong WM Mode! (possible error in init process)");
  2965. #endif
  2966. };
  2967. };
  2968. cIDX += 5;
  2969. break;
  2970. };
  2971. case 0x06:{
  2972. #ifdef DEBUG_EXTRA
  2973. LOG("SUB PACKAGE - System visibility changes");
  2974. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2975. LOG( tBuff );
  2976. #endif
  2977. EVENT_CONTAINER *bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_LRF_VIS_CHANGED, NULL, NULL, NULL );
  2978. if( bEVT != NULL ) {
  2979. m_pEventHeap->broadcast(bEVT);
  2980. };
  2981. cIDX += 4;
  2982. break;
  2983. };
  2984. case 0x07:{
  2985. #ifdef DEBUG_EXTRA
  2986. LOG("SUB PACKAGE - Intruder with Width detected");
  2987. sprintf( tBuff, "Sub Size: %d", Package->m_pData[cIDX] );
  2988. LOG( tBuff );
  2989. #endif
  2990. uint16_t AZ, RANGE;
  2991. uint32_t WIDTH;
  2992. AZ = (( Package->m_pData[cIDX + 3] >> 3 ) << 8 ) | Package->m_pData[cIDX + 4];
  2993. RANGE = (( Package->m_pData[cIDX + 3] & 0x07 ) << 8 ) | Package->m_pData[cIDX + 5];
  2994. WIDTH = ( Package->m_pData[cIDX + 6] << 24 ) | ( Package->m_pData[cIDX + 7] << 16 ) | ( Package->m_pData[cIDX + 8] << 8 ) | Package->m_pData[cIDX + 9];
  2995. #ifdef DEBUG_EXTRA
  2996. sprintf( tBuff, "AZ: %d RANGE: %d WIDTH: %d", AZ, RANGE, WIDTH );
  2997. LOG( tBuff );
  2998. #endif
  2999. EVENT_CONTAINER * bEVT = NULL;
  3000. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH );
  3001. if( m_pTargetFilter != NULL ) {
  3002. if( m_pTargetFilter->validateTarget( m_sNodeData.node_id, tData ) ){
  3003. free( tData );
  3004. if( m_sLRF_DATA.data_status!= ARGUS_DS_ALARMED ) updateDataStatus( ARGUS_DS_ALARMED );
  3005. //Proceed Statuses Of Target
  3006. //if ( !m_bSessionStarted ) startSession();
  3007. //m_nSleepTime = LGS_ALERT_SLEEP_TIME;
  3008. if ( LRF_WM_ALARM != getWM()) {
  3009. setWM(LRF_WM_ALARM);
  3010. };
  3011. cIDX += 10;
  3012. break;
  3013. };
  3014. };
  3015. bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_TARGET_2D_WHITE, NULL, NULL, tData );
  3016. if( bEVT != NULL ) {
  3017. m_pEventHeap->broadcast( bEVT );
  3018. } else {
  3019. free( tData );
  3020. };
  3021. if( m_sLRF_DATA.data_status!= ARGUS_DS_ALARMED ) updateDataStatus( ARGUS_DS_ALARMED );
  3022. //m_nSleepTime = LGS_ALERT_SLEEP_TIME;
  3023. if ( LRF_WM_ALARM != getWM()) {
  3024. setWM(LRF_WM_ALARM);
  3025. };
  3026. cIDX += 10;
  3027. break;
  3028. };
  3029. default:{
  3030. #ifdef DEBUG_EXTRA
  3031. LOG("SUB PACKAGE - Unhandled One!");
  3032. sprintf( tBuff, "Code: %d Sub Size: %d", Package->m_pData[cIDX+1], Package->m_pData[cIDX] );
  3033. LOG( tBuff );
  3034. #endif
  3035. cIDX += Package->m_pData[cIDX] + 3;
  3036. break;
  3037. };
  3038. };
  3039. };
  3040. //setStage( LRF_WS_STAGE_1 );
  3041. transactionSetResult( TRANSACTION_RESULT_OK );
  3042. break;
  3043. };
  3044. case CMD_GET_HZ_DATA:{
  3045. //HZ_PACKET tPack = (PHZ_PACKET) Package->m_pData + SUB_CMD_IDX;
  3046. switch( Package->m_pData[DATA_BEGIN_IDX] ) {
  3047. case HZIT_EVT_GET_HEADER:{
  3048. HZ_EVT_GET_HEADER pC;
  3049. pC.bSubSize = Package->m_pData[SUB_CMD_IDX];
  3050. pC.bType = Package->m_pData[DATA_BEGIN_IDX];
  3051. pC.bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3052. pC.wPolygonCount = Package->m_pData[DATA_BEGIN_IDX+3];
  3053. pC.wPolygonCount = ( pC.wPolygonCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+2];
  3054. pC.wRayCount = Package->m_pData[DATA_BEGIN_IDX+5];
  3055. pC.wRayCount = ( pC.wRayCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+4];
  3056. pC.dwTypeOn = Package->m_pData[DATA_BEGIN_IDX+9];
  3057. pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+8];
  3058. pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+7];
  3059. pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+6];
  3060. #ifdef DEBUG_EXTRA
  3061. sprintf( tBuff, "Poly Cnt: %d Ray Cnt: %d Status: 0x%08X", pC.wPolygonCount, pC.wRayCount, pC.dwTypeOn );
  3062. LOG( tBuff );
  3063. #endif
  3064. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3065. cleanShadowStructs();
  3066. if( pC.wPolygonCount ){
  3067. m_sShadow.m_nEnabled = pC.dwTypeOn;
  3068. // Set Statuses of Masks ?? Now ??? ->
  3069. for( uint8_t MaskLayer=0; MaskLayer < 5; MaskLayer++ ) {
  3070. uint32_t tMaskID = m_pDBC->getLRFMaskID( m_sLRF_DATA.id , 0, MaskLayer );
  3071. if ( tMaskID ) {
  3072. m_pDBC->setLRFMaskStatus( tMaskID, ( m_sShadow.m_nEnabled & (1<<MaskLayer) ) );
  3073. };
  3074. };
  3075. m_sShadow.pPolygones = (SHADOW_POLY *) calloc(pC.wPolygonCount,sizeof(SHADOW_POLY));
  3076. if ( m_sShadow.pPolygones ) {
  3077. memset( m_sShadow.pPolygones, 0, pC.wPolygonCount*sizeof(SHADOW_POLY) );
  3078. m_sShadow.m_nPolygonCount = pC.wPolygonCount;
  3079. //setStage( LRF_WS_STAGE_4 );
  3080. //setWM(ANODE_WM_2D_GET_SHADOW_POLY_INFO);
  3081. } else {
  3082. LOG_ERROR("Error Alocation Memory foe Shadow!");
  3083. //setWM( LRF_WM_IDLE );
  3084. //updateDataStatus( ARGUS_DS_STUDY );
  3085. };
  3086. } else cleanShadowInDB();
  3087. transactionSetResult( TRANSACTION_RESULT_OK );
  3088. break;
  3089. };
  3090. case HZIT_EVT_GET_POLYGON:{
  3091. uint16_t wPointCount = Package->m_pData[DATA_BEGIN_IDX+4];
  3092. wPointCount = ( wPointCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+3];
  3093. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3094. #ifdef DEBUG_EXTRA
  3095. sprintf( tBuff, "Poly[%d] Info: Points %d type: %d",
  3096. m_sShadowHelper.m_nCurrentPolygon,
  3097. wPointCount, Package->m_pData[DATA_BEGIN_IDX+2]
  3098. );
  3099. LOG( tBuff );
  3100. #endif
  3101. if ( wPointCount ) {
  3102. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].bType = Package->m_pData[DATA_BEGIN_IDX+2];
  3103. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint = (HZ_POINT*)calloc( wPointCount, sizeof(HZ_POINT));
  3104. if ( m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint ) {
  3105. memset(m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint, 0, wPointCount*sizeof(HZ_POINT));
  3106. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount = wPointCount;
  3107. m_sShadowHelper.m_nCurrentPoint = 0;
  3108. //setWM( ANODE_WM_2D_GET_SHADOW_POLY_POINT );
  3109. } else LOG_ERROR("Error Alloc Memory for Polygone points!");
  3110. //setWM( LRF_WM_IDLE ); cant quit now - mat be need read DC
  3111. //};
  3112. //Start Point Transfers or Skeep to Relay Settings
  3113. transactionSetResult( TRANSACTION_RESULT_OK );
  3114. } else {
  3115. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint = NULL;
  3116. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount = 0;
  3117. if( m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ) {
  3118. m_sShadowHelper.m_nCurrentPolygon++;
  3119. // Request next polygone
  3120. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3121. } else {
  3122. // Proceed Read of the points (no points -> Skeep )
  3123. transactionSetResult( TRANSACTION_RESULT_OK );
  3124. };
  3125. };
  3126. break;
  3127. };
  3128. case HZIT_EVT_GET_POLYGON_POINT:{
  3129. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX = Package->m_pData[DATA_BEGIN_IDX+3];
  3130. 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];
  3131. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY = Package->m_pData[DATA_BEGIN_IDX+5];
  3132. 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];
  3133. #ifdef DEBUG_EXTRA
  3134. sprintf( tBuff, "PolyPoint[%d] of %d X: %d Y: %d",
  3135. m_sShadowHelper.m_nCurrentPoint,
  3136. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount,
  3137. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX,
  3138. m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY
  3139. );
  3140. LOG( tBuff );
  3141. #endif
  3142. m_sShadowHelper.m_nCurrentPoint++;
  3143. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3144. if( m_sShadowHelper.m_nCurrentPoint < m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount ) {
  3145. //LOG("Back To Read Nex Poly Point!");
  3146. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3147. //setStage( LRF_WS_STAGE_5 );
  3148. //setWM( ANODE_WM_2D_GET_SHADOW_POLY_POINT );
  3149. } else {
  3150. #ifdef DEBUG_EXTRA
  3151. LOG("Done Load Poly Points");
  3152. #endif
  3153. transactionSetResult( TRANSACTION_RESULT_OK );
  3154. m_sShadowHelper.m_nCurrentPolygon++;
  3155. if(m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ) {
  3156. //setStage( LRF_WS_STAGE_4 );
  3157. //setWM( ANODE_WM_2D_GET_SHADOW_POLY_INFO );
  3158. transactionSetResult( TRANSACTION_RESULT_OK );
  3159. } else {
  3160. saveShadowToDB();
  3161. #ifdef DEBUG_EXTRA
  3162. //rasterizeShadow();
  3163. //makeShadowPic("shadow.png");
  3164. #endif
  3165. setWM( LRF_WM_IDLE );
  3166. updateDataStatus( ARGUS_DS_READY );
  3167. };
  3168. };
  3169. break;
  3170. };
  3171. case HZIT_EVT_GET_RAY:{
  3172. HZ_EVT_GET_RAY pC;
  3173. LOG("RAY!");
  3174. setWM( LRF_WM_IDLE );
  3175. break;
  3176. };
  3177. case HZIT_EVT_GET_RAY_LINE:{
  3178. HZ_EVT_GET_RAY_LINE pC;
  3179. LOG("RAY LINE!");
  3180. setWM( LRF_WM_IDLE );
  3181. break;
  3182. };
  3183. case HZIT_EVT_ERROR:{
  3184. HZ_EVT_ERROR pC;
  3185. LOG("ERROR GET SHADOW PING_PONG!");
  3186. setWM( LRF_WM_IDLE );
  3187. break;
  3188. };
  3189. };
  3190. break;
  3191. };
  3192. case CMD_SET_HZ_DATA:{
  3193. #ifdef DEBUG_EXTRA
  3194. sprintf( tBuff,"Replay Set HZ Code: 0x%02X", Package->m_pData[DATA_BEGIN_IDX] );
  3195. LOG( tBuff );
  3196. #endif
  3197. m_sShadowHelper.m_bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
  3198. switch( Package->m_pData[DATA_BEGIN_IDX] ) {
  3199. case HZIT_EVT_SET_HEADER:
  3200. #ifdef DEBUG_EXTRA
  3201. LOG("Header OK");
  3202. #endif
  3203. transactionSetResult( TRANSACTION_RESULT_OK );
  3204. break;
  3205. case HZIT_EVT_SET_POLYGON:
  3206. #ifdef DEBUG_EXTRA
  3207. LOG("Poligon Added OK");
  3208. #endif
  3209. transactionSetResult( TRANSACTION_RESULT_OK );
  3210. break;
  3211. case HZIT_EVT_SET_POLYGON_POINT:
  3212. #ifdef DEBUG_EXTRA
  3213. LOG("PolyPoint Added OK");
  3214. #endif
  3215. m_sShadowHelper.m_nCurrentPoint++;
  3216. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3217. break;
  3218. case HZIT_EVT_SET_RAY:
  3219. m_sShadowHelper.m_nCurrentRay = 0;
  3220. #ifdef DEBUG_EXTRA
  3221. LOG("Rey Added OK");
  3222. #endif
  3223. transactionSetResult( TRANSACTION_RESULT_OK );
  3224. break;
  3225. case HZIT_EVT_SET_RAY_LINE:
  3226. #ifdef DEBUG_EXTRA
  3227. LOG("Ray Line Added OK");
  3228. #endif
  3229. m_sShadowHelper.m_nCurrentRay++;
  3230. transactionSetResult( TRANSACTION_RESULT_REPEAT );
  3231. break;
  3232. case HZIT_EVT_SET_DONE:
  3233. #ifdef DEBUG_EXTRA
  3234. LOG("Cleanup!");
  3235. #endif
  3236. memset( &m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER) );
  3237. m_bOpRetryCnt = 128;
  3238. updateDataStatus( ARGUS_DS_READY );
  3239. transactionSetResult( TRANSACTION_RESULT_OK );
  3240. break;
  3241. case HZIT_EVT_ERROR:{
  3242. HZ_EVT_ERROR pC;
  3243. #ifdef DEBUG_EXTRA
  3244. LOG_ERROR("ERROR SET SHADOW PING_PONG!");
  3245. #endif
  3246. //setWM( ANODE_WM_2D_PING );
  3247. memset( &m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER) );
  3248. //setStage( LRF_WS_STAGE_7 );
  3249. updateDataStatus( ARGUS_DS_READY );
  3250. transactionSetResult( TRANSACTION_RESULT_OK );
  3251. break;
  3252. };
  3253. };
  3254. break;
  3255. };
  3256. case CMD_SET_HZ_ENABLE:{
  3257. transactionSetResult( TRANSACTION_RESULT_OK );
  3258. break;
  3259. };
  3260. case CMD_GET_ACTIVE_PROFILE:{
  3261. //if ( ePSTG == LRF_WS_INIT ) {
  3262. //m_bMultiProfileSupported = true;
  3263. m_nActiveDetectionProfile = 0;
  3264. //setStage( LRF_WS_STAGE_1 );
  3265. //};
  3266. transactionSetResult( TRANSACTION_RESULT_OK );
  3267. break;
  3268. };
  3269. };
  3270. return true;
  3271. #ifdef DEBUG_EXTRA
  3272. } else {
  3273. LOG("Not Mine Package!");
  3274. #endif
  3275. };
  3276. return false;
  3277. };
  3278. #undef PRINTOUT
  3279. /*
  3280. bool device2DSensor::downloadFile( CSTR fname ){
  3281. if( fname == NULL ) return false;
  3282. uint8_t len = strlen( fname );
  3283. if( len == 0 ) return false;
  3284. if( m_bSupportedFS ) {
  3285. m_sOutFSData.nCommand = FS_CMD_SEND_CMD;
  3286. m_sOutFSData.sendcmd.nOrder = 0;
  3287. m_sOutFSData.sendcmd.nLast = 1;
  3288. m_sOutFSData.sendcmd.nPosition = 0;
  3289. m_sOutFSData.sendcmd.nSubSize = len + 4; // Size of FS_PACK
  3290. //Header
  3291. m_sOutFSData.sendcmd.pSubBuffer[0] = LG_FS_OP_OPEN_FILE;
  3292. m_sOutFSData.sendcmd.pSubBuffer[1] = len + 1; //Size of FS_PATH
  3293. m_sOutFSData.sendcmd.pSubBuffer[2] = 0x00;
  3294. // FS_PATH Begins here
  3295. m_sOutFSData.sendcmd.pSubBuffer[3] = len;
  3296. memcpy( &m_sOutFSData.sendcmd.pSubBuffer[4], fname, len );
  3297. if( sendFS_package( &m_sOutFSData ) ){
  3298. return true;
  3299. };
  3300. };
  3301. return false;
  3302. };
  3303. */
  3304. TARGET_DATA *device2DSensor::prepareTargetData( uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID ){
  3305. TARGET_DATA* tVal = NULL;
  3306. systemAnchor* tSystem = systemAnchor::getInstance();
  3307. if( tSystem != NULL ) {
  3308. tVal = (TARGET_DATA*)malloc(sizeof(TARGET_DATA));
  3309. if (tVal != NULL) {
  3310. uint16_t cX, cY;
  3311. memset( tVal, 0, sizeof(TARGET_DATA) );
  3312. tVal->source_position.lat = m_oPosition.getLat();
  3313. tVal->source_position.lon = m_oPosition.getLon();
  3314. tVal->source_position.alt = m_oPosition.getAlt();
  3315. tVal->local_target.r = m_sLRF_DATA.max_range / 2048.0f * (float)RANGE;
  3316. AZ = ( AZ + m_sLRF_DATA.base_shift ) % 6000;
  3317. //tVal->local_target.fi = 360.0f - (360.0f / 6000.0f) * (float) AZ;
  3318. tVal->local_target.tetta = 90.0f;
  3319. tVal->local_target.fi = (360.0f / 6000.0f) * (float) AZ;
  3320. tVal->area = WIDTH;
  3321. tVal->lrf_id = LRFID;//0; // Always Master?
  3322. tVal->digital = RANGE;
  3323. // local - C3D_SPH_DEGREES
  3324. // system - C3D_DECART
  3325. // global - C3D_WGS84_LOC
  3326. tSystem->convertToSystem( &m_oPosition, tVal->local_target, tVal->system_target );
  3327. if ( tSystem->beLocal() ) {
  3328. tVal->global_target.lat = tVal->system_target.y;
  3329. tVal->global_target.lon = tVal->system_target.x;
  3330. tVal->global_target.alt = tVal->system_target.z;
  3331. } else {
  3332. //ToDo: Fix Convert!
  3333. tSystem->convertToGlobal(&m_oPosition, tVal->local_target, tVal->global_target);
  3334. //tSystem->convertToGlobal( &m_oPosition, tVal->system_target, tVal->global_target );
  3335. };
  3336. #ifdef DEBUG_EXTRA
  3337. char tB[128];
  3338. sprintf(tB, "tCords Local: %0.3f %0.3f %0.3f", tVal->local_target.r, tVal->local_target.fi, tVal->local_target.tetta );
  3339. LOG( tB );
  3340. sprintf(tB, "tCords System: %0.3f %0.3f %0.3f", tVal->system_target.x, tVal->system_target.y, tVal->system_target.z );
  3341. LOG( tB );
  3342. sprintf(tB, "tCords Global: %0.3f %0.3f %0.3f", tVal->global_target.lat, tVal->global_target.lon, tVal->global_target.alt );
  3343. LOG( tB );
  3344. #endif
  3345. };
  3346. };
  3347. return tVal;
  3348. };
  3349. void device2DSensor::simulateTarget( void ){
  3350. uint16_t AZ, RANGE;
  3351. uint32_t WIDTH;
  3352. AZ = uint16_t ( rand() * ( 6000.0f /(float) RAND_MAX ));
  3353. RANGE = uint16_t ( rand() * ( 2048.0f /(float) RAND_MAX ));
  3354. WIDTH = 4000;
  3355. TARGET_DATA * tData = prepareTargetData( AZ, RANGE, WIDTH );
  3356. if( tData != NULL ){
  3357. if( m_pTargetFilter != NULL ) {
  3358. if( !m_pTargetFilter->validateTarget( m_sNodeData.node_id, tData ) ){
  3359. free( tData );
  3360. return;
  3361. };
  3362. };
  3363. EVENT_CONTAINER * bEVT = createBasicEvent( m_sNodeData.node_id, m_eEventClass, EVT_TARGET_2D_WHITE, NULL, NULL, tData );
  3364. if (bEVT != NULL) {
  3365. m_pEventHeap->broadcast( bEVT );
  3366. };
  3367. };
  3368. };
  3369. /*
  3370. void device2DSensor::saveRawDrawData( uint16_t alngles ){
  3371. CSTR tID = getUniqID_MD5();
  3372. if( tID!= NULL ) {
  3373. char cPATH[256];
  3374. FILE *fp;
  3375. sprintf( cPATH, "data/device_draws/%s.raw", tID );
  3376. fp = fopen( cPATH, "wb");
  3377. if( fp != NULL ) {
  3378. uint32_t tVal = alngles;
  3379. fwrite( &tVal, 4, 1, fp );
  3380. fwrite( m_vDrawRanges, 4, alngles, fp );
  3381. fclose( fp );
  3382. m_pDBC->addLRFDraw( m_sNodeData.node_id, alngles, tID );
  3383. } else {
  3384. LOG_ERROR("Cannot open DRAW file!");
  3385. }
  3386. free( tID );
  3387. };
  3388. };
  3389. */
  3390. inline int DBL_CMP( const double& a, const double& b, const double quality = 1e-10 ){
  3391. if( fabs(a - b) <= fabs(quality) ) return 0;
  3392. if( a > b ) return 1;
  3393. return -1;
  3394. };
  3395. typedef struct S_VERTEX{
  3396. double x, y, r;
  3397. BOOL f;
  3398. int n;
  3399. }VERTEX, *PVERTEX;
  3400. typedef struct S_SEGMENT{
  3401. int pPoints[2];
  3402. int nIndex;
  3403. }SEGMENT, *PSEGMENT;
  3404. typedef struct S_SEGMENTS{
  3405. PVERTEX pPoints;
  3406. int nCount;
  3407. }SEGMENTS, *PSEGMENTS;
  3408. BOOL CrossProduct( PVERTEX ln0, PVERTEX ln1, PVERTEX pCross, bool fCheck0 = true, bool fCheck1 = true ){
  3409. #undef B0
  3410. double A0, A1, B0, B1, X, Y;
  3411. if( DBL_CMP(ln0[0].x, ln0[1].x) == 0 ){
  3412. A0 = DBL_MAX;
  3413. B0 = ln0[0].x;
  3414. } else {
  3415. A0 = (ln0[0].y - ln0[1].y) / (ln0[0].x - ln0[1].x);
  3416. B0 = ln0[0].y - A0 * ln0[0].x;
  3417. };
  3418. if(DBL_CMP(ln1[0].x , ln1[1].x) == 0){
  3419. A1 = DBL_MAX;
  3420. B1 = ln1[0].x;
  3421. } else {
  3422. A1 = (ln1[0].y - ln1[1].y) / (ln1[0].x - ln1[1].x);
  3423. B1 = ln1[0].y - A1 * ln1[0].x;
  3424. };
  3425. if(A0 == DBL_MAX){
  3426. if(A1 == DBL_MAX) return FALSE;
  3427. X = B0;
  3428. Y = A1 * X + B1;
  3429. } else {
  3430. if(A1 == DBL_MAX) X = B1;
  3431. else {
  3432. if(DBL_CMP( A1, A0 ) != 0) X = (B0 - B1) / (A1 - A0); else return FALSE;
  3433. };
  3434. Y = A0 * X + B0;
  3435. };
  3436. double y = Y, x = X;
  3437. if( fCheck0 ){
  3438. double x0 = ln0[0].x, x1 = ln0[1].x;
  3439. double y0 = ln0[0].y, y1 = ln0[1].y;
  3440. if(DBL_CMP(y0, y1) == -1 && (DBL_CMP(y0, y) == 1 || DBL_CMP(y, y1) == 1)) return FALSE;
  3441. if(DBL_CMP(y0, y1) == 1 && (DBL_CMP(y0, y) == -1 || DBL_CMP(y, y1) == -1)) return FALSE;
  3442. if(DBL_CMP(x0, x1) == -1 && (DBL_CMP(x0, x) == 1 || DBL_CMP(x, x1) == 1)) return FALSE;
  3443. if(DBL_CMP(x0, x1) == 1 && (DBL_CMP(x0, x) == -1 || DBL_CMP(x, x1) == -1)) return FALSE;
  3444. };
  3445. if( fCheck1 ){
  3446. double x0 = ln1[0].x, x1 = ln1[1].x;
  3447. double y0 = ln1[0].y, y1 = ln1[1].y;
  3448. if(DBL_CMP(y0, y1) == -1 && (DBL_CMP(y0, y) == 1 || DBL_CMP(y, y1) == 1)) return FALSE;
  3449. if(DBL_CMP(y0, y1) == 1 && (DBL_CMP(y0, y) == -1 || DBL_CMP(y, y1) == -1)) return FALSE;
  3450. if(DBL_CMP(x0, x1) == -1 && (DBL_CMP(x0, x) == 1 || DBL_CMP(x, x1) == 1)) return FALSE;
  3451. if(DBL_CMP(x0, x1) == 1 && (DBL_CMP(x0, x) == -1 || DBL_CMP(x, x1) == -1)) return FALSE;
  3452. };
  3453. pCross->x = X;
  3454. pCross->y = Y;
  3455. return TRUE;
  3456. };
  3457. BOOL PtInLine( PVERTEX ln, VERTEX& p ){
  3458. double A, B;
  3459. if(DBL_CMP(ln[0].x, ln[1].x) == 0){
  3460. A = DBL_MAX;
  3461. B = ln[0].x;
  3462. } else {
  3463. A = (ln[0].y - ln[1].y) / (ln[0].x - ln[1].x);
  3464. B = ln[0].y - A * ln[0].x;
  3465. };
  3466. if(A == DBL_MAX) {
  3467. if( DBL_CMP(p.x, B) == 0) return TRUE;
  3468. } else {
  3469. if(DBL_CMP(p.x * A + B, p.y) == 0) return TRUE;
  3470. };
  3471. return FALSE;
  3472. };
  3473. int comparePoints( const void *arg1, const void *arg2 ){
  3474. if(((PVERTEX)arg1)->r > ((PVERTEX)arg2)->r) return +1;
  3475. if(((PVERTEX)arg1)->r < ((PVERTEX)arg2)->r) return -1;
  3476. return 0;
  3477. };
  3478. void AddPointToSegment( PSEGMENTS pSegments, int nIndex, PVERTEX pPoint){
  3479. PVERTEX pNew = new VERTEX[pSegments[nIndex].nCount + 1];
  3480. memcpy( pNew, pSegments[nIndex].pPoints, sizeof(VERTEX) * pSegments[nIndex].nCount );
  3481. memcpy( pNew + pSegments[nIndex].nCount, pPoint, sizeof(VERTEX));
  3482. if(pSegments[nIndex].pPoints) delete pSegments[nIndex].pPoints;
  3483. pSegments[nIndex].pPoints = pNew;
  3484. pSegments[nIndex].nCount++;
  3485. };
  3486. void StickSegments( PSEGMENTS pSegments, int nIndex ){
  3487. if( pSegments[nIndex].nCount ){
  3488. qsort( pSegments[nIndex].pPoints, pSegments[nIndex].nCount, sizeof(VERTEX), comparePoints );
  3489. PVERTEX pTemp = new VERTEX[pSegments[nIndex].nCount];
  3490. PVERTEX pPoints = pSegments[nIndex].pPoints;
  3491. int f, nT = 0;
  3492. pTemp[nT++] = pPoints[0];
  3493. f = pPoints[0].f;
  3494. for(int i = 1; i < pSegments[nIndex].nCount;){
  3495. f += pPoints[i].f;
  3496. if(f == 0){
  3497. pTemp[nT++] = pPoints[i++];
  3498. if(i < pSegments[nIndex].nCount){
  3499. pTemp[nT++] = pPoints[i];
  3500. f = pPoints[i++].f;
  3501. };
  3502. } else i++;
  3503. };
  3504. if(pSegments[nIndex].pPoints) delete[] pSegments[nIndex].pPoints;
  3505. pSegments[nIndex].pPoints = new VERTEX[nT];
  3506. memcpy( pSegments[nIndex].pPoints, pTemp, sizeof(VERTEX) * nT );
  3507. pSegments[nIndex].nCount = nT;
  3508. if(pTemp) delete[] pTemp;
  3509. };
  3510. };
  3511. int compareSegments(const void *arg1, const void *arg2){
  3512. if(((PSEGMENT)arg1)->nIndex > ((PSEGMENT)arg2)->nIndex) return +1;
  3513. if(((PSEGMENT)arg1)->nIndex < ((PSEGMENT)arg2)->nIndex) return -1;
  3514. if(((PSEGMENT)arg1)->pPoints[0] > ((PSEGMENT)arg2)->pPoints[0]) return +1;
  3515. if(((PSEGMENT)arg1)->pPoints[0] < ((PSEGMENT)arg2)->pPoints[0]) return -1;
  3516. return 0;
  3517. };
  3518. bool pnpoly( uint16_t nvert, float *vertx, float *verty, float testx, float testy ){
  3519. bool c = false;
  3520. 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;
  3521. return c;
  3522. };
  3523. bool device2DSensor::PtInPolygons( TEST_POINT& point, uint8_t F ){
  3524. for( uint16_t i = 0; i < m_sShadow.m_nPolygonCount; i++)
  3525. if( F == m_sShadow.pPolygones[i].bType )
  3526. if ( PtInPolygon( m_sShadow.pPolygones[i], point ) ) return true;
  3527. return false;
  3528. };
  3529. bool device2DSensor::PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point ){
  3530. if( Poly.wCount < 3 ) return false;
  3531. float *vertx = (float *) calloc( Poly.wCount, sizeof(float));
  3532. float *verty = (float *) calloc( Poly.wCount, sizeof(float));
  3533. for( int z =0; z < Poly.wCount; z++ ) {
  3534. vertx[z] = (float)Poly.pPoint[z].wX;
  3535. verty[z] = (float)Poly.pPoint[z].wY;
  3536. };
  3537. if ( pnpoly( Poly.wCount, vertx, verty, point.x, point.y )){
  3538. free(vertx);
  3539. free(verty);
  3540. return true;
  3541. };
  3542. free(vertx);
  3543. free(verty);
  3544. return false;
  3545. };
  3546. bool device2DSensor::rasterizeShadow(){
  3547. const double TWO_PI = 6.2831853071796;
  3548. const double ONE_PI = 3.1415926535898;
  3549. bool masked[6] = {0};
  3550. uint16_t cMin[6] = {0};
  3551. uint16_t cMax[6] = {0};
  3552. double k = TWO_PI /((double)MAX_2D_SHADOW_RAY_LINES );
  3553. double z_shift = 2.0 * k * ((double)m_sLRF_DATA.base_shift );
  3554. for( uint16_t i=0; i < MAX_2D_SHADOW_RAY_LINES; i++ ) {
  3555. double ca = TWO_PI - ( k * i + z_shift ); // must be checked sign!!
  3556. double sin_val = sin( ca );
  3557. double cos_val = cos( ca );
  3558. memset( &masked, 0, 5*sizeof( bool ) );
  3559. memset( &cMin, 0, 5*sizeof( uint16_t ) );
  3560. memset( &cMax, 0, 5*sizeof( uint16_t ) );
  3561. // 1 - to close polygones that going outside
  3562. for( uint16_t range_digital = 0; range_digital < 2047; range_digital++ ) {
  3563. TEST_POINT TP;
  3564. TP.x = (float)(cos_val*((double)range_digital));
  3565. TP.y = (float)(sin_val*((double)range_digital));
  3566. for( uint8_t z=0; z < 6; z++ ){ // Mask ID
  3567. if( masked[z] ) {
  3568. if(!PtInPolygons( TP, z )){
  3569. masked[z] = false;
  3570. cMax[z] = range_digital;
  3571. if( cMin[z] != cMax[z] ) { //Filter Null Masks
  3572. 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));
  3573. if ( m_sShadow.ray_lines[i].rays == NULL ) {
  3574. LOG_ERROR("Ray realloc failure!");
  3575. m_sShadow.ray_lines[i].nCount = 0;
  3576. return false;
  3577. };
  3578. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMin = cMin[z];
  3579. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMax = cMax[z];
  3580. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].bType = z;
  3581. m_sShadow.ray_lines[i].nCount++;
  3582. #ifdef DEBUG_EXTRA
  3583. char tB[128];
  3584. 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 );
  3585. LOG(tB);
  3586. #endif
  3587. }
  3588. };
  3589. } else {
  3590. if(PtInPolygons( TP, z )){
  3591. masked[z] = true;
  3592. cMin[z] = range_digital;
  3593. };
  3594. };
  3595. };
  3596. };
  3597. // to clode poligones that goed outside
  3598. for( uint8_t z=0; z < 5; z++ ){
  3599. if ( masked[z] ) {
  3600. masked[z] = false;
  3601. 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) );
  3602. if ( m_sShadow.ray_lines[i].rays == NULL ) {
  3603. LOG_ERROR("Ray realloc failure!");
  3604. m_sShadow.ray_lines[i].nCount = 0;
  3605. return false;
  3606. };
  3607. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMin = cMin[z];
  3608. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMax = 2047;
  3609. m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].bType = z;
  3610. m_sShadow.ray_lines[i].nCount++;
  3611. #ifdef DEBUG_EXTRA
  3612. char tB[128];
  3613. sprintf( tB ,"Ray: Mask[%d] angle[%d] min[%d] max[%d]", z, i, cMin[z], 2047 );
  3614. LOG(tB);
  3615. #endif
  3616. };
  3617. };
  3618. };
  3619. return true;
  3620. };
  3621. bool device2DSensor::cleanShadowInDB( void ){
  3622. for( uint8_t MaskLayer=0; MaskLayer < 5; MaskLayer++ ) {
  3623. if( uint32_t tMaskID = m_pDBC->getLRFMaskID( m_sLRF_DATA.id , 0, MaskLayer ) ) m_pDBC->cleanLRFMask( tMaskID, true );
  3624. };
  3625. };
  3626. bool device2DSensor::loadShadowFromDB( void ){
  3627. };
  3628. bool device2DSensor::saveShadowToDB( void ){
  3629. for( uint8_t MaskLayer=0; MaskLayer < 5; MaskLayer++ ) {
  3630. #ifdef DEBUG_EXTRA
  3631. LOG( "Adding Layer To DATABASE");
  3632. #endif
  3633. uint32_t tMaskID = m_pDBC->getLRFMaskID( m_sLRF_DATA.id , 0, MaskLayer );
  3634. if( tMaskID ) {
  3635. #ifdef DEBUG_EXTRA
  3636. LOG("Have Old Mask -> Delete Old!");
  3637. #endif
  3638. m_pDBC->cleanLRFMask( tMaskID, true );
  3639. tMaskID = 0;
  3640. };
  3641. for( uint8_t i = 0; i < m_sShadow.m_nPolygonCount; i++ ){
  3642. if( m_sShadow.pPolygones[i].bType == MaskLayer ){
  3643. if( m_sShadow.pPolygones[i].pPoint ){
  3644. if( tMaskID == 0 ) {
  3645. #ifdef DEBUG_EXTRA
  3646. LOG("No Mask -> Create One!");
  3647. #endif
  3648. tMaskID = m_pDBC->addLRFMask( m_sLRF_DATA.id, 0, MaskLayer );
  3649. };
  3650. if( tMaskID ) {
  3651. uint32_t tPolyID = 0;
  3652. #ifdef DEBUG_EXTRA
  3653. LOG("Creating New Polygone!");
  3654. #endif
  3655. switch( MaskLayer ) {
  3656. case 0: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 255, 0, 255); break;
  3657. case 1: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 255, 255, 0); break;
  3658. case 2: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 255, 255); break;
  3659. case 3: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 255, 0); break;
  3660. case 4: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 0, 255); break;
  3661. default: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 0, 0 ); break;
  3662. };
  3663. if ( tPolyID ) {
  3664. #ifdef DEBUG_EXTRA
  3665. LOG("Add Points to a created Polygone!");
  3666. #endif
  3667. for ( uint16_t k=0;k < m_sShadow.pPolygones[i].wCount; k++ ) {
  3668. m_pDBC->addLRFMaskPolygonePoint(
  3669. tPolyID,
  3670. m_sShadow.pPolygones[i].pPoint[k].wX,
  3671. m_sShadow.pPolygones[i].pPoint[k].wY
  3672. );
  3673. };
  3674. } else LOG("No Polygone Created !!!!");
  3675. } else LOG("No Mask Created !!!!");
  3676. };
  3677. };
  3678. };
  3679. if ( tMaskID ) {
  3680. m_pDBC->setLRFMaskStatus( tMaskID, ( m_sShadow.m_nEnabled & (1<<MaskLayer) ) );
  3681. };
  3682. };
  3683. };
  3684. #ifdef DEBUG
  3685. void device2DSensor::makeShadowPic( CSTR picname ){
  3686. cv::Scalar zone_colors[6] = { cv::Scalar(0, 0, 255),
  3687. cv::Scalar(255, 20, 255),
  3688. cv::Scalar(0, 255, 255),
  3689. cv::Scalar(0, 255, 0),
  3690. cv::Scalar(255, 0, 0),
  3691. cv::Scalar(120, 120, 120)
  3692. };
  3693. const double TWO_PI = 6.2831853071796;
  3694. double k = TWO_PI /((double)MAX_2D_SHADOW_RAY_LINES );
  3695. double z_shift = k * ((double)m_sLRF_DATA.base_shift );
  3696. cv::Mat tPic(512, 512, CV_8UC3, cv::Scalar(20, 20, 20));
  3697. double cx = 256.0;
  3698. double cy = 256.0;
  3699. double r = 255.0/2048.0;
  3700. for ( int i = 0; i < 360; i++ ) {
  3701. double ca = k * i + z_shift; // must be checked sign!!
  3702. double sin_val = sin( ca );
  3703. double cos_val = cos( ca );
  3704. cv::line( tPic, cv::Point( cx, cy ), cv::Point( cx+cos_val*256, cy+sin_val*256 ), zone_colors[5], 1, cv::LINE_AA );
  3705. if( m_sShadow.ray_lines[i].nCount ){
  3706. for ( int z=0; z < m_sShadow.ray_lines[i].nCount; z++ ) {
  3707. int r1 = m_sShadow.ray_lines[i].rays[z].nMin;
  3708. int r2 = m_sShadow.ray_lines[i].rays[z].nMax;
  3709. cv::Scalar color = zone_colors[m_sShadow.ray_lines[i].rays[z].bType];
  3710. int x1 = cx+(cos_val*r1*r);
  3711. int y1 = cy+(sin_val*r1*r);
  3712. int x2 = cx+(cos_val*r2*r);
  3713. int y2 = cy+(sin_val*r2*r);
  3714. cv::line(tPic, cv::Point(x1, y1), cv::Point( x2, y2), color, 1, cv::LINE_AA);
  3715. };
  3716. };
  3717. };
  3718. vector<int> compression_params;
  3719. compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
  3720. compression_params.push_back(9);
  3721. //compression_params.push_back( cv::IMWRITE_JPEG_QUALITY );
  3722. //compression_params.push_back( m_sEmbedVideoData.compression_quality );
  3723. vector<uchar> buf;
  3724. cv::imencode( ".png", tPic, buf, compression_params );
  3725. FILE *fd;
  3726. fd = fopen( picname, "wb");
  3727. if ( fd ) {
  3728. fwrite( buf.data(), 1, buf.size(), fd );
  3729. fclose( fd );
  3730. };
  3731. buf.clear();
  3732. };
  3733. #endif
  3734. void device2DSensor::waitStateFunction( LRF_WORK_STAGE boboStage ){
  3735. if( m_bTimeOutCounter ){
  3736. m_bTimeOutCounter--;
  3737. DELAY_10MS( LGS_DEFAULT_WS_TIME );
  3738. } else {
  3739. if( m_bOpRetryCnt ){
  3740. #ifdef DEBUG_EXTRA
  3741. LOG("COM ATTEMPT RECOVER");
  3742. #endif
  3743. m_bOpRetryCnt--;
  3744. m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
  3745. registerCommError( false );
  3746. LRF_WORK_STAGE pS = getPrevStage();
  3747. if ( pS != LRF_WS_INIT ) {
  3748. setStage( pS, false );
  3749. } else {
  3750. if ( boboStage != LRF_WS_INIT ) {
  3751. setStage( boboStage, false );
  3752. } else {
  3753. setWM( LRF_WM_CONNECTION );
  3754. return;
  3755. };
  3756. };
  3757. } else {
  3758. LOG_ERROR("Communication Wait State TO!");
  3759. registerCommError( true );
  3760. //setStage( boboStage );
  3761. setWM( LRF_WM_CONNECTION );
  3762. return;
  3763. };
  3764. DELAY_10MS( LGS_DEFAULT_WS_TIME );
  3765. transactionResetResult();
  3766. };
  3767. };
  3768. void device2DSensor::poolStateFunction(){
  3769. goNextStage();
  3770. transactionResetResult();
  3771. };
  3772. #undef SIZE_IDX
  3773. #undef DEV_ID_IDX
  3774. #undef CMD_IDX
  3775. #undef SUB_CMD_IDX
  3776. #undef DATA_BEGIN_IDX
  3777. #undef LOG
  3778. #undef LOG_ERROR
  3779. #undef DEBUG_EXTRA