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.

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