auto-sync
This commit is contained in:
parent
8c9a3e69ff
commit
7942bce89b
|
@ -21,6 +21,7 @@
|
|||
#include "main.h"
|
||||
#include "console_io.h"
|
||||
#include "rfiutil.h"
|
||||
#include "tunerstudio.h"
|
||||
|
||||
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
|
||||
#include "usbcfg.h"
|
||||
|
@ -99,6 +100,11 @@ static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size)
|
|||
*p = 0;
|
||||
return false;
|
||||
}
|
||||
if (c == '\n') {
|
||||
consolePutChar('\n');
|
||||
*p = 0;
|
||||
return false;
|
||||
}
|
||||
if (c < 0x20) {
|
||||
continue;
|
||||
}
|
||||
|
@ -151,6 +157,10 @@ bool isConsoleReady(void) {
|
|||
|
||||
bool_t consoleInBinaryMode = false;
|
||||
|
||||
ts_channel_s binaryConsole;
|
||||
|
||||
uint8_t buffer[DL_OUTPUT_BUFFER];
|
||||
|
||||
static THD_WORKING_AREA(consoleThreadStack, 2 * UTILITY_THREAD_STACK_SIZE);
|
||||
static msg_t consoleThreadThreadEntryPoint(void *arg) {
|
||||
(void) arg;
|
||||
|
@ -165,6 +175,10 @@ static msg_t consoleThreadThreadEntryPoint(void *arg) {
|
|||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
binaryConsole.channel = (BaseChannel *) getConsoleChannel();
|
||||
// todo: clean this spot!
|
||||
binaryConsole.writeBuffer = buffer;
|
||||
|
||||
while (true) {
|
||||
efiAssert(getRemainingStack(chThdSelf()) > 256, "lowstck#9e", 0);
|
||||
bool end = getConsoleLine((BaseSequentialStream*) getConsoleChannel(), consoleInput, sizeof(consoleInput));
|
||||
|
@ -174,6 +188,11 @@ static msg_t consoleThreadThreadEntryPoint(void *arg) {
|
|||
}
|
||||
|
||||
(console_line_callback)(consoleInput);
|
||||
|
||||
if (consoleInBinaryMode) {
|
||||
// switch to binary protocol
|
||||
runBinaryProtocolLoop(&binaryConsole);
|
||||
}
|
||||
}
|
||||
#if defined __GNUC__
|
||||
return false;
|
||||
|
@ -233,7 +252,7 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
|
|||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
chThdCreateStatic(consoleThreadStack, sizeof(consoleThreadStack), NORMALPRIO, consoleThreadThreadEntryPoint, NULL);
|
||||
addConsoleAction("~", switchToBinaryProtocol);
|
||||
addConsoleAction(BINARY_COMMAND, switchToBinaryProtocol);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#include <string.h>
|
||||
#include "engine_configuration.h"
|
||||
#include "svnversion.h"
|
||||
#include "loggingcentral.h"
|
||||
|
||||
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
||||
|
||||
|
@ -400,6 +401,11 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
|
|||
|
||||
uint32_t incomingPacketSize = firstByte * 256 + secondByte;
|
||||
|
||||
if(incomingPacketSize==BINARY_SWITCH_TAG) {
|
||||
// we are here if we get a binary switch request while already in binary mode. We will just ignore it.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(tsChannel->crcReadBuffer) - CRC_WRAPPING_SIZE)) {
|
||||
scheduleMsg(tsLogger, "TunerStudio: invalid size: %d", incomingPacketSize);
|
||||
tunerStudioError("ERROR: CRC header size");
|
||||
|
@ -530,6 +536,13 @@ void handleTestCommand(ts_channel_s *tsChannel) {
|
|||
|
||||
extern CommandHandler console_line_callback;
|
||||
|
||||
static void handleGetText(ts_channel_s *tsChannel) {
|
||||
int outputSize;
|
||||
char *output = swapOutputBuffers(&outputSize);
|
||||
|
||||
tunerStudioWriteCrcPacket(tsChannel, TS_RESPONSE_COMMAND_OK, output, outputSize);
|
||||
}
|
||||
|
||||
static void handleExecuteCommand(ts_channel_s *tsChannel, char *data, int incomingPacketSize) {
|
||||
tunerStudioWriteCrcPacket(tsChannel, TS_RESPONSE_COMMAND_OK, NULL, 0);
|
||||
data[incomingPacketSize] = 0;
|
||||
|
@ -613,6 +626,8 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin
|
|||
if (command == TS_HELLO_COMMAND || command == TS_HELLO_COMMAND_DEPRECATED) {
|
||||
tunerStudioDebug("got Query command");
|
||||
handleQueryCommand(tsChannel, TS_CRC);
|
||||
} else if (command == TS_GET_TEXT) {
|
||||
handleGetText(tsChannel);
|
||||
} else if (command == TS_EXECUTE) {
|
||||
handleExecuteCommand(tsChannel, data, incomingPacketSize);
|
||||
} else if (command == TS_OUTPUT_COMMAND) {
|
||||
|
|
|
@ -53,6 +53,7 @@ void requestBurn(void);
|
|||
|
||||
void startTunerStudioConnectivity(Logging *sharedLogger);
|
||||
void syncTunerStudioCopy(void);
|
||||
void runBinaryProtocolLoop(ts_channel_s *tsChannel);
|
||||
|
||||
#if defined __GNUC__
|
||||
// GCC
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#endif
|
||||
|
||||
// that's hex for "~\n", see
|
||||
#define BINARY_SWITCH_TAG 0x7e0d
|
||||
#define BINARY_SWITCH_TAG 0x7e0a
|
||||
#define BINARY_COMMAND "~"
|
||||
|
||||
#define PROTOCOL "001"
|
||||
|
|
|
@ -267,7 +267,7 @@ void firmwareError(const char *errorMsg, ...) {
|
|||
}
|
||||
}
|
||||
|
||||
static char UNUSED_RAM_SIZE[9999];
|
||||
static char UNUSED_RAM_SIZE[2999];
|
||||
|
||||
static char UNUSED_CCM_SIZE[4900] CCM_OPTIONAL;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <stdbool.h>
|
||||
#include "main.h"
|
||||
|
||||
#if ! EFI_UNIT_TEST
|
||||
#if ! EFI_UNIT_TEST || defined(__DOXYGEN__)
|
||||
#include "chprintf.h"
|
||||
#include "chmtx.h"
|
||||
#include "memstreams.h"
|
||||
|
|
|
@ -92,12 +92,16 @@ char * swapOutputBuffers(int *actualOutputBufferSize) {
|
|||
return outputBuffer;
|
||||
}
|
||||
|
||||
extern bool_t consoleInBinaryMode;
|
||||
|
||||
/**
|
||||
* This method actually sends all the pending data to the communication layer.
|
||||
* This method is invoked by the main thread - that's the only thread which should be sending
|
||||
* actual data to console in order to avoid concurrent access to serial hardware.
|
||||
*/
|
||||
void printPending(void) {
|
||||
if (consoleInBinaryMode)
|
||||
return;
|
||||
int actualOutputBufferSize;
|
||||
char *output = swapOutputBuffers(&actualOutputBufferSize);
|
||||
|
||||
|
|
|
@ -53,6 +53,11 @@ public class BinaryProtocol {
|
|||
serialPort.addEventListener(new SerialPortReader(serialPort, listener));
|
||||
}
|
||||
|
||||
void switchToBinaryProtocol() throws SerialPortException, EOFException, InterruptedException {
|
||||
// while (true)
|
||||
serialPort.writeBytes("~\n".getBytes());
|
||||
}
|
||||
|
||||
public void burnChanges(ConfigurationImage newVersion, Logger logger) throws InterruptedException, EOFException, SerialPortException {
|
||||
ConfigurationImage current = getController();
|
||||
// let's have our own copy which no one would be able to change
|
||||
|
@ -101,7 +106,9 @@ public class BinaryProtocol {
|
|||
|
||||
int packetSize = BinaryProtocol.swap16(cbb.getShort());
|
||||
logger.trace("Got packet size " + packetSize);
|
||||
if (packetSize < 0 || packetSize > 300) {
|
||||
if (packetSize < 0
|
||||
// || packetSize > 300
|
||||
) {
|
||||
// invalid packet size
|
||||
return null;
|
||||
}
|
||||
|
@ -263,4 +270,11 @@ public class BinaryProtocol {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void requestText() throws InterruptedException, EOFException, SerialPortException {
|
||||
byte[] response = exchange(new byte[]{'G'});
|
||||
if (response != null && response.length == 1)
|
||||
Thread.sleep(100);
|
||||
System.out.println(new String(response));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SerialPortReader implements SerialPortEventListener {
|
|||
e.printStackTrace(System.err);
|
||||
}
|
||||
} else {
|
||||
FileLog.rlog("SerialPortReader serialEvent " + spe);
|
||||
FileLog.rlog("less expected SerialPortReader serialEvent " + spe);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue