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.

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