![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
final
Fork of C027_SupportTest by
Diff: main.cpp
- Revision:
- 34:2d06e42fac2c
- Parent:
- 33:e27f40fada64
--- a/main.cpp Thu Aug 11 07:12:02 2016 +0000 +++ b/main.cpp Thu Jul 20 09:02:49 2017 +0000 @@ -1,61 +1,51 @@ #include "mbed.h" +#include "MMA7455.h" +#include "MDM.h" -//------------------------------------------------------------------------------------ -/* This example was tested on C027-U20 and C027-G35 with the on board modem. - - Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON - is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this - configuration the following platforms were tested (it is likely that others - will work as well) - - U-BLOX: C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD) - - NXP: LPC1549v2, LPC4088qsb - - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F - - STM: NUCLEO-F401RE, NUCLEO-F030R8 - mount resistors SB13/14 1k, SB62/63 0R -*/ -#include "GPS.h" -#include "MDM.h" -//------------------------------------------------------------------------------------ -// You need to configure these cellular modem / SIM parameters. -// These parameters are ignored for LISA-C200 variants and can be left NULL. -//------------------------------------------------------------------------------------ -//! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. +#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253 + #define SIMPIN "1922" -/*! The APN of your network operator SIM, sometimes it is "internet" check your - contract with the network operator. You can also try to look-up your settings in - google: https://www.google.de/search?q=APN+list */ + #define APN NULL //! Set the user name for your APN, or NULL if not needed #define USERNAME NULL //! Set the password for your APN, or NULL if not needed #define PASSWORD NULL -//------------------------------------------------------------------------------------ + +MMA7455 acc(p32,p31); + +void task_MMA(); -//#define CELLOCATE +double a,b,c; +char str[90]; +char str1[90]; +char str2[90]; int main(void) { + acc.setMode(MMA7455::ModeMeasurement); + acc.setRange(MMA7455::Range_2g); + acc.calibrate(); + int ret; #ifdef LARGE_DATA char buf[2048] = ""; #else char buf[512] = ""; #endif - - // Create the GPS object -#if 1 // use GPSI2C class - GPSI2C gps; -#else // or GPSSerial class - GPSSerial gps; -#endif - // Create the modem object - MDMSerial mdm; // use mdm(D1,D0) if you connect the cellular shield to a C027 - //mdm.setDebug(4); // enable this for debugging issues - // initialize the modem + + MDMSerial mdm; MDMParser::DevStatus devStatus = {}; MDMParser::NetStatus netStatus = {}; bool mdmOk = mdm.init(SIMPIN, &devStatus); mdm.dumpDevStatus(&devStatus); + + + + task_MMA(); + + + if (mdmOk) { #if 0 // file system API @@ -71,8 +61,6 @@ mdm.delFile(filename); } #endif - - // wait until we are connected mdmOk = mdm.registerNet(&netStatus); mdm.dumpNetStatus(&netStatus); } @@ -90,10 +78,9 @@ if (socket >= 0) { mdm.socketSetBlocking(socket, 10000); - if (mdm.socketConnect(socket, "mbed.org", 80)) + if (mdm.socketConnect(socket, "140.118.206.213", 555)) { - const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n"; - mdm.socketSend(socket, http, sizeof(http)-1); + mdm.socketSend(socket, str, sizeof(str)-1); ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); if (ret > 0) @@ -175,20 +162,12 @@ mdm.disconnect(); } - // http://www.geckobeach.com/cellular/secrets/gsmcodes.php - // http://de.wikipedia.org/wiki/USSD-Codes const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION" printf("Ussd Send Command %s\r\n", ussd); ret = mdm.ussdCommand(ussd, buf); if (ret > 0) printf("Ussd Got Answer: \"%s\"\r\n", buf); } - - printf("SMS and GPS Loop\r\n"); - char link[128] = ""; - unsigned int i = 0xFFFFFFFF; - const int wait = 100; - bool abort = false; #ifdef CELLOCATE const int sensorMask = 3; // Hybrid: GNSS + CellLocate const int timeoutMargin = 5; // seconds @@ -198,106 +177,52 @@ bool cellLocWait = false; MDMParser::CellLocData loc; - //Token can be released from u-blox site, when you got one replace "TOKEN" below if (!mdm.cellLocSrvHttp("TOKEN")) mdm.cellLocSrvUdp(); mdm.cellLocConfigSensor(1); // Deep scan mode - //mdm.cellUnsolIndication(1); + #endif - //DigitalOut led(LED1); - while (!abort) { - // led = !led; -#ifndef CELLOCATE - while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) - { - int len = LENGTH(ret); - //printf("NMEA: %.*s\r\n", len-2, msg); - if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) - { - // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS - if ((buf[0] == '$') || buf[1] == 'G') { - #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2])) - if (_CHECK_TALKER("GLL")) { - double la = 0, lo = 0; - char ch; - if (gps.getNmeaAngle(1,buf,len,la) && - gps.getNmeaAngle(3,buf,len,lo) && - gps.getNmeaItem(6,buf,len,ch) && ch == 'A') - { - printf("GPS Location: %.5f %.5f\r\n", la, lo); - sprintf(link, "I am here!\n" - "https://maps.google.com/?q=%.5f,%.5f", la, lo); - } - } else if (_CHECK_TALKER("GGA") || _CHECK_TALKER("GNS") ) { - double a = 0; - if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m] - printf("GPS Altitude: %.1f\r\n", a); - } else if (_CHECK_TALKER("VTG")) { - double s = 0; - if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h] - printf("GPS Speed: %.1f\r\n", s); - } - } - } - } -#endif -#ifdef CELLOCATE - if (mdmOk && (j++ == submitPeriod * 1000/wait)) { - j=0; - printf("CellLocate Request\r\n"); - mdm.cellLocRequest(sensorMask, submitPeriod-timeoutMargin, targetAccuracy); - cellLocWait = true; - } - if (cellLocWait && mdm.cellLocGet(&loc)){ - cellLocWait = false; - printf("CellLocate position received, sensor_used: %d, \r\n", loc.sensorUsed ); - printf(" latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", loc.latitue, loc.longitude, loc.altitutude); - if (loc.sensorUsed == 1) - printf(" uncertainty: %d, speed: %d, direction: %d, vertical_acc: %d, satellite used: %d \r\n", loc.uncertainty,loc.speed,loc.direction,loc.verticalAcc,loc.svUsed); - if (loc.sensorUsed == 1 || loc.sensorUsed == 2) - sprintf(link, "I am here!\n" - "https://maps.google.com/?q=%.5f,%.5f", loc.latitue, loc.longitude); - } - if (cellLocWait && (j%100 == 0 )) - printf("Waiting for CellLocate...\r\n"); -#endif - if (mdmOk && (i++ == 5000/wait)) { - i = 0; - // check the network status - if (mdm.checkNetStatus(&netStatus)) { - mdm.dumpNetStatus(&netStatus, fprintf, stdout); - } - - // checking unread sms - int ix[8]; - int n = mdm.smsList("REC UNREAD", ix, 8); - if (8 < n) n = 8; - while (0 < n--) - { - char num[32]; - printf("Unread SMS at index %d\r\n", ix[n]); - if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) { - printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf); - printf("Delete SMS at index %d\r\n", ix[n]); - mdm.smsDelete(ix[n]); - // provide a reply - const char* reply = "Hello my friend"; - if (strstr(buf, /*w*/"here are you")) - reply = *link ? link : "I don't know"; // reply wil location link - else if (strstr(buf, /*s*/"hutdown")) - abort = true, reply = "bye bye"; - printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num); - mdm.smsSend(num, reply); - } - } - } -#ifdef RTOS_H - Thread::wait(wait); -#else - ::wait_ms(wait); -#endif - } - gps.powerOff(); mdm.powerOff(); return 0; } +void task_MMA(){ + + + char filename[64]; + int32_t x,y,z; + double x1,y1,z1; + double xg,yg,zg; + double xd,yd,zd; + acc.read(x,y,z); + + xg=x*0.016; //實際g值 + yg=y*0.016; //實際g值 + zg=z*0.016; //實際g值 + + x1=xg/(sqrt(pow(yg,2.0)+pow(zg,2.0))); + y1=yg/(sqrt(pow(xg,2.0)+pow(zg,2.0))); + z1=(sqrt(pow(yg,2.0)+pow(xg,2.0)))/zg; + + xd=atan(x1); //徑度 + yd=atan(y1); //徑度 + zd=atan(z1); //徑度 + + a=xd*180.0/PI; + b=yd*180.0/PI; + c=zd*180.0/PI; + + sprintf(str,"%.2f\t",a); + sprintf(str1,"%.2f\t",b); + sprintf(str2,"%.2f",c); + + strcat(str,str1); + strcat(str,str2); + + puts(str); + + + printf("xd: %.2f ",xd*180.0/PI); + printf("yd: %.2f ",yd*180.0/PI); + printf("zd: %.2f ",zd*180.0/PI); + printf("\r\n\n"); +} \ No newline at end of file