Multiple changes.

- Implement parser for embedded APRS message commands.
- Update board definitions.
- Only lock USB for radio id USB active.
- Blue LED blinks on packet decode or fast blinks if paused.
- Revise ublox CSUM implementation.
- Minor TRACE text changes.
pull/4/head
CInsights 2018-04-17 18:04:27 +10:00
rodzic 234772dc2c
commit 07cbb83c7f
16 zmienionych plików z 871 dodań i 347 usunięć

Wyświetl plik

@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1072336591835851262" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="185104218123605097" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

Wyświetl plik

@ -253,7 +253,7 @@ CPPWARN = -Wall -Wextra -Wundef
# List all user C define here, like -D_DEBUG=1
UDEFS = -D_GNU_SOURCE -DARM_MATH_CM4 -DSHELL_CMD_TEST_ENABLED=0 \
-DSHELL_CMD_EXIT_ENABLED=1 -DUSB_TRACE_LEVEL=4 \
-DSHELL_CMD_EXIT_ENABLED=1 -DUSB_TRACE_LEVEL=5 \
-DSHELL_CMD_MEM_ENABLED=0
# -DDISABLE_HW_WATCHDOG=1

Wyświetl plik

@ -297,7 +297,7 @@
// USB
#define LINE_USB_ID PAL_LINE(GPIOA, 10U)
#define LINE_USB_VUSB PAL_LINE(GPIOA, 9U)
#define LINE_USB_VUSB PAL_LINE(GPIOA, 9U)
#define LINE_USB_DM PAL_LINE(GPIOA, 11U)
#define LINE_USB_DP PAL_LINE(GPIOA, 12U)

Wyświetl plik

