Ignore:
Timestamp:
Feb 1, 2019, 9:57:09 PM (5 years ago)
Author:
coas-nagasima
Message:

TINETとSocket APIなどを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/echonet_main.c

    r352 r364  
    11/*
    22 *  TOPPERS ECHONET Lite Communication Middleware
    3  * 
     3 *
    44 *  Copyright (C) 2014-2018 Cores Co., Ltd. Japan
    5  * 
     5 *
    66 *  上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
    77 *  ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
     
    2626 *      由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
    2727 *      免責すること.
    28  * 
     28 *
    2929 *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
    3030 *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
     
    3232 *  アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
    3333 *  の責任を負わない.
    34  * 
     34 *
    3535 *  @(#) $Id$
    3636 */
    3737
    38 /* 
     38/*
    3939 *  サンプルプログラム(1)の本体
    4040 */
     
    5555#include "adafruit_st7735.h"
    5656#include "draw_font.h"
     57#include <tinet_defs.h>
     58#include <tinet_config.h>
     59#include <netinet/in.h>
     60#include <netinet/in_var.h>
     61#include <net/ethernet.h>
     62#include <net/if_var.h>
     63
     64extern uint8_t mac_addr[6];
    5765
    5866/* TODO: メーカーコードを設定 */
     
    111119
    112120        /* サイズが1以外は受け付けない */
    113         if(size != 1)
     121        if (size != 1)
    114122                return 0;
    115123
    116124        *anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
    117125
    118         switch(*(uint8_t *)src){
     126        switch (*(uint8_t *)src) {
    119127        /* ONの場合 */
    120128        case 0x30:
     
    126134                data[1] = *(uint8_t *)src;
    127135                ret = ecn_brk_wai(data, sizeof(data));
    128                 if(ret != E_OK){
     136                if (ret != E_OK) {
    129137                        syslog(LOG_ERROR, "ecn_brk_wai");
    130138                        return 1;
     
    145153{
    146154        /* サイズが1以外は受け付けない */
    147         if(size != 1)
     155        if (size != 1)
    148156                return 0;
    149157
    150158        *anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
    151159
    152         switch(*(uint8_t *)src){
     160        switch (*(uint8_t *)src) {
    153161        /* 異常発生ありの場合 */
    154162        case 0x41:
     
    176184
    177185        /* サイズが2以外は受け付けない */
    178         if(size != 2)
     186        if (size != 2)
    179187                return 0;
    180188
    181189        value = (((uint8_t *)src)[0] << 8) | (((uint8_t *)src)[1] & 0xFF);
    182190
    183         if((value >= -2732) && (value <= 32766)){
     191        if ((value >= -2732) && (value <= 32766)) {
    184192                eobj->propertyE0 = value;
    185193                /* メインタスクに通知 */
    186194                data[0] = 0xE0;
    187195                ret = ecn_brk_wai(data, sizeof(data));
    188                 if(ret != E_OK){
     196                if (ret != E_OK) {
    189197                        syslog(LOG_ERROR, "ecn_brk_wai");
    190198                        return 2;
     
    192200        }
    193201        /* 上記以外は受け付けない */
    194         else{
     202        else {
    195203                return 0;
    196204        }
     
    199207}
    200208
    201 /* 
     209/*
    202210 * 温度計測値取得関数
    203211 */
     
    208216
    209217        /* サイズが2以外は受け付けない */
    210         if(size != 2)
     218        if (size != 2)
    211219                return 0;
    212220
     
    240248
    241249        ret2 = get_tim(&now);
    242         if (ret2 != E_OK){
     250        if (ret2 != E_OK) {
    243251                syslog(LOG_ERROR, "get_tim");
    244252                return;
    245253        }
    246254
    247         for(;;){
     255        for (;;) {
    248256                prev = now;
    249257
     
    253261                /* 応答電文待ち */
    254262                ret = ecn_trcv_esv(&esv, timer);
    255                 if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)){
     263                if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)) {
    256264                        syslog(LOG_ERROR, "ecn_trcv_esv");
    257265                        break;
     
    259267
    260268                ret2 = get_tim(&now);
    261                 if (ret2 != E_OK){
     269                if (ret2 != E_OK) {
    262270                        syslog(LOG_ERROR, "get_tim");
    263271                        break;
     
    274282                        /* 領域解放 */
    275283                        ret = ecn_rel_esv(esv);
    276                         if (ret != E_OK){
     284                        if (ret != E_OK) {
    277285                                syslog(LOG_ERROR, "ecn_rel_esv");
    278286                                break;
     
    283291                        /* 応答電文待ちの割り込みデータ取得 */
    284292                        ret = ecn_get_brk_dat(esv, brkdat, sizeof(brkdat), &len);
    285                         if (ret != E_OK){
     293                        if (ret != E_OK) {
    286294                                syslog(LOG_ERROR, "ecn_get_brk_dat");
    287295                                break;
     
    293301                        /* 領域解放 */
    294302                        ret = ecn_rel_esv(esv);
    295                         if (ret != E_OK){
     303                        if (ret != E_OK) {
    296304                                syslog(LOG_ERROR, "ecn_rel_esv");
    297305                                break;
     
    304312}
    305313
    306 bool_t started = false;
    307 
    308314void echonet_change_netif_link(uint8_t link_up, uint8_t up)
    309315{
     
    313319                return;
    314320
    315         if (up && !started) {
    316                 started = true;
    317 
    318                 /* ECHONETミドルウェアを起動 */
    319                 ret = ecn_sta_svc();
    320                 if (ret != E_OK)
    321                         return;
    322 
    323                 /* ECHONETミドルウェアを起動するのを待つ */
    324                 dly_tsk(100);
     321        if (up) {
     322                /* インスタンスリスト通知の送信 */
     323                ret = ecn_ntf_inl();
     324                if (ret != E_OK) {
     325                        syslog(LOG_ERROR, "ecn_ntf_inl");
     326                }
    325327        }
    326328
     
    328330        uint8_t data[2];
    329331        data[0] = 0x01;
    330         data[1] = up ? 0x01 : 0x02;
     332        data[1] = (up ? 0x01 : 0x02) | (link_up ? 0x10 : 0x20);
    331333        ret = ecn_brk_wai(data, sizeof(data));
    332334        if (ret != E_OK) {
     
    336338}
    337339
    338 enum main_state_t{
     340enum main_state_t {
     341        main_state_start,
    339342        main_state_idle,
    340343};
    341344
    342345int main_timer = TMO_FEVR;
    343 enum main_state_t main_state = main_state_idle;
     346enum main_state_t main_state = main_state_start;
    344347
    345348int main_lcd_timer = TMO_FEVR;
     
    386389        analogin_init(&joystick, P1_12);
    387390
    388         /* 10ms後にボタン状態を確認 */
    389         main_timer = 10 * 1000;
     391        /* ECHONETミドルウェアを起動するのを待つ */
     392        main_state = main_state_start;
     393        main_timer = 1000 * 1000;
    390394
    391395        /* ボタン状態読み込み */
     
    397401        spi_init(&lcd.hspi, P10_14, P10_15, P10_12, NC);
    398402        spi_format(&lcd.hspi, 8, 0, 0);
    399         spi_frequency(&lcd.hspi, 1000000);
     403        spi_frequency(&lcd.hspi, 4000000);
    400404
    401405        gpio_init_out(&lcd.cs_pin, P10_13);
     
    416420        main_lcd_timer = 1000 * 1000;
    417421
     422        /* メインタスクを起動 */
    418423        ER ret = act_tsk(MAIN_TASK);
    419424        if (ret != E_OK) {
     
    429434        int result = main_timer;
    430435
    431         if((result == TMO_FEVR)
    432                 || ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))){
     436        if ((result == TMO_FEVR)
     437                || ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))) {
    433438                result = main_lcd_timer;
    434439        }
     
    442447static void main_progress(int interval)
    443448{
    444         if(main_timer != TMO_FEVR){
     449        if (main_timer != TMO_FEVR) {
    445450                main_timer -= interval;
    446                 if(main_timer < 0){
     451                if (main_timer < 0) {
    447452                        main_timer = 0;
    448453                }
    449454        }
    450455
    451         if(main_lcd_timer != TMO_FEVR){
     456        if (main_lcd_timer != TMO_FEVR) {
    452457                main_lcd_timer -= interval;
    453                 if(main_lcd_timer < 0){
     458                if (main_lcd_timer < 0) {
    454459                        main_lcd_timer = 0;
    455460                }
     
    472477
    473478        ret = ecn_itr_ini(&enm, esv);
    474         if(ret != E_OK){
     479        if (ret != E_OK) {
    475480                syslog(LOG_ERROR, "ecn_itr_ini");
    476481                return;
    477482        }
    478483
    479         for(;;) {
    480                 while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
     484        for (;;) {
     485                while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
    481486                        switch (epc) {
    482487                        case 0xE0:
    483                                 if(in_get && (esv->hdr.edata.esv == ESV_SET_GET_RES)){
     488                                if (in_get && (esv->hdr.edata.esv == ESV_SET_GET_RES)) {
    484489                                        check_response(pdc, p_edt);
    485490                                }
     
    487492                        }
    488493                }
    489                 if(ret != E_BOVR){
     494                if (ret != E_BOVR) {
    490495                        syslog(LOG_ERROR, "ecn_itr_nxt");
    491496                        break;
    492497                }
    493                 if(enm.is_eof)
     498                if (enm.is_eof)
    494499                        break;
    495500
     
    504509static void main_break_wait(uint8_t *brkdat, int32_t len)
    505510{
     511        char mac_text[30] = "mac: ";
     512        char ipaddr_text[30] = "ipadr: ";
     513        const T_IN4_ADDR *ip4_addr;
     514        int pos;
     515
    506516        if (brkdat[0] == 0x01) {
    507                 // Link up/down
     517                pos = str_macaddr(&mac_text[4], sizeof(mac_text) - 4, mac_addr, 0);
     518                mac_text[pos + 4] = '\0';
     519                lcd_drawString(&lcd, mac_text, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 11), ST7735_BLACK, ST7735_WHITE);
     520
     521                ip4_addr = in4_get_ifaddr(0);
     522                pos = str_ipv4addr(&ipaddr_text[6], sizeof(ipaddr_text) - 6, ip4_addr, 0);
     523                ipaddr_text[pos + 6] = '\0';
     524                lcd_drawString(&lcd, ipaddr_text, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 12), ST7735_BLACK, ST7735_WHITE);
    508525                return;
    509526        }
    510527
    511528        if ((len == 2) && (brkdat[0] == 0x80)) {
    512                 switch(brkdat[1]){
     529                switch (brkdat[1]) {
    513530                /* ONの場合 */
    514531                case 0x30:
     
    533550static void main_timeout()
    534551{
    535         if(main_timer == 0){
     552        if (main_timer == 0) {
    536553                main_ontimer();
    537554        }
    538555
    539         if(main_lcd_timer == 0){
     556        if (main_lcd_timer == 0) {
    540557                main_lcd_ontimer();
    541558        }
     
    543560
    544561#define main_ad_count 3
     562#define main_ad_table_count 64
    545563static int16_t main_ad_tempr[main_ad_count] = { 200, 200, 200 };
    546 static uint16_t main_ad_table[64];
    547 #define main_ad_table_count (sizeof(main_ad_table) / sizeof(main_ad_table[0]))
     564static uint16_t main_ad_table[main_ad_count][main_ad_table_count];
    548565static int main_ad_pos = 0;
    549566static uint32_t main_ad_avelage[main_ad_count];
     
    556573static void main_ontimer()
    557574{
     575        ER ret;
    558576        uint8_t btn;
    559577        uint16_t ad_value;
    560578        int16_t ad_tempr;
    561579
    562         switch(main_state){
     580        switch (main_state) {
     581        case main_state_start:
     582                /* ECHONETミドルウェアを起動 */
     583                ret = ecn_sta_svc();
     584                if (ret != E_OK) {
     585                        syslog(LOG_ERROR, "ecn_sta_svc");
     586                }
     587
     588                /* 10ms後にボタン状態を確認 */
     589                main_state = main_state_idle;
     590                main_timer = 10 * 1000;
     591                break;
    563592        case main_state_idle:
    564593                /* 10ms後にボタン状態を確認 */
     
    567596                /* ADCの変換結果取得 */
    568597                for (int i = 0; i < main_ad_count; i++) {
    569                         main_ad_avelage[i] -= main_ad_table[main_ad_pos];
     598                        main_ad_avelage[i] -= main_ad_table[i][main_ad_pos];
    570599                        ad_value = analogin_read_u16(&analogin[i]) >> 4;        // 16bit値取得->12bit
    571                         main_ad_table[main_ad_pos] = ad_value;
     600                        main_ad_table[i][main_ad_pos] = ad_value;
    572601                        main_ad_avelage[i] += ad_value;
    573602                }
    574603
    575604                main_ad_pos++;
    576                 if(main_ad_pos >= main_ad_table_count){
     605                if (main_ad_pos >= main_ad_table_count) {
    577606                        main_ad_pos = 0;
    578607                }
     
    586615                                }
    587616                                else {
     617                                        main_count[i] = 0;
    588618                                        main_ad_tempr[i] = ad_tempr;
    589619
     
    601631
    602632                /* ボタン1の処理 */
    603                 if((btn == BUTTON_LEFT) && !main_btn1_state){
     633                if ((btn == BUTTON_LEFT) && !main_btn1_state) {
    604634                        main_btn1_count++;
    605                         if(main_btn1_count > 10){
     635                        if (main_btn1_count > 10) {
    606636                                main_btn1_count = 0;
    607637                                main_btn1_state = true;
     
    610640                        }
    611641                }
    612                 else if((btn != BUTTON_LEFT) && main_btn1_state){
     642                else if ((btn != BUTTON_LEFT) && main_btn1_state) {
    613643                        main_btn1_count++;
    614                         if(main_btn1_count > 10){
     644                        if (main_btn1_count > 10) {
    615645                                main_btn1_count = 0;
    616646                                main_btn1_state = false;
     
    621651
    622652                /* ボタン2の処理 */
    623                 if((btn == BUTTON_RIGHT) && !main_btn2_state){
     653                if ((btn == BUTTON_RIGHT) && !main_btn2_state) {
    624654                        main_btn2_count++;
    625                         if(main_btn2_count > 10){
     655                        if (main_btn2_count > 10) {
    626656                                main_btn2_count = 0;
    627657                                main_btn2_state = true;
     
    630660                        }
    631661                }
    632                 else if((btn != BUTTON_RIGHT) && main_btn2_state){
     662                else if ((btn != BUTTON_RIGHT) && main_btn2_state) {
    633663                        main_btn2_count++;
    634                         if(main_btn2_count > 10){
     664                        if (main_btn2_count > 10) {
    635665                                main_btn2_count = 0;
    636666                                main_btn2_state = false;
     
    645675static void main_lcd_ontimer()
    646676{
    647         char temp1[] = "温度1:+00.0℃";
    648         char temp2[] = "温度2:+00.0℃";
    649         char humid[] = "湿度 :+00.0%";
     677        char temp1[] = "温度1:+000.0℃";
     678        char temp2[] = "温度2:+000.0℃";
     679        char humid[] = "湿度 :+000.0%";
    650680        char *btn_texts[] = { "none  ", "down  ", "left  ", "select", "up    ", "right " };
    651681        int temp, btn;
     
    653683        switch (main_lcd_state) {
    654684        case 0:
    655                 temp1[9] = (temperature_sensor1_data.propertyE0 >= 0) ? ' ' : '-';
     685                temp1[10] = (temperature_sensor1_data.propertyE0 >= 0) ? ' ' : '-';
    656686                temp = (temperature_sensor1_data.propertyE0 / 1000) % 10;
    657687                if (temp < 0)
    658688                        temp = -temp;
    659                 temp1[10] = '0' + temp;
     689                temp1[11] = '0' + temp;
    660690                temp = (temperature_sensor1_data.propertyE0 / 100) % 10;
    661691                if (temp < 0)
    662692                        temp = -temp;
    663                 temp1[11] = '0' + temp;
     693                temp1[12] = '0' + temp;
    664694                temp = (temperature_sensor1_data.propertyE0 / 10) % 10;
    665695                if (temp < 0)
    666696                        temp = -temp;
    667697                temp1[13] = '0' + temp;
    668                 lcd_drawString(&lcd, &temp1[9], X_LINE_HALF_TO_PIX(&lcd, 8) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
     698                temp = (temperature_sensor1_data.propertyE0 / 1) % 10;
     699                if (temp < 0)
     700                        temp = -temp;
     701                temp1[15] = '0' + temp;
     702                lcd_drawString(&lcd, &temp1[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
    669703                main_lcd_state++;
    670704                break;
    671705        case 1:
    672                 temp2[9] = (temperature_sensor2_data.propertyE0 >= 0) ? ' ' : '-';
     706                temp2[10] = (temperature_sensor2_data.propertyE0 >= 0) ? ' ' : '-';
    673707                temp = (temperature_sensor2_data.propertyE0 / 1000) % 10;
    674708                if (temp < 0)
    675709                        temp = -temp;
    676                 temp2[10] = '0' + temp;
     710                temp2[11] = '0' + temp;
    677711                temp = (temperature_sensor2_data.propertyE0 / 100) % 10;
    678712                if (temp < 0)
    679713                        temp = -temp;
    680                 temp2[11] = '0' + temp;
     714                temp2[12] = '0' + temp;
    681715                temp = (temperature_sensor2_data.propertyE0 / 10) % 10;
    682716                if (temp < 0)
    683717                        temp = -temp;
    684718                temp2[13] = '0' + temp;
    685                 lcd_drawString(&lcd, &temp2[9], X_LINE_HALF_TO_PIX(&lcd, 8) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
     719                temp = (temperature_sensor2_data.propertyE0 / 1) % 10;
     720                if (temp < 0)
     721                        temp = -temp;
     722                temp2[15] = '0' + temp;
     723                lcd_drawString(&lcd, &temp2[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
    686724                main_lcd_state++;
    687725                break;
    688726        case 2:
    689                 humid[9] = ' ';
    690                 temp = (humidity_sensor_data.propertyE0 / 1000) % 10;
    691                 humid[10] = '0' + temp;
     727                humid[10] = ' ';
     728                humid[11] = ' ';
    692729                temp = (humidity_sensor_data.propertyE0 / 100) % 10;
    693                 humid[11] = '0' + temp;
     730                humid[12] = '0' + temp;
    694731                temp = (humidity_sensor_data.propertyE0 / 10) % 10;
    695732                humid[13] = '0' + temp;
    696                 lcd_drawString(&lcd, &humid[9], X_LINE_HALF_TO_PIX(&lcd, 8) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
     733                temp = (humidity_sensor_data.propertyE0 / 1) % 10;
     734                humid[15] = '0' + temp;
     735                lcd_drawString(&lcd, &humid[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
    697736                main_lcd_state++;
    698737                break;
     
    704743        case 6:
    705744                btn = main_read_button(&joystick);
    706                 lcd_drawString(&lcd, btn_texts[btn], X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 10) + 10, ST7735_BLACK, ST7735_WHITE);
     745                lcd_drawString(&lcd, btn_texts[btn], X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 9), ST7735_BLACK, ST7735_WHITE);
    707746                main_lcd_state++;
    708747                break;
     
    711750                break;
    712751        case 10:
    713                 lcd_drawString(&lcd, "温度湿度計", X_LINE_TO_PIX(&lcd, 9) + 10, Y_ROW_TO_PIX(&lcd, 0) + 10, ST7735_BLACK, ST7735_WHITE);
    714                 lcd_drawString(&lcd, temp1, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 0 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
    715                 lcd_drawString(&lcd, temp2, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 1 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
    716                 lcd_drawString(&lcd, humid, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 2 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
     752                lcd_drawString(&lcd, "温度湿度計", X_LINE_TO_PIX(&lcd, 5), Y_ROW_TO_PIX(&lcd, 0), ST7735_BLACK, ST7735_WHITE);
     753                lcd_drawString(&lcd, temp1, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 0 + 2), ST7735_BLACK, ST7735_WHITE);
     754                lcd_drawString(&lcd, temp2, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 1 + 2), ST7735_BLACK, ST7735_WHITE);
     755                lcd_drawString(&lcd, humid, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 2 + 2), ST7735_BLACK, ST7735_WHITE);
    717756                main_lcd_state = 0;
    718757                break;
     
    755794        /* プロパティ設定電文作成 */
    756795        ret = ecn_esv_setc(&esv, eobj, 0xE0, 2, p_edt);
    757         if(ret != E_OK){
     796        if (ret != E_OK) {
    758797                syslog(LOG_ERROR, "ecn_esv_setc");
    759798                return;
     
    761800
    762801        /* 電文送信 */
    763         ecn_snd_esv(esv);
     802        ret = ecn_snd_esv(esv);
     803        if (ret != E_OK) {
     804                syslog(LOG_ERROR, "ecn_snd_esv");
     805        }
    764806}
    765807
     
    798840
    799841        /* 押されて戻った時に処理する */
    800         if(push)
     842        if (push)
    801843                return;
    802844
    803845        /* 温度計測値 */
    804846        main_tmpr -= 10;        /* - 1.0℃ */
    805         if(main_tmpr < -100)    /* -10.0℃までとする */
     847        if (main_tmpr < -100)   /* -10.0℃までとする */
    806848                main_tmpr = -100;
    807849
     
    811853        /* プロパティ値書き込み・読み出し要求電文作成 */
    812854        ret = ecn_esv_set_get(&esv, TEMP_SENSOR_02_EOBJ, 0xE0, 2, p_edt);
    813         if(ret != E_OK){
     855        if (ret != E_OK) {
    814856                syslog(LOG_ERROR, "ecn_esv_setc");
    815857                return;
     
    820862        /* 書き込みプロパティ追加 */
    821863        ret = ecn_add_edt(esv, 0x80, 1, p_edt);
    822         if(ret) {
     864        if (ret) {
    823865                syslog(LOG_ERROR, "ecn_add_edt");
    824866                goto error;
     
    827869        /* プロパティ値書き込み・読み出し要求電文作成:折り返し指定 */
    828870        ret = ecn_trn_set_get(esv, &trn_pos);
    829         if(ret) {
     871        if (ret) {
    830872                syslog(LOG_ERROR, "ecn_trn_set_get");
    831873                goto error;
     
    834876        /* 読み出しプロパティ追加 */
    835877        ret = ecn_add_epc(esv, 0xE0);
    836         if(ret) {
     878        if (ret) {
    837879                syslog(LOG_ERROR, "ecn_add_epc");
    838880                goto error;
     
    841883        /* プロパティ値書き込み・読み出し要求電文作成:終了指定 */
    842884        ret = ecn_end_set_get(esv, trn_pos);
    843         if(ret) {
     885        if (ret) {
    844886                syslog(LOG_ERROR, "ecn_end_set_get");
    845887                goto error;
     
    848890        /* 電文送信 */
    849891        ret = ecn_snd_esv(esv);
    850         if(ret != E_OK){
     892        if (ret != E_OK) {
    851893                syslog(LOG_ERROR, "ecn_snd_esv");
    852894        }
     
    855897        /* 領域解放 */
    856898        ret = ecn_rel_esv(esv);
    857         if (ret != E_OK){
     899        if (ret != E_OK) {
    858900                syslog(LOG_ERROR, "ecn_rel_esv");
    859901        }
     
    871913
    872914        /* 押されて戻った時に処理する */
    873         if(push)
     915        if (push)
    874916                return;
    875917
    876918        /* 温度計測値 */
    877919        main_tmpr += 10;        /* + 1.0℃ */
    878         if(main_tmpr > 400)     /* +40.0℃までとする */
     920        if (main_tmpr > 400)    /* +40.0℃までとする */
    879921                main_tmpr = 400;
    880922
     
    884926        /* プロパティ値書き込み・読み出し要求電文作成 */
    885927        ret = ecn_esv_set_get(&esv, TEMP_SENSOR_02_EOBJ, 0xE0, 2, p_edt);
    886         if(ret != E_OK){
     928        if (ret != E_OK) {
    887929                syslog(LOG_ERROR, "ecn_esv_setc");
    888930                return;
     
    893935        /* 書き込みプロパティ追加 */
    894936        ret = ecn_add_edt(esv, 0x80, 1, p_edt);
    895         if(ret) {
     937        if (ret) {
    896938                syslog(LOG_ERROR, "ecn_add_edt");
    897939                goto error;
     
    900942        /* プロパティ値書き込み・読み出し要求電文作成:折り返し指定 */
    901943        ret = ecn_trn_set_get(esv, &trn_pos);
    902         if(ret) {
     944        if (ret) {
    903945                syslog(LOG_ERROR, "ecn_trn_set_get");
    904946                goto error;
     
    907949        /* 読み出しプロパティ追加 */
    908950        ret = ecn_add_epc(esv, 0xE0);
    909         if(ret) {
     951        if (ret) {
    910952                syslog(LOG_ERROR, "ecn_add_epc");
    911953                goto error;
     
    914956        /* プロパティ値書き込み・読み出し要求電文作成:終了指定 */
    915957        ret = ecn_end_set_get(esv, trn_pos);
    916         if(ret) {
     958        if (ret) {
    917959                syslog(LOG_ERROR, "ecn_end_set_get");
    918960                goto error;
     
    921963        /* 電文送信 */
    922964        ret = ecn_snd_esv(esv);
    923         if(ret != E_OK){
     965        if (ret != E_OK) {
    924966                syslog(LOG_ERROR, "ecn_snd_esv");
    925967        }
     
    928970        /* 領域解放 */
    929971        ret = ecn_rel_esv(esv);
    930         if (ret != E_OK){
     972        if (ret != E_OK) {
    931973                syslog(LOG_ERROR, "ecn_rel_esv");
    932974        }
     
    938980static bool_t check_response(uint8_t pdc, uint8_t *p_edt)
    939981{
    940         if((pdc != 2)
     982        if ((pdc != 2)
    941983                || (p_edt[0] != ((uint16_t)main_tmpr) >> 8)
    942                 || (p_edt[1] != ((uint16_t)main_tmpr) & 0xFF))
    943         {
     984                || (p_edt[1] != ((uint16_t)main_tmpr) & 0xFF)) {
    944985                syslog(LOG_WARNING, "epc_set_get response NG");
    945986                return false;
Note: See TracChangeset for help on using the changeset viewer.