Just some source code style cleanup.

This commit is contained in:
Oliver Schmidt 2018-02-04 20:57:30 +01:00
parent b958c660a9
commit e281c0061b

View File

@ -50,10 +50,10 @@ crc_xmodem(char *ptr, unsigned count)
int main(int argc, char *argv[])
{
// Process the command line arguments
bool bVerbose = false;
bool bLog = true;
char *apFilename[2] = {0, 0};
for (int iArg = 1; iArg < argc; iArg++)
{
if (argv[iArg][0] == '-')
@ -102,6 +102,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
// Memory-map the disk image file(s)
char *apFileData[2] = {0, 0};
for (int iDrive = 0; iDrive < 2; iDrive++)
{
@ -131,11 +132,9 @@ int main(int argc, char *argv[])
}
}
enum sp_return eResult;
// Create a configuration for the serial ports
enum sp_return eResult;
struct sp_port_config *pSerialConfig = 0;
{
eResult = sp_new_config(&pSerialConfig);
assert(eResult == SP_OK);
eResult = sp_set_config_baudrate(pSerialConfig, 230400);
@ -148,7 +147,6 @@ int main(int argc, char *argv[])
assert(eResult == SP_OK);
eResult = sp_set_config_flowcontrol(pSerialConfig, SP_FLOWCONTROL_RTSCTS);
assert(eResult == SP_OK);
}
// Find and configure valid serial ports
const int MAX_PORTS = 2;
@ -183,7 +181,6 @@ int main(int argc, char *argv[])
printf("\tManufacturer: %s\n", sp_get_port_usb_manufacturer(pPort));
printf("\tProduct: %s\n", sp_get_port_usb_product(pPort));
printf("\tSerial #: %s\n", sp_get_port_usb_serial(pPort));
}
// Retain the port and configure it's settings
@ -208,12 +205,10 @@ int main(int argc, char *argv[])
sp_close(pPort);
sp_free_port(pPort);
if (bVerbose)
{
printf("\n\t--- Could not open this port ---\n\n");
}
}
}
}
else // ! usbserial
{
if (bVerbose)
@ -251,14 +246,12 @@ int main(int argc, char *argv[])
// Now read 16-bit block number and byte checksum
iBytesRead = 1 + sp_blocking_read(pPort, auReadBuf + 1, 3, 1/*ms timeout*/);
if (iBytesRead != 4) continue;
if (iBytesRead != 4)
continue;
if (bVerbose)
{
for (int i = 0; i < iBytesRead; i++)
{
printf("\t%02X '%c'\n", auReadBuf[i], auReadBuf[i] & 0x7f);
}
}
int iChksum = auReadBuf[0] ^ auReadBuf[1] ^ auReadBuf[2];
if (iChksum != auReadBuf[3])
{
@ -290,7 +283,8 @@ int main(int argc, char *argv[])
{
// Echo command packet to confirm the request was received
iTxLen = sp_blocking_write(pPort, auReadBuf, 4, 1/*ms timeout*/);
if (iTxLen != 4) continue;
if (iTxLen != 4)
continue;
// Send the requsted block
iTxLen = sp_blocking_write(pPort, pDriveData, 512, 5/*ms timeout*/);
@ -307,7 +301,8 @@ int main(int argc, char *argv[])
// Send checksum
iTxLen = sp_blocking_write(pPort, &iChksum, 1, 30/*ms timeout*/);
if (iTxLen != 1) continue;
if (iTxLen != 1)
continue;
if (bLog)
{
@ -317,7 +312,7 @@ int main(int argc, char *argv[])
}
else // Write block
{
static unsigned char auBlockBuf[513];
static unsigned char auBlockBuf[512 + 1];
int iReadLen = sp_blocking_read(pPort, auBlockBuf, 512 + 1, 30/*ms timeout*/);
assert(iReadLen == 512 + 1);
@ -332,9 +327,7 @@ int main(int argc, char *argv[])
// Block data checksum matches, write it to disk
if (iChksum == auBlockBuf[512])
{
memcpy(pDriveData, auBlockBuf, 512);
}
if (bLog)
{
@ -343,7 +336,6 @@ int main(int argc, char *argv[])
}
}
}
}
}