@ -13,7 +13,7 @@ const conf_t conf_flash_default = {
.thread_conf = {
.active = true,
.cycle = TIME_S2I(60*30),
.init_delay = TIME_S2I(10)
.init_delay = TIME_S2I(30)
},
.radio_conf = {
.pwr = 0x7F,
@ -56,9 +56,9 @@ const conf_t conf_flash_default = {
.img_pri = {
.thread_conf = {
.active = true,
.cycle = TIME_S2I(60*30),
.init_delay = TIME_S2I(60*1),
.send_spacing = TIME_S2I(10)
.cycle = TIME_S2I(60*5),
.init_delay = TIME_S2I(60*5),
.send_spacing = TIME_S2I(5)
},
.radio_conf = {
.pwr = 0x7F,
@ -141,7 +141,11 @@ const conf_t conf_flash_default = {
},
.call = "VK2GJ-5",
.path = "WIDE2-1",
.symbol = SYM_DIGIPEATER
.symbol = SYM_DIGIPEATER,
.fixed = true,
.lat = -337331175,
.lon = 1511143478,
.alt = 144
},
.base = { // The base station parameters - how and where tracker originated messages are sent
.enabled = true,

Wyświetl plik

@ -978,24 +978,26 @@ void vsync_cb(void *arg) {
* Other drivers using resources that can cause DMA competition are locked.
*/
msg_t OV5640_LockResourcesForCapture(void) {
I2C_Lock();
msg_t msg = pktAcquireRadio(PKT_RADIO_1, TIME_INFINITE);
if(msg != MSG_OK) {
return msg;
}
I2C_Lock();
pktPauseReception(PKT_RADIO_1);
//chMtxLock(&trace_mtx);
/* Hold TRACE output on USB. */
if(isUSBactive())
chMtxLock(&trace_mtx);
return MSG_OK;
/* FIXME: USB has to be locked? */
}
/*
* Unlock competing drivers.
*/
void OV5640_UnlockResourcesForCapture(void) {
/* FIXME: USB has to be unlocked? */
//chMtxUnlock(&trace_mtx);
/* Re-enable TRACE output on USB. */
if(isUSBactive())
chMtxUnlock(&trace_mtx);
I2C_Unlock();
pktResumeReception(PKT_RADIO_1);
pktReleaseRadio(PKT_RADIO_1);

Wyświetl plik

@ -26,21 +26,20 @@ const SerialConfig gps_config =
/**
* Transmits a string of bytes to the GPS
*/
void gps_transmit_string(uint8_t *cmd, uint8_t length)
{
#if defined(UBLOX_USE_I2C)
I2C_writeN(UBLOX_MAX_ADDRESS, cmd, length);
#elif defined(UBLOX_USE_UART)
sdWrite(&SD5, cmd, length);
#endif
void gps_transmit_string(uint8_t *cmd, uint8_t length) {
gps_calc_ubx_csum(cmd, length);
#if defined(UBLOX_USE_I2C)
I2C_writeN(UBLOX_MAX_ADDRESS, cmd, length);
#elif defined(UBLOX_USE_UART)
sdWrite(&SD5, cmd, length);
#endif
}
/**
* Receives a single byte from the GPS and assigns to supplied pointer.
* Returns false is there is no byte available else true
*/
bool gps_receive_byte(uint8_t *data)
{
bool gps_receive_byte(uint8_t *data) {
#if defined(UBLOX_USE_I2C)
uint16_t len;
I2C_read16(UBLOX_MAX_ADDRESS, 0xFD, &len);
@ -190,7 +189,7 @@ bool gps_get_fix(gpsFix_t *fix) {
static uint8_t navstatus[32];
// Transmit request
uint8_t navpvt_req[] = {0xB5, 0x62, 0x01, 0x07, 0x00, 0x00, 0x08, 0x19};
uint8_t navpvt_req[] = {0xB5, 0x62, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00};
gps_transmit_string(navpvt_req, sizeof(navpvt_req));
if(!gps_receive_payload(0x01, 0x07, navpvt, 3000)) { // Receive request
@ -198,7 +197,7 @@ bool gps_get_fix(gpsFix_t *fix) {
return false;
}
uint8_t navstatus_req[] = {0xB5, 0x62, 0x01, 0x03, 0x00, 0x00, 0x04, 0x0D};
uint8_t navstatus_req[] = {0xB5, 0x62, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00};
gps_transmit_string(navstatus_req, sizeof(navstatus_req));
if(!gps_receive_payload(0x01, 0x03, navstatus, 3000)) { // Receive request
@ -250,13 +249,22 @@ bool gps_get_fix(gpsFix_t *fix) {
fix->time.second = navpvt[10];
fix->lat = (int32_t) (
(uint32_t)(navpvt[28]) + ((uint32_t)(navpvt[29]) << 8) + ((uint32_t)(navpvt[30]) << 16) + ((uint32_t)(navpvt[31]) << 24)
(uint32_t)(navpvt[28])
+ ((uint32_t)(navpvt[29]) << 8)
+ ((uint32_t)(navpvt[30]) << 16)
+ ((uint32_t)(navpvt[31]) << 24)
);
fix->lon = (int32_t) (
(uint32_t)(navpvt[24]) + ((uint32_t)(navpvt[25]) << 8) + ((uint32_t)(navpvt[26]) << 16) + ((uint32_t)(navpvt[27]) << 24)
(uint32_t)(navpvt[24])
+ ((uint32_t)(navpvt[25]) << 8)
+ ((uint32_t)(navpvt[26]) << 16)
+ ((uint32_t)(navpvt[27]) << 24)
);
int32_t alt_tmp = (((int32_t)
((uint32_t)(navpvt[36]) + ((uint32_t)(navpvt[37]) << 8) + ((uint32_t)(navpvt[38]) << 16) + ((uint32_t)(navpvt[39]) << 24))
((uint32_t)(navpvt[36])
+ ((uint32_t)(navpvt[37]) << 8)
+ ((uint32_t)(navpvt[38]) << 16)
+ ((uint32_t)(navpvt[39]) << 24))
) / 1000);
if (alt_tmp <= 0) {
fix->alt = 1;
@ -298,7 +306,6 @@ uint8_t gps_disable_nmea_output(void) {
0x00, 0x00 // CRC place holders
};
gps_calc_ubx_csum(nonmea, sizeof(nonmea));
gps_transmit_string(nonmea, sizeof(nonmea));
return gps_receive_ack(0x06, 0x00, 1000);
}
@ -338,7 +345,6 @@ uint8_t gps_set_airborne_model(void) {
0x00, 0x00 // CRC place holders
};
gps_calc_ubx_csum(model6, sizeof(model6));
gps_transmit_string(model6, sizeof(model6));
return gps_receive_ack(0x06, 0x24, 1000);
}
@ -369,7 +375,6 @@ uint8_t gps_set_power_save(void) {
0x00, 0x00 // CRC place holders
};
gps_calc_ubx_csum(powersave, sizeof(powersave));
gps_transmit_string(powersave, sizeof(powersave));
return gps_receive_ack(0x06, 0x3B, 1000);
}
@ -386,7 +391,6 @@ uint8_t gps_power_save(int on) {
0x00, 0x00 // CRC place holders
};
gps_calc_ubx_csum(recvmgmt, sizeof(recvmgmt));
gps_transmit_string(recvmgmt, sizeof(recvmgmt));
return gps_receive_ack(0x06, 0x11, 1000);
}
@ -448,14 +452,15 @@ void GPS_Deinit(void)
/*
* Calculate checksum and inserts into buffer.
* Calling function must allocate space in message buff for csum.
*
*/
bool gps_calc_ubx_csum(uint8_t *mbuf, uint16_t mlen) {
uint16_t i;
uint8_t ck_a = 0, ck_b = 0;
/* Counting sync bytes there must be at least one byte to checksum. */
if(mlen < 5)
/* Counting sync bytes there must be at least one byte to checksum. */
return false;
for (i = 2; i < mlen - 2; i++) {

Wyświetl plik

@ -241,10 +241,10 @@ void usb_cmd_send_aprs_message(BaseSequentialStream *chp, int argc, char *argv[]
chprintf(chp, "Message: %s\r\n", m);
/* Send with ack request (last arg false). */
/* Send with ack request (last arg true). */
packet_t packet = aprs_encode_message(conf_sram.aprs.tx.call,
conf_sram.aprs.tx.path,
argv[0], m, false);
argv[0], m, true);
if(packet == NULL) {
TRACE_WARN("CMD > No free packet objects");
return;
@ -258,9 +258,5 @@ void usb_cmd_send_aprs_message(BaseSequentialStream *chp, int argc, char *argv[]
conf_sram.aprs.tx.radio_conf.rssi);
chprintf(chp, "Message sent!\r\n");
/*
(void)argc;
(void)argv;
chprintf(chp, "TODO: Not implemented\r\n");*/
}

Wyświetl plik

@ -18,12 +18,10 @@ int main(void) {
// Init debugging (Serial debug port, LEDs)
DEBUG_INIT();
// This won't actually display since USB isn't initialized yet.
TRACE_INFO("MAIN > Startup");
/*
* Setup buffers in CCM if available.
* Setup IO device arbitration.
* Setup packet primary data.
*/
bool pkt = pktSystemInit();
@ -43,6 +41,8 @@ int main(void) {
startUSB();
#endif
TRACE_INFO("MAIN > Startup");
// Startup threads
start_essential_threads(); // Startup required modules (tracking manager, watchdog)
start_user_threads(); // Startup optional modules (eg. POSITION, LOG, ...)

Wyświetl plik

@ -642,11 +642,11 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
/* Activity LED blink rate scaling variable. */
uint16_t led_count = 0;
#define DECODER_WAIT_TIME 200U /* 200mS. */
#define DECODER_IDLE_TIME 2000U /* 2000uS. */
#define DECODER_WAIT_TIME 100U /* 100mS. */
//#define DECODER_IDLE_TIME 2000U /* 2000uS. */
#define DECODER_POLL_TIME 10U /* 10mS. */
#define DECODER_LED_RATE_POLL 100U /* 1000uS. */
#define DECODER_ACTIVE_TIMEOUT 5U /* 5mS. */
//#define DECODER_LED_RATE_POLL 100U /* 1000uS. */
//#define DECODER_ACTIVE_TIMEOUT 5U /* 5mS. */
#define DECODER_SUSPEND_TIME 2000U /* 2000uS. */
#define DECODER_LED_RATE_SUSPEND 250U /* Blink at 250mS during suspend. */
@ -693,6 +693,7 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
/* Something went wrong if we arrive here. */
chSysHalt("ThdExit");
}
/* Toggle decoder LED in wait state. */
pktWriteDecoderLED(PAL_TOGGLE);
continue;
}
@ -723,12 +724,15 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
TIME_MS2I(DECODER_POLL_TIME));
if(fifo_msg != MSG_OK) {
if(++led_count >= DECODER_LED_RATE_POLL) {
/* Toggle decoder LED. */
/* if(++led_count >= DECODER_LED_RATE_POLL) {
Toggle decoder LED.
pktWriteDecoderLED(PAL_TOGGLE);
led_count = 0;
}
/* No FIFO object posted so loop again. */
}*/
/*
* No FIFO object posted so loop.
* Go back through IDLE and check for STOP event.
*/
myDriver->decoder_state = DECODER_IDLE;
break;
}
@ -796,8 +800,9 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
byte_packed_pwm_t data;
size_t n = iqReadTimeout(myQueue, data.bytes,
sizeof(packed_pwm_counts_t),
TIME_MS2I(DECODER_ACTIVE_TIMEOUT));
/* TODO: Timeout to be calculated from SYMBOL time x (8?). */
chTimeUS2I(833 * 8)
/*TIME_MS2I(DECODER_ACTIVE_TIMEOUT)*/);
/* Timeout calculated as SYMBOL time x 8. */
if(n == sizeof(packed_pwm_counts_t)) {
array_min_pwm_counts_t radio;

Wyświetl plik

@ -589,7 +589,7 @@ static bool Si446x_transmit(radio_unit_t radio,
}
/* Try to get clear channel. */
TRACE_INFO( "SI > Wait maximum of %.1f seconds for clear channel on"
TRACE_INFO( "SI > Run CCA for %.1f seconds on"
" %d.%03d MHz",
(float32_t)(TIME_I2MS(cca_timeout) / 1000),
op_freq/1000000, (op_freq%1000000)/1000);
@ -601,7 +601,7 @@ static bool Si446x_transmit(radio_unit_t radio,
chThdSleep(TIME_MS2I(1));
}
/* Clear channel timing. */
TRACE_INFO( "SI > CCA time = %d milliseconds",
TRACE_INFO( "SI > CCA completed in %d milliseconds",
chTimeI2MS(chVTTimeElapsedSinceX(t0)));
}

Wyświetl plik

@ -21,8 +21,8 @@
#define PKT_SEND_BUFFER_SEM_NAME "pbsem"
#define PKT_CALLBACK_WA_SIZE 8192
#define PKT_TERMINATOR_WA_SIZE 1024
#define PKT_CALLBACK_WA_SIZE (1024 * 10)
#define PKT_TERMINATOR_WA_SIZE (1024 * 1)
/*===========================================================================*/
/* Module data structures and types. */

Wyświetl plik

@ -67,6 +67,7 @@
#endif
//#define LINE_PWM_MIRROR PAL_LINE(GPIOA, 8U)
#define LINE_GPIO_PIN PAL_LINE(GPIOA, 8U)
/**
* ICU related definitions.

Wyświetl plik

@ -40,8 +40,8 @@
#define ORIGIN_OTHER_TRACKER 0x6
#define ORIGIN_DIGIPEATER_CONVERSION 0x7
#define APRS_DEST_CALLSIGN "APECAN" // APExxx = Pecan device
#define APRS_DEST_SSID 0
#define APRS_DEVICE_CALLSIGN "APECAN" // APExxx = Pecan device
//#define APRS_DEST_SSID 0
#define SYM_BALLOON 0x2F4F
#define SYM_SMALLAIRCRAFT 0x2F27
@ -50,17 +50,74 @@
#define SYM_SHIP 0x2F73
#define SYM_DIGIPEATER 0x2F23
#define APRS_HEARD_LIST_SIZE 20
#define APRS_MAX_MSG_ARGUMENTS 10
typedef struct APRSIdentity {
char num[8];
char src[AX25_MAX_ADDR_LEN];
char call[AX25_MAX_ADDR_LEN];
char path[16];
uint16_t symbol;
uint32_t freq;
uint8_t pwr;
mod_t mod;
uint8_t rssi;
} aprs_identity_t;
/**
* @brief Command handler function type.
*/
typedef msg_t (*aprscmd_t)(aprs_identity_t *id, int argc, char *argv[]);
/**
* @brief APRS command entry type.
*/
typedef struct {
const char *ac_name; /**< @brief Command name. */
aprscmd_t ac_function; /**< @brief Command function. */
} APRSCommand;
/* Temporary. Will be deprecated when fixed station feature is implemented. */
extern bool test_gps_enabled;
void aprs_debug_getPacket(packet_t pp, char* buf, uint32_t len);
packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t symbol, dataPoint_t *dataPoint);
packet_t aprs_encode_telemetry_configuration(const char *callsign, const char *path, uint8_t type);
packet_t aprs_encode_message(const char *callsign, const char *path, const char *receiver, const char *text, const bool noCounter);
packet_t aprs_encode_data_packet(const char *callsign, const char *path, char packetType, uint8_t *data);
packet_t aprs_encode_query_answer_aprsd(const char *callsign, const char *path, const char *receiver);
void aprs_decode_packet(packet_t pp);
#ifdef __cplusplus
extern "C" {
#endif
void aprs_debug_getPacket(packet_t pp, char* buf, uint32_t len);
packet_t aprs_encode_position(const char *callsign, const char *path,
uint16_t symbol, dataPoint_t *dataPoint);
packet_t aprs_encode_telemetry_configuration(const char *callsign,
const char *path, uint8_t type);
packet_t aprs_encode_message(const char *callsign, const char *path,
const char *receiver, const char *text,
const bool ack);
packet_t aprs_encode_data_packet(const char *callsign, const char *path,
char packetType, uint8_t *data);
packet_t aprs_compose_aprsd_message(const char *callsign, const char *path,
const char *receiver);
void aprs_decode_packet(packet_t pp);
msg_t aprs_send_position_beacon(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_send_aprsd_message(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_send_aprsh_message(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_handle_gpio_command(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_handle_gps_command(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_execute_config_command(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_execute_config_save(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_execute_img_command(aprs_identity_t *id,
int argc, char *argv[]);
msg_t aprs_execute_system_reset(aprs_identity_t *id,
int argc, char *argv[]);
#ifdef __cplusplus
}
#endif
#endif

Wyświetl plik

@ -61,17 +61,23 @@ THD_FUNCTION(posThread, arg)
chThdSleep(TIME_S2I(5));
}
// Encode/Transmit APRSD packet
/*
* This is a tracker originated message (not a reply to an incoming).
* The message will be sent to the base station if set.
* Encode/Transmit APRSD packet.
* This is a tracker originated message (not a reply to a request).
* The message will be sent to the base station set in path.
*/
if(conf_sram.aprs.base.enabled) {
packet = aprs_encode_query_answer_aprsd(conf->call, /* from */
conf_sram.aprs.base.path, /* via */
conf_sram.aprs.base.call); /* to */
/*
* Send message from this device.
* Use call sign and path as specified in base config.
* There is no acknowledgment requested.
*/
packet = aprs_compose_aprsd_message(
APRS_DEVICE_CALLSIGN,
conf_sram.aprs.base.path,
conf_sram.aprs.base.call);
if(packet == NULL) {
TRACE_WARN("POS > No free packet objects for "
TRACE_WARN("POS > No free packet objects "
"or badly formed APRSD message");
} else {
if(!transmitOnRadio(packet,
@ -87,6 +93,7 @@ THD_FUNCTION(posThread, arg)
chThdSleep(TIME_S2I(5));
}
} else {
/* TODO: Implement a fallback destination if no base station set? */
TRACE_INFO("POS > APRSD data not sent - no base station specified");
}

Wyświetl plik

@ -128,6 +128,10 @@ typedef struct {
uint16_t symbol;
uint8_t rssi; // Squelch for CCA check
bool enabled;
bool fixed;
int32_t lat;
int32_t lon;
int32_t alt;
} thd_tx_conf_t;