mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 07:20:01 +02:00
wip
This commit is contained in:
parent
5b3e5e8d16
commit
3785a314e6
@ -7,8 +7,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h> // readlink
|
#include <unistd.h> // readlink
|
||||||
|
|
||||||
#define FLASH_READ_FNAME "/var/tmp/flash.rawbin"
|
|
||||||
|
|
||||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
||||||
int outputMax, int inputValue, int *outputValue) {
|
int outputMax, int inputValue, int *outputValue) {
|
||||||
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
||||||
@ -198,7 +196,7 @@ int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
|||||||
return verifyChecksum(mess, clientChecksum, &c);
|
return verifyChecksum(mess, clientChecksum, &c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname, ssize_t fsize) {
|
||||||
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
||||||
|
|
||||||
FILE *fp = fopen(fname, "r");
|
FILE *fp = fopen(fname, "r");
|
||||||
@ -218,7 +216,9 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
|||||||
}
|
}
|
||||||
const int readUnitSize = 128;
|
const int readUnitSize = 128;
|
||||||
char buf[readUnitSize];
|
char buf[readUnitSize];
|
||||||
ssize_t bytes = fread(buf, 1, readUnitSize, fp);
|
buf[0]=0xf;
|
||||||
|
ssize_t bytes = 1;
|
||||||
|
ssize_t totalBytesRead = bytes;
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
if (!MD5_Update(&c, buf, bytes)) {
|
if (!MD5_Update(&c, buf, bytes)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -226,75 +226,27 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
|||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
// read only until a particular size (drive)
|
||||||
bytes = fread(buf, 1, readUnitSize, fp);
|
if (fsize != 0 && totalBytesRead >= fsize) {
|
||||||
}
|
LOG(logINFOBLUE, ("\tReached %lu bytes. Not reading more\n", totalBytesRead));
|
||||||
fclose(fp);
|
|
||||||
return verifyChecksum(mess, clientChecksum, &c);
|
|
||||||
}
|
|
||||||
|
|
||||||
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
|
||||||
ssize_t fsize) {
|
|
||||||
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
|
||||||
|
|
||||||
FILE *fp = fopen(fname, "r");
|
|
||||||
if (fp == NULL) {
|
|
||||||
sprintf(mess, "Unable to open %s in read mode to get checksum\n",
|
|
||||||
fname);
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
MD5_CTX c;
|
|
||||||
if (!MD5_Init(&c)) {
|
|
||||||
fclose(fp);
|
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Init)\n");
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *flashfp = fopen(FLASH_READ_FNAME, "w");
|
|
||||||
if (fp == NULL) {
|
|
||||||
sprintf(mess, "Unable to open %s in write mode to get from flash\n",
|
|
||||||
FLASH_READ_FNAME);
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(logINFO, ("\tReading from flash\n"));
|
|
||||||
int oldProgress = 0;
|
|
||||||
ssize_t bytes = 0;
|
|
||||||
while (!feof(fp) && bytes < fsize) {
|
|
||||||
// print progress
|
|
||||||
int progress = (int)(((double)(bytes) / fsize) * 100);
|
|
||||||
if (oldProgress != progress) {
|
|
||||||
printf("%d%%\r", progress);
|
|
||||||
fflush(stdout);
|
|
||||||
oldProgress = progress;
|
|
||||||
}
|
|
||||||
// read source
|
|
||||||
int s = fgetc(fp);
|
|
||||||
if (s < 0) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++bytes;
|
bytes = fread(buf, 1, readUnitSize, fp);
|
||||||
write(flashfp, &s, 1);
|
totalBytesRead += bytes;
|
||||||
// swap bits
|
}
|
||||||
int d = 0;
|
// last null character (if size does not match)
|
||||||
for (int i = 0; i < 8; ++i) {
|
/*if (fsize == totalBytesRead + 1) {
|
||||||
d = d | (((s & (1 << i)) >> i) << (7 - i));
|
bytes = 1;
|
||||||
}
|
totalBytesRead += bytes;
|
||||||
// update md5
|
if (!MD5_Update(&c, buf, bytes)) {
|
||||||
if (!MD5_Update(&c, &d, 1)) {
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", (long int)bytes));
|
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
fclose(flashfp);
|
|
||||||
return verifyChecksum(mess, clientChecksum, &c);
|
return verifyChecksum(mess, clientChecksum, &c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,25 +66,21 @@ void resetFPGA() {
|
|||||||
usleep(CTRL_SRVR_INIT_TIME_US);
|
usleep(CTRL_SRVR_INIT_TIME_US);
|
||||||
}
|
}
|
||||||
|
|
||||||
int deleteOldFile(char *mess) {
|
|
||||||
char cmd[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)) {
|
|
||||||
strcpy(mess,
|
|
||||||
"Could not program fpga. (could not delete old file: ");
|
|
||||||
strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1);
|
|
||||||
strcat(mess, "\n");
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int preparetoCopyFPGAProgram(FILE **fd, uint64_t fsize, char *mess) {
|
int preparetoCopyFPGAProgram(FILE **fd, uint64_t fsize, char *mess) {
|
||||||
|
|
||||||
if (deleteOldFile(mess) == FAIL) {
|
// delete old /var/tmp/file
|
||||||
return FAIL;
|
{
|
||||||
|
char cmd[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)) {
|
||||||
|
strcpy(mess,
|
||||||
|
"Could not program fpga. (could not delete old file: ");
|
||||||
|
strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1);
|
||||||
|
strcat(mess, "\n");
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check available memory to copy program
|
// check available memory to copy program
|
||||||
@ -135,11 +131,7 @@ int copyToFlash(ssize_t fsize, char *clientChecksum, char *mess) {
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteOldFile(mess) == FAIL) {
|
if (verifyChecksumFromFile(mess, clientChecksum, flashDriveName, fsize) ==
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) ==
|
|
||||||
FAIL) {
|
FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
@ -3795,7 +3795,8 @@ int program_fpga(int file_des) {
|
|||||||
|
|
||||||
// checksum of copied program
|
// checksum of copied program
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
ret = verifyChecksumFromFile(mess, checksum, TEMP_PROG_FILE_NAME);
|
ret =
|
||||||
|
verifyChecksumFromFile(mess, checksum, TEMP_PROG_FILE_NAME, 0);
|
||||||
}
|
}
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user