Modularization, stage 1
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
This is a template unit, used for reference when creating new units.
|
||||
It is not registered into the unit registry, and cannot be instantiated.
|
||||
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// Created by MightyPork on 2018/02/03.
|
||||
//
|
||||
|
||||
#include "platform.h"
|
||||
#include "unit_base.h"
|
||||
#include "unit_tpl.h"
|
||||
|
||||
#define TPL_INTERNAL
|
||||
#include "_tpl_internal.h"
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by MightyPork on 2018/02/03.
|
||||
//
|
||||
|
||||
#include "platform.h"
|
||||
#include "unit_base.h"
|
||||
|
||||
#define TPL_INTERNAL
|
||||
#include "_tpl_internal.h"
|
||||
|
||||
/** Allocate data structure and set defaults */
|
||||
error_t UTPL_preInit(Unit *unit)
|
||||
{
|
||||
struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv));
|
||||
if (priv == NULL) return E_OUT_OF_MEM;
|
||||
|
||||
//
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
/** Finalize unit set-up */
|
||||
error_t UTPL_init(Unit *unit)
|
||||
{
|
||||
bool suc = true;
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
//
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/** Tear down the unit */
|
||||
void UTPL_deInit(Unit *unit)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
// de-init peripherals
|
||||
if (unit->status == E_SUCCESS ) {
|
||||
//
|
||||
}
|
||||
|
||||
// Release all resources, deinit pins
|
||||
rsc_teardown(unit);
|
||||
|
||||
// Free memory
|
||||
free_ck(unit->data);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by MightyPork on 2018/02/03.
|
||||
//
|
||||
|
||||
#ifndef GEX_F072_TPL_INTERNAL_H
|
||||
#define GEX_F072_TPL_INTERNAL_H
|
||||
|
||||
#ifndef TPL_INTERNAL
|
||||
#error bad include!
|
||||
#endif
|
||||
|
||||
#include "unit_base.h"
|
||||
|
||||
/** Private data structure */
|
||||
struct priv {
|
||||
// settings
|
||||
|
||||
// internal state
|
||||
};
|
||||
|
||||
/** Allocate data structure and set defaults */
|
||||
error_t UTPL_preInit(Unit *unit);
|
||||
|
||||
/** Load from a binary buffer stored in Flash */
|
||||
void UTPL_loadBinary(Unit *unit, PayloadParser *pp);
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
void UTPL_writeBinary(Unit *unit, PayloadBuilder *pb);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Parse a key-value pair from the INI file */
|
||||
error_t UTPL_loadIni(Unit *unit, const char *key, const char *value);
|
||||
|
||||
/** Generate INI file section for the unit */
|
||||
void UTPL_writeIni(Unit *unit, IniWriter *iw);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Finalize unit set-up */
|
||||
error_t UTPL_init(Unit *unit);
|
||||
|
||||
/** Tear down the unit */
|
||||
void UTPL_deInit(Unit *unit);
|
||||
|
||||
#endif //GEX_F072_TPL_INTERNAL_H
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// Created by MightyPork on 2018/02/03.
|
||||
//
|
||||
|
||||
#include "platform.h"
|
||||
#include "unit_base.h"
|
||||
|
||||
#define TPL_INTERNAL
|
||||
#include "_tpl_internal.h"
|
||||
|
||||
/** Load from a binary buffer stored in Flash */
|
||||
void UTPL_loadBinary(Unit *unit, PayloadParser *pp)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
uint8_t version = pp_u8(pp);
|
||||
(void)version;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
void UTPL_writeBinary(Unit *unit, PayloadBuilder *pb)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
pb_u8(pb, 0); // version
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Parse a key-value pair from the INI file */
|
||||
error_t UTPL_loadIni(Unit *unit, const char *key, const char *value)
|
||||
{
|
||||
bool suc = true;
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
if (false) {
|
||||
//
|
||||
}
|
||||
else {
|
||||
return E_BAD_KEY;
|
||||
}
|
||||
|
||||
if (!suc) return E_BAD_VALUE;
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
/** Generate INI file section for the unit */
|
||||
void UTPL_writeIni(Unit *unit, IniWriter *iw)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Enter unit type identifier (empty to cancel):"
|
||||
read x
|
||||
|
||||
if [ -e $x ]; then
|
||||
exit;
|
||||
fi
|
||||
|
||||
xl="${x,,}"
|
||||
xu="${x^^}"
|
||||
|
||||
for f in *.h; do mv -- "$f" "${f//tpl/$xl}"; done
|
||||
for f in *.c; do mv -- "$f" "${f//tpl/$xl}"; done
|
||||
|
||||
sed "s/tpl/$xl/" -i *.h
|
||||
sed "s/TPL/$xu/" -i *.h
|
||||
sed "s/tpl/$xl/" -i *.c
|
||||
sed "s/TPL/$xu/" -i *.c
|
||||
|
||||
echo "Unit $xu set up completed. Removing installer.."
|
||||
rm '!README.TXT'
|
||||
rm $0
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/11/25.
|
||||
//
|
||||
|
||||
#include "unit_base.h"
|
||||
#include "unit_tpl.h"
|
||||
|
||||
#define TPL_INTERNAL
|
||||
#include "_tpl_internal.h"
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
enum TplCmd_ {
|
||||
//
|
||||
};
|
||||
|
||||
/** Handle a request message */
|
||||
static error_t UTPL_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command,
|
||||
PayloadParser *pp)
|
||||
{
|
||||
switch (command) {
|
||||
default:
|
||||
return E_UNKNOWN_COMMAND;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Handle update-tick (if configured in init)
|
||||
*
|
||||
* @param unit
|
||||
*/
|
||||
static void UTPL_updateTick(Unit *unit)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Unit template */
|
||||
const UnitDriver UNIT_TPL = {
|
||||
.name = "TPL",
|
||||
.description = "Template unit",
|
||||
// Settings
|
||||
.preInit = UTPL_preInit,
|
||||
.cfgLoadBinary = UTPL_loadBinary,
|
||||
.cfgWriteBinary = UTPL_writeBinary,
|
||||
.cfgLoadIni = UTPL_loadIni,
|
||||
.cfgWriteIni = UTPL_writeIni,
|
||||
// Init
|
||||
.init = UTPL_init,
|
||||
.deInit = UTPL_deInit,
|
||||
// Function
|
||||
.handleRequest = UTPL_handleRequest,
|
||||
.updateTick = UTPL_updateTick,
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/11/25.
|
||||
//
|
||||
// Digital input unit; single or multiple pin read access on one port (A-F)
|
||||
//
|
||||
|
||||
#ifndef U_TPL_H
|
||||
#define U_TPL_H
|
||||
|
||||
#include "unit.h"
|
||||
|
||||
extern const UnitDriver UNIT_TPL;
|
||||
|
||||
// UU_ prototypes
|
||||
|
||||
#endif //U_TPL_H
|
||||
Reference in New Issue
Block a user