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

@ -527,7 +527,7 @@ void setupDetector() {
LOG(logINFOBLUE, ("Powering down all dacs\n"));
for (int idac = 0; idac < NDAC; ++idac) {
setDAC(idac, LTC2620_GetPowerDownValue(),
0); // has to be before setvchip
0); // has to be before setvchip
}
// power regulators
@ -2339,7 +2339,7 @@ void *start_timer(void *arg) {
// fill data
memcpy(packetData + sizeof(sls_detector_header),
imageData + srcOffset, dataSize);
imageData + srcOffset, dataSize);
srcOffset += dataSize;
sendUDPPacket(0, packetData, packetSize);

View File

@ -748,9 +748,7 @@ void Beb_ResetFrameNumber() {
}
}
void Beb_ClearBebInfos() {
bebInfoSize = 0;
}
void Beb_ClearBebInfos() { bebInfoSize = 0; }
int Beb_InitBebInfos() { // file name at some point
Beb_ClearBebInfos();
@ -814,7 +812,8 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig,
}
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,
"00:00:00:00:00:00", "10.0.0.1", 20000) ||
!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]), 1,
@ -1187,7 +1186,7 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig,
(ten_gig == 1) << 24 | header_size << 14 | 0;
u_int32_t send_frame_command =
0x62000000 | (!test_just_send_out_packets_no_wait) << 27 |
(ten_gig == 1) << 24 | packet_size << 14 | (npackets - 1);
(ten_gig == 1) << 24 | packet_size << 14 | (npackets - 1);
for (int i = 0; i < 10; i++) {
LOG(logDEBUG1,
("%X\n", Beb_Read32(csp0base, (LEFT_OFFSET + i * 4))));

View File

@ -112,7 +112,7 @@ int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
// Just to know: #define PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS 100
for (int i = 0; ((i < PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS) &&
(words_send <= last_word));
(words_send <= last_word));
i++) {
fifo_ctrl = 0;
if (words_send == 0) {

View File

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

View File

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

View File

@ -1789,7 +1789,7 @@ void *start_timer(void *arg) {
// fill data
memcpy(packetData + sizeof(sls_detector_header),
imageData + srcOffset, dataSize);
imageData + srcOffset, dataSize);
srcOffset += dataSize;
sendUDPPacket(0, packetData, packetsize);
@ -1809,7 +1809,7 @@ void *start_timer(void *arg) {
// fill data
memcpy(packetData2 + sizeof(sls_detector_header),
imageData + srcOffset2, dataSize);
imageData + srcOffset2, dataSize);
srcOffset2 += dataSize;
sendUDPPacket(1, packetData2, packetsize);

View File

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

View File

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

View File

@ -1,197 +1,184 @@
#include <errno.h>
#include <fcntl.h>
#include <signal.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 <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"
#ifdef DEBUG
#define DEBUG_PRINT(fmt, args...) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, \
__FILE__, __LINE__, __func__, ##args)
#define DEBUG_PRINT(fmt, args...) \
fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, \
##args)
#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
struct termios oldtio;
int uart;
int update_files = 1;
void intHandler(int signo)
{
DEBUG_PRINT("signo %d received\n", signo);
if (signo == SIGINT)
{
DEBUG_PRINT("SIGINT handling\n");
tcsetattr(uart,TCSANOW,&oldtio);
close(uart);
exit(0);
}
if (signo == SIGUSR1)
{
DEBUG_PRINT("SIGUSR1 handling\n");
update_files = 1;
}
void intHandler(int signo) {
DEBUG_PRINT("signo %d received\n", signo);
if (signo == SIGINT) {
DEBUG_PRINT("SIGINT handling\n");
tcsetattr(uart, TCSANOW, &oldtio);
close(uart);
exit(0);
}
if (signo == SIGUSR1) {
DEBUG_PRINT("SIGUSR1 handling\n");
update_files = 1;
}
}
void kill_servers()
{
system("killall gotthard2DetectorServer mythen3DetectorServer gotthard2DetectorServer_developer mythen3DetectorServer_developer");
void kill_servers() {
system("killall gotthard2DetectorServer mythen3DetectorServer "
"gotthard2DetectorServer_developer mythen3DetectorServer_developer");
}
void set_hv_zero()
{
FILE* hv;
hv = fopen("/etc/devlinks/hvdac", "w");
if (hv == NULL)
fprintf(stderr, "Could not open hvdac file.\n");
else
{
fputc('0', hv);
fclose(hv);
}
void set_hv_zero() {
FILE *hv;
hv = fopen("/etc/devlinks/hvdac", "w");
if (hv == NULL)
fprintf(stderr, "Could not open hvdac file.\n");
else {
fputc('0', hv);
fclose(hv);
}
}
void disable_chip_power()
{
unsigned* mem_ptr;
unsigned mem_val;
unsigned mem_address = 0x18040000;
int mem_desc;
mem_desc = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (mem_desc == -1)
fprintf(stderr, "Cannot open /dev/mem\n");
else
{
mem_ptr = (unsigned *) mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mem_desc, mem_address);
if (mem_ptr == MAP_FAILED)
fprintf(stderr, "Cannot map memory area\n");
else
{
mem_val = mem_ptr[0x84/4];
mem_val = mem_val & 0x7FFFFFFF; // Removes top bit
mem_ptr[0x84/4] = mem_val;
munmap((unsigned*) mem_address, 0x1000);
}
close(mem_desc);
}
void disable_chip_power() {
unsigned *mem_ptr;
unsigned mem_val;
unsigned mem_address = 0x18040000;
int mem_desc;
mem_desc = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (mem_desc == -1)
fprintf(stderr, "Cannot open /dev/mem\n");
else {
mem_ptr =
(unsigned *)mmap(0, 0x1000, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, mem_desc, mem_address);
if (mem_ptr == MAP_FAILED)
fprintf(stderr, "Cannot map memory area\n");
else {
mem_val = mem_ptr[0x84 / 4];
mem_val = mem_val & 0x7FFFFFFF; // Removes top bit
mem_ptr[0x84 / 4] = mem_val;
munmap((unsigned *)mem_address, 0x1000);
}
close(mem_desc);
}
}
void prepare_for_shutdown()
{
kill_servers();
set_hv_zero();
disable_chip_power();
system("sync");
return;
void prepare_for_shutdown() {
kill_servers();
set_hv_zero();
disable_chip_power();
system("sync");
return;
}
int uart_setup(struct termios* old_settings)
{
int desc;
struct termios newtio;
desc = open(UART_DEVICE, O_RDWR | O_NOCTTY);
if (desc < 0) { perror(UART_DEVICE); exit(-1); }
tcgetattr(desc, old_settings);
newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | IGNCR | IXANY;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;
tcflush(desc, TCIFLUSH);
tcsetattr(desc,TCSANOW,&newtio);
return desc;
int uart_setup(struct termios *old_settings) {
int desc;
struct termios newtio;
desc = open(UART_DEVICE, O_RDWR | O_NOCTTY);
if (desc < 0) {
perror(UART_DEVICE);
exit(-1);
}
tcgetattr(desc, old_settings);
newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | IGNCR | IXANY;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;
tcflush(desc, TCIFLUSH);
tcsetattr(desc, TCSANOW, &newtio);
return desc;
}
int get_boot_condition()
{
FILE* ru_trig_cond;
char ru_trig_cond_content[10];
int bytes_read;
int get_boot_condition() {
FILE *ru_trig_cond;
char ru_trig_cond_content[10];
int bytes_read;
ru_trig_cond = fopen("/sys/devices/platform/sopc@0/18000000.bridge/180000c0.remoteupdate/remote_update/trig_cond","r");
if (ru_trig_cond == NULL)
fprintf(stderr, "Cannot read remote update status\n");
bytes_read = fread(ru_trig_cond_content, 1, 10, ru_trig_cond);
if (bytes_read < 4)
fprintf(stderr, "Invalid file content\n");
return strtoul(ru_trig_cond_content, NULL, 0);
ru_trig_cond = fopen("/sys/devices/platform/sopc@0/18000000.bridge/"
"180000c0.remoteupdate/remote_update/trig_cond",
"r");
if (ru_trig_cond == NULL)
fprintf(stderr, "Cannot read remote update status\n");
bytes_read = fread(ru_trig_cond_content, 1, 10, ru_trig_cond);
if (bytes_read < 4)
fprintf(stderr, "Invalid file content\n");
return strtoul(ru_trig_cond_content, NULL, 0);
}
void write_cmd_in_file(char* cmd, char* filename, int lines)
{
int res,i;
char buf[255];
FILE* cmd_file;
cmd_file = fopen(filename, "w");
write(uart, cmd, 1);
for (i=0; i < lines; i++)
{
res = read(uart, buf, 255);
fwrite(buf, 1, res, cmd_file);
}
fclose(cmd_file);
void write_cmd_in_file(char *cmd, char *filename, int lines) {
int res, i;
char buf[255];
FILE *cmd_file;
cmd_file = fopen(filename, "w");
write(uart, cmd, 1);
for (i = 0; i < lines; i++) {
res = read(uart, buf, 255);
fwrite(buf, 1, res, cmd_file);
}
fclose(cmd_file);
}
int main(int argc, char *argv[]) {
char buf[255];
fd_set readfs;
int maxfd;
int res;
char factory_image_detected_cmd = 'f';
char get_voltage_cmd = 'u';
char get_versions_cmd = 'v';
char get_eventlog_cmd = 'e';
int main(int argc, char* argv[])
{
char buf[255];
fd_set readfs;
int maxfd;
int res;
char factory_image_detected_cmd = 'f';
char get_voltage_cmd = 'u';
char get_versions_cmd = 'v';
char get_eventlog_cmd = 'e';
uart = uart_setup(&oldtio);
signal(SIGINT, intHandler);
signal(SIGUSR1, intHandler);
uart = uart_setup(&oldtio);
signal(SIGINT, intHandler);
signal(SIGUSR1, intHandler);
maxfd = uart + 1;
maxfd = uart+1;
if (get_boot_condition() != 4)
write(uart, &factory_image_detected_cmd, 1);
if (get_boot_condition() != 4)
write(uart, &factory_image_detected_cmd, 1);
while (1) {
if (update_files == 1) {
DEBUG_PRINT("Updating files...\n");
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_eventlog_cmd, "/tmp/uc_eventlog", 16);
update_files = 0;
}
FD_SET(uart, &readfs);
res = select(maxfd, &readfs, NULL, NULL, NULL);
if ((res == -1) && (errno == EINTR)) // If SIGUSR1 occured
continue;
if (FD_ISSET(uart, &readfs)) {
res = read(uart, buf, 255);
buf[res] = 0;
DEBUG_PRINT("-->%s:%d<--", buf, res);
if ((buf[0] == 'S') && (res < 5)) {
prepare_for_shutdown();
exit(0);
}
}
usleep(1000);
}
// Should never get here
tcsetattr(uart, TCSANOW, &oldtio);
while (1)
{
if (update_files == 1)
{
DEBUG_PRINT("Updating files...\n");
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_eventlog_cmd, "/tmp/uc_eventlog", 16);
update_files = 0;
}
FD_SET(uart, &readfs);
res = select(maxfd, &readfs, NULL, NULL, NULL);
if ((res == -1) && (errno == EINTR)) // If SIGUSR1 occured
continue;
if (FD_ISSET(uart,&readfs))
{
res = read(uart, buf, 255);
buf[res] = 0;
DEBUG_PRINT("-->%s:%d<--", buf, res);
if ((buf[0] == 'S') && (res < 5))
{
prepare_for_shutdown();
exit(0);
}
}
usleep(1000);
}
// Should never get here
tcsetattr(uart,TCSANOW,&oldtio);
return 0;
return 0;
}

View File

@ -674,7 +674,7 @@ void DetectorImpl::readFrameFromReceiver() {
// free resources
delete[] image;
delete[] multiframe;
delete[] multiframe;
delete[] multigappixels;
}

View File

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

View File

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

View File

@ -264,10 +264,10 @@ ToString(const T &obj) {
}
template <typename T>
std::vector<T> StringTo(const std::vector<std::string>& strings){
std::vector<T> StringTo(const std::vector<std::string> &strings) {
std::vector<T> result;
result.reserve(strings.size());
for (const auto& s : strings)
for (const auto &s : strings)
result.push_back(StringTo<T>(s));
return result;
}

View File

@ -3,10 +3,10 @@
#define APILIB 0x200409
#define APIRECEIVER 0x200409
#define APIGUI 0x200409
#define APIEIGER 0x200610
#define APICTB 0x200610
#define APIGOTTHARD 0x200610
#define APIEIGER 0x200610
#define APICTB 0x200610
#define APIGOTTHARD 0x200610
#define APIGOTTHARD2 0x200610
#define APIJUNGFRAU 0x200610
#define APIMYTHEN3 0x200610
#define APIMOENCH 0x200610
#define APIJUNGFRAU 0x200610
#define APIMYTHEN3 0x200610
#define APIMOENCH 0x200610

View File

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

View File

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