start configurator

This commit is contained in:
2025-02-27 22:46:51 +03:00
parent 70dec29f02
commit 943409c53e
14 changed files with 231 additions and 5 deletions

View File

@@ -478,3 +478,34 @@ int cmdS(SSscmd *cmd){
int cmdL(SSlcmd *cmd){
return bincmd((uint8_t *)cmd, sizeof(SSlcmd));
}
// rw == 1 to write, 0 to read
int cmdC(SSconfig *conf, int rw){
static data_t *wcmd = NULL, *rcmd = NULL;
int ret = FALSE;
// dummy buffer to clear trash in input
char ans[300];
data_t a = {.buf = (uint8_t*)ans, .maxlen=299};
if(!wcmd) wcmd = cmd2dat(CMD_PROGFLASH);
if(!rcmd) rcmd = cmd2dat(CMD_DUMPFLASH);
pthread_mutex_lock(&mntmutex);
if(rw){ // write
if(!wr(wcmd, &a, 1)) goto rtn;
}else{ // read
data_t d;
d.buf = (uint8_t *) conf;
d.len = 0; d.maxlen = sizeof(SSconfig);
ret = wr(rcmd, &d, 1);
DBG("wr returned %s; got %zd bytes of %zd", ret ? "TRUE" : "FALSE", d.len, d.maxlen);
if(d.len != d.maxlen) return FALSE;
// simplest checksum
uint16_t sum = 0;
for(uint32_t i = 0; i < sizeof(SSconfig)-2; ++i) sum += d.buf[i];
if(sum != conf->checksum){
DBG("got sum: %u, need: %u", conf->checksum, sum);
return FALSE;
}
}
rtn:
pthread_mutex_unlock(&mntmutex);
return ret;
}