Init
This commit is contained in:
commit
b8925e4a4b
|
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// Created by xemon on 09.11.22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef UVEOS_ON_NATION_SERIALBRIDGE_H
|
||||||
|
#define UVEOS_ON_NATION_SERIALBRIDGE_H
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include "XfcProtProcessorUtilDefines.h"
|
||||||
|
#include "SerialPort.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
uint8_t nameLength;
|
||||||
|
uint8_t flags;
|
||||||
|
tSerialPortIO *serialIo;
|
||||||
|
} tSerialBridge;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t count;
|
||||||
|
uint16_t limit;
|
||||||
|
tSerialBridge *items;
|
||||||
|
} tSerialBridges;
|
||||||
|
|
||||||
|
|
||||||
|
void SerialBridges_Init(tSerialBridges *env, tSerialBridge *allocatedMem, uint16_t memCountLimit);
|
||||||
|
|
||||||
|
#define SerialBridges_InitStatic(ENV, MEM) SerialBridges_Init(ENV,MEM,sizeof(MEM)/sizeof(tSerialBridge));
|
||||||
|
|
||||||
|
bool SerialBridges_Add(tSerialBridges *env, char *staticStringName, uint8_t nameLen, tSerialPortIO *io);
|
||||||
|
|
||||||
|
#define SerialBridges_AddStatic(ENV, STR, IO) SerialBridges_Add(ENV,STR,sizeof(STR)-1,IO)
|
||||||
|
|
||||||
|
tSerialBridge *SerialBridges_GetForName(tSerialBridges *table, char *name, uint8_t nameLen);
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
void XfcProtMethodsAdd_SerialBridge(tXfcProtTable *protTab, tSerialBridges *bridges);
|
||||||
|
|
||||||
|
////Methods
|
||||||
|
uint8_t XfcProtMethod_SerialBridgeTable(tXfcArray *request, tXfcArray *response, tSerialBridges *env);
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_SerialBridgeReed(tXfcArray *request, tXfcArray *response, tSerialBridges *env);
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_SerialBridgeWrite(tXfcArray *request, tXfcArray *response, tSerialBridges *env);
|
||||||
|
|
||||||
|
#endif //UVEOS_ON_NATION_SERIALBRIDGE_H
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
обычный транспортный протокол XfcTransportProtocol:
|
||||||
|
Прописать в modular.json:
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "ficom_modules",
|
||||||
|
"repo": "XfcTransportProtocol"
|
||||||
|
},
|
||||||
|
|
||||||
|
Расширеный транспортный протокол XfcTransportProtocol_Extended.
|
||||||
|
Прописать в modular.json:
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "ficom_modules",
|
||||||
|
"repo": "XfcTransportProtocol_Extended"
|
||||||
|
},
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
//
|
||||||
|
// Created by xemon on 10.11.22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ComIntCmd/SerialBridge.h"
|
||||||
|
|
||||||
|
void XfcProtMethodsAdd_SerialBridge(tXfcProtTable *protTab, tSerialBridges *bridges) {
|
||||||
|
XfcProtTable_AddStatic(protTab, "SERIAL_BRIDGE_TABLE", XfcProtMethod_SerialBridgeTable, bridges);
|
||||||
|
XfcProtTable_AddStatic(protTab, "SERIAL_BRIDGE_READ", XfcProtMethod_SerialBridgeReed, bridges);
|
||||||
|
XfcProtTable_AddStatic(protTab, "SERIAL_BRIDGE_WRITE", XfcProtMethod_SerialBridgeWrite, bridges);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
//
|
||||||
|
// Created by xemon on 09.11.22.
|
||||||
|
//
|
||||||
|
#include "ComIntCmd/SerialBridge.h"
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_SerialBridgeReed(tXfcArray *request, tXfcArray *response, tSerialBridges *env) {
|
||||||
|
char name[64];
|
||||||
|
uint8_t nameLength;
|
||||||
|
uint16_t blockLimit;
|
||||||
|
|
||||||
|
XFC_CMD_RX_GET_RAW(nameLength);
|
||||||
|
XFC_CMD_RX_GET_ARR(name, nameLength);
|
||||||
|
XFC_CMD_RX_GET_RAW(blockLimit);
|
||||||
|
|
||||||
|
|
||||||
|
name[nameLength] = '\0';
|
||||||
|
tSerialBridge *bridge = SerialBridges_GetForName(env, name, nameLength);
|
||||||
|
|
||||||
|
if (blockLimit > XfcArrayGetSpace(response)) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bridge) {
|
||||||
|
|
||||||
|
uint16_t reedBytes = SerialPortReceive(bridge->serialIo, response->data, blockLimit, 10);
|
||||||
|
if(reedBytes){
|
||||||
|
XfcArrayAddLength(response, reedBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
//
|
||||||
|
// Created by xemon on 09.11.22.
|
||||||
|
//
|
||||||
|
#include "ComIntCmd/SerialBridge.h"
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_SerialBridgeWrite(tXfcArray *request, tXfcArray *response, tSerialBridges *env) {
|
||||||
|
char name[64];
|
||||||
|
uint8_t nameLength;
|
||||||
|
|
||||||
|
XFC_CMD_RX_GET_RAW(nameLength);
|
||||||
|
XFC_CMD_RX_GET_ARR(name, nameLength);
|
||||||
|
|
||||||
|
name[nameLength] = '\0';
|
||||||
|
tSerialBridge *bridge = SerialBridges_GetForName(env, name, nameLength);
|
||||||
|
|
||||||
|
if (bridge) {
|
||||||
|
uint16_t bytesInRequest = XfcArrayGetDataSize(request);
|
||||||
|
|
||||||
|
uint16_t bytesWriten = SerialPortTransmit(
|
||||||
|
bridge->serialIo, request->data + request->begin, bytesInRequest, 100
|
||||||
|
);
|
||||||
|
|
||||||
|
if (bytesWriten == bytesInRequest) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// Created by xemon 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;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// Created by xemon on 09.11.22.
|
||||||
|
//
|
||||||
|
#include "ComIntCmd/SerialBridge.h"
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_SerialBridgeTable(tXfcArray *request, tXfcArray *response, tSerialBridges *table) {
|
||||||
|
|
||||||
|
XFC_CMD_TX_ADD_RAW(table->count);
|
||||||
|
|
||||||
|
uint8_t flagAllowAll = 0xFF;
|
||||||
|
|
||||||
|
for (uint16_t idx = 0; idx < table->count; ++idx) {
|
||||||
|
XFC_CMD_TX_ADD_RAW(table->items[idx].nameLength);
|
||||||
|
XFC_CMD_TX_ADD_ARR(table->items[idx].name, table->items[idx].nameLength);
|
||||||
|
//todo
|
||||||
|
XFC_CMD_TX_ADD_RAW(flagAllowAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"dep": [
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "GONEC_NEW",
|
||||||
|
"repo": "XfcTransportProtocol"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "GONEC_NEW",
|
||||||
|
"repo": "SerialPort"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"Inc"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"Src/**.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue