Esempio n. 1
0
    sdlCommand.find(">HelpLinks>HelpLink").each((i, child) => {
        let helpLink = $(child).attr("name");
        if (helpLink) {
            if (command && !command.helpLink) {
                command.helpLink = localPathToFileUrl(docPath + "/" + $(child).attr("url"));
            }

            if (query && !query.helpLink) {
                query.helpLink = localPathToFileUrl(docPath + "/" + $(child).attr("url"));
            }
        }
    });
async function createScpi(extensionFolderPath: string) {
    const scpi: Scpi = new Scpi();

    const { commands, enums } = await loadCommandsFromExtensionFolder(extensionFolderPath);

    const extensionFolderPathUrl = localPathToFileUrl(extensionFolderPath);

    const subsystems = new Map<string, any>();

    commands.forEach(command => {
        let subsystemName = splitCommandToMnemonics(command.name)[0];
        if (subsystemName.startsWith("*")) {
            subsystemName = "Common commands";
        } else if (subsystemName.startsWith("[")) {
            subsystemName = subsystemName.substr(1, subsystemName.length - 2);
        }

        let scpiSubsystem = subsystems.get(subsystemName);
        if (!scpiSubsystem) {
            scpiSubsystem = {
                name: subsystemName,
                commands: []
            };
            subsystems.set(subsystemName, scpiSubsystem);
        }

        scpiSubsystem.commands.push(
            Object.assign({}, command, {
                helpLink: command.helpLink && command.helpLink.substr(extensionFolderPathUrl.length)
            })
        );
    });

    (scpi as any).enums = enums;
    (scpi as any).subsystems = Array.from(subsystems.values());

    return scpi;
}
Esempio n. 3
0
export async function loadInstrumentExtension(extensionFolderPath: string) {
    try {
        let idfFilePath = await findIdfFile(extensionFolderPath);
        if (!idfFilePath) {
            throw "IDF file not found";
        }

        if (isRenderer()) {
            let idfXmlAsString = await readTextFile(idfFilePath);
            let idf = parseXmlString(idfXmlAsString);
            let ScpiConfiguration = $(idf).find(">ScpiConfigurations");
            if (ScpiConfiguration.length && ScpiConfiguration.attr("guid")) {
                let id = ScpiConfiguration.attr("guid")!;

                let name = ScpiConfiguration.attr("name") || "Unknown name";
                let version = ScpiConfiguration.attr("firmwareVersion") || "Unknown version";

                let properties: IInstrumentExtensionProperties;
                let isEditable: boolean;
                let downloadUrl: string | undefined;
                let sha256: string | undefined;
                let moreDescription: string | undefined;

                let packageJsonFilePath = extensionFolderPath + "/package.json";
                if (await fileExists(packageJsonFilePath)) {
                    const packageJson = await readPackageJson(packageJsonFilePath);
                    version = packageJson.version;
                    properties = packageJson["eez-studio"];
                    isEditable = await fileExists(extensionFolderPath + "/.editable");
                    downloadUrl = packageJson.download;
                    sha256 = packageJson.sha256;
                    moreDescription = properties.moreDescription;
                } else {
                    properties = EMPTY_INSTRUMENT_PROPERTIES;
                    isEditable = true;

                    await writeBinaryData(extensionFolderPath + "/.editable", "");

                    await writeJsObjectToFile(packageJsonFilePath, {
                        name,
                        version,
                        "eez-studio": properties
                    });

                    downloadUrl = undefined;
                }

                const isDirty =
                    isEditable &&
                    ((await fileExists(extensionFolderPath + "/package.json")) ||
                        (await fileExists(extensionFolderPath + "/image.png")));

                const extension: IExtension = observable(
                    {
                        id,
                        type: "instrument",
                        name,
                        description:
                            ScpiConfiguration.attr("description") || "Unknown description.",
                        moreDescription,
                        version,
                        author: ScpiConfiguration.attr("author") || "Unknown author",
                        image: "",
                        renderPropertiesComponent: () => {
                            const {
                                renderPropertiesComponent
                            } = require("instrument/properties-component") as typeof PropertiesComponentModule;

                            return new Promise<JSX.Element>(resolve => {
                                resolve(renderPropertiesComponent(extension));
                            });
                        },
                        properties,
                        isEditable,
                        isDirty,

                        shortName: ScpiConfiguration.attr("shortName") || "",
                        revisionNumber: ScpiConfiguration.attr("revisionNumber") || "",
                        supportedModels: ScpiConfiguration.attr("supportedModels") || "",
                        revisionComments: ScpiConfiguration.attr("revisionComments") || ""
                    },
                    {
                        properties: observable.shallow
                    }
                );

                const imageFilePath = extensionFolderPath + "/" + "image.png";
                if (await fileExists(imageFilePath)) {
                    extension.image = localPathToFileUrl(imageFilePath);
                } else {
                    extension.image = INSTRUMENT_NO_IMAGE;
                }

                extension.download = downloadUrl;
                extension.sha256 = sha256;

                extension.installationFolderPath = extensionFolderPath;

                return extension;
            }
        } else {
            let packageJSON = await readPackageJson(extensionFolderPath + "/package.json");

            const extension: IExtension = {
                id: packageJSON["id"],
                type: "instrument",
                name: "",
                description: "",
                version: "",
                author: "",
                image: "",
                properties: packageJSON["eez-studio"]
            };

            return extension;
        }
    } catch (err) {
        console.error(err);
    }

    throw "Unknown extension type!";
}