mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-04 00:50:42 +02:00
moved movefile and writefile to common and avoiding need to send different named files for nios
This commit is contained in:
parent
25eecf7039
commit
c532ecc2e8
@ -8,6 +8,10 @@
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#define TEMP_PROG_FOLDER_NAME "/var/tmp/"
|
||||
#define TEMP_PROG_FOLDER_NAME_ALL_FILES "/var/tmp/*"
|
||||
#define TEMP_PROG_FILE_NAME TEMP_PROG_FOLDER_NAME "tmp.rawbin"
|
||||
|
||||
enum numberMode { DEC, HEX };
|
||||
enum PROGRAM_INDEX { PROGRAM_FPGA, PROGRAM_KERNEL, PROGRAM_SERVER };
|
||||
|
||||
@ -49,4 +53,7 @@ int verifyChecksum(char *mess, char *functionType, char *clientChecksum,
|
||||
MD5_CTX *c, char *msg);
|
||||
int setupDetectorServer(char *mess, char *sname);
|
||||
|
||||
int writeBinaryFile(char* mess, char* fname, char* buffer, const uint64_t filesize);
|
||||
int writeBinaryFile(char *mess, char *fname, char *buffer,
|
||||
const uint64_t filesize, char *errorPrefix);
|
||||
|
||||
int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix);
|
||||
|
@ -8,10 +8,6 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define TEMP_PROG_FOLDER_NAME "/var/tmp/"
|
||||
#define TEMP_PROG_FOLDER_NAME_ALL_FILES "/var/tmp/*"
|
||||
#define TEMP_PROG_FILE_NAME TEMP_PROG_FOLDER_NAME "tmp.rawbin"
|
||||
|
||||
int defineGPIOpins(char *mess);
|
||||
int FPGAdontTouchFlash(char *mess);
|
||||
int FPGATouchFlash(char *mess);
|
||||
@ -37,4 +33,3 @@ int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, FILE *srcfd);
|
||||
/** Notify fpga to pick up firmware from flash and wait for status confirmation
|
||||
*/
|
||||
int waitForFPGAtoTouchFlash(char *mess);
|
||||
int moveBinaryFile(char *mess, char *serverName);
|
||||
|
@ -496,15 +496,15 @@ int setupDetectorServer(char *mess, char *sname) {
|
||||
}
|
||||
|
||||
int writeBinaryFile(char *mess, char *fname, char *buffer,
|
||||
const uint64_t filesize) {
|
||||
const uint64_t filesize, char *errorPrefix) {
|
||||
LOG(logINFO, ("\tWriting Detector Server Binary...\n"));
|
||||
|
||||
FILE *fp = fopen(fname, "wb");
|
||||
if (fp == NULL) {
|
||||
sprintf(mess,
|
||||
"Could not copy detector server. (opening file to write(%s). "
|
||||
"Maybe it is being used? Try another server name?\n",
|
||||
fname);
|
||||
"Could not %s. (opening file to write(%s). "
|
||||
"Maybe it is being used? Try another name?\n",
|
||||
errorPrefix, fname);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@ -532,9 +532,9 @@ int writeBinaryFile(char *mess, char *fname, char *buffer,
|
||||
// write
|
||||
if (bytes != (size_t)writeSize) {
|
||||
sprintf(mess,
|
||||
"Could not copy detector server. Expected to write %lu "
|
||||
"Could not %s. Expected to write %lu "
|
||||
"bytes, wrote %lu bytes). No space left? \n",
|
||||
(long unsigned int)filesize,
|
||||
errorPrefix, (long unsigned int)filesize,
|
||||
(long unsigned int)bytesWritten);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
@ -545,12 +545,35 @@ int writeBinaryFile(char *mess, char *fname, char *buffer,
|
||||
}
|
||||
printf("\n");
|
||||
if (fclose(fp) != 0) {
|
||||
sprintf(mess,
|
||||
"Could not copy detector server. (closing file pointer)\n");
|
||||
sprintf(mess, "Could not %s. (closing file pointer)\n", errorPrefix);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("\tWritten server binary to %s (%lu bytes)\n", fname,
|
||||
LOG(logINFO, ("\tWritten binary to %s (%lu bytes)\n", fname,
|
||||
(long unsigned int)bytesWritten));
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix) {
|
||||
char cmd[MAX_STR_LENGTH] = {0};
|
||||
char retvals[MAX_STR_LENGTH] = {0};
|
||||
|
||||
// one can move into the current process binary (will not interfere in
|
||||
// kernel mode)
|
||||
|
||||
char *format = "mv %s %s";
|
||||
if (snprintf(cmd, MAX_STR_LENGTH, format, src, dest) >= MAX_STR_LENGTH) {
|
||||
sprintf(mess, "Could not %s. Command to move binary is too long\n",
|
||||
errorPrefix);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||
snprintf(mess, MAX_STR_LENGTH, "Could not %s. (moving). %s\n",
|
||||
errorPrefix, retvals);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("\tMoved file from %s to %s\n", src, dest));
|
||||
return OK;
|
||||
}
|
||||
|
@ -574,26 +574,3 @@ int waitForFPGAtoTouchFlash(char *mess) {
|
||||
LOG(logINFO, ("\tFPGA has picked up the program from flash\n"));
|
||||
return OK;
|
||||
}
|
||||
|
||||
int moveBinaryFile(char *mess, char *serverName) {
|
||||
char cmd[MAX_STR_LENGTH] = {0};
|
||||
char retvals[MAX_STR_LENGTH] = {0};
|
||||
|
||||
char *format = "mv %s %s";
|
||||
if (snprintf(cmd, MAX_STR_LENGTH, format, TEMP_PROG_FILE_NAME,
|
||||
serverName) >= MAX_STR_LENGTH) {
|
||||
strcpy(mess, "Could not copy detector server. Command "
|
||||
"to move server binary is too long\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||
snprintf(mess, MAX_STR_LENGTH,
|
||||
"Could not copy detector server (moving). %s\n", retvals);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("\tmoved from temp folder to main with proper name (%s)\n",
|
||||
serverName));
|
||||
return OK;
|
||||
}
|
||||
|
@ -9381,7 +9381,8 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
|
||||
totalsize);
|
||||
break;
|
||||
case PROGRAM_SERVER:
|
||||
ret = moveBinaryFile(mess, serverName);
|
||||
ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME,
|
||||
"update detector server");
|
||||
if (ret == OK) {
|
||||
ret = setupDetectorServer(mess, serverName);
|
||||
}
|
||||
@ -9468,7 +9469,14 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index,
|
||||
#endif
|
||||
#if defined(GOTTHARD2D) || defined(MYTHEN3D) || defined(EIGERD)
|
||||
case PROGRAM_SERVER:
|
||||
ret = writeBinaryFile(mess, serverName, src, filesize);
|
||||
ret = writeBinaryFile(mess, TEMP_PROG_FILE_NAME, src, filesize,
|
||||
"update detector server");
|
||||
// extra step to write to temp and move to real file as
|
||||
// fopen will give text busy if opening same name as process name
|
||||
if (ret == OK) {
|
||||
ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME,
|
||||
"update detector server");
|
||||
}
|
||||
if (ret == OK) {
|
||||
ret = verifyChecksumFromFile(mess, functionType, checksum,
|
||||
serverName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user