int main (int ac, char *ag[]) { int len, addr; EIBConnection *con; uchar buf[255]; eibaddr_t dest; char *prog = ag[0]; parseKey (&ac, &ag); if (ac != 5) die ("usage: %s url [-k key] eibaddr addr count", prog); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); dest = readaddr (ag[2]); addr = readHex (ag[3]); len = atoi (ag[4]); if (EIB_MC_Connect (con, dest) == -1) die ("Connect failed"); auth (con); len = EIB_MC_Read (con, addr, len, buf); if (len == -1) die ("Read failed"); printHex (len, buf); EIBClose (con); return 0; }
int main (int ac, char *ag[]) { uchar buf[255]; int len; EIBConnection *con; if (ac != 2) die ("usage: %s url", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); if (EIBOpenBusmonitorText (con) == -1) die ("Open Busmonitor failed"); while (1) { len = EIBGetBusmonitorPacket (con, sizeof (buf), buf); if (len == -1) die ("Read failed"); buf[len] = 0; printf ("%s\n", buf); fflush (stdout); } EIBClose (con); return 0; }
int main (int ac, char *ag[]) { int len; EIBConnection *con; eibaddr_t dest; char *prog = ag[0]; parseKey (&ac, &ag); if (ac != 3) die ("usage: %s [-k key] url eibaddr", prog); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); dest = readaddr (ag[2]); if (EIB_MC_Connect (con, dest) == -1) die ("Connect failed"); auth (con); len = EIB_MC_Progmode_Toggle (con); if (len == -1) die ("Set failed"); EIBClose (con); return 0; }
int main (int ac, char *ag[]) { uchar buf[255]; int len; uint32_t ts; uint8_t status; EIBConnection *con; if (ac != 2) die ("usage: %s url", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); if (EIBOpenBusmonitorTS (con, &ts) == -1) die ("Open Busmonitor failed"); printf ("TS-Base: %08x\n", ts); while (1) { len = EIBGetBusmonitorPacketTS (con, &status, &ts, sizeof (buf), buf); if (len == -1) die ("Read failed"); printf ("(%d, %08x) ", status, ts); printHex (len, buf); printf ("\n"); fflush (stdout); } EIBClose (con); return 0; }
int main (int ac, char *ag[]) { int len; EIBConnection *con; eibaddr_t dest; uchar buf[255] = { 0, 0x80 }; if (ac < 4) die ("usage: %s url eibaddr val val ...", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); dest = readgaddr (ag[2]); len = readBlock (buf + 2, sizeof (buf) - 2, ac - 3, ag + 3); if (EIBOpen_GroupSocket (con, 1) == -1) die ("Connect failed"); len = EIBSendGroup (con, dest, 2 + len, buf); if (len == -1) die ("Request failed"); printf ("Send request\n"); EIBClose (con); return 0; }
int main (int ac, char *ag[]) { uchar buf[255]; buf[0] = 0xFA; buf[1] = 0xBC; buf[2] = 0x3; buf[3] = 0x4; int rc=0, i=0; eibaddr_t myAddr = 22; eibaddr_t dest = 11; EIBConnection *con; if (ac != 2) { printf("usage: %s <EIB-URL>\n\n", ag[0]); return -1; } con = EIBSocketURL (ag[1]); if (!con) { printf("EIBSocketURL() failed\n\n"); return -1; } printf("URL opened\n\n"); //if (EIBOpenBusmonitor(con) == -1) if (EIBOpenVBusmonitor(con) == -1) { printf("EIBOpenBusmonitor() failed\n\n"); return -1; } printf("entering loop\n"); while(1) { printf("waiting..."); rc = EIBGetBusmonitorPacket(con, sizeof(buf), buf); if(rc == -1) { printf("EIBGetBusmonitorPacket() failed\n\n"); return -1; } else { for(i=0; i < rc; i++) printf("%02X ", buf[i]); decodeFrame(buf); } } EIBClose (con); printf("con closed\n\n"); return 0; }
int main (int ac, char *ag[]) { uchar buf[10000]; int len; int i; EIBConnection *con; eibaddr_t dest; fd_set read; char *prog = ag[0]; parseKey (&ac, &ag); if (ac != 3) die ("usage: %s [-k key] url eibaddr", prog); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); dest = readaddr (ag[2]); if (EIB_MC_Connect (con, dest) == -1) die ("Connect failed"); auth (con); len = EIB_MC_PropertyScan_async (con, sizeof (buf), buf); if (len == -1) die ("Read failed"); lp: FD_ZERO (&read); FD_SET (EIB_Poll_FD (con), &read); printf ("Waiting\n"); if (select (EIB_Poll_FD (con) + 1, &read, 0, 0, 0) == -1) die ("select failed"); printf ("Data available\n"); len = EIB_Poll_Complete (con); if (len == -1) die ("Read failed"); if (len == 0) goto lp; printf ("Completed\n"); len = EIBComplete (con); for (i = 0; i < len; i += 6) if (buf[i + 1] == 1 && buf[i + 2] == 4) printf ("Obj: %d Property: %d Type: %d Objtype:%d Access:%02X\n", buf[i + 0], buf[i + 1], buf[i + 2], (buf[i + 3] << 8) | buf[i + 4], buf[i + 5]); else printf ("Obj: %d Property: %d Type: %d Count:%d Access:%02X\n", buf[i + 0], buf[i + 1], buf[i + 2], (buf[i + 3] << 8) | buf[i + 4], buf[i + 5]); EIBClose (con); return 0; }
void KnxConnection::Run (pth_sem_t * stop1) { if (url_m == "") return; stop_m = pth_event (PTH_EVENT_SEM, stop1); bool retry = true; while (retry) { con_m = EIBSocketURL(url_m.c_str()); if (con_m) { EIBSetEvent (con_m, stop_m); if (EIBOpen_GroupSocket (con_m, 0) != -1) { logger_m.infoStream() << "KnxConnection: Group socket opened. Waiting for messages." << endlog; // If scope reached this point, there is no doubt that the // connection with the bus is up and ready. isReady_m = true; int retval; while ((retval = checkInput()) > 0) { /* TODO: find another way to check if event occured struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; pth_select_ev(0,0,0,0,&tv,stop); */ } if (retval == -1) retry = false; } else logger_m.errorStream() << "Failed to open group socket." << endlog; if (con_m) EIBClose(con_m); con_m = 0; } else logger_m.errorStream() << "Failed to open knxConnection url." << endlog; if (retry) { struct timeval tv; tv.tv_sec = 60; tv.tv_usec = 0; pth_select_ev(0,0,0,0,&tv,stop_m); if (pth_event_status (stop_m) == PTH_STATUS_OCCURRED) retry = false; } } logger_m.infoStream() << "Out of KnxConnection loop." << endlog; pth_event_free (stop_m, PTH_FREE_THIS); stop_m = 0; }
int main (int ac, char *ag[]) { //MM hires-time struct timeval tv; struct tm* ptm; char time_string[40]; long milliseconds; /* Obtain the time of day, and convert it to a tm struct. */ gettimeofday (&tv, NULL); ptm = localtime (&tv.tv_sec); /* Format the date and time, down to a single second. */ strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S", ptm); /* Compute milliseconds from microseconds. */ milliseconds = tv.tv_usec / 1000; /* Print the formatted time, in seconds, followed by a decimal point and the milliseconds. */ printf ("%s.%03ld\n", time_string, milliseconds); //MM end time uchar buf[255]; int len; EIBConnection *con; if (ac != 2) die ("usage: %s url", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); if (EIBOpenVBusmonitorText (con) == -1) die ("Open Busmonitor failed"); while (1) { len = EIBGetBusmonitorPacket (con, sizeof (buf), buf); if (len == -1) die ("Read failed"); buf[len] = 0; gettimeofday (&tv, NULL); ptm = localtime (&tv.tv_sec); strftime (time_string, sizeof (time_string), "%H:%M:%S", ptm); milliseconds = tv.tv_usec / 1000; printf ("%s.%03ld %s\n", time_string, milliseconds, buf); fflush (stdout); } EIBClose (con); return 0; }
int main (int ac, char *ag[]) { int len; EIBConnection *con; if (ac != 2) die ("usage: %s url", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); len = EIB_Cache_Clear (con); if (len == -1) die ("Clear failed"); EIBClose (con); return 0; }
int main (int ac, char *ag[]) { uchar buf[255]; int len; EIBConnection *con; fd_set read; if (ac != 2) die ("usage: %s url", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); if (EIBOpenVBusmonitorText (con) == -1) die ("Open Busmonitor failed"); while (1) { lp: FD_ZERO (&read); FD_SET (EIB_Poll_FD (con), &read); printf ("Waiting\n"); if (select (EIB_Poll_FD (con) + 1, &read, 0, 0, 0) == -1) die ("select failed"); printf ("Data available\n"); len = EIB_Poll_Complete (con); if (len == -1) die ("Read failed"); if (len == 0) goto lp; printf ("Completed\n"); len = EIBGetBusmonitorPacket (con, sizeof (buf), buf); if (len == -1) die ("Read failed"); printf ("%s\n", buf); fflush (stdout); } EIBClose (con); return 0; }
int main (int ac, char *ag[]) { int len; EIBConnection *con; eibaddr_t dest; if (ac != 3) die ("usage: %s url eibaddr", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); dest = readaddr (ag[2]); len = EIB_M_WriteIndividualAddress (con, dest); if (len == -1) die ("Set failed"); EIBClose (con); return 0; }
int main (int ac, char *ag[]) { int len; EIBConnection *con; eibaddr_t dest; if (ac != 3) die ("usage: %s url eibaddr", ag[0]); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); dest = readaddr (ag[2]); len = EIB_M_GetMaskVersion (con, dest); if (len == -1) die ("Read failed"); printf ("Mask: %04X\n", len); EIBClose (con); return 0; }
int main (int ac, char *ag[]) { int len, obj, prop, start, nr_of_elem; EIBConnection *con; uchar buf[255]; uchar res[255]; eibaddr_t dest; char *prog = ag[0]; if (ac < 7) die ("usage: %s url eibaddr obj prop start nr_of_elem [xx xx ..]", prog); con = EIBSocketURL (ag[1]); if (!con) die ("Open failed"); dest = readaddr (ag[2]); obj = atoi (ag[3]); prop = atoi (ag[4]); start = atoi (ag[5]); nr_of_elem = atoi (ag[6]); len = readBlock (buf, sizeof (buf), ac - 7, ag + 7); if (EIB_MC_Individual_Open (con, dest) == -1) die ("Connect failed"); printf ("Write: "); printHex (len, buf); printf ("\n"); len = EIB_MC_PropertyWrite (con, obj, prop, start, nr_of_elem, len, buf, sizeof (res), res); if (len == -1) die ("Write failed"); printHex (len, res); EIBClose (con); return 0; }
int main (int argc, char *argv[]) { int len; EIBConnection *eibcon; eibaddr_t eibdest; eibaddr_t eibsrc; uchar eibbuf[200]; int tmpeibval; int sw_verbose = -1; FILE *fh_cfg_file = NULL; // Файл с соответствиями KNX телеграммы <-> IPкоманды listGroupAddr myListGA[LENGTH_OF_LIST_OF_GADDR]; eibaddr_t testga; int index_gaddr; // index for group address array char *parsed_cfg_str; // Будет равна LENGTH_OF_CMD_STR char mcom[] = "next\n"; int size_of_list_gaddr; // real length of list of group address - counting due to read if (argc < 3) die ("usage: %s Url(ip:localhost:6720) file(with list of cmd)", argv[0]); //Prepare KNX connection if (argc > 3) sw_verbose = strncmp(argv[3], "--v", 3); // Выводить сообщения в stdout если присутствует ключ --v else sw_verbose = 1; eibcon = EIBSocketURL (argv[1]); if (!eibcon) die ("Open failed"); if (EIBOpen_GroupSocket (eibcon, 0) == -1) die ("Connect failed"); //Fill array from file if((fh_cfg_file = fopen(argv[2], "r")) == NULL) die ("Error Open file with list of group address"); // Читаем командные строки из конфигурационного файла и заполняем массив структур myListGA index_gaddr = 0; parsed_cfg_str = (char*)malloc(LENGTH_OF_CMD_STR * sizeof(char)); while(fgets(parsed_cfg_str, LENGTH_OF_CMD_STR, fh_cfg_file) != NULL) { // Здесь парсим строку convert_str_to_myListGA(parsed_cfg_str, myListGA, index_gaddr); index_gaddr++; if(index_gaddr == LENGTH_OF_LIST_OF_GADDR) break; } free(parsed_cfg_str); size_of_list_gaddr=index_gaddr; // real number of monitoring group address if(sw_verbose == 0) { for(index_gaddr=0; index_gaddr != size_of_list_gaddr; index_gaddr++) printf("Result N:%d -> %s - %d - %s - %d - %s - %X\n", index_gaddr, myListGA[index_gaddr].group_addr,\ myListGA[index_gaddr].value, myListGA[index_gaddr].send_to_ip, myListGA[index_gaddr].send_to_port,\ myListGA[index_gaddr].cmd_string, myListGA[index_gaddr].group_addr_in_hex); } fclose(fh_cfg_file); while (1) { len = EIBGetGroup_Src (eibcon, sizeof (eibbuf), eibbuf, &eibsrc, &eibdest); if (len == -1) die ("Read failed"); if (len < 2) die ("Invalid Packet"); if ((eibbuf[0] & 0x3) || (eibbuf[1] & 0xC0) == 0xC0) { if(sw_verbose == 0) { printf ("Unknown APDU from "); printIndividual (eibsrc); printf (" to "); printGroup (eibdest); printf (": "); printHex (len, eibbuf); printf ("\n"); } } else { if(sw_verbose == 0) { switch (eibbuf[1] & 0xC0) { case 0x00: printf ("Read"); break; case 0x40: printf ("Response"); break; case 0x80: printf ("Write"); break; } printf (" from "); printIndividual (eibsrc); printf (" to "); printGroup (eibdest); if (eibbuf[1] & 0xC0) { printf (": "); if (len == 2) { printf ("%02X", eibbuf[1] & 0x3F); } else printHex (len - 2, eibbuf + 2); } printf(" Destination in HEX is -> %X ", eibdest); } tmpeibval = eibbuf[1] & 0x3F; for(index_gaddr=0; index_gaddr != size_of_list_gaddr; index_gaddr++) { if((myListGA[index_gaddr].group_addr_in_hex == eibdest) && (myListGA[index_gaddr].value == tmpeibval)) { if(sw_verbose == 0) { printf("\n Caught command => %s \n", myListGA[index_gaddr].cmd_string); } mpdControl(myListGA[index_gaddr].cmd_string, myListGA[index_gaddr].send_to_ip, myListGA[index_gaddr].send_to_port, sw_verbose); } } fflush (stdout); } } EIBClose (eibcon); return 0; }
int main () { int len=0; EIBConnection *con; int i,j; double fval; int sign=0,exp=0,mant=0; eibaddr_t dest; uchar buf[255] = { 0, 0x80 }; char tmpbuf[255]; printf("Content-Type: text/plain\r\n\r\n"); readParseCGI(); if (*eiburl == NULL) *eiburl = "local:/tmp/eib"; con = EIBSocketURL (*eiburl); if (!con) cgidie ("Open failed"); dest=gadest; if (EIBOpenT_Group (con, dest, 1) == -1) cgidie ("Connect failed"); if (!gadest || !strlen(data)>0) cgidie ("Need ga(g),value(v)"); switch (dpt) { case 0: len=1; for(i = 0; i < strlen(data)/2; i++) { tmpbuf[0] = data[i*2]; tmpbuf[1] = data[(i*2)+1]; sscanf(tmpbuf, "%x", &j); buf[i+1] = j; len++; } // only allow A_GroupValue_Write if ((buf[1] &0x80) != 0x80) cgidie ("Only A_GroupValue_Write allowed"); break; case 1: buf[1] |= atoi(data) & 0x3f; len=2; break; case 3: // EIS2/DPT3 4bit dim buf[1] |= atoi(data) & 0x3f; len=2; break; case 5: buf[2] = atoi(data)*255/100; len=3; break; case 51: case 5001: buf[2] = atoi(data); len=3; break; case 9: fval=atof(data); if (fval<0) sign = 0x8000; mant = (int)(fval * 100.0); while (abs(mant) > 2047) { mant = mant >> 1; exp++; } i = sign | (exp << 11) | (mant & 0x07ff); buf[2] = i >> 8; buf[3] = i & 0xff; //return $data >> 8, $data & 0xff; len=4; break; case 16: len=2; for (i=0;i<strlen(data); i++) { buf[i+2] = (int)(data[i]); len++; } } len = EIBSendAPDU (con, len, buf); if (len == -1) cgidie ("Request failed"); printf ("{'success':%d}\n",len-1); //don't confuse client with leading 0x00 //printf("size %d %d\n",sizeof(buf),strlen(buf)); //printf("buf 0x%02X 0x%02X 0x%02X 0x%02X v:%s l:%d\n" ,buf[1],buf[2],buf[3],buf[4],data,strlen(data)); EIBClose (con); return 0; }