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.

92 lines
3.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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( $EUARTID ){
  48. $QS = "SELECT `id`, `device_id` FROM `lrf_sensors` WHERE `uart_id`={$EUARTID}";
  49. $RR = $DATABASE->Query( $QS );
  50. if( count( $RR ) ){
  51. if( $EPROTOID == 0 ){
  52. $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';
  53. } else {
  54. foreach( $RR as $R ){
  55. if( $R['device_id'] == $EPROTOID ) {
  56. $Data['msg'] = "On the selected UART line already exists sensor with selected Device ID[{$EPROTOID}]";
  57. };
  58. if( $R['device_id'] == 0 ){
  59. $Data['msg'] = "On the selected UART line already exists sensor with Device ID[0]<br/>This UART can not be assigned to another sensor!";
  60. };
  61. };
  62. if( !isset( $Data['msg'] ) ){
  63. // All OK
  64. $QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`uart_id`,`device_id`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,{$EUARTID},{$EPROTOID},{$ERANGE},255)";
  65. $DATABASE->Query( $QS );
  66. $SIID = $DATABASE->getLastInsertID();
  67. $NAME = 'SENSOR_'.$SIID;
  68. $QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
  69. $DATABASE->Query( $QS );
  70. $Data['status'] = 'ok';
  71. };
  72. };
  73. } else {
  74. // No device assigned with this UART
  75. $QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`uart_id`,`device_id`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,{$EUARTID},{$EPROTOID},{$ERANGE},255)";
  76. $DATABASE->Query( $QS );
  77. $SIID = $DATABASE->getLastInsertID();
  78. $NAME = 'SENSOR_'.$SIID;
  79. $QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
  80. $DATABASE->Query( $QS );
  81. $Data['status'] = 'ok';
  82. };
  83. } else {
  84. $Data['msg'] = 'The UART Not Selected!';
  85. };
  86. break;
  87. };
  88. };
  89. echo json_encode( $Data );
  90. } else {
  91. header('location: /');
  92. };
  93. ?>