Commit fcf72c26 authored by Greg Williams's avatar Greg Williams
Browse files

Updated kinetic_socket/pdu/client APIs. Still need to complete updating...

Updated kinetic_socket/pdu/client APIs. Still need to complete updating per-operation client tests and system/examples.
parent df3cdeea
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
#!/bin/sh
# Run astyle on all C files in all project source folders
astyle --style=kr --break-closing-brackets --pad-oper --pad-header --unpad-paren --convert-tabs --indent=spaces=4 --lineend=linux --recursive src/*.* ./include/*.h
astyle --suffix=none --style=kr --break-closing-brackets --pad-oper --pad-header --unpad-paren --convert-tabs --indent=spaces=4 --indent-col1-comments --min-conditional-indent=0 --align-pointer=type --align-reference=type --keep-one-line-statements --lineend=linux --recursive "src/*.h" --recursive "src/*.c" --recursive "test/*.c" --recursive "test/*.h"  --recursive "include/*.h"
+8 −10
Original line number Diff line number Diff line
@@ -91,8 +91,7 @@ typedef int KineticSessionHandle;
/**
 * @brief Structure used to specify the configuration of a session.
 */
typedef struct _KineticSession
{
typedef struct _KineticSession {
    // Host name/IP address of Kinetic Device
    char    host[HOST_NAME_MAX];

@@ -138,8 +137,7 @@ typedef struct _KineticSession
typedef int KineticOperationHandle;

// Kinetic Status Codes
typedef enum
{
typedef enum {
    KINETIC_STATUS_INVALID = -1,        // Status not available (no reponse/status available)
    KINETIC_STATUS_SUCCESS = 0,         // Operation successful
    KINETIC_STATUS_SESSION_EMPTY,       // Session was NULL in request
+19 −10
Original line number Diff line number Diff line
@@ -2,14 +2,18 @@
#include <assert.h>
#include <string.h>

ByteArray ByteArray_Create(uint8_t* data, size_t len)
ByteArray ByteArray_Create(void* data, size_t len)
{
    return (ByteArray) {.data = (uint8_t*)(data), .len = len};
    return (ByteArray) {
        .data = (uint8_t*)(data), .len = len
    };
}

ByteArray ByteArray_CreateWithCString(char* str)
{
    return (ByteArray) {.data = (uint8_t*)str, .len = strlen(str)};
    return (ByteArray) {
        .data = (uint8_t*)str, .len = strlen(str)
    };
}

void ByteArray_FillWithDummyData(ByteArray array)
@@ -24,22 +28,26 @@ ByteArray ByteArray_GetSlice(ByteArray array, size_t start, size_t len)
    assert(array.data != NULL);
    assert(start < array.len);
    assert(start + len <= array.len);
    return (ByteArray){.data = &array.data[start], .len = len};
    return (ByteArray) {
        .data = &array.data[start], .len = len
    };
}



ByteBuffer ByteBuffer_Create(uint8_t* data, size_t max_len)
ByteBuffer ByteBuffer_Create(void* data, size_t max_len)
{
    return (ByteBuffer) {
        .array = (ByteArray) {.data = data, .len = max_len},
        .array = (ByteArray) {.data = (uint8_t*)data, .len = max_len},
        .bytesUsed = 0,
    };
}

ByteBuffer ByteBuffer_CreateWithArray(ByteArray array)
{
    return (ByteBuffer) {.array = array, .bytesUsed = 0};
    return (ByteBuffer) {
        .array = array, .bytesUsed = 0
    };
}

long ByteBuffer_BytesRemaining(const ByteBuffer buffer)
@@ -64,8 +72,9 @@ ByteArray ByteBuffer_Consume(ByteBuffer* buffer, size_t len)
}

bool ByteBuffer_Append(ByteBuffer* buffer,
    const uint8_t* data, size_t len)
                       const void* data, size_t len)
{
    assert(buffer != NULL);
    assert(buffer->array.data != NULL);
    assert(data != NULL);
    if (len == 0 || ((buffer->bytesUsed + len) > buffer->array.len)) {
+8 −6
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ typedef struct _ByteArray {
/** @brief Convenience macro to represent an empty array with no data */
#define BYTE_ARRAY_NONE (ByteArray){.len = 0, .data = NULL}

ByteArray ByteArray_Create(uint8_t* data, size_t len);
ByteArray ByteArray_Create(void* data, size_t len);
ByteArray ByteArray_CreateWithCString(char* str);
void ByteArray_FillWithDummyData(ByteArray array);
ByteArray ByteArray_GetSlice(ByteArray array, size_t start, size_t len);
@@ -31,17 +31,19 @@ ByteArray ByteArray_GetSlice(ByteArray array, size_t start, size_t len);
 * The `bytesUsed` field is initialized to zero, and is to incremented as each
 * byte is consumed, but shall not exceed the `array` length
 */
typedef struct
{
typedef struct {
    ByteArray   array;     /**< ByteArray holding allocated array w/length = allocated size */
    size_t      bytesUsed; /**< Reflects the number of bytes used from the `array` */
} ByteBuffer;

ByteBuffer ByteBuffer_Create(uint8_t* data, size_t max_len);
/** @brief Convenience macro to represent an empty buffer with no data */
#define BYTE_BUFFER_NONE (ByteBuffer){.array = BYTE_ARRAY_NONE}

ByteBuffer ByteBuffer_Create(void* data, size_t max_len);
ByteBuffer ByteBuffer_CreateWithArray(ByteArray array);
long ByteBuffer_BytesRemaining(const ByteBuffer buffer);
ByteArray ByteBuffer_Consume(ByteBuffer* buffer, size_t len);
bool ByteBuffer_Append(ByteBuffer* buffer, const uint8_t* data, size_t len);
bool ByteBuffer_Append(ByteBuffer* buffer, const void* data, size_t len);
bool ByteBuffer_AppendArray(ByteBuffer* buffer, const ByteArray array);
bool ByteBuffer_AppendCString(ByteBuffer* buffer, const char* data);
bool ByteBuffer_AppendDummyData(ByteBuffer* buffer, size_t len);
+5 −3
Original line number Diff line number Diff line
@@ -148,7 +148,9 @@ void KineticAllocator_FreeList(KineticList* list)
        LOG("  Nothing to free!");
    }

    *list = (KineticList){.start = NULL, .last = NULL};
    *list = (KineticList) {
        .start = NULL, .last = NULL
    };
}


Loading