Kim Hyeongmin / Mbed 2 deprecated mbed_spatial

Dependencies:   mbed

Fork of mbed_gps3 by Kim Hyeongmin

Committer:
FDLKHM
Date:
Sat May 12 07:28:33 2018 +0000
Revision:
0:0389ce4f9789
Child:
1:fbc9c604df21
This is my code;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
FDLKHM 0:0389ce4f9789 1 #include <stdio.h>
FDLKHM 0:0389ce4f9789 2 #include <stdlib.h>
FDLKHM 0:0389ce4f9789 3 #include <stdint.h>
FDLKHM 0:0389ce4f9789 4 #include <string.h>
FDLKHM 0:0389ce4f9789 5 #include <math.h>
FDLKHM 0:0389ce4f9789 6 #include <iostream>
FDLKHM 0:0389ce4f9789 7 #include "an_packet_protocol.h"
FDLKHM 0:0389ce4f9789 8 #include "spatial_packets.h"
FDLKHM 0:0389ce4f9789 9 #include "mbed.h"
FDLKHM 0:0389ce4f9789 10
FDLKHM 0:0389ce4f9789 11 #define M_PI 3.14
FDLKHM 0:0389ce4f9789 12 #define RADIANS_TO_DEGREES (180.0/M_PI)
FDLKHM 0:0389ce4f9789 13
FDLKHM 0:0389ce4f9789 14
FDLKHM 0:0389ce4f9789 15 Serial pc(USBTX, USBRX); // tx, rx
FDLKHM 0:0389ce4f9789 16 Serial device(p9, p10); // tx, rx
FDLKHM 0:0389ce4f9789 17
FDLKHM 0:0389ce4f9789 18 int main() {
FDLKHM 0:0389ce4f9789 19
FDLKHM 0:0389ce4f9789 20 an_decoder_t an_decoder;
FDLKHM 0:0389ce4f9789 21 an_packet_t *an_packet;
FDLKHM 0:0389ce4f9789 22
FDLKHM 0:0389ce4f9789 23 system_state_packet_t system_state_packet;
FDLKHM 0:0389ce4f9789 24
FDLKHM 0:0389ce4f9789 25 an_decoder_initialise(&an_decoder);
FDLKHM 0:0389ce4f9789 26
FDLKHM 0:0389ce4f9789 27 pc.baud(115200);
FDLKHM 0:0389ce4f9789 28 device.baud(115200);
FDLKHM 0:0389ce4f9789 29
FDLKHM 0:0389ce4f9789 30 while(1) {
FDLKHM 0:0389ce4f9789 31
FDLKHM 0:0389ce4f9789 32 while(device.readable()) {
FDLKHM 0:0389ce4f9789 33
FDLKHM 0:0389ce4f9789 34 int i = an_decoder.buffer_length;
FDLKHM 0:0389ce4f9789 35 an_decoder.buffer[i+1] = device.getc();
FDLKHM 0:0389ce4f9789 36 an_decoder_increment(&an_decoder, 1);
FDLKHM 0:0389ce4f9789 37
FDLKHM 0:0389ce4f9789 38
FDLKHM 0:0389ce4f9789 39 }
FDLKHM 0:0389ce4f9789 40
FDLKHM 0:0389ce4f9789 41 /* iterate through an example data dump from spatial */
FDLKHM 0:0389ce4f9789 42 if (40 < an_decoder.buffer_length)
FDLKHM 0:0389ce4f9789 43 {
FDLKHM 0:0389ce4f9789 44
FDLKHM 0:0389ce4f9789 45 //calculate the number of bytes to copy
FDLKHM 0:0389ce4f9789 46 //bytes_to_copy = an_decoder_size(&an_decoder);
FDLKHM 0:0389ce4f9789 47
FDLKHM 0:0389ce4f9789 48 while ((an_packet = an_packet_decode(&an_decoder)) != NULL)
FDLKHM 0:0389ce4f9789 49 {
FDLKHM 0:0389ce4f9789 50 //an_packet = an_packet_decode(&an_decoder);
FDLKHM 0:0389ce4f9789 51 pc.printf("what is problem? \r\n");
FDLKHM 0:0389ce4f9789 52
FDLKHM 0:0389ce4f9789 53 if (an_packet->id == packet_id_system_state) //system state packet
FDLKHM 0:0389ce4f9789 54 { pc.printf("what is problem?222");
FDLKHM 0:0389ce4f9789 55
FDLKHM 0:0389ce4f9789 56 //copy all the binary data into the typedef struct for the packet
FDLKHM 0:0389ce4f9789 57 //this allows easy access to all the different values
FDLKHM 0:0389ce4f9789 58 if (decode_system_state_packet(&system_state_packet, an_packet) == 0)
FDLKHM 0:0389ce4f9789 59 {pc.printf("what is problem?222");
FDLKHM 0:0389ce4f9789 60 pc.printf("System State Packet:\n");
FDLKHM 0:0389ce4f9789 61 pc.printf("\tLatitude = %f, Longitude = %f, Height = %f\n", system_state_packet.latitude * RADIANS_TO_DEGREES, system_state_packet.longitude * RADIANS_TO_DEGREES, system_state_packet.height);
FDLKHM 0:0389ce4f9789 62 pc.printf("\tRoll = %f, Pitch = %f, Heading = %f\n", system_state_packet.orientation[0] * RADIANS_TO_DEGREES, system_state_packet.orientation[1] * RADIANS_TO_DEGREES, system_state_packet.orientation[2] * RADIANS_TO_DEGREES);
FDLKHM 0:0389ce4f9789 63 }
FDLKHM 0:0389ce4f9789 64 }
FDLKHM 0:0389ce4f9789 65 else
FDLKHM 0:0389ce4f9789 66 {
FDLKHM 0:0389ce4f9789 67 pc.printf("Packet ID %u of Length %u\n", an_packet->id, an_packet->length);
FDLKHM 0:0389ce4f9789 68 }
FDLKHM 0:0389ce4f9789 69 }
FDLKHM 0:0389ce4f9789 70 }
FDLKHM 0:0389ce4f9789 71 }
FDLKHM 0:0389ce4f9789 72
FDLKHM 0:0389ce4f9789 73
FDLKHM 0:0389ce4f9789 74 }
FDLKHM 0:0389ce4f9789 75