2015-11-20 01:59:09 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-02-04 04:27:53 -05:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-20 01:59:09 -05:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_loadmodule.hpp"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "ff.h"
|
2016-02-04 04:27:53 -05:00
|
|
|
#include "event_m0.hpp"
|
2015-11-20 01:59:09 -05:00
|
|
|
#include "hackrf_gpio.hpp"
|
|
|
|
#include "portapack.hpp"
|
2016-01-05 14:17:55 -05:00
|
|
|
#include "portapack_shared_memory.hpp"
|
2015-11-20 01:59:09 -05:00
|
|
|
#include "hackrf_hal.hpp"
|
2016-02-04 04:27:53 -05:00
|
|
|
#include "string_format.hpp"
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2016-04-28 08:59:14 -04:00
|
|
|
#include "ui_rds.hpp"
|
|
|
|
#include "ui_xylos.hpp"
|
2016-05-13 03:34:15 -04:00
|
|
|
#include "ui_epar.hpp"
|
2016-04-28 08:59:14 -04:00
|
|
|
#include "ui_lcr.hpp"
|
2016-05-09 14:42:20 -04:00
|
|
|
#include "analog_audio_app.hpp"
|
|
|
|
#include "ui_soundboard.hpp"
|
2016-04-28 08:59:14 -04:00
|
|
|
#include "ui_debug.hpp"
|
2016-05-11 06:45:03 -04:00
|
|
|
#include "ui_closecall.hpp"
|
2016-05-09 14:42:20 -04:00
|
|
|
#include "ui_audiotx.hpp"
|
2016-07-25 10:21:27 -04:00
|
|
|
#include "ui_jammer.hpp"
|
2016-04-28 08:59:14 -04:00
|
|
|
|
2015-11-20 01:59:09 -05:00
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-06 17:19:28 -05:00
|
|
|
using namespace portapack;
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void LoadModuleView::focus() {
|
|
|
|
button_ok.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadModuleView::on_show() {
|
2016-02-06 17:19:28 -05:00
|
|
|
char md5_signature[16];
|
|
|
|
uint8_t c;
|
2016-01-05 14:17:55 -05:00
|
|
|
|
2016-02-06 17:19:28 -05:00
|
|
|
memcpy(md5_signature, (const void *)(0x10087FF0), 16);
|
|
|
|
for (c=0; c<16; c++) {
|
|
|
|
if (md5_signature[c] != _hash[c]) break;
|
|
|
|
}
|
2016-04-28 08:59:14 -04:00
|
|
|
//text_info.set(to_string_hex(*((unsigned int*)0x10087FF0), 8));
|
|
|
|
|
2016-02-06 17:19:28 -05:00
|
|
|
if (c == 16) {
|
|
|
|
text_info.set("Module already loaded :)");
|
|
|
|
_mod_loaded = true;
|
|
|
|
} else {
|
|
|
|
text_info.set("Loading module");
|
|
|
|
loadmodule();
|
|
|
|
}
|
2016-01-05 14:17:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
int LoadModuleView::load_image() {
|
|
|
|
const char magic[6] = {'P', 'P', 'M', ' ', 0x02, 0x00};
|
|
|
|
UINT bw;
|
|
|
|
uint8_t i;
|
|
|
|
uint32_t cnt;
|
|
|
|
char md5sum[16];
|
|
|
|
FILINFO modinfo;
|
|
|
|
FIL modfile;
|
|
|
|
DIR rootdir;
|
|
|
|
FRESULT res;
|
|
|
|
|
|
|
|
// Scan SD card root directory for files with the right MD5 fingerprint at the right location
|
|
|
|
if (f_opendir(&rootdir, "/") == FR_OK) {
|
|
|
|
for (;;) {
|
|
|
|
res = f_readdir(&rootdir, &modinfo);
|
|
|
|
if (res != FR_OK || modinfo.fname[0] == 0) break; // Reached last file, abort
|
|
|
|
// Only care about files with .bin extension
|
|
|
|
if ((!(modinfo.fattrib & AM_DIR)) && (modinfo.fname[9] == 'B') && (modinfo.fname[10] == 'I') && (modinfo.fname[11] == 'N')) {
|
|
|
|
res = f_open(&modfile, modinfo.fname, FA_OPEN_EXISTING | FA_READ);
|
|
|
|
if (res != FR_OK) return 0;
|
|
|
|
// Magic bytes and version check
|
|
|
|
f_read(&modfile, &md5sum, 6, &bw);
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
if (md5sum[i] != magic[i]) break;
|
|
|
|
if (i == 6) {
|
|
|
|
f_lseek(&modfile, 26);
|
|
|
|
f_read(&modfile, &md5sum, 16, &bw);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if (md5sum[i] != _hash[i]) break;
|
|
|
|
// f_read can't read more than 512 bytes at a time ?
|
|
|
|
if (i == 16) {
|
|
|
|
f_lseek(&modfile, 512);
|
|
|
|
for (cnt = 0; cnt < 64; cnt++) {
|
|
|
|
if (f_read(&modfile, reinterpret_cast<void*>(portapack::memory::map::m4_code.base() + (cnt * 512)), 512, &bw)) return 0;
|
|
|
|
}
|
|
|
|
f_close(&modfile);
|
|
|
|
f_closedir(&rootdir);
|
|
|
|
LPC_RGU->RESET_CTRL[0] = (1 << 13);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_close(&modfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_closedir(&rootdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:17:55 -05:00
|
|
|
void LoadModuleView::loadmodule() {
|
2016-07-26 21:03:40 -04:00
|
|
|
//baseband::shutdown();
|
2016-02-06 17:19:28 -05:00
|
|
|
|
|
|
|
/*EventDispatcher::message_map().register_handler(Message::ID::ReadyForSwitch,
|
2015-11-20 01:59:09 -05:00
|
|
|
[this](Message* const p) {
|
2016-02-06 17:19:28 -05:00
|
|
|
(void)p;*/
|
2016-02-04 04:27:53 -05:00
|
|
|
if (load_image()) {
|
|
|
|
text_infob.set("Module loaded :)");
|
2015-11-20 01:59:09 -05:00
|
|
|
_mod_loaded = true;
|
|
|
|
} else {
|
|
|
|
text_info.set("Module not found :(");
|
|
|
|
_mod_loaded = false;
|
|
|
|
}
|
2016-02-06 17:19:28 -05:00
|
|
|
// }
|
|
|
|
//);
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadModuleView::LoadModuleView(
|
|
|
|
NavigationView& nav,
|
|
|
|
const char * hash,
|
2016-05-11 06:45:03 -04:00
|
|
|
ViewID viewid
|
2015-11-20 01:59:09 -05:00
|
|
|
)
|
|
|
|
{
|
2016-05-11 06:45:03 -04:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2015-11-20 01:59:09 -05:00
|
|
|
&text_info,
|
2016-02-04 04:27:53 -05:00
|
|
|
&text_infob,
|
2015-11-20 01:59:09 -05:00
|
|
|
&button_ok
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
_hash = hash;
|
2016-05-11 06:45:03 -04:00
|
|
|
|
|
|
|
button_ok.on_select = [this, &nav, viewid](Button&){
|
|
|
|
nav.pop();
|
2016-04-28 08:59:14 -04:00
|
|
|
if (_mod_loaded == true) {
|
2016-05-11 06:45:03 -04:00
|
|
|
if (viewid == AudioTX) nav.push<AudioTXView>();
|
|
|
|
if (viewid == Xylos) nav.push<XylosView>();
|
2016-05-13 03:34:15 -04:00
|
|
|
if (viewid == EPAR) nav.push<EPARView>();
|
2016-05-11 06:45:03 -04:00
|
|
|
if (viewid == LCR) nav.push<LCRView>();
|
|
|
|
if (viewid == SoundBoard) nav.push<SoundBoardView>();
|
|
|
|
if (viewid == AnalogAudio) nav.push<AnalogAudioView>();
|
|
|
|
if (viewid == RDS) nav.push<RDSView>();
|
|
|
|
if (viewid == CloseCall) nav.push<CloseCallView>();
|
|
|
|
if (viewid == Receiver) nav.push<ReceiverMenuView>();
|
2016-07-25 10:21:27 -04:00
|
|
|
if (viewid == Jammer) nav.push<JammerView>();
|
2016-04-28 08:59:14 -04:00
|
|
|
}
|
2015-11-20 01:59:09 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|