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.

4551 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. it = cArr->find("web_port");
  1395. if( it != cArr->end() ){
  1396. tPtr->port = atoi( it->second.c_str() );
  1397. };
  1398. it = cArr->find("width");
  1399. if( it != cArr->end() ){
  1400. tPtr->width = atoi( it->second.c_str() );
  1401. };
  1402. it = cArr->find("height");
  1403. if( it != cArr->end() ){
  1404. tPtr->height = atoi( it->second.c_str() );
  1405. };
  1406. it = cArr->find("compression_quality");
  1407. if( it != cArr->end() ){
  1408. tPtr->compression_quality = atoi( it->second.c_str() );
  1409. };
  1410. it = cArr->find("show_ts");
  1411. if( it != cArr->end() ){
  1412. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  1413. };
  1414. it = cArr->find("ts_x");
  1415. if( it != cArr->end() ){
  1416. tPtr->ts_x = atoi( it->second.c_str() );
  1417. };
  1418. it = cArr->find("ts_y");
  1419. if( it != cArr->end() ){
  1420. tPtr->ts_y = atoi( it->second.c_str() );
  1421. };
  1422. it = cArr->find("ts_font_face");
  1423. if( it != cArr->end() ){
  1424. tPtr->ts_font_face = atoi( it->second.c_str() );
  1425. };
  1426. it = cArr->find("ts_font_scale");
  1427. if( it != cArr->end() ){
  1428. tPtr->ts_font_scale = atof( it->second.c_str() );
  1429. };
  1430. it = cArr->find("ts_font_thickness");
  1431. if( it != cArr->end() ){
  1432. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  1433. };
  1434. it = cArr->find("ts_line_type");
  1435. if( it != cArr->end() ){
  1436. tPtr->ts_line_type = atoi( it->second.c_str() );
  1437. };
  1438. it = cArr->find("ts_transperant");
  1439. if( it != cArr->end() ){
  1440. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  1441. };
  1442. it = cArr->find("show_label");
  1443. if( it != cArr->end() ){
  1444. tPtr->show_label = (bool)atoi( it->second.c_str() );
  1445. };
  1446. it = cArr->find("label_x");
  1447. if( it != cArr->end() ){
  1448. tPtr->label_x = atoi( it->second.c_str() );
  1449. };
  1450. it = cArr->find("label_y");
  1451. if( it != cArr->end() ){
  1452. tPtr->label_y = atoi( it->second.c_str() );
  1453. };
  1454. it = cArr->find("label_font_face");
  1455. if( it != cArr->end() ){
  1456. tPtr->label_font_face = atoi( it->second.c_str() );
  1457. };
  1458. it = cArr->find("label_font_scale");
  1459. if( it != cArr->end() ){
  1460. tPtr->label_font_scale = atof( it->second.c_str() );
  1461. };
  1462. it = cArr->find("label_font_thickness");
  1463. if( it != cArr->end() ){
  1464. tPtr->label_font_thickness = atoi( it->second.c_str() );
  1465. };
  1466. it = cArr->find("label_line_type");
  1467. if( it != cArr->end() ){
  1468. tPtr->label_line_type = atoi( it->second.c_str() );
  1469. };
  1470. it = cArr->find("label_transperant");
  1471. if( it != cArr->end() ){
  1472. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  1473. };
  1474. it = cArr->find("show_logo");
  1475. if( it != cArr->end() ){
  1476. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  1477. };
  1478. it = cArr->find("logo_w");
  1479. if( it != cArr->end() ){
  1480. tPtr->logo_w = atoi( it->second.c_str() );
  1481. };
  1482. it = cArr->find("logo_h");
  1483. if( it != cArr->end() ){
  1484. tPtr->logo_h = atoi( it->second.c_str() );
  1485. };
  1486. it = cArr->find("logo_x");
  1487. if( it != cArr->end() ){
  1488. tPtr->logo_x = atoi( it->second.c_str() );
  1489. };
  1490. it = cArr->find("logo_y");
  1491. if( it != cArr->end() ){
  1492. tPtr->logo_y = atoi( it->second.c_str() );
  1493. };
  1494. it = cArr->find("logo_md5");
  1495. if( it != cArr->end() ){
  1496. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  1497. tPtr->logo_md5[32]=(char)0;
  1498. };
  1499. };
  1500. };
  1501. };
  1502. deleteResult( result );
  1503. };
  1504. return tPtr;
  1505. };
  1506. DBC_MEDIA_STREAM_DATA *sqliteDBC::getMediaStreamData(uint32_t ID){
  1507. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  1508. if( m_bStoIsConnected ){
  1509. char tQBuf[CTEXT];
  1510. AAssoc *result;
  1511. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  1512. #ifdef DEBUG_ALL
  1513. LOG(tQBuf);
  1514. #endif
  1515. result = m_pDataStorage->Query( tQBuf );
  1516. if( result!= NULL ) {
  1517. if( result->size() > 0 ) {
  1518. Assoc *cArr;
  1519. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  1520. if( tVal != NULL ) {
  1521. memset( tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA) );
  1522. Assoc::iterator it;
  1523. cArr = result->at(0);
  1524. tVal->id = ID;
  1525. it = cArr->find("source_id");
  1526. if( it != cArr->end() ){
  1527. tVal->source_id = atoi( it->second.c_str() );
  1528. };
  1529. it = cArr->find("source_type");
  1530. if( it != cArr->end() ){
  1531. sprintf( tVal->source_type, it->second.c_str() );
  1532. };
  1533. it = cArr->find("valid");
  1534. if( it != cArr->end() ){
  1535. tVal->valid = (bool) atoi( it->second.c_str() );
  1536. };
  1537. it = cArr->find("token");
  1538. if( it != cArr->end() ){
  1539. sprintf( tVal->token, it->second.c_str() );
  1540. };
  1541. it = cArr->find("img_width");
  1542. if( it != cArr->end() ){
  1543. tVal->width = atoi( it->second.c_str() );
  1544. };
  1545. it = cArr->find("img_height");
  1546. if( it != cArr->end() ){
  1547. tVal->height = atoi( it->second.c_str() );
  1548. };
  1549. it = cArr->find("fps");
  1550. if( it != cArr->end() ){
  1551. tVal->fps = atoi( it->second.c_str() );
  1552. };
  1553. it = cArr->find("compression_type");
  1554. if( it != cArr->end() ){
  1555. sprintf(tVal->c_type, it->second.c_str());
  1556. };
  1557. it = cArr->find("mrl_proto");
  1558. if( it != cArr->end() ){
  1559. sprintf( tVal->mrl_proto, it->second.c_str() );
  1560. };
  1561. it = cArr->find("mrl_port");
  1562. if( it != cArr->end() ){
  1563. tVal->mrl_port = atoi( it->second.c_str() );
  1564. };
  1565. it = cArr->find("mrl");
  1566. if( it != cArr->end() ){
  1567. sprintf( tVal->mrl, it->second.c_str() );
  1568. };
  1569. };
  1570. };
  1571. };
  1572. deleteResult( result );
  1573. };
  1574. return tVal;
  1575. };
  1576. uint32_t sqliteDBC::getMediaStreamID( uint32_t source_id, CSTR token ){
  1577. uint32_t RetVal = 0;
  1578. if( m_bStoIsConnected ){
  1579. char tQBuf[CTEXT];
  1580. AAssoc *result;
  1581. sprintf(tQBuf, "SELECT `id` FROM `media_streams` WHERE `source_id`=%d AND `token`='%s'", source_id, token );
  1582. #ifdef DEBUG_ALL
  1583. LOG(tQBuf);
  1584. #endif
  1585. result = m_pDataStorage->Query( tQBuf );
  1586. if( result!= NULL ) {
  1587. if( result->size() > 0 ) {
  1588. Assoc *cArr;
  1589. Assoc::iterator it;
  1590. cArr = result->at(0);
  1591. it = cArr->find("id");
  1592. if( it != cArr->end() ){
  1593. RetVal = atoi( it->second.c_str() );
  1594. };
  1595. };
  1596. };
  1597. deleteResult( result );
  1598. };
  1599. return RetVal;
  1600. };
  1601. DBC_MODEM_MANAGER_DATA *sqliteDBC::getModemManagerData( uint32_t ID ){
  1602. DBC_MODEM_MANAGER_DATA *tVal = NULL;
  1603. if( m_bStoIsConnected ){
  1604. char tQBuf[CTEXT];
  1605. AAssoc *result;
  1606. sprintf(tQBuf, "SELECT * FROM `module_modem` WHERE `id`=%d", ID);
  1607. #ifdef DEBUG_ALL
  1608. LOG(tQBuf);
  1609. #endif
  1610. result = m_pDataStorage->Query( tQBuf );
  1611. if( result!= NULL ) {
  1612. if( result->size() > 0 ) {
  1613. Assoc *cArr;
  1614. tVal = (DBC_MODEM_MANAGER_DATA*) malloc(sizeof(DBC_MODEM_MANAGER_DATA));
  1615. if( tVal != NULL ) {
  1616. memset( tVal, 0 , sizeof( DBC_MODEM_MANAGER_DATA ) );
  1617. tVal->id = ID;
  1618. Assoc::iterator it;
  1619. cArr = result->at(0);
  1620. it = cArr->find("modem_id");
  1621. if( it != cArr->end() ){
  1622. tVal->modem_id = atoi( it->second.c_str() );
  1623. };
  1624. it = cArr->find("evt_mode");
  1625. if( it != cArr->end() ){
  1626. tVal->evt_mode = atoi( it->second.c_str() );
  1627. };
  1628. it = cArr->find("time_window");
  1629. if( it != cArr->end() ){
  1630. tVal->time_window = atoi( it->second.c_str() );
  1631. };
  1632. it = cArr->find("sms_enabled");
  1633. if( it != cArr->end() ){
  1634. tVal->sms_enabled =(bool) atoi( it->second.c_str() );
  1635. };
  1636. it = cArr->find("call_enabled");
  1637. if( it != cArr->end() ){
  1638. tVal->call_enabled =(bool) atoi( it->second.c_str() );
  1639. };
  1640. it = cArr->find("call_hangup_wait");
  1641. if( it != cArr->end() ){
  1642. tVal->call_hangup_wait = atoi( it->second.c_str() );
  1643. };
  1644. };
  1645. };
  1646. };
  1647. deleteResult( result );
  1648. };
  1649. return tVal;
  1650. };
  1651. DBC_MODEM_PHONEBOOK_RECORD *sqliteDBC::getModemPhonebookRecord( uint32_t ID ){
  1652. DBC_MODEM_PHONEBOOK_RECORD *tVal = NULL;
  1653. if( m_bStoIsConnected ){
  1654. char tQBuf[CTEXT];
  1655. AAssoc *result;
  1656. sprintf(tQBuf, "SELECT * FROM `module_modem_phonebook` WHERE `id`=%d", ID);
  1657. #ifdef DEBUG_ALL
  1658. LOG(tQBuf);
  1659. #endif
  1660. result = m_pDataStorage->Query( tQBuf );
  1661. if( result!= NULL ) {
  1662. if( result->size() > 0 ) {
  1663. Assoc *cArr;
  1664. tVal = (DBC_MODEM_PHONEBOOK_RECORD*) malloc(sizeof(DBC_MODEM_PHONEBOOK_RECORD));
  1665. if( tVal != NULL ) {
  1666. memset( tVal, 0 , sizeof( DBC_MODEM_PHONEBOOK_RECORD ) );
  1667. Assoc::iterator it;
  1668. cArr = result->at(0);
  1669. it = cArr->find("id");
  1670. if( it != cArr->end() ){
  1671. tVal->id = atoi( it->second.c_str() );
  1672. };
  1673. it = cArr->find("number");
  1674. if( it != cArr->end() ){
  1675. strncpy( tVal->number, it->second.c_str(), 63 );
  1676. tVal->number[63]=(char)0;
  1677. };
  1678. it = cArr->find("mode");
  1679. if( it != cArr->end() ){
  1680. tVal->mode = atoi( it->second.c_str() );
  1681. };
  1682. it = cArr->find("trig_special");
  1683. if( it != cArr->end() ){
  1684. tVal->trigger_special = atoi( it->second.c_str() );
  1685. };
  1686. it = cArr->find("label");
  1687. if( it != cArr->end() ){
  1688. strncpy( tVal->label, it->second.c_str(), 63 );
  1689. tVal->label[63]=(char)0;
  1690. };
  1691. it = cArr->find("custom_msg");
  1692. if( it != cArr->end() ){
  1693. strncpy( tVal->custom_msg, it->second.c_str(), 127 );
  1694. tVal->custom_msg[127]=(char)0;
  1695. };
  1696. };
  1697. };
  1698. };
  1699. deleteResult( result );
  1700. };
  1701. return tVal;
  1702. };
  1703. DBC_MODULE_DATA *sqliteDBC::getModuleData( uint32_t ID ){
  1704. DBC_MODULE_DATA *tVal = NULL;
  1705. if( m_bStoIsConnected ){
  1706. char tQBuf[CTEXT];
  1707. AAssoc *result;
  1708. sprintf(tQBuf, "SELECT * FROM modules WHERE `id`=%d", ID );
  1709. #ifdef DEBUG_ALL
  1710. LOG(tQBuf);
  1711. #endif
  1712. result = m_pDataStorage->Query( tQBuf );
  1713. if( result!= NULL ) {
  1714. if( result->size() > 0 ) {
  1715. Assoc *cArr;
  1716. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  1717. if( tVal != NULL ) {
  1718. Assoc::iterator it;
  1719. cArr = result->at(0);
  1720. it = cArr->find("id");
  1721. if( it != cArr->end() ){
  1722. tVal->module_id = atoi( it->second.c_str() );
  1723. };
  1724. it = cArr->find("aux_id");
  1725. if( it != cArr->end() ){
  1726. tVal->aux_id = atoi( it->second.c_str() );
  1727. };
  1728. it = cArr->find("type");
  1729. if( it != cArr->end() ){
  1730. tVal->type = atoi( it->second.c_str() );
  1731. };
  1732. it = cArr->find("enabled");
  1733. if( it != cArr->end() ){
  1734. tVal->enabled = (bool)atoi( it->second.c_str() );
  1735. };
  1736. };
  1737. };
  1738. };
  1739. deleteResult( result );
  1740. };
  1741. return tVal;
  1742. };
  1743. DBC_LRF_INI *sqliteDBC::getINIData( uint32_t lrfID ){
  1744. DBC_LRF_INI * tVal = NULL;
  1745. if( m_bStoIsConnected ){
  1746. char tQBuf[CTEXT];
  1747. AAssoc *result;
  1748. sprintf(tQBuf, "SELECT * FROM `lrf_ini_settings` WHERE `sensor_id`=%d", lrfID );
  1749. #ifdef DEBUG_ALL
  1750. LOG(tQBuf);
  1751. #endif
  1752. result = m_pDataStorage->Query( tQBuf );
  1753. if( result!= NULL ) {
  1754. if( result->size() > 0 ) {
  1755. Assoc *cArr;
  1756. tVal = (DBC_LRF_INI*) malloc(sizeof(DBC_LRF_INI));
  1757. if( tVal != NULL ) {
  1758. memset( tVal, 0 , sizeof(DBC_LRF_INI));
  1759. Assoc::iterator it;
  1760. cArr = result->at(0);
  1761. it = cArr->find("AUTORESET_ENABLE");
  1762. if( it != cArr->end() ){
  1763. tVal->_AUTO_RESET_ENABLE = (bool) atoi( it->second.c_str() );
  1764. };
  1765. it = cArr->find("AUTORESET_INTERLEAVE");
  1766. if( it != cArr->end() ){
  1767. tVal->_AUTO_RESET_INTERLEAVE = atoi( it->second.c_str() );
  1768. };
  1769. it = cArr->find("AUTORESET_TIMEOUT");
  1770. if( it != cArr->end() ){
  1771. tVal->_AUTO_RESET_TIMEOUT = atoi( it->second.c_str() );
  1772. };
  1773. it = cArr->find("BOARD_TEMPERATURE");
  1774. if( it != cArr->end() ){
  1775. tVal->_BOARD_TEMPERATURE = atoi( it->second.c_str() );
  1776. };
  1777. it = cArr->find("BOARD_ZEROSHIFT");
  1778. if( it != cArr->end() ){
  1779. tVal->_BOARD_ZEROSHIFT = atoi( it->second.c_str() );
  1780. };
  1781. it = cArr->find("BOARD_SPEED");
  1782. if( it != cArr->end() ){
  1783. tVal->_BOARD_SPEED = atoi( it->second.c_str() );
  1784. };
  1785. it = cArr->find("RUN_DIR");
  1786. if( it != cArr->end() ){
  1787. tVal->_RUN_DIR = atoi( it->second.c_str() );
  1788. };
  1789. it = cArr->find("NO_BLACK_TARGETS");
  1790. if( it != cArr->end() ){
  1791. tVal->_NO_BLACK_TARGETS = atoi( it->second.c_str() );
  1792. };
  1793. it = cArr->find("JUST_MOVING_TARGETS");
  1794. if( it != cArr->end() ){
  1795. tVal->_JUST_MOVING_TARGETS = (bool) atoi( it->second.c_str() );
  1796. };
  1797. it = cArr->find("JUST_MOVING_RADIAL");
  1798. if( it != cArr->end() ){
  1799. tVal->_JUST_MOVING_RADIAL = (bool) atoi( it->second.c_str() );
  1800. };
  1801. it = cArr->find("JUST_MOVING_DISTANCE");
  1802. if( it != cArr->end() ){
  1803. tVal->_JUST_MOVING_DISTANCE = (bool) atoi( it->second.c_str() );
  1804. };
  1805. it = cArr->find("FREEZ_FIRST_TH");
  1806. if( it != cArr->end() ){
  1807. tVal->_FREEZ_FIRST_TH = (bool) atoi( it->second.c_str() );
  1808. };
  1809. it = cArr->find("SAVE_FIRST_TH");
  1810. if( it != cArr->end() ){
  1811. tVal->_SAVE_FIRST_TH = (bool) atoi( it->second.c_str() );
  1812. };
  1813. };
  1814. };
  1815. };
  1816. deleteResult( result );
  1817. };
  1818. return tVal;
  1819. };
  1820. bool sqliteDBC::getEventSessionStatus( uint32_t nodeID ){
  1821. bool rv = false;
  1822. if( m_bRepIsConnected ){
  1823. char tQBuf[CTEXT];
  1824. AAssoc *result;
  1825. //Since Unimodule -> no need to check NodeID
  1826. //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 );
  1827. 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 );
  1828. #ifdef DEBUG_ALL
  1829. LOG(tQBuf);
  1830. #endif
  1831. result = m_pDataReports->Query( tQBuf );
  1832. if( result!= NULL ) {
  1833. if( result->size() > 0 ) {
  1834. Assoc *cArr;
  1835. Assoc::iterator it;
  1836. cArr = result->at(0);
  1837. it = cArr->find("evt_type");
  1838. if( it != cArr->end() ){
  1839. if( atoi( it->second.c_str() ) == EVT_LRF_START_SESSION ) rv = true;
  1840. };
  1841. };
  1842. };
  1843. deleteResult( result );
  1844. };
  1845. return rv;
  1846. };
  1847. /*
  1848. * The Last TS is from the current report (as latest)
  1849. */
  1850. uint32_t sqliteDBC::getLastEventTS(){
  1851. uint32_t rv = 0;
  1852. if( m_bRepIsConnected ){
  1853. char tQBuf[CTEXT];
  1854. AAssoc *result;
  1855. sprintf( tQBuf, "SELECT `ts` FROM `events` ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1" );
  1856. #ifdef DEBUG_ALL
  1857. LOG(tQBuf);
  1858. #endif
  1859. result = m_pDataReports->Query( tQBuf );
  1860. if( result!= NULL ) {
  1861. if( result->size() > 0 ) {
  1862. Assoc *cArr;
  1863. Assoc::iterator it;
  1864. cArr = result->at(0);
  1865. it = cArr->find("ts");
  1866. if( it != cArr->end() ){
  1867. rv = atoi( it->second.c_str() );
  1868. };
  1869. };
  1870. };
  1871. deleteResult( result );
  1872. };
  1873. return rv;
  1874. };
  1875. /*
  1876. * The first TS is generaly must show a DAY of first registered event so TS fetched
  1877. * from general statistics
  1878. */
  1879. uint32_t sqliteDBC::getFirstEventTS(){
  1880. uint32_t rv = 0;
  1881. if( m_bStaIsConnected ){
  1882. char tQBuf[CTEXT];
  1883. AAssoc *result;
  1884. sprintf( tQBuf, "SELECT `year`,`month`,`day` FROM `days` ORDER BY `year`,`month`,`day` LIMIT 1" );
  1885. #ifdef DEBUG_ALL
  1886. LOG(tQBuf);
  1887. #endif
  1888. result = m_pDataStatistics->Query( tQBuf );
  1889. if( result!= NULL ) {
  1890. if( result->size() > 0 ) {
  1891. REPORT_DIRINFO RDF = { 0 };
  1892. Assoc *cArr;
  1893. Assoc::iterator it;
  1894. cArr = result->at(0);
  1895. it = cArr->find("year");
  1896. if( it != cArr->end() ){
  1897. strncpy( RDF.YEAR, it->second.c_str(), 4 );
  1898. };
  1899. it = cArr->find("month");
  1900. if( it != cArr->end() ){
  1901. strncpy( RDF.MONTH, it->second.c_str(), 2 );
  1902. };
  1903. it = cArr->find("day");
  1904. if( it != cArr->end() ){
  1905. strncpy( RDF.DAY, it->second.c_str(), 2 );
  1906. };
  1907. rv = getTsFromRDF( RDF );
  1908. };
  1909. };
  1910. deleteResult( result );
  1911. };
  1912. return rv;
  1913. };
  1914. bool sqliteDBC::deleteReportDate( uint32_t ts ){
  1915. if( ts ){
  1916. REPORT_DIRINFO tRDF = {0};
  1917. fillRDF( ts, tRDF );
  1918. LOG("Delete RDF Dir");
  1919. if( deleteRDFDir( m_pDbReportBase, tRDF ) ){
  1920. LOG("Dir Deleted OK");
  1921. return deleteReportStat( tRDF );
  1922. };
  1923. };
  1924. return false;
  1925. };
  1926. DBC_LRF_DATA *sqliteDBC::getLRFData( uint32_t ID ){
  1927. DBC_LRF_DATA * tVal = NULL;
  1928. if( m_bStoIsConnected ){
  1929. char tQBuf[CTEXT];
  1930. AAssoc *result;
  1931. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1932. #ifdef DEBUG_ALL
  1933. LOG(tQBuf);
  1934. #endif
  1935. result = m_pDataStorage->Query( tQBuf );
  1936. if( result!= NULL ) {
  1937. if( result->size() > 0 ) {
  1938. Assoc *cArr;
  1939. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1940. if( tVal != NULL ) {
  1941. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1942. Assoc::iterator it;
  1943. tVal->id = ID;
  1944. cArr = result->at(0);
  1945. it = cArr->find("data_status");
  1946. if( it != cArr->end() ){
  1947. tVal->data_status = atoi( it->second.c_str() );
  1948. };
  1949. it = cArr->find("serial");
  1950. if( it != cArr->end() ){
  1951. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1952. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1953. };
  1954. it = cArr->find("version");
  1955. if( it != cArr->end() ){
  1956. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1957. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1958. };
  1959. it = cArr->find("x");
  1960. if( it != cArr->end() ){
  1961. tVal->x = atof( it->second.c_str() );
  1962. };
  1963. it = cArr->find("y");
  1964. if( it != cArr->end() ){
  1965. tVal->y = atof( it->second.c_str() );
  1966. };
  1967. it = cArr->find("z");
  1968. if( it != cArr->end() ){
  1969. tVal->z = atof( it->second.c_str() );
  1970. };
  1971. it = cArr->find("x_rot");
  1972. if( it != cArr->end() ){
  1973. tVal->x_rot = atof( it->second.c_str() );
  1974. };
  1975. it = cArr->find("y_rot");
  1976. if( it != cArr->end() ){
  1977. tVal->y_rot = atof( it->second.c_str() );
  1978. };
  1979. it = cArr->find("z_rot");
  1980. if( it != cArr->end() ){
  1981. tVal->z_rot = atof( it->second.c_str() );
  1982. };
  1983. it = cArr->find("uart_id");
  1984. if( it != cArr->end() ){
  1985. tVal->uart_id = atoi( it->second.c_str() );
  1986. };
  1987. it = cArr->find("device_id");
  1988. if( it != cArr->end() ){
  1989. tVal->device_id = atoi( it->second.c_str() );
  1990. };
  1991. it = cArr->find("ip");
  1992. if( it != cArr->end() ){
  1993. sprintf( tVal->master_host, it->second.c_str() );
  1994. };
  1995. it = cArr->find("aux_ip");
  1996. if( it != cArr->end() ){
  1997. sprintf( tVal->slave_host, it->second.c_str() );
  1998. };
  1999. it = cArr->find("port");
  2000. if( it != cArr->end() ){
  2001. tVal->master_port = atoi( it->second.c_str() );
  2002. };
  2003. it = cArr->find("aux_port");
  2004. if( it != cArr->end() ){
  2005. tVal->slave_port = atoi( it->second.c_str() );
  2006. };
  2007. it = cArr->find("auto_draw");
  2008. if( it != cArr->end() ){
  2009. tVal->auto_draw = atoi( it->second.c_str() );
  2010. };
  2011. it = cArr->find("filter_id");
  2012. if( it != cArr->end() ){
  2013. tVal->filter_id = atoi( it->second.c_str() );
  2014. };
  2015. it = cArr->find("enabled_lrf");
  2016. if( it != cArr->end() ){
  2017. tVal->enabled_lrf = atoi( it->second.c_str() );
  2018. };
  2019. it = cArr->find("max_range");
  2020. if( it != cArr->end() ){
  2021. tVal->max_range = atof( it->second.c_str() );
  2022. };
  2023. it = cArr->find("base_shift");
  2024. if( it != cArr->end() ){
  2025. tVal->base_shift = atoi( it->second.c_str() );
  2026. };
  2027. //it = cArr->find("mirror_shift");
  2028. //if( it != cArr->end() ){
  2029. // tVal->mirror_shift = atoi( it->second.c_str() );
  2030. //};
  2031. it = cArr->find("detection_profile_id");
  2032. if( it != cArr->end() ){
  2033. tVal->detection_profile_id = atoi( it->second.c_str() );
  2034. };
  2035. it = cArr->find("prefered_camera_id");
  2036. if( it != cArr->end() ){
  2037. tVal->prefered_camera_id = atoi( it->second.c_str() );
  2038. };
  2039. /*
  2040. it = cArr->find("draw_lrf_id");
  2041. if( it != cArr->end() ){
  2042. tVal->draw_lrf_id = atoi( it->second.c_str() );
  2043. };
  2044. it = cArr->find("width_table_id");
  2045. if( it != cArr->end() ){
  2046. tVal->width_table_id = atoi( it->second.c_str() );
  2047. };
  2048. it = cArr->find("zoom_table_id");
  2049. if( it != cArr->end() ){
  2050. tVal->zoom_table_id = atoi( it->second.c_str() );
  2051. };
  2052. it = cArr->find("embd_cam");
  2053. if( it != cArr->end() ){
  2054. tVal->embd_cam = atoi( it->second.c_str() );
  2055. };
  2056. it = cArr->find("embd_cam_auto");
  2057. if( it != cArr->end() ){
  2058. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  2059. };
  2060. it = cArr->find("embd_dc");
  2061. if( it != cArr->end() ){
  2062. tVal->embd_dc = atoi( it->second.c_str() );
  2063. };
  2064. it = cArr->find("autoreset");
  2065. if( it != cArr->end() ){
  2066. tVal->autoreset = (bool)atoi( it->second.c_str() );
  2067. };
  2068. it = cArr->find("force_settings");
  2069. if( it != cArr->end() ){
  2070. tVal->force_settings = (bool)atoi( it->second.c_str() );
  2071. };
  2072. */
  2073. };
  2074. };
  2075. };
  2076. deleteResult( result );
  2077. };
  2078. return tVal;
  2079. };
  2080. PLGS_2D_PARAMETERS sqliteDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
  2081. PLGS_2D_PARAMETERS retVal = NULL;
  2082. if( m_bStoIsConnected ){
  2083. char tQBuf[CTEXT];
  2084. AAssoc *result;
  2085. sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=%d", lrfID, profileID,((master)?1:0) );
  2086. #ifdef DEBUG_ALL
  2087. LOG(tQBuf);
  2088. #endif
  2089. result = m_pDataStorage->Query( tQBuf );
  2090. if( result!= NULL ) {
  2091. if( result->size() > 0 ) {
  2092. retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
  2093. memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
  2094. Assoc *cArr;
  2095. Assoc::iterator it;
  2096. cArr = result->at(0);
  2097. it = cArr->find("order");
  2098. if( it != cArr->end() ){
  2099. retVal->nOrder = atoi(it->second.c_str());
  2100. };
  2101. it = cArr->find("offset");
  2102. if( it != cArr->end() ){
  2103. retVal->nOffset = atoi(it->second.c_str());
  2104. };
  2105. it = cArr->find("delta");
  2106. if( it != cArr->end() ){
  2107. retVal->nDelta = atoi(it->second.c_str());
  2108. };
  2109. it = cArr->find("flip");
  2110. if( it != cArr->end() ){
  2111. retVal->nFlip = atoi(it->second.c_str());
  2112. };
  2113. it = cArr->find("width");
  2114. if( it != cArr->end() ){
  2115. retVal->nWidth = atoi(it->second.c_str());
  2116. };
  2117. it = cArr->find("sst");
  2118. if( it != cArr->end() ){
  2119. retVal->bSST = atoi(it->second.c_str());
  2120. };
  2121. it = cArr->find("sun");
  2122. if( it != cArr->end() ){
  2123. retVal->nSun = atoi(it->second.c_str());
  2124. };
  2125. };
  2126. };
  2127. deleteResult( result );
  2128. };
  2129. return retVal;
  2130. };
  2131. RELAY_PARAMETERS *sqliteDBC::getLRFDryContact( uint32_t lrfID ){
  2132. RELAY_PARAMETERS *retVal = NULL;
  2133. if( m_bStoIsConnected ){
  2134. char tQBuf[CTEXT];
  2135. AAssoc *result;
  2136. sprintf(tQBuf, "SELECT `dc_auto`, `dc_no`, `dc_window` FROM `lrf_sensors` WHERE `id`=%d", lrfID );
  2137. #ifdef DEBUG_ALL
  2138. LOG(tQBuf);
  2139. #endif
  2140. result = m_pDataStorage->Query( tQBuf );
  2141. if( result!= NULL ) {
  2142. if( result->size() > 0 ) {
  2143. retVal = (RELAY_PARAMETERS*) malloc(sizeof(RELAY_PARAMETERS));
  2144. if( retVal ) {
  2145. Assoc *cArr;
  2146. Assoc::iterator it;
  2147. cArr = result->at(0);
  2148. it = cArr->find("dc_auto");
  2149. if( it != cArr->end() ){
  2150. retVal->bAuto = atoi( it->second.c_str() );
  2151. };
  2152. it = cArr->find("dc_no");
  2153. if( it != cArr->end() ){
  2154. retVal->bNormallyClose = ( atoi( it->second.c_str() ) == 0 );
  2155. };
  2156. it = cArr->find("dc_window");
  2157. if( it != cArr->end() ){
  2158. retVal->nAutoDelay = atoi( it->second.c_str() );
  2159. };
  2160. };
  2161. };
  2162. };
  2163. deleteResult( result );
  2164. };
  2165. return retVal;
  2166. };
  2167. uint8_t sqliteDBC::getLRFDataStatus( uint32_t ID ){
  2168. uint8_t RetVal = 0;
  2169. if( m_bStoIsConnected ){
  2170. char tQBuf[CTEXT];
  2171. AAssoc *result;
  2172. sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );
  2173. #ifdef DEBUG_ALL
  2174. LOG(tQBuf);
  2175. #endif
  2176. result = m_pDataStorage->Query( tQBuf );
  2177. if( result!= NULL ) {
  2178. if( result->size() > 0 ) {
  2179. Assoc *cArr;
  2180. Assoc::iterator it;
  2181. cArr = result->at(0);
  2182. it = cArr->find("data_status");
  2183. if( it != cArr->end() ){
  2184. RetVal = atoi( it->second.c_str() );
  2185. };
  2186. };
  2187. };
  2188. deleteResult( result );
  2189. };
  2190. return RetVal;
  2191. };
  2192. uint32_t sqliteDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){
  2193. uint32_t RetVal = 0;
  2194. if( m_bStoIsConnected ){
  2195. char tQBuf[CTEXT];
  2196. AAssoc *result;
  2197. sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );
  2198. #ifdef DEBUG_ALL
  2199. LOG(tQBuf);
  2200. #endif
  2201. result = m_pDataStorage->Query( tQBuf );
  2202. if( result!= NULL ) {
  2203. if( result->size() > 0 ) {
  2204. Assoc *cArr;
  2205. Assoc::iterator it;
  2206. cArr = result->at(0);
  2207. it = cArr->find("id");
  2208. if( it != cArr->end() ){
  2209. RetVal = atoi( it->second.c_str() );
  2210. };
  2211. };
  2212. };
  2213. deleteResult( result );
  2214. };
  2215. return RetVal;
  2216. };
  2217. uint32_t sqliteDBC::getLRFMaskPolygoneID( uint32_t maskID, uint8_t vertecID ){
  2218. uint32_t RetVal = 0;
  2219. if( m_bStoIsConnected ){
  2220. char tQBuf[CTEXT];
  2221. AAssoc *result;
  2222. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d AND `vertex_id`=%d", maskID, vertecID );
  2223. #ifdef DEBUG_ALL
  2224. LOG(tQBuf);
  2225. #endif
  2226. result = m_pDataStorage->Query( tQBuf );
  2227. if( result!= NULL ) {
  2228. if( result->size() > 0 ) {
  2229. Assoc *cArr;
  2230. Assoc::iterator it;
  2231. cArr = result->at(0);
  2232. it = cArr->find("id");
  2233. if( it != cArr->end() ){
  2234. RetVal = atoi( it->second.c_str() );
  2235. };
  2236. };
  2237. };
  2238. deleteResult( result );
  2239. };
  2240. return RetVal;
  2241. };
  2242. uint8_t sqliteDBC::getLRFMasksStatus( uint32_t deviceID ){
  2243. uint8_t RetVal = 0;
  2244. if( m_bStoIsConnected ){
  2245. char tQBuf[CTEXT];
  2246. AAssoc *result;
  2247. sprintf(tQBuf, "SELECT `layer` FROM `lrf_masks` WHERE `sensor_id`=%d AND `status`='E'", deviceID );
  2248. #ifdef DEBUG_ALL
  2249. LOG(tQBuf);
  2250. #endif
  2251. result = m_pDataStorage->Query( tQBuf );
  2252. if( result!= NULL ) {
  2253. if( result->size() > 0 ) {
  2254. Assoc *cArr;
  2255. Assoc::iterator it;
  2256. for(int i=0;i<result->size();i++) {
  2257. cArr = result->at(i);
  2258. it = cArr->find("layer");
  2259. if( it != cArr->end() ){
  2260. RetVal |= ( 1<< atoi( it->second.c_str() ));
  2261. };
  2262. };
  2263. };
  2264. };
  2265. deleteResult( result );
  2266. };
  2267. return RetVal;
  2268. };
  2269. DBC_LRF_UPLOAD_DATA *sqliteDBC::getLRFUploadData( uint32_t upID ){
  2270. DBC_LRF_UPLOAD_DATA *RetVal = NULL;
  2271. if( m_bStoIsConnected ){
  2272. char tQBuf[CTEXT];
  2273. AAssoc *result;
  2274. sprintf(tQBuf, "SELECT * FROM `lrf_uploads` WHERE `id`=%d", upID );
  2275. #ifdef DEBUG_ALL
  2276. LOG(tQBuf);
  2277. #endif
  2278. result = m_pDataStorage->Query( tQBuf );
  2279. if( result->size() > 0 ) {
  2280. Assoc *cArr;
  2281. RetVal = (DBC_LRF_UPLOAD_DATA*) malloc(sizeof(DBC_LRF_UPLOAD_DATA));
  2282. if( RetVal != NULL ) {
  2283. memset( RetVal, 0, sizeof(DBC_LRF_UPLOAD_DATA));
  2284. Assoc::iterator it;
  2285. RetVal->id = upID;
  2286. cArr = result->at(0);
  2287. it = cArr->find("md5");
  2288. if( it != cArr->end() ){
  2289. strncpy( RetVal->md5, it->second.c_str(), 32 );
  2290. };
  2291. it = cArr->find("file");
  2292. if( it != cArr->end() ){
  2293. strncpy( RetVal->fname, it->second.c_str(), 16 );
  2294. };
  2295. it = cArr->find("issue_reset");
  2296. if( it != cArr->end() ){
  2297. RetVal->transfer_mode = atoi( it->second.c_str() );
  2298. };
  2299. };
  2300. };
  2301. deleteResult( result );
  2302. };
  2303. return RetVal;
  2304. };
  2305. DBC_WIDTH_TABLE *sqliteDBC::getLRFWidthTable( uint32_t lrfID ){
  2306. DBC_WIDTH_TABLE *retVal = NULL;
  2307. if( m_bStoIsConnected ){
  2308. retVal = (DBC_WIDTH_TABLE *)malloc(sizeof(DBC_WIDTH_TABLE));
  2309. if ( retVal ) {
  2310. char tQBuf[CTEXT];
  2311. AAssoc *result;
  2312. sprintf(tQBuf, "SELECT `range_k`, `width_k` FROM `lrf_detection_width_tables` WHERE `aux_id`=%d ORDER BY `range_k`", lrfID );
  2313. #ifdef DEBUG_ALL
  2314. LOG(tQBuf);
  2315. #endif
  2316. memset( retVal, 0 , sizeof( DBC_WIDTH_TABLE ));
  2317. result = m_pDataStorage->Query( tQBuf );
  2318. if( result!= NULL ) {
  2319. if( result->size() > 0 ) {
  2320. retVal->count = result->size();
  2321. retVal->wt_records = (DBC_WT_RECORD*) calloc( retVal->count, sizeof(DBC_WT_RECORD));
  2322. if ( retVal->wt_records ) {
  2323. Assoc *cArr;
  2324. Assoc::iterator it;
  2325. for( int i = 0; i < retVal->count; i++ ) {
  2326. cArr = result->at(i);
  2327. it = cArr->find("range_k");
  2328. if( it != cArr->end() ){
  2329. retVal->wt_records[i].rangePercent = atoi( it->second.c_str() );
  2330. };
  2331. it = cArr->find("width_k");
  2332. if( it != cArr->end() ){
  2333. retVal->wt_records[i].widthPercent = atoi( it->second.c_str() );
  2334. };
  2335. };
  2336. } else {
  2337. //retVal->count = 0;
  2338. LOG_ERROR("No Memory To create WT Record!");
  2339. free( retVal );
  2340. retVal = NULL;
  2341. };
  2342. };
  2343. };
  2344. deleteResult( result );
  2345. } else {
  2346. LOG_ERROR("No Memory To create WT!");
  2347. };
  2348. };
  2349. return retVal;
  2350. };
  2351. uint32_t sqliteDBC::getNodeAuxParam( uint32_t NodeID ){
  2352. uint32_t retVal = 0;
  2353. if( m_bStoIsConnected ){
  2354. char tQBuf[CTEXT];
  2355. AAssoc *result;
  2356. sprintf(tQBuf, "SELECT `aux_parameter` FROM `nodes` WHERE `id`=%d", NodeID );
  2357. #ifdef DEBUG_ALL
  2358. LOG(tQBuf);
  2359. #endif
  2360. result = m_pDataStorage->Query( tQBuf );
  2361. if( result!= NULL ) {
  2362. if( result->size() > 0 ) {
  2363. Assoc *cArr;
  2364. Assoc::iterator it;
  2365. cArr = result->at(0);
  2366. it = cArr->find("aux_parameter");
  2367. if( it != cArr->end() ){
  2368. retVal = atoi( it->second.c_str() );
  2369. };
  2370. };
  2371. };
  2372. deleteResult( result );
  2373. };
  2374. return retVal;
  2375. };
  2376. DBC_NODE_DATA *sqliteDBC::getNodeData( uint32_t ID ){
  2377. DBC_NODE_DATA * tVal = NULL;
  2378. if( m_bStoIsConnected ){
  2379. char tQBuf[CTEXT];
  2380. AAssoc *result;
  2381. sprintf(tQBuf, "SELECT * FROM `nodes` WHERE `id`=%d", ID );
  2382. #ifdef DEBUG_ALL
  2383. LOG(tQBuf);
  2384. #endif
  2385. result = m_pDataStorage->Query( tQBuf );
  2386. if( result!= NULL ) {
  2387. if( result->size() > 0 ) {
  2388. Assoc *cArr;
  2389. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  2390. if( tVal != NULL ) {
  2391. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  2392. Assoc::iterator it;
  2393. tVal->node_id = ID;
  2394. cArr = result->at(0);
  2395. it = cArr->find("type");
  2396. if( it != cArr->end() ){
  2397. tVal->type = /*(NODE_TYPE)*/ atoi( it->second.c_str() );
  2398. };
  2399. it = cArr->find("aux_id");
  2400. if( it != cArr->end() ){
  2401. tVal->aux_id = atoi( it->second.c_str() );
  2402. };
  2403. it = cArr->find("aux_parameter");
  2404. if( it != cArr->end() ){
  2405. tVal->aux_parameter = atoi( it->second.c_str() );
  2406. };
  2407. it = cArr->find("online");
  2408. if( it != cArr->end() ){
  2409. tVal->online = (bool)atoi( it->second.c_str() );
  2410. };
  2411. it = cArr->find("enable");
  2412. if( it != cArr->end() ){
  2413. tVal->enabled = (bool)atoi( it->second.c_str() );
  2414. };
  2415. it = cArr->find("name");
  2416. if( it != cArr->end() ){
  2417. sprintf( tVal->name, it->second.c_str() );
  2418. };
  2419. };
  2420. };
  2421. };
  2422. deleteResult( result );
  2423. };
  2424. return tVal;
  2425. };
  2426. uint32_t sqliteDBC::getNodeIdByTypeAndAux( uint8_t type, uint32_t aux_id ){
  2427. uint32_t retVal = 0;
  2428. if( m_bStoIsConnected ){
  2429. char tQBuf[CTEXT];
  2430. AAssoc *result;
  2431. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `type`=%d AND `aux_id`=%d", type, aux_id);
  2432. #ifdef DEBUG_ALL
  2433. LOG(tQBuf);
  2434. #endif
  2435. result = m_pDataStorage->Query( tQBuf );
  2436. if( result!= NULL ) {
  2437. if( result->size() > 0 ) {
  2438. Assoc *cArr;
  2439. Assoc::iterator it;
  2440. cArr = result->at(0);
  2441. it = cArr->find("id");
  2442. if( it != cArr->end() ){
  2443. retVal = atoi( it->second.c_str() );
  2444. };
  2445. };
  2446. };
  2447. deleteResult( result );
  2448. };
  2449. return retVal;
  2450. };
  2451. CSTR sqliteDBC::getNodeName( uint32_t NodeID ){
  2452. CSTR retVal = NULL;
  2453. if( m_bStoIsConnected ){
  2454. char tQBuf[CTEXT];
  2455. AAssoc *result;
  2456. sprintf(tQBuf, "SELECT `name` FROM `nodes` WHERE `id`=%d", NodeID );
  2457. #ifdef DEBUG_ALL
  2458. LOG(tQBuf);
  2459. #endif
  2460. result = m_pDataStorage->Query( tQBuf );
  2461. if( result!= NULL ) {
  2462. if( result->size() > 0 ) {
  2463. Assoc *cArr;
  2464. Assoc::iterator it;
  2465. cArr = result->at(0);
  2466. it = cArr->find("name");
  2467. if( it != cArr->end() ){
  2468. retVal = strdup( it->second.c_str() );
  2469. };
  2470. };
  2471. };
  2472. deleteResult( result );
  2473. };
  2474. return retVal;
  2475. };
  2476. DBC_NET_IF_DATA *sqliteDBC::getNIF_Data( uint32_t nif_id ){
  2477. DBC_NET_IF_DATA * tVal = NULL;
  2478. if( m_bStoIsConnected ){
  2479. char tQBuf[CTEXT];
  2480. AAssoc *result;
  2481. sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id );
  2482. #ifdef DEBUG_ALL
  2483. LOG(tQBuf);
  2484. #endif
  2485. result = m_pDataStorage->Query( tQBuf );
  2486. if( result!= NULL ) {
  2487. if( result->size() > 0 ) {
  2488. Assoc *cArr;
  2489. tVal = (DBC_NET_IF_DATA*) malloc(sizeof(DBC_NET_IF_DATA));
  2490. if( tVal != NULL ) {
  2491. Assoc::iterator it;
  2492. tVal->id = nif_id;
  2493. cArr = result->at(0);
  2494. it = cArr->find("type");
  2495. if( it != cArr->end() ){
  2496. tVal->type = atoi(it->second.c_str());
  2497. };
  2498. it = cArr->find("mode");
  2499. if( it != cArr->end() ){
  2500. tVal->mode = atoi(it->second.c_str());
  2501. };
  2502. it = cArr->find("device_name");
  2503. if( it != cArr->end() ){
  2504. strncpy( tVal->device_name, it->second.c_str(),11);
  2505. tVal->device_name[10]=(char)0;
  2506. };
  2507. it = cArr->find("mac");
  2508. if( it != cArr->end() ){
  2509. strncpy( tVal->mac, it->second.c_str(), 33 );
  2510. tVal->mac[32]=(char)0;
  2511. };
  2512. it = cArr->find("aux_id");
  2513. if( it != cArr->end() ){
  2514. tVal->aux_id = atoi(it->second.c_str());
  2515. };
  2516. };
  2517. };
  2518. };
  2519. deleteResult( result );
  2520. };
  2521. return tVal;
  2522. };
  2523. uint32_t sqliteDBC::getNIF_ID( CSTR key ){
  2524. uint32_t tVal = 0;
  2525. if( m_bStoIsConnected ){
  2526. char tQBuf[CTEXT];
  2527. AAssoc *result;
  2528. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  2529. #ifdef DEBUG_ALL
  2530. LOG(tQBuf);
  2531. #endif
  2532. result = m_pDataStorage->Query( tQBuf );
  2533. if( result!= NULL ) {
  2534. if( result->size() > 0 ) {
  2535. Assoc *cArr;
  2536. Assoc::iterator it;
  2537. cArr = result->at(0);
  2538. it = cArr->find("id");
  2539. if( it != cArr->end() ){
  2540. tVal = atoi( it->second.c_str() );
  2541. };
  2542. };
  2543. };
  2544. deleteResult( result );
  2545. };
  2546. return tVal;
  2547. };
  2548. uint32_t sqliteDBC::getNIF_IDbyDevice( CSTR device ){
  2549. uint32_t tVal = 0;
  2550. if( m_bStoIsConnected ){
  2551. char tQBuf[CTEXT];
  2552. AAssoc *result;
  2553. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );
  2554. #ifdef DEBUG_ALL
  2555. LOG(tQBuf);
  2556. #endif
  2557. result = m_pDataStorage->Query( tQBuf );
  2558. if( result!= NULL ) {
  2559. if( result->size() > 0 ) {
  2560. Assoc *cArr;
  2561. Assoc::iterator it;
  2562. cArr = result->at(0);
  2563. it = cArr->find("id");
  2564. if( it != cArr->end() ){
  2565. tVal = atoi( it->second.c_str() );
  2566. };
  2567. };
  2568. };
  2569. deleteResult( result );
  2570. };
  2571. return tVal;
  2572. };
  2573. uint32_t sqliteDBC::getNetworkInfrastructureID( uint32_t nif_id ){
  2574. uint32_t tVal = 0;
  2575. if( m_bStoIsConnected ){
  2576. char tQBuf[CTEXT];
  2577. AAssoc *result;
  2578. sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id );
  2579. #ifdef DEBUG_ALL
  2580. LOG(tQBuf);
  2581. #endif
  2582. result = m_pDataStorage->Query( tQBuf );
  2583. if( result!= NULL ) {
  2584. if( result->size() > 0 ) {
  2585. Assoc *cArr;
  2586. Assoc::iterator it;
  2587. cArr = result->at(0);
  2588. it = cArr->find("id");
  2589. if( it != cArr->end() ){
  2590. tVal = atoi( it->second.c_str() );
  2591. };
  2592. };
  2593. };
  2594. deleteResult( result );
  2595. };
  2596. return tVal;
  2597. };
  2598. REPORT_DIRINFO *sqliteDBC::getReportDirInfo( uint32_t id ){
  2599. REPORT_DIRINFO *tVal = NULL;
  2600. if( m_bStaIsCreated ){
  2601. char tQBuf[CTEXT];
  2602. AAssoc *result;
  2603. sprintf(tQBuf, "SELECT * FROM `days` WHERE `ROWID`=%d", id );
  2604. #ifdef DEBUG_ALL
  2605. LOG(tQBuf);
  2606. #endif
  2607. result = m_pDataStorage->Query( tQBuf );
  2608. if( result!= NULL ) {
  2609. if( result->size() > 0 ) {
  2610. tVal = (REPORT_DIRINFO *) malloc( sizeof(REPORT_DIRINFO));
  2611. if ( tVal ) {
  2612. Assoc *cArr;
  2613. Assoc::iterator it;
  2614. memset( tVal, 0 , sizeof( REPORT_DIRINFO));
  2615. cArr = result->at(0);
  2616. it = cArr->find("year");
  2617. if( it != cArr->end() ){
  2618. strncpy( tVal->YEAR, it->second.c_str(), 5 );
  2619. };
  2620. it = cArr->find("month");
  2621. if( it != cArr->end() ){
  2622. strncpy( tVal->MONTH, it->second.c_str(), 3 );
  2623. };
  2624. it = cArr->find("day");
  2625. if( it != cArr->end() ){
  2626. strncpy( tVal->DAY, it->second.c_str(), 3 );
  2627. };
  2628. };
  2629. };
  2630. };
  2631. deleteResult( result );
  2632. };
  2633. return tVal;
  2634. };
  2635. DBC_RESOURCE_DATA *sqliteDBC::getResourceData( uint32_t ResourceID ){
  2636. DBC_RESOURCE_DATA *tVal = NULL;
  2637. if( m_bStoIsConnected ){
  2638. char tQBuf[CTEXT];
  2639. AAssoc *result;
  2640. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM `resources` WHERE `id`=%d", ResourceID );
  2641. #ifdef DEBUG_ALL
  2642. LOG(tQBuf);
  2643. #endif
  2644. result = m_pDataStorage->Query( tQBuf );
  2645. if( result!= NULL ) {
  2646. if( result->size() > 0 ) {
  2647. Assoc *cArr;
  2648. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  2649. if( tVal != NULL ) {
  2650. Assoc::iterator it;
  2651. cArr = result->at(0);
  2652. tVal->id = ResourceID;
  2653. it = cArr->find("node_id");
  2654. if( it != cArr->end() ){
  2655. tVal->node_id = atoi( it->second.c_str() );
  2656. };
  2657. it = cArr->find("type");
  2658. if( it != cArr->end() ){
  2659. tVal->type = atoi( it->second.c_str() );
  2660. };
  2661. it = cArr->find("aux_id");
  2662. if( it != cArr->end() ){
  2663. tVal->aux_id = atoi( it->second.c_str() );
  2664. };
  2665. it = cArr->find("device");
  2666. if( it != cArr->end() ){
  2667. strncpy( tVal->device, it->second.c_str(), 64 );
  2668. tVal->device[63] = (char)0;
  2669. };
  2670. };
  2671. };
  2672. };
  2673. deleteResult( result );
  2674. };
  2675. return tVal;
  2676. };
  2677. uint32_t sqliteDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  2678. uint32_t RetVal = 0;
  2679. if( m_bStoIsConnected ){
  2680. char tQBuf[CTEXT];
  2681. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  2682. #ifdef DEBUG_ALL
  2683. LOG(tQBuf);
  2684. #endif
  2685. AAssoc *result;
  2686. result = m_pDataStorage->Query( tQBuf );
  2687. if( result!= NULL ) {
  2688. if( result->size() > 0 ) {
  2689. Assoc * cArr;
  2690. Assoc::iterator it;
  2691. cArr = result->at(0);
  2692. it = cArr->find("id");
  2693. if( it != cArr->end() ){
  2694. RetVal = atoi( it->second.c_str() );
  2695. };
  2696. };
  2697. };
  2698. deleteResult( result );
  2699. };
  2700. return RetVal;
  2701. };
  2702. DBC_SITE_DATA *sqliteDBC::getSiteData( uint32_t ID ){
  2703. DBC_SITE_DATA * tVal = NULL;
  2704. if( m_bStoIsConnected ){
  2705. char tQBuf[CTEXT];
  2706. AAssoc *result;
  2707. sprintf(tQBuf, "SELECT * FROM `system_props` WHERE `id`=%d", ID);
  2708. #ifdef DEBUG_ALL
  2709. LOG(tQBuf);
  2710. #endif
  2711. result = m_pDataStorage->Query( tQBuf );
  2712. if( result!= NULL ) {
  2713. if( result->size() > 0 ) {
  2714. Assoc *cArr;
  2715. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  2716. if( tVal != NULL ) {
  2717. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  2718. Assoc::iterator it;
  2719. cArr = result->at(0);
  2720. it = cArr->find("type");
  2721. if( it != cArr->end() ){
  2722. tVal->account_id = atoi( it->second.c_str() );
  2723. };
  2724. it = cArr->find("name");
  2725. if( it != cArr->end() ){
  2726. sprintf( tVal->name, it->second.c_str() );
  2727. };
  2728. //it = cArr->find("server_ident");
  2729. //if( it != cArr->end() ){
  2730. // sprintf( tVal->ident, it->second.c_str() );
  2731. //};
  2732. it = cArr->find("anchor_lat");
  2733. if( it != cArr->end() ){
  2734. tVal->lat = atof( it->second.c_str() );
  2735. };
  2736. it = cArr->find("anchor_lon");
  2737. if( it != cArr->end() ){
  2738. tVal->lon = atof( it->second.c_str() );
  2739. };
  2740. it = cArr->find("anchor_alt");
  2741. if( it != cArr->end() ){
  2742. tVal->alt = atof( it->second.c_str() );
  2743. };
  2744. it = cArr->find("hemisphere");
  2745. if( it != cArr->end() ){
  2746. tVal->SH = ( it->second.c_str()[0] == 'S' );
  2747. };
  2748. it = cArr->find("map_id");
  2749. if( it != cArr->end() ){
  2750. tVal->map_id = atoi( it->second.c_str() );
  2751. };
  2752. it = cArr->find("local_binding");
  2753. if( it != cArr->end() ){
  2754. tVal->local_binding = (bool) atoi(it->second.c_str());
  2755. };
  2756. it = cArr->find("work_mode");
  2757. if( it != cArr->end() ){
  2758. tVal->work_mode = atoi(it->second.c_str());
  2759. };
  2760. it = cArr->find("report_cleanup");
  2761. if( it != cArr->end() ){
  2762. tVal->report_cleanup = atoi(it->second.c_str());
  2763. };
  2764. it = cArr->find("preserve_empty");
  2765. if( it != cArr->end() ){
  2766. tVal->preserve_empty = atoi(it->second.c_str());
  2767. };
  2768. it = cArr->find("remote_ip");
  2769. if( it != cArr->end() ){
  2770. sprintf( tVal->remote_ip, it->second.c_str() );
  2771. };
  2772. it = cArr->find("remote_port");
  2773. if( it != cArr->end() ){
  2774. tVal->remote_port = atoi(it->second.c_str());
  2775. };
  2776. it = cArr->find("use_remote_server");
  2777. if( it != cArr->end() ){
  2778. tVal->use_remote_server = atoi(it->second.c_str());
  2779. };
  2780. it = cArr->find("skip_local_report");
  2781. if( it != cArr->end() ){
  2782. tVal->skip_local_report = atoi(it->second.c_str());
  2783. };
  2784. };
  2785. };
  2786. };
  2787. deleteResult( result );
  2788. };
  2789. return tVal;
  2790. };
  2791. uint32_t sqliteDBC::getServerID( CSTR identity ){
  2792. uint32_t RetVal = 0;
  2793. if( m_bStoIsConnected ){
  2794. char tQBuf[CTEXT];
  2795. sprintf(tQBuf,"SELECT `id` FROM `servers` WHERE `identity`='%s'", identity );
  2796. #ifdef DEBUG_ALL
  2797. LOG(tQBuf);
  2798. #endif
  2799. AAssoc *result;
  2800. result = m_pDataStorage->Query( tQBuf );
  2801. if( result!= NULL ) {
  2802. if( result->size() > 0 ) {
  2803. Assoc * cArr;
  2804. Assoc::iterator it;
  2805. cArr = result->at(0);
  2806. it = cArr->find("id");
  2807. if( it != cArr->end() ){
  2808. RetVal = atoi( it->second.c_str() );
  2809. };
  2810. };
  2811. };
  2812. deleteResult( result );
  2813. };
  2814. return RetVal;
  2815. };
  2816. uint32_t sqliteDBC::getServerNode( uint32_t SID ){
  2817. uint32_t RetVal = 0;
  2818. if( m_bStoIsConnected ){
  2819. char tQBuf[CTEXT];
  2820. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  2821. #ifdef DEBUG_ALL
  2822. LOG(tQBuf);
  2823. #endif
  2824. AAssoc *result;
  2825. result = m_pDataStorage->Query( tQBuf );
  2826. if( result!= NULL ) {
  2827. if( result->size() > 0 ) {
  2828. Assoc * cArr;
  2829. Assoc::iterator it;
  2830. cArr = result->at(0);
  2831. it = cArr->find("id");
  2832. if( it != cArr->end() ){
  2833. RetVal = atoi( it->second.c_str() );
  2834. };
  2835. };
  2836. };
  2837. deleteResult( result );
  2838. };
  2839. return RetVal;
  2840. }
  2841. DBC_TARGET_FLITER_DATA *sqliteDBC::getTargetFilterData( uint32_t ID ){
  2842. DBC_TARGET_FLITER_DATA * tVal = NULL;
  2843. if( m_bStoIsConnected ){
  2844. char tQBuf[CTEXT];
  2845. AAssoc *result;
  2846. sprintf(tQBuf, "SELECT * FROM `target_filters` WHERE `id`=%d", ID );
  2847. #ifdef DEBUG_ALL
  2848. LOG(tQBuf);
  2849. #endif
  2850. result = m_pDataStorage->Query( tQBuf );
  2851. if( result!= NULL ) {
  2852. if( result->size() > 0 ) {
  2853. Assoc *cArr;
  2854. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  2855. if( tVal != NULL ) {
  2856. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  2857. Assoc::iterator it;
  2858. tVal->id = ID;
  2859. cArr = result->at(0);
  2860. it = cArr->find("type");
  2861. if( it != cArr->end() ){
  2862. tVal->type = (TARGET_FILTER_TYPE) atoi( it->second.c_str() );
  2863. };
  2864. it = cArr->find("aux_id");
  2865. if( it != cArr->end() ){
  2866. tVal->aux_id = atoi( it->second.c_str() );
  2867. };
  2868. it = cArr->find("enabled");
  2869. if( it != cArr->end() ){
  2870. tVal->enabled = (bool) atoi( it->second.c_str() );
  2871. };
  2872. };
  2873. };
  2874. };
  2875. deleteResult( result );
  2876. };
  2877. return tVal;
  2878. };
  2879. TRAIN_FILTER_DATA *sqliteDBC::getTrainFilterData( uint32_t ID ){
  2880. TRAIN_FILTER_DATA * tVal = NULL;
  2881. if( m_bStoIsConnected ){
  2882. char tQBuf[CTEXT];
  2883. AAssoc *result;
  2884. sprintf(tQBuf, "SELECT * FROM `target_filter_train` WHERE `id`=%d", ID );
  2885. #ifdef DEBUG_ALL
  2886. LOG(tQBuf);
  2887. #endif
  2888. result = m_pDataStorage->Query( tQBuf );
  2889. if( result!= NULL ) {
  2890. if( result->size() > 0 ) {
  2891. Assoc *cArr;
  2892. tVal = (TRAIN_FILTER_DATA*) malloc(sizeof(TRAIN_FILTER_DATA));
  2893. if( tVal != NULL ) {
  2894. memset( tVal, 0 , sizeof(TRAIN_FILTER_DATA));
  2895. Assoc::iterator it;
  2896. cArr = result->at(0);
  2897. it = cArr->find("UPPER_SENSOR");
  2898. if( it != cArr->end() ){
  2899. tVal->nUpperSensorID = atoi( it->second.c_str() );
  2900. };
  2901. it = cArr->find("LOWER_SENSOR");
  2902. if( it != cArr->end() ){
  2903. tVal->nBottomSensorID = atoi( it->second.c_str() );
  2904. };
  2905. it = cArr->find("TRAIN_DETECT");
  2906. if( it != cArr->end() ){
  2907. tVal->bDetectTrain = (bool)atoi( it->second.c_str() );
  2908. };
  2909. it = cArr->find("TRAIN_WIDTH");
  2910. if( it != cArr->end() ){
  2911. tVal->nTrainWidth = atoi( it->second.c_str() );
  2912. };
  2913. it = cArr->find("DECISION_TIME");
  2914. if( it != cArr->end() ){
  2915. tVal->nDecisionTime = 1000 * atoi( it->second.c_str() );
  2916. };
  2917. it = cArr->find("SUSPECT_TIME");
  2918. if( it != cArr->end() ){
  2919. tVal->nSuspectTime = 1000 * atoi( it->second.c_str() );
  2920. };
  2921. it = cArr->find("TRACK_TRAIN");
  2922. if( it != cArr->end() ){
  2923. tVal->bTrackTrain = (bool)atoi( it->second.c_str() );
  2924. };
  2925. it = cArr->find("AUX_IP");
  2926. if( it != cArr->end() ){
  2927. strncpy( tVal->aux_ip, it->second.c_str(), 15 );
  2928. };
  2929. //it = cArr->find("AUX_PORT");
  2930. //if( it != cArr->end() ){
  2931. // tVal->aux_port = atoi( it->second.c_str() );
  2932. //};
  2933. it = cArr->find("DEBUG");
  2934. if( it != cArr->end() ){
  2935. tVal->bDebugMode = (bool)atoi( it->second.c_str() );
  2936. };
  2937. };
  2938. };
  2939. };
  2940. deleteResult( result );
  2941. };
  2942. return tVal;
  2943. };
  2944. DBC_UART_DATA *sqliteDBC::getUartData( uint32_t UartID ){
  2945. DBC_UART_DATA *tVal = NULL;
  2946. if( m_bStoIsConnected ) {
  2947. char tQBuf[MAX_PATH_LEN];
  2948. AAssoc *result;
  2949. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  2950. #ifdef DEBUG_ALL
  2951. LOG(tQBuf);
  2952. #endif
  2953. result = m_pDataStorage->Query( tQBuf );
  2954. if( result!= NULL ) {
  2955. if( result->size() > 0 ) {
  2956. Assoc *cArr;
  2957. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  2958. if( tVal != NULL ) {
  2959. Assoc::iterator it;
  2960. cArr = result->at(0);
  2961. it = cArr->find("type");
  2962. if( it != cArr->end() ){
  2963. tVal->type = atoi( it->second.c_str() );
  2964. };
  2965. it = cArr->find("speed");
  2966. if( it != cArr->end() ){
  2967. tVal->speed = atoi( it->second.c_str() );
  2968. };
  2969. it = cArr->find("mode");
  2970. if( it != cArr->end() ){
  2971. tVal->mode = atoi( it->second.c_str() );
  2972. };
  2973. it = cArr->find("port");
  2974. if( it != cArr->end() ){
  2975. tVal->port = atoi( it->second.c_str() );
  2976. };
  2977. it = cArr->find("path");
  2978. if( it != cArr->end() ){
  2979. strncpy( tVal->path, it->second.c_str(), 128 );
  2980. };
  2981. };
  2982. };
  2983. };
  2984. deleteResult( result );
  2985. };
  2986. return tVal;
  2987. };
  2988. uint32_t sqliteDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  2989. uint32_t RetVal = 0;
  2990. if( m_bStoIsConnected ){
  2991. char tQBuf[CTEXT];
  2992. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  2993. #ifdef DEBUG_ALL
  2994. LOG(tQBuf);
  2995. #endif
  2996. AAssoc *result;
  2997. result = m_pDataStorage->Query( tQBuf );
  2998. if( result!= NULL ) {
  2999. if( result->size() > 0 ) {
  3000. Assoc * cArr;
  3001. Assoc::iterator it;
  3002. cArr = result->at(0);
  3003. it = cArr->find("id");
  3004. if( it != cArr->end() ){
  3005. RetVal = atoi( it->second.c_str() );
  3006. };
  3007. };
  3008. };
  3009. deleteResult( result );
  3010. };
  3011. return RetVal;
  3012. };
  3013. uint32_t sqliteDBC::getWiFi_ID( uint32_t nif_id ){
  3014. uint32_t tVal = 0;
  3015. if( m_bStoIsConnected ){
  3016. char tQBuf[CTEXT];
  3017. AAssoc *result;
  3018. sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );
  3019. #ifdef DEBUG_ALL
  3020. LOG(tQBuf);
  3021. #endif
  3022. result = m_pDataStorage->Query( tQBuf );
  3023. if( result!= NULL ) {
  3024. if( result->size() > 0 ) {
  3025. Assoc *cArr;
  3026. Assoc::iterator it;
  3027. cArr = result->at(0);
  3028. it = cArr->find("id");
  3029. if( it != cArr->end() ){
  3030. tVal = atoi( it->second.c_str() );
  3031. };
  3032. };
  3033. };
  3034. deleteResult( result );
  3035. };
  3036. return tVal;
  3037. };
  3038. DBC_INT_LIST *sqliteDBC::listCamPresets( uint32_t SETID ){
  3039. DBC_INT_LIST * tVal = NULL;
  3040. if( m_bStoIsConnected ){
  3041. char tQBuf[CTEXT];
  3042. AAssoc *result;
  3043. sprintf(tQBuf, "SELECT `id` FROM `cameras_presets` WHERE `preset_id`=%d", SETID );
  3044. #ifdef DEBUG_ALL
  3045. LOG(tQBuf);
  3046. #endif
  3047. result = m_pDataStorage->Query( tQBuf );
  3048. if( result!= NULL ) {
  3049. if( result->size() > 0 ) {
  3050. Assoc *cArr;
  3051. tVal = new DBC_INT_LIST();
  3052. if( tVal != NULL ) {
  3053. Assoc::iterator it;
  3054. for(int i=0;i<result->size();i++) {
  3055. cArr = result->at(i);
  3056. it = cArr->find("id");
  3057. if( it != cArr->end() ){
  3058. tVal->push_back( atoi( it->second.c_str() ));
  3059. };
  3060. };
  3061. };
  3062. };
  3063. };
  3064. deleteResult( result );
  3065. };
  3066. return tVal;
  3067. };
  3068. DBC_INT_LIST *sqliteDBC::listFilters( uint32_t ServerID ){
  3069. DBC_INT_LIST * tVal = NULL;
  3070. if( m_bStoIsConnected ){
  3071. char tQBuf[CTEXT];
  3072. AAssoc *result;
  3073. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `enabled`=1" );
  3074. #ifdef DEBUG_ALL
  3075. LOG(tQBuf);
  3076. #endif
  3077. result = m_pDataStorage->Query( tQBuf );
  3078. if( result!= NULL ) {
  3079. if( result->size() > 0 ) {
  3080. Assoc *cArr;
  3081. tVal = new DBC_INT_LIST();
  3082. if( tVal != NULL ) {
  3083. Assoc::iterator it;
  3084. for(int i=0;i<result->size();i++) {
  3085. cArr = result->at(i);
  3086. it = cArr->find("id");
  3087. if( it != cArr->end() ){
  3088. tVal->push_back( atoi( it->second.c_str() ));
  3089. };
  3090. };
  3091. };
  3092. };
  3093. };
  3094. deleteResult( result );
  3095. };
  3096. return tVal;
  3097. };
  3098. DBC_INT_LIST *sqliteDBC::listLRFUploads( uint32_t deviceID ){
  3099. DBC_INT_LIST * tVal = NULL;
  3100. if( m_bStoIsConnected ){
  3101. char tQBuf[CTEXT];
  3102. AAssoc *result;
  3103. sprintf(tQBuf, "SELECT `id` FROM `lrf_uploads` WHERE `status`=-1 AND `sensor_id`=%d", deviceID );
  3104. #ifdef DEBUG_ALL
  3105. LOG(tQBuf);
  3106. #endif
  3107. result = m_pDataStorage->Query( tQBuf );
  3108. if( result!= NULL ) {
  3109. if( result->size() > 0 ) {
  3110. Assoc *cArr;
  3111. tVal = new DBC_INT_LIST();
  3112. if( tVal != NULL ) {
  3113. Assoc::iterator it;
  3114. for(int i=0;i<result->size();i++) {
  3115. cArr = result->at(i);
  3116. it = cArr->find("id");
  3117. if( it != cArr->end() ){
  3118. tVal->push_back( atoi( it->second.c_str() ));
  3119. };
  3120. };
  3121. };
  3122. };
  3123. };
  3124. deleteResult( result );
  3125. };
  3126. return tVal;
  3127. };
  3128. DBC_INT_LIST *sqliteDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  3129. DBC_INT_LIST * tVal = NULL;
  3130. if( m_bStoIsConnected ){
  3131. char tQBuf[CTEXT];
  3132. AAssoc *result;
  3133. switch( listMode ){
  3134. case LIST_VALID_RECORDS:
  3135. 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" );
  3136. break;
  3137. case LIST_INVALID_RECORDS:
  3138. 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" );
  3139. break;
  3140. default:
  3141. 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" );
  3142. };
  3143. #ifdef DEBUG_ALL
  3144. LOG(tQBuf);
  3145. #endif
  3146. result = m_pDataStorage->Query( tQBuf );
  3147. if( result!= NULL ) {
  3148. if( result->size() > 0 ) {
  3149. Assoc *cArr;
  3150. tVal = new DBC_INT_LIST();
  3151. if( tVal != NULL ) {
  3152. Assoc::iterator it;
  3153. for(int i=0;i<result->size();i++) {
  3154. cArr = result->at(i);
  3155. it = cArr->find("id");
  3156. if( it != cArr->end() ){
  3157. tVal->push_back( atoi( it->second.c_str() ));
  3158. };
  3159. };
  3160. };
  3161. };
  3162. };
  3163. deleteResult( result );
  3164. };
  3165. return tVal;
  3166. };
  3167. DBC_INT_LIST *sqliteDBC::listModules(){
  3168. DBC_INT_LIST * tVal = NULL;
  3169. if( m_bStoIsConnected ){
  3170. AAssoc *result;
  3171. result = m_pDataStorage->Query( "SELECT `id` FROM `modules` WHERE `enabled`=1" );
  3172. if( result!= NULL ) {
  3173. if( result->size() > 0 ) {
  3174. Assoc *cArr;
  3175. tVal = new DBC_INT_LIST();
  3176. if( tVal != NULL ) {
  3177. Assoc::iterator it;
  3178. for(int i=0;i<result->size();i++) {
  3179. cArr = result->at(i);
  3180. it = cArr->find("id");
  3181. if( it != cArr->end() ){
  3182. tVal->push_back( atoi( it->second.c_str() ));
  3183. };
  3184. };
  3185. };
  3186. };
  3187. };
  3188. deleteResult( result );
  3189. };
  3190. return tVal;
  3191. };
  3192. DBC_INT_LIST *sqliteDBC::listNewModules( DBC_INT_LIST * old_ids ){
  3193. DBC_INT_LIST * tVal = NULL;
  3194. if( m_bStoIsConnected ){
  3195. char tParam[CTEXT];
  3196. //memset( tParam, 0, CTEXT );
  3197. sprintf(tParam,"0");
  3198. if( old_ids != NULL ) {
  3199. char tBuffer[CTEXT];
  3200. for(int i = 0; i< old_ids->size(); i++ ) {
  3201. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  3202. strncpy( tParam, tBuffer, CTEXT );
  3203. };
  3204. };
  3205. char tQBuf[CTEXT];
  3206. AAssoc *result;
  3207. sprintf(tQBuf, "SELECT `id` FROM `modules` WHERE `enabled`=1 AND `id` NOT IN (%s)", tParam );
  3208. #ifdef DEBUG_ALL
  3209. LOG(tQBuf);
  3210. #endif
  3211. result = m_pDataStorage->Query( tQBuf );
  3212. if( result!= NULL ) {
  3213. if( result->size() > 0 ) {
  3214. Assoc *cArr;
  3215. tVal = new DBC_INT_LIST();
  3216. if( tVal != NULL ) {
  3217. Assoc::iterator it;
  3218. for(int i=0;i<result->size();i++) {
  3219. cArr = result->at(i);
  3220. it = cArr->find("id");
  3221. if( it != cArr->end() ){
  3222. tVal->push_back( atoi( it->second.c_str() ));
  3223. };
  3224. };
  3225. };
  3226. };
  3227. };
  3228. deleteResult( result );
  3229. };
  3230. return tVal;
  3231. };
  3232. DBC_INT_LIST *sqliteDBC::listNewNodes( DBC_INT_LIST * old_ids ){
  3233. DBC_INT_LIST * tVal = NULL;
  3234. if( m_bStoIsConnected ){
  3235. char tParam[CTEXT];
  3236. //memset( tParam, 0, CTEXT );
  3237. sprintf(tParam,"0");
  3238. if( old_ids != NULL ) {
  3239. char tBuffer[CTEXT];
  3240. for(int i = 0; i< old_ids->size(); i++ ) {
  3241. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  3242. strncpy( tParam, tBuffer, CTEXT );
  3243. };
  3244. };
  3245. char tQBuf[CTEXT];
  3246. AAssoc *result;
  3247. sprintf(tQBuf, "SELECT id FROM nodes WHERE `type` > 0 AND `enable`=1 AND `id` NOT IN(%s)", tParam );
  3248. #ifdef DEBUG_ALL
  3249. LOG(tQBuf);
  3250. #endif
  3251. result = m_pDataStorage->Query( tQBuf );
  3252. if( result!= NULL ) {
  3253. if( result->size() > 0 ) {
  3254. Assoc *cArr;
  3255. tVal = new DBC_INT_LIST();
  3256. if( tVal != NULL ) {
  3257. Assoc::iterator it;
  3258. for(int i=0;i<result->size();i++) {
  3259. cArr = result->at(i);
  3260. it = cArr->find("id");
  3261. if( it != cArr->end() ){
  3262. tVal->push_back( atoi( it->second.c_str() ));
  3263. };
  3264. };
  3265. };
  3266. };
  3267. };
  3268. deleteResult( result );
  3269. };
  3270. return tVal;
  3271. };
  3272. DBC_INT_LIST *sqliteDBC::listNodes( bool all ){
  3273. DBC_INT_LIST * tVal = NULL;
  3274. if( m_bStoIsConnected ){
  3275. char tQBuf[1024];
  3276. AAssoc *result;
  3277. if( all ) {
  3278. sprintf(tQBuf, "SELECT `id` FROM `nodes`");
  3279. } else {
  3280. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `type` > 0 AND `enable`=1" );
  3281. };
  3282. #ifdef DEBUG_ALL
  3283. LOG(tQBuf);
  3284. #endif
  3285. result = m_pDataStorage->Query( tQBuf );
  3286. if( result!= NULL ) {
  3287. if( result->size() > 0 ) {
  3288. Assoc *cArr;
  3289. tVal = new DBC_INT_LIST();
  3290. if( tVal != NULL ) {
  3291. Assoc::iterator it;
  3292. for(int i=0; i <result->size();i++) {
  3293. cArr = result->at(i);
  3294. it = cArr->find("id");
  3295. if( it != cArr->end() ){
  3296. tVal->push_back( atoi( it->second.c_str() ));
  3297. };
  3298. };
  3299. };
  3300. };
  3301. };
  3302. deleteResult( result );
  3303. };
  3304. return tVal;
  3305. };
  3306. DBC_INT_LIST *sqliteDBC::listOlderReportStat( CSTR Y, CSTR M, CSTR D ){
  3307. DBC_INT_LIST * tVal = NULL;
  3308. if ( m_bStaIsConnected ) {
  3309. char tQBuf[MAX_PATH_LEN];
  3310. AAssoc *result;
  3311. 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 );
  3312. result = m_pDataStatistics->Query( tQBuf );
  3313. if( result!= NULL ) {
  3314. if( result->size() > 0 ) {
  3315. Assoc *cArr;
  3316. tVal = new DBC_INT_LIST();
  3317. if( tVal != NULL ) {
  3318. Assoc::iterator it;
  3319. for(int i=0;i<result->size();i++) {
  3320. cArr = result->at(i);
  3321. it = cArr->find("ROWID");
  3322. if( it != cArr->end() ){
  3323. tVal->push_back( atoi( it->second.c_str() ));
  3324. };
  3325. };
  3326. };
  3327. };
  3328. };
  3329. deleteResult( result );
  3330. };
  3331. return tVal;
  3332. };
  3333. DBC_INT_LIST *sqliteDBC::listOlderReportStat( uint32_t TS ){
  3334. DBC_INT_LIST * tVal = NULL;
  3335. if ( m_bStaIsConnected ) {
  3336. char tQBuf[MAX_PATH_LEN];
  3337. AAssoc *result;
  3338. sprintf(tQBuf, "SELECT `ROWID` FROM `days` WHERE `ts`< %d", TS );
  3339. result = m_pDataStatistics->Query( tQBuf );
  3340. if( result!= NULL ) {
  3341. if( result->size() > 0 ) {
  3342. Assoc *cArr;
  3343. tVal = new DBC_INT_LIST();
  3344. if( tVal != NULL ) {
  3345. Assoc::iterator it;
  3346. for(int i=0;i<result->size();i++) {
  3347. cArr = result->at(i);
  3348. it = cArr->find("ROWID");
  3349. if( it != cArr->end() ){
  3350. tVal->push_back( atoi( it->second.c_str() ));
  3351. };
  3352. };
  3353. };
  3354. };
  3355. };
  3356. deleteResult( result );
  3357. };
  3358. return tVal;
  3359. };
  3360. DBC_INT_LIST *sqliteDBC::listPhonebook( ){
  3361. DBC_INT_LIST * tVal = NULL;
  3362. if( m_bStoIsConnected ){
  3363. char tQBuf[CTEXT];
  3364. AAssoc *result;
  3365. sprintf(tQBuf, "SELECT `id` FROM `module_modem_phonebook`" );
  3366. #ifdef DEBUG_ALL
  3367. LOG(tQBuf);
  3368. #endif
  3369. result = m_pDataStorage->Query( tQBuf );
  3370. if( result!= NULL ) {
  3371. if( result->size() > 0 ) {
  3372. Assoc *cArr;
  3373. tVal = new DBC_INT_LIST();
  3374. if( tVal != NULL ) {
  3375. Assoc::iterator it;
  3376. for(int i=0;i<result->size();i++) {
  3377. cArr = result->at(i);
  3378. it = cArr->find("id");
  3379. if( it != cArr->end() ){
  3380. tVal->push_back( atoi( it->second.c_str() ));
  3381. };
  3382. };
  3383. };
  3384. };
  3385. };
  3386. deleteResult( result );
  3387. };
  3388. return tVal;
  3389. };
  3390. DBC_INT_LIST *sqliteDBC::listResources( uint32_t NodeID ){
  3391. DBC_INT_LIST * tVal = NULL;
  3392. if( m_bStoIsConnected ){
  3393. char tQBuf[CTEXT];
  3394. AAssoc *result;
  3395. if ( NodeID == 0 ) NodeID = m_nServerNodeID;
  3396. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d", NodeID );
  3397. #ifdef DEBUG_ALL
  3398. LOG(tQBuf);
  3399. #endif
  3400. result = m_pDataStorage->Query( tQBuf );
  3401. if( result!= NULL ) {
  3402. if( result->size() > 0 ) {
  3403. Assoc *cArr;
  3404. tVal = new DBC_INT_LIST();
  3405. if( tVal != NULL ) {
  3406. Assoc::iterator it;
  3407. for(int i=0;i<result->size();i++) {
  3408. cArr = result->at(i);
  3409. it = cArr->find("id");
  3410. if( it != cArr->end() ){
  3411. tVal->push_back( atoi( it->second.c_str() ));
  3412. };
  3413. };
  3414. };
  3415. };
  3416. };
  3417. deleteResult( result );
  3418. };
  3419. return tVal;
  3420. };
  3421. bool sqliteDBC::pushMemCMD( uint32_t NODE_ID, uint8_t CMD, CSTR DATA ){
  3422. DBC_PUSHED_CMD * RetVal = NULL;
  3423. if ( m_bMemIsConnected ) {
  3424. char QS[MAX_PATH];
  3425. sprintf( QS, "INSERT INTO `nodes_qcq`(`node_id`,`cmd`,`status`,`parameter`) VALUES(%d,%d,0,%s)", NODE_ID, CMD, DATA );
  3426. #ifdef DEBUG_ALL
  3427. LOG( QS );
  3428. #endif
  3429. m_pDataMemory->SilentQuery( QS );
  3430. return true;
  3431. };
  3432. return false;
  3433. };
  3434. void sqliteDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){
  3435. if( m_bStoIsConnected ){
  3436. m_nSiteID = SiteID;
  3437. char tQBuf[MAX_PATH_LEN];
  3438. #ifdef DEFAULT_SERVER_ID
  3439. 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'",
  3440. DEFAULT_SERVER_ID, SiteID, identity, _BUILD_STRING_, identity, _BUILD_STRING_ );
  3441. #else
  3442. sprintf( tQBuf, "INSERT INTO `servers`(`site_id`,`identity`,`version_string`) VALUES (%d,'%s','%s') ON CONFLICT(`identity`) DO UPDATE SET `version_string`='%s'",
  3443. SiteID, identity, _BUILD_STRING_, _BUILD_STRING_ );
  3444. #endif
  3445. #ifdef DEBUG_ALL
  3446. LOG(tQBuf);
  3447. #endif
  3448. m_pDataStorage->SilentQuery( tQBuf );
  3449. #ifdef DEFAULT_SERVER_ID
  3450. m_nServerID = DEFAULT_SERVER_ID;
  3451. #else
  3452. m_nServerID = getServerID( identity );
  3453. #endif
  3454. *ServID = m_nServerID;
  3455. if( m_nServerID ) {
  3456. //if ( bRecreateMemStructures )
  3457. initMemDB( m_nServerID );
  3458. sprintf( tQBuf, "UPDATE `servers` SET `pid`=%d,`ts`=STRFTIME('%%s') WHERE `id`=%d", PID, m_nServerID );
  3459. #ifdef DEBUG_ALL
  3460. LOG(tQBuf);
  3461. #endif
  3462. m_pDataMemory->SilentQuery( tQBuf );
  3463. 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 );
  3464. #ifdef DEBUG_ALL
  3465. LOG(tQBuf);
  3466. #endif
  3467. m_nServerNodeID = ( uint32_t ) m_pDataStorage->QueryID( tQBuf );
  3468. if( m_nServerNodeID== 0 ){
  3469. m_nServerNodeID = getServerNode( m_nServerID );
  3470. };
  3471. *ServNode = m_nServerNodeID;
  3472. // Clenup Nodes and services ...
  3473. sprintf(tQBuf,"UPDATE `nodes` SET `online`=0" );
  3474. #ifdef DEBUG_ALL
  3475. LOG(tQBuf);
  3476. #endif
  3477. m_pDataStorage->SilentQuery( tQBuf );
  3478. sprintf(tQBuf,"UPDATE `cameras` SET `online`=0 WHERE `manual`=0" );
  3479. #ifdef DEBUG_ALL
  3480. LOG(tQBuf);
  3481. #endif
  3482. m_pDataStorage->SilentQuery( tQBuf );
  3483. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=0 WHERE `source_id` IN ( SELECT `id` FROM `cameras` WHERE `manual`=0 )" );
  3484. #ifdef DEBUG_ALL
  3485. LOG(tQBuf);
  3486. #endif
  3487. m_pDataStorage->SilentQuery( tQBuf );
  3488. //sprintf(tQBuf,"UPDATE `cameras` SET `online`=1 WHERE `manual`=1" );
  3489. #ifdef DEBUG_ALL
  3490. //LOG(tQBuf);
  3491. #endif
  3492. //m_pDataStorage->SilentQuery( tQBuf );
  3493. //sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=1 WHERE `source_id` IN ( SELECT `id` FROM `cameras` WHERE `online`=1 )" );
  3494. #ifdef DEBUG_ALL
  3495. //LOG(tQBuf);
  3496. #endif
  3497. //m_pDataStorage->SilentQuery( tQBuf );
  3498. // sprintf(tQBuf,"UPDATE `media_server_streams` SET `valid`=0, `online`=0" );
  3499. #ifdef DEBUG_ALL
  3500. // LOG(tQBuf);
  3501. #endif
  3502. // m_pDataStorage->SilentQuery( tQBuf );
  3503. //cleanResources( tServerNodeID );
  3504. setNodeOnline( m_nServerNodeID );
  3505. };
  3506. };
  3507. };
  3508. bool sqliteDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  3509. if( m_bStoIsConnected ) {
  3510. char tQBuf[MAX_PATH_LEN];
  3511. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  3512. #ifdef DEBUG_ALL
  3513. LOG(tQBuf);
  3514. #endif
  3515. m_pDataStorage->SilentQuery( tQBuf );
  3516. return true;
  3517. };
  3518. return false;
  3519. };
  3520. bool sqliteDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  3521. if( m_bStoIsConnected ) {
  3522. char tQBuf[MAX_PATH_LEN];
  3523. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  3524. #ifdef DEBUG_ALL
  3525. LOG(tQBuf);
  3526. #endif
  3527. m_pDataStorage->SilentQuery( tQBuf );
  3528. return true;
  3529. };
  3530. return false;
  3531. };
  3532. bool sqliteDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  3533. if( m_bStoIsConnected ) {
  3534. char tQBuf[MAX_PATH_LEN];
  3535. if( status ) {
  3536. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='E' WHERE `id`=%d", maskID );
  3537. } else {
  3538. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='D' WHERE `id`=%d", maskID );
  3539. };
  3540. #ifdef DEBUG_ALL
  3541. LOG(tQBuf);
  3542. #endif
  3543. m_pDataStorage->SilentQuery( tQBuf );
  3544. return true;
  3545. };
  3546. return false;
  3547. };
  3548. bool sqliteDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  3549. if( m_bStoIsConnected ) {
  3550. char tQBuf[MAX_PATH_LEN];
  3551. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  3552. #ifdef DEBUG_ALL
  3553. LOG(tQBuf);
  3554. #endif
  3555. m_pDataStorage->SilentQuery( tQBuf );
  3556. return true;
  3557. };
  3558. return false;
  3559. };
  3560. bool sqliteDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  3561. if( m_bStoIsConnected ) {
  3562. char tQBuf[MAX_PATH_LEN];
  3563. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  3564. #ifdef DEBUG_ALL
  3565. LOG(tQBuf);
  3566. #endif
  3567. m_pDataStorage->SilentQuery( tQBuf );
  3568. return true;
  3569. };
  3570. return false;
  3571. };
  3572. bool sqliteDBC::setNodeOffline( uint32_t NodeID ){
  3573. if( m_bStoIsConnected ){
  3574. char tQBuf[CTEXT];
  3575. if( NodeID ) {
  3576. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  3577. #ifdef DEBUG_ALL
  3578. LOG(tQBuf);
  3579. #endif
  3580. m_pDataStorage->SilentQuery( tQBuf );
  3581. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  3582. #ifdef DEBUG_ALL
  3583. LOG(tQBuf);
  3584. #endif
  3585. m_pDataStorage->SilentQuery( tQBuf );
  3586. return true;
  3587. };
  3588. };
  3589. return false;
  3590. };
  3591. bool sqliteDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  3592. if( m_bStoIsConnected ){
  3593. char tQBuf[CTEXT];
  3594. if( NodeID ) {
  3595. sprintf(tQBuf,"UPDATE `nodes` SET `online`=%d WHERE `id`=%d", status, NodeID );
  3596. #ifdef DEBUG_ALL
  3597. LOG(tQBuf);
  3598. #endif
  3599. m_pDataStorage->SilentQuery( tQBuf );
  3600. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  3601. #ifdef DEBUG_ALL
  3602. LOG(tQBuf);
  3603. #endif
  3604. m_pDataStorage->SilentQuery( tQBuf );
  3605. return true;
  3606. };
  3607. };
  3608. return false;
  3609. };
  3610. bool sqliteDBC::setRessourceActive( uint32_t RessourceID, bool Status ){
  3611. if( m_bStoIsConnected ){
  3612. char tQBuf[CTEXT];
  3613. if( RessourceID ) {
  3614. sprintf(tQBuf,"UPDATE `resources` SET `active`=%d WHERE `id`=%d", Status, RessourceID );
  3615. #ifdef DEBUG_ALL
  3616. LOG(tQBuf);
  3617. #endif
  3618. m_pDataStorage->SilentQuery( tQBuf );
  3619. return true;
  3620. };
  3621. };
  3622. return false;
  3623. };
  3624. bool sqliteDBC::setStreamValid( uint32_t streamID, bool status ){
  3625. if( m_bStoIsConnected ) {
  3626. char tQBuf[MAX_PATH_LEN];
  3627. if ( status ) {
  3628. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID);
  3629. } else {
  3630. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID);
  3631. };
  3632. #ifdef DEBUG_ALL
  3633. LOG(tQBuf);
  3634. #endif
  3635. m_pDataStorage->SilentQuery( tQBuf );
  3636. return true;
  3637. };
  3638. return false;
  3639. };
  3640. void sqliteDBC::unregisterServer( void ){
  3641. if( m_bStoIsConnected ) {
  3642. char tQBuf[MAX_PATH_LEN];
  3643. sprintf(tQBuf,"UPDATE `cameras` SET `online`=0" );
  3644. #ifdef DEBUG_ALL
  3645. LOG(tQBuf);
  3646. #endif
  3647. m_pDataStorage->SilentQuery( tQBuf );
  3648. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=0" );
  3649. #ifdef DEBUG_ALL
  3650. LOG(tQBuf);
  3651. #endif
  3652. m_pDataStorage->SilentQuery( tQBuf );
  3653. };
  3654. setNodeOffline( m_nServerNodeID );
  3655. };
  3656. bool sqliteDBC::updateSystemInfo( DBC_SYS_INFO *ptr ){
  3657. if( m_bStoIsConnected ) {
  3658. char tQBuf[MAX_PATH_LEN];
  3659. sprintf(tQBuf, "UPDATE `system_props` SET `os_info`='%s', `hw_info`='%s' WHERE `id`=%d",
  3660. ptr->OS_INFO,
  3661. ptr->HW_INFO,
  3662. m_nSiteID
  3663. );
  3664. #ifdef DEBUG_ALL
  3665. LOG(tQBuf);
  3666. #endif
  3667. m_pDataStorage->SilentQuery( tQBuf );
  3668. return true;
  3669. };
  3670. return false;
  3671. };
  3672. bool sqliteDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){
  3673. if( m_bStoIsConnected ){
  3674. char tQBuf[CTEXT];
  3675. AAssoc *result;
  3676. 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 );
  3677. #ifdef DEBUG_ALL
  3678. LOG(tQBuf);
  3679. #endif
  3680. result = m_pDataStorage->Query( tQBuf );
  3681. if( result!= NULL ) {
  3682. if( result->size() > 0 ) {
  3683. SH.m_nEnabled = 0xFFFFFFFF;
  3684. SH.m_nPolygonCount = result->size();
  3685. SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) );
  3686. if ( SH.pPolygones ) {
  3687. Assoc * cArr;
  3688. for ( uint8_t idx = 0; idx < result->size(); idx++ ) {
  3689. Assoc::iterator it;
  3690. cArr = result->at(idx);
  3691. it = cArr->find("id");
  3692. if( it != cArr->end() ){
  3693. SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str());
  3694. };
  3695. it = cArr->find("layer");
  3696. if( it != cArr->end() ){
  3697. SH.pPolygones[idx].bType = atoi(it->second.c_str());
  3698. };
  3699. it = cArr->find("status");
  3700. if( it != cArr->end() ){
  3701. SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<<SH.pPolygones[idx].bType);
  3702. };
  3703. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID );
  3704. #ifdef DEBUG_ALL
  3705. LOG(tQBuf);
  3706. #endif
  3707. AAssoc *v_result = m_pDataStorage->Query( tQBuf );
  3708. if( v_result!= NULL ) {
  3709. if( v_result->size() > 0 ) {
  3710. SH.pPolygones[idx].wCount = v_result->size();
  3711. SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) );
  3712. if(SH.pPolygones[idx].pPoint ) {
  3713. for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) {
  3714. cArr = v_result->at(zdx);
  3715. it = cArr->find("x");
  3716. if( it != cArr->end() ){
  3717. SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str());
  3718. };
  3719. it = cArr->find("y");
  3720. if( it != cArr->end() ){
  3721. SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str());
  3722. };
  3723. LOG("Point Added!");
  3724. };
  3725. } else {
  3726. LOG("No mem for Points!");
  3727. };
  3728. } else {
  3729. LOG("No Points!");
  3730. SH.pPolygones[idx].wCount = 0;
  3731. SH.pPolygones[idx].pPoint = NULL;
  3732. };
  3733. deleteResult( v_result );
  3734. };
  3735. };
  3736. };
  3737. };
  3738. deleteResult( result );
  3739. };
  3740. return true;
  3741. };
  3742. return false;
  3743. };
  3744. bool sqliteDBC::getAppDebugMode(){
  3745. bool rVal = false;
  3746. if( m_bStoIsConnected ){
  3747. char tQBuf[CTEXT];
  3748. AAssoc *result;
  3749. sprintf(tQBuf, "SELECT `work_mode` FROM `system_props` WHERE `id`=1" );
  3750. #ifdef DEBUG_ALL
  3751. LOG(tQBuf);
  3752. #endif
  3753. result = m_pDataStorage->Query( tQBuf );
  3754. if( result!= NULL ) {
  3755. if( result->size() > 0 ) {
  3756. Assoc *cArr;
  3757. Assoc::iterator it;
  3758. cArr = result->at(0);
  3759. it = cArr->find("work_mode");
  3760. if( it != cArr->end() ){
  3761. rVal = (bool) atoi( it->second.c_str() );
  3762. };
  3763. };
  3764. };
  3765. deleteResult( result );
  3766. };
  3767. return rVal;
  3768. };
  3769. DBC_CAM_DATA *sqliteDBC::getCamData( uint32_t ID ){
  3770. DBC_CAM_DATA *tVal = NULL;
  3771. if( m_bStoIsConnected ){
  3772. char tQBuf[CTEXT];
  3773. AAssoc *result;
  3774. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  3775. #ifdef DEBUG_ALL
  3776. LOG(tQBuf);
  3777. #endif
  3778. result = m_pDataStorage->Query( tQBuf );
  3779. if( result!= NULL ) {
  3780. if( result->size() > 0 ) {
  3781. Assoc *cArr;
  3782. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  3783. if( tVal != NULL ) {
  3784. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  3785. tVal->id = ID;
  3786. Assoc::iterator it;
  3787. cArr = result->at(0);
  3788. it = cArr->find("type");
  3789. if( it != cArr->end() ){
  3790. tVal->type = atoi( it->second.c_str() );
  3791. };
  3792. it = cArr->find("online");
  3793. if( it != cArr->end() ){
  3794. tVal->online = (bool) atoi( it->second.c_str() );
  3795. };
  3796. it = cArr->find("stream_id");
  3797. if( it != cArr->end() ){
  3798. tVal->stream_id = atoi( it->second.c_str() );
  3799. };
  3800. it = cArr->find("hardware");
  3801. if( it != cArr->end() ){
  3802. strncpy( tVal->hardware, it->second.c_str(), 32 );
  3803. };
  3804. it = cArr->find("name");
  3805. if( it != cArr->end() ){
  3806. strncpy( tVal->name, it->second.c_str(), 64 );
  3807. };
  3808. it = cArr->find("status");
  3809. if( it != cArr->end() ){
  3810. tVal->status = atoi( it->second.c_str() );
  3811. };
  3812. it = cArr->find("session");
  3813. if( it != cArr->end() ){
  3814. strncpy( tVal->session, it->second.c_str(), 32 );
  3815. };
  3816. it = cArr->find("protocol");
  3817. if( it != cArr->end() ){
  3818. tVal->protocol = atoi( it->second.c_str() );
  3819. };
  3820. it = cArr->find("protocol_aux");
  3821. if( it != cArr->end() ){
  3822. tVal->protocol_aux = atoi( it->second.c_str() );
  3823. };
  3824. it = cArr->find("uart_id");
  3825. if( it != cArr->end() ){
  3826. tVal->uart_id = atoi( it->second.c_str() );
  3827. };
  3828. it = cArr->find("x");
  3829. if( it != cArr->end() ){
  3830. tVal->x = atof( it->second.c_str() );
  3831. };
  3832. it = cArr->find("y");
  3833. if( it != cArr->end() ){
  3834. tVal->y = atof( it->second.c_str() );
  3835. };
  3836. it = cArr->find("z");
  3837. if( it != cArr->end() ){
  3838. tVal->z = atof( it->second.c_str() );
  3839. };
  3840. it = cArr->find("x_rot");
  3841. if( it != cArr->end() ){
  3842. tVal->x_rot = atof( it->second.c_str() );
  3843. };
  3844. it = cArr->find("y_rot");
  3845. if( it != cArr->end() ){
  3846. tVal->y_rot = atof( it->second.c_str() );
  3847. };
  3848. it = cArr->find("z_rot");
  3849. if( it != cArr->end() ){
  3850. tVal->z_rot = atof( it->second.c_str() );
  3851. };
  3852. it = cArr->find("imager_type");
  3853. if( it != cArr->end() ){
  3854. tVal->imager_type = atoi( it->second.c_str() );
  3855. };
  3856. it = cArr->find("lens_f");
  3857. if( it != cArr->end() ){
  3858. tVal->lens_f = atoi( it->second.c_str() );
  3859. };
  3860. it = cArr->find("ptz_speed_step");
  3861. if( it != cArr->end() ){
  3862. tVal->ptz_speed_step = atof( it->second.c_str() );
  3863. };
  3864. it = cArr->find("pan_model");
  3865. if( it != cArr->end() ){
  3866. tVal->pan_model = atoi( it->second.c_str() );
  3867. };
  3868. it = cArr->find("pan_angles");
  3869. if( it != cArr->end() ){
  3870. tVal->pan_angles = atoi( it->second.c_str() );
  3871. };
  3872. it = cArr->find("tilt_model");
  3873. if( it != cArr->end() ){
  3874. tVal->tilt_model = atoi( it->second.c_str() );
  3875. };
  3876. it = cArr->find("tilt_angles");
  3877. if( it != cArr->end() ){
  3878. tVal->tilt_angles = atoi( it->second.c_str() );
  3879. };
  3880. it = cArr->find("zoom_model");
  3881. if( it != cArr->end() ){
  3882. tVal->zoom_model = atoi( it->second.c_str() );
  3883. };
  3884. it = cArr->find("zoom");
  3885. if( it != cArr->end() ){
  3886. tVal->zoom = atof( it->second.c_str() );
  3887. };
  3888. it = cArr->find("max_range");
  3889. if( it != cArr->end() ){
  3890. tVal->max_range = atof( it->second.c_str() );
  3891. };
  3892. it = cArr->find("access_login");
  3893. if( it != cArr->end() ){
  3894. strncpy( tVal->username, it->second.c_str(), 16 );
  3895. };
  3896. it = cArr->find("access_pass");
  3897. if( it != cArr->end() ){
  3898. strncpy( tVal->password, it->second.c_str(), 16 );
  3899. };
  3900. it = cArr->find("uuid");
  3901. if( it != cArr->end() ){
  3902. strncpy( tVal->uuid, it->second.c_str(), 64 );
  3903. };
  3904. it = cArr->find("mac");
  3905. if( it != cArr->end() ){
  3906. strncpy( tVal->mac, it->second.c_str(), 16 );
  3907. };
  3908. it = cArr->find("ip");
  3909. if( it != cArr->end() ){
  3910. strncpy( tVal->ip, it->second.c_str(), 16 );
  3911. };
  3912. it = cArr->find("port");
  3913. if( it != cArr->end() ){
  3914. tVal->port = atoi( it->second.c_str() );
  3915. };
  3916. it = cArr->find("onvif_access");
  3917. if( it != cArr->end() ){
  3918. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  3919. };
  3920. it = cArr->find("onvif_ctrl");
  3921. if( it != cArr->end() ){
  3922. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  3923. };
  3924. it = cArr->find("ptz_token");
  3925. if( it != cArr->end() ){
  3926. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  3927. };
  3928. it = cArr->find("trigger_mode");
  3929. if( it != cArr->end() ){
  3930. tVal->triggering_mode = atoi( it->second.c_str() );
  3931. };
  3932. it = cArr->find("auth_mode");
  3933. if( it != cArr->end() ){
  3934. tVal->auth_mode = atoi( it->second.c_str() );
  3935. };
  3936. it = cArr->find("ptz_axel");
  3937. if( it != cArr->end() ){
  3938. tVal->ptz_axel = atoi( it->second.c_str() );
  3939. };
  3940. it = cArr->find("manual");
  3941. if( it != cArr->end() ){
  3942. tVal->manual = (bool) atoi( it->second.c_str() );
  3943. };
  3944. it = cArr->find("homing_enable");
  3945. if( it != cArr->end() ){
  3946. tVal->homing_enable = (bool) atoi( it->second.c_str() );
  3947. };
  3948. it = cArr->find("homing_to");
  3949. if( it != cArr->end() ){
  3950. tVal->homing_to = atoi( it->second.c_str() );
  3951. };
  3952. //it = cArr->find("home_token");
  3953. //if( it != cArr->end() ){
  3954. // strncpy( tVal->home_token, it->second.c_str(), 32 );
  3955. //};
  3956. it = cArr->find("eco_ir");
  3957. if( it != cArr->end() ){
  3958. tVal->eco_ir = (bool) atoi( it->second.c_str() );
  3959. };
  3960. it = cArr->find("prefered_events_only");
  3961. if( it != cArr->end() ){
  3962. tVal->prefered_events_only = (bool) atoi( it->second.c_str() );
  3963. };
  3964. };
  3965. };
  3966. };
  3967. deleteResult( result );
  3968. };
  3969. return tVal;
  3970. };
  3971. uint32_t sqliteDBC::getCamId( CSTR UUID ){
  3972. uint32_t RetVal = 0;
  3973. if( m_bStoIsConnected ){
  3974. char tQBuf[CTEXT];
  3975. AAssoc *result;
  3976. sprintf(tQBuf, "SELECT `id` FROM `cameras` WHERE `uuid`='%s'", UUID );
  3977. #ifdef DEBUG_ALL
  3978. LOG(tQBuf);
  3979. #endif
  3980. result = m_pDataStorage->Query( tQBuf );
  3981. if( result!= NULL ) {
  3982. if( result->size() > 0 ) {
  3983. Assoc *cArr;
  3984. Assoc::iterator it;
  3985. cArr = result->at(0);
  3986. it = cArr->find("id");
  3987. if( it != cArr->end() ){
  3988. RetVal = atoi( it->second.c_str() );
  3989. };
  3990. };
  3991. };
  3992. deleteResult( result );
  3993. };
  3994. return RetVal;
  3995. };
  3996. CAM_PRESET *sqliteDBC::getCamPreset( uint32_t SETID ){
  3997. CAM_PRESET *tVal = NULL;
  3998. if( m_bStoIsConnected ){
  3999. char tQBuf[CTEXT];
  4000. AAssoc *result;
  4001. sprintf(tQBuf, "SELECT * FROM `cameras_presets` WHERE `id`=%d", SETID );
  4002. #ifdef DEBUG_ALL
  4003. LOG(tQBuf);
  4004. #endif
  4005. result = m_pDataStorage->Query( tQBuf );
  4006. if( result!= NULL ) {
  4007. if( result->size() > 0 ) {
  4008. Assoc *cArr;
  4009. tVal = (CAM_PRESET*) malloc(sizeof(CAM_PRESET));
  4010. if( tVal != NULL ) {
  4011. memset( tVal, 0 , sizeof(CAM_PRESET));
  4012. tVal->id = SETID;
  4013. Assoc::iterator it;
  4014. cArr = result->at(0);
  4015. it = cArr->find("token");
  4016. if( it != cArr->end() ){
  4017. strncpy( tVal->token, it->second.c_str(), 2 );
  4018. tVal->token[3] = (char)0;
  4019. };
  4020. it = cArr->find("role");
  4021. if( it != cArr->end() ){
  4022. tVal->role = atoi( it->second.c_str() );
  4023. };
  4024. it = cArr->find("row");
  4025. if( it != cArr->end() ){
  4026. tVal->row = atoi( it->second.c_str() );
  4027. };
  4028. it = cArr->find("column");
  4029. if( it != cArr->end() ){
  4030. tVal->col = atoi( it->second.c_str() );
  4031. };
  4032. };
  4033. };
  4034. };
  4035. deleteResult( result );
  4036. };
  4037. return tVal;
  4038. };
  4039. DBC_PRESETS_INFO *sqliteDBC::getCamPresetInfo( uint32_t CamID ){
  4040. DBC_PRESETS_INFO *tVal = NULL;
  4041. if( m_bStoIsConnected ){
  4042. char tQBuf[CTEXT];
  4043. AAssoc *result;
  4044. sprintf(tQBuf, "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`=%d", CamID );
  4045. #ifdef DEBUG_ALL
  4046. LOG(tQBuf);
  4047. #endif
  4048. result = m_pDataStorage->Query( tQBuf );
  4049. if( result!= NULL ) {
  4050. if( result->size() > 0 ) {
  4051. Assoc *cArr;
  4052. tVal = (DBC_PRESETS_INFO*) malloc(sizeof(DBC_PRESETS_INFO));
  4053. if( tVal != NULL ) {
  4054. memset( tVal, 0 , sizeof(DBC_PRESETS_INFO));
  4055. Assoc::iterator it;
  4056. cArr = result->at(0);
  4057. it = cArr->find("maxCount");
  4058. if( it != cArr->end() ){
  4059. tVal->maxCount = atoi( it->second.c_str() );
  4060. };
  4061. it = cArr->find("p_segs");
  4062. if( it != cArr->end() ){
  4063. tVal->gCols = atoi( it->second.c_str() );
  4064. };
  4065. it = cArr->find("z_segs");
  4066. if( it != cArr->end() ){
  4067. tVal->gRows = atoi( it->second.c_str() );
  4068. };
  4069. };
  4070. };
  4071. };
  4072. deleteResult( result );
  4073. };
  4074. return tVal;
  4075. };
  4076. CSTR sqliteDBC::getDataParam( uint8_t pid ){
  4077. switch ( pid ) {
  4078. case 0: return strdup( m_pDbFile ); break;
  4079. case 1: return strdup( web_access_user ); break;
  4080. case 2: return strdup( web_access_group ); break;
  4081. };
  4082. return NULL;
  4083. };
  4084. bool sqliteDBC::updateIPCam( uint32_t CamID, CSTR Addr ){
  4085. if( m_bStoIsConnected ) {
  4086. char tQBuf[MAX_PATH_LEN];
  4087. char tIpBuf[CTEXT];
  4088. char *tPos;
  4089. char *tPos2;
  4090. uint16_t tPort = 0;
  4091. tPos = strstr(Addr,"//");
  4092. if( tPos != NULL ) {
  4093. tPos2 = strstr( tPos + 2,":");
  4094. if( tPos2 != NULL ) {
  4095. LOG("IP Port Defined!");
  4096. int len, len2, len3;
  4097. len = tPos2 - tPos - 2;
  4098. strncpy( tIpBuf, tPos + 2, len);
  4099. tIpBuf[len] = (char)0;
  4100. tPort = atoi( tPos2 + 1 );
  4101. //strncpy( tPath, tPos + 2 + len, CTEXT );
  4102. } else {
  4103. tPos2 = strstr( tPos + 2,"/");
  4104. if( tPos2 != NULL ) {
  4105. int len, len2, len3;
  4106. len = tPos2 - tPos - 2;
  4107. strncpy( tIpBuf, tPos + 2, len);
  4108. tIpBuf[len] = (char)0;
  4109. //strncpy( tPath, tPos + 2 + len, CTEXT );
  4110. } else {
  4111. tPos2 = strstr( tPos + 2,"/");
  4112. LOG_ERROR("Pos 2 - err");
  4113. tIpBuf[0] = (char)0;
  4114. };
  4115. };
  4116. } else {
  4117. LOG_ERROR("Pos 0 - err");
  4118. tIpBuf[0] = (char)0;
  4119. };
  4120. if ( tPort ) {
  4121. sprintf(tQBuf, "UPDATE `cameras` SET `online`=1, `onvif_ctrl`='%s', `ip`='%s', `port`=%d WHERE `id`=%d",
  4122. Addr,
  4123. tIpBuf,
  4124. tPort,
  4125. CamID
  4126. );
  4127. } else {
  4128. sprintf(tQBuf, "UPDATE `cameras` SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE `id`=%d",
  4129. Addr,
  4130. tIpBuf,
  4131. CamID
  4132. );
  4133. }
  4134. #ifdef DEBUG_ALL
  4135. LOG(tQBuf);
  4136. #endif
  4137. m_pDataStorage->SilentQuery( tQBuf );
  4138. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", CamID );
  4139. #ifdef DEBUG_ALL
  4140. LOG(tQBuf);
  4141. #endif
  4142. m_pDataStorage->SilentQuery( tQBuf );
  4143. return true;
  4144. };
  4145. return false;
  4146. };
  4147. bool sqliteDBC::updateCamRange( uint32_t camID, float range ){
  4148. if( m_bStoIsConnected ) {
  4149. char tQBuf[MAX_PATH_LEN];
  4150. sprintf(tQBuf,"UPDATE `cameras` SET `max_range`=%.3f WHERE `id`=%d",
  4151. range,
  4152. camID
  4153. );
  4154. #ifdef DEBUG_ALL
  4155. LOG(tQBuf);
  4156. #endif
  4157. m_pDataStorage->SilentQuery( tQBuf );
  4158. return true;
  4159. };
  4160. return false;
  4161. };
  4162. bool sqliteDBC::updateCamOnlineStatus( uint32_t camID, bool online ){
  4163. if( m_bStoIsConnected ) {
  4164. char tQBuf[MAX_PATH_LEN];
  4165. if ( online ) {
  4166. sprintf( tQBuf, "UPDATE `cameras` SET `online`=1 WHERE `id`=%d", camID );
  4167. } else {
  4168. sprintf( tQBuf, "UPDATE `cameras` SET `online`=0 WHERE `id`=%d", camID );
  4169. };
  4170. m_pDataStorage->SilentQuery(tQBuf);
  4171. if ( online ) {
  4172. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", camID);
  4173. } else {
  4174. sprintf( tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `source_id`=%d", camID );
  4175. };
  4176. m_pDataStorage->SilentQuery(tQBuf);
  4177. return true;
  4178. };
  4179. return false;
  4180. };
  4181. bool sqliteDBC::updateIPCam( CSTR uuid, CSTR Addr ){
  4182. if( m_bStoIsConnected ) {
  4183. uint32_t cID = getCamId( uuid );
  4184. if ( cID ) {
  4185. return updateIPCam( cID, Addr );
  4186. };
  4187. };
  4188. return false;
  4189. };
  4190. bool sqliteDBC::updateLocalCam( CSTR uuid ){
  4191. if( m_bStoIsConnected ) {
  4192. uint32_t cID = getCamId( uuid );
  4193. if ( cID ) {
  4194. return updateLocalCam( cID );
  4195. };
  4196. };
  4197. return false;
  4198. };
  4199. bool sqliteDBC::updateLocalCam( uint32_t CamID ){
  4200. if( m_bStoIsConnected ) {
  4201. char tQBuf[MAX_PATH_LEN];
  4202. sprintf(tQBuf,"UPDATE cameras SET `online`=1 WHERE `id`=%d", CamID );
  4203. #ifdef DEBUG_ALL
  4204. LOG(tQBuf);
  4205. #endif
  4206. m_pDataStorage->SilentQuery( tQBuf );
  4207. sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", CamID );
  4208. #ifdef DEBUG_ALL
  4209. LOG(tQBuf);
  4210. #endif
  4211. m_pDataStorage->SilentQuery( tQBuf );
  4212. return true;
  4213. };
  4214. return false;
  4215. };
  4216. bool sqliteDBC::updateLRFComStat( uint32_t lrfID, uint32_t ErrorPerMinute ){
  4217. if( m_bStoIsConnected ) {
  4218. char tQBuf[MAX_PATH_LEN];
  4219. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `com_epm`=%d WHERE `id`=%d", ErrorPerMinute, lrfID );
  4220. #ifdef DEBUG_ALL
  4221. LOG(tQBuf);
  4222. #endif
  4223. m_pDataStorage->SilentQuery( tQBuf );
  4224. return true;
  4225. };
  4226. return false;
  4227. };
  4228. bool sqliteDBC::updateLRFFrozenStatus( uint32_t lrfID, bool FFT, bool SFT ){
  4229. if( m_bStoIsConnected ) {
  4230. char tQBuf[MAX_PATH_LEN];
  4231. sprintf(tQBuf, "UPDATE `lrf_ini_settings` SET `FREEZ_FIRST_TH`=%d, `SAVE_FIRST_TH`=%d WHERE `sensor_id`=%d", FFT, SFT, lrfID );
  4232. #ifdef DEBUG_ALL
  4233. LOG(tQBuf);
  4234. #endif
  4235. m_pDataStorage->SilentQuery( tQBuf );
  4236. return true;
  4237. };
  4238. return false;
  4239. };
  4240. 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 ){
  4241. if( m_bStoIsConnected ) {
  4242. char tQBuf[MAX_PATH_LEN];
  4243. if( master ) {
  4244. 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",
  4245. lrfID,
  4246. profileID,
  4247. nOrder,
  4248. nOffset,
  4249. nDelta,
  4250. nFlip,
  4251. nWidth,
  4252. bSST,
  4253. nSun,
  4254. GP,
  4255. spikes,
  4256. nOrder,
  4257. nOffset,
  4258. nDelta,
  4259. nFlip,
  4260. nWidth,
  4261. bSST,
  4262. nSun,
  4263. GP,
  4264. spikes );
  4265. } else {
  4266. 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",
  4267. lrfID,
  4268. profileID,
  4269. nOrder,
  4270. nOffset,
  4271. nDelta,
  4272. nFlip,
  4273. nWidth,
  4274. bSST,
  4275. nSun,
  4276. GP,
  4277. spikes,
  4278. nOrder,
  4279. nOffset,
  4280. nDelta,
  4281. nFlip,
  4282. nWidth,
  4283. bSST,
  4284. nSun,
  4285. GP,
  4286. spikes );
  4287. };
  4288. #ifdef DEBUG_ALL
  4289. LOG(tQBuf);
  4290. #endif
  4291. m_pDataStorage->SilentQuery( tQBuf );
  4292. return true;
  4293. };
  4294. return false;
  4295. };
  4296. bool sqliteDBC::updateLRFDryContact( uint32_t lrfID, bool bAuto, bool bNO, uint16_t wWindow ){
  4297. if( m_bStoIsConnected ) {
  4298. char tQBuf[MAX_PATH_LEN];
  4299. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `dc_auto`=%d, `dc_no`=%d, `dc_window`=%d WHERE `id`=%d", bAuto, bNO, wWindow, lrfID );
  4300. #ifdef DEBUG_ALL
  4301. LOG(tQBuf);
  4302. #endif
  4303. m_pDataStorage->SilentQuery( tQBuf );
  4304. return true;
  4305. };
  4306. return false;
  4307. };
  4308. bool sqliteDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  4309. if( m_bStoIsConnected ) {
  4310. char tQBuf[MAX_PATH_LEN];
  4311. CSTR tES = m_pDataStorage->escapeString( Serial );
  4312. if( tES ) {
  4313. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  4314. free( tES );
  4315. #ifdef DEBUG_ALL
  4316. LOG(tQBuf);
  4317. #endif
  4318. m_pDataStorage->SilentQuery( tQBuf );
  4319. return true;
  4320. };
  4321. };
  4322. return false;
  4323. };
  4324. bool sqliteDBC::updateLRFUpload( uint32_t id, uint8_t status ){
  4325. if( m_bStoIsConnected ) {
  4326. char tQBuf[MAX_PATH_LEN];
  4327. sprintf( tQBuf, "UPDATE `lrf_uploads` SET `status`=%d WHERE `id`=%d", status, id );
  4328. #ifdef DEBUG_ALL
  4329. LOG(tQBuf);
  4330. #endif
  4331. m_pDataStorage->SilentQuery( tQBuf );
  4332. return true;
  4333. };
  4334. return false;
  4335. };
  4336. bool sqliteDBC::updateLRFUnfinishedUploads( uint32_t deviceID ){
  4337. if( m_bStoIsConnected ) {
  4338. char tQBuf[MAX_PATH_LEN];
  4339. sprintf( tQBuf, "UPDATE `lrf_uploads` SET `status`=-1 WHERE `sensor_id`=%d AND `status` < 101 ", deviceID );
  4340. #ifdef DEBUG_ALL
  4341. LOG(tQBuf);
  4342. #endif
  4343. m_pDataStorage->SilentQuery( tQBuf );
  4344. return true;
  4345. };
  4346. return false;
  4347. };
  4348. bool sqliteDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  4349. if( m_bStoIsConnected ) {
  4350. char tQBuf[MAX_PATH_LEN];
  4351. CSTR tES = m_pDataStorage->escapeString( version );
  4352. if( tES ) {
  4353. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  4354. free( tES );
  4355. #ifdef DEBUG_ALL
  4356. LOG(tQBuf);
  4357. #endif
  4358. m_pDataStorage->SilentQuery( tQBuf );
  4359. return true;
  4360. };
  4361. };
  4362. return false;
  4363. };
  4364. bool sqliteDBC::updateServerIdentity( uint32_t m_nServerID, CSTR m_sIdentity ){
  4365. if( m_bStoIsConnected ) {
  4366. char tQBuf[MAX_PATH_LEN];
  4367. CSTR tES = m_pDataStorage->escapeString( m_sIdentity );
  4368. if( tES ) {
  4369. sprintf( tQBuf, "UPDATE `servers` SET `identity`='%s' WHERE `id`=%d", tES, m_nServerID );
  4370. free( tES );
  4371. #ifdef DEBUG_ALL
  4372. LOG(tQBuf);
  4373. #endif
  4374. m_pDataStorage->SilentQuery( tQBuf );
  4375. return true;
  4376. };
  4377. };
  4378. return false;
  4379. };
  4380. #undef LOG
  4381. #undef LOG_ERROR