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.

4669 lines
177 KiB

4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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
​
​
​
​
​
​
​
​
​
​
2 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
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
3 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
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
​
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
2 years ago
4 years ago
​
2 years ago
4 years ago
4 years ago
3 years ago
4 years ago
​
​
3 years ago
4 years ago
2 years ago
4 years ago
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
3 years ago
​
​
​
2 years ago
3 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
​
​
​
2 years ago
4 years ago
​
​
3 years ago
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
2 years ago
4 years ago
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
3 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
3 years ago
2 years ago
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
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
​
2 years ago
4 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
2 years ago
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
2 years ago
4 years ago
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
4 years ago
2 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
4 years ago
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
2 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
​
  1. #include "SQLite_dataBinder.h"
  2. #include "../../components/base/basicEvent.h"
  3. #define LOG( X ) m_pLog->Log( "SDBC", this, X )
  4. #ifdef DEBUG
  5. #define LOG_ERROR( X ) {\
  6. char _tBfrErrMSG2w34[256];\
  7. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  8. m_pLog->Log( "SDBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  9. }
  10. #else
  11. #define LOG_ERROR( X ) m_pLog->Log( "SDBC", this, _LOG_ERROR, X );
  12. #endif
  13. sqliteDBC *sqliteDBC::_instance = NULL;
  14. /**
  15. * Returns the single instance of the object.
  16. */
  17. sqliteDBC *sqliteDBC::getInstance( config_setting_t * Settings ) {
  18. // check if the instance has been created yet
  19. if( 0 == _instance ){
  20. // if not, then create it
  21. _instance = new sqliteDBC( Settings );
  22. };
  23. // return the single instance
  24. return _instance;
  25. };
  26. /*
  27. uint32_t sqliteDBC::getTsFromRDF( REPORT_DIRINFO &RDF ){
  28. struct tm ltm;
  29. memset( &ltm, 0, sizeof( struct tm ));
  30. ltm.tm_mday = atoi( RDF.DAY );
  31. ltm.tm_mon = atoi( RDF.MONTH ) - 1;
  32. ltm.tm_year = atoi( RDF.YEAR ) - 1900;
  33. return (uint32_t) timelocal( &ltm );
  34. };
  35. bool sqliteDBC::createAccessibleDir( CSTR path ){
  36. if( mkdir( path, STORAGE_DIR_MODE ) != 0 ) return false;
  37. chown( path, web_access_user, web_access_group );
  38. return true;
  39. };
  40. bool sqliteDBC::checkRDFDir( CSTR basePath, REPORT_DIRINFO &RDF, bool recreate ){
  41. char tBuff[MAX_PATH];
  42. sprintf( tBuff, "%s/%s", basePath, RDF.YEAR );
  43. #ifdef DEBUG
  44. LOG( tBuff );
  45. #endif
  46. if( fileExist( tBuff ) == 0 ){
  47. if ( recreate ) {
  48. if (!createAccessibleDir(tBuff)) return false;
  49. } else return false;
  50. };
  51. sprintf( tBuff, "%s/%s/%s", basePath, RDF.YEAR, RDF.MONTH );
  52. #ifdef DEBUG
  53. LOG( tBuff );
  54. #endif
  55. if( fileExist( tBuff ) == 0 ){
  56. if ( recreate ) {
  57. if( !createAccessibleDir( tBuff ) ) return false;
  58. } else return false;
  59. };
  60. sprintf( tBuff, "%s/%s/%s/%s", basePath, RDF.YEAR, RDF.MONTH, RDF.DAY );
  61. #ifdef DEBUG
  62. LOG( tBuff );
  63. #endif
  64. if( fileExist( tBuff ) == 0 ){
  65. if ( recreate ) {
  66. if( !createAccessibleDir( tBuff ) ) return false;
  67. } else return false;
  68. };
  69. return true;
  70. };
  71. */
  72. sqliteDBC::sqliteDBC( config_setting_t * Settings ):dataBinder(){
  73. m_pLog = basicLogCollection::getInstance();
  74. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DATABASE" );
  75. m_bStoIsConnected = false;
  76. m_bMemIsConnected = false;
  77. m_bRepIsConnected = false;
  78. m_bStaIsConnected = false;
  79. m_bLastEventWasClosed = false;
  80. m_pDataStorage = NULL;
  81. m_pDataMemory = NULL;
  82. m_pDataReports = NULL;
  83. m_pDataStatistics = NULL;
  84. m_nServerID = 1;
  85. };
  86. sqliteDBC::~sqliteDBC(){
  87. if ( m_pDataStorage ) delete( m_pDataStorage );
  88. if ( m_pDataMemory ) delete( m_pDataMemory );
  89. if ( m_pDataReports ) delete( m_pDataReports );
  90. if ( m_pDataStatistics ) delete( m_pDataStatistics );
  91. m_bStoIsConnected = false;
  92. m_bMemIsConnected = false;
  93. m_bRepIsConnected = false;
  94. m_bStaIsConnected = false;
  95. _instance = NULL;
  96. };
  97. bool sqliteDBC::connect( void ){
  98. if ( m_pSettings == NULL) return false;
  99. bool bRecreateMemStructures = false;
  100. config_setting_t * pSetting;
  101. const char * tBuff;
  102. //Disconnect if Connected
  103. m_bStoIsConnected = false;
  104. m_bMemIsConnected = false;
  105. m_bRepIsConnected = false;
  106. m_bStaIsConnected = false;
  107. m_bLastEventWasClosed = false;
  108. //Apply New Config
  109. #ifdef DEBUG
  110. LOG( "Reading DB Settings ... " );
  111. #endif
  112. if(!config_setting_lookup_string(m_pSettings, "DATA_FILE_NAME", (const char**)&tBuff )){
  113. pSetting = config_setting_add(m_pSettings, "DATA_FILE_NAME", CONFIG_TYPE_STRING);
  114. sprintf( m_pDbFile, "data/mysqlitedb.db" );
  115. config_setting_set_string( pSetting, m_pDbFile );
  116. basicSettingsProvider::getInstance()->compromise();
  117. LOG("Data Storage not set - using default");
  118. } else {
  119. sprintf( m_pDbFile, tBuff );
  120. };
  121. if(!config_setting_lookup_string(m_pSettings, "REPORTS_DIR_NAME", (const char**)&tBuff )){
  122. pSetting = config_setting_add(m_pSettings, "REPORTS_DIR_NAME", CONFIG_TYPE_STRING);
  123. sprintf( m_pDbReportBase, "data/reports" );
  124. config_setting_set_string( pSetting, m_pDbReportBase );
  125. basicSettingsProvider::getInstance()->compromise();
  126. LOG("Reports Storage not set - using default");
  127. } else {
  128. sprintf( m_pDbReportBase, tBuff );
  129. };
  130. if(!config_setting_lookup_string(m_pSettings, "WEB_ACCESS_USER", (const char**)&tBuff )){
  131. pSetting = config_setting_add(m_pSettings, "WEB_ACCESS_USER", CONFIG_TYPE_STRING);
  132. sprintf( web_access_user, "www-data" );
  133. config_setting_set_string( pSetting, web_access_user );
  134. basicSettingsProvider::getInstance()->compromise();
  135. LOG("Web Access User not set - using default");
  136. } else {
  137. sprintf( web_access_user, tBuff );
  138. };
  139. if(!config_setting_lookup_string(m_pSettings, "WEB_ACCESS_GROUP", (const char**)&tBuff )){
  140. pSetting = config_setting_add(m_pSettings, "WEB_ACCESS_GROUP", CONFIG_TYPE_STRING);
  141. sprintf( web_access_group, "www-data" );
  142. config_setting_set_string( pSetting, web_access_group );
  143. basicSettingsProvider::getInstance()->compromise();
  144. LOG("Web Access Group not set - using default");
  145. } else {
  146. sprintf( web_access_group, tBuff );
  147. };
  148. if( !fileExist( DB_SHMEM_POINT )) {
  149. bRecreateMemStructures = true;
  150. mkdir( DB_SHMEM_POINT, STORAGE_DIR_MODE );// S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
  151. chown( DB_SHMEM_POINT, getUserUid(web_access_user), getUserGid(web_access_group) ); //To make Accessed from PHP
  152. chmod( DB_SHMEM_POINT, STORAGE_DIR_MODE );
  153. };
  154. char tB[128];
  155. if (!config_setting_lookup_string(m_pSettings, "DATA_MEMORY_NAME", (const char **)&tBuff)) {
  156. pSetting = config_setting_add(m_pSettings, "DATA_MEMORY_NAME", CONFIG_TYPE_STRING);
  157. tBuff = tB;
  158. sprintf( tB, "mem_db.db" );
  159. config_setting_set_string( pSetting, tB );
  160. basicSettingsProvider::getInstance()->compromise();
  161. LOG("Memory Storage not set - using default");
  162. };
  163. sprintf( m_pDbMemory, "%s/%s", DB_SHMEM_POINT, tBuff );
  164. basicSettingsProvider::getInstance()->validate();
  165. // Kill Connection if any
  166. if ( m_pDataStorage ) delete( m_pDataStorage );
  167. if ( m_pDataMemory ) delete( m_pDataMemory );
  168. if ( m_pDataReports ) delete( m_pDataReports );
  169. if ( m_pDataStatistics ) delete( m_pDataStatistics );
  170. m_pDataMemory = NULL;
  171. m_pDataStorage = NULL;
  172. m_pDataReports = NULL;
  173. m_pDataStatistics = NULL;
  174. #ifdef DEBUG
  175. LOG( m_pDbFile );
  176. #endif
  177. // Create New Connections
  178. m_pDataStorage = new SQLite_Connector();
  179. if ( m_pDataStorage ) {
  180. if( m_pDataStorage->Connect( m_pDbFile, 0, true ) ){
  181. #ifdef DEBUG
  182. LOG("DB File Opened");
  183. #endif
  184. chown( m_pDbFile, getUserUid(web_access_user), getUserGid(web_access_group) );
  185. chmod( m_pDbFile, DB_FILE_MODE );
  186. m_bStoIsConnected = true;
  187. } else{
  188. LOG_ERROR("Cannot Connect to DB File");
  189. delete( m_pDataStorage );
  190. m_pDataStorage = NULL;
  191. LOG("Storage Deleted!");
  192. return false;
  193. };
  194. };
  195. #ifdef DEBUG
  196. LOG( m_pDbMemory );
  197. #endif
  198. if( !fileExist( m_pDbMemory )) {
  199. bRecreateMemStructures = true;
  200. //Always recreate
  201. unlink( m_pDbMemory );
  202. };
  203. m_pDataMemory = new SQLite_Connector();
  204. if ( m_pDataMemory ) {
  205. if( m_pDataMemory->Connect( m_pDbMemory, 0, true ) ){
  206. #ifdef DEBUG
  207. LOG("DB Memory Opened");
  208. #endif
  209. chown( m_pDbMemory, getUserUid(web_access_user), getUserGid(web_access_group) );
  210. chmod( m_pDbMemory, DB_FILE_MODE );
  211. m_pDataMemory->SilentQuery("PRAGMA journal_mode=WAL");
  212. //Recreate at Register Server
  213. m_bMemIsConnected = true;
  214. } else{
  215. LOG_ERROR("Cannot Connect to DB Memory");
  216. delete( m_pDataStorage );
  217. delete( m_pDataMemory );
  218. m_bStoIsConnected = false;
  219. m_pDataStorage = NULL;
  220. m_pDataMemory = NULL;
  221. return false;
  222. };
  223. };
  224. sprintf( m_pDbStat, "%s/stat.db", m_pDbReportBase );
  225. m_pDataStatistics = new SQLite_Connector();
  226. if ( m_pDataStatistics ) {
  227. if ( fileExist( m_pDbStat )) {
  228. m_bStaIsCreated = false;
  229. if( m_pDataStatistics->Connect( m_pDbStat, 0, true) ) {
  230. #ifdef DEBUG
  231. LOG( m_pDbStat );
  232. LOG("DB Statistics Opened");
  233. #endif
  234. m_pDataStatistics->SilentQuery("PRAGMA journal_mode=WAL");
  235. m_bStaIsConnected = true;
  236. } else {
  237. LOG_ERROR("Cannot Connect to DB Statistics");
  238. delete( m_pDataStorage );
  239. delete( m_pDataMemory );
  240. delete( m_pDataStatistics );
  241. m_bMemIsConnected = false;
  242. m_bStoIsConnected = false;
  243. m_pDataStorage = NULL;
  244. m_pDataMemory = NULL;
  245. m_pDataStatistics = NULL;
  246. return false;
  247. };
  248. } else {
  249. m_bStaIsCreated = true;
  250. if( m_pDataStatistics->Connect( m_pDbStat, 0, true) ) {
  251. #ifdef DEBUG
  252. LOG("NEW DB Statistics Creating");
  253. #endif
  254. chown( m_pDbStat, getUserUid(web_access_user), getUserGid(web_access_group) );
  255. chmod( m_pDbStat, DB_FILE_MODE );
  256. m_pDataStatistics->SilentQuery("PRAGMA journal_mode=WAL");
  257. m_pDataStatistics->SilentQuery("CREATE TABLE IF NOT EXISTS \"days\" (\"year\" INTEGER,\"month\" INTEGER,\"day\" INTEGER,\"evt_count\" INTEGER DEFAULT 0,\"session_count\" INTEGER DEFAULT 0,\"videos_count\" INTEGER DEFAULT 0,\"session_closed\" INTEGER DEFAULT 0, CONSTRAINT \"date_uni\" UNIQUE(\"year\",\"month\",\"day\") );");
  258. m_bStaIsConnected = true;
  259. } else {
  260. LOG_ERROR("Cannot Connect to DB Statistics");
  261. delete( m_pDataStorage );
  262. delete( m_pDataMemory );
  263. delete( m_pDataStatistics );
  264. m_bMemIsConnected = false;
  265. m_bStoIsConnected = false;
  266. m_pDataStorage = NULL;
  267. m_pDataMemory = NULL;
  268. m_pDataStatistics = NULL;
  269. return false;
  270. };
  271. };
  272. };
  273. bool create_tables = false;
  274. m_pDataReports = new SQLite_Connector();
  275. if ( m_pDataReports ) {
  276. memset( &m_sPRepInfo, 0, sizeof(REPORT_DIRINFO));
  277. if( !m_bStaIsCreated ){
  278. #ifdef DEBUG
  279. LOG("OLD Statistics PRESENT Report Created!");
  280. #endif
  281. AAssoc * result = m_pDataStatistics->Query( "SELECT * FROM `days` ORDER BY `year` DESC, `month` DESC, `day` DESC LIMIT 1" );
  282. if ( result ) {
  283. if( result->size() > 0 ) {
  284. Assoc * cArr;
  285. Assoc::iterator it;
  286. cArr = result->at(0);
  287. it = cArr->find("year");
  288. if( it != cArr->end() ){
  289. strncpy( m_sPRepInfo.YEAR, it->second.c_str(), 4 );
  290. };
  291. it = cArr->find("month");
  292. if( it != cArr->end() ){
  293. sprintf( m_sPRepInfo.MONTH, "%02d", atoi( it->second.c_str() ) );
  294. };
  295. it = cArr->find("day");
  296. if( it != cArr->end() ){
  297. sprintf( m_sPRepInfo.DAY, "%02d", atoi( it->second.c_str() ) );
  298. };
  299. m_sPRepInfo.ts = getTsFromRDF( m_sPRepInfo );
  300. } else {
  301. create_tables = true;
  302. #ifdef DEBUG
  303. LOG("No Rows Fetched from STAT!");
  304. #endif
  305. };
  306. };
  307. m_pDataMemory->deleteResult( result );
  308. };
  309. if ( m_sPRepInfo.ts != 0 ) {
  310. #ifdef DEBUG
  311. LOG("Have Old Reports!");
  312. #endif
  313. if( checkRDFDir( m_pDbReportBase, m_sPRepInfo, false ) == 0 ) {
  314. LOG_ERROR("Error Connecting to Prev Report!");
  315. m_bLastEventWasClosed = true;
  316. create_tables = true;
  317. } else {
  318. #ifdef DEBUG
  319. LOG("Connect to old Report Database");
  320. #endif
  321. sprintf( m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sPRepInfo.YEAR, m_sPRepInfo.MONTH, m_sPRepInfo.DAY );
  322. LOG( m_pDbReport );
  323. if( fileExist( m_pDbReport ) ){
  324. SQLite_Connector *tDBC = new SQLite_Connector();
  325. if ( tDBC ) {
  326. if( tDBC->Connect( m_pDbReport, 0, true) ) {
  327. char tQBuf[CTEXT];
  328. AAssoc *result;
  329. sprintf( tQBuf, "SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO );
  330. #ifdef DEBUG_ALL
  331. LOG(tQBuf);
  332. #endif
  333. result = tDBC->Query( tQBuf );
  334. if( result!= NULL ) {
  335. if( result->size() > 0 ) {
  336. Assoc *cArr;
  337. Assoc::iterator it;
  338. cArr = result->at(0);
  339. it = cArr->find("evt_type");
  340. if( it != cArr->end() ){
  341. if( atoi( it->second.c_str() ) != EVT_LRF_START_SESSION ) m_bLastEventWasClosed = true;
  342. };
  343. } else m_bLastEventWasClosed = true;
  344. };
  345. deleteResult( result );
  346. } else {
  347. LOG_ERROR("Error Connecting to Prev Report!");
  348. m_bLastEventWasClosed = true;
  349. create_tables = true;
  350. };
  351. delete( tDBC );
  352. } else {
  353. LOG_ERROR("Error Create DB Connection Object!");
  354. m_bLastEventWasClosed = true;
  355. create_tables = true;
  356. };
  357. } else {
  358. LOG_ERROR("Error No Prev Report Database!");
  359. m_bLastEventWasClosed = true;
  360. create_tables = true;
  361. };
  362. };
  363. } else {
  364. m_bLastEventWasClosed = true;
  365. create_tables = true;
  366. };
  367. if ( m_bLastEventWasClosed ) {
  368. #ifdef DEBUG
  369. LOG("Last Session is Closed!");
  370. #endif
  371. fillRDF( time( NULL ), m_sCRepInfo );
  372. } else {
  373. #ifdef DEBUG
  374. LOG("Last Session is NOT Closed!");
  375. #endif
  376. memcpy( &m_sCRepInfo, &m_sPRepInfo, sizeof(REPORT_DIRINFO) );
  377. };
  378. #ifdef DEBUG
  379. LOG( m_pDbReportBase );
  380. #endif
  381. if( !checkRDFDir( m_pDbReportBase, m_sCRepInfo, true, getUserUid(web_access_user), getUserGid(web_access_group) ) ) {
  382. LOG_ERROR("Cannot Open Report!!");
  383. return false;
  384. };
  385. sprintf( m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  386. #ifdef DEBUG
  387. LOG( m_pDbReport );
  388. #endif
  389. if (m_pDataReports->Connect( m_pDbReport, 0, true )) {
  390. #ifdef DEBUG
  391. LOG("Report File Opened");
  392. #endif
  393. chown( m_pDbReport, getUserUid(web_access_user), getUserGid(web_access_group) );
  394. chmod( m_pDbReport, DB_FILE_MODE );
  395. //Recreate Table in any case
  396. //if ( m_sCRepInfo.ts != m_sPRepInfo.ts || create_tables ) {
  397. // Created New Report ??
  398. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events\" ( \"id\" INTEGER NOT NULL, \"node_id\" INTEGER NOT NULL, \"uuid\" TEXT NOT NULL UNIQUE, \"ts\" INTEGER NOT NULL, \"ts_ms\" INTEGER NOT NULL, \"evt_type\" INTEGER NOT NULL, \"lrf_id\" INTEGER, \"range_digital\" INTEGER, \"azimuth\" REAL, \"elevation\" REAL, \"range\" REAL, \"area\" REAL, \"lat\" REAL, \"lon\" REAL, \"alt\" REAL, \"ref_id\" INTEGER, \"ref_uuid\" TEXT, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
  399. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_pictures\" ( \"evt_id\" INTEGER NOT NULL, \"picture_id\" INTEGER NOT NULL )");
  400. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_videos\" ( \"evt_id\" INTEGER NOT NULL, \"video_id\" INTEGER NOT NULL, \"frame\" INTEGER DEFAULT 0, \"tss\" INTEGER, \"tms\" INTEGER )");
  401. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"pictures\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT NULL, \"data\" BLOB COLLATE BINARY, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
  402. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"videos\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT NULL, \"fps\" INTEGER NOT NULL, \"flength\" INTEGER, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
  403. //};
  404. m_bRepIsConnected = true;
  405. } else{
  406. LOG_ERROR("Cannot Connect to DB File");
  407. delete( m_pDataReports );
  408. m_pDataReports = NULL;
  409. LOG("Storage Deleted!");
  410. return false;
  411. };
  412. };
  413. return ( m_bRepIsConnected && m_bMemIsConnected && m_bStoIsConnected && m_bStaIsConnected );
  414. };
  415. void sqliteDBC::initMemDB( uint32_t sid ){
  416. m_pDataMemory->SilentQuery("DROP TABLE \"nodes_qcq\"");
  417. m_pDataMemory->SilentQuery("CREATE TABLE \"nodes_qcq\" ( \
  418. \"id\" INTEGER NOT NULL,\
  419. \"node_id\" INTEGER NOT NULL,\
  420. \"cmd\" INTEGER NOT NULL,\
  421. \"status\" INTEGER DEFAULT 0,\
  422. \"parameter\" TEXT,\
  423. PRIMARY KEY(\"id\" AUTOINCREMENT)\
  424. );");
  425. m_pDataMemory->SilentQuery("DROP TABLE \"servers\"");
  426. m_pDataMemory->SilentQuery("CREATE TABLE \"servers\" (\
  427. \"id\" INTEGER NOT NULL,\
  428. \"ts\" INTEGER DEFAULT 0,\
  429. \"pid\" INTEGER DEFAULT 0,\
  430. \"hw_info\" TEXT,\
  431. \"os_info\" TEXT,\
  432. \"cpu_cores\" INTEGER DEFAULT 1,\
  433. \"stat_cpu1\" REAL DEFAULT 0.0,\
  434. \"stat_cpu5\" REAL DEFAULT 0.0,\
  435. \"stat_cpu15\" REAL DEFAULT 0.0,\
  436. \"stat_mem\" REAL DEFAULT 0.0,\
  437. \"stat_disk\" REAL DEFAULT 0.0,\
  438. \"val_mem_tottal\" INTEGER DEFAULT 0,\
  439. \"val_mem_current\" INTEGER DEFAULT 0,\
  440. \"val_disk_tottal\" INTEGER DEFAULT 0,\
  441. \"val_disk_current\" INTEGER DEFAULT 0,\
  442. \"temp0\" REAL DEFAULT 0.0,\
  443. PRIMARY KEY(\"id\" AUTOINCREMENT)\
  444. );");
  445. char tB[128];
  446. sprintf( tB, "INSERT INTO `servers` (`id`,`ts`) VALUES (%d, strftime('%%s') )", sid );
  447. m_pDataMemory->SilentQuery( tB );
  448. };
  449. CSTR sqliteDBC::getCurrentReportDir( void ){
  450. CSTR tV = NULL;
  451. if ( m_sCRepInfo.ts ) {
  452. char tBuf[256];
  453. sprintf( tBuf, "%s/%s/%s", m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  454. tV = strdup( tBuf );
  455. };
  456. return tV;
  457. };
  458. DBC_PUSHED_CMD *sqliteDBC::getNodePushedCMD( uint32_t NodeID ){
  459. DBC_PUSHED_CMD * RetVal = NULL;
  460. if ( m_bMemIsConnected ) {
  461. char QS[MAX_PATH];
  462. AAssoc * result;
  463. sprintf( QS, "select * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 ORDER BY `id` LIMIT 1", NodeID );
  464. #ifdef DEBUG_ALL
  465. LOG( QS );
  466. #endif
  467. result = m_pDataMemory->Query( QS );
  468. if ( result ) {
  469. if( result->size() > 0 ) {
  470. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  471. if( RetVal ) {
  472. Assoc * cArr;
  473. Assoc::iterator it;
  474. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  475. cArr = result->at(0);
  476. it = cArr->find("id");
  477. if( it != cArr->end() ){
  478. RetVal->id = atoi( it->second.c_str() );
  479. };
  480. it = cArr->find("cmd");
  481. if( it != cArr->end() ){
  482. RetVal->CMD = atoi( it->second.c_str() );
  483. };
  484. it = cArr->find("parameter");
  485. if( it != cArr->end() ){
  486. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  487. RetVal->PARAM[255] = (char)0;
  488. };
  489. };
  490. #ifdef DEBUG_ALL
  491. } else {
  492. LOG("No Rows Fetched!");
  493. #endif
  494. };
  495. };
  496. m_pDataMemory->deleteResult( result );
  497. };
  498. return RetVal;
  499. };
  500. bool sqliteDBC::updateModemManagerActiveCall( uint32_t MMID, int32_t callID ){
  501. if ( m_bMemIsConnected ) {
  502. char QS[MAX_PATH];
  503. sprintf( QS, "UPDATE `module_modem` SET `active_call`=%d WHERE `id`=%d ", callID, MMID );
  504. return m_pDataStorage->SilentQuery( QS );
  505. };
  506. return false;
  507. };
  508. bool sqliteDBC::updateModemManagerLTS( uint32_t MMID, uint32_t ts ){
  509. if ( m_bMemIsConnected ) {
  510. char QS[MAX_PATH];
  511. sprintf( QS, "UPDATE `module_modem` SET `last_trigger_ts`=%d WHERE `id`=%d ", ts, MMID );
  512. return m_pDataStorage->SilentQuery( QS );
  513. };
  514. return false;
  515. };
  516. bool sqliteDBC::updateModemManagerActivePhoneBookID( uint32_t MMID, uint32_t pbID ){
  517. if ( m_bMemIsConnected ) {
  518. char QS[MAX_PATH];
  519. sprintf( QS, "UPDATE `module_modem` SET `active_ph_id`=%d WHERE `id`=%d ", pbID, MMID );
  520. return m_pDataStorage->SilentQuery( QS );
  521. };
  522. return false;
  523. };
  524. bool sqliteDBC::updateModemManagerActiveSMS( uint32_t MMID, int32_t smsID ){
  525. if ( m_bMemIsConnected ) {
  526. char QS[MAX_PATH];
  527. sprintf( QS, "UPDATE `module_modem` SET `active_sms`=%d WHERE `id`=%d ", smsID, MMID );
  528. return m_pDataStorage->SilentQuery( QS );
  529. };
  530. return false;
  531. };
  532. bool sqliteDBC::updateNodePushedCMD( uint32_t CmdID, uint8_t status ){
  533. if ( m_bMemIsConnected ) {
  534. char QS[MAX_PATH];
  535. sprintf( QS, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID );
  536. return m_pDataMemory->SilentQuery( QS );
  537. };
  538. return false;
  539. };
  540. bool sqliteDBC::cleanNodePushedCMD( void ){
  541. if ( m_bMemIsConnected ) {
  542. return m_pDataMemory->SilentQuery( "DELETE FROM `nodes_qcq` WHERE `status` > 200" );
  543. };
  544. return false;
  545. };
  546. void sqliteDBC::deleteNIF( uint32_t NifID ){
  547. if ( m_bStoIsConnected ) {
  548. char tQBuf[MAX_PATH_LEN];
  549. sprintf( tQBuf, "", NifID );
  550. #ifdef DEBUG_ALL
  551. LOG( tQBuf );
  552. #endif
  553. m_pDataStorage->SilentQuery( tQBuf );
  554. };
  555. };
  556. void sqliteDBC::deleteNIS( uint32_t NisID ){
  557. };
  558. void sqliteDBC::deleteNetwork( uint32_t NetID ){
  559. };
  560. bool sqliteDBC::deleteReportStat( REPORT_DIRINFO &RDF ){
  561. if ( m_bStaIsConnected ) {
  562. char tQBuf[MAX_PATH_LEN];
  563. sprintf( tQBuf, "DELETE FROM `days` WHERE `year`=%s AND `month`=%s AND `day`=%s", RDF.YEAR, RDF.MONTH, RDF.DAY );
  564. #ifdef DEBUG_ALL
  565. LOG( tQBuf );
  566. #endif
  567. m_pDataStatistics->SilentQuery( tQBuf );
  568. return true;
  569. };
  570. return false;
  571. };
  572. void sqliteDBC::deleteResource( uint32_t ResourceID ){
  573. };
  574. void sqliteDBC::deleteSensor( uint32_t SensorID ){
  575. };
  576. void sqliteDBC::deleteUART( uint32_t UARTID ){
  577. };
  578. bool sqliteDBC::updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){
  579. if( m_bMemIsConnected ) {
  580. char tQBuf[MAX_PATH_LEN];
  581. sprintf(tQBuf, "UPDATE `servers` SET `ts`=STRFTIME('%%s'), `cpu_cores`=%d, `stat_cpu1`=%0.1f, `stat_cpu5`=%0.1f, `stat_cpu15`=%0.1f, `stat_mem`=%0.1f, `stat_disk`=%0.1f, `temp0`=%0.1f, `val_mem_tottal`=%" PRIu64 ", `val_mem_current`=%" PRIu64 ", `val_disk_tottal`=%" PRIu64 ", `val_disk_current`=%" PRIu64 " WHERE `id`=%d",
  582. ptr->CPU_CORES,
  583. ptr->cpu1,
  584. ptr->cpu5,
  585. ptr->cpu15,
  586. ptr->mem,
  587. ptr->disk,
  588. ptr->temperature,
  589. ptr->T_DISK,
  590. ptr->C_DISK,
  591. ptr->T_MEM,
  592. ptr->C_MEM,
  593. m_nServerID
  594. );
  595. #ifdef DEBUG_ALL
  596. LOG(tQBuf);
  597. #endif
  598. m_pDataMemory->SilentQuery( tQBuf );
  599. return true;
  600. };
  601. return false;
  602. };
  603. /********************************************************************
  604. * *
  605. * Slow DB Functions *
  606. * *
  607. ********************************************************************/
  608. bool sqliteDBC::addLRFDraw( uint32_t node_id, CSTR uniq_id, uint8_t lrf_id, uint8_t type ){
  609. if ( m_bStoIsConnected ){
  610. char tQBuf[1024];
  611. sprintf( tQBuf, "INSERT INTO `lrf_draw`(`node_id`,`lrf_id`,`type`,`ts`,`data`) VALUES(%d,%d,%d,STRFTIME('%%s'),'%s')",
  612. node_id, lrf_id, type, uniq_id );
  613. #ifdef DEBUG_ALL
  614. LOG(tQBuf);
  615. #endif
  616. m_pDataStorage->SilentQuery( tQBuf );
  617. return true;
  618. };
  619. return false;
  620. };
  621. bool sqliteDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ){
  622. if ( m_bStoIsConnected ){
  623. if ( type == 0 ) {
  624. char tQBuf[1024];
  625. CSTR uid = getUniqID_MD5();
  626. if( uid == NULL ) return false;
  627. sprintf( tQBuf, "data/device_draws/%s.raw", uid );
  628. FILE *fd = fopen( tQBuf, "wb+" );
  629. if( fd!= NULL ) {
  630. uint32_t sisi = th_size >> 2;
  631. fwrite( &sisi, 4, 1, fd );
  632. fwrite( th_data, 4, sisi, fd );
  633. fclose( fd );
  634. bool rV = addLRFDraw( DBID, uid, lrf, type );
  635. free ( uid );
  636. return rV;
  637. };
  638. free( uid );
  639. } else {
  640. return addLRFDraw( DBID, (CSTR) th_data, lrf, type );
  641. };
  642. };
  643. return false;
  644. };
  645. void sqliteDBC::updateStats( bool evt, bool video, uint8_t ses_status ){
  646. if ( m_bStaIsConnected ) {
  647. char tQBuf[1024];
  648. switch ( ses_status ) {
  649. case SESSION_CONTINUE:{
  650. if ( video ) {
  651. sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`videos_count`) VALUES(%s,%s,%s,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `videos_count`=`videos_count`+1",
  652. m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  653. } else {
  654. sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`evt_count`) VALUES(%s,%s,%s,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `evt_count`=`evt_count`+1",
  655. m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  656. };
  657. #ifdef DEBUG_ALL
  658. LOG( tQBuf );
  659. #endif
  660. m_pDataStatistics->SilentQuery( tQBuf );
  661. break;
  662. };
  663. case SESSION_START:{
  664. //Check New Day Reports
  665. REPORT_DIRINFO tRR = {0};
  666. fillRDF( time( NULL ), tRR );
  667. if( tRR.ts > m_sCRepInfo.ts ) {
  668. //New Day Report
  669. if ( m_bRepIsConnected ) {
  670. m_bRepIsConnected = false;
  671. LOG("Disconnect Report!");
  672. m_pDataReports->Disconnect();
  673. };
  674. memcpy( &m_sPRepInfo, &m_sCRepInfo, sizeof(REPORT_DIRINFO) );
  675. memcpy( &m_sCRepInfo, &tRR, sizeof(REPORT_DIRINFO) );
  676. if( checkRDFDir( m_pDbReportBase, m_sCRepInfo, true, getUserUid(web_access_user), getUserGid(web_access_group) ) ){
  677. sprintf( m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  678. LOG("Connect Report!");
  679. LOG( m_pDbReport );
  680. if( m_pDataReports->Connect( m_pDbReport, 0, true ) ){
  681. chown( m_pDbReport, getUserUid(web_access_user), getUserGid(web_access_group) );
  682. chmod( m_pDbReport, DB_FILE_MODE );
  683. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events\" ( \"id\" INTEGER NOT NULL, \"node_id\" INTEGER NOT NULL, \"uuid\" TEXT NOT NULL UNIQUE, \"ts\" INTEGER NOT NULL, \"ts_ms\" INTEGER NOT NULL, \"evt_type\" INTEGER NOT NULL, \"lrf_id\" INTEGER, \"range_digital\" INTEGER, \"azimuth\" REAL, \"elevation\" REAL, \"range\" REAL, \"area\" REAL, \"lat\" REAL, \"lon\" REAL, \"alt\" REAL, \"ref_id\" INTEGER, \"ref_uuid\" TEXT, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
  684. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_pictures\" ( \"evt_id\" INTEGER NOT NULL, \"picture_id\" INTEGER NOT NULL )");
  685. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_videos\" ( \"evt_id\" INTEGER NOT NULL, \"video_id\" INTEGER NOT NULL, \"frame\" INTEGER DEFAULT 0, \"tss\" INTEGER, \"tms\" INTEGER )");
  686. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"pictures\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT NULL, \"data\" BLOB COLLATE BINARY, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
  687. m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"videos\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT NULL, \"fps\" INTEGER NOT NULL, \"flength\" INTEGER, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
  688. m_bRepIsConnected = true;
  689. LOG("Report Connected!");
  690. // Create New Day Record
  691. sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
  692. m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  693. LOG( tQBuf );
  694. m_pDataStatistics->SilentQuery( tQBuf );
  695. };
  696. };
  697. };
  698. // Create New record
  699. sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,1,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
  700. m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  701. #ifdef DEBUG_ALL
  702. LOG( tQBuf );
  703. #endif
  704. m_pDataStatistics->SilentQuery( tQBuf );
  705. break;
  706. };
  707. case SESSION_END:{
  708. sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_closed`=1",
  709. m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  710. #ifdef DEBUG_ALL
  711. LOG( tQBuf );
  712. #endif
  713. m_pDataStatistics->SilentQuery( tQBuf );
  714. break;
  715. };
  716. case SESSION_DROP:{
  717. //sprintf( tQBuf, "UPDATE `days` SET `session_count`=`session_count`-1, `session_closed`=1 WHERE `year`='%s' AND `month`='%s' AND `day`='%s'",
  718. sprintf( tQBuf, "UPDATE `days` SET `session_closed`=1 WHERE `year`='%s' AND `month`='%s' AND `day`='%s'",
  719. m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
  720. #ifdef DEBUG_ALL
  721. LOG( tQBuf );
  722. #endif
  723. m_pDataStatistics->SilentQuery( tQBuf );
  724. break;
  725. };
  726. };
  727. };
  728. };
  729. bool sqliteDBC::dropSession(){
  730. if ( m_bRepIsConnected ) {
  731. char tQBuf[1024];
  732. AAssoc *result;
  733. #ifdef REMOVE_ONLY_SESSION_MARKS
  734. sprintf( tQBuf, "SELECT `ts`, `ts_ms` FROM `events` WHERE `evt_type`=%d ORDER BY `ts` DESC,`ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION );
  735. #else
  736. sprintf( tQBuf, "SELECT `ts`, `ts_ms` FROM `events` WHERE `evt_type`=%d ORDER BY `ts` DESC,`ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION );
  737. #endif
  738. m_pDataReports->Query(tQBuf);
  739. #ifdef DEBUG_ALL
  740. LOG(tQBuf);
  741. #endif
  742. result = m_pDataReports->Query( tQBuf );
  743. if( result!= NULL ) {
  744. uint32_t ts = 0;
  745. uint32_t ms = 0;
  746. uint64_t r = 0;
  747. if( result->size() > 0 ) {
  748. Assoc *cArr;
  749. Assoc::iterator it;
  750. cArr = result->at(0);
  751. it = cArr->find("ts");
  752. if( it != cArr->end() ){
  753. ts = atoi( it->second.c_str() );
  754. };
  755. it = cArr->find("ts_ms");
  756. if( it != cArr->end() ){
  757. ms = atoi( it->second.c_str() );
  758. };
  759. r = ts;
  760. r = ( r * 1000 ) + ms;
  761. };
  762. deleteResult( result );
  763. if ( r ) {
  764. #ifdef REMOVE_ONLY_SESSION_MARKS
  765. sprintf(tQBuf, "DELETE FROM `events` WHERE ((`ts`*1000+`ts_ms`) >= %" PRIu64 ") AND ( `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d )", r, EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_TO, EVT_LRF_END_SESSION_MA );
  766. #else
  767. sprintf(tQBuf, "DELETE FROM `events` WHERE (`ts`*1000+`ts_ms`) >= %" PRIu64, r );
  768. #endif
  769. #ifdef DEBUG_ALL
  770. LOG(tQBuf);
  771. #endif
  772. m_pDataReports->SilentQuery( tQBuf );
  773. };
  774. };
  775. };
  776. updateStats( false, false, SESSION_DROP );
  777. return true;
  778. }
  779. uint32_t sqliteDBC::addEvent( DBC_EVT_RECORD *ptr ){
  780. if ( ptr == NULL ) return 0;
  781. if ( m_bRepIsConnected ) {
  782. char tQBuf[1024];
  783. switch ( ptr->type ) {
  784. case EVT_LRF_END_SESSION_TO:
  785. case EVT_LRF_END_SESSION_MA:
  786. updateStats( false, false, SESSION_END );
  787. sprintf( tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)",
  788. ptr->node_id,
  789. ptr->uuid,
  790. ptr->ts_s,
  791. ptr->ts_ms,
  792. ptr->type
  793. );
  794. break;
  795. case EVT_LRF_START_SESSION:
  796. updateStats( false, false, SESSION_START );
  797. sprintf( tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)",
  798. ptr->node_id,
  799. ptr->uuid,
  800. ptr->ts_s,
  801. ptr->ts_ms,
  802. ptr->type
  803. );
  804. break;
  805. case EVT_FLT_LATF_CHK:
  806. case EVT_FLT_LATF_UP_DETEC:
  807. case EVT_FLT_LATF_BT_DETEC:
  808. case EVT_FLT_LATF_TRP_DET:
  809. case EVT_FLT_LATF_TRP_UPDT:
  810. case EVT_FLT_LATF_SUSP_START:
  811. case EVT_FLT_LATF_REGULAR:
  812. case EVT_FLT_LATF_DISABLED:
  813. case EVT_FLT_LATF_SUSP_DET:
  814. case EVT_FLT_LATF_DIFF_DET:{
  815. updateStats();
  816. sprintf( tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`,`lrf_id`,`range_digital`,`azimuth`,`range`,`area`,`lat`,`lon`,`alt`)" \
  817. " VALUES(%d,'%s',%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.7f,%0.7f,%0.2f)",
  818. ptr->node_id,
  819. ptr->uuid,
  820. ptr->ts_s,
  821. ptr->ts_ms,
  822. ptr->type,
  823. ptr->lrf_id,
  824. ptr->range_digital,
  825. ptr->az,
  826. ptr->ra,
  827. ptr->area,
  828. ptr->lat,
  829. ptr->lon,
  830. ptr->alt
  831. );
  832. break;
  833. };
  834. case EVT_FLT_LATF_OP_DISABLED:
  835. case EVT_FLT_LATF_OP_TD:
  836. case EVT_FLT_LATF_OP_TG:
  837. case EVT_FLT_LATF_OP_EXP:
  838. case EVT_FLT_LATF_TRP_EXP:
  839. case EVT_FLT_LATF_SUSP_NAK:
  840. case EVT_FLT_LATF_SUSP_EXP:{
  841. updateStats();
  842. sprintf( tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)",
  843. ptr->node_id,
  844. ptr->uuid,
  845. ptr->ts_s,
  846. ptr->ts_ms,
  847. ptr->type
  848. );
  849. break;
  850. };
  851. case EVT_OP_ACK_MASK:
  852. case EVT_OP_NACK_MASK:
  853. case EVT_OP_ON_MASK:
  854. case EVT_OP_OFF_MASK:
  855. case EVT_CONNECTED:
  856. case EVT_DISCONNECTED:
  857. case EVT_COMMUNICATION_JAMED:
  858. case EVT_STUDY:
  859. case EVT_BUSY:
  860. case EVT_FLIP:
  861. case EVT_READY:
  862. case EVT_ERR_LRF_NO_IRQ:
  863. case EVT_ERR_LRF_NO_ZERO:
  864. case EVT_ERR_LRF_ANGLE:
  865. case EVT_ERR_LRF_VOLTAGE:
  866. case EVT_ERR_LRF_BROKEN:
  867. case EVT_LRF_VIS_CHANGED:
  868. case EVT_ERR_OVERFLOW:
  869. case EVT_SST_OVERFLOW:
  870. case EVT_VIDEO_FPS_DEGRADED:
  871. case EVT_VIDEO_FPS_RAISED:{
  872. updateStats();
  873. sprintf( tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)",
  874. ptr->node_id,
  875. ptr->uuid,
  876. ptr->ts_s,
  877. ptr->ts_ms,
  878. ptr->type
  879. );
  880. break;
  881. };
  882. case EVT_ROI_ACTIVE:
  883. case EVT_TARGET_3D_WHITE:
  884. case EVT_TARGET_3D_BLACK:{
  885. updateStats();
  886. sprintf( tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`,`lrf_id`,`range_digital`,`azimuth`,`elevation`,`range`,`area`,`lat`,`lon`,`alt`)" \
  887. " VALUES(%d,'%s',%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.2f,%0.7f,%0.7f,%0.2f)",
  888. ptr->node_id,
  889. ptr->uuid,
  890. ptr->ts_s,
  891. ptr->ts_ms,
  892. ptr->type,
  893. ptr->lrf_id,
  894. ptr->range_digital,
  895. ptr->az,
  896. ptr->el,
  897. ptr->ra,
  898. ptr->area,
  899. ptr->lat,
  900. ptr->lon,
  901. ptr->alt
  902. );
  903. break;
  904. };
  905. case EVT_TARGET_2D_WHITE:
  906. case EVT_TARGET_2D_BLACK:{
  907. updateStats();
  908. sprintf( tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`,`lrf_id`,`range_digital`,`azimuth`,`range`,`area`,`lat`,`lon`,`alt`)" \
  909. " VALUES(%d,'%s',%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.7f,%0.7f,%0.2f)",
  910. ptr->node_id,
  911. ptr->uuid,
  912. ptr->ts_s,
  913. ptr->ts_ms,
  914. ptr->type,
  915. ptr->lrf_id,
  916. ptr->range_digital,
  917. ptr->az,
  918. ptr->ra,
  919. ptr->area,
  920. ptr->lat,
  921. ptr->lon,
  922. ptr->alt
  923. );
  924. break;
  925. };
  926. default: return 0;
  927. };
  928. #ifdef DEBUG_ALL
  929. LOG( tQBuf );
  930. #endif
  931. if ( m_bRepIsConnected ) {
  932. return ptr->id = m_pDataReports->QueryID(tQBuf);
  933. } else {
  934. LOG_ERROR("Report DB Droped!");
  935. }
  936. };
  937. return 0;
  938. };
  939. bool sqliteDBC::addIPCam( OBSERVER_RESULT *tPtr ){
  940. if(m_bStoIsConnected) {
  941. char tQBuf[1024];
  942. char tIpBuf[32];
  943. char tProto[32];
  944. char tPath[CTEXT];
  945. char *tPos;
  946. char *tPos2;
  947. uint16_t tPort = 0;
  948. memcpy( tProto, tPtr->XAddrs, 5 );
  949. tProto[5] = (char)0;
  950. if( tProto[4] == ':') tProto[4] = (char)0;
  951. memset( tPath, 0, CTEXT );
  952. tPos = strstr(tPtr->XAddrs,"//");
  953. if( tPos != NULL ) {
  954. tPos2 = strstr( tPos + 2,":");
  955. if( tPos2 != NULL ) {
  956. LOG("IP Port Defined!");
  957. int len, len2, len3;
  958. len = tPos2 - tPos - 2;
  959. strncpy( tIpBuf, tPos + 2, len);
  960. tIpBuf[len] = (char)0;
  961. tPort = atoi( tPos2 + 1 );
  962. strncpy( tPath, tPos + 2 + len, CTEXT );
  963. } else {
  964. tPos2 = strstr( tPos + 2,"/");
  965. if( tPos2 != NULL ) {
  966. int len, len2, len3;
  967. len = tPos2 - tPos - 2;
  968. strncpy( tIpBuf, tPos + 2, len);
  969. tIpBuf[len] = (char)0;
  970. strncpy( tPath, tPos + 2 + len, CTEXT );
  971. } else {
  972. tPos2 = strstr( tPos + 2,"/");
  973. LOG_ERROR("Pos 2 - err");
  974. tIpBuf[0] = (char)0;
  975. };
  976. };
  977. } else {
  978. LOG_ERROR("Pos 0 - err");
  979. tIpBuf[0] = (char)0;
  980. };
  981. if ( tPort ) {
  982. sprintf(tQBuf, "INSERT INTO cameras (`online`,`uuid`,`onvif_ctrl`,`ip`,`port`,`type`,`status`,`mac`,`hardware`,`name`,`onvif_access`) VALUES (1,'%s','%s','%s',%d,12,0,'%s','%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1, `ip`='%s', `port`=%d",
  983. tPtr->RefID,
  984. //tPtr->XAddrs,
  985. tPath,
  986. tIpBuf,
  987. tPort,
  988. tPtr->MAC,
  989. tPtr->Hardware,
  990. tPtr->Name,
  991. tProto,
  992. //tPtr->XAddrs,
  993. tIpBuf,
  994. tPort
  995. );
  996. } else {
  997. sprintf(tQBuf, "INSERT INTO cameras (`online`,`uuid`,`onvif_ctrl`,`ip`,`type`,`status`,`mac`,`hardware`,`name`,`onvif_access`) VALUES (1,'%s','%s','%s',12,0,'%s','%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1, `ip`='%s'",
  998. tPtr->RefID,
  999. //tPtr->XAddrs,
  1000. tPath,
  1001. tIpBuf,
  1002. tPtr->MAC,
  1003. tPtr->Hardware,
  1004. tPtr->Name,
  1005. tProto,
  1006. //tPtr->XAddrs,
  1007. tIpBuf
  1008. );
  1009. }
  1010. #ifdef DEBUG_ALL
  1011. LOG(tQBuf);
  1012. #endif
  1013. m_pDataStorage->SilentQuery( tQBuf );
  1014. return true;
  1015. };
  1016. return false;
  1017. };
  1018. uint32_t sqliteDBC::addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height, uint16_t fps, uint16_t den ){
  1019. uint32_t RetVal = 0;
  1020. if( m_bStoIsConnected ) {
  1021. char tQBuf[1024];
  1022. char tM5[33];
  1023. CSTR tMD5 = MD5String( path );
  1024. if( tMD5 != NULL ) {
  1025. memcpy( tM5, tMD5, 33 );
  1026. tM5[32]=(char)0;
  1027. free( tMD5 );
  1028. sprintf(tQBuf,"INSERT INTO cameras (`online`,`uuid`,`type`,`status`,`hardware`,`name`,`ip`) VALUES (1,'%s',10,0,'%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1",
  1029. tM5,
  1030. hardware,
  1031. name,
  1032. path
  1033. );
  1034. #ifdef DEBUG_ALL
  1035. LOG(tQBuf);
  1036. #endif
  1037. uint32_t camID = (uint32_t) m_pDataStorage->QueryID( tQBuf );
  1038. if ( camID == 0 ) {
  1039. camID = getCamId( tM5 );
  1040. };
  1041. sprintf(tQBuf, "INSERT INTO `media_streams`(`source_id`,`source_type`,`valid`,`name`,`token`,`img_width`,`img_height`,`mrl_proto`,`mrl`,`picture_proto`,`fps`) VALUES(%d,'A',1,'%s','%s',%d,%d,'v4l2','%s','v4l2',%d) ON CONFLICT(`source_id`,`token`) DO UPDATE SET `valid`=1, img_width=%d, img_height=%d, `fps`=%d",
  1042. camID, name, tM5, width, height, path, fps, width, height, fps );
  1043. #ifdef DEBUG_ALL
  1044. LOG(tQBuf);
  1045. #endif
  1046. RetVal = (uint32_t) m_pDataStorage->QueryID( tQBuf );
  1047. if( RetVal == 0 ){
  1048. RetVal = getMediaStreamID( camID, tM5 );
  1049. };
  1050. };
  1051. };
  1052. return RetVal;
  1053. };
  1054. uint32_t sqliteDBC::addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  1055. uint32_t RetVal = 0;
  1056. if( m_bStoIsConnected ) {
  1057. char tQBuf[MAX_PATH_LEN];
  1058. sprintf( tQBuf, "INSERT INTO `networks`(`nif_id`,`type`,`address`,`gateway`,`mask`,`broadcast`) VALUES (%d,%d,'%s','%s','%s','%s') ON CONFLICT(`nif_id`,`type`) DO UPDATE SET `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s'",
  1059. NIF_ID,
  1060. net_type,
  1061. address,
  1062. gateway,
  1063. mask,
  1064. broadcast,
  1065. address,
  1066. gateway,
  1067. mask,
  1068. broadcast
  1069. );
  1070. #ifdef DEBUG_ALL
  1071. LOG(tQBuf);
  1072. #endif
  1073. RetVal = m_pDataStorage->QueryID( tQBuf );
  1074. // On Update IF data no need to return ID
  1075. //if( RetVal == 0 ) {
  1076. // RetVal = getNetworkInterfaceID( tKey );
  1077. //};
  1078. };
  1079. return RetVal;
  1080. };
  1081. uint32_t sqliteDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  1082. uint32_t RetVal = 0;
  1083. if( m_bStoIsConnected ) {
  1084. char tQBuf[MAX_PATH_LEN];
  1085. bool ena_routing = true;
  1086. if( OUTBOUND_NIF == 0 ){
  1087. ena_routing = false;
  1088. };
  1089. if( ena_dhcp ){
  1090. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  1091. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  1092. return 0;
  1093. };
  1094. sprintf(tQBuf, "INSERT INTO `network_infrastructure`(`nif_id`,`enable_routing`,`outbond_nif`,`enable_dhcp`,`dhcp_range_begin`,`dhcp_range_end`,`dhcp_range_mask`,`dhcp_lease_time`) VALUES (%d,%d,%d,1,'%s','%s','%s','%s') ON CONFLICT(`nif_id`) DO UPDATE SET `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s'",
  1095. NIF_ID,
  1096. ena_routing,
  1097. OUTBOUND_NIF,
  1098. BRANG,
  1099. ERANG,
  1100. MASK,
  1101. LEASE_TIME,
  1102. ena_routing,
  1103. OUTBOUND_NIF,
  1104. BRANG,
  1105. ERANG,
  1106. MASK,
  1107. LEASE_TIME
  1108. );
  1109. } else {
  1110. if( ena_routing ){
  1111. sprintf(tQBuf, "INSERT INTO `network_infrastructure`(`nif_id`,`enable_routing`,`outbond_nif`) VALUES(%d,1,%d) ON CONFLICT(`nif_id`) DO UPDATE SET `enable_routing`=1, `outbond_nif`=%d",
  1112. NIF_ID,
  1113. OUTBOUND_NIF,
  1114. OUTBOUND_NIF
  1115. );
  1116. } else {
  1117. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  1118. return 0;
  1119. };
  1120. };
  1121. #ifdef DEBUG_ALL
  1122. LOG(tQBuf);
  1123. #endif
  1124. RetVal = m_pDataStorage->QueryID( tQBuf );
  1125. // On Update IF data no need to return ID
  1126. if( RetVal == 0 ) {
  1127. RetVal = getNetworkInfrastructureID( NIF_ID );
  1128. };
  1129. };
  1130. return RetVal;
  1131. };
  1132. uint32_t sqliteDBC::addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id ){
  1133. uint32_t RetVal = 0;
  1134. if( m_bStoIsConnected ) {
  1135. char tQBuf[MAX_PATH_LEN];
  1136. char * tKey = MD5String( device );
  1137. if( tKey != NULL ) {
  1138. sprintf( tQBuf, "INSERT INTO `network_interfaces` (`type`,`key`,`device_name`,`mac`,`mode`,`aux_id`) VALUES (%d,'%s','%s','%s',%d,%d) ON CONFLICT(`key`) DO UPDATE SET `mode`=%d,`aux_id`=%d,`mac`='%s'",
  1139. dtype,
  1140. tKey,
  1141. device,
  1142. mac,
  1143. dmode,
  1144. aux_id,
  1145. dmode,
  1146. aux_id,
  1147. mac
  1148. );
  1149. #ifdef DEBUG_ALL
  1150. LOG(tQBuf);
  1151. #endif
  1152. RetVal = m_pDataStorage->QueryID( tQBuf );
  1153. if( RetVal == 0 ) {
  1154. RetVal = getNIF_ID( tKey );
  1155. };
  1156. free( tKey );
  1157. };
  1158. };
  1159. return RetVal;
  1160. };
  1161. uint32_t sqliteDBC::addLocalUART( uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){
  1162. uint32_t RetVal = 0;
  1163. if( m_bStoIsConnected ) {
  1164. char tQBuf[MAX_PATH_LEN];
  1165. sprintf( tQBuf, "INSERT INTO `uart_settings`(`node_id`,`type`,`speed`,`bit`,`parity`,`stop_bit`,`mode`,`port`,`path`) VALUES (%d,%d,%d,%d,'%c',%.1f,%d,%d,'%s') ON CONFLICT(`node_id`,`type`,`path`) DO UPDATE SET `id`=`id`",
  1166. m_nServerNodeID,
  1167. utype,
  1168. speed,
  1169. bit,
  1170. parity,
  1171. stop_bit,
  1172. mode,
  1173. port,
  1174. PATH
  1175. );
  1176. #ifdef DEBUG_ALL
  1177. LOG(tQBuf);
  1178. #endif
  1179. RetVal = m_pDataStorage->QueryID( tQBuf );
  1180. if( RetVal == 0 ) {
  1181. RetVal = getUartID( m_nServerNodeID, utype, PATH );
  1182. };
  1183. };
  1184. return RetVal;
  1185. };
  1186. uint32_t sqliteDBC::addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id ){
  1187. uint32_t RetVal = 0;
  1188. if( m_bStoIsConnected ) {
  1189. char tQBuf[MAX_PATH_LEN];
  1190. sprintf( tQBuf, "INSERT INTO `wifis` (`nif_id`,`mode`,`aux_id`,`SSID`,`password`,`encryption_type`) VALUES (%d,%d,%d,'%s','%s',%d) ON CONFLICT (`nif_id`) DO UPDATE SET `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d",
  1191. NIF_ID,
  1192. mode,
  1193. router_id,
  1194. SSID,
  1195. password,
  1196. encryption,
  1197. mode,
  1198. router_id,
  1199. SSID,
  1200. password,
  1201. encryption
  1202. );
  1203. #ifdef DEBUG_ALL
  1204. LOG(tQBuf);
  1205. #endif
  1206. RetVal = m_pDataStorage->QueryID( tQBuf );
  1207. if( RetVal == 0 ) {
  1208. RetVal = getWiFi_ID( NIF_ID );
  1209. };
  1210. };
  1211. return RetVal;
  1212. };
  1213. bool sqliteDBC::cleanLRFMask( uint32_t maskID, bool deleteMask ){
  1214. if( m_bStoIsConnected ) {
  1215. char tQBuf[MAX_PATH_LEN];
  1216. //sprintf( tQBuf, "DELETE FROM `lrf_mask_trace_zones` WHERE `zone_id` IN ( SELECT `id` FROM `lrf_mask_traces` WHERE `mask_id`=%d )", maskID );
  1217. #ifdef DEBUG_ALL
  1218. //LOG(tQBuf);
  1219. #endif
  1220. //m_pDataStorage->SilentQuery( tQBuf );
  1221. //sprintf( tQBuf, "DELETE FROM `lrf_mask_traces` WHERE `mask_id`=%d", maskID );
  1222. #ifdef DEBUG_ALL
  1223. //LOG(tQBuf);
  1224. #endif
  1225. //m_pDataStorage->SilentQuery( tQBuf );
  1226. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertex_points` WHERE `vertex_id` IN ( SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d )", maskID );
  1227. #ifdef DEBUG
  1228. LOG(tQBuf);
  1229. #endif
  1230. m_pDataStorage->SilentQuery( tQBuf );
  1231. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", maskID );
  1232. #ifdef DEBUG_ALL
  1233. LOG(tQBuf);
  1234. #endif
  1235. m_pDataStorage->SilentQuery( tQBuf );
  1236. //Delete Mask Itself!
  1237. if ( deleteMask ) {
  1238. sprintf( tQBuf, "DELETE FROM `lrf_masks` WHERE `id`=%d", maskID );
  1239. #ifdef DEBUG_ALL
  1240. LOG(tQBuf);
  1241. #endif
  1242. m_pDataStorage->SilentQuery( tQBuf );
  1243. };
  1244. return true;
  1245. };
  1246. return false;
  1247. };
  1248. bool sqliteDBC::cleanLRFWidthTable( uint32_t sensorID ){
  1249. if( m_bStoIsConnected ) {
  1250. char tQBuf[MAX_PATH_LEN];
  1251. sprintf( tQBuf, "DELETE FROM `lrf_detection_width_tables` WHERE `aux_id`=%d", sensorID );
  1252. #ifdef DEBUG_ALL
  1253. LOG(tQBuf);
  1254. #endif
  1255. m_pDataStorage->SilentQuery( tQBuf );
  1256. return true;
  1257. };
  1258. return false;
  1259. };
  1260. bool sqliteDBC::cleanResources( bool all ){
  1261. if( m_bStoIsConnected ) {
  1262. char tQBuf[MAX_PATH_LEN];
  1263. if( all ) {
  1264. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id`=%d", m_nServerNodeID );
  1265. } else {
  1266. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE ( `node_id`=%d ) AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", m_nServerNodeID );
  1267. };
  1268. #ifdef DEBUG_ALL
  1269. LOG(tQBuf);
  1270. #endif
  1271. m_pDataStorage->SilentQuery( tQBuf );
  1272. return true;
  1273. };
  1274. return false;
  1275. };
  1276. bool sqliteDBC::wipeServerResources(){
  1277. if( m_bStoIsConnected ) {
  1278. char tQBuf[MAX_PATH_LEN];
  1279. sprintf( tQBuf, "DELETE FROM `resources` WHERE `node_id`=%d", m_nServerNodeID );
  1280. #ifdef DEBUG_ALL
  1281. LOG(tQBuf);
  1282. #endif
  1283. m_pDataStorage->SilentQuery( tQBuf );
  1284. return true;
  1285. };
  1286. return false;
  1287. };
  1288. uint32_t sqliteDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
  1289. uint32_t RetVal = 0;
  1290. if( m_bStoIsConnected ) {
  1291. char tQBuf[MAX_PATH_LEN];
  1292. sprintf( tQBuf, "INSERT INTO `lrf_masks`(`sensor_id`,`lrf_id`,`layer`) VALUES(%d,%d,%d) ON CONFLICT(`sensor_id`,`lrf_id`,`layer`) DO UPDATE SET `layer`=%d",
  1293. devID,
  1294. lrfID,
  1295. layerID,
  1296. layerID
  1297. );
  1298. #ifdef DEBUG
  1299. LOG(tQBuf);
  1300. #endif
  1301. RetVal = m_pDataStorage->QueryID( tQBuf );
  1302. if( RetVal == 0 ) {
  1303. RetVal = getLRFMaskID( devID, lrfID, layerID );
  1304. };
  1305. };
  1306. return RetVal;
  1307. };
  1308. uint32_t sqliteDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t vertexID, uint8_t r, uint8_t g, uint8_t b ){
  1309. uint32_t RetVal = 0;
  1310. if( m_bStoIsConnected ) {
  1311. char tQBuf[MAX_PATH_LEN];
  1312. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes`(`mask_id`,`vertex_id`,`r`,`g`,`b`) VALUES(%d,%d,%d,%d,%d)",
  1313. maskID,
  1314. vertexID,
  1315. r,
  1316. g,
  1317. b
  1318. );
  1319. #ifdef DEBUG_ALL
  1320. LOG(tQBuf);
  1321. #endif
  1322. RetVal = m_pDataStorage->QueryID( tQBuf );
  1323. if( RetVal == 0 ) {
  1324. RetVal = getLRFMaskPolygoneID( maskID, vertexID );
  1325. };
  1326. };
  1327. return RetVal;
  1328. };
  1329. bool sqliteDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){
  1330. if( m_bStoIsConnected ) {
  1331. char tQBuf[MAX_PATH_LEN];
  1332. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points`(`vertex_id`,`x`,`y`) VALUES(%d,%d,%d)",
  1333. polyID,
  1334. x,
  1335. y
  1336. );
  1337. #ifdef DEBUG_ALL
  1338. LOG(tQBuf);
  1339. #endif
  1340. m_pDataStorage->SilentQuery( tQBuf );
  1341. return true;
  1342. };
  1343. return false;
  1344. };
  1345. bool sqliteDBC::addLRFWidthTable( uint32_t sensorID, PWIDTH_TABLE ptr ){
  1346. if( m_bStoIsConnected ) {
  1347. char tQBuf[MAX_PATH_LEN];
  1348. float kK = 100.0f / ptr->nCount;
  1349. for( int i = 0; i < ptr->nCount; i++ ) {
  1350. uint16_t CC = kK * i;
  1351. sprintf(tQBuf, "INSERT INTO `lrf_detection_width_tables`(`aux_id`,`width_k`,`range_k`) VALUES(%d,%d,%d)",
  1352. sensorID,
  1353. ptr->pTable[i],
  1354. CC
  1355. );
  1356. #ifdef DEBUG_ALL
  1357. LOG(tQBuf);
  1358. #endif
  1359. m_pDataStorage->SilentQuery( tQBuf );
  1360. };
  1361. return true;
  1362. };
  1363. return false;
  1364. };
  1365. bool sqliteDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){
  1366. bool rVal = false;
  1367. if( ptr != NULL ){
  1368. if( m_bRepIsConnected ){
  1369. char tQBuf[MAX_PATH_LEN];
  1370. uint32_t pic_id;
  1371. sprintf( tQBuf, "%s/%s/%s/%s/%s.%s",
  1372. m_pDbReportBase, m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY, ptr->md5, ext );
  1373. #ifdef DEBUG_ALL
  1374. LOG(tQBuf);
  1375. #endif
  1376. FILE *fd = fopen( tQBuf, "wb+" );
  1377. if( fd ){
  1378. fwrite( ptr->data, 1, ptr->data_size, fd );
  1379. fclose(fd);
  1380. chown( tQBuf, getUserUid(web_access_user), getUserGid(web_access_group) );
  1381. } else {
  1382. LOG_ERROR("Error Saving Captured picture!");
  1383. return rVal;
  1384. };
  1385. sprintf( tQBuf, "INSERT INTO pictures(`media_stream_id`,`uts`,`uts_ms`,`md5`,`ext`) VALUES(%d,%d,0,'%s','%s')",
  1386. ptr->stream_id, ptr->ts, ptr->md5, ext );
  1387. pic_id = (uint32_t) m_pDataReports->QueryID( tQBuf );
  1388. if ( pic_id ) {
  1389. for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) {
  1390. sprintf( tQBuf, "INSERT INTO `events_2_pictures`(`evt_id`,`picture_id`) VALUES(%d,%d)", (*idx), pic_id );
  1391. m_pDataReports->SilentQuery( tQBuf );
  1392. };
  1393. rVal = true;
  1394. };
  1395. };
  1396. };
  1397. return rVal;
  1398. };
  1399. uint32_t sqliteDBC::addResource( uint8_t type, CSTR devName, uint32_t auxID ){
  1400. uint32_t RetVal = 0;
  1401. if( m_bStoIsConnected ){
  1402. char tQBuf[2048];
  1403. sprintf( tQBuf, "%d:%d:%s", m_nServerNodeID, type, devName );
  1404. CSTR tMD5 = MD5String( tQBuf );
  1405. if( tMD5 ) {
  1406. sprintf( tQBuf, "INSERT INTO `resources`(`node_id`,`type`,`md5`,`aux_id`,`device`,`active`) VALUES (%d,%d,'%s',%d,'%s',1) ON CONFLICT(`md5`) DO UPDATE SET `active`=1, `aux_id`=%d",
  1407. m_nServerNodeID,
  1408. type,
  1409. tMD5,
  1410. auxID,
  1411. devName,
  1412. auxID
  1413. );
  1414. free( tMD5 );
  1415. #ifdef DEBUG_ALL
  1416. LOG(tQBuf);
  1417. #endif
  1418. RetVal = (uint32_t) m_pDataStorage->QueryID( tQBuf );
  1419. if( RetVal == 0 ) {
  1420. RetVal = getResourceID( m_nServerNodeID, type, auxID );
  1421. };
  1422. };
  1423. };
  1424. return RetVal;
  1425. };
  1426. bool sqliteDBC::addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t frame, uint32_t tss, uint32_t tms ){
  1427. if( m_bRepIsConnected ){
  1428. char tQBuf[2048];
  1429. sprintf( tQBuf, "INSERT INTO `events_2_videos`(`evt_id`,`video_id`,`frame`,`tss`,`tms`) VALUES(%d,%d,%d,%d,%d)",
  1430. evtID,
  1431. videoID,
  1432. frame,
  1433. tss,
  1434. tms
  1435. );
  1436. #ifdef DEBUG_ALL
  1437. LOG(tQBuf);
  1438. #endif
  1439. m_pDataReports->SilentQuery( tQBuf );
  1440. };
  1441. return false;
  1442. };
  1443. uint32_t sqliteDBC::addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t tss, uint32_t tms, uint32_t fps ){
  1444. uint32_t RetVal = 0;
  1445. if( m_bRepIsConnected ){
  1446. updateStats( false, true );
  1447. char tQBuf[2048];
  1448. sprintf( tQBuf, "INSERT INTO `videos`(`media_stream_id`,`md5`,`uts`,`uts_ms`,`ext`,`fps`) VALUES(%d,'%s',%d,%d,'%s',%d)",
  1449. streamID,
  1450. md5,
  1451. tss,
  1452. tms,
  1453. ext,
  1454. fps
  1455. );
  1456. #ifdef DEBUG
  1457. LOG(tQBuf);
  1458. #endif
  1459. RetVal = (uint32_t) m_pDataReports->QueryID( tQBuf );
  1460. };
  1461. return RetVal;
  1462. };
  1463. DBC_MODULE_EMBED_VIDEO_DATA *sqliteDBC::getEmbedVideoData( uint32_t ID ){
  1464. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  1465. if( m_bStoIsConnected ) {
  1466. char tQBuf[MAX_PATH_LEN];
  1467. AAssoc *result;
  1468. sprintf( tQBuf, "SELECT * FROM `module_eve` WHERE `id`=%d", ID );
  1469. #ifdef DEBUG_ALL
  1470. LOG(tQBuf);
  1471. #endif
  1472. result = m_pDataStorage->Query( tQBuf );
  1473. if( result!= NULL ) {
  1474. if( result->size() > 0 ) {
  1475. Assoc *cArr;
  1476. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  1477. if( tPtr!= NULL ) {
  1478. Assoc::iterator it;
  1479. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  1480. cArr = result->at(0);
  1481. it = cArr->find("output_mode");
  1482. if( it != cArr->end() ){
  1483. tPtr->output_mode = atoi( it->second.c_str() );
  1484. };
  1485. //Togo Bug
  1486. if ( tPtr->output_mode == 0) tPtr->output_mode = 2;//Video Output
  1487. it = cArr->find("web_port");
  1488. if( it != cArr->end() ){
  1489. tPtr->port = atoi( it->second.c_str() );
  1490. };
  1491. it = cArr->find("width");
  1492. if( it != cArr->end() ){
  1493. tPtr->width = atoi( it->second.c_str() );
  1494. };
  1495. it = cArr->find("height");
  1496. if( it != cArr->end() ){
  1497. tPtr->height = atoi( it->second.c_str() );
  1498. };
  1499. it = cArr->find("compression_quality");
  1500. if( it != cArr->end() ){
  1501. tPtr->compression_quality = atoi( it->second.c_str() );
  1502. };
  1503. it = cArr->find("show_ts");
  1504. if( it != cArr->end() ){
  1505. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  1506. };
  1507. it = cArr->find("ts_x");
  1508. if( it != cArr->end() ){
  1509. tPtr->ts_x = atoi( it->second.c_str() );
  1510. };
  1511. it = cArr->find("ts_y");
  1512. if( it != cArr->end() ){
  1513. tPtr->ts_y = atoi( it->second.c_str() );
  1514. };
  1515. it = cArr->find("ts_font_face");
  1516. if( it != cArr->end() ){
  1517. tPtr->ts_font_face = atoi( it->second.c_str() );
  1518. };
  1519. it = cArr->find("ts_font_scale");
  1520. if( it != cArr->end() ){
  1521. tPtr->ts_font_scale = atof( it->second.c_str() );
  1522. };
  1523. it = cArr->find("ts_font_thickness");
  1524. if( it != cArr->end() ){
  1525. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  1526. };
  1527. it = cArr->find("ts_line_type");
  1528. if( it != cArr->end() ){
  1529. tPtr->ts_line_type = atoi( it->second.c_str() );
  1530. };
  1531. it = cArr->find("ts_transperant");
  1532. if( it != cArr->end() ){
  1533. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  1534. };
  1535. it = cArr->find("show_label");
  1536. if( it != cArr->end() ){
  1537. tPtr->show_label = (bool)atoi( it->second.c_str() );
  1538. };
  1539. it = cArr->find("label_x");
  1540. if( it != cArr->end() ){
  1541. tPtr->label_x = atoi( it->second.c_str() );
  1542. };
  1543. it = cArr->find("label_y");
  1544. if( it != cArr->end() ){
  1545. tPtr->label_y = atoi( it->second.c_str() );
  1546. };
  1547. it = cArr->find("label_font_face");
  1548. if( it != cArr->end() ){
  1549. tPtr->label_font_face = atoi( it->second.c_str() );
  1550. };
  1551. it = cArr->find("label_font_scale");
  1552. if( it != cArr->end() ){
  1553. tPtr->label_font_scale = atof( it->second.c_str() );
  1554. };
  1555. it = cArr->find("label_font_thickness");
  1556. if( it != cArr->end() ){
  1557. tPtr->label_font_thickness = atoi( it->second.c_str() );
  1558. };
  1559. it = cArr->find("label_line_type");
  1560. if( it != cArr->end() ){
  1561. tPtr->label_line_type = atoi( it->second.c_str() );
  1562. };
  1563. it = cArr->find("label_transperant");
  1564. if( it != cArr->end() ){
  1565. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  1566. };
  1567. it = cArr->find("show_logo");
  1568. if( it != cArr->end() ){
  1569. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  1570. };
  1571. it = cArr->find("logo_w");
  1572. if( it != cArr->end() ){
  1573. tPtr->logo_w = atoi( it->second.c_str() );
  1574. };
  1575. it = cArr->find("logo_h");
  1576. if( it != cArr->end() ){
  1577. tPtr->logo_h = atoi( it->second.c_str() );
  1578. };
  1579. it = cArr->find("logo_x");
  1580. if( it != cArr->end() ){
  1581. tPtr->logo_x = atoi( it->second.c_str() );
  1582. };
  1583. it = cArr->find("logo_y");
  1584. if( it != cArr->end() ){
  1585. tPtr->logo_y = atoi( it->second.c_str() );
  1586. };
  1587. it = cArr->find("logo_md5");
  1588. if( it != cArr->end() ){
  1589. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  1590. tPtr->logo_md5[32]=(char)0;
  1591. };
  1592. };
  1593. };
  1594. };
  1595. deleteResult( result );
  1596. };
  1597. return tPtr;
  1598. };
  1599. DBC_MEDIA_STREAM_DATA *sqliteDBC::getMediaStreamData(uint32_t ID){
  1600. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  1601. if( m_bStoIsConnected ){
  1602. char tQBuf[CTEXT];
  1603. AAssoc *result;
  1604. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  1605. #ifdef DEBUG_ALL
  1606. LOG(tQBuf);
  1607. #endif
  1608. result = m_pDataStorage->Query( tQBuf );
  1609. if( result!= NULL ) {
  1610. if( result->size() > 0 ) {
  1611. Assoc *cArr;
  1612. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  1613. if( tVal != NULL ) {
  1614. memset( tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA) );
  1615. Assoc::iterator it;
  1616. cArr = result->at(0);
  1617. tVal->id = ID;
  1618. it = cArr->find("source_id");
  1619. if( it != cArr->end() ){
  1620. tVal->source_id = atoi( it->second.c_str() );
  1621. };
  1622. it = cArr->find("source_type");
  1623. if( it != cArr->end() ){
  1624. sprintf( tVal->source_type, it->second.c_str() );
  1625. };
  1626. it = cArr->find("valid");
  1627. if( it != cArr->end() ){
  1628. tVal->valid = (bool) atoi( it->second.c_str() );
  1629. };
  1630. it = cArr->find("token");
  1631. if( it != cArr->end() ){
  1632. sprintf( tVal->token, it->second.c_str() );
  1633. };
  1634. it = cArr->find("img_width");
  1635. if( it != cArr->end() ){
  1636. tVal->width = atoi( it->second.c_str() );
  1637. };
  1638. it = cArr->find("img_height");
  1639. if( it != cArr->end() ){
  1640. tVal->height = atoi( it->second.c_str() );
  1641. };
  1642. it = cArr->find("fps");
  1643. if( it != cArr->end() ){
  1644. tVal->fps = atoi( it->second.c_str() );
  1645. };
  1646. it = cArr->find("compression_type");
  1647. if( it != cArr->end() ){
  1648. sprintf(tVal->c_type, it->second.c_str());
  1649. };
  1650. it = cArr->find("mrl_proto");
  1651. if( it != cArr->end() ){
  1652. sprintf( tVal->mrl_proto, it->second.c_str() );
  1653. };
  1654. it = cArr->find("mrl_port");
  1655. if( it != cArr->end() ){
  1656. tVal->mrl_port = atoi( it->second.c_str() );
  1657. };
  1658. it = cArr->find("mrl");
  1659. if( it != cArr->end() ){
  1660. sprintf( tVal->mrl, it->second.c_str() );
  1661. };
  1662. };
  1663. };
  1664. };
  1665. deleteResult( result );
  1666. };
  1667. return tVal;
  1668. };
  1669. uint32_t sqliteDBC::getMediaStreamID( uint32_t source_id, CSTR token ){
  1670. uint32_t RetVal = 0;
  1671. if( m_bStoIsConnected ){
  1672. char tQBuf[CTEXT];
  1673. AAssoc *result;
  1674. sprintf(tQBuf, "SELECT `id` FROM `media_streams` WHERE `source_id`=%d AND `token`='%s'", source_id, token );
  1675. #ifdef DEBUG_ALL
  1676. LOG(tQBuf);
  1677. #endif
  1678. result = m_pDataStorage->Query( tQBuf );
  1679. if( result!= NULL ) {
  1680. if( result->size() > 0 ) {
  1681. Assoc *cArr;
  1682. Assoc::iterator it;
  1683. cArr = result->at(0);
  1684. it = cArr->find("id");
  1685. if( it != cArr->end() ){
  1686. RetVal = atoi( it->second.c_str() );
  1687. };
  1688. };
  1689. };
  1690. deleteResult( result );
  1691. };
  1692. return RetVal;
  1693. };
  1694. DBC_MODEM_MANAGER_DATA *sqliteDBC::getModemManagerData( uint32_t ID ){
  1695. DBC_MODEM_MANAGER_DATA *tVal = NULL;
  1696. if( m_bStoIsConnected ){
  1697. char tQBuf[CTEXT];
  1698. AAssoc *result;
  1699. sprintf(tQBuf, "SELECT * FROM `module_modem` WHERE `id`=%d", ID);
  1700. #ifdef DEBUG_ALL
  1701. LOG(tQBuf);
  1702. #endif
  1703. result = m_pDataStorage->Query( tQBuf );
  1704. if( result!= NULL ) {
  1705. if( result->size() > 0 ) {
  1706. Assoc *cArr;
  1707. tVal = (DBC_MODEM_MANAGER_DATA*) malloc(sizeof(DBC_MODEM_MANAGER_DATA));
  1708. if( tVal != NULL ) {
  1709. memset( tVal, 0 , sizeof( DBC_MODEM_MANAGER_DATA ) );
  1710. tVal->id = ID;
  1711. Assoc::iterator it;
  1712. cArr = result->at(0);
  1713. it = cArr->find("modem_id");
  1714. if( it != cArr->end() ){
  1715. tVal->modem_id = atoi( it->second.c_str() );
  1716. };
  1717. it = cArr->find("evt_mode");
  1718. if( it != cArr->end() ){
  1719. tVal->evt_mode = atoi( it->second.c_str() );
  1720. };
  1721. it = cArr->find("time_window");
  1722. if( it != cArr->end() ){
  1723. tVal->time_window = atoi( it->second.c_str() );
  1724. };
  1725. it = cArr->find("sms_enabled");
  1726. if( it != cArr->end() ){
  1727. tVal->sms_enabled =(bool) atoi( it->second.c_str() );
  1728. };
  1729. it = cArr->find("call_enabled");
  1730. if( it != cArr->end() ){
  1731. tVal->call_enabled =(bool) atoi( it->second.c_str() );
  1732. };
  1733. it = cArr->find("call_hangup_wait");
  1734. if( it != cArr->end() ){
  1735. tVal->call_hangup_wait = atoi( it->second.c_str() );
  1736. };
  1737. };
  1738. };
  1739. };
  1740. deleteResult( result );
  1741. };
  1742. return tVal;
  1743. };
  1744. DBC_MODEM_PHONEBOOK_RECORD *sqliteDBC::getModemPhonebookRecord( uint32_t ID ){
  1745. DBC_MODEM_PHONEBOOK_RECORD *tVal = NULL;
  1746. if( m_bStoIsConnected ){
  1747. char tQBuf[CTEXT];
  1748. AAssoc *result;
  1749. sprintf(tQBuf, "SELECT * FROM `module_modem_phonebook` WHERE `id`=%d", ID);
  1750. #ifdef DEBUG_ALL
  1751. LOG(tQBuf);
  1752. #endif
  1753. result = m_pDataStorage->Query( tQBuf );
  1754. if( result!= NULL ) {
  1755. if( result->size() > 0 ) {
  1756. Assoc *cArr;
  1757. tVal = (DBC_MODEM_PHONEBOOK_RECORD*) malloc(sizeof(DBC_MODEM_PHONEBOOK_RECORD));
  1758. if( tVal != NULL ) {
  1759. memset( tVal, 0 , sizeof( DBC_MODEM_PHONEBOOK_RECORD ) );
  1760. Assoc::iterator it;
  1761. cArr = result->at(0);
  1762. it = cArr->find("id");
  1763. if( it != cArr->end() ){
  1764. tVal->id = atoi( it->second.c_str() );
  1765. };
  1766. it = cArr->find("number");
  1767. if( it != cArr->end() ){
  1768. strncpy( tVal->number, it->second.c_str(), 63 );
  1769. tVal->number[63]=(char)0;
  1770. };
  1771. it = cArr->find("mode");
  1772. if( it != cArr->end() ){
  1773. tVal->mode = atoi( it->second.c_str() );
  1774. };
  1775. it = cArr->find("trig_special");
  1776. if( it != cArr->end() ){
  1777. tVal->trigger_special = atoi( it->second.c_str() );
  1778. };
  1779. it = cArr->find("label");
  1780. if( it != cArr->end() ){
  1781. strncpy( tVal->label, it->second.c_str(), 63 );
  1782. tVal->label[63]=(char)0;
  1783. };
  1784. it = cArr->find("custom_msg");
  1785. if( it != cArr->end() ){
  1786. strncpy( tVal->custom_msg, it->second.c_str(), 127 );
  1787. tVal->custom_msg[127]=(char)0;
  1788. };
  1789. };
  1790. };
  1791. };
  1792. deleteResult( result );
  1793. };
  1794. return tVal;
  1795. };
  1796. DBC_MODULE_DATA *sqliteDBC::getModuleData( uint32_t ID ){
  1797. DBC_MODULE_DATA *tVal = NULL;
  1798. if( m_bStoIsConnected ){
  1799. char tQBuf[CTEXT];
  1800. AAssoc *result;
  1801. sprintf(tQBuf, "SELECT * FROM modules WHERE `id`=%d", ID );
  1802. #ifdef DEBUG_ALL
  1803. LOG(tQBuf);
  1804. #endif
  1805. result = m_pDataStorage->Query( tQBuf );
  1806. if( result!= NULL ) {
  1807. if( result->size() > 0 ) {
  1808. Assoc *cArr;
  1809. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  1810. if( tVal != NULL ) {
  1811. Assoc::iterator it;
  1812. cArr = result->at(0);
  1813. it = cArr->find("id");
  1814. if( it != cArr->end() ){
  1815. tVal->module_id = atoi( it->second.c_str() );
  1816. };
  1817. it = cArr->find("aux_id");
  1818. if( it != cArr->end() ){
  1819. tVal->aux_id = atoi( it->second.c_str() );
  1820. };
  1821. it = cArr->find("type");
  1822. if( it != cArr->end() ){
  1823. tVal->type = atoi( it->second.c_str() );
  1824. };
  1825. it = cArr->find("enabled");
  1826. if( it != cArr->end() ){
  1827. tVal->enabled = (bool)atoi( it->second.c_str() );
  1828. };
  1829. };
  1830. };
  1831. };
  1832. deleteResult( result );
  1833. };
  1834. return tVal;
  1835. };
  1836. DBC_LRF_INI *sqliteDBC::getINIData( uint32_t lrfID ){
  1837. DBC_LRF_INI * tVal = NULL;
  1838. if( m_bStoIsConnected ){
  1839. char tQBuf[CTEXT];
  1840. AAssoc *result;
  1841. sprintf(tQBuf, "SELECT * FROM `lrf_ini_settings` WHERE `sensor_id`=%d", lrfID );
  1842. #ifdef DEBUG_ALL
  1843. LOG(tQBuf);
  1844. #endif
  1845. result = m_pDataStorage->Query( tQBuf );
  1846. if( result!= NULL ) {
  1847. if( result->size() > 0 ) {
  1848. Assoc *cArr;
  1849. tVal = (DBC_LRF_INI*) malloc(sizeof(DBC_LRF_INI));
  1850. if( tVal != NULL ) {
  1851. memset( tVal, 0 , sizeof(DBC_LRF_INI));
  1852. Assoc::iterator it;
  1853. cArr = result->at(0);
  1854. it = cArr->find("AUTORESET_ENABLE");
  1855. if( it != cArr->end() ){
  1856. tVal->_AUTO_RESET_ENABLE = (bool) atoi( it->second.c_str() );
  1857. };
  1858. it = cArr->find("AUTORESET_INTERLEAVE");
  1859. if( it != cArr->end() ){
  1860. tVal->_AUTO_RESET_INTERLEAVE = atoi( it->second.c_str() );
  1861. };
  1862. it = cArr->find("AUTORESET_TIMEOUT");
  1863. if( it != cArr->end() ){
  1864. tVal->_AUTO_RESET_TIMEOUT = atoi( it->second.c_str() );
  1865. };
  1866. it = cArr->find("BOARD_TEMPERATURE");
  1867. if( it != cArr->end() ){
  1868. tVal->_BOARD_TEMPERATURE = atoi( it->second.c_str() );
  1869. };
  1870. it = cArr->find("BOARD_ZEROSHIFT");
  1871. if( it != cArr->end() ){
  1872. tVal->_BOARD_ZEROSHIFT = atoi( it->second.c_str() );
  1873. };
  1874. it = cArr->find("BOARD_SPEED");
  1875. if( it != cArr->end() ){
  1876. tVal->_BOARD_SPEED = atoi( it->second.c_str() );
  1877. };
  1878. it = cArr->find("RUN_DIR");
  1879. if( it != cArr->end() ){
  1880. tVal->_RUN_DIR = atoi( it->second.c_str() );
  1881. };
  1882. it = cArr->find("NO_BLACK_TARGETS");
  1883. if( it != cArr->end() ){
  1884. tVal->_NO_BLACK_TARGETS = atoi( it->second.c_str() );
  1885. };
  1886. it = cArr->find("JUST_MOVING_TARGETS");
  1887. if( it != cArr->end() ){
  1888. tVal->_JUST_MOVING_TARGETS = (bool) atoi( it->second.c_str() );
  1889. };
  1890. it = cArr->find("JUST_MOVING_RADIAL");
  1891. if( it != cArr->end() ){
  1892. tVal->_JUST_MOVING_RADIAL = (bool) atoi( it->second.c_str() );
  1893. };
  1894. it = cArr->find("JUST_MOVING_DISTANCE");
  1895. if( it != cArr->end() ){
  1896. tVal->_JUST_MOVING_DISTANCE = (bool) atoi( it->second.c_str() );
  1897. };
  1898. it = cArr->find("FREEZ_FIRST_TH");
  1899. if( it != cArr->end() ){
  1900. tVal->_FREEZ_FIRST_TH = (bool) atoi( it->second.c_str() );
  1901. };
  1902. it = cArr->find("SAVE_FIRST_TH");
  1903. if( it != cArr->end() ){
  1904. tVal->_SAVE_FIRST_TH = (bool) atoi( it->second.c_str() );
  1905. };
  1906. };
  1907. };
  1908. };
  1909. deleteResult( result );
  1910. };
  1911. return tVal;
  1912. };
  1913. bool sqliteDBC::getEventSessionStatus( uint32_t nodeID ){
  1914. bool rv = false;
  1915. if( m_bRepIsConnected ){
  1916. char tQBuf[CTEXT];
  1917. AAssoc *result;
  1918. //Since Unimodule -> no need to check NodeID
  1919. //sprintf( tQBuf, "SELECT `evt_type` FROM `events` WHERE `node_id`=%d AND ( `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ) ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", nodeID, EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO );
  1920. sprintf( tQBuf, "SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO );
  1921. #ifdef DEBUG_ALL
  1922. LOG(tQBuf);
  1923. #endif
  1924. result = m_pDataReports->Query( tQBuf );
  1925. if( result!= NULL ) {
  1926. if( result->size() > 0 ) {
  1927. Assoc *cArr;
  1928. Assoc::iterator it;
  1929. cArr = result->at(0);
  1930. it = cArr->find("evt_type");
  1931. if( it != cArr->end() ){
  1932. if( atoi( it->second.c_str() ) == EVT_LRF_START_SESSION ) rv = true;
  1933. };
  1934. };
  1935. };
  1936. deleteResult( result );
  1937. };
  1938. return rv;
  1939. };
  1940. /*
  1941. * The Last TS is from the current report (as latest)
  1942. */
  1943. uint32_t sqliteDBC::getLastEventTS(){
  1944. uint32_t rv = 0;
  1945. if( m_bRepIsConnected ){
  1946. char tQBuf[CTEXT];
  1947. AAssoc *result;
  1948. sprintf( tQBuf, "SELECT `ts` FROM `events` ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1" );
  1949. #ifdef DEBUG_ALL
  1950. LOG(tQBuf);
  1951. #endif
  1952. result = m_pDataReports->Query( tQBuf );
  1953. if( result!= NULL ) {
  1954. if( result->size() > 0 ) {
  1955. Assoc *cArr;
  1956. Assoc::iterator it;
  1957. cArr = result->at(0);
  1958. it = cArr->find("ts");
  1959. if( it != cArr->end() ){
  1960. rv = atoi( it->second.c_str() );
  1961. };
  1962. };
  1963. };
  1964. deleteResult( result );
  1965. };
  1966. return rv;
  1967. };
  1968. /*
  1969. * The first TS is generaly must show a DAY of first registered event so TS fetched
  1970. * from general statistics
  1971. */
  1972. uint32_t sqliteDBC::getFirstEventTS(){
  1973. uint32_t rv = 0;
  1974. if( m_bStaIsConnected ){
  1975. char tQBuf[CTEXT];
  1976. AAssoc *result;
  1977. sprintf( tQBuf, "SELECT `year`,`month`,`day` FROM `days` ORDER BY `year`,`month`,`day` LIMIT 1" );
  1978. #ifdef DEBUG_ALL
  1979. LOG(tQBuf);
  1980. #endif
  1981. result = m_pDataStatistics->Query( tQBuf );
  1982. if( result!= NULL ) {
  1983. if( result->size() > 0 ) {
  1984. REPORT_DIRINFO RDF = { 0 };
  1985. Assoc *cArr;
  1986. Assoc::iterator it;
  1987. cArr = result->at(0);
  1988. it = cArr->find("year");
  1989. if( it != cArr->end() ){
  1990. strncpy( RDF.YEAR, it->second.c_str(), 4 );
  1991. };
  1992. it = cArr->find("month");
  1993. if( it != cArr->end() ){
  1994. strncpy( RDF.MONTH, it->second.c_str(), 2 );
  1995. };
  1996. it = cArr->find("day");
  1997. if( it != cArr->end() ){
  1998. strncpy( RDF.DAY, it->second.c_str(), 2 );
  1999. };
  2000. rv = getTsFromRDF( RDF );
  2001. };
  2002. };
  2003. deleteResult( result );
  2004. };
  2005. return rv;
  2006. };
  2007. bool sqliteDBC::deleteReportDate( uint32_t ts ){
  2008. if( ts ){
  2009. REPORT_DIRINFO tRDF = {0};
  2010. fillRDF( ts, tRDF );
  2011. LOG("Delete RDF Dir");
  2012. if( deleteRDFDir( m_pDbReportBase, tRDF ) ){
  2013. LOG("Dir Deleted OK");
  2014. return deleteReportStat( tRDF );
  2015. };
  2016. };
  2017. return false;
  2018. };
  2019. DBC_LRF_DATA *sqliteDBC::getLRFData( uint32_t ID ){
  2020. DBC_LRF_DATA * tVal = NULL;
  2021. if( m_bStoIsConnected ){
  2022. char tQBuf[CTEXT];
  2023. AAssoc *result;
  2024. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  2025. #ifdef DEBUG_ALL
  2026. LOG(tQBuf);
  2027. #endif
  2028. result = m_pDataStorage->Query( tQBuf );
  2029. if( result!= NULL ) {
  2030. if( result->size() > 0 ) {
  2031. Assoc *cArr;
  2032. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  2033. if( tVal != NULL ) {
  2034. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  2035. Assoc::iterator it;
  2036. tVal->id = ID;
  2037. cArr = result->at(0);
  2038. it = cArr->find("data_status");
  2039. if( it != cArr->end() ){
  2040. tVal->data_status = atoi( it->second.c_str() );
  2041. };
  2042. it = cArr->find("serial");
  2043. if( it != cArr->end() ){
  2044. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  2045. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  2046. };
  2047. it = cArr->find("version");
  2048. if( it != cArr->end() ){
  2049. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  2050. tVal->version[sizeof(tVal->version)-1]=(char)0;
  2051. };
  2052. it = cArr->find("x");
  2053. if( it != cArr->end() ){
  2054. tVal->x = atof( it->second.c_str() );
  2055. };
  2056. it = cArr->find("y");
  2057. if( it != cArr->end() ){
  2058. tVal->y = atof( it->second.c_str() );
  2059. };
  2060. it = cArr->find("z");
  2061. if( it != cArr->end() ){
  2062. tVal->z = atof( it->second.c_str() );
  2063. };
  2064. it = cArr->find("x_rot");
  2065. if( it != cArr->end() ){
  2066. tVal->x_rot = atof( it->second.c_str() );
  2067. };
  2068. it = cArr->find("y_rot");
  2069. if( it != cArr->end() ){
  2070. tVal->y_rot = atof( it->second.c_str() );
  2071. };
  2072. it = cArr->find("z_rot");
  2073. if( it != cArr->end() ){
  2074. tVal->z_rot = atof( it->second.c_str() );
  2075. };
  2076. it = cArr->find("uart_id");
  2077. if( it != cArr->end() ){
  2078. tVal->uart_id = atoi( it->second.c_str() );
  2079. };
  2080. it = cArr->find("device_id");
  2081. if( it != cArr->end() ){
  2082. tVal->device_id = atoi( it->second.c_str() );
  2083. };
  2084. it = cArr->find("ip");
  2085. if( it != cArr->end() ){
  2086. sprintf( tVal->master_host, it->second.c_str() );
  2087. };
  2088. it = cArr->find("aux_ip");
  2089. if( it != cArr->end() ){
  2090. sprintf( tVal->slave_host, it->second.c_str() );
  2091. };
  2092. it = cArr->find("port");
  2093. if( it != cArr->end() ){
  2094. tVal->master_port = atoi( it->second.c_str() );
  2095. };
  2096. it = cArr->find("aux_port");
  2097. if( it != cArr->end() ){
  2098. tVal->slave_port = atoi( it->second.c_str() );
  2099. };
  2100. it = cArr->find("auto_draw");
  2101. if( it != cArr->end() ){
  2102. tVal->auto_draw = atoi( it->second.c_str() );
  2103. };
  2104. it = cArr->find("filter_id");
  2105. if( it != cArr->end() ){
  2106. tVal->filter_id = atoi( it->second.c_str() );
  2107. };
  2108. it = cArr->find("enabled_lrf");
  2109. if( it != cArr->end() ){
  2110. tVal->enabled_lrf = atoi( it->second.c_str() );
  2111. };
  2112. it = cArr->find("max_range");
  2113. if( it != cArr->end() ){
  2114. tVal->max_range = atof( it->second.c_str() );
  2115. };
  2116. it = cArr->find("base_shift");
  2117. if( it != cArr->end() ){
  2118. tVal->base_shift = atoi( it->second.c_str() );
  2119. };
  2120. //it = cArr->find("mirror_shift");
  2121. //if( it != cArr->end() ){
  2122. // tVal->mirror_shift = atoi( it->second.c_str() );
  2123. //};
  2124. it = cArr->find("detection_profile_id");
  2125. if( it != cArr->end() ){
  2126. tVal->detection_profile_id = atoi( it->second.c_str() );
  2127. };
  2128. it = cArr->find("prefered_camera_id");
  2129. if( it != cArr->end() ){
  2130. tVal->prefered_camera_id = atoi( it->second.c_str() );
  2131. };
  2132. /*
  2133. it = cArr->find("draw_lrf_id");
  2134. if( it != cArr->end() ){
  2135. tVal->draw_lrf_id = atoi( it->second.c_str() );
  2136. };
  2137. it = cArr->find("width_table_id");
  2138. if( it != cArr->end() ){
  2139. tVal->width_table_id = atoi( it->second.c_str() );
  2140. };
  2141. it = cArr->find("zoom_table_id");
  2142. if( it != cArr->end() ){
  2143. tVal->zoom_table_id = atoi( it->second.c_str() );
  2144. };
  2145. it = cArr->find("embd_cam");
  2146. if( it != cArr->end() ){
  2147. tVal->embd_cam = atoi( it->second.c_str() );
  2148. };
  2149. it = cArr->find("embd_cam_auto");
  2150. if( it != cArr->end() ){
  2151. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  2152. };
  2153. it = cArr->find("embd_dc");
  2154. if( it != cArr->end() ){
  2155. tVal->embd_dc = atoi( it->second.c_str() );
  2156. };
  2157. it = cArr->find("autoreset");
  2158. if( it != cArr->end() ){
  2159. tVal->autoreset = (bool)atoi( it->second.c_str() );
  2160. };
  2161. it = cArr->find("force_settings");
  2162. if( it != cArr->end() ){
  2163. tVal->force_settings = (bool)atoi( it->second.c_str() );
  2164. };
  2165. */
  2166. };
  2167. };
  2168. };
  2169. deleteResult( result );
  2170. };
  2171. return tVal;
  2172. };
  2173. PLGS_2D_PARAMETERS sqliteDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
  2174. PLGS_2D_PARAMETERS retVal = NULL;
  2175. if( m_bStoIsConnected ){
  2176. char tQBuf[CTEXT];
  2177. AAssoc *result;
  2178. sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=%d", lrfID, profileID,((master)?1:0) );
  2179. #ifdef DEBUG_ALL
  2180. LOG(tQBuf);
  2181. #endif
  2182. result = m_pDataStorage->Query( tQBuf );
  2183. if( result!= NULL ) {
  2184. if( result->size() > 0 ) {
  2185. retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
  2186. memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
  2187. Assoc *cArr;
  2188. Assoc::iterator it;
  2189. cArr = result->at(0);
  2190. it = cArr->find("order");
  2191. if( it != cArr->end() ){
  2192. retVal->nOrder = atoi(it->second.c_str());
  2193. };
  2194. it = cArr->find("offset");
  2195. if( it != cArr->end() ){
  2196. retVal->nOffset = atoi(it->second.c_str());
  2197. };
  2198. it = cArr->find("delta");
  2199. if( it != cArr->end() ){
  2200. retVal->nDelta = atoi(it->second.c_str());
  2201. };
  2202. it = cArr->find("flip");
  2203. if( it != cArr->end() ){
  2204. retVal->nFlip = atoi(it->second.c_str());
  2205. };
  2206. it = cArr->find("width");
  2207. if( it != cArr->end() ){
  2208. retVal->nWidth = atoi(it->second.c_str());
  2209. };
  2210. it = cArr->find("sst");
  2211. if( it != cArr->end() ){
  2212. retVal->bSST = atoi(it->second.c_str());
  2213. };
  2214. it = cArr->find("sun");
  2215. if( it != cArr->end() ){
  2216. retVal->nSun = atoi(it->second.c_str());
  2217. };
  2218. };
  2219. };
  2220. deleteResult( result );
  2221. };
  2222. return retVal;
  2223. };
  2224. RELAY_PARAMETERS *sqliteDBC::getLRFDryContact( uint32_t lrfID ){
  2225. RELAY_PARAMETERS *retVal = NULL;
  2226. if( m_bStoIsConnected ){
  2227. char tQBuf[CTEXT];
  2228. AAssoc *result;
  2229. sprintf(tQBuf, "SELECT `dc_auto`, `dc_no`, `dc_window` FROM `lrf_sensors` WHERE `id`=%d", lrfID );
  2230. #ifdef DEBUG_ALL
  2231. LOG(tQBuf);
  2232. #endif
  2233. result = m_pDataStorage->Query( tQBuf );
  2234. if( result!= NULL ) {
  2235. if( result->size() > 0 ) {
  2236. retVal = (RELAY_PARAMETERS*) malloc(sizeof(RELAY_PARAMETERS));
  2237. if( retVal ) {
  2238. Assoc *cArr;
  2239. Assoc::iterator it;
  2240. cArr = result->at(0);
  2241. it = cArr->find("dc_auto");
  2242. if( it != cArr->end() ){
  2243. retVal->bAuto = atoi( it->second.c_str() );
  2244. };
  2245. it = cArr->find("dc_no");
  2246. if( it != cArr->end() ){
  2247. retVal->bNormallyClose = ( atoi( it->second.c_str() ) == 0 );
  2248. };
  2249. it = cArr->find("dc_window");
  2250. if( it != cArr->end() ){
  2251. retVal->nAutoDelay = atoi( it->second.c_str() );
  2252. };
  2253. };
  2254. };
  2255. };
  2256. deleteResult( result );
  2257. };
  2258. return retVal;
  2259. };
  2260. uint8_t sqliteDBC::getLRFDataStatus( uint32_t ID ){
  2261. uint8_t RetVal = 0;
  2262. if( m_bStoIsConnected ){
  2263. char tQBuf[CTEXT];
  2264. AAssoc *result;
  2265. sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );
  2266. #ifdef DEBUG_ALL
  2267. LOG(tQBuf);
  2268. #endif
  2269. result = m_pDataStorage->Query( tQBuf );
  2270. if( result!= NULL ) {
  2271. if( result->size() > 0 ) {
  2272. Assoc *cArr;
  2273. Assoc::iterator it;
  2274. cArr = result->at(0);
  2275. it = cArr->find("data_status");
  2276. if( it != cArr->end() ){
  2277. RetVal = atoi( it->second.c_str() );
  2278. };
  2279. };
  2280. };
  2281. deleteResult( result );
  2282. };
  2283. return RetVal;
  2284. };
  2285. uint32_t sqliteDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){
  2286. uint32_t RetVal = 0;
  2287. if( m_bStoIsConnected ){
  2288. char tQBuf[CTEXT];
  2289. AAssoc *result;
  2290. sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );
  2291. #ifdef DEBUG_ALL
  2292. LOG(tQBuf);
  2293. #endif
  2294. result = m_pDataStorage->Query( tQBuf );
  2295. if( result!= NULL ) {
  2296. if( result->size() > 0 ) {
  2297. Assoc *cArr;
  2298. Assoc::iterator it;
  2299. cArr = result->at(0);
  2300. it = cArr->find("id");
  2301. if( it != cArr->end() ){
  2302. RetVal = atoi( it->second.c_str() );
  2303. };
  2304. };
  2305. };
  2306. deleteResult( result );
  2307. };
  2308. return RetVal;
  2309. };
  2310. uint32_t sqliteDBC::getLRFMaskPolygoneID( uint32_t maskID, uint8_t vertecID ){
  2311. uint32_t RetVal = 0;
  2312. if( m_bStoIsConnected ){
  2313. char tQBuf[CTEXT];
  2314. AAssoc *result;
  2315. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d AND `vertex_id`=%d", maskID, vertecID );
  2316. #ifdef DEBUG_ALL
  2317. LOG(tQBuf);
  2318. #endif
  2319. result = m_pDataStorage->Query( tQBuf );
  2320. if( result!= NULL ) {
  2321. if( result->size() > 0 ) {
  2322. Assoc *cArr;
  2323. Assoc::iterator it;
  2324. cArr = result->at(0);
  2325. it = cArr->find("id");
  2326. if( it != cArr->end() ){
  2327. RetVal = atoi( it->second.c_str() );
  2328. };
  2329. };
  2330. };
  2331. deleteResult( result );
  2332. };
  2333. return RetVal;
  2334. };
  2335. uint8_t sqliteDBC::getLRFMasksStatus( uint32_t deviceID ){
  2336. uint8_t RetVal = 0;
  2337. if( m_bStoIsConnected ){
  2338. char tQBuf[CTEXT];
  2339. AAssoc *result;
  2340. sprintf(tQBuf, "SELECT `layer` FROM `lrf_masks` WHERE `sensor_id`=%d AND `status`='E'", deviceID );
  2341. #ifdef DEBUG_ALL
  2342. LOG(tQBuf);
  2343. #endif
  2344. result = m_pDataStorage->Query( tQBuf );
  2345. if( result!= NULL ) {
  2346. if( result->size() > 0 ) {
  2347. Assoc *cArr;
  2348. Assoc::iterator it;
  2349. for(int i=0;i<result->size();i++) {
  2350. cArr = result->at(i);
  2351. it = cArr->find("layer");
  2352. if( it != cArr->end() ){
  2353. RetVal |= ( 1<< atoi( it->second.c_str() ));
  2354. };
  2355. };
  2356. };
  2357. };
  2358. deleteResult( result );
  2359. };
  2360. return RetVal;
  2361. };
  2362. DBC_LRF_UPLOAD_DATA *sqliteDBC::getLRFUploadData( uint32_t upID ){
  2363. DBC_LRF_UPLOAD_DATA *RetVal = NULL;
  2364. if( m_bStoIsConnected ){
  2365. char tQBuf[CTEXT];
  2366. AAssoc *result;
  2367. sprintf(tQBuf, "SELECT * FROM `lrf_uploads` WHERE `id`=%d", upID );
  2368. #ifdef DEBUG_ALL
  2369. LOG(tQBuf);
  2370. #endif
  2371. result = m_pDataStorage->Query( tQBuf );
  2372. if( result->size() > 0 ) {
  2373. Assoc *cArr;
  2374. RetVal = (DBC_LRF_UPLOAD_DATA*) malloc(sizeof(DBC_LRF_UPLOAD_DATA));
  2375. if( RetVal != NULL ) {
  2376. memset( RetVal, 0, sizeof(DBC_LRF_UPLOAD_DATA));
  2377. Assoc::iterator it;
  2378. RetVal->id = upID;
  2379. cArr = result->at(0);
  2380. it = cArr->find("md5");
  2381. if( it != cArr->end() ){
  2382. strncpy( RetVal->md5, it->second.c_str(), 32 );
  2383. };
  2384. it = cArr->find("file");
  2385. if( it != cArr->end() ){
  2386. strncpy( RetVal->fname, it->second.c_str(), 16 );
  2387. };
  2388. it = cArr->find("issue_reset");
  2389. if( it != cArr->end() ){
  2390. RetVal->transfer_mode = atoi( it->second.c_str() );
  2391. };
  2392. };
  2393. };
  2394. deleteResult( result );
  2395. };
  2396. return RetVal;
  2397. };
  2398. DBC_WIDTH_TABLE *sqliteDBC::getLRFWidthTable( uint32_t lrfID ){
  2399. DBC_WIDTH_TABLE *retVal = NULL;
  2400. if( m_bStoIsConnected ){
  2401. retVal = (DBC_WIDTH_TABLE *)malloc(sizeof(DBC_WIDTH_TABLE));
  2402. if ( retVal ) {
  2403. char tQBuf[CTEXT];
  2404. AAssoc *result;
  2405. sprintf(tQBuf, "SELECT `range_k`, `width_k` FROM `lrf_detection_width_tables` WHERE `aux_id`=%d ORDER BY `range_k`", lrfID );
  2406. #ifdef DEBUG_ALL
  2407. LOG(tQBuf);
  2408. #endif
  2409. memset( retVal, 0 , sizeof( DBC_WIDTH_TABLE ));
  2410. result = m_pDataStorage->Query( tQBuf );
  2411. if( result!= NULL ) {
  2412. if( result->size() > 0 ) {
  2413. retVal->count = result->size();
  2414. retVal->wt_records = (DBC_WT_RECORD*) calloc( retVal->count, sizeof(DBC_WT_RECORD));
  2415. if ( retVal->wt_records ) {
  2416. Assoc *cArr;
  2417. Assoc::iterator it;
  2418. for( int i = 0; i < retVal->count; i++ ) {
  2419. cArr = result->at(i);
  2420. it = cArr->find("range_k");
  2421. if( it != cArr->end() ){
  2422. retVal->wt_records[i].rangePercent = atoi( it->second.c_str() );
  2423. };
  2424. it = cArr->find("width_k");
  2425. if( it != cArr->end() ){
  2426. retVal->wt_records[i].widthPercent = atoi( it->second.c_str() );
  2427. };
  2428. };
  2429. } else {
  2430. //retVal->count = 0;
  2431. LOG_ERROR("No Memory To create WT Record!");
  2432. free( retVal );
  2433. retVal = NULL;
  2434. };
  2435. };
  2436. };
  2437. deleteResult( result );
  2438. } else {
  2439. LOG_ERROR("No Memory To create WT!");
  2440. };
  2441. };
  2442. return retVal;
  2443. };
  2444. uint32_t sqliteDBC::getNodeAuxParam( uint32_t NodeID ){
  2445. uint32_t retVal = 0;
  2446. if( m_bStoIsConnected ){
  2447. char tQBuf[CTEXT];
  2448. AAssoc *result;
  2449. sprintf(tQBuf, "SELECT `aux_parameter` FROM `nodes` WHERE `id`=%d", NodeID );
  2450. #ifdef DEBUG_ALL
  2451. LOG(tQBuf);
  2452. #endif
  2453. result = m_pDataStorage->Query( tQBuf );
  2454. if( result!= NULL ) {
  2455. if( result->size() > 0 ) {
  2456. Assoc *cArr;
  2457. Assoc::iterator it;
  2458. cArr = result->at(0);
  2459. it = cArr->find("aux_parameter");
  2460. if( it != cArr->end() ){
  2461. retVal = atoi( it->second.c_str() );
  2462. };
  2463. };
  2464. };
  2465. deleteResult( result );
  2466. };
  2467. return retVal;
  2468. };
  2469. DBC_NODE_DATA *sqliteDBC::getNodeData( uint32_t ID ){
  2470. DBC_NODE_DATA * tVal = NULL;
  2471. if( m_bStoIsConnected ){
  2472. char tQBuf[CTEXT];
  2473. AAssoc *result;
  2474. sprintf(tQBuf, "SELECT * FROM `nodes` WHERE `id`=%d", ID );
  2475. #ifdef DEBUG_ALL
  2476. LOG(tQBuf);
  2477. #endif
  2478. result = m_pDataStorage->Query( tQBuf );
  2479. if( result!= NULL ) {
  2480. if( result->size() > 0 ) {
  2481. Assoc *cArr;
  2482. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  2483. if( tVal != NULL ) {
  2484. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  2485. Assoc::iterator it;
  2486. tVal->node_id = ID;
  2487. cArr = result->at(0);
  2488. it = cArr->find("type");
  2489. if( it != cArr->end() ){
  2490. tVal->type = /*(NODE_TYPE)*/ atoi( it->second.c_str() );
  2491. };
  2492. it = cArr->find("aux_id");
  2493. if( it != cArr->end() ){
  2494. tVal->aux_id = atoi( it->second.c_str() );
  2495. };
  2496. it = cArr->find("aux_parameter");
  2497. if( it != cArr->end() ){
  2498. tVal->aux_parameter = atoi( it->second.c_str() );
  2499. };
  2500. it = cArr->find("online");
  2501. if( it != cArr->end() ){
  2502. tVal->online = (bool)atoi( it->second.c_str() );
  2503. };
  2504. it = cArr->find("enable");
  2505. if( it != cArr->end() ){
  2506. tVal->enabled = (bool)atoi( it->second.c_str() );
  2507. };
  2508. it = cArr->find("name");
  2509. if( it != cArr->end() ){
  2510. sprintf( tVal->name, it->second.c_str() );
  2511. };
  2512. };
  2513. };
  2514. };
  2515. deleteResult( result );
  2516. };
  2517. return tVal;
  2518. };
  2519. uint32_t sqliteDBC::getNodeIdByTypeAndAux( uint8_t type, uint32_t aux_id ){
  2520. uint32_t retVal = 0;
  2521. if( m_bStoIsConnected ){
  2522. char tQBuf[CTEXT];
  2523. AAssoc *result;
  2524. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `type`=%d AND `aux_id`=%d", type, aux_id);
  2525. #ifdef DEBUG_ALL
  2526. LOG(tQBuf);
  2527. #endif
  2528. result = m_pDataStorage->Query( tQBuf );
  2529. if( result!= NULL ) {
  2530. if( result->size() > 0 ) {
  2531. Assoc *cArr;
  2532. Assoc::iterator it;
  2533. cArr = result->at(0);
  2534. it = cArr->find("id");
  2535. if( it != cArr->end() ){
  2536. retVal = atoi( it->second.c_str() );
  2537. };
  2538. };
  2539. };
  2540. deleteResult( result );
  2541. };
  2542. return retVal;
  2543. };
  2544. CSTR sqliteDBC::getNodeName( uint32_t NodeID ){
  2545. CSTR retVal = NULL;
  2546. if( m_bStoIsConnected ){
  2547. char tQBuf[CTEXT];
  2548. AAssoc *result;
  2549. sprintf(tQBuf, "SELECT `name` FROM `nodes` WHERE `id`=%d", NodeID );
  2550. #ifdef DEBUG_ALL
  2551. LOG(tQBuf);
  2552. #endif
  2553. result = m_pDataStorage->Query( tQBuf );
  2554. if( result!= NULL ) {
  2555. if( result->size() > 0 ) {
  2556. Assoc *cArr;
  2557. Assoc::iterator it;
  2558. cArr = result->at(0);
  2559. it = cArr->find("name");
  2560. if( it != cArr->end() ){
  2561. retVal = strdup( it->second.c_str() );
  2562. };
  2563. };
  2564. };
  2565. deleteResult( result );
  2566. };
  2567. return retVal;
  2568. };
  2569. DBC_NET_IF_DATA *sqliteDBC::getNIF_Data( uint32_t nif_id ){
  2570. DBC_NET_IF_DATA * tVal = NULL;
  2571. if( m_bStoIsConnected ){
  2572. char tQBuf[CTEXT];
  2573. AAssoc *result;
  2574. sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id );
  2575. #ifdef DEBUG_ALL
  2576. LOG(tQBuf);
  2577. #endif
  2578. result = m_pDataStorage->Query( tQBuf );
  2579. if( result!= NULL ) {
  2580. if( result->size() > 0 ) {
  2581. Assoc *cArr;
  2582. tVal = (DBC_NET_IF_DATA*) malloc(sizeof(DBC_NET_IF_DATA));
  2583. if( tVal != NULL ) {
  2584. Assoc::iterator it;
  2585. tVal->id = nif_id;
  2586. cArr = result->at(0);
  2587. it = cArr->find("type");
  2588. if( it != cArr->end() ){
  2589. tVal->type = atoi(it->second.c_str());
  2590. };
  2591. it = cArr->find("mode");
  2592. if( it != cArr->end() ){
  2593. tVal->mode = atoi(it->second.c_str());
  2594. };
  2595. it = cArr->find("device_name");
  2596. if( it != cArr->end() ){
  2597. strncpy( tVal->device_name, it->second.c_str(),11);
  2598. tVal->device_name[10]=(char)0;
  2599. };
  2600. it = cArr->find("mac");
  2601. if( it != cArr->end() ){
  2602. strncpy( tVal->mac, it->second.c_str(), 33 );
  2603. tVal->mac[32]=(char)0;
  2604. };
  2605. it = cArr->find("aux_id");
  2606. if( it != cArr->end() ){
  2607. tVal->aux_id = atoi(it->second.c_str());
  2608. };
  2609. };
  2610. };
  2611. };
  2612. deleteResult( result );
  2613. };
  2614. return tVal;
  2615. };
  2616. uint32_t sqliteDBC::getNIF_ID( CSTR key ){
  2617. uint32_t tVal = 0;
  2618. if( m_bStoIsConnected ){
  2619. char tQBuf[CTEXT];
  2620. AAssoc *result;
  2621. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  2622. #ifdef DEBUG_ALL
  2623. LOG(tQBuf);
  2624. #endif
  2625. result = m_pDataStorage->Query( tQBuf );
  2626. if( result!= NULL ) {
  2627. if( result->size() > 0 ) {
  2628. Assoc *cArr;
  2629. Assoc::iterator it;
  2630. cArr = result->at(0);
  2631. it = cArr->find("id");
  2632. if( it != cArr->end() ){
  2633. tVal = atoi( it->second.c_str() );
  2634. };
  2635. };
  2636. };
  2637. deleteResult( result );
  2638. };
  2639. return tVal;
  2640. };
  2641. uint32_t sqliteDBC::getNIF_IDbyDevice( CSTR device ){
  2642. uint32_t tVal = 0;
  2643. if( m_bStoIsConnected ){
  2644. char tQBuf[CTEXT];
  2645. AAssoc *result;
  2646. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );
  2647. #ifdef DEBUG_ALL
  2648. LOG(tQBuf);
  2649. #endif
  2650. result = m_pDataStorage->Query( tQBuf );
  2651. if( result!= NULL ) {
  2652. if( result->size() > 0 ) {
  2653. Assoc *cArr;
  2654. Assoc::iterator it;
  2655. cArr = result->at(0);
  2656. it = cArr->find("id");
  2657. if( it != cArr->end() ){
  2658. tVal = atoi( it->second.c_str() );
  2659. };
  2660. };
  2661. };
  2662. deleteResult( result );
  2663. };
  2664. return tVal;
  2665. };
  2666. uint32_t sqliteDBC::getNetworkInfrastructureID( uint32_t nif_id ){
  2667. uint32_t tVal = 0;
  2668. if( m_bStoIsConnected ){
  2669. char tQBuf[CTEXT];
  2670. AAssoc *result;
  2671. sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id );
  2672. #ifdef DEBUG_ALL
  2673. LOG(tQBuf);
  2674. #endif
  2675. result = m_pDataStorage->Query( tQBuf );
  2676. if( result!= NULL ) {
  2677. if( result->size() > 0 ) {
  2678. Assoc *cArr;
  2679. Assoc::iterator it;
  2680. cArr = result->at(0);
  2681. it = cArr->find("id");
  2682. if( it != cArr->end() ){
  2683. tVal = atoi( it->second.c_str() );
  2684. };
  2685. };
  2686. };
  2687. deleteResult( result );
  2688. };
  2689. return tVal;
  2690. };
  2691. REPORT_DIRINFO *sqliteDBC::getReportDirInfo( uint32_t id ){
  2692. REPORT_DIRINFO *tVal = NULL;
  2693. if( m_bStaIsCreated ){
  2694. char tQBuf[CTEXT];
  2695. AAssoc *result;
  2696. sprintf(tQBuf, "SELECT * FROM `days` WHERE `ROWID`=%d", id );
  2697. #ifdef DEBUG_ALL
  2698. LOG(tQBuf);
  2699. #endif
  2700. result = m_pDataStorage->Query( tQBuf );
  2701. if( result!= NULL ) {
  2702. if( result->size() > 0 ) {
  2703. tVal = (REPORT_DIRINFO *) malloc( sizeof(REPORT_DIRINFO));
  2704. if ( tVal ) {
  2705. Assoc *cArr;
  2706. Assoc::iterator it;
  2707. memset( tVal, 0 , sizeof( REPORT_DIRINFO));
  2708. cArr = result->at(0);
  2709. it = cArr->find("year");
  2710. if( it != cArr->end() ){
  2711. strncpy( tVal->YEAR, it->second.c_str(), 5 );
  2712. };
  2713. it = cArr->find("month");
  2714. if( it != cArr->end() ){
  2715. strncpy( tVal->MONTH, it->second.c_str(), 3 );
  2716. };
  2717. it = cArr->find("day");
  2718. if( it != cArr->end() ){
  2719. strncpy( tVal->DAY, it->second.c_str(), 3 );
  2720. };
  2721. };
  2722. };
  2723. };
  2724. deleteResult( result );
  2725. };
  2726. return tVal;
  2727. };
  2728. DBC_RESOURCE_DATA *sqliteDBC::getResourceData( uint32_t ResourceID ){
  2729. DBC_RESOURCE_DATA *tVal = NULL;
  2730. if( m_bStoIsConnected ){
  2731. char tQBuf[CTEXT];
  2732. AAssoc *result;
  2733. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM `resources` WHERE `id`=%d", ResourceID );
  2734. #ifdef DEBUG_ALL
  2735. LOG(tQBuf);
  2736. #endif
  2737. result = m_pDataStorage->Query( tQBuf );
  2738. if( result!= NULL ) {
  2739. if( result->size() > 0 ) {
  2740. Assoc *cArr;
  2741. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  2742. if( tVal != NULL ) {
  2743. Assoc::iterator it;
  2744. cArr = result->at(0);
  2745. tVal->id = ResourceID;
  2746. it = cArr->find("node_id");
  2747. if( it != cArr->end() ){
  2748. tVal->node_id = atoi( it->second.c_str() );
  2749. };
  2750. it = cArr->find("type");
  2751. if( it != cArr->end() ){
  2752. tVal->type = atoi( it->second.c_str() );
  2753. };
  2754. it = cArr->find("aux_id");
  2755. if( it != cArr->end() ){
  2756. tVal->aux_id = atoi( it->second.c_str() );
  2757. };
  2758. it = cArr->find("device");
  2759. if( it != cArr->end() ){
  2760. strncpy( tVal->device, it->second.c_str(), 64 );
  2761. tVal->device[63] = (char)0;
  2762. };
  2763. };
  2764. };
  2765. };
  2766. deleteResult( result );
  2767. };
  2768. return tVal;
  2769. };
  2770. uint32_t sqliteDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  2771. uint32_t RetVal = 0;
  2772. if( m_bStoIsConnected ){
  2773. char tQBuf[CTEXT];
  2774. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  2775. #ifdef DEBUG_ALL
  2776. LOG(tQBuf);
  2777. #endif
  2778. AAssoc *result;
  2779. result = m_pDataStorage->Query( tQBuf );
  2780. if( result!= NULL ) {
  2781. if( result->size() > 0 ) {
  2782. Assoc * cArr;
  2783. Assoc::iterator it;
  2784. cArr = result->at(0);
  2785. it = cArr->find("id");
  2786. if( it != cArr->end() ){
  2787. RetVal = atoi( it->second.c_str() );
  2788. };
  2789. };
  2790. };
  2791. deleteResult( result );
  2792. };
  2793. return RetVal;
  2794. };
  2795. DBC_SITE_DATA *sqliteDBC::getSiteData( uint32_t ID ){
  2796. DBC_SITE_DATA * tVal = NULL;
  2797. if( m_bStoIsConnected ){
  2798. char tQBuf[CTEXT];
  2799. AAssoc *result;
  2800. sprintf(tQBuf, "SELECT * FROM `system_props` WHERE `id`=%d", ID);
  2801. #ifdef DEBUG_ALL
  2802. LOG(tQBuf);
  2803. #endif
  2804. result = m_pDataStorage->Query( tQBuf );
  2805. if( result!= NULL ) {
  2806. if( result->size() > 0 ) {
  2807. Assoc *cArr;
  2808. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  2809. if( tVal != NULL ) {
  2810. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  2811. Assoc::iterator it;
  2812. cArr = result->at(0);
  2813. it = cArr->find("type");
  2814. if( it != cArr->end() ){
  2815. tVal->account_id = atoi( it->second.c_str() );
  2816. };
  2817. it = cArr->find("name");
  2818. if( it != cArr->end() ){
  2819. sprintf( tVal->name, it->second.c_str() );
  2820. };
  2821. //it = cArr->find("server_ident");
  2822. //if( it != cArr->end() ){
  2823. // sprintf( tVal->ident, it->second.c_str() );
  2824. //};
  2825. it = cArr->find("anchor_lat");
  2826. if( it != cArr->end() ){
  2827. tVal->lat = atof( it->second.c_str() );
  2828. };
  2829. it = cArr->find("anchor_lon");
  2830. if( it != cArr->end() ){
  2831. tVal->lon = atof( it->second.c_str() );
  2832. };
  2833. it = cArr->find("anchor_alt");
  2834. if( it != cArr->end() ){
  2835. tVal->alt = atof( it->second.c_str() );
  2836. };
  2837. it = cArr->find("hemisphere");
  2838. if( it != cArr->end() ){
  2839. tVal->SH = ( it->second.c_str()[0] == 'S' );
  2840. };
  2841. it = cArr->find("map_id");
  2842. if( it != cArr->end() ){
  2843. tVal->map_id = atoi( it->second.c_str() );
  2844. };
  2845. it = cArr->find("local_binding");
  2846. if( it != cArr->end() ){
  2847. tVal->local_binding = (bool) atoi(it->second.c_str());
  2848. };
  2849. it = cArr->find("work_mode");
  2850. if( it != cArr->end() ){
  2851. tVal->work_mode = atoi(it->second.c_str());
  2852. };
  2853. it = cArr->find("report_cleanup");
  2854. if( it != cArr->end() ){
  2855. tVal->report_cleanup = atoi(it->second.c_str());
  2856. };
  2857. it = cArr->find("preserve_empty");
  2858. if( it != cArr->end() ){
  2859. tVal->preserve_empty = atoi(it->second.c_str());
  2860. };
  2861. it = cArr->find("remote_ip");
  2862. if( it != cArr->end() ){
  2863. sprintf( tVal->remote_ip, it->second.c_str() );
  2864. };
  2865. it = cArr->find("remote_port");
  2866. if( it != cArr->end() ){
  2867. tVal->remote_port = atoi(it->second.c_str());
  2868. };
  2869. it = cArr->find("remote_backup_ip");
  2870. if( it != cArr->end() ){
  2871. sprintf( tVal->remote_ip, it->second.c_str() );
  2872. };
  2873. it = cArr->find("remote_backup_port");
  2874. if( it != cArr->end() ){
  2875. tVal->remote_port = atoi(it->second.c_str());
  2876. };
  2877. it = cArr->find("use_remote_server");
  2878. if( it != cArr->end() ){
  2879. tVal->use_remote_server = atoi(it->second.c_str());
  2880. };
  2881. it = cArr->find("skip_local_report");
  2882. if( it != cArr->end() ){
  2883. tVal->skip_local_report = atoi(it->second.c_str());
  2884. };
  2885. };
  2886. };
  2887. };
  2888. deleteResult( result );
  2889. };
  2890. return tVal;
  2891. };
  2892. uint32_t sqliteDBC::getServerID( CSTR identity ){
  2893. uint32_t RetVal = 0;
  2894. if( m_bStoIsConnected ){
  2895. char tQBuf[CTEXT];
  2896. sprintf(tQBuf,"SELECT `id` FROM `servers` WHERE `identity`='%s'", identity );
  2897. #ifdef DEBUG_ALL
  2898. LOG(tQBuf);
  2899. #endif
  2900. AAssoc *result;
  2901. result = m_pDataStorage->Query( tQBuf );
  2902. if( result!= NULL ) {
  2903. if( result->size() > 0 ) {
  2904. Assoc * cArr;
  2905. Assoc::iterator it;
  2906. cArr = result->at(0);
  2907. it = cArr->find("id");
  2908. if( it != cArr->end() ){
  2909. RetVal = atoi( it->second.c_str() );
  2910. };
  2911. };
  2912. };
  2913. deleteResult( result );
  2914. };
  2915. return RetVal;
  2916. };
  2917. uint32_t sqliteDBC::getServerNode( uint32_t SID ){
  2918. uint32_t RetVal = 0;
  2919. if( m_bStoIsConnected ){
  2920. char tQBuf[CTEXT];
  2921. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  2922. #ifdef DEBUG_ALL
  2923. LOG(tQBuf);
  2924. #endif
  2925. AAssoc *result;
  2926. result = m_pDataStorage->Query( tQBuf );
  2927. if( result!= NULL ) {
  2928. if( result->size() > 0 ) {
  2929. Assoc * cArr;
  2930. Assoc::iterator it;
  2931. cArr = result->at(0);
  2932. it = cArr->find("id");
  2933. if( it != cArr->end() ){
  2934. RetVal = atoi( it->second.c_str() );
  2935. };
  2936. };
  2937. };
  2938. deleteResult( result );
  2939. };
  2940. return RetVal;
  2941. }
  2942. DBC_TARGET_FLITER_DATA *sqliteDBC::getTargetFilterData( uint32_t ID ){
  2943. DBC_TARGET_FLITER_DATA * tVal = NULL;
  2944. if( m_bStoIsConnected ){
  2945. char tQBuf[CTEXT];
  2946. AAssoc *result;
  2947. sprintf(tQBuf, "SELECT * FROM `target_filters` WHERE `id`=%d", ID );
  2948. #ifdef DEBUG_ALL
  2949. LOG(tQBuf);
  2950. #endif
  2951. result = m_pDataStorage->Query( tQBuf );
  2952. if( result!= NULL ) {
  2953. if( result->size() > 0 ) {
  2954. Assoc *cArr;
  2955. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  2956. if( tVal != NULL ) {
  2957. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  2958. Assoc::iterator it;
  2959. tVal->id = ID;
  2960. cArr = result->at(0);
  2961. it = cArr->find("type");
  2962. if( it != cArr->end() ){
  2963. tVal->type = (TARGET_FILTER_TYPE) atoi( it->second.c_str() );
  2964. };
  2965. it = cArr->find("aux_id");
  2966. if( it != cArr->end() ){
  2967. tVal->aux_id = atoi( it->second.c_str() );
  2968. };
  2969. it = cArr->find("enabled");
  2970. if( it != cArr->end() ){
  2971. tVal->enabled = (bool) atoi( it->second.c_str() );
  2972. };
  2973. };
  2974. };
  2975. };
  2976. deleteResult( result );
  2977. };
  2978. return tVal;
  2979. };
  2980. TRAIN_FILTER_DATA *sqliteDBC::getTrainFilterData( uint32_t ID ){
  2981. TRAIN_FILTER_DATA * tVal = NULL;
  2982. if( m_bStoIsConnected ){
  2983. char tQBuf[CTEXT];
  2984. AAssoc *result;
  2985. sprintf(tQBuf, "SELECT * FROM `target_filter_train` WHERE `id`=%d", ID );
  2986. #ifdef DEBUG_ALL
  2987. LOG(tQBuf);
  2988. #endif
  2989. result = m_pDataStorage->Query( tQBuf );
  2990. if( result!= NULL ) {
  2991. if( result->size() > 0 ) {
  2992. Assoc *cArr;
  2993. tVal = (TRAIN_FILTER_DATA*) malloc(sizeof(TRAIN_FILTER_DATA));
  2994. if( tVal != NULL ) {
  2995. memset( tVal, 0 , sizeof(TRAIN_FILTER_DATA));
  2996. Assoc::iterator it;
  2997. cArr = result->at(0);
  2998. it = cArr->find("UPPER_SENSOR");
  2999. if( it != cArr->end() ){
  3000. tVal->nUpperSensorID = atoi( it->second.c_str() );
  3001. };
  3002. it = cArr->find("LOWER_SENSOR");
  3003. if( it != cArr->end() ){
  3004. tVal->nBottomSensorID = atoi( it->second.c_str() );
  3005. };
  3006. it = cArr->find("TRAIN_DETECT");
  3007. if( it != cArr->end() ){
  3008. tVal->bDetectTrain = (bool)atoi( it->second.c_str() );
  3009. };
  3010. it = cArr->find("TRAIN_WIDTH");
  3011. if( it != cArr->end() ){
  3012. tVal->nTrainWidth = atoi( it->second.c_str() );
  3013. };
  3014. it = cArr->find("DECISION_TIME");
  3015. if( it != cArr->end() ){
  3016. tVal->nDecisionTime = 1000 * atoi( it->second.c_str() );
  3017. };
  3018. it = cArr->find("SUSPECT_TIME");
  3019. if( it != cArr->end() ){
  3020. tVal->nSuspectTime = 1000 * atoi( it->second.c_str() );
  3021. };
  3022. it = cArr->find("TRACK_TRAIN");
  3023. if( it != cArr->end() ){
  3024. tVal->bTrackTrain = (bool)atoi( it->second.c_str() );
  3025. };
  3026. it = cArr->find("AUX_IP");
  3027. if( it != cArr->end() ){
  3028. strncpy( tVal->aux_ip, it->second.c_str(), 15 );
  3029. };
  3030. it = cArr->find("AUX_PORT");
  3031. if( it != cArr->end() ){
  3032. tVal->aux_port = atoi( it->second.c_str() );
  3033. };
  3034. #ifdef EFT_AUTO_RESET_UPPER_SENSOR
  3035. it = cArr->find("UPPER_RESTART");
  3036. if( it != cArr->end() ){
  3037. tVal->nUpperSensorRestartTO = atoi( it->second.c_str() ) * 3600; // Hours -> Seconds
  3038. } else {
  3039. tVal->nUpperSensorRestartTO = 24 * 3600;
  3040. };
  3041. #endif
  3042. #ifdef EFT_MINIMAL_RANGE_SUSPICIOUS
  3043. it = cArr->find("MINIMAL_RANGE");
  3044. if( it != cArr->end() ){
  3045. tVal->fMinimalRange = atof( it->second.c_str() );
  3046. } else {
  3047. tVal->fMinimalRange = 0.0;
  3048. };
  3049. #endif
  3050. it = cArr->find("DEBUG");
  3051. if( it != cArr->end() ){
  3052. tVal->bDebugMode = (bool)atoi( it->second.c_str() );
  3053. };
  3054. };
  3055. };
  3056. };
  3057. deleteResult( result );
  3058. };
  3059. return tVal;
  3060. };
  3061. DBC_UART_DATA *sqliteDBC::getUartData( uint32_t UartID ){
  3062. DBC_UART_DATA *tVal = NULL;
  3063. if( m_bStoIsConnected ) {
  3064. char tQBuf[MAX_PATH_LEN];
  3065. AAssoc *result;
  3066. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  3067. #ifdef DEBUG_ALL
  3068. LOG(tQBuf);
  3069. #endif
  3070. result = m_pDataStorage->Query( tQBuf );
  3071. if( result!= NULL ) {
  3072. if( result->size() > 0 ) {
  3073. Assoc *cArr;
  3074. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  3075. if( tVal != NULL ) {
  3076. Assoc::iterator it;
  3077. cArr = result->at(0);
  3078. it = cArr->find("type");
  3079. if( it != cArr->end() ){
  3080. tVal->type = atoi( it->second.c_str() );
  3081. };
  3082. it = cArr->find("speed");
  3083. if( it != cArr->end() ){
  3084. tVal->speed = atoi( it->second.c_str() );
  3085. };
  3086. it = cArr->find("mode");
  3087. if( it != cArr->end() ){
  3088. tVal->mode = atoi( it->second.c_str() );
  3089. };
  3090. it = cArr->find("port");
  3091. if( it != cArr->end() ){
  3092. tVal->port = atoi( it->second.c_str() );
  3093. };
  3094. it = cArr->find("path");
  3095. if( it != cArr->end() ){
  3096. strncpy( tVal->path, it->second.c_str(), 128 );
  3097. };
  3098. };
  3099. };
  3100. };
  3101. deleteResult( result );
  3102. };
  3103. return tVal;
  3104. };
  3105. uint32_t sqliteDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  3106. uint32_t RetVal = 0;
  3107. if( m_bStoIsConnected ){
  3108. char tQBuf[CTEXT];
  3109. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  3110. #ifdef DEBUG_ALL
  3111. LOG(tQBuf);
  3112. #endif
  3113. AAssoc *result;
  3114. result = m_pDataStorage->Query( tQBuf );
  3115. if( result!= NULL ) {
  3116. if( result->size() > 0 ) {
  3117. Assoc * cArr;
  3118. Assoc::iterator it;
  3119. cArr = result->at(0);
  3120. it = cArr->find("id");
  3121. if( it != cArr->end() ){
  3122. RetVal = atoi( it->second.c_str() );
  3123. };
  3124. };
  3125. };
  3126. deleteResult( result );
  3127. };
  3128. return RetVal;
  3129. };
  3130. uint32_t sqliteDBC::getWiFi_ID( uint32_t nif_id ){
  3131. uint32_t tVal = 0;
  3132. if( m_bStoIsConnected ){
  3133. char tQBuf[CTEXT];
  3134. AAssoc *result;
  3135. sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );
  3136. #ifdef DEBUG_ALL
  3137. LOG(tQBuf);
  3138. #endif
  3139. result = m_pDataStorage->Query( tQBuf );
  3140. if( result!= NULL ) {
  3141. if( result->size() > 0 ) {
  3142. Assoc *cArr;
  3143. Assoc::iterator it;
  3144. cArr = result->at(0);
  3145. it = cArr->find("id");
  3146. if( it != cArr->end() ){
  3147. tVal = atoi( it->second.c_str() );
  3148. };
  3149. };
  3150. };
  3151. deleteResult( result );
  3152. };
  3153. return tVal;
  3154. };
  3155. DBC_INT_LIST *sqliteDBC::listCamPresets( uint32_t SETID ){
  3156. DBC_INT_LIST * tVal = NULL;
  3157. if( m_bStoIsConnected ){
  3158. char tQBuf[CTEXT];
  3159. AAssoc *result;
  3160. sprintf(tQBuf, "SELECT `id` FROM `cameras_presets` WHERE `preset_id`=%d", SETID );
  3161. #ifdef DEBUG_ALL
  3162. LOG(tQBuf);
  3163. #endif
  3164. result = m_pDataStorage->Query( tQBuf );
  3165. if( result!= NULL ) {
  3166. if( result->size() > 0 ) {
  3167. Assoc *cArr;
  3168. tVal = new DBC_INT_LIST();
  3169. if( tVal != NULL ) {
  3170. Assoc::iterator it;
  3171. for(int i=0;i<result->size();i++) {
  3172. cArr = result->at(i);
  3173. it = cArr->find("id");
  3174. if( it != cArr->end() ){
  3175. tVal->push_back( atoi( it->second.c_str() ));
  3176. };
  3177. };
  3178. };
  3179. };
  3180. };
  3181. deleteResult( result );
  3182. };
  3183. return tVal;
  3184. };
  3185. DBC_INT_LIST *sqliteDBC::listFilters( uint32_t ServerID ){
  3186. DBC_INT_LIST * tVal = NULL;
  3187. if( m_bStoIsConnected ){
  3188. char tQBuf[CTEXT];
  3189. AAssoc *result;
  3190. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `enabled`=1" );
  3191. #ifdef DEBUG_ALL
  3192. LOG(tQBuf);
  3193. #endif
  3194. result = m_pDataStorage->Query( tQBuf );
  3195. if( result!= NULL ) {
  3196. if( result->size() > 0 ) {
  3197. Assoc *cArr;
  3198. tVal = new DBC_INT_LIST();
  3199. if( tVal != NULL ) {
  3200. Assoc::iterator it;
  3201. for(int i=0;i<result->size();i++) {
  3202. cArr = result->at(i);
  3203. it = cArr->find("id");
  3204. if( it != cArr->end() ){
  3205. tVal->push_back( atoi( it->second.c_str() ));
  3206. };
  3207. };
  3208. };
  3209. };
  3210. };
  3211. deleteResult( result );
  3212. };
  3213. return tVal;
  3214. };
  3215. DBC_INT_LIST *sqliteDBC::listLRFUploads( uint32_t deviceID ){
  3216. DBC_INT_LIST * tVal = NULL;
  3217. if( m_bStoIsConnected ){
  3218. char tQBuf[CTEXT];
  3219. AAssoc *result;
  3220. sprintf(tQBuf, "SELECT `id` FROM `lrf_uploads` WHERE `status`=-1 AND `sensor_id`=%d", deviceID );
  3221. #ifdef DEBUG_ALL
  3222. LOG(tQBuf);
  3223. #endif
  3224. result = m_pDataStorage->Query( tQBuf );
  3225. if( result!= NULL ) {
  3226. if( result->size() > 0 ) {
  3227. Assoc *cArr;
  3228. tVal = new DBC_INT_LIST();
  3229. if( tVal != NULL ) {
  3230. Assoc::iterator it;
  3231. for(int i=0;i<result->size();i++) {
  3232. cArr = result->at(i);
  3233. it = cArr->find("id");
  3234. if( it != cArr->end() ){
  3235. tVal->push_back( atoi( it->second.c_str() ));
  3236. };
  3237. };
  3238. };
  3239. };
  3240. };
  3241. deleteResult( result );
  3242. };
  3243. return tVal;
  3244. };
  3245. DBC_INT_LIST *sqliteDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  3246. DBC_INT_LIST * tVal = NULL;
  3247. if( m_bStoIsConnected ){
  3248. char tQBuf[CTEXT];
  3249. AAssoc *result;
  3250. switch( listMode ){
  3251. case LIST_VALID_RECORDS:
  3252. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13,14,15) AND `ms`.`valid`=1 AND `nd`.`online`=1" );
  3253. break;
  3254. case LIST_INVALID_RECORDS:
  3255. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13,14,15) AND `ms`.`valid`=1 AND `nd`.`online`=0" );
  3256. break;
  3257. default:
  3258. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13,14,15) AND `ms`.`valid`=1" );
  3259. };
  3260. #ifdef DEBUG_ALL
  3261. LOG(tQBuf);
  3262. #endif
  3263. result = m_pDataStorage->Query( tQBuf );
  3264. if( result!= NULL ) {
  3265. if( result->size() > 0 ) {
  3266. Assoc *cArr;
  3267. tVal = new DBC_INT_LIST();
  3268. if( tVal != NULL ) {
  3269. Assoc::iterator it;
  3270. for(int i=0;i<result->size();i++) {
  3271. cArr = result->at(i);
  3272. it = cArr->find("id");
  3273. if( it != cArr->end() ){
  3274. tVal->push_back( atoi( it->second.c_str() ));
  3275. };
  3276. };
  3277. };
  3278. };
  3279. };
  3280. deleteResult( result );
  3281. };
  3282. return tVal;
  3283. };
  3284. DBC_INT_LIST *sqliteDBC::listModules(){
  3285. DBC_INT_LIST * tVal = NULL;
  3286. if( m_bStoIsConnected ){
  3287. AAssoc *result;
  3288. result = m_pDataStorage->Query( "SELECT `id` FROM `modules` WHERE `enabled`=1" );
  3289. if( result!= NULL ) {
  3290. if( result->size() > 0 ) {
  3291. Assoc *cArr;
  3292. tVal = new DBC_INT_LIST();
  3293. if( tVal != NULL ) {
  3294. Assoc::iterator it;
  3295. for(int i=0;i<result->size();i++) {
  3296. cArr = result->at(i);
  3297. it = cArr->find("id");
  3298. if( it != cArr->end() ){
  3299. tVal->push_back( atoi( it->second.c_str() ));
  3300. };
  3301. };
  3302. };
  3303. };
  3304. };
  3305. deleteResult( result );
  3306. };
  3307. return tVal;
  3308. };
  3309. DBC_INT_LIST *sqliteDBC::listNewModules( DBC_INT_LIST * old_ids ){
  3310. DBC_INT_LIST * tVal = NULL;
  3311. if( m_bStoIsConnected ){
  3312. char tParam[CTEXT];
  3313. //memset( tParam, 0, CTEXT );
  3314. sprintf(tParam,"0");
  3315. if( old_ids != NULL ) {
  3316. char tBuffer[CTEXT];
  3317. for(int i = 0; i< old_ids->size(); i++ ) {
  3318. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  3319. strncpy( tParam, tBuffer, CTEXT );
  3320. };
  3321. };
  3322. char tQBuf[CTEXT];
  3323. AAssoc *result;
  3324. sprintf(tQBuf, "SELECT `id` FROM `modules` WHERE `enabled`=1 AND `id` NOT IN (%s)", tParam );
  3325. #ifdef DEBUG_ALL
  3326. LOG(tQBuf);
  3327. #endif
  3328. result = m_pDataStorage->Query( tQBuf );
  3329. if( result!= NULL ) {
  3330. if( result->size() > 0 ) {
  3331. Assoc *cArr;
  3332. tVal = new DBC_INT_LIST();
  3333. if( tVal != NULL ) {
  3334. Assoc::iterator it;
  3335. for(int i=0;i<result->size();i++) {
  3336. cArr = result->at(i);
  3337. it = cArr->find("id");
  3338. if( it != cArr->end() ){
  3339. tVal->push_back( atoi( it->second.c_str() ));
  3340. };
  3341. };
  3342. };
  3343. };
  3344. };
  3345. deleteResult( result );
  3346. };
  3347. return tVal;
  3348. };
  3349. DBC_INT_LIST *sqliteDBC::listNewNodes( DBC_INT_LIST * old_ids ){
  3350. DBC_INT_LIST * tVal = NULL;
  3351. if( m_bStoIsConnected ){
  3352. char tParam[CTEXT];
  3353. //memset( tParam, 0, CTEXT );
  3354. sprintf(tParam,"0");
  3355. if( old_ids != NULL ) {
  3356. char tBuffer[CTEXT];
  3357. for(int i = 0; i< old_ids->size(); i++ ) {
  3358. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  3359. strncpy( tParam, tBuffer, CTEXT );
  3360. };
  3361. };
  3362. char tQBuf[CTEXT];
  3363. AAssoc *result;
  3364. sprintf(tQBuf, "SELECT id FROM nodes WHERE `type` > 0 AND `enable`=1 AND `id` NOT IN(%s)", tParam );
  3365. #ifdef DEBUG_ALL
  3366. LOG(tQBuf);
  3367. #endif
  3368. result = m_pDataStorage->Query( tQBuf );
  3369. if( result!= NULL ) {
  3370. if( result->size() > 0 ) {
  3371. Assoc *cArr;
  3372. tVal = new DBC_INT_LIST();
  3373. if( tVal != NULL ) {
  3374. Assoc::iterator it;
  3375. for(int i=0;i<result->size();i++) {
  3376. cArr = result->at(i);
  3377. it = cArr->find("id");
  3378. if( it != cArr->end() ){
  3379. tVal->push_back( atoi( it->second.c_str() ));
  3380. };
  3381. };
  3382. };
  3383. };
  3384. };
  3385. deleteResult( result );
  3386. };
  3387. return tVal;
  3388. };
  3389. DBC_INT_LIST *sqliteDBC::listNodes( bool all ){
  3390. DBC_INT_LIST * tVal = NULL;
  3391. if( m_bStoIsConnected ){
  3392. char tQBuf[1024];
  3393. AAssoc *result;
  3394. if( all ) {
  3395. sprintf(tQBuf, "SELECT `id` FROM `nodes`");
  3396. } else {
  3397. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `type` > 0 AND `enable`=1" );
  3398. };
  3399. #ifdef DEBUG_ALL
  3400. LOG(tQBuf);
  3401. #endif
  3402. result = m_pDataStorage->Query( tQBuf );
  3403. if( result!= NULL ) {
  3404. if( result->size() > 0 ) {
  3405. Assoc *cArr;
  3406. tVal = new DBC_INT_LIST();
  3407. if( tVal != NULL ) {
  3408. Assoc::iterator it;
  3409. for(int i=0; i <result->size();i++) {
  3410. cArr = result->at(i);
  3411. it = cArr->find("id");
  3412. if( it != cArr->end() ){
  3413. tVal->push_back( atoi( it->second.c_str() ));
  3414. };
  3415. };
  3416. };
  3417. };
  3418. };
  3419. deleteResult( result );
  3420. };
  3421. return tVal;
  3422. };
  3423. DBC_INT_LIST *sqliteDBC::listOlderReportStat( CSTR Y, CSTR M, CSTR D ){
  3424. DBC_INT_LIST * tVal = NULL;
  3425. if ( m_bStaIsConnected ) {
  3426. char tQBuf[MAX_PATH_LEN];
  3427. AAssoc *result;
  3428. sprintf(tQBuf, "SELECT `ROWID` FROM `days` WHERE ((`year`*12*31)+(`month`*31)+`day`)<=((%s*12*31)+(%s*31)+%s) ORDER BY `ROWID`", Y, M, D );
  3429. result = m_pDataStatistics->Query( tQBuf );
  3430. if( result!= NULL ) {
  3431. if( result->size() > 0 ) {
  3432. Assoc *cArr;
  3433. tVal = new DBC_INT_LIST();
  3434. if( tVal != NULL ) {
  3435. Assoc::iterator it;
  3436. for(int i=0;i<result->size();i++) {
  3437. cArr = result->at(i);
  3438. it = cArr->find("ROWID");
  3439. if( it != cArr->end() ){
  3440. tVal->push_back( atoi( it->second.c_str() ));
  3441. };
  3442. };
  3443. };
  3444. };
  3445. };
  3446. deleteResult( result );
  3447. };
  3448. return tVal;
  3449. };
  3450. DBC_INT_LIST *sqliteDBC::listOlderReportStat( uint32_t TS ){
  3451. DBC_INT_LIST * tVal = NULL;
  3452. if ( m_bStaIsConnected ) {
  3453. char tQBuf[MAX_PATH_LEN];
  3454. AAssoc *result;
  3455. sprintf(tQBuf, "SELECT `ROWID` FROM `days` WHERE `ts`< %d", TS );
  3456. result = m_pDataStatistics->Query( tQBuf );
  3457. if( result!= NULL ) {
  3458. if( result->size() > 0 ) {
  3459. Assoc *cArr;
  3460. tVal = new DBC_INT_LIST();
  3461. if( tVal != NULL ) {
  3462. Assoc::iterator it;
  3463. for(int i=0;i<result->size();i++) {
  3464. cArr = result->at(i);
  3465. it = cArr->find("ROWID");
  3466. if( it != cArr->end() ){
  3467. tVal->push_back( atoi( it->second.c_str() ));
  3468. };
  3469. };
  3470. };
  3471. };
  3472. };
  3473. deleteResult( result );
  3474. };
  3475. return tVal;
  3476. };
  3477. DBC_INT_LIST *sqliteDBC::listPhonebook( ){
  3478. DBC_INT_LIST * tVal = NULL;
  3479. if( m_bStoIsConnected ){
  3480. char tQBuf[CTEXT];
  3481. AAssoc *result;
  3482. sprintf(tQBuf, "SELECT `id` FROM `module_modem_phonebook`" );
  3483. #ifdef DEBUG_ALL
  3484. LOG(tQBuf);
  3485. #endif
  3486. result = m_pDataStorage->Query( tQBuf );
  3487. if( result!= NULL ) {
  3488. if( result->size() > 0 ) {
  3489. Assoc *cArr;
  3490. tVal = new DBC_INT_LIST();
  3491. if( tVal != NULL ) {
  3492. Assoc::iterator it;
  3493. for(int i=0;i<result->size();i++) {
  3494. cArr = result->at(i);
  3495. it = cArr->find("id");
  3496. if( it != cArr->end() ){
  3497. tVal->push_back( atoi( it->second.c_str() ));
  3498. };
  3499. };
  3500. };
  3501. };
  3502. };
  3503. deleteResult( result );
  3504. };
  3505. return tVal;
  3506. };
  3507. DBC_INT_LIST *sqliteDBC::listResources( uint32_t NodeID ){
  3508. DBC_INT_LIST * tVal = NULL;
  3509. if( m_bStoIsConnected ){
  3510. char tQBuf[CTEXT];
  3511. AAssoc *result;
  3512. if ( NodeID == 0 ) NodeID = m_nServerNodeID;
  3513. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d", NodeID );
  3514. #ifdef DEBUG_ALL
  3515. LOG(tQBuf);
  3516. #endif
  3517. result = m_pDataStorage->Query( tQBuf );
  3518. if( result!= NULL ) {
  3519. if( result->size() > 0 ) {
  3520. Assoc *cArr;
  3521. tVal = new DBC_INT_LIST();
  3522. if( tVal != NULL ) {
  3523. Assoc::iterator it;
  3524. for(int i=0;i<result->size();i++) {
  3525. cArr = result->at(i);
  3526. it = cArr->find("id");
  3527. if( it != cArr->end() ){
  3528. tVal->push_back( atoi( it->second.c_str() ));
  3529. };
  3530. };
  3531. };
  3532. };
  3533. };
  3534. deleteResult( result );
  3535. };
  3536. return tVal;
  3537. };
  3538. bool sqliteDBC::pushMemCMD( uint32_t NODE_ID, uint8_t CMD, CSTR DATA ){
  3539. DBC_PUSHED_CMD * RetVal = NULL;
  3540. if ( m_bMemIsConnected ) {
  3541. char QS[MAX_PATH];
  3542. sprintf( QS, "INSERT INTO `nodes_qcq`(`node_id`,`cmd`,`status`,`parameter`) VALUES(%d,%d,0,%s)", NODE_ID, CMD, DATA );
  3543. #ifdef DEBUG_ALL
  3544. LOG( QS );
  3545. #endif
  3546. m_pDataMemory->SilentQuery( QS );
  3547. return true;
  3548. };
  3549. return false;
  3550. };
  3551. void sqliteDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){
  3552. if( m_bStoIsConnected ){
  3553. m_nSiteID = SiteID;
  3554. char tQBuf[MAX_PATH_LEN];
  3555. #ifdef DEFAULT_SERVER_ID
  3556. sprintf( tQBuf, "INSERT INTO `servers`(`id`,`site_id`,`identity`,`version_string`) VALUES (%d,%d,'%s','%s') ON CONFLICT(`id`) DO UPDATE SET `identity`='%s',`version_string`='%s'",
  3557. DEFAULT_SERVER_ID, SiteID, identity, _BUILD_STRING_, identity, _BUILD_STRING_ );
  3558. #else
  3559. sprintf( tQBuf, "INSERT INTO `servers`(`site_id`,`identity`,`version_string`) VALUES (%d,'%s','%s') ON CONFLICT(`identity`) DO UPDATE SET `version_string`='%s'",
  3560. SiteID, identity, _BUILD_STRING_, _BUILD_STRING_ );
  3561. #endif
  3562. #ifdef DEBUG_ALL
  3563. LOG(tQBuf);
  3564. #endif
  3565. m_pDataStorage->SilentQuery( tQBuf );
  3566. #ifdef DEFAULT_SERVER_ID
  3567. m_nServerID = DEFAULT_SERVER_ID;
  3568. #else
  3569. m_nServerID = getServerID( identity );
  3570. #endif
  3571. *ServID = m_nServerID;
  3572. if( m_nServerID ) {
  3573. //if ( bRecreateMemStructures )
  3574. initMemDB( m_nServerID );
  3575. sprintf( tQBuf, "UPDATE `servers` SET `pid`=%d,`ts`=STRFTIME('%%s') WHERE `id`=%d", PID, m_nServerID );
  3576. #ifdef DEBUG_ALL
  3577. LOG(tQBuf);
  3578. #endif
  3579. m_pDataMemory->SilentQuery( tQBuf );
  3580. sprintf(tQBuf,"INSERT INTO `nodes`(`aux_id`,`type`,`online`,`name`) VALUES (%d, 0,1,'Controller') ON CONFLICT(`type`,`aux_id`) DO UPDATE SET `online`=1", *ServID );
  3581. #ifdef DEBUG_ALL
  3582. LOG(tQBuf);
  3583. #endif
  3584. m_nServerNodeID = ( uint32_t ) m_pDataStorage->QueryID( tQBuf );
  3585. if( m_nServerNodeID== 0 ){
  3586. m_nServerNodeID = getServerNode( m_nServerID );
  3587. };
  3588. *ServNode = m_nServerNodeID;
  3589. // Clenup Nodes and services ...
  3590. sprintf(tQBuf,"UPDATE `nodes` SET `online`=0" );
  3591. #ifdef DEBUG_ALL
  3592. LOG(tQBuf);
  3593. #endif
  3594. m_pDataStorage->SilentQuery( tQBuf );
  3595. sprintf(tQBuf,"UPDATE `cameras` SET `online`=0 WHERE `manual`=0" );
  3596. #ifdef DEBUG_ALL
  3597. LOG(tQBuf);
  3598. #endif
  3599. m_pDataStorage->SilentQuery( tQBuf );
  3600. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=0 WHERE `source_id` IN ( SELECT `id` FROM `cameras` WHERE `manual`=0 )" );
  3601. #ifdef DEBUG_ALL
  3602. LOG(tQBuf);
  3603. #endif
  3604. m_pDataStorage->SilentQuery( tQBuf );
  3605. //sprintf(tQBuf,"UPDATE `cameras` SET `online`=1 WHERE `manual`=1" );
  3606. #ifdef DEBUG_ALL
  3607. //LOG(tQBuf);
  3608. #endif
  3609. //m_pDataStorage->SilentQuery( tQBuf );
  3610. //sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=1 WHERE `source_id` IN ( SELECT `id` FROM `cameras` WHERE `online`=1 )" );
  3611. #ifdef DEBUG_ALL
  3612. //LOG(tQBuf);
  3613. #endif
  3614. //m_pDataStorage->SilentQuery( tQBuf );
  3615. // sprintf(tQBuf,"UPDATE `media_server_streams` SET `valid`=0, `online`=0" );
  3616. #ifdef DEBUG_ALL
  3617. // LOG(tQBuf);
  3618. #endif
  3619. // m_pDataStorage->SilentQuery( tQBuf );
  3620. //cleanResources( tServerNodeID );
  3621. setNodeOnline( m_nServerNodeID );
  3622. };
  3623. };
  3624. };
  3625. bool sqliteDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  3626. if( m_bStoIsConnected ) {
  3627. char tQBuf[MAX_PATH_LEN];
  3628. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  3629. #ifdef DEBUG_ALL
  3630. LOG(tQBuf);
  3631. #endif
  3632. m_pDataStorage->SilentQuery( tQBuf );
  3633. return true;
  3634. };
  3635. return false;
  3636. };
  3637. bool sqliteDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  3638. if( m_bStoIsConnected ) {
  3639. char tQBuf[MAX_PATH_LEN];
  3640. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  3641. #ifdef DEBUG_ALL
  3642. LOG(tQBuf);
  3643. #endif
  3644. m_pDataStorage->SilentQuery( tQBuf );
  3645. return true;
  3646. };
  3647. return false;
  3648. };
  3649. bool sqliteDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  3650. if( m_bStoIsConnected ) {
  3651. char tQBuf[MAX_PATH_LEN];
  3652. if( status ) {
  3653. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='E' WHERE `id`=%d", maskID );
  3654. } else {
  3655. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='D' WHERE `id`=%d", maskID );
  3656. };
  3657. #ifdef DEBUG_ALL
  3658. LOG(tQBuf);
  3659. #endif
  3660. m_pDataStorage->SilentQuery( tQBuf );
  3661. return true;
  3662. };
  3663. return false;
  3664. };
  3665. bool sqliteDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  3666. if( m_bStoIsConnected ) {
  3667. char tQBuf[MAX_PATH_LEN];
  3668. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  3669. #ifdef DEBUG_ALL
  3670. LOG(tQBuf);
  3671. #endif
  3672. m_pDataStorage->SilentQuery( tQBuf );
  3673. return true;
  3674. };
  3675. return false;
  3676. };
  3677. bool sqliteDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  3678. if( m_bStoIsConnected ) {
  3679. char tQBuf[MAX_PATH_LEN];
  3680. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  3681. #ifdef DEBUG_ALL
  3682. LOG(tQBuf);
  3683. #endif
  3684. m_pDataStorage->SilentQuery( tQBuf );
  3685. return true;
  3686. };
  3687. return false;
  3688. };
  3689. bool sqliteDBC::setNodeOffline( uint32_t NodeID ){
  3690. if( m_bStoIsConnected ){
  3691. char tQBuf[CTEXT];
  3692. if( NodeID ) {
  3693. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  3694. #ifdef DEBUG_ALL
  3695. LOG(tQBuf);
  3696. #endif
  3697. m_pDataStorage->SilentQuery( tQBuf );
  3698. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  3699. #ifdef DEBUG_ALL
  3700. LOG(tQBuf);
  3701. #endif
  3702. m_pDataStorage->SilentQuery( tQBuf );
  3703. return true;
  3704. };
  3705. };
  3706. return false;
  3707. };
  3708. bool sqliteDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  3709. if( m_bStoIsConnected ){
  3710. char tQBuf[CTEXT];
  3711. if( NodeID ) {
  3712. sprintf(tQBuf,"UPDATE `nodes` SET `online`=%d WHERE `id`=%d", status, NodeID );
  3713. #ifdef DEBUG_ALL
  3714. LOG(tQBuf);
  3715. #endif
  3716. m_pDataStorage->SilentQuery( tQBuf );
  3717. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  3718. #ifdef DEBUG_ALL
  3719. LOG(tQBuf);
  3720. #endif
  3721. m_pDataStorage->SilentQuery( tQBuf );
  3722. return true;
  3723. };
  3724. };
  3725. return false;
  3726. };
  3727. bool sqliteDBC::setRessourceActive( uint32_t RessourceID, bool Status ){
  3728. if( m_bStoIsConnected ){
  3729. char tQBuf[CTEXT];
  3730. if( RessourceID ) {
  3731. sprintf(tQBuf,"UPDATE `resources` SET `active`=%d WHERE `id`=%d", Status, RessourceID );
  3732. #ifdef DEBUG_ALL
  3733. LOG(tQBuf);
  3734. #endif
  3735. m_pDataStorage->SilentQuery( tQBuf );
  3736. return true;
  3737. };
  3738. };
  3739. return false;
  3740. };
  3741. bool sqliteDBC::setStreamValid( uint32_t streamID, bool status ){
  3742. if( m_bStoIsConnected ) {
  3743. char tQBuf[MAX_PATH_LEN];
  3744. if ( status ) {
  3745. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID);
  3746. } else {
  3747. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID);
  3748. };
  3749. #ifdef DEBUG_ALL
  3750. LOG(tQBuf);
  3751. #endif
  3752. m_pDataStorage->SilentQuery( tQBuf );
  3753. return true;
  3754. };
  3755. return false;
  3756. };
  3757. void sqliteDBC::unregisterServer( void ){
  3758. if( m_bStoIsConnected ) {
  3759. char tQBuf[MAX_PATH_LEN];
  3760. sprintf(tQBuf,"UPDATE `cameras` SET `online`=0" );
  3761. #ifdef DEBUG_ALL
  3762. LOG(tQBuf);
  3763. #endif
  3764. m_pDataStorage->SilentQuery( tQBuf );
  3765. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=0" );
  3766. #ifdef DEBUG_ALL
  3767. LOG(tQBuf);
  3768. #endif
  3769. m_pDataStorage->SilentQuery( tQBuf );
  3770. };
  3771. setNodeOffline( m_nServerNodeID );
  3772. };
  3773. bool sqliteDBC::updateSystemInfo( DBC_SYS_INFO *ptr ){
  3774. if( m_bStoIsConnected ) {
  3775. char tQBuf[MAX_PATH_LEN];
  3776. sprintf(tQBuf, "UPDATE `system_props` SET `os_info`='%s', `hw_info`='%s' WHERE `id`=%d",
  3777. ptr->OS_INFO,
  3778. ptr->HW_INFO,
  3779. m_nSiteID
  3780. );
  3781. #ifdef DEBUG_ALL
  3782. LOG(tQBuf);
  3783. #endif
  3784. m_pDataStorage->SilentQuery( tQBuf );
  3785. return true;
  3786. };
  3787. return false;
  3788. };
  3789. bool sqliteDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){
  3790. if( m_bStoIsConnected ){
  3791. char tQBuf[CTEXT];
  3792. AAssoc *result;
  3793. sprintf(tQBuf, "SELECT `lv`.`id`, `lm`.`layer`, `lm`.`status` FROM `lrf_mask_vertexes` `lv` LEFT JOIN `lrf_masks` `lm` ON (`lm`.`id` = `lv`.`mask_id`) WHERE `lm`.`sensor_id`=%d ORDER BY `lv`.`id`", ID );
  3794. #ifdef DEBUG_ALL
  3795. LOG(tQBuf);
  3796. #endif
  3797. result = m_pDataStorage->Query( tQBuf );
  3798. if( result!= NULL ) {
  3799. if( result->size() > 0 ) {
  3800. SH.m_nEnabled = 0xFFFFFFFF;
  3801. SH.m_nPolygonCount = result->size();
  3802. SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) );
  3803. if ( SH.pPolygones ) {
  3804. Assoc * cArr;
  3805. for ( uint8_t idx = 0; idx < result->size(); idx++ ) {
  3806. Assoc::iterator it;
  3807. cArr = result->at(idx);
  3808. it = cArr->find("id");
  3809. if( it != cArr->end() ){
  3810. SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str());
  3811. };
  3812. it = cArr->find("layer");
  3813. if( it != cArr->end() ){
  3814. SH.pPolygones[idx].bType = atoi(it->second.c_str());
  3815. };
  3816. it = cArr->find("status");
  3817. if( it != cArr->end() ){
  3818. SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<<SH.pPolygones[idx].bType);
  3819. };
  3820. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID );
  3821. #ifdef DEBUG_ALL
  3822. LOG(tQBuf);
  3823. #endif
  3824. AAssoc *v_result = m_pDataStorage->Query( tQBuf );
  3825. if( v_result!= NULL ) {
  3826. if( v_result->size() > 0 ) {
  3827. SH.pPolygones[idx].wCount = v_result->size();
  3828. SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) );
  3829. if(SH.pPolygones[idx].pPoint ) {
  3830. for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) {
  3831. cArr = v_result->at(zdx);
  3832. it = cArr->find("x");
  3833. if( it != cArr->end() ){
  3834. SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str());
  3835. };
  3836. it = cArr->find("y");
  3837. if( it != cArr->end() ){
  3838. SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str());
  3839. };
  3840. LOG("Point Added!");
  3841. };
  3842. } else {
  3843. LOG("No mem for Points!");
  3844. };
  3845. } else {
  3846. LOG("No Points!");
  3847. SH.pPolygones[idx].wCount = 0;
  3848. SH.pPolygones[idx].pPoint = NULL;
  3849. };
  3850. deleteResult( v_result );
  3851. };
  3852. };
  3853. };
  3854. };
  3855. deleteResult( result );
  3856. };
  3857. return true;
  3858. };
  3859. return false;
  3860. };
  3861. bool sqliteDBC::getAppDebugMode(){
  3862. bool rVal = false;
  3863. if( m_bStoIsConnected ){
  3864. char tQBuf[CTEXT];
  3865. AAssoc *result;
  3866. sprintf(tQBuf, "SELECT `work_mode` FROM `system_props` WHERE `id`=1" );
  3867. #ifdef DEBUG_ALL
  3868. LOG(tQBuf);
  3869. #endif
  3870. result = m_pDataStorage->Query( tQBuf );
  3871. if( result!= NULL ) {
  3872. if( result->size() > 0 ) {
  3873. Assoc *cArr;
  3874. Assoc::iterator it;
  3875. cArr = result->at(0);
  3876. it = cArr->find("work_mode");
  3877. if( it != cArr->end() ){
  3878. rVal = (bool) atoi( it->second.c_str() );
  3879. };
  3880. };
  3881. };
  3882. deleteResult( result );
  3883. };
  3884. return rVal;
  3885. };
  3886. DBC_CAM_DATA *sqliteDBC::getCamData( uint32_t ID ){
  3887. DBC_CAM_DATA *tVal = NULL;
  3888. if( m_bStoIsConnected ){
  3889. char tQBuf[CTEXT];
  3890. AAssoc *result;
  3891. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  3892. #ifdef DEBUG_ALL
  3893. LOG(tQBuf);
  3894. #endif
  3895. result = m_pDataStorage->Query( tQBuf );
  3896. if( result!= NULL ) {
  3897. if( result->size() > 0 ) {
  3898. Assoc *cArr;
  3899. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  3900. if( tVal != NULL ) {
  3901. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  3902. tVal->id = ID;
  3903. Assoc::iterator it;
  3904. cArr = result->at(0);
  3905. it = cArr->find("type");
  3906. if( it != cArr->end() ){
  3907. tVal->type = atoi( it->second.c_str() );
  3908. };
  3909. it = cArr->find("online");
  3910. if( it != cArr->end() ){
  3911. tVal->online = (bool) atoi( it->second.c_str() );
  3912. };
  3913. it = cArr->find("stream_id");
  3914. if( it != cArr->end() ){
  3915. tVal->stream_id = atoi( it->second.c_str() );
  3916. };
  3917. it = cArr->find("hardware");
  3918. if( it != cArr->end() ){
  3919. strncpy( tVal->hardware, it->second.c_str(), 32 );
  3920. };
  3921. it = cArr->find("name");
  3922. if( it != cArr->end() ){
  3923. strncpy( tVal->name, it->second.c_str(), 64 );
  3924. };
  3925. it = cArr->find("status");
  3926. if( it != cArr->end() ){
  3927. tVal->status = atoi( it->second.c_str() );
  3928. };
  3929. it = cArr->find("session");
  3930. if( it != cArr->end() ){
  3931. strncpy( tVal->session, it->second.c_str(), 32 );
  3932. };
  3933. it = cArr->find("protocol");
  3934. if( it != cArr->end() ){
  3935. tVal->protocol = atoi( it->second.c_str() );
  3936. };
  3937. it = cArr->find("protocol_aux");
  3938. if( it != cArr->end() ){
  3939. tVal->protocol_aux = atoi( it->second.c_str() );
  3940. };
  3941. it = cArr->find("uart_id");
  3942. if( it != cArr->end() ){
  3943. tVal->uart_id = atoi( it->second.c_str() );
  3944. };
  3945. it = cArr->find("x");
  3946. if( it != cArr->end() ){
  3947. tVal->x = atof( it->second.c_str() );
  3948. };
  3949. it = cArr->find("y");
  3950. if( it != cArr->end() ){
  3951. tVal->y = atof( it->second.c_str() );
  3952. };
  3953. it = cArr->find("z");
  3954. if( it != cArr->end() ){
  3955. tVal->z = atof( it->second.c_str() );
  3956. };
  3957. it = cArr->find("x_rot");
  3958. if( it != cArr->end() ){
  3959. tVal->x_rot = atof( it->second.c_str() );
  3960. };
  3961. it = cArr->find("y_rot");
  3962. if( it != cArr->end() ){
  3963. tVal->y_rot = atof( it->second.c_str() );
  3964. };
  3965. it = cArr->find("z_rot");
  3966. if( it != cArr->end() ){
  3967. tVal->z_rot = atof( it->second.c_str() );
  3968. };
  3969. it = cArr->find("imager_type");
  3970. if( it != cArr->end() ){
  3971. tVal->imager_type = atoi( it->second.c_str() );
  3972. };
  3973. it = cArr->find("lens_f");
  3974. if( it != cArr->end() ){
  3975. tVal->lens_f = atoi( it->second.c_str() );
  3976. };
  3977. it = cArr->find("ptz_speed_step");
  3978. if( it != cArr->end() ){
  3979. tVal->ptz_speed_step = atof( it->second.c_str() );
  3980. };
  3981. it = cArr->find("pan_model");
  3982. if( it != cArr->end() ){
  3983. tVal->pan_model = atoi( it->second.c_str() );
  3984. };
  3985. it = cArr->find("pan_angles");
  3986. if( it != cArr->end() ){
  3987. tVal->pan_angles = atoi( it->second.c_str() );
  3988. };
  3989. it = cArr->find("tilt_model");
  3990. if( it != cArr->end() ){
  3991. tVal->tilt_model = atoi( it->second.c_str() );
  3992. };
  3993. it = cArr->find("tilt_angles");
  3994. if( it != cArr->end() ){
  3995. tVal->tilt_angles = atoi( it->second.c_str() );
  3996. };
  3997. it = cArr->find("zoom_model");
  3998. if( it != cArr->end() ){
  3999. tVal->zoom_model = atoi( it->second.c_str() );
  4000. };
  4001. it = cArr->find("zoom");
  4002. if( it != cArr->end() ){
  4003. tVal->zoom = atof( it->second.c_str() );
  4004. };
  4005. it = cArr->find("max_range");
  4006. if( it != cArr->end() ){
  4007. tVal->max_range = atof( it->second.c_str() );
  4008. };
  4009. it = cArr->find("access_login");
  4010. if( it != cArr->end() ){
  4011. strncpy( tVal->username, it->second.c_str(), 16 );
  4012. };
  4013. it = cArr->find("access_pass");
  4014. if( it != cArr->end() ){
  4015. strncpy( tVal->password, it->second.c_str(), 16 );
  4016. };
  4017. it = cArr->find("uuid");
  4018. if( it != cArr->end() ){
  4019. strncpy( tVal->uuid, it->second.c_str(), 64 );
  4020. };
  4021. it = cArr->find("mac");
  4022. if( it != cArr->end() ){
  4023. strncpy( tVal->mac, it->second.c_str(), 16 );
  4024. };
  4025. it = cArr->find("ip");
  4026. if( it != cArr->end() ){
  4027. strncpy( tVal->ip, it->second.c_str(), 16 );
  4028. };
  4029. it = cArr->find("port");
  4030. if( it != cArr->end() ){
  4031. tVal->port = atoi( it->second.c_str() );
  4032. };
  4033. it = cArr->find("onvif_access");
  4034. if( it != cArr->end() ){
  4035. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  4036. };
  4037. it = cArr->find("onvif_ctrl");
  4038. if( it != cArr->end() ){
  4039. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  4040. };
  4041. it = cArr->find("ptz_token");
  4042. if( it != cArr->end() ){
  4043. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  4044. };
  4045. it = cArr->find("trigger_mode");
  4046. if( it != cArr->end() ){
  4047. tVal->triggering_mode = atoi( it->second.c_str() );
  4048. };
  4049. it = cArr->find("auth_mode");
  4050. if( it != cArr->end() ){
  4051. tVal->auth_mode = atoi( it->second.c_str() );
  4052. };
  4053. it = cArr->find("ptz_axel");
  4054. if( it != cArr->end() ){
  4055. tVal->ptz_axel = atoi( it->second.c_str() );
  4056. };
  4057. it = cArr->find("manual");
  4058. if( it != cArr->end() ){
  4059. tVal->manual = (bool) atoi( it->second.c_str() );
  4060. };
  4061. it = cArr->find("homing_enable");
  4062. if( it != cArr->end() ){
  4063. tVal->homing_enable = (bool) atoi( it->second.c_str() );
  4064. };
  4065. it = cArr->find("homing_to");
  4066. if( it != cArr->end() ){
  4067. tVal->homing_to = atoi( it->second.c_str() );
  4068. };
  4069. it = cArr->find("home_token");
  4070. if( it != cArr->end() ){
  4071. strncpy( tVal->home_token, it->second.c_str(), 32 );
  4072. };
  4073. it = cArr->find("eco_ir");
  4074. if( it != cArr->end() ){
  4075. tVal->eco_ir = (bool) atoi( it->second.c_str() );
  4076. };
  4077. it = cArr->find("prefered_events_only");
  4078. if( it != cArr->end() ){
  4079. tVal->prefered_events_only = (bool) atoi( it->second.c_str() );
  4080. };
  4081. };
  4082. };
  4083. };
  4084. deleteResult( result );
  4085. };
  4086. return tVal;
  4087. };
  4088. uint32_t sqliteDBC::getCamId( CSTR UUID ){
  4089. uint32_t RetVal = 0;
  4090. if( m_bStoIsConnected ){
  4091. char tQBuf[CTEXT];
  4092. AAssoc *result;
  4093. sprintf(tQBuf, "SELECT `id` FROM `cameras` WHERE `uuid`='%s'", UUID );
  4094. #ifdef DEBUG_ALL
  4095. LOG(tQBuf);
  4096. #endif
  4097. result = m_pDataStorage->Query( tQBuf );
  4098. if( result!= NULL ) {
  4099. if( result->size() > 0 ) {
  4100. Assoc *cArr;
  4101. Assoc::iterator it;
  4102. cArr = result->at(0);
  4103. it = cArr->find("id");
  4104. if( it != cArr->end() ){
  4105. RetVal = atoi( it->second.c_str() );
  4106. };
  4107. };
  4108. };
  4109. deleteResult( result );
  4110. };
  4111. return RetVal;
  4112. };
  4113. CAM_PRESET *sqliteDBC::getCamPreset( uint32_t SETID ){
  4114. CAM_PRESET *tVal = NULL;
  4115. if( m_bStoIsConnected ){
  4116. char tQBuf[CTEXT];
  4117. AAssoc *result;
  4118. sprintf(tQBuf, "SELECT * FROM `cameras_presets` WHERE `id`=%d", SETID );
  4119. #ifdef DEBUG_ALL
  4120. LOG(tQBuf);
  4121. #endif
  4122. result = m_pDataStorage->Query( tQBuf );
  4123. if( result!= NULL ) {
  4124. if( result->size() > 0 ) {
  4125. Assoc *cArr;
  4126. tVal = (CAM_PRESET*) malloc(sizeof(CAM_PRESET));
  4127. if( tVal != NULL ) {
  4128. memset( tVal, 0 , sizeof(CAM_PRESET));
  4129. tVal->id = SETID;
  4130. Assoc::iterator it;
  4131. cArr = result->at(0);
  4132. it = cArr->find("token");
  4133. if( it != cArr->end() ){
  4134. strncpy( tVal->token, it->second.c_str(), 2 );
  4135. tVal->token[3] = (char)0;
  4136. };
  4137. it = cArr->find("role");
  4138. if( it != cArr->end() ){
  4139. tVal->role = atoi( it->second.c_str() );
  4140. };
  4141. it = cArr->find("row");
  4142. if( it != cArr->end() ){
  4143. tVal->row = atoi( it->second.c_str() );
  4144. };
  4145. it = cArr->find("column");
  4146. if( it != cArr->end() ){
  4147. tVal->col = atoi( it->second.c_str() );
  4148. };
  4149. };
  4150. };
  4151. };
  4152. deleteResult( result );
  4153. };
  4154. return tVal;
  4155. };
  4156. DBC_PRESETS_INFO *sqliteDBC::getCamPresetInfo( uint32_t CamID ){
  4157. DBC_PRESETS_INFO *tVal = NULL;
  4158. if( m_bStoIsConnected ){
  4159. char tQBuf[CTEXT];
  4160. AAssoc *result;
  4161. sprintf(tQBuf, "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`=%d", CamID );
  4162. #ifdef DEBUG_ALL
  4163. LOG(tQBuf);
  4164. #endif
  4165. result = m_pDataStorage->Query( tQBuf );
  4166. if( result!= NULL ) {
  4167. if( result->size() > 0 ) {
  4168. Assoc *cArr;
  4169. tVal = (DBC_PRESETS_INFO*) malloc(sizeof(DBC_PRESETS_INFO));
  4170. if( tVal != NULL ) {
  4171. memset( tVal, 0 , sizeof(DBC_PRESETS_INFO));
  4172. Assoc::iterator it;
  4173. cArr = result->at(0);
  4174. it = cArr->find("maxCount");
  4175. if( it != cArr->end() ){
  4176. tVal->maxCount = atoi( it->second.c_str() );
  4177. };
  4178. it = cArr->find("p_segs");
  4179. if( it != cArr->end() ){
  4180. tVal->gCols = atoi( it->second.c_str() );
  4181. };
  4182. it = cArr->find("z_segs");
  4183. if( it != cArr->end() ){
  4184. tVal->gRows = atoi( it->second.c_str() );
  4185. };
  4186. };
  4187. };
  4188. };
  4189. deleteResult( result );
  4190. };
  4191. return tVal;
  4192. };
  4193. CSTR sqliteDBC::getDataParam( uint8_t pid ){
  4194. switch ( pid ) {
  4195. case 0: return strdup( m_pDbFile ); break;
  4196. case 1: return strdup( web_access_user ); break;
  4197. case 2: return strdup( web_access_group ); break;
  4198. };
  4199. return NULL;
  4200. };
  4201. bool sqliteDBC::updateIPCam( uint32_t CamID, CSTR Addr ){
  4202. if( m_bStoIsConnected ) {
  4203. char tQBuf[MAX_PATH_LEN];
  4204. char tIpBuf[CTEXT];
  4205. char *tPos;
  4206. char *tPos2;
  4207. uint16_t tPort = 0;
  4208. tPos = strstr(Addr,"//");
  4209. if( tPos != NULL ) {
  4210. tPos2 = strstr( tPos + 2,":");
  4211. if( tPos2 != NULL ) {
  4212. LOG("IP Port Defined!");
  4213. int len, len2, len3;
  4214. len = tPos2 - tPos - 2;
  4215. strncpy( tIpBuf, tPos + 2, len);
  4216. tIpBuf[len] = (char)0;
  4217. tPort = atoi( tPos2 + 1 );
  4218. //strncpy( tPath, tPos + 2 + len, CTEXT );
  4219. } else {
  4220. tPos2 = strstr( tPos + 2,"/");
  4221. if( tPos2 != NULL ) {
  4222. int len, len2, len3;
  4223. len = tPos2 - tPos - 2;
  4224. strncpy( tIpBuf, tPos + 2, len);
  4225. tIpBuf[len] = (char)0;
  4226. //strncpy( tPath, tPos + 2 + len, CTEXT );
  4227. } else {
  4228. tPos2 = strstr( tPos + 2,"/");
  4229. LOG_ERROR("Pos 2 - err");
  4230. tIpBuf[0] = (char)0;
  4231. };
  4232. };
  4233. } else {
  4234. LOG_ERROR("Pos 0 - err");
  4235. tIpBuf[0] = (char)0;
  4236. };
  4237. if ( tPort ) {
  4238. sprintf(tQBuf, "UPDATE `cameras` SET `online`=1, `onvif_ctrl`='%s', `ip`='%s', `port`=%d WHERE `id`=%d",
  4239. Addr,
  4240. tIpBuf,
  4241. tPort,
  4242. CamID
  4243. );
  4244. } else {
  4245. sprintf(tQBuf, "UPDATE `cameras` SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE `id`=%d",
  4246. Addr,
  4247. tIpBuf,
  4248. CamID
  4249. );
  4250. }
  4251. #ifdef DEBUG_ALL
  4252. LOG(tQBuf);
  4253. #endif
  4254. m_pDataStorage->SilentQuery( tQBuf );
  4255. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", CamID );
  4256. #ifdef DEBUG_ALL
  4257. LOG(tQBuf);
  4258. #endif
  4259. m_pDataStorage->SilentQuery( tQBuf );
  4260. return true;
  4261. };
  4262. return false;
  4263. };
  4264. bool sqliteDBC::updateCamRange( uint32_t camID, float range ){
  4265. if( m_bStoIsConnected ) {
  4266. char tQBuf[MAX_PATH_LEN];
  4267. sprintf(tQBuf,"UPDATE `cameras` SET `max_range`=%.3f WHERE `id`=%d",
  4268. range,
  4269. camID
  4270. );
  4271. #ifdef DEBUG_ALL
  4272. LOG(tQBuf);
  4273. #endif
  4274. m_pDataStorage->SilentQuery( tQBuf );
  4275. return true;
  4276. };
  4277. return false;
  4278. };
  4279. bool sqliteDBC::updateCamOnlineStatus( uint32_t camID, bool online ){
  4280. if( m_bStoIsConnected ) {
  4281. char tQBuf[MAX_PATH_LEN];
  4282. if ( online ) {
  4283. sprintf( tQBuf, "UPDATE `cameras` SET `online`=1 WHERE `id`=%d", camID );
  4284. } else {
  4285. sprintf( tQBuf, "UPDATE `cameras` SET `online`=0 WHERE `id`=%d", camID );
  4286. };
  4287. m_pDataStorage->SilentQuery(tQBuf);
  4288. if ( online ) {
  4289. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", camID);
  4290. } else {
  4291. sprintf( tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `source_id`=%d", camID );
  4292. };
  4293. m_pDataStorage->SilentQuery(tQBuf);
  4294. return true;
  4295. };
  4296. return false;
  4297. };
  4298. bool sqliteDBC::updateIPCam( CSTR uuid, CSTR Addr ){
  4299. if( m_bStoIsConnected ) {
  4300. uint32_t cID = getCamId( uuid );
  4301. if ( cID ) {
  4302. return updateIPCam( cID, Addr );
  4303. };
  4304. };
  4305. return false;
  4306. };
  4307. bool sqliteDBC::updateLocalCam( CSTR uuid ){
  4308. if( m_bStoIsConnected ) {
  4309. uint32_t cID = getCamId( uuid );
  4310. if ( cID ) {
  4311. return updateLocalCam( cID );
  4312. };
  4313. };
  4314. return false;
  4315. };
  4316. bool sqliteDBC::updateLocalCam( uint32_t CamID ){
  4317. if( m_bStoIsConnected ) {
  4318. char tQBuf[MAX_PATH_LEN];
  4319. sprintf(tQBuf,"UPDATE cameras SET `online`=1 WHERE `id`=%d", CamID );
  4320. #ifdef DEBUG_ALL
  4321. LOG(tQBuf);
  4322. #endif
  4323. m_pDataStorage->SilentQuery( tQBuf );
  4324. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", CamID );
  4325. #ifdef DEBUG_ALL
  4326. LOG(tQBuf);
  4327. #endif
  4328. m_pDataStorage->SilentQuery( tQBuf );
  4329. return true;
  4330. };
  4331. return false;
  4332. };
  4333. bool sqliteDBC::updateLRFComStat( uint32_t lrfID, uint32_t ErrorPerMinute ){
  4334. if( m_bStoIsConnected ) {
  4335. char tQBuf[MAX_PATH_LEN];
  4336. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `com_epm`=%d WHERE `id`=%d", ErrorPerMinute, lrfID );
  4337. #ifdef DEBUG_ALL
  4338. LOG(tQBuf);
  4339. #endif
  4340. m_pDataStorage->SilentQuery( tQBuf );
  4341. return true;
  4342. };
  4343. return false;
  4344. };
  4345. bool sqliteDBC::updateLRFFrozenStatus( uint32_t lrfID, bool FFT, bool SFT ){
  4346. if( m_bStoIsConnected ) {
  4347. char tQBuf[MAX_PATH_LEN];
  4348. sprintf(tQBuf, "UPDATE `lrf_ini_settings` SET `FREEZ_FIRST_TH`=%d, `SAVE_FIRST_TH`=%d WHERE `sensor_id`=%d", FFT, SFT, lrfID );
  4349. #ifdef DEBUG_ALL
  4350. LOG(tQBuf);
  4351. #endif
  4352. m_pDataStorage->SilentQuery( tQBuf );
  4353. return true;
  4354. };
  4355. return false;
  4356. };
  4357. bool sqliteDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP, uint32_t spikes ){
  4358. if( m_bStoIsConnected ) {
  4359. char tQBuf[MAX_PATH_LEN];
  4360. if( master ) {
  4361. sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles`(`aux_id`,`profile_id`,`master`,`order`,`offset`,`delta`,`flip`,`width`,`sst`,`sun`,`gp`,`spikes`) VALUES(%d,%d,1,%d,%d,%d,%d,%d,%d,%d,%d,%d)ON CONFLICT(`aux_id`,`lrf_id`,`master`) DO UPDATE SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
  4362. lrfID,
  4363. profileID,
  4364. nOrder,
  4365. nOffset,
  4366. nDelta,
  4367. nFlip,
  4368. nWidth,
  4369. bSST,
  4370. nSun,
  4371. GP,
  4372. spikes,
  4373. nOrder,
  4374. nOffset,
  4375. nDelta,
  4376. nFlip,
  4377. nWidth,
  4378. bSST,
  4379. nSun,
  4380. GP,
  4381. spikes );
  4382. } else {
  4383. sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles`(`aux_id`,`profile_id`,`master`,`order`,`offset`,`delta`,`flip`,`width`,`sst`,`sun`,`gp`,`spikes`) VALUES(%d,%d,0,%d,%d,%d,%d,%d,%d,%d,%d,%d)ON CONFLICT(`aux_id`,`lrf_id`,`master`) DO UPDATE SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
  4384. lrfID,
  4385. profileID,
  4386. nOrder,
  4387. nOffset,
  4388. nDelta,
  4389. nFlip,
  4390. nWidth,
  4391. bSST,
  4392. nSun,
  4393. GP,
  4394. spikes,
  4395. nOrder,
  4396. nOffset,
  4397. nDelta,
  4398. nFlip,
  4399. nWidth,
  4400. bSST,
  4401. nSun,
  4402. GP,
  4403. spikes );
  4404. };
  4405. #ifdef DEBUG_ALL
  4406. LOG(tQBuf);
  4407. #endif
  4408. m_pDataStorage->SilentQuery( tQBuf );
  4409. return true;
  4410. };
  4411. return false;
  4412. };
  4413. bool sqliteDBC::updateLRFDryContact( uint32_t lrfID, bool bAuto, bool bNO, uint16_t wWindow ){
  4414. if( m_bStoIsConnected ) {
  4415. char tQBuf[MAX_PATH_LEN];
  4416. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `dc_auto`=%d, `dc_no`=%d, `dc_window`=%d WHERE `id`=%d", bAuto, bNO, wWindow, lrfID );
  4417. #ifdef DEBUG_ALL
  4418. LOG(tQBuf);
  4419. #endif
  4420. m_pDataStorage->SilentQuery( tQBuf );
  4421. return true;
  4422. };
  4423. return false;
  4424. };
  4425. bool sqliteDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  4426. if( m_bStoIsConnected ) {
  4427. char tQBuf[MAX_PATH_LEN];
  4428. CSTR tES = m_pDataStorage->escapeString( Serial );
  4429. if( tES ) {
  4430. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  4431. free( tES );
  4432. #ifdef DEBUG_ALL
  4433. LOG(tQBuf);
  4434. #endif
  4435. m_pDataStorage->SilentQuery( tQBuf );
  4436. return true;
  4437. };
  4438. };
  4439. return false;
  4440. };
  4441. bool sqliteDBC::updateLRFUpload( uint32_t id, uint8_t status ){
  4442. if( m_bStoIsConnected ) {
  4443. char tQBuf[MAX_PATH_LEN];
  4444. sprintf( tQBuf, "UPDATE `lrf_uploads` SET `status`=%d WHERE `id`=%d", status, id );
  4445. #ifdef DEBUG_ALL
  4446. LOG(tQBuf);
  4447. #endif
  4448. m_pDataStorage->SilentQuery( tQBuf );
  4449. return true;
  4450. };
  4451. return false;
  4452. };
  4453. bool sqliteDBC::updateLRFUnfinishedUploads( uint32_t deviceID ){
  4454. if( m_bStoIsConnected ) {
  4455. char tQBuf[MAX_PATH_LEN];
  4456. sprintf( tQBuf, "UPDATE `lrf_uploads` SET `status`=-1 WHERE `sensor_id`=%d AND `status` < 101 ", deviceID );
  4457. #ifdef DEBUG_ALL
  4458. LOG(tQBuf);
  4459. #endif
  4460. m_pDataStorage->SilentQuery( tQBuf );
  4461. return true;
  4462. };
  4463. return false;
  4464. };
  4465. bool sqliteDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  4466. if( m_bStoIsConnected ) {
  4467. char tQBuf[MAX_PATH_LEN];
  4468. CSTR tES = m_pDataStorage->escapeString( version );
  4469. if( tES ) {
  4470. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  4471. free( tES );
  4472. #ifdef DEBUG_ALL
  4473. LOG(tQBuf);
  4474. #endif
  4475. m_pDataStorage->SilentQuery( tQBuf );
  4476. return true;
  4477. };
  4478. };
  4479. return false;
  4480. };
  4481. bool sqliteDBC::updateServerIdentity( uint32_t m_nServerID, CSTR m_sIdentity ){
  4482. if( m_bStoIsConnected ) {
  4483. char tQBuf[MAX_PATH_LEN];
  4484. CSTR tES = m_pDataStorage->escapeString( m_sIdentity );
  4485. if( tES ) {
  4486. sprintf( tQBuf, "UPDATE `servers` SET `identity`='%s' WHERE `id`=%d", tES, m_nServerID );
  4487. free( tES );
  4488. #ifdef DEBUG_ALL
  4489. LOG(tQBuf);
  4490. #endif
  4491. m_pDataStorage->SilentQuery( tQBuf );
  4492. return true;
  4493. };
  4494. };
  4495. return false;
  4496. };
  4497. #undef LOG
  4498. #undef LOG_ERROR