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.

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