Let add2debugmsgsave use 20 lines of memory

pull/1042/head
Mike Black W9MDB 2022-05-22 22:15:55 -05:00
rodzic f44fe0ed31
commit 2127633678
2 zmienionych plików z 77 dodań i 22 usunięć

Wyświetl plik

@ -26,11 +26,13 @@ float freqA = 14074000;
float freqB = 14074500;
mode_t modeA = RIG_MODE_CW;
mode_t modeB = RIG_MODE_USB;
int datamode = 0;
int datamodeA = 0;
int datamodeB = 0;
pbwidth_t widthA = 0;
pbwidth_t widthB = 1;
ant_t ant_curr = 0;
int ant_option = 0;
int ptt = 0;
void dumphex(unsigned char *buf, int n)
{
@ -251,6 +253,27 @@ void frameParse(int fd, unsigned char *frame, int len)
}
break;
case 0x1c:
switch(frame[5])
{
case 0:
if (frame[6] == 0xfd)
{
frame[6] = ptt;
frame[7] = 0xfd;
write(fd, frame, 8);
}
else {
ptt = frame[6];
frame[7] = 0xfb;
frame[8] = 0xfd;
write(fd, frame, 9);
}
break;
}
break;
#ifdef X25
@ -273,7 +296,7 @@ void frameParse(int fd, unsigned char *frame, int len)
}
else
{
freq = from_bcd(&frame[5], (civ_731_mode ? 4 : 5) * 2);
freq = from_bcd(&frame[6], (civ_731_mode ? 4 : 5) * 2);
printf("set_freq to %.0f\n", freq);
if (frame[5] == 0x00) { freqA = freq; }
@ -281,6 +304,7 @@ void frameParse(int fd, unsigned char *frame, int len)
frame[4] = 0xfb;
frame[5] = 0xfd;
write(fd, frame, 6);
}
break;
@ -290,12 +314,33 @@ void frameParse(int fd, unsigned char *frame, int len)
if (frame[6] == 0xfd) // then a query
{
for (int i = 0; i < 6; ++i) { printf("%02x:", frame[i]); }
frame[6] = frame[5] == 0 ? modeA : modeB;
frame[7] = datamode;
frame[7] = frame[5] == 0 ? datamodeA : datamodeB;
frame[8] = 0xfb;
frame[9] = 0xfd;
write(fd, frame, 10);
}
else
{
for (int i = 0; i < 12; ++i) { printf("%02x:", frame[i]); }
if (frame[6] == 0)
{
modeA = frame[7];
datamodeA = frame[8];
}
else
{
modeB = frame[7];
datamodeB = frame[8];
}
frame[4] = 0xfb;
frame[5] = 0xfd;
write(fd, frame, 6);
}
printf("\n");
break;
@ -361,10 +406,12 @@ void rigStatus()
{
char vfoa = current_vfo == RIG_VFO_A ? '*' : ' ';
char vfob = current_vfo == RIG_VFO_B ? '*' : ' ';
printf("%cVFOA: mode=%s width=%ld freq=%.0f\n", vfoa, rig_strrmode(modeA),
printf("%cVFOA: mode=%d datamode=%d width=%ld freq=%.0f\n", vfoa, modeA,
datamodeA,
widthA,
freqA);
printf("%cVFOB: mode=%s width=%ld freq=%.0f\n", vfob, rig_strrmode(modeB),
printf("%cVFOB: mode=%d datamode=%d width=%ld freq=%.0f\n", vfob, modeB,
datamodeB,
widthB,
freqB);
}

Wyświetl plik

@ -313,29 +313,37 @@ char debugmsgsave3[DEBUGMSGSAVE_SIZE] = "";
void add2debugmsgsave(const char *s)
{
int l1 = strlen(debugmsgsave);
int l2 = strlen(s);
int l3 = sizeof(debugmsgsave) - 2;
char *p;
char stmp[DEBUGMSGSAVE_SIZE];
int i,nlines;
memset(stmp, 0, sizeof(stmp));
p = debugmsgsave;
while (l1 + l2 > l3)
// we'll keep 20 lines including this one
// so count the lines
for(i=0,nlines=0;debugmsgsave[i] != 0;++i)
{
char *p = strchr(debugmsgsave, '\n');
memmove(debugmsgsave, p + 1, strlen(p + 1) + 1); // include null byte
l1 = strlen(debugmsgsave);
if (l1 == 0)
{
//rig_debug(RIG_DEBUG_ERR, "%s: debugmsgsave criticl error...overflow\n");
// we'll keep some of whatever this thing is
strncat(debugmsgsave, p, sizeof(debugmsgsave) / 2);
return;
}
if (debugmsgsave[i] == '\n') ++nlines;
}
// strip the last 19 lines
while (nlines > 19)
{
p = strchr(debugmsgsave,'\n');
strcpy(stmp,p+1);
strcpy(debugmsgsave,stmp);
--nlines;
}
strcat(debugmsgsave, s);
if (strlen(stmp) + strlen(s) + 1 < DEBUGMSGSAVE_SIZE)
{
strcat(debugmsgsave, s);
}
else
{
rig_debug(RIG_DEBUG_BUG, "%s: debugmsgsave overflow!! len of debugmsgsave=%d, len of add=%d\n", __func__, (int)strlen(debugmsgsave), (int)strlen(s));
}
}
/**
* \brief get string describing the error code
* \param errnum The error code