Web Interface For Lite Argus Control modules
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.

106 lines
3.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
3 years ago
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. if( $CUser->Data['id'] > 1 ){
  4. $Data = array();
  5. $Data['status'] = 'na';
  6. if( isset( $_POST['CCMD'] ) ){
  7. $CCMD = intval( $_POST['CCMD'] );
  8. } else $CCMD = 0;
  9. if( isset( $_POST['NID'] ) ) {
  10. $NodeID = intval($_POST['NID']);
  11. } else $NodeID = 0;
  12. switch( $CCMD ){
  13. case 0:{
  14. // Default Op Mode ------> NCQ Commands
  15. if( isset( $_POST['CMD'] ) ){
  16. $CMD = intval( $_POST['CMD'] );
  17. } else {
  18. $CMD = 0;
  19. };
  20. if( isset( $_POST['PARAM'] ) ){
  21. $PARAM = $DATABASE->escape( $_POST['PARAM'] );
  22. } else {
  23. $PARAM = '';
  24. };
  25. if( $NodeID > 0 && $CMD > 0 ){
  26. $RBASE = new SQLite_DB( '/dev/shm/argus/mem_db.db');
  27. $Data['success'] = true;
  28. $Data['status'] = 'ok';
  29. $QS = "INSERT INTO `nodes_qcq`(`node_id`,`cmd`,`status`,`parameter`) VALUES({$NodeID},{$CMD},0,'{$PARAM}')";
  30. $Data['query'] = $QS;
  31. $RBASE->Query( $QS, false );
  32. $Data['operation_id'] = intval( $RBASE->getLastInsertID() );
  33. } else {
  34. $Data['msg']='Wrong Parameters';
  35. };
  36. break;
  37. };
  38. case 1:{
  39. // Add Sensor
  40. if( isset( $_POST['SENSID'] ) ) {
  41. $SensorID = intval($_POST['SENSID']);
  42. } else $SensorID = 0;
  43. $ETYP = intval( $_POST['TYPE'] );
  44. $EPROTOID = intval( $_POST['DEVID'] );
  45. $EUARTID = intval( $_POST['UART'] );
  46. $ERANGE = intval( $_POST['RANGE'] );
  47. if( $ETYP < 5 ){
  48. if( $EUARTID ){
  49. $QS = "SELECT `id`, `device_id` FROM `lrf_sensors` WHERE `uart_id`={$EUARTID}";
  50. $RR = $DATABASE->Query( $QS );
  51. if( count( $RR ) ){
  52. if( $EPROTOID == 0 ){
  53. $Data['msg'] = 'Cannot Assign Protocol Device ID[0] on selected UART<br/>Another devices already exists!<br/>Device ID[0] May be set just in exclusive UART usage mode';
  54. } else {
  55. foreach( $RR as $R ){
  56. if( $R['device_id'] == $EPROTOID ) {
  57. $Data['msg'] = "On the selected UART line already exists sensor with selected Device ID[{$EPROTOID}]";
  58. };
  59. if( $R['device_id'] == 0 ){
  60. $Data['msg'] = "On the selected UART line already exists sensor with Device ID[0]<br/>This UART can not be assigned to another sensor!";
  61. };
  62. };
  63. if( !isset( $Data['msg'] ) ){
  64. // All OK
  65. $QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`uart_id`,`device_id`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,{$EUARTID},{$EPROTOID},{$ERANGE},255)";
  66. $DATABASE->Query( $QS );
  67. $SIID = $DATABASE->getLastInsertID();
  68. $NAME = 'SENSOR_'.$SIID;
  69. $QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
  70. $DATABASE->Query( $QS );
  71. $Data['status'] = 'ok';
  72. };
  73. };
  74. } else {
  75. // No device assigned with this UART
  76. $QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`uart_id`,`device_id`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,{$EUARTID},{$EPROTOID},{$ERANGE},255)";
  77. $DATABASE->Query( $QS );
  78. $SIID = $DATABASE->getLastInsertID();
  79. $NAME = 'SENSOR_'.$SIID;
  80. $QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
  81. $DATABASE->Query( $QS );
  82. $Data['status'] = 'ok';
  83. };
  84. } else {
  85. $Data['msg'] = 'The UART Not Selected!';
  86. };
  87. } else {
  88. $EIP = $DATABASE->escape( $_POST['ADDR'] );
  89. $EPORT = intval( $_POST['PORT'] );
  90. //IP Sensor
  91. $QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`ip`,`port`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,'{$EIP}',{$EPORT},{$ERANGE},255)";
  92. $DATABASE->Query( $QS );
  93. $SIID = $DATABASE->getLastInsertID();
  94. $NAME = 'SENSOR_'.$SIID;
  95. $QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
  96. $DATABASE->Query( $QS );
  97. $Data['status'] = 'ok';
  98. };
  99. break;
  100. };
  101. };
  102. echo json_encode( $Data );
  103. } else {
  104. header('location: /');
  105. };
  106. ?>