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

Function doRemoteCommand

xs/platforms/zephyr/xsPlatform.c:548–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

546}
547
548void doRemoteCommand(txMachine *the, uint8_t *cmd, uint32_t cmdLen)
549{
550 uint16_t resultID = 0;
551 int16_t resultCode = 0;
552 uint8_t cmdID;
553
554 if (!cmdLen)
555 return;
556
557 cmdID = *cmd++;
558 cmdLen -= 1;
559
560 if (cmdLen >= 2) {
561 resultID = (cmd[0] << 8) | cmd[1];
562 cmd += 2, cmdLen -= 2;
563
564 the->echoBuffer[0] = 5;
565 the->echoBuffer[1] = resultID >> 8;
566 the->echoBuffer[2] = resultID & 0xff;
567 the->echoBuffer[3] = 0;
568 the->echoBuffer[4] = 0;
569 the->echoOffset = 5;
570 }
571
572 switch (cmdID) {
573 case 1: // restart
574 the->wsState = 18;
575 break;
576
577#if MODDEF_XS_MODS
578 case 2: { // uninstall
579 uint8_t erase[16] = {0};
580 uint32_t offset = (uintptr_t)kModulesStart - (uintptr_t)kFlashStart;
581 if (!modSPIWrite(offset, sizeof(erase), erase))
582 resultCode = -2;
583 } break;
584
585 case 3: { // install some
586 uint32_t offset = c_read32be(cmd);
587 cmd += 4, cmdLen -= 4;
588 if ((offset + cmdLen) > kModulesByteLength) {
589 resultCode = -3;
590 break;
591 }
592
593 offset += (uintptr_t)kModulesStart - (uintptr_t)kFlashStart;
594
595 int firstSector = offset / kFlashSectorSize, lastSector = (offset + cmdLen) / kFlashSectorSize;
596 if (!((offset + cmdLen) % kFlashSectorSize)) // ends on sector boundary, don't fall into next sector
597 lastSector -= 1;
598 if (!(offset % kFlashSectorSize)) // starts on sector boundary
599 modSPIErase(offset, kFlashSectorSize * ((lastSector - firstSector) + 1));
600 else if (firstSector != lastSector)
601 modSPIErase((firstSector + 1) * kFlashSectorSize, kFlashSectorSize * (lastSector - firstSector)); // crosses into a new sector
602
603 int write = cmdLen - (cmdLen % kModulesWriteAlign);
604 if (!modSPIWrite(offset, write, cmd))
605 resultCode = -1;

Callers 1

fxReceiveFunction · 0.70

Calls 12

modGetModAtomFunction · 0.85
zephyr_resetFunction · 0.85
modSPIWriteFunction · 0.70
modSPIEraseFunction · 0.70
modSPIReadFunction · 0.70
modPreferenceSetFunction · 0.70
modPreferenceGetFunction · 0.70
modSetTimeFunction · 0.70
modSetTimeZoneFunction · 0.70
fxSendFunction · 0.70
fxDisconnectFunction · 0.70

Tested by

no test coverage detected