2025-02-04 21:33:02 +03:00

71 lines
2.1 KiB
C

/*
* This file is part of the libsidservo project.
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "serial.h"
#include "ssii.h"
uint16_t SScalcChecksum(uint8_t *buf, int len){
uint16_t checksum = 0;
for(int i = 0; i < len; i++)
checksum += *buf++;
checksum ^= 0xFF00; // invert high byte
//DBG("Checksum of %d bytes: 0x%04x", len, checksum);
return checksum;
}
// send short/long binary command
static int bincmd(uint8_t *cmd, int len){
data_t d;
if(len == sizeof(SSscmd)){
((SSscmd*)cmd)->checksum = SScalcChecksum(cmd, len-2);
DBG("Short command");
d.buf = CMD_SHORTCMD;
d.len = sizeof(CMD_SHORTCMD) - 1;
if(!MountWriteRead(&d, NULL)) return -1;
}else if(len == sizeof(SSlcmd)){
((SSlcmd*)cmd)->checksum = SScalcChecksum(cmd, len-2);
DBG("Long command");
d.buf = CMD_LONGCMD;
d.len = sizeof(CMD_LONGCMD) - 1;
if(!MountWriteRead(&d, NULL)) return -1;
}else{
return -1;
}
DBG("Write %d bytes and wait for ans", len);
d.buf = cmd;
d.len = d.maxlen = len;
return MountWriteRead(&d, &d);
}
// return TRUE if OK
int SScmdS(SSscmd *cmd){
return bincmd(cmd, sizeof(SSscmd));
}
int SScmdL(SSlcmd *cmd){
return bincmd(cmd, sizeof(SSlcmd));
}
/**
* @brief SSconvstat - convert stat from SSII format to human
* @param status (i) - just read data
* @param mountdata (o) - output
*/
void SSconvstat(const SSstat *status, mountdata_t *mountdata){
;
}