Esempio n. 1
0
void LocalPC::tcpServerReceiveData(void *tcp, char *buffer, int size)
{
    DEBUG_OUTPUT("[LocalPC]receive:\n%s\n", buffer_format(buffer, size));
    HeartbeatProtocol protocol;
    Heartbeat *hb = protocol.find(buffer, size);
    if(hb!=NULL)
    {
        delete hb;

        char *p = NULL;
        int size = 0;
        bool slave = isSlave();
        double timePoint = getSetupTime();
        Heartbeat *t = protocol.makeHeartbeat(slave, timePoint);
        if(NULL!=t)
        {
            if(t->makeBuffer(&p, size))
            {
                TcpClient *client = (TcpClient *)tcp;
                client->send(p, size);
                delete p;
            }
        }
    }
}
Esempio n. 2
0
std::string Customer::toString() const {
    char data[4096];

    std::string str;

    sprintf(data,"Cust %s)  SetupTime=%.1f   Cap=%-6.0f  IniQty=%-6.0f   Safety=%-6.0f",
            getIndexStr().c_str(),getSetupTime(),capacity_,initialQuantity_,safetyLevel_);

    sprintf(data,"%s Trailers=[",data);
    bool first=true;
    for(Trailer* t: allowedTrailers_){
        sprintf(data,"%s%s%d",data,(first?"":"-"),t->getIndex());
        first = false;
    }
    sprintf(data,"%s]",data);


    int tam = (int)forecast_.size();
    int n = 0, day = 0;
    double dailyAmount;
    sprintf(data,"%s\n         ",data);
    sprintf(data,"%s  Forecast=[",data);
    for(double d: forecast_){
        dailyAmount += d;
        if( n % 24 == 23 ) {
            sprintf(data,"%s%6.0f%s",data,dailyAmount,(n==tam-1?"":";"));
            if( (n/24)%10 == 9 && n < tam-1 )
                sprintf(data,"%s\n                     ",data);
            dailyAmount = 0.0;
        }
        n++;
    }
    sprintf(data,"%s]",data);

    str = data;
    return str;
}