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.

4743 lines
179 KiB

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