示例#1
0
static const char *protoselect_cb(guiObject_t *obj, int dir, void *data)
{
    (void)data;
    (void)obj;
    u8 changed;
    enum Protocols new_protocol;
    new_protocol = GUI_TextSelectHelper(Model.protocol, PROTOCOL_NONE, PROTOCOL_COUNT-1, dir, 1, 1, &changed);
    if (changed) {
        const u8 *oldmap = ProtocolChannelMap[Model.protocol];
    	// DeInit() the old protocol (Model.protocol unchanged)
        PROTOCOL_DeInit();
        // Load() the new protocol
        Model.protocol = new_protocol;
        PROTOCOL_Load(1);
        TELEMETRY_SetTypeByProtocol(Model.protocol);
        Model.num_channels = PROTOCOL_DefaultNumChannels();
        if (! PROTOCOL_HasPowerAmp(Model.protocol))
            Model.tx_power = TXPOWER_150mW;
        else
            Model.tx_power = mp->last_txpower;
        memset(Model.proto_opts, 0, sizeof(Model.proto_opts));
        guiObject_t *obj = _get_obj(ITEM_NUMCHAN, 0);
        if (obj)
            GUI_Redraw(obj);
        obj = _get_obj(ITEM_TXPOWER, 0);
        if (obj)
            GUI_Redraw(obj);
        if (Model.mixer_mode == MIXER_STANDARD)
            STDMIXER_SetChannelOrderByProtocol();
        else
            RemapChannelsForProtocol(oldmap);
        configure_bind_button();
    }
    GUI_TextSelectEnablePress((guiTextSelect_t *)obj, PROTOCOL_GetOptions() ? 1 : 0);
    if (Model.protocol == 0)
        return _tr("None");
    if(PROTOCOL_HasModule(Model.protocol))
        return ProtocolNames[Model.protocol];
    sprintf(tempstring, "*%s", ProtocolNames[Model.protocol]);
    return tempstring;
}
示例#2
0
void PROTOCOL_Load(int no_dlg)
{
    (void)no_dlg;
#ifdef MODULAR
    if(! PROTOCOL_HasModule(Model.protocol)) {
        *loaded_protocol = 0;
        return;
    }
    if(*loaded_protocol == Model.protocol)
        return;
    char file[25];
    strcpy(file, "protocol/");
    #define PROTODEF(proto, module, map, cmd, name) case proto: strcat(file,name); break;
    switch(Model.protocol) {
        #include "protocol.h"
        default: *loaded_protocol = 0; return;
    }
    #undef PROTODEF
    file[17] = '\0'; //truncate filename to 8 characters
    strcat(file, ".mod");
    FILE *fh;
    //We close the current font because on the dveo8 we reuse
    //the font filehandle to read the protocol.
    //Thatis necessary because we need to be able to load the
    //protocol while an ini file is open, and we don't want to
    //waste the RAM for an extra filehandle
    u8 old_font = LCD_SetFont(0);
    finit(&FontFAT, ""); //In case no fonts are loaded yet
    fh = fopen2(&FontFAT, file, "r");
    //printf("Loading %s: %08lx\n", file, fh);
    if(! fh) {
        if(! no_dlg) {
            sprintf(tempstring, "Misisng protocol:\n%s", file);
            PAGE_ShowWarning(NULL, tempstring);
        }
        LCD_SetFont(old_font);
        return;
    }
    setbuf(fh, 0);
    int size = 0;
    unsigned char buf[256];
    int len;
    char *ptr = (char *)loaded_protocol;
    while(size < 4096) {
        len = fread(buf, 1, 256, fh);
        if(len) {
            memcpy(ptr, buf, len);
            ptr += len;
        }
        size += len;
        if (len != 256)
            break;
    }
    fclose(fh);
    LCD_SetFont(old_font);
    if ((unsigned long)&_data_loadaddr != *loaded_protocol) {
        if(! no_dlg) {
            sprintf(tempstring, "Protocol Mismatch:\n%08x\n%08x", (unsigned long)&_data_loadaddr, *loaded_protocol);
            PAGE_ShowWarning(NULL, tempstring);
        }
        *loaded_protocol = 0;
        return;
    }
    //printf("Updated %d (%d) bytes: Data: %08lx %08lx %08lx\n", size, len, *loaded_protocol, *(loaded_protocol+1), *(loaded_protocol+2));
    //We use the same file for multiple protocols, so we need to manually set this here
    *loaded_protocol = Model.protocol;
#else
    if(! PROTOCOL_HasModule(Model.protocol)) {
        PROTO_Cmds = NULL;
        printf("Module is not defined!\n");
        return;
    }
    #define PROTODEF(proto, module, map, cmd, name) case proto: PROTO_Cmds = cmd; break;
    switch(Model.protocol) {
        #include "protocol.h"
        default: PROTO_Cmds = NULL;
    }
    #undef PROTODEF
#endif
    PROTOCOL_SetSwitch(get_module(Model.protocol));
}
示例#3
0
void PROTOCOL_Load(int no_dlg)
{
    (void)no_dlg;
#ifdef ENABLE_MODULAR
    FATFS ModuleFAT;
    FILE *fh;

    if(! PROTOCOL_HasModule(Model.protocol)) {
        *loaded_protocol = 0;
        return;
    }
    if(*loaded_protocol == Model.protocol)
        return;
    char file[25];
    strcpy(file, "protocol/");

    if (Model.protocol > PROTOCOL_COUNT)
    {
        *loaded_protocol = 0;
        return;
    }
    else
    {
        strcat(file, Protocols[Model.protocol].name);
    }
    file[17] = '\0'; //truncate filename to 8 characters
    strcat(file, ".mod");

    memset(&ModuleFAT, 0, sizeof(ModuleFAT));
    finit(&ModuleFAT, "protocol");
    fh = fopen2(&ModuleFAT, file, "r");
    //printf("Loading %s: %08lx\n", file, fh);
    if(! fh) {
        if(! no_dlg) {
            sprintf(tempstring, "Misisng protocol:\n%s", file);
            PAGE_ShowWarning(NULL, tempstring);
        }
        return;
    }
    setbuf(fh, 0);
    fread(loaded_protocol, 1, 4 * 1024, fh);
    fclose(fh);
    if ((unsigned long)&_data_loadaddr != *loaded_protocol) {
        if(! no_dlg) {
            sprintf(tempstring, "Protocol Mismatch:\n%08x\n%08x", (unsigned long)&_data_loadaddr, *loaded_protocol);
            PAGE_ShowWarning(NULL, tempstring);
        }
        *loaded_protocol = 0;
        return;
    }
    //printf("Updated %d (%d) bytes: Data: %08lx %08lx %08lx\n", size, len, *loaded_protocol, *(loaded_protocol+1), *(loaded_protocol+2));
    //We use the same file for multiple protocols, so we need to manually set this here
    *loaded_protocol = Model.protocol;
#else
    if(! PROTOCOL_HasModule(Model.protocol)) {
        PROTO_Cmds = NULL;
        printf("Module is not defined!\n");
        return;
    }
    PROTO_Cmds = Protocols[Model.protocol].cmd;
#endif
    PROTOCOL_SetSwitch(get_module(Model.protocol));
    if (PROTOCOL_GetTelemetryState() != PROTO_TELEM_UNSUPPORTED) {
        memset(&Telemetry, 0, sizeof(Telemetry));
        TELEMETRY_SetType(PROTOCOL_GetTelemetryType());
    }

    CurrentProtocolChannelMap = PROTOCOL_GetChannelMap();
}