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.

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