/** chybovy vypis (stderr) */ void printferr(const char *format, ...) { va_list ap; print_now(stderr); va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); fprintf(stderr, "\n"); }
// [1] スキャンしたアドバタイズパケットの取得 void ble_evt_gap_scan_response( const struct ble_msg_gap_scan_response_evt_t *msg ){ /* if (found_devices_count >= MAX_DEVICES) { change_state(state_finish); } // Check if this device already found for (i = 0; i < found_devices_count; i++) { if (!cmp_bdaddr(msg->sender, found_devices[i])) return; } found_devices_count++; memcpy(found_devices[i].addr, msg->sender.addr, sizeof(bd_addr)); */ // パケットデータ全体のダンプ // printf("#packet:"); // print_hex(msg->data.data, msg->data.len); // printf("\n"); // Parse data memset(&ap, 0, sizeof(adv_pkt)); parse_packet(msg->data.data, msg->data.len); // 時刻 print_now(); // アドレス printf(","); print_bdaddr(msg->sender); // RSSI printf(",RSSI:%d", msg->rssi); print_flags(); if (ap.name[0] != 0) { printf(",Name:%s", ap.name); } if (ap.ibeacon) { printf(",iBeacon"); printf (",UUID:"); print_hex(ap.uuid, 16); printf (",major:%d,minor:%d,txpower:%d", ap.major, ap.minor, ap.txpower); } if (ap.services_len != 0) { print_services(); } #ifdef DEBUG // パケットデータ全体のダンプ printf(",packet:"); print_hex(msg->data.data, msg->data.len); #endif printf("\n"); }
/** debug hlasky na std. vystup. Bezi pri zapnutem flagu verbose. */ void printfdbg(const char *format, ...) { va_list ap; if (verbose) { print_now(stdout); } va_start(ap, format); if (verbose) { vfprintf(stdout, format, ap); } va_end(ap); if (verbose) { printf("\n"); } }
int main(int argc , char **argv) { if(argc>1 && strcmp(argv[1],"DEBUG")==0) debug=1; int msgflg = IPC_CREAT | 0666; if ((upqid = msgget(key_up, msgflg)) < 0) die("Error connecting to Up queue "); if ((downqid = msgget(key_down, msgflg)) < 0) die("Error connecting to Down queue "); int pid=fork(); if(pid==0)listen_for_connection(); //if(debug)printf("After connection\n"); struct msgbuf buffer; int len,i; while(1){ if (msgrcv(upqid, &buffer, MAXSIZE, 1, MSG_EXCEPT) < 0) die("Could not receive msg from client "); if(buffer.mtype==1)continue; //if(debug)printf("Received msg with type %ld and msg:%s\n",buffer.mtype,buffer.mtext); len=strlen(buffer.mtext); for(i=0;i<len;++i){ if(buffer.mtext[i]-'a'>=0 && buffer.mtext[i]-'a'<=26) buffer.mtext[i]=buffer.mtext[i]-'a'+'A'; else if(buffer.mtext[i]-'A'>=0 && buffer.mtext[i]-'A'<=26) buffer.mtext[i]=buffer.mtext[i]-'A'+'a'; } print_now(); size_t buflen=strlen(buffer.mtext)+1; if (msgsnd(downqid, &buffer, buflen, IPC_NOWAIT) < 0){ //if(debug)printf ("%d, %ld, %s, %d\n", downqid, buffer.mtype, buffer.mtext, (int)buflen); die("msgsnd"); } else{ //if(debug)printf("response sent : %s\n\n\n",buffer.mtext); } } waitpid(pid,NULL,WUNTRACED); }