Пример #1
0
// Process( MsgJob )
//------------------------------------------------------------------------------
void Server::Process( const ConnectionInfo * connection, const Protocol::MsgJob * msg, const void * payload, size_t payloadSize )
{
    ClientState * cs = (ClientState *)connection->GetUserData();
    MutexHolder mh( cs->m_Mutex );
    ASSERT( cs->m_NumJobsRequested > 0 );
    cs->m_NumJobsRequested--;
    cs->m_NumJobsActive++;

    // deserialize job
    ConstMemoryStream ms( payload, payloadSize );

    Job * job = FNEW( Job( ms ) );
    job->SetUserData( cs );

    //
    const uint64_t toolId = msg->GetToolId();
    ASSERT( toolId );

    MutexHolder manifestMH( m_ToolManifestsMutex ); // ensure we don't make redundant requests

    ToolManifest ** found = m_Tools.FindDeref( toolId );
    ToolManifest * manifest = found ? *found : nullptr;
    if ( manifest )
    {
        job->SetToolManifest( manifest );
        if ( manifest->IsSynchronized() )
        {
            // we have all the files - we can do the job
            JobQueueRemote::Get().QueueJob( job );
            return;
        }

        // missing some files - request them
        RequestMissingFiles( connection, manifest );
    }
    else
    {
        // first time seeing this tool

        // create manifest object
        manifest = FNEW( ToolManifest( toolId ) );
        job->SetToolManifest( manifest );
        m_Tools.Append( manifest );

        // request manifest of tool chain
        Protocol::MsgRequestManifest reqMsg( toolId );
        reqMsg.Send( connection );
    }

    // can't start job yet - put it on hold
    cs->m_WaitingJobs.Append( job );
}
Пример #2
0
int  LedCtrl::getZigbeeCfg(unsigned int id,TZigbeeCfg* cfg,long waitMs)
{
    if(isSimulate)
    {
        StreetLight* _pTemp = getSimLight(id,0);

        if(_pTemp != NULL)
        {
            //memcpy(pLight->zigbeeCfg,_pTemp,sizeof(StreetLight));
            *cfg = _pTemp->zigbeeCfg;
            return ERR_OK;
        }
        return  -1;
    }
    else
    {
        LedMessage respMsg;
        LedMessage reqMsg(id,0,CMD_QUERY_ZIGBEE_CFG,true,sizeof(TZigbeeCfg),waitMs);

        sendMessage (&reqMsg);

        if( waitRespMessage (&reqMsg,&respMsg))
        {
            if(respMsg.respCode == ERR_OK)
            {
                int len = 0;
                unsigned char* pData = respMsg.getBuffVal (len);

                if(len != ZIGBEE_CFG_SIZE) return NULL;

                cfg->address    = Buf2Short16 (pData);
                cfg->netID      = pData[2];
                cfg->netType    = (ZgbNetType)pData[3];
                cfg->nodeType   = (ZgbNodeType)pData[4];
                cfg->txMode     = (ZgbTxMode)pData[5];
                cfg->baudRate   = (ZgbBaud)pData[6];
                cfg->parity     = (ZgbParity)pData[7];
                cfg->dataBit    = (ZgbDataBit)pData[8];
                cfg->dataMode   = (ZgbDataMode)pData[9];
                cfg->timeOut    = pData[10];
                cfg->channal    = pData[11];
                cfg->kw         = pData[12];
                cfg->addrMode   = (ZgbAddressMode)pData[13];
                return ERR_OK;
            }

        }
    }

    return -1;
}
Пример #3
0
int  LedCtrl::writeE2prom(unsigned int id,unsigned char group,LedParam* pPara,long waitMs)
{
    LedMessage respMsg;
    LedMessage reqMsg(id,group,CMD_WRITE_EEPROM,true,0,waitMs);
    reqMsg.setBuffVal ((unsigned char*)pPara,sizeof(LedParam));

    sendMessage (&reqMsg);

    if( waitRespMessage (&reqMsg,&respMsg))
    {
        return respMsg.respCode;
    }

    return -1;
}
Пример #4
0
int  LedCtrl::getAllData(unsigned int id,unsigned char group,StreetLight* pLight,long waitMs)
{
    if(isSimulate)
    {
        StreetLight* _pTemp = getSimLight(id,group);

        if(_pTemp != NULL)
        {
            memcpy(pLight,_pTemp,sizeof(StreetLight));

            return ERR_OK;
        }
        return  -1;
    }
    else
    {

        LedMessage respMsg;
        LedMessage reqMsg(id,0,CMD_QUERY_ALL,true,25,waitMs);

        sendMessage (&reqMsg);

        if( waitRespMessage (&reqMsg,&respMsg))
        {
            if(respMsg.respCode == ERR_OK)
            {
                int len = 0;
                unsigned char* pData = respMsg.getBuffVal (len);
                if(len == 25)
                {
                    pLight->voltage = Buf2Int32(pData);
                    pLight->current = Buf2Int32(pData+4);
                    pLight->kw = Buf2Int32(pData+8);
                    pLight->brightness = pData[12];
                    pLight->defBright = pData[13];
                    pLight->adjustTime = pData[14];
                    pLight->group = pData[15];
                    pLight->devId = Buf2Int32(pData+16);
                    pLight->ver  = pData[20];
                    pLight->resetCnt = Buf2Int32(pData+21);
                    return ERR_OK;
                }

            }
        }
    }
    return -1;
}
Пример #5
0
    inline void HandleReqMsg(std::string msg,amqp_basic_properties_t *p)
        {
            std::cout<<msg<<std::endl;

            char key[4096];
            memset(key,0,sizeof(key));
            strncpy(key,(char*)(p->reply_to.bytes),p->reply_to.len);
            std::cout<<key<<std::endl;


            std::stringstream ss(msg);
            stock::PriceReq *req=new stock::PriceReq();
            boost::archive::xml_iarchive ia(ss);
            ia >> BOOST_SERIALIZATION_NVP(*req);
            
            PriceReqMessage reqMsg(req,key);
            Send(reqMsg, parent);
        }
