Browse Source

added MSP_UID patch from cGiessen

added sending cell voltages (faked) via frsky telemetry by fiendie
two additional cli commands (aux and dump) from jef79m - aux allows setting switches from command line, dump creates a copy-pasteable config which can be sent to a new board.


git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@283 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
master
timecop@gmail.com 12 years ago
parent
commit
600f50ecac
  1. 2
      baseflight.uvproj
  2. 6363
      obj/baseflight.hex
  3. 5
      src/board.h
  4. 100
      src/cli.c
  5. 10
      src/serial.c
  6. 60
      src/telemetry.c

2
baseflight.uvproj

@ -166,7 +166,7 @@
<DriverSelection>4096</DriverSelection>
</Flash1>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3></Flash3>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
</Utilities>
<TargetArmAds>

6363
obj/baseflight.hex
File diff suppressed because it is too large
View File

5
src/board.h

@ -21,6 +21,11 @@
#define RADX10 (M_PI / 1800.0f) // 0.001745329252f
// Chip Unique ID on F103
#define U_ID_0 (*(uint32_t*)0x1FFFF7E8)
#define U_ID_1 (*(uint32_t*)0x1FFFF7EC)
#define U_ID_2 (*(uint32_t*)0x1FFFF7F0)
typedef enum {
SENSOR_ACC = 1 << 0,
SENSOR_BARO = 1 << 1,

100
src/cli.c

@ -3,8 +3,10 @@
// we unset this on 'exit'
extern uint8_t cliMode;
static void cliAux(char *cmdline);
static void cliCMix(char *cmdline);
static void cliDefaults(char *cmdline);
static void cliDump(char *cmdLine);
static void cliExit(char *cmdline);
static void cliFeature(char *cmdline);
static void cliHelp(char *cmdline);
@ -63,8 +65,10 @@ typedef struct {
// should be sorted a..z for bsearch()
const clicmd_t cmdTable[] = {
{ "aux", "feature_name auxflag or blank for list", cliAux },
{ "cmix", "design custom mixer", cliCMix },
{ "defaults", "reset to defaults and reboot", cliDefaults },
{ "dump", "print configurable settings in a pastable form", cliDump },
{ "exit", "", cliExit },
{ "feature", "list or -val or val", cliFeature },
{ "help", "", cliHelp },
@ -387,6 +391,30 @@ static int cliCompare(const void *a, const void *b)
return strncasecmp(ca->name, cb->name, strlen(cb->name));
}
static void cliAux(char *cmdline)
{
int i, val = 0;
uint8_t len;
char *ptr;
len = strlen(cmdline);
if (len == 0) {
// print out aux channel settings
for (i = 0; i < CHECKBOXITEMS; i++)
printf("aux %u %u\r\n", i, cfg.activate[i]);
} else {
ptr = cmdline;
i = atoi(ptr);
if (i < CHECKBOXITEMS) {
ptr = strchr(cmdline, ' ');
val = atoi(ptr);
cfg.activate[i] = val;
} else {
printf("Invalid Feature index: must be < %u\r\n", CHECKBOXITEMS);
}
}
}
static void cliCMix(char *cmdline)
{
int i, check = 0;
@ -482,6 +510,78 @@ static void cliDefaults(char *cmdline)
systemReset(false);
}
static void cliDump(char *cmdline)
{
int i, val = 0;
char buf[16];
float thr, roll, pitch, yaw;
uint32_t mask;
const clivalue_t *setval;
printf("Current Config: Copy everything below here...\r\n");
// print out aux switches
cliAux("");
// print out current motor mix
printf("mixer %s\r\n", mixerNames[cfg.mixerConfiguration - 1]);
// print custom mix if exists
if (cfg.customMixer[0].throttle != 0.0f) {
for (i = 0; i < MAX_MOTORS; i++) {
if (cfg.customMixer[i].throttle == 0.0f)
break;
thr = cfg.customMixer[i].throttle;
roll = cfg.customMixer[i].roll;
pitch = cfg.customMixer[i].pitch;
yaw = cfg.customMixer[i].yaw;
printf("cmix %d", i + 1);
if (thr < 0)
printf(" ");
printf("%s", ftoa(thr, buf));
if (roll < 0)
printf(" ");
printf("%s", ftoa(roll, buf));
if (pitch < 0)
printf(" ");
printf("%s", ftoa(pitch, buf));
if (yaw < 0)
printf(" ");
printf("%s\r\n", ftoa(yaw, buf));
}
printf("cmix %d 0 0 0 0\r\n", i + 1);
}
// print enabled features
mask = featureMask();
for (i = 0; ; i++) { // disable all feature first
if (featureNames[i] == NULL)
break;
printf("feature -%s\r\n", featureNames[i]);
}
for (i = 0; ; i++) { // reenable what we want.
if (featureNames[i] == NULL)
break;
if (mask & (1 << i))
printf("feature %s\r\n", featureNames[i]);
}
// print RC MAPPING
for (i = 0; i < 8; i++)
buf[cfg.rcmap[i]] = rcChannelLetters[i];
buf[i] = '\0';
printf("map %s\r\n", buf);
// print settings
for (i = 0; i < VALUE_COUNT; i++) {
setval = &valueTable[i];
printf("set %s = ", valueTable[i].name);
cliPrintVar(setval, 0);
uartPrint("\r\n");
}
}
static void cliExit(char *cmdline)
{
uartPrint("\r\nLeaving CLI mode...\r\n");

10
src/serial.c

@ -44,6 +44,9 @@
#define MSP_ACC_TRIM 240 //out message get acc angle trim values
#define MSP_SET_ACC_TRIM 239 //in message set acc angle trim values
// Additional commands that are not compatible with MultiWii
#define MSP_UID 160 //out message Unique device ID
#define INBUF_SIZE 64
static const char boxnames[] =
@ -378,6 +381,13 @@ static void evaluateCommand(void)
for (i = 0; i < 4; i++)
serialize16(debug[i]); // 4 variables are here for general monitoring purpose
break;
// Additional commands that are not compatible with MultiWii
case MSP_UID:
headSerialReply(12);
serialize32(U_ID_0);
serialize32(U_ID_1);
serialize32(U_ID_2);
break;
default: // we do not know how to handle the (valid) message, indicate error MSP $M!
headSerialError(0);
break;

60
src/telemetry.c

@ -45,6 +45,10 @@
#define ID_GYRO_Y 0x41
#define ID_GYRO_Z 0x42
// from sensors.c
extern uint8_t batteryCellCount;
static void sendDataHead(uint8_t id)
{
uartWrite(PROTOCOL_HEADER);
@ -132,11 +136,56 @@ static void sendGPS(void)
serialize16(GPS_coord[LON] < 0 ? 'W' : 'E');
}
/*
* Send voltage via ID_VOLT
*
* NOTE: This sends voltage divided by batteryCellCount. To get the real
* battery voltage, you need to multiply the value by batteryCellCount.
*/
static void sendVoltage(void)
{
uint16_t voltage;
static uint16_t currentCell = 0;
uint16_t cellNumber;
uint32_t cellVoltage;
uint16_t payload;
/*
* Note: Fuck the pdf. Format for Voltage Data for single cells is like this:
*
* llll llll cccc hhhh
* l: Low voltage bits
* h: High voltage bits
* c: Cell number (starting at 0)
*/
cellVoltage = vbat / batteryCellCount;
// Map to 12 bit range
cellVoltage = (cellVoltage * 2100) / 42;
cellNumber = currentCell % batteryCellCount;
// Cell number is at bit 9-12
payload = (cellNumber << 4);
// Lower voltage bits are at bit 0-8
payload |= ((cellVoltage & 0x0ff) << 8);
// Higher voltage bits are at bits 13-15
payload |= ((cellVoltage & 0xf00) >> 8);
voltage = (vbat * 110) / 21;
sendDataHead(ID_VOLT);
serialize16(payload);
currentCell++;
currentCell %= batteryCellCount;
}
/*
* Send voltage with ID_VOLTAGE_AMP
*/
static void sendVoltageAmp()
{
uint16_t voltage = (vbat * 110) / 21;
sendDataHead(ID_VOLTAGE_AMP_BP);
serialize16(voltage / 100);
@ -186,10 +235,15 @@ void sendTelemetry(void)
if ((cycleNum % 8) == 0) { // Sent every 1s
sendTemperature1();
if (feature(FEATURE_VBAT))
if (feature(FEATURE_VBAT)) {
sendVoltage();
sendVoltageAmp();
}
if (sensors(SENSOR_GPS))
sendGPS();
sendTelemetryTail();
}

Loading…
Cancel
Save