MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxInstallFragment

Function fxInstallFragment

tools/serial2xsbug/serial2xsbug.c:839–880  ·  view source on GitHub ↗

erases first block and writes gInstallFragmentSize bytes of header skips kInstallSkipFragmentSize bytes writes remaining for data backs up to offset 0 and writes the kInstallSkipFragmentSize bytes skipped this ensures that the mod header is only valid if all bytes are received @@ add GET VERSION

Source from the content-addressed store, hash-verified

837// this ensures that the mod header is only valid if all bytes are received
838//@@ add GET VERSION
839void fxInstallFragment(txSerialTool self)
840{
841 char preamble[32];
842 char *out = malloc(gInstallFragmentSize + 16);
843 int use = (0 == gInstallOffset) ? kInstallInitialFragmentSize : gInstallFragmentSize;
844 uint8_t id = 0xe0;
845
846 fseek(gInstallFD, gInstallOffset, SEEK_SET);
847 use = fread(out + 9, 1, use, gInstallFD);
848 if (0 == use) {
849 if (self->traceCommands)
850 fprintf(stderr, "### update install header\n");
851 gInstallOffset = kInstallInitialFragmentSize;
852 fseek(gInstallFD, gInstallOffset, SEEK_SET);
853 use = fread(out + 9, 1, kInstallSkipFragmentSize, gInstallFD);
854 id = 0xe8;
855 }
856
857 if (self->traceCommands)
858 fprintf(stderr, "### install fragment @ %d size %d\n", gInstallOffset, use);
859
860 sprintf(preamble, "\r\n<?xs#%8.8X?>", self->currentMachine->value);
861 fxWriteSerial(self, preamble, strlen(preamble));
862
863 out[0] = ((use + 7) >> 8) & 0xff; // length high
864 out[1] = (use + 7) & 0xff; // length low
865 out[2] = 3; // install cmd
866 out[3] = id; // id high
867 out[4] = id; // id low
868 out[5] = (gInstallOffset >> 24) & 255;
869 out[6] = (gInstallOffset >> 16) & 255;
870 out[7] = (gInstallOffset >> 8) & 255;
871 out[8] = gInstallOffset & 255;
872
873 fxWriteSerial(self, out, use + 4 + 5);
874
875 if (0 == gInstallOffset)
876 gInstallOffset += kInstallSkipFragmentSize;
877 gInstallOffset += use;
878
879 free(out);
880}
881
882int mapHex(char c)
883{

Callers 1

fxCommandReceivedFunction · 0.85

Calls 1

fxWriteSerialFunction · 0.70

Tested by

no test coverage detected