Пример #6
0
int  LedCtrl::getIntResp(unsigned int id,LedCmdType type,int size,long waitMs)
{
    if(isSimulate)
    {
        return getSimParam(id,0,type);
    }
    else
    {

        LedMessage respMsg;
        LedMessage reqMsg(id,0,type,true,size,waitMs);

        sendMessage (&reqMsg);

        if( waitRespMessage (&reqMsg,&respMsg))
        {
            if(respMsg.respCode == ERR_OK)
            {
                switch(size)
                {
                case 1:
                    return respMsg.getCharVal ();
                    break;
                case 2:
                    return respMsg.getShortVal ();
                    break;
                case 4:
                    return respMsg.getIntVal ();
                    break;
                default:
                    break;
                }
            }

            return -respMsg.respCode;
        }


    }
    return -1;
}
Пример #7
0
//FIXME
int  LedCtrl::setZigbeeCfg(unsigned int id,TZigbeeCfg* pCfg,long waitMs)
{
    if(isSimulate)
    {
        StreetLight* _pTemp = getSimLight(id,0);

        if(_pTemp != NULL)
        {
            //memcpy(pLight->zigbeeCfg,_pTemp,sizeof(StreetLight));
            _pTemp->zigbeeCfg = *pCfg;
            return ERR_OK;
        }
        return  -1;
    }
    else
    {
        LedMessage respMsg;
        LedMessage reqMsg(id,0,CMD_SET_ZIGBEE_CFG,true,0,waitMs);

        sendMessage (&reqMsg);

        if( waitRespMessage (&reqMsg,&respMsg))
        {
            if(respMsg.respCode == ERR_OK)
            {
                int len = 0;
                unsigned char* pData = respMsg.getBuffVal (len);
                if(len > 0)
                {


                }
                return 0;
            }
            return -respMsg.respCode;

        }
    }
    return -1;
}
Пример #8
0
int  LedCtrl::setIntResp(unsigned int id,unsigned char group,LedCmdType type,int value,int size,long waitMs)
{
    if(isSimulate)
    {
        return setSimParam (id,group,type,value);
    }
    else
    {

        LedMessage respMsg;
        LedMessage reqMsg(id,group,type,true,size,waitMs);

        switch(size)
        {
        case 1:
            reqMsg.setCharVal (value);
            break;
        case 2:
            reqMsg.setShortVal (value);
            break;
        case 4:
            reqMsg.setIntVal (value);
            break;
        default:
            reqMsg.setCharVal (value);
            break;
        }
        sendMessage (&reqMsg);

        if( waitRespMessage (&reqMsg,&respMsg))
        {
            return -respMsg.respCode;
        }

        return -1;
    }

}