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: TextLCD mbed ConfigFile
main.cpp
00001 #include "mbed.h" 00002 00003 # include "string.h" 00004 00005 #include "TextLCD.h" 00006 00007 #include "ConfigFile.h" 00008 00009 #include "eth_comfort.h" 00010 #include "rfm.h" 00011 #include "rfm12b.h" 00012 00013 /*! 00014 * \file main.cpp 00015 * \brief Read messages from ETH-Radio-Shutters and send On/Off-Commands to KNX (via freebus-rs-interface) 00016 * \author Karl Zweimüller 00017 */ 00018 00019 TextLCD lcd(p30, p29, p28, p27, p26, p25, TextLCD::LCD16x2); // rs, e, d0-d3 00020 00021 eth_comfort eth_comf(p11, p12, p13, p14, p18, LED4); // mosi, miso, sclk, cs, rxdata, rxled 00022 00023 Serial pc(USBTX, USBRX); // tx, rx 00024 00025 //Freebus-RS-Interface connected to serial 00026 Serial knxrs(p9, p10); // tx, rx 00027 00028 // Filesystem for Config-File 00029 LocalFileSystem local("local"); 00030 00031 ConfigFile cfg; 00032 00033 // mbed LEDs 00034 /* 00035 DigitalOut led1(LED1); 00036 DigitalOut led2(LED2); 00037 DigitalOut led3(LED3); 00038 DigitalOut led4(LED4); 00039 */ 00040 00041 //--------------------------------------------------------------------- 00042 // 00043 //--------------------------------------------------------------------- 00044 00045 int main() { 00046 00047 char group[255]; // the KNX-Group-address 00048 char ethid[255]; //the ETH-ID as string 00049 char command[255]; // a command to send to the freebus rs-interface 00050 00051 eth_message message; // holds a message from the ETH-window-shutter 00052 00053 pc.baud(115200); 00054 00055 pc.printf("\n\rConnected to mbed\n\r"); 00056 lcd.printf("ETH-Freebus: OK\n"); 00057 00058 /* 00059 * Read the configuration file from mbed. 00060 */ 00061 if (!cfg.read("/local/knx.cfg")) { 00062 pc.printf("Failure to read configuration file knx.cfg.\n\r"); 00063 } 00064 00065 00066 // initialize freebus-rs-interface 00067 // 115.200 Baud,n,8,1 00068 knxrs.baud(115200); 00069 00070 knxrs.printf("fbecho=0\r"); //switch off echo 00071 00072 00073 do { 00074 // anything new? 00075 if (eth_comf.readable()) { 00076 // read the new message and display 00077 message = eth_comf.getMessage(); 00078 pc.printf("\n\rCounter: %02X\n\r",message.cnt); 00079 pc.printf( " Dev-ID: %06X\n\r",message.adr); 00080 pc.printf( " cmd: %0X\n\r",message.cmd); 00081 //pc.printf( "cmd&0x80: %0X\n\r",message.cmd&0x80); 00082 // why doesn't work the following?????????????? 00083 //pc.printf( "Battery: "); 00084 //if (message.cmd&0x80 == 0x00) pc.printf("GOOD\n\r"); else pc.printf("WEAK\n\r"); 00085 00086 pc.printf( "Window : %s\n\r\n\r", (message.cmd&0x01 != 0x00) ? "OPEN" : "CLOSE"); 00087 lcd.cls(); 00088 lcd.printf("#:%02X ID: %06X\n",message.cnt,message.adr); 00089 lcd.printf("Window : %s\n", (message.cmd&0x01 != 0x00) ? "OPEN" : "CLOSE"); 00090 pc.printf("\n\r"); 00091 00092 00093 // convert id to string 00094 sprintf(ethid,"%06X",message.adr); 00095 /* 00096 * Get the group address from configuration value. 00097 */ 00098 if (cfg.getValue(ethid, &group[0], sizeof(group))) { 00099 pc.printf("Config-File: '%s'='%s'\n\r", ethid,group ); 00100 } else { 00101 strcpy(group ,""); 00102 } 00103 00104 00105 if (strlen(group) > 0) { 00106 sprintf(command, "fbs01/%s=%s\r",group,(message.cmd&0x01 != 0x00) ? "1" : "0"); // EIS01 on Group-address group : Open=1 Close=0 00107 // Send a KNX-Telegramm 00108 knxrs.printf("%s",command); 00109 pc.printf("%s\n\r",command); 00110 } else { 00111 // device not in config file, so add it 00112 // add the new device to the config and write file 00113 pc.printf("new unknown device!\n\r"); 00114 /* we don't write the file, as all comments are lost 00115 if (!cfg.setValue(ethid, "")) { 00116 error("Failure to set a value.\n\r"); 00117 } 00118 if (!cfg.write("/local/knx.cfg")) { 00119 error("Failure to write the configuration file.\n\r"); 00120 } 00121 */ 00122 } 00123 } 00124 } while (1==1); 00125 00126 } 00127 00128
Generated on Tue Jul 12 2022 17:36:56 by
1.7.2