Import of CSR's demo for SirfV. Has minor cleanup.
Dependencies: CsrLocation mbed GPSProvider
Fork of CsrLocationDemo by
CsrLocationDemo.cpp@20:42aca3a90941, 2014-11-04 (annotated)
- Committer:
- rgrover1
- Date:
- Tue Nov 04 14:25:31 2014 +0000
- Revision:
- 20:42aca3a90941
- Parent:
- 19:b8703d1c1b38
- Child:
- 21:398bb500bb37
switching to use CSR's private location library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 16:24128dedf8db | 1 | /* CSRLocation class for mbed Microcontroller |
zhjcpi | 0:789f6b6f710d | 2 | * Copyright 2014 CSR plc |
zhjcpi | 0:789f6b6f710d | 3 | */ |
zhjcpi | 0:789f6b6f710d | 4 | |
zhjcpi | 0:789f6b6f710d | 5 | #include "mbed.h" |
zhjcpi | 0:789f6b6f710d | 6 | #include "CsrLocation.h" |
rgrover1 | 16:24128dedf8db | 7 | #include "GPSProvider.h" |
zhjcpi | 0:789f6b6f710d | 8 | |
rgrover1 | 19:b8703d1c1b38 | 9 | #define PINMAP_GPIO_BTN D5 |
rgrover1 | 19:b8703d1c1b38 | 10 | #define PINMAP_GPIO_TEST D10 |
rgrover1 | 19:b8703d1c1b38 | 11 | #define LOC_LED1 D7 |
rgrover1 | 19:b8703d1c1b38 | 12 | #define LOC_LED2 D6 |
rgrover1 | 15:495c22f32cc6 | 13 | |
zhjcpi | 3:7a3ed8ae071d | 14 | #define APP_DBG_PORT_BAUD 115200 |
zhjcpi | 3:7a3ed8ae071d | 15 | #define CSR_APP_LOG_INFO(...) sSerialDebug.printf(__VA_ARGS__) |
zhjcpi | 3:7a3ed8ae071d | 16 | |
zhjcpi | 0:789f6b6f710d | 17 | /* appliation commands */ |
rgrover1 | 15:495c22f32cc6 | 18 | typedef enum AppCmd { |
rgrover1 | 15:495c22f32cc6 | 19 | APP_CMD_IDLE, // No special command |
rgrover1 | 15:495c22f32cc6 | 20 | APP_CMD_HELP, // Show the supported commands |
rgrover1 | 15:495c22f32cc6 | 21 | APP_CMD_START, // Start location |
rgrover1 | 15:495c22f32cc6 | 22 | APP_CMD_STOP, // Stop location |
rgrover1 | 15:495c22f32cc6 | 23 | APP_CMD_PM_FULL, // Set full power mode |
rgrover1 | 15:495c22f32cc6 | 24 | APP_CMD_PM_PTF, // Set low power PTF mode |
rgrover1 | 15:495c22f32cc6 | 25 | APP_CMD_PTF_GETPOS, // Get location immediately in low power PTF mode |
rgrover1 | 16:24128dedf8db | 26 | APP_CMD_RESET, // Debug command, pull reset pin high level |
rgrover1 | 15:495c22f32cc6 | 27 | } eAppCmd; |
zhjcpi | 0:789f6b6f710d | 28 | |
zhjcpi | 0:789f6b6f710d | 29 | static void _AppShowCmd(void); |
zhjcpi | 9:87d1555b6219 | 30 | static void _AppBtnPushed(void); |
zhjcpi | 0:789f6b6f710d | 31 | static void _ConsoleRxHandler(void); |
zhjcpi | 0:789f6b6f710d | 32 | static void _AppCmdProcess(char *pCmd); |
zhjcpi | 0:789f6b6f710d | 33 | |
rgrover1 | 16:24128dedf8db | 34 | static int sAppCmd = APP_CMD_IDLE; |
zhjcpi | 0:789f6b6f710d | 35 | |
rgrover1 | 16:24128dedf8db | 36 | static DigitalOut sLedLocOn(LOC_LED1); |
rgrover1 | 16:24128dedf8db | 37 | static DigitalOut sLedPosReport(LOC_LED2); |
rgrover1 | 16:24128dedf8db | 38 | static InterruptIn sBtn(PINMAP_GPIO_BTN); |
rgrover1 | 16:24128dedf8db | 39 | static DigitalOut sPinTest(PINMAP_GPIO_TEST); |
rgrover1 | 16:24128dedf8db | 40 | |
rgrover1 | 18:c75558f5959f | 41 | Serial sSerialDebug(USBTX, USBRX); |
zhjcpi | 0:789f6b6f710d | 42 | |
rgrover1 | 17:ebf95368b2d8 | 43 | void |
rgrover1 | 17:ebf95368b2d8 | 44 | locationHandler(const GPSProvider::LocationUpdateParams_t *params) |
rgrover1 | 17:ebf95368b2d8 | 45 | { |
rgrover1 | 17:ebf95368b2d8 | 46 | CSR_APP_LOG_INFO("received location update\r\n"); |
rgrover1 | 17:ebf95368b2d8 | 47 | } |
rgrover1 | 17:ebf95368b2d8 | 48 | |
zhjcpi | 0:789f6b6f710d | 49 | int main(void) |
zhjcpi | 0:789f6b6f710d | 50 | { |
rgrover1 | 15:495c22f32cc6 | 51 | sLedLocOn = 0; |
rgrover1 | 15:495c22f32cc6 | 52 | sLedPosReport = 0; |
rgrover1 | 15:495c22f32cc6 | 53 | sPinTest = 1; |
rgrover1 | 15:495c22f32cc6 | 54 | sBtn.mode(PullUp); |
rgrover1 | 15:495c22f32cc6 | 55 | sBtn.fall(&_AppBtnPushed); |
rgrover1 | 15:495c22f32cc6 | 56 | |
rgrover1 | 15:495c22f32cc6 | 57 | /* initialize the debug serial port */ |
zhjcpi | 3:7a3ed8ae071d | 58 | sSerialDebug.baud(APP_DBG_PORT_BAUD); |
zhjcpi | 0:789f6b6f710d | 59 | sSerialDebug.attach(&_ConsoleRxHandler); |
zhjcpi | 0:789f6b6f710d | 60 | |
rgrover1 | 16:24128dedf8db | 61 | GPSProvider gps; |
rgrover1 | 16:24128dedf8db | 62 | gps.setPowerMode(GPSProvider::POWER_FULL); |
rgrover1 | 16:24128dedf8db | 63 | gps.reset(); |
rgrover1 | 17:ebf95368b2d8 | 64 | gps.onLocationUpdate(locationHandler); |
rgrover1 | 15:495c22f32cc6 | 65 | CSR_APP_LOG_INFO("Success to new csrLocation.\r\n"); |
zhjcpi | 0:789f6b6f710d | 66 | |
zhjcpi | 0:789f6b6f710d | 67 | _AppShowCmd(); |
zhjcpi | 0:789f6b6f710d | 68 | |
rgrover1 | 15:495c22f32cc6 | 69 | while (true) { |
rgrover1 | 15:495c22f32cc6 | 70 | switch (sAppCmd) { |
rgrover1 | 15:495c22f32cc6 | 71 | case APP_CMD_HELP: |
rgrover1 | 15:495c22f32cc6 | 72 | sAppCmd = APP_CMD_IDLE; |
rgrover1 | 15:495c22f32cc6 | 73 | _AppShowCmd(); |
rgrover1 | 15:495c22f32cc6 | 74 | break; |
rgrover1 | 16:24128dedf8db | 75 | case APP_CMD_IDLE: |
rgrover1 | 17:ebf95368b2d8 | 76 | gps.process(); |
rgrover1 | 16:24128dedf8db | 77 | break; |
rgrover1 | 15:495c22f32cc6 | 78 | case APP_CMD_START: |
rgrover1 | 15:495c22f32cc6 | 79 | sAppCmd = APP_CMD_IDLE; |
rgrover1 | 15:495c22f32cc6 | 80 | CSR_APP_LOG_INFO("start location.\r\n"); |
rgrover1 | 16:24128dedf8db | 81 | gps.start(); |
rgrover1 | 15:495c22f32cc6 | 82 | sLedLocOn = 1; |
rgrover1 | 15:495c22f32cc6 | 83 | break; |
rgrover1 | 15:495c22f32cc6 | 84 | case APP_CMD_STOP: |
rgrover1 | 15:495c22f32cc6 | 85 | sAppCmd = APP_CMD_IDLE; |
rgrover1 | 15:495c22f32cc6 | 86 | CSR_APP_LOG_INFO("stop location.\r\n"); |
rgrover1 | 16:24128dedf8db | 87 | gps.stop(); |
rgrover1 | 15:495c22f32cc6 | 88 | sLedLocOn = 0; |
rgrover1 | 15:495c22f32cc6 | 89 | break; |
rgrover1 | 16:24128dedf8db | 90 | case APP_CMD_RESET: |
rgrover1 | 16:24128dedf8db | 91 | sAppCmd = APP_CMD_IDLE; |
rgrover1 | 16:24128dedf8db | 92 | gps.reset(); |
rgrover1 | 16:24128dedf8db | 93 | CSR_APP_LOG_INFO("reset on.\r\n"); |
rgrover1 | 15:495c22f32cc6 | 94 | break; |
rgrover1 | 18:c75558f5959f | 95 | case APP_CMD_PTF_GETPOS: |
rgrover1 | 18:c75558f5959f | 96 | CSR_APP_LOG_INFO("lpm get pos.\r\n"); |
rgrover1 | 18:c75558f5959f | 97 | sAppCmd = APP_CMD_IDLE; |
rgrover1 | 18:c75558f5959f | 98 | gps.lpmGetImmediateLocation(); |
rgrover1 | 18:c75558f5959f | 99 | break; |
rgrover1 | 16:24128dedf8db | 100 | case APP_CMD_PM_FULL: |
rgrover1 | 15:495c22f32cc6 | 101 | sAppCmd = APP_CMD_IDLE; |
rgrover1 | 16:24128dedf8db | 102 | gps.setPowerMode(GPSProvider::POWER_FULL); |
rgrover1 | 15:495c22f32cc6 | 103 | CSR_APP_LOG_INFO("fpm set.\r\n"); |
rgrover1 | 15:495c22f32cc6 | 104 | break; |
rgrover1 | 15:495c22f32cc6 | 105 | case APP_CMD_PM_PTF: |
rgrover1 | 16:24128dedf8db | 106 | sAppCmd = APP_CMD_IDLE; |
rgrover1 | 16:24128dedf8db | 107 | gps.setPowerMode(GPSProvider::POWER_LOW); |
rgrover1 | 15:495c22f32cc6 | 108 | CSR_APP_LOG_INFO("lpm ptf set.\r\n"); |
rgrover1 | 15:495c22f32cc6 | 109 | break; |
zhjcpi | 0:789f6b6f710d | 110 | } |
zhjcpi | 0:789f6b6f710d | 111 | } |
zhjcpi | 0:789f6b6f710d | 112 | } |
zhjcpi | 0:789f6b6f710d | 113 | |
zhjcpi | 0:789f6b6f710d | 114 | static void _AppShowCmd(void) |
zhjcpi | 0:789f6b6f710d | 115 | { |
zhjcpi | 3:7a3ed8ae071d | 116 | CSR_APP_LOG_INFO("Location commands:\r\n"); |
zhjcpi | 3:7a3ed8ae071d | 117 | CSR_APP_LOG_INFO(" help - help to show supported commands\r\n"); |
zhjcpi | 3:7a3ed8ae071d | 118 | CSR_APP_LOG_INFO(" start - begin location\r\n"); |
zhjcpi | 3:7a3ed8ae071d | 119 | CSR_APP_LOG_INFO(" stop - end location\r\n"); |
zhjcpi | 3:7a3ed8ae071d | 120 | CSR_APP_LOG_INFO(" fpm - full power mode\r\n"); |
zhjcpi | 3:7a3ed8ae071d | 121 | CSR_APP_LOG_INFO(" ptf - ptf low power mode\r\n"); |
zhjcpi | 3:7a3ed8ae071d | 122 | CSR_APP_LOG_INFO(" getpos - get location immediately in low power ptf mode\r\n"); |
zhjcpi | 0:789f6b6f710d | 123 | } |
zhjcpi | 0:789f6b6f710d | 124 | |
zhjcpi | 9:87d1555b6219 | 125 | static void _AppBtnPushed(void) |
zhjcpi | 9:87d1555b6219 | 126 | { |
rgrover1 | 15:495c22f32cc6 | 127 | sAppCmd = APP_CMD_PTF_GETPOS; |
rgrover1 | 15:495c22f32cc6 | 128 | // sLedLocOn = !sLedLocOn; |
zhjcpi | 9:87d1555b6219 | 129 | } |
zhjcpi | 9:87d1555b6219 | 130 | |
zhjcpi | 0:789f6b6f710d | 131 | static void _ConsoleRxHandler(void) |
zhjcpi | 0:789f6b6f710d | 132 | { |
rgrover1 | 15:495c22f32cc6 | 133 | static char cmd[32] = {0}; |
rgrover1 | 15:495c22f32cc6 | 134 | char ch; |
zhjcpi | 0:789f6b6f710d | 135 | |
zhjcpi | 0:789f6b6f710d | 136 | ch = sSerialDebug.getc(); |
zhjcpi | 0:789f6b6f710d | 137 | sSerialDebug.putc(ch); |
rgrover1 | 15:495c22f32cc6 | 138 | if (ch == '\r') { |
zhjcpi | 0:789f6b6f710d | 139 | sSerialDebug.putc('\n'); |
rgrover1 | 15:495c22f32cc6 | 140 | if (strlen(cmd) > 0) { |
rgrover1 | 15:495c22f32cc6 | 141 | _AppCmdProcess(cmd); |
rgrover1 | 15:495c22f32cc6 | 142 | memset(cmd, 0, sizeof(cmd)); |
zhjcpi | 0:789f6b6f710d | 143 | } |
rgrover1 | 15:495c22f32cc6 | 144 | } else { |
rgrover1 | 15:495c22f32cc6 | 145 | cmd[strlen(cmd)] = ch; |
rgrover1 | 15:495c22f32cc6 | 146 | } |
zhjcpi | 0:789f6b6f710d | 147 | } |
rgrover1 | 15:495c22f32cc6 | 148 | |
zhjcpi | 0:789f6b6f710d | 149 | static void _AppCmdProcess(char *pCmd) |
zhjcpi | 0:789f6b6f710d | 150 | { |
rgrover1 | 15:495c22f32cc6 | 151 | if (strcmp(pCmd, "help") == 0) { |
zhjcpi | 0:789f6b6f710d | 152 | sAppCmd = APP_CMD_HELP; |
rgrover1 | 15:495c22f32cc6 | 153 | } else if (strcmp(pCmd, "start") == 0) { |
zhjcpi | 0:789f6b6f710d | 154 | sAppCmd = APP_CMD_START; |
rgrover1 | 15:495c22f32cc6 | 155 | } else if (strcmp(pCmd, "stop") == 0) { |
zhjcpi | 0:789f6b6f710d | 156 | sAppCmd = APP_CMD_STOP; |
rgrover1 | 15:495c22f32cc6 | 157 | } else if (strcmp(pCmd, "fpm") == 0) { |
zhjcpi | 0:789f6b6f710d | 158 | sAppCmd = APP_CMD_PM_FULL; |
rgrover1 | 15:495c22f32cc6 | 159 | } else if (strcmp(pCmd, "ptf") == 0) { |
zhjcpi | 0:789f6b6f710d | 160 | sAppCmd = APP_CMD_PM_PTF; |
rgrover1 | 15:495c22f32cc6 | 161 | } else if (strcmp(pCmd, "getpos") == 0) { |
zhjcpi | 0:789f6b6f710d | 162 | sAppCmd = APP_CMD_PTF_GETPOS; |
rgrover1 | 16:24128dedf8db | 163 | } else if (strcmp(pCmd, "reset") == 0) { |
rgrover1 | 16:24128dedf8db | 164 | sAppCmd = APP_CMD_RESET; |
rgrover1 | 15:495c22f32cc6 | 165 | } else { |
zhjcpi | 3:7a3ed8ae071d | 166 | CSR_APP_LOG_INFO("\r\nUnknown command %s\r\n", pCmd); |
zhjcpi | 0:789f6b6f710d | 167 | } |
rgrover1 | 15:495c22f32cc6 | 168 | |
rgrover1 | 15:495c22f32cc6 | 169 | CSR_APP_LOG_INFO("\r\n"); |
zhjcpi | 0:789f6b6f710d | 170 | } |