1
0
mirror of https://github.com/peterantypas/maiana.git synced 2025-05-28 05:10:40 -07:00

Multiplexing to single UART

This commit is contained in:
Peter Antypas 2016-06-07 15:38:10 -07:00
parent 2c114fd11f
commit dcf4fdd6e5
9 changed files with 87 additions and 16 deletions

View File

@ -360,5 +360,12 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/ais_transponder"/>
</configuration>
<configuration configurationName="Release">
<resource resourceType="PROJECT" workspacePath="/ais_transponder"/>
</configuration>
</storageModule>
</cproject>

View File

@ -111,6 +111,25 @@ void write_char(USART_TypeDef* USARTx, char c)
USART_SendData(USARTx, c);
}
#ifdef MULTIPLEXED_OUTPUT
void DataTerminal::write(const char *cls, const char* s, bool interactive)
{
if ( mInteractive && !interactive )
return;
write_char(USART3, '[');
for ( size_t i = 0; i < strlen(cls); ++i )
write_char(USART3, cls[i]);
write_char(USART3, ']');
for ( int i = 0; s[i] != 0; ++i )
write_char(USART3, s[i]);
}
#else
void DataTerminal::write(const char* s, bool interactive)
{
if ( mInteractive && !interactive )
@ -119,6 +138,7 @@ void DataTerminal::write(const char* s, bool interactive)
for ( int i = 0; s[i] != 0; ++i )
write_char(USART3, s[i]);
}
#endif
void DataTerminal::clearScreen()
{
@ -128,7 +148,11 @@ void DataTerminal::clearScreen()
void DataTerminal::_write(const char *s)
{
#ifdef MULTIPLEXED_OUTPUT
write("", s, true);
#else
write(s, true);
#endif
}
void DataTerminal::showScreen(MenuScreen screen)

View File

@ -21,8 +21,11 @@ public:
void init();
void processEvent(Event *e);
#ifdef MULTIPLEXED_OUTPUT
void write(const char* cls, const char* line, bool interactive=false);
#else
void write(const char* line, bool interactive = false);
#endif
void processCharacter(char c);
private:
DataTerminal();

View File

@ -248,7 +248,11 @@ void GPS::parseSentence(const char *buff)
if ( sentence.code().find("RMC") == 2 ) {
#ifdef ENABLE_TERMINAL
#ifdef OUTPUT_GPS_NMEA
DataTerminal::instance().write(buff);
#ifdef MULTIPLEXED_OUTPUT
DataTerminal::instance().write("NMEA", buff);
#else
DataTerminal::instance().write(buff);
#endif
#endif
#endif

View File

@ -16,6 +16,7 @@
#include "printf2.h"
#include "AISChannels.h"
static char __buff[100];
RXPacketProcessor::RXPacketProcessor ()
: mLastDumpTime(0), mGoodCount(0), mBadCRCCount(0), mInvalidCount(0), mLat(-200), mLng(-200)
@ -48,8 +49,10 @@ void RXPacketProcessor::processEvent(Event *e)
else if ( pe->mTime - mLastDumpTime >= 60 ) {
mLastDumpTime = pe->mTime;
float yield = (float)mGoodCount / (float)(mGoodCount+mBadCRCCount+mInvalidCount);
printf2("\n[Yield: %.1fpct, Valid: %d, Wrong CRC: %d, Malformed: %d]\r\n", yield*100.0, mGoodCount, mBadCRCCount, mInvalidCount);
printf2("[Unique MMSIs: %d]\r\n\n", mUniqueMMSIs.size());
printf2("\r\n");
printf2("[Yield: %.1fpct, Valid: %d, Wrong CRC: %d, Malformed: %d]\r\n", yield*100.0, mGoodCount, mBadCRCCount, mInvalidCount);
printf2("[Unique MMSIs: %d]\r\n", mUniqueMMSIs.size());
printf2("\r\n");
mUniqueMMSIs.clear();
mBadCRCCount = 0;
mInvalidCount = 0;
@ -125,8 +128,13 @@ void RXPacketProcessor::processEvent(Event *e)
mSentences.clear();
mEncoder.encode(*pe->mPacket, mSentences);
for (vector<string>::iterator i = mSentences.begin(); i != mSentences.end(); ++i) {
#ifdef MULTIPLEXED_OUTPUT
sprintf(__buff, "%s\r\n", i->c_str());
DataTerminal::instance().write("NMEA", __buff);
#else
DataTerminal::instance().write(i->c_str());
DataTerminal::instance().write("\r\n");
#endif
}
#endif
switch (pe->mPacket->messageType()) {

View File

@ -132,8 +132,10 @@ void TXScheduler::processEvent(Event *event)
void TXScheduler::scheduleTestPacket()
{
/*
TXPacket *p = TXPacketPool::instance().newTXPacket(AIS_CHANNELS[rand() % 2 + 18].vhf, mUTC);
VHFChannel channel = CH_84;
if ( rand() % 2 == 0 )
channel = CH_85;
TXPacket *p = TXPacketPool::instance().newTXPacket(channel, mUTC);
if ( !p )
return;
@ -141,7 +143,6 @@ void TXScheduler::scheduleTestPacket()
p->addBit(rand() % 2);
}
RadioManager::instance().scheduleTransmission(p);
*/
}

View File

@ -31,12 +31,12 @@
#ifdef CALIBRATION_MODE
#define TX_POWER_LEVEL PWR_M16
#define TX_POWER_LEVEL PWR_M10
#else
#ifdef TX_TEST_MODE
#define TX_POWER_LEVEL PWR_P16
#define TX_POWER_LEVEL PWR_P27
#else
#define TX_POWER_LEVEL PWR_M27
#define TX_POWER_LEVEL PWR_M10
#endif
#endif
@ -77,5 +77,16 @@
// Extra debugging using halting assertions
#define DEV_MODE 1
/*
* Defining this symbol forces all output (NMEA + printf2 + LED status) to the high-speed UART3 for tunneling to an application that demuxes it.
* Multiplexed output is still ASCII, but every line of text begins with a message class in square brackets. Examples:
*
* [NMEA]!AIVDM,....
* [DEBUG]GPS Initialized
* [LED]0:BLINK
* [ASSERT]...
*
*/
#define MULTIPLEXED_OUTPUT 1
#endif /* GLOBALS_H_ */

View File

@ -95,10 +95,10 @@ main(int argc, char* argv[])
RadioManager::instance().init();
RadioManager::instance().transmitCW(CH_86);
#elif defined TX_TEST_MODE
Radio::instance().init();
RadioManager::instance().init();
GPS::instance().init();
Radio::instance().start();
Radio::instance().startReceiving(4);
RadioManager::instance().start();
//Radio::instance().startReceiving(4);
txScheduler.startTXTesting();
#else
RXPacketProcessor packetProcessor;

View File

@ -11,12 +11,15 @@
#include <stdlib.h>
#include "Events.hpp"
#include "Utils.hpp"
#include "globals.h"
#include "EventQueue.hpp"
#include <diag/Trace.h>
#include "DataTerminal.hpp"
void printf2_Init(int baudrate)
{
#ifndef MULTIPLEXED_OUTPUT
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
@ -34,10 +37,11 @@ void printf2_Init(int baudrate)
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
#endif
}
#ifndef MULTIPLEXED_OUTPUT
void USART_putc(USART_TypeDef* USARTx, char c)
{
while (!(USARTx->ISR & 0x00000040))
@ -45,11 +49,13 @@ void USART_putc(USART_TypeDef* USARTx, char c)
USART_SendData(USARTx, c);
}
void USART_puts(USART_TypeDef* USARTx, const char *s)
{
for ( int i = 0; s[i] != 0; ++i )
USART_putc(USARTx, s[i]);
}
#endif
static char __buffer[256];
@ -59,13 +65,16 @@ void printf2_now(const char *format, ...)
va_start(list, format);
vsnprintf(__buffer, 255, format, list);
va_end(list);
#ifdef MULTIPLEXED_OUTPUT
DataTerminal::instance().write("DEBUG", __buffer);
#else
USART_puts(USART2, __buffer);
#endif
}
#ifdef ENABLE_PRINTF2
void printf2(const char *format, ...)
{
if ( Utils::inISR() ) {
DebugEvent *e = static_cast<DebugEvent*>(EventPool::instance().newEvent(DEBUG_EVENT));
if ( e == NULL )
@ -83,7 +92,11 @@ void printf2(const char *format, ...)
va_start(list, format);
vsnprintf(__buffer, 255, format, list);
va_end(list);
#ifdef MULTIPLEXED_OUTPUT
DataTerminal::instance().write("DEBUG", __buffer);
#else
USART_puts(USART2, __buffer);
#endif
}
}
#else