refactor v1

This commit is contained in:
2025-01-10 13:53:27 +01:00
parent 09c7107a07
commit 285ec4b38d
52 changed files with 79 additions and 21 deletions

13
.gitignore vendored
View File

@@ -1,6 +1,7 @@
UnitFirmware/module_rev0/build/* software/firmware_module/module_rev0/build/*
UnitFirmware/module_rev0/build software/firmware_module/module_rev0/build
Server/build/* software/pc_client/build/*
Server/build software/pc_client/build
ModuleController/ModuleController-backups/* hardware/module_controller/ModuleController-backups/*
ModuleController/ModuleController-backups hardware/module_controller/ModuleController-backups
hardware/module_controller/~*.lck

View File

@@ -6,7 +6,7 @@ Notable changes:
* Hot-swappable modules * Hot-swappable modules
* New Backplane * New Backplane
* New PCB, using mostly smd components and an atmega8 mcu. * New PCB, using mostly smd components and an atmega8 mcu.
* RS-485 bus * RS-485 at 19200-Baud, Half-Duplex
* Custom leightweight protocol * Custom leightweight protocol
* Controller, running an WebSockets-Server. * Controller, running an WebSockets-Server.
* Homing-Failure and overcurrent detection * Homing-Failure and overcurrent detection

0
buildtools/git-hook.sh Normal file
View File

View File

@@ -1,4 +1,6 @@
#include "devicemgr.h" #include "devicemgr.h"
#include <json-c/json_object.h>
#include <string.h>
/* /*
* This file provides an abstraction layer to access many devices * This file provides an abstraction layer to access many devices
@@ -8,6 +10,8 @@ enum SFDEVICE_STATE { NEW, OFFLINE, ONLINE, FAILED };
enum SFDEVICE_POWER { DISABLED, ENABLED, UNKNOWN }; enum SFDEVICE_POWER { DISABLED, ENABLED, UNKNOWN };
struct SFDEVICE { struct SFDEVICE {
int pos_x;
int pos_y;
u_int16_t address; u_int16_t address;
int rs485_descriptor; int rs485_descriptor;
double reg_voltage; double reg_voltage;
@@ -20,14 +24,24 @@ struct SFDEVICE {
#define SFDEVICE_MAXDEV 128 #define SFDEVICE_MAXDEV 128
#define SFDEVICE_MAX_X 20
#define SFDEVICE_MAX_Y 4
// next free slot to register device // next free slot to register device
int nextFreeSlot = -1; int nextFreeSlot = -1;
int deviceMap[SFDEVICE_MAX_X][SFDEVICE_MAX_Y];
struct SFDEVICE devices[SFDEVICE_MAXDEV]; struct SFDEVICE devices[SFDEVICE_MAXDEV];
const char* symbols[] = {" ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Ä", "Ö", "Ü", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ".", "-", "?", "!"};
void devicemgr_init() { void devicemgr_init() {
// reserve memory buffer // reserve memory buffer
for (int y = 0; y<SFDEVICE_MAX_Y; y++){
for (int x = 0; x<SFDEVICE_MAX_X; x++){
deviceMap[x][y] = -1; //all empty slots are -1
}
}
} }
int devicemgr_readStatus(int device_id) { int devicemgr_readStatus(int device_id) {
@@ -53,11 +67,30 @@ int devicemgr_readStatus(int device_id) {
} }
} }
json_object * devicemgr_printMap(){
json_object *rows_array = json_object_new_array();
for (int y = 0; y<SFDEVICE_MAX_Y; y++){
json_object *columns_array = json_object_new_array();
for (int x = 0; x<SFDEVICE_MAX_X; x++){
json_object_array_add(columns_array, json_object_new_int(deviceMap[x][y]));
}
json_object_array_add(rows_array,columns_array);
}
return rows_array;
}
json_object * devicemgr_printDetails(int device_id){ json_object * devicemgr_printDetails(int device_id){
// generate json object with status // generate json object with status
json_object *root = json_object_new_object(); json_object *root = json_object_new_object();
json_object_object_add(root, "id", json_object_new_int(device_id)); json_object_object_add(root, "id", json_object_new_int(device_id));
json_object_object_add(root, "address", json_object_new_int(devices[device_id].address)); json_object_object_add(root, "address", json_object_new_int(devices[device_id].address));
json_object_object_add(root, "flapID", json_object_new_int(devices[device_id].current_flap));
json_object_object_add(root, "flapChar", json_object_new_string(symbols[devices[device_id].current_flap]));
json_object *position = json_object_new_object();
json_object_object_add(position, "x", json_object_new_int(devices[device_id].pos_x));
json_object_object_add(position, "y", json_object_new_int(devices[device_id].pos_y));
json_object_object_add(root, "position", position);
json_object *status = json_object_new_object(); json_object *status = json_object_new_object();
json_object_object_add(status, "voltage", json_object_new_double(devices[device_id].reg_voltage)); json_object_object_add(status, "voltage", json_object_new_double(devices[device_id].reg_voltage));
json_object_object_add(status, "rotations", json_object_new_int(devices[device_id].reg_counter)); json_object_object_add(status, "rotations", json_object_new_int(devices[device_id].reg_counter));
@@ -101,6 +134,7 @@ json_object * devicemgr_printDetailsAll(){
if ( devices[i].deviceState == ONLINE ){devices_online++;} if ( devices[i].deviceState == ONLINE ){devices_online++;}
json_object_array_add(devices_arr, devicemgr_printDetails(i)); json_object_array_add(devices_arr, devicemgr_printDetails(i));
} }
json_object_object_add(root, "map", devicemgr_printMap());
json_object_object_add(root, "devices", devices_arr); json_object_object_add(root, "devices", devices_arr);
json_object_object_add(root, "devices_online", json_object_new_int(devices_online)); json_object_object_add(root, "devices_online", json_object_new_int(devices_online));
@@ -108,9 +142,24 @@ json_object * devicemgr_printDetailsAll(){
return root; return root;
} }
void setSingle(int id, u_int8_t flap){
sfbus_display_full(devices[id].rs485_descriptor , devices[id].address,flap);
devices[nextFreeSlot].current_flap = flap;
}
int devicemgr_register(int rs485_descriptor, u_int16_t address) { void printText(char* text,int x,int y){
for (int i = 0; i<strlen(text);i++){
int this_id = deviceMap[x+i][y];
if (this_id >= 0){
setSingle(devices[this_id].address,*(text+i));
}
}
}
int devicemgr_register(int rs485_descriptor, u_int16_t address, int x,int y) {
nextFreeSlot++; nextFreeSlot++;
devices[nextFreeSlot].pos_x = x;
devices[nextFreeSlot].pos_y = y;
devices[nextFreeSlot].address = address; devices[nextFreeSlot].address = address;
devices[nextFreeSlot].rs485_descriptor = rs485_descriptor; devices[nextFreeSlot].rs485_descriptor = rs485_descriptor;
devices[nextFreeSlot].reg_voltage = 0; devices[nextFreeSlot].reg_voltage = 0;
@@ -121,6 +170,12 @@ int devicemgr_register(int rs485_descriptor, u_int16_t address) {
devices[nextFreeSlot].powerState = DISABLED; devices[nextFreeSlot].powerState = DISABLED;
// try to reach device // try to reach device
devicemgr_readStatus(nextFreeSlot); devicemgr_readStatus(nextFreeSlot);
if (deviceMap[x][y] >= 0){ // rest old ones
int old_id = deviceMap[x][y];
devices[old_id].pos_x = -1;
devices[old_id].pos_y = -1;
}
deviceMap[x][y] = nextFreeSlot;
return nextFreeSlot; return nextFreeSlot;
} }

View File

@@ -15,4 +15,5 @@
int devicemgr_readStatus(int device_id) ; int devicemgr_readStatus(int device_id) ;
json_object * devicemgr_printDetails(int device_id); json_object * devicemgr_printDetails(int device_id);
json_object * devicemgr_printDetailsAll(); json_object * devicemgr_printDetailsAll();
int devicemgr_register(int rs485_descriptor, u_int16_t address); int devicemgr_register(int rs485_descriptor, u_int16_t address, int x,int y);
void devicemgr_init();

View File

@@ -67,10 +67,11 @@ int main(int argc, char *argv[]) {
int fd = rs485_init(port, B19200); // setup rs485 int fd = rs485_init(port, B19200); // setup rs485
// test // test
devicemgr_register(fd,0); devicemgr_init();
devicemgr_register(fd,1); devicemgr_register(fd,0,0,0);
devicemgr_register(fd,1,1,0);
devicemgr_printDetailsAll(); devicemgr_printDetailsAll();
exit(1); //exit(1);
if (strcmp(command, "ping") == 0) { if (strcmp(command, "ping") == 0) {
sfbus_ping(fd, addr_int); sfbus_ping(fd, addr_int);