cueOS  2.4
cueOS - Universal Show Control OS for ARM
DMX512_fixture_pool.c
1/***============================================================================================================================
2 * Dependencies inclusion
3 * Necessary dependencies should be declared here. Header file should contain as little dependecies declarations as possible
4 *=============================================================================================================================*/
5
6#include "cueos_config.h"
7#if cueOS_CONFIG_NODETYPE == cueOS_NODETYPE_SLAVE_DMX
8#include <stdlib.h>
9#include <string.h>
10#include "cmsis_os.h"
11#include "DMX512_fixture_pool.h"
12
13
14/***============================================================================================================================
15 * Private functions definitions
16 * These functions are only accessible from within the file's scope
17 *=============================================================================================================================*/
18
27static int16_t _DMX512_fixture_pool_search(DMX512_fixture_pool_s *fixture_pool, uint16_t id){
28 for(uint16_t i=0; i<fixture_pool->fixture_count; i++){
29 if(id == fixture_pool->fixtures[i].id){
30 return i;
31 }
32 }
33 return -1;
34}
35
42static uint8_t _DMX512_fixture_pool_check(DMX512_fixture_pool_s *fixture_pool, DMX512_fixture_s fixture){
43
45
46 if(_DMX512_fixture_pool_search(fixture_pool, fixture.id) >= 0 ){
48 }else if(fixture.ch_stop > DMX512_CHANNEL_ADDRESS_MAX){
50 }else{
51 for(uint16_t i=0; i<fixture_pool->fixture_count; i++){
52 if(fixture.addr <= fixture_pool->fixtures[i].ch_stop &&
53 fixture_pool->fixtures[i].addr <= fixture.ch_count + fixture.addr - 1){
55 }
56 }
57 }
58
59 return err;
60
61}
62
63
64/***============================================================================================================================
65 * Public functions definitions
66 * These functions can be accessed outside of the file's scope
67 * @see DMX512_fixture_pool.h for declarations
68 *=============================================================================================================================*/
69
76 DMX512_fixture_pool_s *fixture_pool = pvPortMalloc(sizeof(DMX512_fixture_pool_s));
77 fixture_pool->fixtures = NULL;
78 fixture_pool->fixture_count = 0;
79 return fixture_pool;
80}
81
90
91 //TODO: check if fixture instance is valid first
92 DMX512_engine_err_e err = _DMX512_fixture_pool_check(fixture_pool, fixture);
93
94 if(err == DMX512_ENGINE_OK){
95 fixture_pool->fixtures = (DMX512_fixture_s*) pvPortRealloc(fixture_pool->fixtures, sizeof(DMX512_fixture_s) * (fixture_pool->fixture_count + 1));
96 fixture_pool->fixtures[fixture_pool->fixture_count] = fixture;
97 fixture_pool->fixture_count++;
98 }
99
100 return err;
101
102}
103
111
113 int16_t index = _DMX512_fixture_pool_search(fixture_pool, id);
114
115 if(index >= 0){
116 for(uint16_t i=index+1; i< fixture_pool->fixture_count; i++){
117 fixture_pool->fixtures[i-1] = fixture_pool->fixtures[i];
118 }
119 fixture_pool->fixture_count--;
120 fixture_pool->fixtures = pvPortRealloc(fixture_pool->fixtures, sizeof(DMX512_fixture_s) * (fixture_pool->fixture_count));
121 err = DMX512_ENGINE_OK;
122 }
123
124 return err;
125
126}
127
137
139
140 int16_t index = _DMX512_fixture_pool_search(fixture_pool, id);
141
142 if(index >= 0){
143 *fixture = &fixture_pool->fixtures[index];
144 err = DMX512_ENGINE_OK;
145 }
146
147 return err;
148
149}
150
157 vPortFree(fixture_pool->fixtures);
158 vPortFree(fixture_pool);
159}
160
161#endif
#define DMX512_CHANNEL_ADDRESS_MAX
DMX512 max channel address.
Definition: DMX512_defs.h:13
DMX512_engine_err_e
DMX512 engine error index constants.
Definition: DMX512_defs.h:24
@ DMX512_ENGINE_INSTANCE_UNDEFINED
Definition: DMX512_defs.h:28
@ DMX512_ENGINE_INSTANCE_DUPLICATE
Definition: DMX512_defs.h:26
@ DMX512_ENGINE_OK
Definition: DMX512_defs.h:25
@ DMX512_ENGINE_INSTANCE_INVALID
Definition: DMX512_defs.h:27
void DMX512_fixture_pool_free(DMX512_fixture_pool_s *fixture_pool)
Frees instance pool.
DMX512_engine_err_e DMX512_fixture_pool_del(DMX512_fixture_pool_s *fixture_pool, uint16_t id)
Deletes a fixture instance from the pool.
DMX512_fixture_pool_s * DMX512_fixture_pool_new(void)
Creates a new fixture pool instance.
DMX512_engine_err_e DMX512_fixture_pool_add(DMX512_fixture_pool_s *fixture_pool, DMX512_fixture_s fixture)
Adds a fixture instance into the pool.
DMX512_engine_err_e DMX512_fixture_pool_get(DMX512_fixture_pool_s *fixture_pool, uint16_t id, DMX512_fixture_s **fixture)
Gets a fixture instance from the pool.
DMX512 fixture pool structure object.
DMX512_fixture_s * fixtures
DMX512 fixture structure object.
uint16_t ch_stop
uint16_t ch_count