47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
//
|
|
// Created by CFIF on 09.11.22.
|
|
//
|
|
#include "ComIntCmd/SerialBridge.h"
|
|
#include "string.h"
|
|
|
|
|
|
void SerialBridges_Init(tSerialBridges *env, tSerialBridge *allocatedMem, uint16_t memCountLimit) {
|
|
env->limit = memCountLimit;
|
|
env->items = allocatedMem;
|
|
env->count = 0;
|
|
memset(env->items, 0, env->limit * sizeof(tSerialBridge));
|
|
}
|
|
|
|
bool SerialBridges_Add(
|
|
tSerialBridges *env,
|
|
char *staticStringName,
|
|
uint8_t nameLen,
|
|
tSerialPortIO *io
|
|
) {
|
|
if (env->limit <= env->count) {
|
|
return false;
|
|
}
|
|
|
|
tSerialBridge *item = env->items + env->count;
|
|
|
|
item->name = staticStringName;
|
|
item->nameLength = nameLen;
|
|
item->serialIo = io;
|
|
|
|
++env->count;
|
|
|
|
return true;
|
|
}
|
|
|
|
tSerialBridge *SerialBridges_GetForName(tSerialBridges *table, char *name, uint8_t nameLen) {
|
|
|
|
for (uint16_t idx = 0; idx < table->count; ++idx) {
|
|
tSerialBridge *bridge = table->items + idx;
|
|
if (bridge->nameLength == nameLen) {
|
|
if (strncmp(bridge->name, name, nameLen) == 0) {
|
|
return bridge;
|
|
}
|
|
}
|
|
}
|
|
return NULL;
|
|
} |