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)); }
static void CE_lo() { #if HAS_MULTIMOD_SUPPORT PROTOCOL_SetSwitch(NRF24L01); #endif }
void PROTOCOL_InitModules() { #if HAS_MULTIMOD_SUPPORT int error = 0; const char * missing[TX_MODULE_LAST]; memset(missing, 0, sizeof(missing)); if (PROTOCOL_SetSwitch(TX_MODULE_LAST) == 0) { //No Switch found /* missing[MULTIMOD] = MODULE_NAME[MULTIMOD]; for(int i = 0; i < MULTIMOD; i++) { if(Transmitter.module_enable[i].port == SWITCH_ADDRESS) { error = 1; printf("Disabling %s because switch wasn't found\n", MODULE_NAME[i]); missing[i] = MODULE_NAME[i]; Transmitter.module_enable[i].port = 0; } } */ } int orig_proto = Model.protocol; for(int i = 0; i < MULTIMOD; i++) { if(Transmitter.module_enable[i].port) { for(int j = 1; j < PROTOCOL_COUNT; j++) { if (get_module(j) == i) { //Try this module Model.protocol = j; PROTOCOL_Load(1); if (! PROTOCOL_LOADED) continue; int res = (long)PROTO_Cmds(PROTOCMD_RESET); if (res == 0) continue; if (res < 0) { error = 1; missing[i] = MODULE_NAME[i]; if (! (Transmitter.extra_hardware & FORCE_MODULES)) Transmitter.module_enable[i].port = 0; } break; } } } } //Put this last because the switch will not respond until after it has been initialized if (Transmitter.module_enable[MULTIMOD].port && PROTOCOL_SetSwitch(TX_MODULE_LAST) == 0) { //No Switch found error = 1; missing[MULTIMOD] = MODULE_NAME[MULTIMOD]; } Model.protocol = orig_proto; if(error) { proto_state |= PROTO_MODULEDLG; PAGE_ShowModuleDialog(missing); } else #endif //HAS_MULTIMOD_SUPPORT { PROTOCOL_Init(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(); }