Skip to content

Commit

Permalink
more appropriate handling of checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpiep committed Feb 27, 2022
1 parent c00c9b9 commit 609ba3b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 44 deletions.
6 changes: 3 additions & 3 deletions include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#define FN_VERSION_MAJOR 0
#define FN_VERSION_MINOR 5

#define FN_VERSION_BUILD "b78e2b62"
#define FN_VERSION_BUILD "c00c9b97"

#define FN_VERSION_DATE "2022-02-26 21:37:46"
#define FN_VERSION_DATE "2022-02-27 19:43:14"

#define FN_VERSION_FULL "0.5.b78e2b62"
#define FN_VERSION_FULL "0.5.c00c9b97"


23 changes: 17 additions & 6 deletions lib/bus/iwm/iwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,13 @@ void iwmDevice::iwm_return_badcmd(cmdPacket_t cmd)
IWM.iwm_send_packet((unsigned char *)packet_buffer);
}

void iwmDevice::iwm_return_ioerror(cmdPacket_t cmd)
{
Debug_printf("\r\nUnit %02x Bad Command %02x", id(), cmd.command);
encode_error_reply_packet(SP_ERR_IOERROR);
IWM.iwm_send_packet((unsigned char *)packet_buffer);
}

//*****************************************************************************
// Function: verify_cmdpkt_checksum
// Parameters: none
Expand Down Expand Up @@ -1273,11 +1280,6 @@ void iwmBus::service()
portENABLE_INTERRUPTS();
return;
}
if (verify_cmdpkt_checksum())
{
Debug_printf("\r\nBAD CHECKSUM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return;
}
// should not ACK unless we know this is our Command
if (command_packet.command == 0x85)
{
Expand All @@ -1301,6 +1303,7 @@ void iwmBus::service()
print_packet(command_packet.data);
Debug_printf("\r\nhandling init command");
#endif
// to do - checksum verification? How to respond?
handle_init();
}
else
Expand Down Expand Up @@ -1331,7 +1334,15 @@ void iwmBus::service()
#endif
_activeDev = devicep;
// handle command
_activeDev->process(command_packet);
if (verify_cmdpkt_checksum())
{
Debug_printf("\r\nBAD CHECKSUM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
_activeDev->iwm_return_ioerror(command_packet);
}
else
{
_activeDev->process(command_packet);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/bus/iwm/iwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ friend iwmBus; // put here for prototype, not sure if will need to keep it
virtual void iwm_write(cmdPacket_t cmd) {};

void iwm_return_badcmd(cmdPacket_t cmd);
void iwm_return_ioerror(cmdPacket_t cmd);

public:
bool device_active;
Expand Down
71 changes: 36 additions & 35 deletions lib/device/iwm/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ void iwmDisk::iwm_readblock(cmdPacket_t cmd)

void iwmDisk::iwm_writeblock(cmdPacket_t cmd)
{
uint8_t status = 0;
uint8_t source = cmd.dest; // packet_buffer[6];
// to do - actually we will already know that the cmd.dest == id(), so can just use id() here
Debug_printf("\r\nDrive %02x ", source);
Expand All @@ -543,44 +544,44 @@ void iwmDisk::iwm_writeblock(cmdPacket_t cmd)
return;
}
// partition number indicates which 32mb block we access
int status = 0; // force no error - to do - work out
decode_data_packet();
if (status == 0)
{ //ok
//write block to CF card
//Serial.print(F("\r\nWrite Bl. n.r: "));
//Serial.print(block_num);
if (block_num != last_block_num + 1) // example optimization, only do seek if not writing next block -tschak
{
Debug_printf("\r\n");
if (fseek(d.sdf, (block_num * 512), SEEK_SET))
if (decode_data_packet())
iwm_return_ioerror(cmd);
else
{ // ok
//write block to CF card
//Serial.print(F("\r\nWrite Bl. n.r: "));
//Serial.print(block_num);
if (block_num != last_block_num + 1) // example optimization, only do seek if not writing next block -tschak
{
Debug_printf("\r\nRead seek err! block #%02x", block_num);
encode_error_reply_packet(SP_ERR_BADBLOCK);
IWM.iwm_send_packet((unsigned char *)packet_buffer);
return; // todo - send an error status packet?
// to do - set a flag here to check for error status
Debug_printf("\r\n");
if (fseek(d.sdf, (block_num * 512), SEEK_SET))
{
Debug_printf("\r\nRead seek err! block #%02x", block_num);
encode_error_reply_packet(SP_ERR_BADBLOCK);
IWM.iwm_send_packet((unsigned char *)packet_buffer);
return; // todo - send an error status packet?
// to do - set a flag here to check for error status
}
}
}
size_t sdstato = fwrite((unsigned char *)packet_buffer, 1, 512, d.sdf);
if (sdstato != 512)
{
Debug_printf("\r\nFile Write err: %d bytes", sdstato);
if (sdstato == 0)
status = 0x2B; // write protected todo: we should probably have a read-only flag that gets set and tested up top
else
status = 0x27; // 6;
//return;
}
//now return status code to host
encode_write_status_packet(source, status);
IWM.iwm_send_packet((unsigned char *)packet_buffer);
//Serial.print(F("\r\nSent status Packet Data\r\n") );
//print_packet ((unsigned char*) sector_buffer,512);
size_t sdstato = fwrite((unsigned char *)packet_buffer, 1, 512, d.sdf);
if (sdstato != 512)
{
Debug_printf("\r\nFile Write err: %d bytes", sdstato);
if (sdstato == 0)
status = 0x2B; // write protected todo: we should probably have a read-only flag that gets set and tested up top
else
status = 0x27; // 6;
//return;
}
//now return status code to host
encode_write_status_packet(source, status);
IWM.iwm_send_packet((unsigned char *)packet_buffer);
//Serial.print(F("\r\nSent status Packet Data\r\n") );
//print_packet ((unsigned char*) sector_buffer,512);

//print_packet ((unsigned char*) packet_buffer,get_packet_length());
last_block_num = block_num;
}
//print_packet ((unsigned char*) packet_buffer,get_packet_length());
last_block_num = block_num;
}
}


Expand Down

0 comments on commit 609ba3b

Please sign in to comment.