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

Function fxCommandReceived

tools/serial2xsbug/serial2xsbug.c:347–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347void fxCommandReceived(txSerialTool self, void *bufferIn, int size)
348{
349 uint8_t *buffer = bufferIn;
350 uint16_t resultId = (buffer[1] << 8) | buffer[2];
351 int16_t resultCode = (buffer[3] << 8) | buffer[4];
352
353 if (resultCode) {
354 fprintf(stderr, "### fxCommandReceived: remote operation id %#04x failed with resultCode %d\n", (int)resultId, (int)resultCode);
355 exit(-1);
356 }
357 else if (self->traceCommands)
358 fprintf(stderr, "### fxCommandReceived: remote operation id %#04x SUCCESS with resultCode %d\n", (int)resultId, (int)resultCode);
359
360 if (0xff02 == resultId) { // uninstall
361 if (self->traceCommands)
362 fprintf(stderr, "### uninstalled\n");
363 fxRestart(self);
364 usleep(50000);
365 return;
366 }
367
368 if (0xff0f == resultId) { // get install space
369 uint32_t installSpace;
370
371 if (0 != resultCode) {
372 fprintf(stderr, "getInstallSpace failed %d\n", (int)resultCode);
373 return;
374 }
375
376 installSpace = (buffer[5] << 24) | (buffer[6] << 16) | (buffer[7] << 8) | buffer[8];
377
378 gInstallFragmentSize = 512;
379 if (size >= 13)
380 gInstallFragmentSize = (buffer[9] << 24) | (buffer[10] << 16) | (buffer[11] << 8) | buffer[12];
381
382 if (self->traceCommands)
383 fprintf(stderr, "### installSpace: %d, fragment size %d\n", (int)installSpace, (int)gInstallFragmentSize);
384
385 if (installSpace < gInstallArchiveSize) {
386 fprintf(stderr, "install failed. mod needs %d bytes, only %d available\n", (int)gInstallArchiveSize, (int)installSpace);
387 return;
388 }
389
390 fxInstallFragment(self);
391 return;
392 }
393
394 if (0xe0e0 == resultId) { // installed fragment
395 if ((gInstallOffset / 4096) != ((gInstallOffset - gInstallFragmentSize) / 4096))
396 fprintf(stderr, ".");
397 fxInstallFragment(self);
398 return;
399 }
400 if (0xe8e8 == resultId) { // install complete
401 if (self->traceCommands)
402 fprintf(stderr, "### install complete\n");
403
404 fprintf(stderr, "..complete\n");

Callers 1

fxReadSerialBufferFunction · 0.85

Calls 3

fxRestartFunction · 0.85
fxInstallFragmentFunction · 0.85
fxSetPrefFunction · 0.85

Tested by

no test coverage detected