예제 #1
0
bool EditorWidget::verifyContents()
{
    //If any cells are currently edited add their contents
    //to the tableWidget
    QWidget *cellWidget = m_tableWidget->cellWidget(m_tableWidget->currentRow(), m_tableWidget->currentColumn());
    if (cellWidget) {
        QAbstractItemDelegate *delegate = m_tableWidget->itemDelegateForColumn(m_tableWidget->currentColumn());
        if (delegate) {
            delegate->setModelData(cellWidget,m_tableWidget->model(),m_tableWidget->currentIndex());
        }
    }

    QString repoUID = m_repoUID->text();
    if (!checkID(repoUID)) {
        QMessageBox::warning(this, tr("Invalid input"),
                             tr("The '%1' field is invalid, "
                                "it must be a hexidecimal number no longer than 8 digits.")
                             .arg(m_repoLabel->text()));
        m_repoUID->setFocus();
        return false;
    }

    QString keyId;
    QString path;
#ifdef INCL_TYPE
    QString type;
#endif
    for(int i=0; i < m_tableWidget->rowCount(); i++) {
        keyId = m_tableWidget->item(i, EditorWidget::KeyId)->text();
        if (!checkID(keyId)) {
            QMessageBox::warning(this, tr("Invalid Key ID"),
                                 tr("The Key ID field is invalid, it must be a hexidecimal number no longer than 8 digits"));
            m_tableWidget->setCurrentCell(i, EditorWidget::KeyId);
            m_tableWidget->setFocus();
            return false;
        }

        path = m_tableWidget->item(i, EditorWidget::Path)->text();
        if (path.isEmpty() || !path.startsWith(QLatin1Char('/'))) {
            QMessageBox::warning(this, tr("Invalid Path"),
                                 tr("The Key Path field is invalid, it must not be empty and start with a /"));
            m_tableWidget->setCurrentCell(i, EditorWidget::Path);
            m_tableWidget->setFocus();
            return false;
        }

#ifdef INCL_TYPE
        type = m_tableWidget->item(i, EditorWidget::Type)->text();
        if (type.isEmpty()) {
            QMessageBox::warning(this, tr("Invalid Type"),
                                 tr("The Type field is invalid, it must not be empty"));
            m_tableWidget->setCurrentCell(i, EditorWidget::Type);
            m_tableWidget->setFocus();
            return false;
        }
#endif
    }
    return true;
}
 void Weather::begin(void)
{
  Wire.begin();

  uint8_t ID_Temp_Hum = checkID();

  int x = 0;

  if(ID_Temp_Hum == 0x15)//Ping CheckID register
    x = 1;
  else if(ID_Temp_Hum == 0x32)
    x = 2;
  else
    x = 0;

  if(x == 1)
  {
    Serial.println("Si7021 Found");
    //Serial.println(ID_Temp_Hum, HEX);
  }
  else if(x == 2)
  {
    Serial.println("HTU21D Found");
    //Serial.println(ID_Temp_Hum, HEX);
  }
  else
  	Serial.println("No Devices Detected");
  	//Serial.println(ID_Temp_Hum, HEX);
}
예제 #3
0
파일: EntityManager.cpp 프로젝트: F4r3n/ECS
void EntityManager::killAll() {
    for(auto& e : _entities_alive)
    {
        if(e && e->allocated)
        {
            if(!checkID(e->ID) && _entitiesComponents[e->ID])
            {
                _entitiesComponents[e->ID].reset();
            }
            
			delete e;
		}
	}

    for(size_t i = 0; i < _temp_entities.size(); ++i)
    {
        if(_temp_entities[i] && _temp_entities[i]->allocated)
        {
            delete _temp_entities[i];
        }
    }
    _temp_entities.clear();

    size_t sizeFreeID = _free_id.size();
    for(size_t i = 0; i < sizeFreeID; ++i)
    {
        _free_id.push(i);
    }
	_entities_alive.clear();
	_entities_killed.clear();
	_capacity = 0;

}
예제 #4
0
void PMXMLParser::parseChildObjects( QDomElement& e, PMObject* parent )
{
   QDomNode c = e.firstChild( );
   while( !c.isNull( ) )
   {
      if( c.isElement( ) )
      {
         QDomElement ce = c.toElement( );
         PMPrototypeManager* m = m_pPart->prototypeManager( );
         PMObject* obj = m->newObject( m->className( ce.tagName( ) ) );
         if( obj )
         {
            PMXMLHelper hlp( ce, m_pPart, this,
                             m_majorDocumentFormat, m_minorDocumentFormat );
            obj->readAttributes( hlp );
            if( insertChild( obj, parent ) )
            {
               parseChildObjects( ce, obj );

               if( obj->isA( "Declare" ) )
                  checkID( ( PMDeclare* ) obj );
            }
            else
               delete obj;
         }
         else if( ce.tagName( ) != "extra_data" )
            printError( i18n( "Unknown object %1" ).arg( ce.tagName( ) ) );
      }
      c = c.nextSibling( );
   }
}
예제 #5
0
/* getInterval - get the interval time in ms for a task
    Parameters  int Task ID to check

    Return int  < 0 invalid ID
                >= 0 Valid interval time
*/
int getInterval( int ID )
{
int i;

if( ( i = checkID( ID ) ) < 0 )
  return i;
return taskTable[ ID ].interval;
}
예제 #6
0
/* getStatus - get task status even if running task
    Parameters  int Task ID to get status for

    Return int  -1  invalid ID
               any other value Status (including other user errors -ve
*/
int getStatus( int ID )
{
int i;

// Check valid ID, not running and interval
if( ( i = checkID( ID ) ) < 0 )
  return i;
return taskTable[ ID ].status;
}
예제 #7
0
/* getTime - get next execution time in ms of a task
    As value is unsigned long impossible to guarantee error codes
    So if values listed below for errors check current millis() value
    to see if could be real or error.

    Parameters  int Task ID to check

    Return      unsigned long of time (or could be errors)
                0 could be execution time or errro of invalid ID
                1 could be execution time or error of NO interval check
*/
unsigned long getTime( int ID )
{
int i;

if( ( i = checkID( ID ) ) < 0 )
  return 0;
if( taskTable[ ID ].interval <= 0 )
  return 1;
return taskTable[ ID ].next;
}
예제 #8
0
파일: geom.cpp 프로젝트: Fandekasp/steps
void swm::Geom::_checkPatchID(string const & id) const
{
    checkID(id);
    if (pPatches.find(id) != pPatches.end())
    {
		ostringstream os;
        os << "'" << id << "' is already in use";
        throw steps::ArgErr(os.str());
    }
}
예제 #9
0
int checkVersion(int fd, unsigned char capeAddr)
{
	int boardVer = getVersionNumber(capeAddr - 0x2c);
    int softVer = checkID(fd, boardVer);
    if (softVer != 0) { 
        printf("Error: software version and board version are incompatible\n");
        printf("       Board version = %d, Software version = %d\n",
                boardVer, softVer);
        printf("NOTE: if any version number is -1, the version is not found\n");
		return -1;
    }
	return 0;
}
예제 #10
0
파일: Reports.cpp 프로젝트: majeski/NUBZ
void Reports::insert(const Report &report) {
    auto experimentOpt = Experiments{session}.getActive();
    if (!experimentOpt || experimentOpt.value().ID != report.experimentID) {
        throw InvalidData{"given experiment ID is not an ID of currently active experiment"};
    }
    auto experiment = experimentOpt.value();

    checkID(report.ID);
    checkEvents(experiment, report.history);
    checkSurveyAns(experiment.surveyBefore, report.surveyBefore);
    checkSurveyAns(experiment.surveyAfter, report.surveyAfter);

    retainExhibits(report.history);
    Impl::insert(session, toDB(report));
}
예제 #11
0
/* Start - Start a task if not running and has interval set
   Cannot start an already started task

   It is responsibility of the task to stop its task and any associated
   resources (GPIO/TWI/SPI etc).

    Parameters  int Task ID to start

    Return int  -3  Task already started
                -2  No interval on task
                -1  invalid ID
                 0  current task running
                > 0 Valid
*/
int Start( int ID )
{
int i;

// Check valid ID, not running and interval
if( ( i = checkID( ID ) ) <= 0 )
  return i;
if( taskTable[ ID ].interval <= 0 )
  return -2;
if( taskTable[ ID ].status  > 0 )
  return -3;
// Start task
taskTable[ ID ].status = 1;
taskTable[ ID ].next = old_ms + taskTable[ ID ].interval;
return 1;
}
예제 #12
0
/* setInterval - set the interval time in ms for a task
   If task running just sets interval as next execution will be set at task end.

   When task NOT running, also sets next execution time to now plus interval.

    Parameters  int Task ID to check
                int interval to set

    Return int  -2 invalid interval
                -1 invalid ID
                 0  task is running
                > 0 task interval and execution time set
*/
int setInterval( int ID, int interval )
{
int i;

if( ( i = checkID( ID ) ) < 0 )
  return i;
if( interval < MIN_TASK_INTERVAL )
  return -2;
taskTable[ ID ].interval = interval;
if( i != 0 )
  {
  taskTable[ ID ].next = millis( ) + interval;
  return 1;
  }
return 0;
}
예제 #13
0
int DMCCstart(unsigned char capeAddr)
{
    capeAddr+=0x2c;
    char filename[20];
    strcpy(filename,"/dev/i2c-1");

    int fd;

    //Opens a file descriptor to the board
    fd = open(filename, O_RDWR);
    if (fd <0) {
        printf("Error: cannot open %s\n",filename);
        exit(1);
    }
    if (ioctl(fd, I2C_SLAVE, capeAddr) < 0) {
        printf("Error: cannot ioctl to addr 0x%x\n", capeAddr);
        close(fd);
        exit(1);
    }
   
    int boardVer = getVersionNumber(capeAddr - 0x2c);
    int softVer = checkID(fd, boardVer);
    if (softVer != 0) { 
        printf("Error: software version and board version are incompatible\n");
        printf("       Board version = %d, Software version = %d\n",
                boardVer, softVer);
        printf("NOTE: if any version number is -1, the version is not found\n");
        close(fd);
        exit(1);
    }

    //Default PID constants
    setPIDConstants(fd, 1, -19200, -8000, -150, 1);
    setPIDConstants(fd, 1, -19200, -8000, -150, 1);
    setPIDConstants(fd, 0, -5248, -75, -500, 1);
    setPIDConstants(fd, 0, -10000, -75, -500, 2);
    return fd;
}
예제 #14
0
int command_interpreter(FTPinfo * FTP_information)
{
    char        pure_command[MAXLINE]; 
    char        arg_opt[MAXLINE];
    int         fail;         // this variable make program code readable.
    char        buf[MAXLINE]; // This will be used for multiple purpose below.
    char*       userpath;     // user relative path.

    
    strcpy(pure_command, FTP_information->RAW_command); //unsafe.
    fail = command_parser(FTP_information->RAW_command, pure_command, arg_opt);
    /*  
        for example,
        command_parser("USER localhost -arg -opt", buffer-pointer, buffer-pointer2);
        buffer-pointer  -> USER
        buffer-pointer2 -> localhost -arg -opt
    */
    
    /*
    if(fail) // fail to parse command due to invalid command.
    {
        perror("parse error");
        return -1;
    }
    */
    
    /*        interpret command.        */
    if( strcmp(pure_command, "USER") == 0)
    {
        //strcpy(FTP_information->response_code, "331");
        strcpy(FTP_information->response_code, "331 Please specify the password.\r\n");
        strcpy(FTP_information->loginID, arg_opt);
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 331;
    }
    else if( strcmp(pure_command, "PASS") == 0)
    {
        chdir("/Users/tracking/Desktop/old/REAL_FTP/REAL_FTP"); // for xcode debug. you should delete
        
        
        fail = checkID(FTP_information->loginID, arg_opt);
        if(fail)
        {
            strcpy(FTP_information->response_code, "530 Login incorrect.\r\n");
            return 530;
        }
        
        
        
        // if there not exist user directory, then the program need to make it.
        if( access(FTP_information->loginID,F_OK) == -1)
            mkdir(FTP_information->loginID, 0777); // you'd better correct permission.

                // configure user directory.
        chdir(FTP_information->loginID);
        getcwd(FTP_information->root_directory, BUFSIZE);
        getcwd(FTP_information->working_directory, BUFSIZE);
        
        strcpy(FTP_information->response_code, "230- Welcome to my FTP world.\r\n");
        strcat(FTP_information->response_code, "230-\r\n");
        strcat(FTP_information->response_code, "230- This system is for authorized users only. All access is logged.\r\n");
        strcat(FTP_information->response_code, "230 Login successful.\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 230;
    }
    else if( strcmp(pure_command, "SYST") == 0)
    {
        strcpy(FTP_information->response_code, "215 MACOS Type: L8\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 215;
    }
    else if( strcmp(pure_command, "FEAT") == 0)
    {
        strcpy(FTP_information->response_code, "211 \r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 211;
    }
    else if( strcmp(pure_command, "PWD") == 0)
    {

//        strcpy(buf, FTP_information->working_directory);
        userpath    =   Generate_userpath(FTP_information->working_directory, FTP_information->root_directory);
        if( *userpath == 0) // NULL is user-root directory
        {
            buf[0] = '/';
            buf[1] = 0;
            userpath = buf;
        }
        sprintf(FTP_information->response_code, "257 \"%s\"\r\n", userpath);
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 257;
    }
    else if( strcmp(pure_command, "CWD") == 0)
    {
        
        if(access(arg_opt, F_OK	) == -1)
        {
            sprintf(FTP_information->response_code, "550 %s: No such file or directory\r\n", arg_opt);
            return 550;
        }
        chdir(arg_opt);
        getcwd(buf, MAXLINE);
        // since user can't move upper directory than user direcory!
        if( strlen(buf) < strlen(FTP_information->root_directory))
            chdir(FTP_information->root_directory);
        getcwd(FTP_information->working_directory, BUFSIZE);
        strcpy(FTP_information->response_code, "250 CWD command successful.\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 250;
        
    }
    else if( strcmp(pure_command, "QUIT") == 0)
    {
        sprintf(FTP_information->response_code, "221 Goodbye \r\n");
        close(FTP_information->controlsockfd);
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 221;
    }
    else if( strcmp(pure_command, "PORT") == 0)
    {
        /* previous code.
        Get_dataportandIP(FTP_information,arg_opt);
        strcpy(FTP_information->response_code, "200 PORT command successful.\r\n");
        strcpy(FTP_information->RAW_command, pure_command);
        */
        
        Get_dataportandIP(FTP_information,arg_opt);
        strcpy(FTP_information->response_code, "200 PORT command successful.\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code));
        
        active_open(FTP_information);
        strcpy(FTP_information->response_code, "150 Data Connection OK\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code));
        return 200;
    }
    else if( strcmp(pure_command, "NOOP") == 0)
    {
        strcpy(FTP_information->response_code, "200 NOOP command successful.\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 200;
    }
    else if( strcmp(pure_command, "PASV") == 0)
    {
        passive_open(FTP_information);
        
        // on failure, I would send the message "cannot open connection.".
        strcpy(FTP_information->response_code, "150 Data Connection OK\r\n"); // not need.
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        
        return 227;
    }
    /*
    else if( strcmp(pure_command, "LIST") == 0)
    {
        active_open(FTP_information); // needs to return -1 or 0. for exception proces
        strcpy(FTP_information->response_code, "125 Data Connection OK\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 125;
    }
    */
    else if( strcmp(pure_command, "TYPE") == 0)
    {
        strcpy(FTP_information->response_code,"200 TYPE Command OK\r\n");
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
        return 200;
    }
    else if( strcmp(pure_command, "MKD") == 0)
    {
//        strcpy(FTP_information->response_code, ")
    
        fail = mkdir(arg_opt, 0644);
        
        if(fail)
        {
            perror("directory error : ");
            strcpy(FTP_information->response_code, "503 Bad sequence of commands.\r\n");
            return 503;
        }
        else
        {
            
            strcpy(FTP_information->response_code, "257 Directory Command succesful\r\n");
            return 257;
        }
        write(FTP_information->controlsockfd, FTP_information->response_code,
              strlen(FTP_information->response_code)); // send response.
    }
    else
    {
        fail = Data_gateway(FTP_information); // maybe data transfer command.
        if(fail)
        {
            sprintf(FTP_information->response_code, "502 Command not implemented.\r\n");
            write(FTP_information->controlsockfd, FTP_information->response_code,
                  strlen(FTP_information->response_code));
            return 502;
        }
        else
        {
            close(FTP_information->datasockfd); // transfer complete.
            write(FTP_information->controlsockfd, FTP_information->response_code,
                  strlen(FTP_information->response_code));
            return 226;
        }
    }
    return 0;
}
예제 #15
0
//--------------------------------------------------------------
void ofApp::update(){
    if(ofGetFrameNum() % 60 == 0)
    {
        _reservedID.clear();
        
        for(int i=0;i<_movers.size();i++)
        {
            for(int k=0;k<4;k++)
            {
                _flag[k] = false;
            }
            
            while(1)
            {
                _movers[i].randomf = ofRandom(0,1);
                if(_movers[i].randomf < 0.25)             //right
                {
                    int num = _movers[i].presentID+1;
                    
                    if(num % SPRIT_NUM_X != 0)
                    {
                        if(checkID(num))
                        {
                            _movers[i].pastID = _movers[i].presentID;
                            _movers[i].presentID = num;
                            break;
                        }
                        else
                        {
                            _flag[0] = true;

                        }
                    }
                }
                else if(_movers[i].randomf < 0.5)         //left
                {
                    int num = _movers[i].presentID-1;
                    if(num >= 0 && num % SPRIT_NUM_X != SPRIT_NUM_X-1)
                    {
                        if(checkID(num))
                        {
                            _movers[i].pastID = _movers[i].presentID;
                            _movers[i].presentID = num;
                            break;
                        }
                        else
                        {
                            _flag[1] = true;

                        }
                    }
                }
                else if(_movers[i].randomf < 0.75)        //down
                {
                    int num = _movers[i].presentID+SPRIT_NUM_X;
                    if(num < _pos.size())
                    {
                        if(checkID(num))
                        {
                            _movers[i].pastID = _movers[i].presentID;
                            _movers[i].presentID = num;
                            break;
                        }
                        else
                        {
                            _flag[2] = true;

                        }
                    }

                }
                else                                      //up
                {
                    int num = _movers[i].presentID-SPRIT_NUM_X;
                    if(num >= 0)
                    {
                        if(checkID(num))
                        {
                            _movers[i].pastID = _movers[i].presentID;
                            _movers[i].presentID = num;
                            _reservedID.push_back(num);
                            break;
                        }
                        else
                        {
                            _flag[3] = true;

                        }
                    }
                }
                
                
                if(_flag[0] && _flag[1] && _flag[2] && _flag[3])
                {
                    _movers.erase(_movers.begin()+i);
                    break;
                }
                
            }
        }
        _tweenCubicX.setParameters(0,_easingCubic,ofxTween::easeOut, 0, 1, 900, 0);
        _tweenCubicY.setParameters(1,_easingCubic,ofxTween::easeOut, 0, 1, 900, 0);
    }
    
    
    for(int i=0;i<_movers.size();i++)
    {
        if(_movers[i].randomf < 0.5)
        {
            _movers[i].pos.x = _pos[_movers[i].pastID].x + (_pos[_movers[i].presentID].x-_pos[_movers[i].pastID].x)*_tweenCubicX.update();
            _movers[i].pos.y = _pos[_movers[i].pastID].y;
        }
        else
        {
            _movers[i].pos.x = _pos[_movers[i].pastID].x;
            _movers[i].pos.y = _pos[_movers[i].pastID].y + (_pos[_movers[i].presentID].y-_pos[_movers[i].pastID].y)*_tweenCubicY.update();
        }
    }
}