Data['id'] > 1 ){
$Data = array();
$Data['status'] = 'na';
if( isset( $_POST['CCMD'] ) ){
$CCMD = intval( $_POST['CCMD'] );
} else $CCMD = 0;
if( isset( $_POST['NID'] ) ) {
$NodeID = intval($_POST['NID']);
} else $NodeID = 0;
switch( $CCMD ){
case 0:{
// Default Op Mode ------> NCQ Commands
if( isset( $_POST['CMD'] ) ){
$CMD = intval( $_POST['CMD'] );
} else {
$CMD = 0;
};
if( isset( $_POST['PARAM'] ) ){
$PARAM = $DATABASE->escape( $_POST['PARAM'] );
} else {
$PARAM = '';
};
if( $NodeID > 0 && $CMD > 0 ){
$RBASE = new SQLite_DB( '/dev/shm/argus/mem_db.db');
$Data['success'] = true;
$Data['status'] = 'ok';
$QS = "INSERT INTO `nodes_qcq`(`node_id`,`cmd`,`status`,`parameter`) VALUES({$NodeID},{$CMD},0,'{$PARAM}')";
$Data['query'] = $QS;
$RBASE->Query( $QS, false );
$Data['operation_id'] = intval( $RBASE->getLastInsertID() );
} else {
$Data['msg']='Wrong Parameters';
};
break;
};
case 1:{
// Add Sensor
if( isset( $_POST['SENSID'] ) ) {
$SensorID = intval($_POST['SENSID']);
} else $SensorID = 0;
$ETYP = intval( $_POST['TYPE'] );
$EPROTOID = intval( $_POST['DEVID'] );
$EUARTID = intval( $_POST['UART'] );
$ERANGE = intval( $_POST['RANGE'] );
if( $ETYP < 5 ){
if( $EUARTID ){
$QS = "SELECT `id`, `device_id` FROM `lrf_sensors` WHERE `uart_id`={$EUARTID}";
$RR = $DATABASE->Query( $QS );
if( count( $RR ) ){
if( $EPROTOID == 0 ){
$Data['msg'] = 'Cannot Assign Protocol Device ID[0] on selected UART
Another devices already exists!
Device ID[0] May be set just in exclusive UART usage mode';
} else {
foreach( $RR as $R ){
if( $R['device_id'] == $EPROTOID ) {
$Data['msg'] = "On the selected UART line already exists sensor with selected Device ID[{$EPROTOID}]";
};
if( $R['device_id'] == 0 ){
$Data['msg'] = "On the selected UART line already exists sensor with Device ID[0]
This UART can not be assigned to another sensor!";
};
};
if( !isset( $Data['msg'] ) ){
// All OK
$QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`uart_id`,`device_id`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,{$EUARTID},{$EPROTOID},{$ERANGE},255)";
$DATABASE->Query( $QS );
$SIID = $DATABASE->getLastInsertID();
$NAME = 'SENSOR_'.$SIID;
$QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
$DATABASE->Query( $QS );
$Data['status'] = 'ok';
};
};
} else {
// No device assigned with this UART
$QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`uart_id`,`device_id`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,{$EUARTID},{$EPROTOID},{$ERANGE},255)";
$DATABASE->Query( $QS );
$SIID = $DATABASE->getLastInsertID();
$NAME = 'SENSOR_'.$SIID;
$QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
$DATABASE->Query( $QS );
$Data['status'] = 'ok';
};
} else {
$Data['msg'] = 'The UART Not Selected!';
};
} else {
$EIP = $DATABASE->escape( $_POST['ADDR'] );
$EPORT = intval( $_POST['PORT'] );
//IP Sensor
$QS="INSERT INTO `lrf_sensors`(`type`,`data_status`,`ip`,`port`,`max_range`,`enabled_lrf`) VALUES({$ETYP},1,'{$EIP}',{$EPORT},{$ERANGE},255)";
$DATABASE->Query( $QS );
$SIID = $DATABASE->getLastInsertID();
$NAME = 'SENSOR_'.$SIID;
$QS="INSERT INTO `nodes`(`type`,`aux_id`,`name`,`online`) VALUES({$ETYP},{$SIID},'{$NAME}',0)";
$DATABASE->Query( $QS );
$Data['status'] = 'ok';
};
break;
};
};
echo json_encode( $Data );
} else {
header('location: /');
};
?>