1.2.13.2 Using The Library

The SE Log Report library is called with information related to the current operation of a Smart Energy communication stack (G3 or PRIME) or service in order to report it with the given purpose (error, warning, information, debug) in an appropriate format.

The following example illustrates how information is passed to the SE Log Report service.

Example of SE Log Report library usage

void SRV_QUEUE_Append(SRV_QUEUE *queue, SRV_QUEUE_ELEMENT *element)
{
    SRV_QUEUE_ELEMENT *currentElement;
    uint16_t queueCounter;

    /* Check if element is already in the queue (size > 1) */
    if ((element->next != NULL) || (element->prev != NULL))
    {
        /* Do nothing - element is already in queue */
        SRV_LOG_REPORT_Message_With_Code(SRV_LOG_REPORT_ERROR, QUEUE_APPEND_AGAIN,
            "Trying to append an element already in the queue");
        return;
    }

    /* Check if element is already in the queue (size = 1) */
    if ((queue->size == 1) && (queue->head == element))
    {
        /* Do nothing - element is already in queue */
        SRV_LOG_REPORT_Message_With_Code(SRV_LOG_REPORT_WARNING, QUEUE_APPEND_AGAIN_ONE_ELEMENT,
            "Trying to append an element already in a queue with size 1");
        return;
    }

    if (((queue->iniQueue != NULL) && (queue->lastElement != NULL)) &&
        ((element < queue->iniQueue) || (element > queue->lastElement)))
    {
        SRV_LOG_REPORT_Message_With_Code(SRV_LOG_REPORT_ERROR, QUEUE_APPEND_BAD_ELEMENT,
            "Trying to append a bad element\r\n");
        return;
    }

    /* Check if queue is full */
    if (queue->size >= queue->capacity)
    {
        /* Element cannot be appended because queue is full */
        SRV_LOG_REPORT_Message_With_Code(SRV_LOG_REPORT_ERROR, QUEUE_FULL_APPEND,
            "Error in SRV_QUEUE_Append: QUEUE_FULL\r\n");
        return;
    }
    else
    {
        /* Check whether queue is empty */
        if (queue->size == 0)
        {
            _SRV_QUEUE_Insert_First_Element(queue, element);
        }
        else
        {
            if (queue->type == SRV_QUEUE_TYPE_SINGLE)
            {
                _SRV_QUEUE_Insert_Last_Element(queue, element);
            }
            else
            {
                /* Insert in priority queue */
                /* Search for the first element with the same priority */
                /* and insert at the end */
                queueCounter = queue->size + 1;
                currentElement = queue->tail;
                while (queueCounter != 0)
                {
                    if (element->priority < currentElement->priority)
                    {
                        if (currentElement->prev != NULL)
                        {
                            /* Move current element to previous element*/
                            currentElement = currentElement->prev;
                            queueCounter--;
                        }
                        else
                        {
                            /* First element of the queue */
                            /* Add element at the beginning*/
                            SRV_QUEUE_Insert_Before(queue, currentElement,
                                                    element);
                            break;
                        }
                    }
                    else
                    {
                        SRV_QUEUE_Insert_After(queue, currentElement, element);
                        break;
                    }
               }
            }
        }
    }

    _SRV_QUEUE_Check_Queue_Consistent(queue);
}