ネットワークアップデート機能とか、Pachubeへの情報登録とかの処理を追加しています

Dependencies:   Terminal EthernetNetIf Pachube TextLCD mbed ConfigFile FirmwareUpdater

Committer:
abe00makoto
Date:
Mon Jun 06 19:56:43 2011 +0000
Revision:
1:1eb67d074bed
Parent:
0:a62f36392b9b
add set_time function. for fist use mbed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abe00makoto 0:a62f36392b9b 1 /**
abe00makoto 0:a62f36392b9b 2 * =============================================================================
abe00makoto 0:a62f36392b9b 3 * Application configuration for 'Expansion Board One' example no.2
abe00makoto 0:a62f36392b9b 4 * http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex2_en/
abe00makoto 0:a62f36392b9b 5 * =============================================================================
abe00makoto 0:a62f36392b9b 6 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
abe00makoto 0:a62f36392b9b 7 *
abe00makoto 0:a62f36392b9b 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
abe00makoto 0:a62f36392b9b 9 * of this software and associated documentation files (the "Software"), to deal
abe00makoto 0:a62f36392b9b 10 * in the Software without restriction, including without limitation the rights
abe00makoto 0:a62f36392b9b 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
abe00makoto 0:a62f36392b9b 12 * copies of the Software, and to permit persons to whom the Software is
abe00makoto 0:a62f36392b9b 13 * furnished to do so, subject to the following conditions:
abe00makoto 0:a62f36392b9b 14 *
abe00makoto 0:a62f36392b9b 15 * The above copyright notice and this permission notice shall be included in
abe00makoto 0:a62f36392b9b 16 * all copies or substantial portions of the Software.
abe00makoto 0:a62f36392b9b 17 *
abe00makoto 0:a62f36392b9b 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
abe00makoto 0:a62f36392b9b 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
abe00makoto 0:a62f36392b9b 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
abe00makoto 0:a62f36392b9b 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
abe00makoto 0:a62f36392b9b 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
abe00makoto 0:a62f36392b9b 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
abe00makoto 0:a62f36392b9b 24 * THE SOFTWARE.
abe00makoto 0:a62f36392b9b 25 * =============================================================================
abe00makoto 0:a62f36392b9b 26 */
abe00makoto 0:a62f36392b9b 27
abe00makoto 0:a62f36392b9b 28 #include "appconf.h"
abe00makoto 0:a62f36392b9b 29 #include "ConfigFile.h"
abe00makoto 0:a62f36392b9b 30
abe00makoto 0:a62f36392b9b 31 #define KEY_PACHUBE_APIKEY "PACHUBE_APIKEY"
abe00makoto 0:a62f36392b9b 32 #define KEY_PACHUBE_FEEDID "PACHUBE_FEEDID"
abe00makoto 0:a62f36392b9b 33 //#define KEY_PACHUBE_INTERVAL "PACHUBE_INTERVAL"
abe00makoto 0:a62f36392b9b 34
abe00makoto 0:a62f36392b9b 35 /**
abe00makoto 0:a62f36392b9b 36 * Initialize configuration.
abe00makoto 0:a62f36392b9b 37 *
abe00makoto 0:a62f36392b9b 38 * @param p A pointer to a application config.
abe00makoto 0:a62f36392b9b 39 */
abe00makoto 0:a62f36392b9b 40 void appconf_init(appconf_t *p) {
abe00makoto 0:a62f36392b9b 41 memset(p->apikey, 0, sizeof(p->apikey));
abe00makoto 0:a62f36392b9b 42 memset(p->feedid, 0, sizeof(p->feedid));
abe00makoto 0:a62f36392b9b 43 // p->interval = 0;
abe00makoto 0:a62f36392b9b 44 }
abe00makoto 0:a62f36392b9b 45
abe00makoto 0:a62f36392b9b 46 /**
abe00makoto 0:a62f36392b9b 47 * Read configuration.
abe00makoto 0:a62f36392b9b 48 *
abe00makoto 0:a62f36392b9b 49 * @param filename Filename.
abe00makoto 0:a62f36392b9b 50 * @param p A pointer to a application config.
abe00makoto 0:a62f36392b9b 51 * @return Return zero if it succeed.
abe00makoto 0:a62f36392b9b 52 */
abe00makoto 0:a62f36392b9b 53 int appconf_read(char *filename, appconf_t *p) {
abe00makoto 0:a62f36392b9b 54 ConfigFile cf;
abe00makoto 0:a62f36392b9b 55 if (!cf.read(filename)) {
abe00makoto 0:a62f36392b9b 56 return -1;
abe00makoto 0:a62f36392b9b 57 }
abe00makoto 0:a62f36392b9b 58 if (!cf.getValue(KEY_PACHUBE_APIKEY, p->apikey, sizeof(p->apikey))) {
abe00makoto 0:a62f36392b9b 59 return -2;
abe00makoto 0:a62f36392b9b 60 }
abe00makoto 0:a62f36392b9b 61 if (!cf.getValue(KEY_PACHUBE_FEEDID, p->feedid, sizeof(p->feedid))) {
abe00makoto 0:a62f36392b9b 62 return -3;
abe00makoto 0:a62f36392b9b 63 }
abe00makoto 0:a62f36392b9b 64 /*
abe00makoto 0:a62f36392b9b 65 char buf[64];
abe00makoto 0:a62f36392b9b 66 if (!cf.getValue(KEY_PACHUBE_INTERVAL, buf, sizeof(buf))) {
abe00makoto 0:a62f36392b9b 67 return -4;
abe00makoto 0:a62f36392b9b 68 } else {
abe00makoto 0:a62f36392b9b 69 if (sscanf(buf, "%d", &(p->interval)) != 1) {
abe00makoto 0:a62f36392b9b 70 return -5;
abe00makoto 0:a62f36392b9b 71 }
abe00makoto 0:a62f36392b9b 72 }
abe00makoto 0:a62f36392b9b 73 */
abe00makoto 0:a62f36392b9b 74 return 0;
abe00makoto 0:a62f36392b9b 75 }
abe00makoto 0:a62f36392b9b 76
abe00makoto 0:a62f36392b9b 77 /**
abe00makoto 0:a62f36392b9b 78 * Write configuration.
abe00makoto 0:a62f36392b9b 79 *
abe00makoto 0:a62f36392b9b 80 * @param filename Filename.
abe00makoto 0:a62f36392b9b 81 * @param p A pointer to a application config.
abe00makoto 0:a62f36392b9b 82 * @return Return zero if it succeed.
abe00makoto 0:a62f36392b9b 83 */
abe00makoto 0:a62f36392b9b 84 int appconf_write(char *filename, appconf_t *p) {
abe00makoto 0:a62f36392b9b 85 ConfigFile cf;
abe00makoto 0:a62f36392b9b 86 if (!cf.setValue(KEY_PACHUBE_APIKEY, p->apikey)) {
abe00makoto 0:a62f36392b9b 87 return -1;
abe00makoto 0:a62f36392b9b 88 }
abe00makoto 0:a62f36392b9b 89 if (!cf.setValue(KEY_PACHUBE_FEEDID, p->feedid)) {
abe00makoto 0:a62f36392b9b 90 return -2;
abe00makoto 0:a62f36392b9b 91 }
abe00makoto 0:a62f36392b9b 92 /*
abe00makoto 0:a62f36392b9b 93 char buf[64];
abe00makoto 0:a62f36392b9b 94 snprintf(buf, sizeof(buf) - 1, "%d", p->interval);
abe00makoto 0:a62f36392b9b 95 if (!cf.setValue(KEY_PACHUBE_INTERVAL, buf)) {
abe00makoto 0:a62f36392b9b 96 return -3;
abe00makoto 0:a62f36392b9b 97 }
abe00makoto 0:a62f36392b9b 98 */
abe00makoto 0:a62f36392b9b 99 if (!cf.write(filename)) {
abe00makoto 0:a62f36392b9b 100 return -4;
abe00makoto 0:a62f36392b9b 101 }
abe00makoto 0:a62f36392b9b 102 return 0;
abe00makoto 0:a62f36392b9b 103 }