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

Function doRemoteCommand

xs/platforms/pico/xsPlatform.c:555–744  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

553}
554
555void doRemoteCommand(txMachine *the, uint8_t *cmd, uint32_t cmdLen)
556{
557 uint16_t resultID = 0;
558 int16_t resultCode = 0;
559 uint8_t cmdID;
560 int baud = 0;
561
562 if (!cmdLen)
563 return;
564
565 cmdID = *cmd++;
566 cmdLen -= 1;
567//printf("do Remote command %d\n", cmdID);
568
569 if (cmdLen >= 2) {
570 resultID = (cmd[0] << 8) | cmd[1];
571 cmd += 2, cmdLen -= 2;
572
573 the->echoBuffer[0] = 5;
574 the->echoBuffer[1] = resultID >> 8;
575 the->echoBuffer[2] = resultID & 0xff;
576 the->echoBuffer[3] = 0;
577 the->echoBuffer[4] = 0;
578 the->echoOffset = 5;
579 }
580
581 switch (cmdID) {
582 case 1: // restart
583 break;
584
585#if MODDEF_XS_MODS
586 case 2: { // uninstall
587 uint8_t erase[16] = {0};
588 uint32_t offset = (uintptr_t)kModulesStart - (uintptr_t)kFlashStart;
589 if (!modSPIWrite(offset, sizeof(erase), erase))
590 resultCode = -1;
591 } break;
592
593 case 3: { // install some
594 uint32_t offset = c_read32be(cmd);
595 cmd += 4, cmdLen -= 4;
596 if ((offset + cmdLen) > kModulesByteLength) {
597 resultCode = -2;
598 break;
599 }
600
601 offset += (uintptr_t)kModulesStart - (uintptr_t)kFlashStart;
602
603 int firstSector = offset / kFlashSectorSize, lastSector = (offset + cmdLen) / kFlashSectorSize;
604 if (!(offset % kFlashSectorSize)) // starts on sector boundary
605 modSPIErase(offset, kFlashSectorSize * ((lastSector - firstSector) + 1));
606 else if (firstSector != lastSector)
607 modSPIErase((firstSector + 1) * kFlashSectorSize, kFlashSectorSize * (lastSector - firstSector)); // crosses into a new sector
608
609 if (!modSPIWrite(offset, cmdLen, cmd))
610 resultCode = -1;
611 }
612 break;

Callers 1

fxReceiveFunction · 0.70

Calls 11

pico_get_macFunction · 0.85
modGetModAtomFunction · 0.85
modSPIWriteFunction · 0.70
modSPIEraseFunction · 0.70
modSetTimeFunction · 0.70
modSetTimeZoneFunction · 0.70
fxSendFunction · 0.70
fxDisconnectFunction · 0.70
modPreferenceSetFunction · 0.50
modPreferenceGetFunction · 0.50

Tested by

no test coverage detected