Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AlarmClock DigitalClock EthernetInterface FourDigitLED HTTPClient NTPClient SDFileSystem TrainStat WeatherInfo XML_aide mbed-rtos mbed picojson wolfSSL
Revision 2:bcc1a40ffa04, committed 2015-06-26
- Comitter:
- takashikojo
- Date:
- Fri Jun 26 09:35:53 2015 +0000
- Parent:
- 1:1a28aaca601d
- Child:
- 3:2cb03c287c22
- Commit message:
- Adding TransStat class
Changed in this revision
--- a/TrainStat.cpp Fri Jun 26 08:02:30 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-#include "mbed.h"
-#include "EthernetInterface.h"
-#include "HTTPClient.h"
-#include "vector"
-#include "picojson.h"
-
-#include "AlarmClock.h"
-
-#define ACCESS_TOKEN "6d60c19c9497e9b2f5b847d31ab70cccce76269bbaf461b5ebd90dd16e71003c"
-#define API_URL "https://api.tokyometroapp.jp:443/api/v2"
-
-extern AlarmClock alarmclock ;
-static HTTPClient http;
-static char recvBuff[1024*64];
-
-static picojson::value trainStat ;
-
-void metro_query(const char *type, const char *query, char *recv, int size) {
- int ret ;
- #define BUFF_SIZE 256
- char queryBuff[BUFF_SIZE] ;
- sprintf(queryBuff, "%s/%s?rdf:type=%s&acl:consumerKey=%s", API_URL, type, query, ACCESS_TOKEN) ;
- //puts(queryBuff) ;
- ret = http.get(queryBuff, recvBuff, size);
- if (!ret) {
- // printf("Result: %s\n", recv);
- } else {
- printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
- }
-}
-
-static std::map<std::string, string> lineTbl ;
-static void init_station(void) {
- lineTbl["odpt.Railway:TokyoMetro.Tozai"] = "東西線 " ;
- lineTbl["odpt.Railway:TokyoMetro.Marunouchi"] = "丸の内線" ;
- lineTbl["odpt.Railway:TokyoMetro.Namboku"] = "南北線 " ;
- lineTbl["odpt.Railway:TokyoMetro.Hibiya"] = "日比谷線" ;
- lineTbl["odpt.Railway:TokyoMetro.Fukutoshin"] = "副都心線" ;
- lineTbl["odpt.Railway:TokyoMetro.Hanzomon"] = "半蔵門線" ;
- lineTbl["odpt.Railway:TokyoMetro.Ginza"] = "銀座線 " ;
- lineTbl["odpt.Railway:TokyoMetro.Yurakucho"] = "有楽町線" ;
- lineTbl["odpt.Railway:TokyoMetro.Chiyoda"] = "千代田線" ;
-}
-
-static string watchingLine = "" ;
-
-static void set_station(string name) {
- map<string, string>::iterator it = lineTbl.begin(); ;
-
- for(it = lineTbl.begin(); it != lineTbl.end(); ++it) {
- if(it->second == name){
- watchingLine = it->first ;
- }
- }
-}
-
-static void print_stat(const char *line, const char *stat) {
- #define JST (9*60*60)
- struct tm t;
- time_t ctTime;
- ctTime = time(NULL) + JST ;
- t = *localtime(&ctTime);
-
- printf("%d月%d日%d時%d分:%sの運転状況:%s\n",
- t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, line, stat) ;
-}
-
-static bool get_stat(const char *buff) {
-
- std::string err;
- picojson::parse(trainStat, (const char *)buff, (const char *)recvBuff+strlen(recvBuff), &err);
- if (!err.empty()) {
- printf("Metro Site Result ERROR: %s", err.c_str());
- return ;
- }
- picojson::array array = trainStat.get<picojson::array>();
- for (picojson::array::iterator it = array.begin(); it != array.end(); it++)
- {
- picojson::object& obj = it->get<picojson::object>();
- if(watchingLine == "")
- print_stat(
- lineTbl[obj["odpt:railway"].get<std::string>()].c_str(),
- obj["odpt:trainInformationText"].get<std::string>().c_str());
- else if(obj["odpt:railway"].get<std::string>()==watchingLine){
- print_stat(
- lineTbl[watchingLine].c_str(),
- obj["odpt:trainInformationText"].get<std::string>().c_str());
- if(obj["odpt:trainInformationText"].get<std::string>().find("平常どおり") == std::string::npos)
- return false ;
- }
- }
- return true ;
-}
-
-void net_main(void const *av)
-{
- bool sw ;
- init_station() ;
- set_station("有楽町線") ;
- while(1) {
- sw = !sw ;
- metro_query("datapoints", "odpt:TrainInformation", recvBuff, sizeof(recvBuff)) ;
- if(!get_stat((const char *)recvBuff))
- { printf("遅れあり\n") ; alarmclock.setBlink(true) ; }
- else
- { printf("遅れなし\n") ; alarmclock.setBlink(false) ; }
- wait(60.0) ;
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TrainStat.lib Fri Jun 26 09:35:53 2015 +0000 @@ -0,0 +1,1 @@ +TrainStat#a59f55690685
--- a/main.cpp Fri Jun 26 08:02:30 2015 +0000
+++ b/main.cpp Fri Jun 26 09:35:53 2015 +0000
@@ -3,8 +3,7 @@
#include "EthernetInterface.h"
#include "NTPClient.h"
#include "AlarmClock.h"
-
-extern void net_main(void const *av) ;
+#include "TrainStat.h"
AlarmClock alarmclock (
/* Segment 0 - 6, Dot */ D11,D6, D3, D1, D0, D10,D4, D2 ,
@@ -12,6 +11,8 @@
/* Alarm, Hour, Min, Tone */D13, D14, D15, PTC11
) ;
+TrainStat trainstat ;
+
static void ntp(char *site)
{
NTPClient ntp;
@@ -36,6 +37,22 @@
}
}
+void net_main(void const *av)
+{
+ bool sw ;
+
+ trainstat.setLine("千代田線") ;
+ wait(2.0) ;
+ while(1) {
+ sw = !sw ;
+ if(!trainstat.getStat())
+ { printf("遅れあり\n") ; alarmclock.setBlink(true) ; }
+ else
+ { printf("遅れなし\n") ; alarmclock.setBlink(false) ; }
+ wait(60.0) ;
+ }
+}
+
int main() {
EthernetInterface eth;
int ret ;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/net_main.txt Fri Jun 26 09:35:53 2015 +0000
@@ -0,0 +1,109 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "HTTPClient.h"
+#include "vector"
+#include "picojson.h"
+
+#include "AlarmClock.h"
+
+#define ACCESS_TOKEN "6d60c19c9497e9b2f5b847d31ab70cccce76269bbaf461b5ebd90dd16e71003c"
+#define API_URL "https://api.tokyometroapp.jp:443/api/v2"
+
+extern AlarmClock alarmclock ;
+static HTTPClient http;
+static char recvBuff[1024*64];
+
+static picojson::value trainStat ;
+
+void metro_query(const char *type, const char *query, char *recv, int size) {
+ int ret ;
+ #define BUFF_SIZE 256
+ char queryBuff[BUFF_SIZE] ;
+ sprintf(queryBuff, "%s/%s?rdf:type=%s&acl:consumerKey=%s", API_URL, type, query, ACCESS_TOKEN) ;
+ //puts(queryBuff) ;
+ ret = http.get(queryBuff, recvBuff, size);
+ if (!ret) {
+ // printf("Result: %s\n", recv);
+ } else {
+ printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+ }
+}
+
+static std::map<std::string, string> lineTbl ;
+static void init_station(void) {
+ lineTbl["odpt.Railway:TokyoMetro.Tozai"] = "東西線 " ;
+ lineTbl["odpt.Railway:TokyoMetro.Marunouchi"] = "丸の内線" ;
+ lineTbl["odpt.Railway:TokyoMetro.Namboku"] = "南北線 " ;
+ lineTbl["odpt.Railway:TokyoMetro.Hibiya"] = "日比谷線" ;
+ lineTbl["odpt.Railway:TokyoMetro.Fukutoshin"] = "副都心線" ;
+ lineTbl["odpt.Railway:TokyoMetro.Hanzomon"] = "半蔵門線" ;
+ lineTbl["odpt.Railway:TokyoMetro.Ginza"] = "銀座線 " ;
+ lineTbl["odpt.Railway:TokyoMetro.Yurakucho"] = "有楽町線" ;
+ lineTbl["odpt.Railway:TokyoMetro.Chiyoda"] = "千代田線" ;
+}
+
+static string watchingLine = "" ;
+
+static void set_station(string name) {
+ map<string, string>::iterator it = lineTbl.begin(); ;
+
+ for(it = lineTbl.begin(); it != lineTbl.end(); ++it) {
+ if(it->second == name){
+ watchingLine = it->first ;
+ }
+ }
+}
+
+static void print_stat(const char *line, const char *stat) {
+ #define JST (9*60*60)
+ struct tm t;
+ time_t ctTime;
+ ctTime = time(NULL) + JST ;
+ t = *localtime(&ctTime);
+
+ printf("%d月%d日%d時%d分:%sの運転状況:%s\n",
+ t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, line, stat) ;
+}
+
+static bool get_stat(const char *buff) {
+
+ std::string err;
+ picojson::parse(trainStat, (const char *)buff, (const char *)recvBuff+strlen(recvBuff), &err);
+ if (!err.empty()) {
+ printf("Metro Site Result ERROR: %s", err.c_str());
+ return false ;
+ }
+ picojson::array array = trainStat.get<picojson::array>();
+ for (picojson::array::iterator it = array.begin(); it != array.end(); it++)
+ {
+ picojson::object& obj = it->get<picojson::object>();
+ if(watchingLine == "")
+ print_stat(
+ lineTbl[obj["odpt:railway"].get<std::string>()].c_str(),
+ obj["odpt:trainInformationText"].get<std::string>().c_str());
+ else if(obj["odpt:railway"].get<std::string>()==watchingLine){
+ print_stat(
+ lineTbl[watchingLine].c_str(),
+ obj["odpt:trainInformationText"].get<std::string>().c_str());
+ if(obj["odpt:trainInformationText"].get<std::string>().find("平常どおり") == std::string::npos)
+ return false ;
+ }
+ }
+ return true ;
+}
+
+void net_main(void const *av)
+{
+ bool sw ;
+ init_line() ;
+ set_line("有楽町線") ;
+ while(1) {
+ sw = !sw ;
+ metro_query("datapoints", "odpt:TrainInformation", recvBuff, sizeof(recvBuff)) ;
+ if(!get_stat((const char *)recvBuff))
+ { printf("遅れあり\n") ; alarmclock.setBlink(true) ; }
+ else
+ { printf("遅れなし\n") ; alarmclock.setBlink(false) ; }
+ wait(60.0) ;
+ }
+}