mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
execute command used properly
This commit is contained in:
@ -7,8 +7,8 @@
|
|||||||
#include "slsDetectorServer_defs.h"
|
#include "slsDetectorServer_defs.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h> // usleep
|
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
#include <unistd.h> // usleep
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@ -18,7 +18,7 @@
|
|||||||
#define FLASH_BUFFER_MEMORY_SIZE (128 * 1024) // 500 KB
|
#define FLASH_BUFFER_MEMORY_SIZE (128 * 1024) // 500 KB
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
#define FLASH_DRIVE_NAME_SIZE 16
|
#define FLASH_DRIVE_NAME_SIZE 16
|
||||||
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
||||||
int gpioDefined = 0;
|
int gpioDefined = 0;
|
||||||
|
|
||||||
@ -71,16 +71,25 @@ void resetFPGA() {
|
|||||||
int deleteOldFile(char *mess) {
|
int deleteOldFile(char *mess) {
|
||||||
char cmd[MAX_STR_LENGTH] = {0};
|
char cmd[MAX_STR_LENGTH] = {0};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
sprintf(cmd, "rm -fr %s", TEMP_PROG_FILE_NAME);
|
|
||||||
if (FAIL == executeCommand(cmd, retvals, logDEBUG1)) {
|
char *format = "rm -fr %s";
|
||||||
strcpy(mess,
|
if (snprintf(cmd, MAX_STR_LENGTH, format, TEMP_PROG_FILE_NAME) >=
|
||||||
"Could not program fpga. (could not delete old file: ");
|
MAX_STR_LENGTH) {
|
||||||
strncat(mess, retvals, MAX_STR_LENGTH - strlen(mess) - 1);
|
sptrcpy(
|
||||||
strcat(mess, "\n");
|
mess,
|
||||||
|
"Could not program fpga. Command to delete old file is too long\n");
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("\tDeleted old programming file (%s)\n", TEMP_PROG_FILE_NAME));
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
|
"Could not program fpga. (could not delete old file: %s)\n",
|
||||||
|
retvals);
|
||||||
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
LOG(logINFO,
|
||||||
|
("\tDeleted old programming file (%s)\n", TEMP_PROG_FILE_NAME));
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,12 +151,11 @@ int copyToFlash(ssize_t fsize, char *clientChecksum, char *mess) {
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ignoring this until a consistent way to read from bfin flash
|
/* ignoring this until a consistent way to read from bfin flash
|
||||||
if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) ==
|
if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize)
|
||||||
FAIL) {
|
== FAIL) { return FAIL;
|
||||||
return FAIL;
|
}
|
||||||
}
|
*/
|
||||||
*/
|
|
||||||
if (waitForFPGAtoTouchFlash(mess) == FAIL) {
|
if (waitForFPGAtoTouchFlash(mess) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -171,12 +179,13 @@ int getDrive(char *mess) {
|
|||||||
|
|
||||||
char cmd[MAX_STR_LENGTH] = {0};
|
char cmd[MAX_STR_LENGTH] = {0};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
|
|
||||||
strcpy(cmd, CMD_GET_FLASH);
|
strcpy(cmd, CMD_GET_FLASH);
|
||||||
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
strcpy(mess, "Could not program fpga. (could not get flash drive: ");
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1);
|
"Could not program fpga. (could not get flash drive: %s)\n",
|
||||||
strcat(mess, "\n");
|
retvals);
|
||||||
LOG(logERROR, (mess));
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,15 +239,22 @@ int eraseFlash(char *mess) {
|
|||||||
#endif
|
#endif
|
||||||
char cmd[MAX_STR_LENGTH] = {0};
|
char cmd[MAX_STR_LENGTH] = {0};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
sprintf(cmd, "flash_eraseall %s", flashDriveName);
|
char *format = "flash_eraseall %s";
|
||||||
if (FAIL == executeCommand(cmd, retvals, logDEBUG1)) {
|
if (snprintf(cmd, MAX_STR_LENGTH, format, flashDriveName) >=
|
||||||
strcpy(mess, "Could not program fpga. (could not erase flash: ");
|
MAX_STR_LENGTH) {
|
||||||
strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1);
|
ret = FAIL;
|
||||||
strcat(mess, "\n");
|
sptrcpy(mess,
|
||||||
|
"Could not program fpga. Command to erase flash is too long\n");
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
|
"Could not program fpga. (could not erase flash: %s)\n",
|
||||||
|
retvals);
|
||||||
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
LOG(logINFO, ("\tFlash erased\n"));
|
LOG(logINFO, ("\tFlash erased\n"));
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -246,8 +262,7 @@ int eraseFlash(char *mess) {
|
|||||||
int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
||||||
LOG(logDEBUG1, ("writing to flash\n"));
|
LOG(logDEBUG1, ("writing to flash\n"));
|
||||||
|
|
||||||
|
char *buffer = malloc(FLASH_BUFFER_MEMORY_SIZE);
|
||||||
char* buffer = malloc(FLASH_BUFFER_MEMORY_SIZE);
|
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
fclose(flashfd);
|
fclose(flashfd);
|
||||||
fclose(srcfd);
|
fclose(srcfd);
|
||||||
@ -260,12 +275,13 @@ int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
|||||||
|
|
||||||
int oldProgress = 0;
|
int oldProgress = 0;
|
||||||
ssize_t totalBytes = 0;
|
ssize_t totalBytes = 0;
|
||||||
ssize_t bytes = fread((void*)buffer, sizeof(char), FLASH_BUFFER_MEMORY_SIZE, srcfd);
|
ssize_t bytes =
|
||||||
|
fread((void *)buffer, sizeof(char), FLASH_BUFFER_MEMORY_SIZE, srcfd);
|
||||||
|
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
|
|
||||||
ssize_t bytesWritten =
|
ssize_t bytesWritten =
|
||||||
fwrite((void*)buffer, sizeof(char), bytes, flashfd);
|
fwrite((void *)buffer, sizeof(char), bytes, flashfd);
|
||||||
totalBytes += bytesWritten;
|
totalBytes += bytesWritten;
|
||||||
|
|
||||||
if (bytesWritten != bytes) {
|
if (bytesWritten != bytes) {
|
||||||
@ -289,9 +305,11 @@ int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
oldProgress = progress;
|
oldProgress = progress;
|
||||||
}
|
}
|
||||||
} else printf(".");
|
} else
|
||||||
|
printf(".");
|
||||||
|
|
||||||
bytes = fread((void*)buffer, sizeof(char), FLASH_BUFFER_MEMORY_SIZE, srcfd);
|
bytes = fread((void *)buffer, sizeof(char), FLASH_BUFFER_MEMORY_SIZE,
|
||||||
|
srcfd);
|
||||||
}
|
}
|
||||||
if (fsize <= 0) {
|
if (fsize <= 0) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -302,15 +320,18 @@ int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
|||||||
LOG(logINFO, ("\tWrote %ld bytes to flash\n", totalBytes));
|
LOG(logINFO, ("\tWrote %ld bytes to flash\n", totalBytes));
|
||||||
|
|
||||||
if (totalBytes != fsize) {
|
if (totalBytes != fsize) {
|
||||||
sprintf(mess, "Could not program fpga. Incorrect bytes written to flash %lu [expected: %lu]\n", totalBytes, fsize);
|
sprintf(mess,
|
||||||
|
"Could not program fpga. Incorrect bytes written to flash %lu "
|
||||||
|
"[expected: %lu]\n",
|
||||||
|
totalBytes, fsize);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int waitForFPGAtoTouchFlash(char* mess) {
|
int waitForFPGAtoTouchFlash(char *mess) {
|
||||||
// touch and program
|
// touch and program
|
||||||
FPGATouchFlash();
|
FPGATouchFlash();
|
||||||
|
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
@ -325,26 +346,31 @@ int waitForFPGAtoTouchFlash(char* mess) {
|
|||||||
usleep(1000);
|
usleep(1000);
|
||||||
timeSpent += 1000;
|
timeSpent += 1000;
|
||||||
if (timeSpent >= MAX_TIME_FPGA_TOUCH_FLASH_US) {
|
if (timeSpent >= MAX_TIME_FPGA_TOUCH_FLASH_US) {
|
||||||
sprintf(mess, "Could not program fpga. (exceeded max time allowed: %ds)\n",
|
sprintf(
|
||||||
MAX_TIME_FPGA_TOUCH_FLASH_US/(1000 * 1000));
|
mess,
|
||||||
|
"Could not program fpga. (exceeded max time allowed: %ds)\n",
|
||||||
|
MAX_TIME_FPGA_TOUCH_FLASH_US / (1000 * 1000));
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read gpio status
|
// read gpio status
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
if (FAIL == executeCommand(CMD_FPGA_PICKED_STATUS, retvals, logDEBUG1)) {
|
if (FAIL ==
|
||||||
strcpy(mess,
|
executeCommand(CMD_FPGA_PICKED_STATUS, retvals, logDEBUG1)) {
|
||||||
"Could not program fpga. (could not read gpio status: ");
|
snprintf(
|
||||||
strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1);
|
mess, MAX_STR_LENGTH,
|
||||||
strcat(mess, "\n");
|
"Could not program fpga. (could not read gpio status: %s)\n",
|
||||||
LOG(logERROR, (mess));
|
retvals);
|
||||||
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert to int
|
// convert to int
|
||||||
if (sscanf(retvals, "%d\n", &result) != 1) {
|
if (sscanf(retvals, "%d\n", &result) != 1) {
|
||||||
sprintf(mess, "Could not program fpga. (could not scan int for gpio status: [%s])\n",
|
sprintf(mess,
|
||||||
|
"Could not program fpga. (could not scan int for gpio "
|
||||||
|
"status: [%s])\n",
|
||||||
retvals);
|
retvals);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
|
|
||||||
#define CMD_GET_FLASH "awk \'$5== \"Application\" {print $1}\' /proc/mtd"
|
#define CMD_GET_FLASH "awk \'$5== \"Application\" {print $1}\' /proc/mtd"
|
||||||
|
|
||||||
#define FLASH_DRIVE_NAME_SIZE 16
|
#define FLASH_DRIVE_NAME_SIZE 16
|
||||||
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
||||||
#define MICROCONTROLLER_FILE "/dev/ttyAL0"
|
#define MICROCONTROLLER_FILE "/dev/ttyAL0"
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ int eraseAndWriteToFlash(char *mess, char *checksum, char *fpgasrc,
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eraseFlash(mess) == FAIL) {
|
if (eraseFlash(mess) == FAIL) {
|
||||||
fclose(flashfd);
|
fclose(flashfd);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -88,10 +88,10 @@ int getDrive(char *mess) {
|
|||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
strcpy(cmd, CMD_GET_FLASH);
|
strcpy(cmd, CMD_GET_FLASH);
|
||||||
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
strcpy(mess, "Could not program fpga. (could not get flash drive: ");
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1);
|
"Could not program fpga. (could not get flash drive: %s)\n",
|
||||||
strcat(mess, "\n");
|
retvals);
|
||||||
LOG(logERROR, (mess));
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,14 +129,23 @@ int eraseFlash(char *mess) {
|
|||||||
#endif
|
#endif
|
||||||
char cmd[MAX_STR_LENGTH] = {0};
|
char cmd[MAX_STR_LENGTH] = {0};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
sprintf(cmd, "flash_erase %s 0 0", flashDriveName);
|
|
||||||
if (FAIL == executeCommand(cmd, retvals, logDEBUG1)) {
|
char *format = "flash_erase %s 0 0";
|
||||||
strcpy(mess, "Could not program fpga. (could not erase flash: ");
|
if (snprintf(cmd, MAX_STR_LENGTH, format, flashDriveName) >=
|
||||||
strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1);
|
MAX_STR_LENGTH) {
|
||||||
strcat(mess, "\n");
|
ret = FAIL;
|
||||||
|
sptrcpy(mess,
|
||||||
|
"Could not program fpga. Command to erase flash is too long\n");
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
|
"Could not program fpga. (could not erase flash: %s)\n",
|
||||||
|
retvals);
|
||||||
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
LOG(logINFO, ("\tFlash erased\n"));
|
LOG(logINFO, ("\tFlash erased\n"));
|
||||||
return OK;
|
return OK;
|
||||||
@ -148,10 +157,10 @@ int writeToFlash(ssize_t fsize, FILE *flashfd, char *buffer, char *mess) {
|
|||||||
ssize_t bytesWritten = fwrite((void *)buffer, sizeof(char), fsize, flashfd);
|
ssize_t bytesWritten = fwrite((void *)buffer, sizeof(char), fsize, flashfd);
|
||||||
if (bytesWritten != fsize) {
|
if (bytesWritten != fsize) {
|
||||||
fclose(flashfd);
|
fclose(flashfd);
|
||||||
sprintf(
|
sprintf(mess,
|
||||||
mess,
|
"Could not program fpga. Incorrect bytes written to flash %lu "
|
||||||
"Could not program fpga. Incorrect bytes written to flash %lu [expected: %lu]\n",
|
"[expected: %lu]\n",
|
||||||
(long int)bytesWritten, (long int)fsize);
|
(long int)bytesWritten, (long int)fsize);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user