Пример #1
0
extern EOreceiver* eo_receiver_New(const eOreceiver_cfg_t *cfg)
{
    EOreceiver *retptr = NULL;   

    if(NULL == cfg)
    {    
        cfg = &eo_receiver_cfg_default;
    }
    
    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOreceiver), 1);
    retptr->ropframeinput       = eo_ropframe_New();
    retptr->ropframereply       = eo_ropframe_New();
    retptr->ropinput            = eo_rop_New(cfg->sizes.capacityofropinput);
    retptr->ropreply            = eo_rop_New(cfg->sizes.capacityofropreply);
    retptr->agent               = cfg->agent;
    retptr->ipv4addr            = 0;
    retptr->ipv4port            = 0;
    retptr->bufferropframereply = (0 == cfg->sizes.capacityofropframereply) ? (NULL) : (eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->sizes.capacityofropframereply, 1));
    retptr->rx_seqnum           = eok_uint64dummy;
    retptr->tx_ageofframe       = eok_uint64dummy;
    memset(&retptr->error_seqnumber, 0, sizeof(retptr->error_seqnumber));       // even if it is already zero.
    memset(&retptr->error_invalidframe, 0, sizeof(retptr->error_invalidframe)); // even if it is already zero. 
    retptr->on_error_seqnumber  = cfg->extfn.onerrorseqnumber;
    retptr->on_error_invalidframe = cfg->extfn.onerrorinvalidframe;
    // now we need to allocate the buffer for the ropframereply

#if defined(USE_DEBUG_EORECEIVER)    
    memset(&retptr->debug, 0, sizeof(EOreceiverDEBUG_t));
#endif  
    
    eo_ropframe_Load(retptr->ropframereply, retptr->bufferropframereply, eo_ropframe_sizeforZEROrops, cfg->sizes.capacityofropframereply);
    eo_ropframe_Clear(retptr->ropframereply);
    
    return(retptr);
}
Пример #2
0
extern EOtransmitter* eo_transmitter_New(const eo_transmitter_cfg_t *cfg)
{
    EOtransmitter *retptr = NULL;   

    if(NULL == cfg)
    {    
        cfg = &eo_transmitter_cfg_default;
    }
    
    // i get the memory for the object
    retptr = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, sizeof(EOtransmitter), 1);
    
    retptr->txpacket                = eo_packet_New(cfg->capacityoftxpacket);
    retptr->ropframereadytotx       = eo_ropframe_New();
    retptr->ropframeregulars        = eo_ropframe_New();
    retptr->ropframeoccasionals     = eo_ropframe_New();
    retptr->ropframereplies         = eo_ropframe_New();
    retptr->roptmp                  = eo_rop_New(cfg->capacityofrop);
    retptr->nvscfg                  = cfg->nvscfg;
    retptr->theagent                = eo_agent_Initialise(NULL);
    retptr->ipv4addr                = cfg->ipv4addr;
    retptr->ipv4port                = cfg->ipv4port;
    retptr->bufferropframeregulars  = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->capacityofropframeregulars, 1);
    retptr->bufferropframeoccasionals = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->capacityofropframeoccasionals, 1);
    retptr->bufferropframereplies   = eo_mempool_GetMemory(eo_mempool_GetHandle(), eo_mempool_align_32bit, cfg->capacityofropframereplies, 1);
    retptr->listofregropinfo        = (0 == cfg->maxnumberofregularrops) ? (NULL) : (eo_list_New(sizeof(eo_transm_regrop_info_t), cfg->maxnumberofregularrops, NULL, 0, NULL, NULL));
    retptr->currenttime             = 0;
    retptr->tx_seqnum               = 0;

    eo_ropframe_Load(retptr->ropframeregulars, retptr->bufferropframeregulars, eo_ropframe_sizeforZEROrops, cfg->capacityofropframeregulars);
    eo_ropframe_Clear(retptr->ropframeregulars);
    eo_ropframe_Load(retptr->ropframeoccasionals, retptr->bufferropframeoccasionals, eo_ropframe_sizeforZEROrops, cfg->capacityofropframeoccasionals);
    eo_ropframe_Clear(retptr->ropframeoccasionals);
    eo_ropframe_Load(retptr->ropframereplies, retptr->bufferropframereplies, eo_ropframe_sizeforZEROrops, cfg->capacityofropframereplies);
    eo_ropframe_Clear(retptr->ropframereplies);


    {   // we set the content of ropframereadytotx with the same memory used by txpacket, so that when we operate on 
        // ropframereadytotx then we prepare the txpacket.
        uint8_t *data;
        uint16_t size;
        uint16_t capacity;
        
        eo_packet_Payload_Get(retptr->txpacket, &data, &size);
        eo_packet_Capacity_Get(retptr->txpacket, &capacity);
    
        eo_ropframe_Load(retptr->ropframereadytotx, data, eo_ropframe_sizeforZEROrops, capacity); // dont use size because size is now zero.
        eo_ropframe_Clear(retptr->ropframereadytotx);
        
        if(eobool_true != eo_ropframe_IsValid(retptr->ropframereadytotx))
        {
            eo_errman_Error(eo_errman_GetHandle(), eo_errortype_fatal, s_eobj_ownname, "the ropframeready2tx is not valid... cannot continue");
        }

        // the destination ipv4addr and ipv4port are constant and are the ones passed through configuration
        eo_packet_Addressing_Set(retptr->txpacket, retptr->ipv4addr, retptr->ipv4port);
    } 

    if((NULL != cfg->mutex_fn_new) && (eo_transmitter_protection_total == cfg->protection))
    {
        retptr->mtx_replies     = cfg->mutex_fn_new();
        retptr->mtx_regulars    = cfg->mutex_fn_new();
        retptr->mtx_occasionals = cfg->mutex_fn_new();        
    }
    else
    {
        retptr->mtx_replies     = NULL;
        retptr->mtx_regulars    = NULL;
        retptr->mtx_occasionals = NULL;
    }
    
#if defined(USE_DEBUG_EOTRANSMITTER)
    // DEBUG
    retptr->debug.txropframeistoobigforthepacket = 0;
#endif
    
    return(retptr);
}