formatting

This commit is contained in:
maliakal_d 2020-06-10 17:29:28 +02:00
parent 200186ddde
commit ab72d342c9
16 changed files with 188 additions and 207 deletions

View File

@ -748,9 +748,7 @@ void Beb_ResetFrameNumber() {
} }
} }
void Beb_ClearBebInfos() { void Beb_ClearBebInfos() { bebInfoSize = 0; }
bebInfoSize = 0;
}
int Beb_InitBebInfos() { // file name at some point int Beb_InitBebInfos() { // file name at some point
Beb_ClearBebInfos(); Beb_ClearBebInfos();
@ -814,7 +812,8 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig,
} }
int Beb_CheckSourceStuffBebInfo() { int Beb_CheckSourceStuffBebInfo() {
for (unsigned int i = 1; i < bebInfoSize; i++) { // header stuff always starts from 1 for (unsigned int i = 1; i < bebInfoSize;
i++) { // header stuff always starts from 1
if (!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]), 0, if (!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]), 0,
"00:00:00:00:00:00", "10.0.0.1", 20000) || "00:00:00:00:00:00", "10.0.0.1", 20000) ||
!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]), 1, !Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]), 1,

View File

@ -1019,8 +1019,7 @@ int setModule(sls_detector_module myMod, char *mess) {
for (int i = 0; i < NDAC; ++i) { for (int i = 0; i < NDAC; ++i) {
setDAC((enum DACINDEX)i, myMod.dacs[i], 0); setDAC((enum DACINDEX)i, myMod.dacs[i], 0);
if (myMod.dacs[i] != (detectorModules)->dacs[i]) { if (myMod.dacs[i] != (detectorModules)->dacs[i]) {
sprintf(mess, "Could not set module. Could not set dac %d\n", sprintf(mess, "Could not set module. Could not set dac %d\n", i);
i);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
setSettings(UNDEFINED); setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined\n")); LOG(logERROR, ("Settings has been changed to undefined\n"));
@ -2139,7 +2138,8 @@ void *start_timer(void *arg) {
// loop packet // loop packet
{ {
int i = 0; i != numPacketsPerFrame; ++i) { int i = 0;
i != numPacketsPerFrame; ++i) {
// set header // set header
char packetData[packetsize]; char packetData[packetsize];
memset(packetData, 0, packetsize); memset(packetData, 0, packetsize);
@ -2170,7 +2170,8 @@ void *start_timer(void *arg) {
int dstOffset = sizeof(sls_detector_header); int dstOffset = sizeof(sls_detector_header);
int dstOffset2 = sizeof(sls_detector_header); int dstOffset2 = sizeof(sls_detector_header);
{ {
for (int psize = 0; psize < datasize; psize += npixelsx) { for (int psize = 0; psize < datasize;
psize += npixelsx) {
if (dr == 32 && tgEnable == 0) { if (dr == 32 && tgEnable == 0) {
memcpy(packetData + dstOffset, memcpy(packetData + dstOffset,

View File

@ -1113,11 +1113,11 @@ int getADC(enum ADCINDEX ind) {
// only the first time // only the first time
if (i <= 10) { if (i <= 10) {
if (ind == TEMP_ADC) if (ind == TEMP_ADC)
value = (value << 1) + value =
(bus_r(addrout) & TEMP_SPI_OUT_T1_DT_MSK); (value << 1) + (bus_r(addrout) & TEMP_SPI_OUT_T1_DT_MSK);
else else
value = (value << 1) + value =
(bus_r(addrout) & TEMP_SPI_OUT_T2_DT_MSK); (value << 1) + (bus_r(addrout) & TEMP_SPI_OUT_T2_DT_MSK);
} }
} }

View File

@ -1962,8 +1962,7 @@ void *start_timer(void *arg) {
// set header // set header
char packetData[packetSize]; char packetData[packetSize];
memset(packetData, 0, packetSize); memset(packetData, 0, packetSize);
sls_detector_header *header = sls_detector_header *header = (sls_detector_header *)(packetData);
(sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType; header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr; header->frameNumber = frameNr;
@ -1981,8 +1980,8 @@ void *start_timer(void *arg) {
} }
LOG(logINFO, ("Sent frame: %d\n", frameNr)); LOG(logINFO, ("Sent frame: %d\n", frameNr));
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + int64_t timeNs =
(end.tv_nsec - begin.tv_nsec)); ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime) // sleep for (period - exptime)
if (frameNr < numFrames) { // if there is a next frame if (frameNr < numFrames) { // if there is a next frame

View File

@ -76,8 +76,8 @@ int main(int argc, char *argv[]) {
return -1; return -1;
} }
if (sscanf(argv[i + 1], "%d", &portno) == 0) { if (sscanf(argv[i + 1], "%d", &portno) == 0) {
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", LOG(logERROR,
argv[i + 1])); ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
return -1; return -1;
} }
LOG(logINFO, ("Detected port: %d\n", portno)); LOG(logINFO, ("Detected port: %d\n", portno));
@ -89,8 +89,7 @@ int main(int argc, char *argv[]) {
return -1; return -1;
} }
if (sscanf(argv[i + 1], "%d", &phaseShift) == 0) { if (sscanf(argv[i + 1], "%d", &phaseShift) == 0) {
LOG(logERROR, LOG(logERROR, ("cannot decode phase shift value %s. Exiting.\n",
("cannot decode phase shift value %s. Exiting.\n",
argv[i + 1])); argv[i + 1]));
return -1; return -1;
} }

View File

@ -1,20 +1,21 @@
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <signal.h>
#include <errno.h>
#define UART_DEVICE "/dev/ttyAL0" #define UART_DEVICE "/dev/ttyAL0"
#ifdef DEBUG #ifdef DEBUG
#define DEBUG_PRINT(fmt, args...) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, \ #define DEBUG_PRINT(fmt, args...) \
__FILE__, __LINE__, __func__, ##args) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, \
##args)
#else #else
#define DEBUG_PRINT(fmt, args...) /* Don't do anything in release builds */ #define DEBUG_PRINT(fmt, args...) /* Don't do anything in release builds */
#endif #endif
@ -23,43 +24,37 @@ struct termios oldtio;
int uart; int uart;
int update_files = 1; int update_files = 1;
void intHandler(int signo) void intHandler(int signo) {
{
DEBUG_PRINT("signo %d received\n", signo); DEBUG_PRINT("signo %d received\n", signo);
if (signo == SIGINT) if (signo == SIGINT) {
{
DEBUG_PRINT("SIGINT handling\n"); DEBUG_PRINT("SIGINT handling\n");
tcsetattr(uart, TCSANOW, &oldtio); tcsetattr(uart, TCSANOW, &oldtio);
close(uart); close(uart);
exit(0); exit(0);
} }
if (signo == SIGUSR1) if (signo == SIGUSR1) {
{
DEBUG_PRINT("SIGUSR1 handling\n"); DEBUG_PRINT("SIGUSR1 handling\n");
update_files = 1; update_files = 1;
} }
} }
void kill_servers() void kill_servers() {
{ system("killall gotthard2DetectorServer mythen3DetectorServer "
system("killall gotthard2DetectorServer mythen3DetectorServer gotthard2DetectorServer_developer mythen3DetectorServer_developer"); "gotthard2DetectorServer_developer mythen3DetectorServer_developer");
} }
void set_hv_zero() void set_hv_zero() {
{
FILE *hv; FILE *hv;
hv = fopen("/etc/devlinks/hvdac", "w"); hv = fopen("/etc/devlinks/hvdac", "w");
if (hv == NULL) if (hv == NULL)
fprintf(stderr, "Could not open hvdac file.\n"); fprintf(stderr, "Could not open hvdac file.\n");
else else {
{
fputc('0', hv); fputc('0', hv);
fclose(hv); fclose(hv);
} }
} }
void disable_chip_power() void disable_chip_power() {
{
unsigned *mem_ptr; unsigned *mem_ptr;
unsigned mem_val; unsigned mem_val;
unsigned mem_address = 0x18040000; unsigned mem_address = 0x18040000;
@ -67,13 +62,13 @@ void disable_chip_power()
mem_desc = open("/dev/mem", O_RDWR | O_SYNC, 0); mem_desc = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (mem_desc == -1) if (mem_desc == -1)
fprintf(stderr, "Cannot open /dev/mem\n"); fprintf(stderr, "Cannot open /dev/mem\n");
else else {
{ mem_ptr =
mem_ptr = (unsigned *) mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mem_desc, mem_address); (unsigned *)mmap(0, 0x1000, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, mem_desc, mem_address);
if (mem_ptr == MAP_FAILED) if (mem_ptr == MAP_FAILED)
fprintf(stderr, "Cannot map memory area\n"); fprintf(stderr, "Cannot map memory area\n");
else else {
{
mem_val = mem_ptr[0x84 / 4]; mem_val = mem_ptr[0x84 / 4];
mem_val = mem_val & 0x7FFFFFFF; // Removes top bit mem_val = mem_val & 0x7FFFFFFF; // Removes top bit
mem_ptr[0x84 / 4] = mem_val; mem_ptr[0x84 / 4] = mem_val;
@ -83,8 +78,7 @@ void disable_chip_power()
} }
} }
void prepare_for_shutdown() void prepare_for_shutdown() {
{
kill_servers(); kill_servers();
set_hv_zero(); set_hv_zero();
disable_chip_power(); disable_chip_power();
@ -92,12 +86,14 @@ void prepare_for_shutdown()
return; return;
} }
int uart_setup(struct termios* old_settings) int uart_setup(struct termios *old_settings) {
{
int desc; int desc;
struct termios newtio; struct termios newtio;
desc = open(UART_DEVICE, O_RDWR | O_NOCTTY); desc = open(UART_DEVICE, O_RDWR | O_NOCTTY);
if (desc < 0) { perror(UART_DEVICE); exit(-1); } if (desc < 0) {
perror(UART_DEVICE);
exit(-1);
}
tcgetattr(desc, old_settings); tcgetattr(desc, old_settings);
newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD; newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | IGNCR | IXANY; newtio.c_iflag = IGNPAR | IGNCR | IXANY;
@ -108,13 +104,14 @@ int uart_setup(struct termios* old_settings)
return desc; return desc;
} }
int get_boot_condition() int get_boot_condition() {
{
FILE *ru_trig_cond; FILE *ru_trig_cond;
char ru_trig_cond_content[10]; char ru_trig_cond_content[10];
int bytes_read; int bytes_read;
ru_trig_cond = fopen("/sys/devices/platform/sopc@0/18000000.bridge/180000c0.remoteupdate/remote_update/trig_cond","r"); ru_trig_cond = fopen("/sys/devices/platform/sopc@0/18000000.bridge/"
"180000c0.remoteupdate/remote_update/trig_cond",
"r");
if (ru_trig_cond == NULL) if (ru_trig_cond == NULL)
fprintf(stderr, "Cannot read remote update status\n"); fprintf(stderr, "Cannot read remote update status\n");
bytes_read = fread(ru_trig_cond_content, 1, 10, ru_trig_cond); bytes_read = fread(ru_trig_cond_content, 1, 10, ru_trig_cond);
@ -123,24 +120,20 @@ int get_boot_condition()
return strtoul(ru_trig_cond_content, NULL, 0); return strtoul(ru_trig_cond_content, NULL, 0);
} }
void write_cmd_in_file(char* cmd, char* filename, int lines) void write_cmd_in_file(char *cmd, char *filename, int lines) {
{
int res, i; int res, i;
char buf[255]; char buf[255];
FILE *cmd_file; FILE *cmd_file;
cmd_file = fopen(filename, "w"); cmd_file = fopen(filename, "w");
write(uart, cmd, 1); write(uart, cmd, 1);
for (i=0; i < lines; i++) for (i = 0; i < lines; i++) {
{
res = read(uart, buf, 255); res = read(uart, buf, 255);
fwrite(buf, 1, res, cmd_file); fwrite(buf, 1, res, cmd_file);
} }
fclose(cmd_file); fclose(cmd_file);
} }
int main(int argc, char *argv[]) {
int main(int argc, char* argv[])
{
char buf[255]; char buf[255];
fd_set readfs; fd_set readfs;
int maxfd; int maxfd;
@ -159,12 +152,8 @@ int main(int argc, char* argv[])
if (get_boot_condition() != 4) if (get_boot_condition() != 4)
write(uart, &factory_image_detected_cmd, 1); write(uart, &factory_image_detected_cmd, 1);
while (1) {
if (update_files == 1) {
while (1)
{
if (update_files == 1)
{
DEBUG_PRINT("Updating files...\n"); DEBUG_PRINT("Updating files...\n");
write_cmd_in_file(&get_voltage_cmd, "/tmp/uc_voltage", 1); write_cmd_in_file(&get_voltage_cmd, "/tmp/uc_voltage", 1);
write_cmd_in_file(&get_versions_cmd, "/tmp/uc_versions", 2); write_cmd_in_file(&get_versions_cmd, "/tmp/uc_versions", 2);
@ -176,13 +165,11 @@ int main(int argc, char* argv[])
if ((res == -1) && (errno == EINTR)) // If SIGUSR1 occured if ((res == -1) && (errno == EINTR)) // If SIGUSR1 occured
continue; continue;
if (FD_ISSET(uart,&readfs)) if (FD_ISSET(uart, &readfs)) {
{
res = read(uart, buf, 255); res = read(uart, buf, 255);
buf[res] = 0; buf[res] = 0;
DEBUG_PRINT("-->%s:%d<--", buf, res); DEBUG_PRINT("-->%s:%d<--", buf, res);
if ((buf[0] == 'S') && (res < 5)) if ((buf[0] == 'S') && (res < 5)) {
{
prepare_for_shutdown(); prepare_for_shutdown();
exit(0); exit(0);
} }

View File

@ -153,15 +153,16 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
// create master file // create master file
if (!(*overWriteEnable)) { if (!(*overWriteEnable)) {
if (nullptr == (masterfd = fopen((const char *)masterFileName.c_str(), if (nullptr == (masterfd = fopen(
"wx"))) { (const char *)masterFileName.c_str(), "wx"))) {
masterfd = nullptr; masterfd = nullptr;
throw sls::RuntimeError("Could not create binary master file " throw sls::RuntimeError("Could not create binary master file "
"(without overwrite enable) " + "(without overwrite enable) " +
masterFileName); masterFileName);
} }
} else if (nullptr == (masterfd = fopen( } else if (nullptr ==
(const char *)masterFileName.c_str(), "w"))) { (masterfd =
fopen((const char *)masterFileName.c_str(), "w"))) {
masterfd = nullptr; masterfd = nullptr;
throw sls::RuntimeError("Could not create binary master file " throw sls::RuntimeError("Could not create binary master file "
"(with overwrite enable) " + "(with overwrite enable) " +

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "TypeTraits.h"
#include "ToString.h" #include "ToString.h"
#include "TypeTraits.h"
#include <array> #include <array>
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
@ -189,7 +189,4 @@ std::ostream &operator<<(std::ostream &os,
return os << ToString(c); return os << ToString(c);
} }
} // namespace sls } // namespace sls

View File

@ -3,8 +3,8 @@
#include "catch.hpp" #include "catch.hpp"
#include <array> #include <array>
#include <vector>
#include <sstream> #include <sstream>
#include <vector>
using sls::StaticVector; using sls::StaticVector;
TEST_CASE("StaticVector is a container") { TEST_CASE("StaticVector is a container") {

View File

@ -31,7 +31,6 @@ TEST_CASE("copy a long string") {
} }
#endif #endif
TEST_CASE("split a string with end delimiter") { TEST_CASE("split a string with end delimiter") {
std::string s("abra+kadabra+"); std::string s("abra+kadabra+");
auto r = sls::split(s, '+'); auto r = sls::split(s, '+');
@ -49,7 +48,6 @@ TEST_CASE("split a string without end delimiter") {
REQUIRE(r[2] == "filibom"); REQUIRE(r[2] == "filibom");
} }
TEST_CASE("Remove char from string") { TEST_CASE("Remove char from string") {
char str[] = "sometest"; char str[] = "sometest";
sls::removeChar(str, 'e'); sls::removeChar(str, 'e');