int main(int argc, char *argv[]) { int *counter, counter_fd; char new_name[MAX_PATH_LENGTH], work_dir[MAX_PATH_LENGTH]; if (get_afd_path(&argc, argv, work_dir) < 0) { exit(1); } p_work_dir = work_dir; if (argc != 4) { (void)fprintf(stderr, "Usage: %s <original name> <filter> <rename to rule>\n", argv[0]); exit(1); } if ((counter_fd = open_counter_file(COUNTER_FILE, &counter)) == -1) { printf("Failed to open counter file.\n"); exit(1); } change_name(argv[1], argv[2], argv[3], new_name, MAX_PATH_LENGTH, &counter_fd, &counter, 0); printf("new name = %s\n", new_name); exit(0); }
BOOL Grafik::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult) { switch (message) { case UPDATE_NAME: change_name(); return 1; case UPDATE_REIHE: change_reihe((int) wParam, (int)lParam & FLAG_NAME, (int)lParam & FLAG_FARBE); return 1; case UPDATE_WERT: change_wert((int)wParam, (int)lParam); return 1; case UPDATE_ALL: change_all((int)lParam & FLAG_NAME, (int)lParam & FLAG_FARBE, (int)lParam & FLAG_WERT); return 1; case CLOSE_ALL: SendMessage(WM_CLOSE); return 1; default: return CDialog::OnWndMsg(message, wParam, lParam, pResult); } }
void replace(char **str, t_list *list, int ant) { t_list *link; int i; i = 0; link = list; while (str[i]) { TC->name = change_name(str[i], link); link = link->next; i++; } i--; change_status(list, i, ant); }
void check_name(t_env *e, int cs, char *line) { int i; int j; i = 0; j = 1; while (line[i] != '\0') { if (line[i] < 33 || line[i] > 126) j = 0; i++; } if (i > 8) send(cs, "Nickname limited at 9.\0", 23, 0); else if (i == 0) send(cs, "Nickname has to be set.\0", 24, 0); else if (j == 0) send(cs, "Nickname can't take special caractere.\0", 39, 0); else change_name(e, cs, line); }
bool iol2opc_IDL::read(yarp::os::ConnectionReader& connection) { yarp::os::idl::WireReader reader(connection); reader.expectAccept(); if (!reader.readListHeader()) { reader.fail(); return false; } yarp::os::ConstString tag = reader.readTag(); bool direct = (tag=="__direct__"); if (direct) tag = reader.readTag(); while (!reader.isError()) { // TODO: use quick lookup, this is just a test if (tag == "train_object") { std::string name; if (!reader.readString(name)) { reader.fail(); return false; } bool _return; _return = train_object(name); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "remove_object") { std::string name; if (!reader.readString(name)) { reader.fail(); return false; } bool _return; _return = remove_object(name); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "remove_all") { bool _return; _return = remove_all(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "change_name") { std::string old_name; std::string new_name; if (!reader.readString(old_name)) { reader.fail(); return false; } if (!reader.readString(new_name)) { reader.fail(); return false; } bool _return; _return = change_name(old_name,new_name); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "help") { std::string functionName; if (!reader.readString(functionName)) { functionName = "--all"; } std::vector<std::string> _return=help(functionName); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(2)) return false; if (!writer.writeTag("many",1, 0)) return false; if (!writer.writeListBegin(BOTTLE_TAG_INT, static_cast<uint32_t>(_return.size()))) return false; std::vector<std::string> ::iterator _iterHelp; for (_iterHelp = _return.begin(); _iterHelp != _return.end(); ++_iterHelp) { if (!writer.writeString(*_iterHelp)) return false; } if (!writer.writeListEnd()) return false; } reader.accept(); return true; } if (reader.noMore()) { reader.fail(); return false; } yarp::os::ConstString next_tag = reader.readTag(); if (next_tag=="") break; tag = tag + "_" + next_tag; } return false; }
void chat_interface(int new_fd) { clear(); refresh(); int flag = 3; int ch; WINDOW *new_window1, *new_window2, *new_window5; setlocale(LC_ALL, ""); //initscr(); //keypad(ch_window4, 1); new_window1 = newwin(3, 91,0,22); ch_window2 = newwin(13, 68,4,23); new_window5 = newwin(15, 70,3,22); ch_window3 = newwin(6, 70,18,22); ch_window4 = newwin(21, 21,3,92); ch_window5 = newwin(6, 20,0,2); ch_window1 = newwin(18, 20,6,2); box(new_window1, 0, 0); box(ch_window4, 0, 0); box(ch_window5, 0, 0); box(new_window5, 0, 0); box(ch_window1, 0, 0); box(ch_window2, ' ', ' '); box(ch_window3, 0, 0); mvwaddstr(ch_window1, 1, 5, "ONLINE-USER"); mvwaddstr(ch_window1, 2, 5, "==========="); mvwaddstr(ch_window5, 2, 7, msg1.name); mvwaddstr(ch_window5, 3, 6, msg1.id); mvwaddstr(ch_window4, 1, 6, "FUNCTION"); mvwaddstr(ch_window4, 2, 5, "==========="); mvwaddstr(ch_window4, 3, 5, "私聊"); mvwaddstr(ch_window4, 4, 5, "群聊"); mvwaddstr(ch_window4, 5, 5, "发送表情"); mvwaddstr(ch_window4, 6, 5, "查看聊天记录"); mvwaddstr(ch_window4, 7, 5, "删除聊天记录"); mvwaddstr(ch_window4, 8, 5, "发送文件"); mvwaddstr(ch_window4, 9, 5, "修改昵称"); mvwaddstr(ch_window4, 10, 5, "修改密码"); mvwaddstr(ch_window4, 11, 5, "切换用户"); wrefresh(new_window1); wrefresh(ch_window3); wrefresh(ch_window5); wrefresh(new_window5); wrefresh(ch_window1); wrefresh(ch_window2); wrefresh(ch_window4); mvwaddstr(ch_window4, flag, 3, "=>"); wrefresh(ch_window4); keypad(ch_window4,true); cbreak(); while(1) { if(filesend == FILE_SEND) { file_receive(new_fd); filesend = 0; } curs_set(0); /*mvwaddstr(ch_window4, flag, 3, " "); flag = 3; mvwaddstr(ch_window4, flag, 3, "=>"); wrefresh(ch_window4);*/ noecho(); while((ch = wgetch(ch_window4)) != '\n') { if(ch == KEY_UP) { mvwaddstr(ch_window4, flag, 3, " "); if(flag == 3) { flag = 11; } else { flag--; } mvwaddstr(ch_window4, flag, 3, "=>"); } if(ch == KEY_DOWN) { mvwaddstr(ch_window4, flag, 3, " "); if(flag == 11) { flag = 3; } else { flag++; } mvwaddstr(ch_window4, flag, 3, "=>"); } wrefresh(ch_window4); } switch(flag) { case 3: { private_chat(new_fd); break; } case 4: { group_chat(new_fd); break; } case 5: { send_face(new_fd); break; } case 6: { check_history(new_fd); break; } case 7: { delete_history(new_fd); break; } case 8: { file_send(new_fd); break; } case 9: { change_name(new_fd); break; } case 10: { change_password(new_fd); box(new_window1, 0, 0); box(ch_window4, 0, 0); box(ch_window5, 0, 0); box(new_window5, 0, 0); box(ch_window1, 0, 0); box(ch_window2, ' ', ' '); box(ch_window3, 0, 0); mvwaddstr(ch_window1, 1, 5, "ONLINE-USER"); mvwaddstr(ch_window1, 2, 5, "==========="); mvwaddstr(ch_window5, 2, 7, msg1.name); mvwaddstr(ch_window5, 3, 6, msg1.id); mvwaddstr(ch_window4, 1, 6, "FUNCTION"); mvwaddstr(ch_window4, 2, 5, "==========="); mvwaddstr(ch_window4, 3, 5, "私聊"); mvwaddstr(ch_window4, 4, 5, "群聊"); mvwaddstr(ch_window4, 5, 5, "发送表情"); mvwaddstr(ch_window4, 6, 5, "查看聊天记录"); mvwaddstr(ch_window4, 7, 5, "删除聊天记录"); mvwaddstr(ch_window4, 8, 5, "发送文件"); mvwaddstr(ch_window4, 9, 5, "修改昵称"); mvwaddstr(ch_window4, 10, 5, "修改密码"); mvwaddstr(ch_window4, 11, 5, "切换用户"); wrefresh(new_window1); wrefresh(ch_window3); wrefresh(ch_window5); wrefresh(new_window5); wrefresh(ch_window1); wrefresh(ch_window2); wrefresh(ch_window4); mvwaddstr(ch_window4, flag, 3, "=>"); wrefresh(ch_window4); break; } case 11: { clear(); refresh(); new_window2 = newwin(13, 50, 5, 30); box(new_window2, 0, 0); mvwaddstr(new_window2, 3, 22, "GOODBYE"); mvwaddstr(new_window2, 5, 22, msg1.name); wrefresh(new_window2); msg1.action = QUIT; write(new_fd, &msg1, sizeof(Node)); goto EXIT_CHATINTERFACE; break; } } } EXIT_CHATINTERFACE: curs_set(1); wgetch(new_window1); }
/************************************************************************ *函数原型 : void led_dr_work(struct work_struct *work) *描述 : DR灯亮灭接口工作队列 *输入 : 无 *输出 : 无 *返回值 : 无 *修改历史 : 1.日 期 : 20140809 修改内容 : 新生成函数 *************************************************************************/ static void led_dr_work(struct work_struct *work) { int ret = BR_ERROR; unsigned long time_local = 0; int brightness = 0; struct balong_led_device *led_dat = NULL; struct led_classdev *led_cdev = NULL; mutex_lock(&led_dr_mutex); led_dat = container_of(work, struct balong_led_device, work); led_cdev = &(led_dat->cdev); brightness = led_dat->brightness; if(!led_cdev) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); goto out; } ret = change_name(led_cdev); if(BR_ERROR == ret) { goto out; } if (brightness >= LED_FULL) { brightness = LED_FULL; } if(1 == brightness) { if(LED_NAME_2 < g_dr_name) { #ifdef BSP_CONFIG_BOARD_E5 brightness = DR345_BRIGHTNESS_4_5MA; #else brightness = DR345_BRIGHTNESS_3MA; #endif } else { brightness = DR12_BRIGHTNESS_3MA; } } if(g_dr_brightness[g_dr_name - 1] == brightness) /*重复设置亮度*/ { goto out; } g_dr_brightness[g_dr_name - 1] = brightness; /*亮度值更新*/ ret = led_dr_trigger_hold(); if(BR_ERROR == ret) { goto out; } /*设置灯的状态为长灭*/ if (LED_OFF == brightness) { ret = set_led_dr_attr(BRT_ATTR_FULL_ON, time_local); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_ON,time_local) failded.\n", __func__); goto out; } ret = set_led_dr_attr(BRT_ATTR_FULL_OFF, LED_LONG_TIME); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_OFF, LED_LONG_TIME) failded.\n", __func__); goto out; } } /*设置灯的状态为长亮*/ else { ret = set_led_dr_attr(BRT_ATTR_FULL_ON, LED_LONG_TIME); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_ON, LED_LONG_TIME) failded.\n", __func__); goto out; } ret = set_led_dr_attr(BRT_ATTR_FULL_OFF, time_local); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_OFF, time_local) failded.\n", __func__); goto out; } } ret = set_led_dr_attr(BRT_ATTR_FADE_ON, time_local); if(BR_ERROR == ret) { goto out; } ret = set_led_dr_attr(BRT_ATTR_FADE_OFF, time_local); if(BR_ERROR == ret) { goto out; } ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, brightness); if(BR_ERROR == ret) { goto out; } out: mutex_unlock(&led_dr_mutex); }
/************************************************************************ *函数原型 : int led_dr_breath_set(struct led_classdev *led_cdev, unsigned long *full_on, unsigned long *full_off, unsigned long *fade_on, unsigned long *fade_off) *描述 : 用户态操作DR灯开始呼吸的接口 *输入 : 无 *输出 : 无 *返回值 : BR_OK OR BR_ERRO *修改历史 : 1.日 期 : 20140620 修改内容 : 新生成函数 *************************************************************************/ int led_dr_breath_set(struct led_classdev *led_cdev, unsigned long *full_on, unsigned long *full_off, unsigned long *fade_on, unsigned long *fade_off) { int ret = BR_ERROR; /* argument check */ if((!led_cdev) || (!full_on) || (!full_off) || (!fade_on) || (!fade_off)) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); return BR_ERROR; } led_cdev->breath_full_on = *full_on; led_cdev->breath_full_off = *full_off; led_cdev->breath_fade_on = *fade_on; led_cdev->breath_fade_off = *fade_off; ret = change_name(led_cdev); if(BR_ERROR == ret) { return ret; } g_dr_brightness[g_dr_name - 1] = -1; /*亮度值复位*/ ret = led_dr_trigger_hold(); if(BR_ERROR == ret) { return ret; } /*应用层下发的时间参数是毫秒级的,而底层定义的参数是微秒级的,在用户态参数传入的时候需要转换*/ ret = set_led_dr_attr(BRT_ATTR_FULL_ON, (led_cdev->breath_full_on)*1000); if(BR_ERROR == ret) { return ret; } ret = set_led_dr_attr(BRT_ATTR_FULL_OFF, (led_cdev->breath_full_off)*1000); if(BR_ERROR == ret) { return ret; } ret = set_led_dr_attr(BRT_ATTR_FADE_ON, (led_cdev->breath_fade_on)*1000); if(BR_ERROR == ret) { return ret; } ret = set_led_dr_attr(BRT_ATTR_FADE_OFF, (led_cdev->breath_fade_off)*1000); if(BR_ERROR == ret) { return ret; } /*时间赋值完毕进入亮度设置*/ if ((led_cdev->breath_full_on)&&(led_cdev->breath_full_off)&&(led_cdev->breath_fade_on)&&(led_cdev->breath_fade_off)) { if ((0 == led_cdev->brightness) || (1 == led_cdev->brightness)) { if(LED_NAME_2 < g_dr_name) { ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, DR345_BRIGHTNESS_3MA); } else { ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, DR12_BRIGHTNESS_3MA); } } else { ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, led_cdev->brightness); } if(BR_ERROR == ret) { return ret; } } return BR_OK; }
// returns a buffer to respond with // consider different cases // b_ip = server B's IP (the referral) bool respond(char *in_buf, char *out_buf, char *b_ip, int *len) { FixedDNSHeader *fd = (FixedDNSHeader *)in_buf; char name[MAX_DNS_SIZE]; parse_name(in_buf + sizeof(FixedDNSHeader), name); printf("[server] Query: %s, ", name); USHORT txid = ntohs(fd->ID); // flags = 0x8500 if available, 0x8500 if unavailable // 850 = response packet, authoritative, recursion unavailable // 0 = no error, 3 = name error // FOR REFERENCE ONLY //FixedRR typeA(DNS_A, DNS_INET, 0, 4); //FixedRR typeNS(DNS_NS, DNS_INET, 0, depends_on_name); QueryHeader *qh = (QueryHeader *)(in_buf + strlen(name) + 2 + sizeof(FixedDNSHeader)); printf("Type: %d\n", ntohs(qh->qtype)); int sz = strlen(name); // the X and Y need to be changed, but not now if ((sz == 19 || sz == 16) && (strncmp(name + sz - 12, "iresearch.us", 12) == 0 /*|| strncmp(name + sz - 12, "IRESEARCH.us", 12) == 0*/)) { USHORT *head = (USHORT *)out_buf; head[0] = htons(txid); head[1] = htons(0x8500); head[2] = htons(1); // 1 question head[3] = htons(0); // 0 answer head[4] = htons(1); // 1 authoritative head[5] = htons(1); // 1 additional (to prevent re-query) // QUESTION change_name(name, out_buf + sizeof(FixedDNSHeader)); int cur_pos = strlen(name) + 2 + sizeof(FixedDNSHeader); QueryHeader *out_qh = (QueryHeader *)(out_buf + cur_pos); out_qh->qclass = htons(ntohs(qh->qclass)); out_qh->qtype = htons(ntohs(qh->qtype)); cur_pos += sizeof(QueryHeader); if (ntohs(qh->qtype) == DNS_AAAA) { head[1] = htons(0x8503); head[4] = htons(0); head[5] = htons(0); return true; } char ns[MAX_DNS_SIZE]; ns[0] = 0; strcat(ns, "ns."); strcat(ns, name); // AUTHORITY change_name(name, out_buf + cur_pos); cur_pos += (strlen(name) + 2); FixedRR *rr = (FixedRR *)(out_buf + cur_pos); *rr = FixedRR(htons(DNS_NS), htons(DNS_INET), htons(0), htons(USHORT(strlen(ns)) + 2)); cur_pos += sizeof(FixedRR); change_name(ns, out_buf + cur_pos); cur_pos += (strlen(ns) + 2); // ADDITIONAL change_name(ns, out_buf + cur_pos); cur_pos += (strlen(ns) + 2); FixedRR *rrA = (FixedRR *)(out_buf + cur_pos); *rrA = FixedRR(htons(DNS_A), htons(DNS_INET), htons(0), htons(4)); cur_pos += sizeof(FixedRR); int *ip = (int *)(out_buf + cur_pos); *ip = inet_addr(b_ip); cur_pos += 4; *len = cur_pos; } else if (strlen(name) == 22 && strncmp(name + 10, "iresearch.us", 12) == 0) { // this is the query where X doesn't "trust" us USHORT *head = (USHORT *)out_buf; head[0] = htons(txid); head[1] = htons(0x8500); head[2] = htons(1); // 1 question head[3] = htons(1); // 1 answer head[4] = htons(0); // already gave authoritative head[5] = htons(0); // no additional req'd // QUESTION change_name(name, out_buf + sizeof(FixedDNSHeader)); int cur_pos = strlen(name) + 2 + sizeof(FixedDNSHeader); QueryHeader *out_qh = (QueryHeader *)(out_buf + cur_pos); out_qh->qclass = htons(ntohs(qh->qclass)); out_qh->qtype = htons(ntohs(qh->qtype)); cur_pos += sizeof(QueryHeader); if (ntohs(qh->qtype) == DNS_AAAA) { head[1] = htons(0x8502); head[3] = htons(0); return true; } char *ns = name; // ANSWER change_name(ns, out_buf + cur_pos); cur_pos += (strlen(ns) + 2); FixedRR *rr = (FixedRR *)(out_buf + cur_pos); *rr = FixedRR(htons(DNS_A), htons(DNS_INET), htons(0), htons(4)); cur_pos += sizeof(FixedRR); int *ip = (int *)(out_buf + cur_pos); *ip = inet_addr(b_ip); cur_pos += 4; *len = cur_pos; } else { // invalid query -- reject USHORT *head = (USHORT *)out_buf; head[0] = htons(txid); head[1] = htons(0x8503); // Rcode = 3 -- error head[2] = htons(1); // 1 question head[3] = htons(0); // no answer head[4] = htons(0); // already gave authoritative head[5] = htons(0); // no additional req'd // QUESTION change_name(name, out_buf + sizeof(FixedDNSHeader)); int cur_pos = strlen(name) + 2 + sizeof(FixedDNSHeader); QueryHeader *out_qh = (QueryHeader *)(out_buf + cur_pos); out_qh->qclass = htons(ntohs(qh->qclass)); out_qh->qtype = htons(ntohs(qh->qtype)); cur_pos += sizeof(QueryHeader); *len = cur_pos; } return true; }
void upsdrv_updateinfo(void) { time_t now; int ok; float load; if (status & UPSC_STAT_NOTINIT) { upsdrv_initinfo(); } if (status & UPSC_STAT_NOTINIT) { return; } status = 0; ok = upsc_getparams("UPDS", simple); time(&now); if (ok && now - last_full > full_update_timer) { last_full = now; ok = upsc_getparams("UPDV", nominal); if (ok && can_upbs) ok = upsc_getparams("UPBS", battery); } if (!ok) { dstate_datastale(); last_full = 0; return; } if (!inited_phaseinfo) { if (dstate_getinfo("input.L3-L1.voltage") || dstate_getinfo("input.L3-N.voltage")) { num_inphases = 3; change_name(simple, "input.current", "input.L1.current"); change_name(simple, "input.realpower", "input.L1.realpower"); change_name(simple, "input.power", "input.L1.power"); change_name(simple, "input.voltage", "input.L1-N.voltage"); } if (dstate_getinfo("output.L3-L1.voltage") || dstate_getinfo("output.L3-N.voltage")) { const char *s; num_outphases = 3; if ((s=dstate_getinfo("ups.model")) && (!strncmp(s, "UPS9075", 7) || !strncmp(s, "UPS9100", 7) || !strncmp(s, "UPS9150", 7) || !strncmp(s, "UPS9200", 7) || !strncmp(s, "UPS9250", 7) || !strncmp(s, "UPS9300", 7) || !strncmp(s, "UPS9400", 7) || !strncmp(s, "UPS9500", 7) || !strncmp(s, "UPS9600", 7)) ) { /* Insert kludges for Fiskars UPS9000 here */ upslogx(LOG_INFO, "Fiskars UPS9000 detected, protocol kludges activated"); batt_volt_nom = 384; dstate_setinfo("battery.voltage.nominal", "%.0f", batt_volt_nom); } else { outpwr_factor *= 3; } change_name(simple, "output.current", "output.L1.current"); change_name(simple, "output.current.peak", "output.L1.current.peak"); change_name(simple, "output.realpower", "output.L1.realpower"); change_name(simple, "output.power", "output.L1.power"); change_name(simple, "output.voltage", "output.L1-N.voltage"); } dstate_setinfo("input.phases", "%d", num_inphases); dstate_setinfo("output.phases", "%d", num_outphases); inited_phaseinfo=1; } load = calc_upsload(); if (load >= 0) { upsdebugx(2, "ups.load: %.1f", load*100); dstate_setinfo("ups.load", "%.1f", load*100); } else { upsdebugx(2, "ups.load: No value"); } /* TODO/FIXME: Set UPS date/time on startup and daily if needed */ if (can_updt) { char dtbuf[UPSC_BUFLEN]; if (upsc_getvalue("UPDT", "0", "ACDT", NULL, dtbuf)) { dstate_setinfo("ups.date", "%s", dtbuf); } } if (can_uptm) { char tmbuf[UPSC_BUFLEN]; if (upsc_getvalue("UPTM", "0", "ACTM", NULL, tmbuf)) { dstate_setinfo("ups.time", "%s", tmbuf); } } if (batt_charge < 0) { if (batt_current < 0) { /* Reset battery current history if discharging */ numbatthist = lastbatthist = 0; } batt_charge = batt_charge_pct(); } if (batt_charge >= 0) { dstate_setinfo("battery.charge", "%.1f", batt_charge); } else { dstate_delinfo("battery.charge"); } /* 9999 == unknown value */ if (batt_runtime >= 0 && batt_runtime < 9999) { dstate_setinfo("battery.runtime", "%.0f", batt_runtime*60); } else if (load > 0 && batt_disch_curr_max != 0) { float est_battcurr = load * abs(batt_disch_curr_max); /* Peukert equation */ float runtime = (batt_cap_nom*3600)/pow(est_battcurr, 1.35); upsdebugx(2, "Calculated runtime: %.0f seconds", runtime); if (batt_runtime_max > 0 && runtime > batt_runtime_max*60) { runtime = batt_runtime_max*60; } dstate_setinfo("battery.runtime", "%.0f", runtime); } else if (batt_runtime_max > 0) { /* Show max possible runtime as reported by UPS */ dstate_setinfo("battery.runtime", "%.0f", batt_runtime_max*60); } else { dstate_delinfo("battery.runtime"); } /* Some UPSen only provides this when on battery, so reset between * each iteration to make sure we use the right value */ batt_charge = -1; batt_runtime = -1; if (!(status & UPSC_STAT_ONBATT)) status |= UPSC_STAT_ONLINE; upsc_setstatus(status); dstate_dataok(); ser_comm_good(); }
int main() { fp = fopen("log.txt", "w"); log_time(); fprintf(fp, "Start Programm\n"); int target_floor, target_room; int view_flag = 1; building *building_list = (building *) malloc(sizeof(building)); log_time(); fprintf(fp, "init building_list\n"); init(building_list); add_floor(building_list, FALSE); add_room(building_list, FALSE); add_room(building_list, FALSE); add_room(building_list, FALSE); while (1) { fflush(fp); if (view_flag) view_building(building_list, TRUE); else { view_room(building_list, target_floor, target_room); } switch (input_cmd()) { case 1: { // [1] 건물 확장 switch (input_extend_cmd()) { case 1: { // [1] 층 확장 add_floor(building_list, TRUE); break; } case 2: { // [2] 방 확장 add_room(building_list, TRUE); break; } } break; } case 2: { // [2] View 변환 if (view_flag) { printf("특정 방 내부 보여주기 로 View가 변환되었습니다.\n"); printf("층과 호수를 입력하세요\n"); if (tts_flag) { system("pico2wave -w test.wav \"Translated the view into the specific room viewing.\""); system("aplay -q test.wav"); system("pico2wave -w test.wav \"Input floor number and room number\""); system("aplay -q test.wav"); } scanf("%d %d", &target_floor, &target_room); view_flag = 0; } else { printf("전체 방 보여주기 로 View가 변환되었습니다.\n"); if (tts_flag) { system("pico2wave -w test.wav \"Translated the view into the total room viewing.\""); system("aplay -q test.wav"); } view_flag = 1; } break; } case 3: { // [3] 방 별 칸 변환 change_space(building_list); break; } case 4: { // [4] 칸 별 사람 이름 변환 change_name(building_list); break; } case 5: { search_name(building_list); break; } case 6: { // [6] TTS ON/OFF if (tts_flag) { printf("TTS를 사용하지않습니다.\n"); tts_flag = 0; } else { printf("TTS를 사용합니다.\n"); system("pico2wave -w test.wav \"From now, Use text to speach.\""); system("aplay -q test.wav"); tts_flag = 1; } break; } case 7: { // [5] 종료 printf("\n프로그램을 종료합니다.\n"); if (tts_flag) { system("pico2wave -w test.wav \"Exit Program.\""); system("aplay -q test.wav"); } return 0; break; } } } return 0; }
int mesg_from_client (int filedes, FILE *logfp, struct cinfo **phead) { struct c_mesg msg; int nbytes; char notify_toolong[] = "! SYSTEM NOTIFICATION: name too long! Nickname set yet truncated to 255 characters.\n"; char notify_noname[] = "! SYSTEM NOTIFICATIOM: no name part found in your message! failed to change nickname!\n"; char notify_succeed[] = "! SYSTEM NOTIFICATION: succeed changing nickname!:)\n"; int rvalue; struct cinfo *node; char broadcast[MAXMSG + MAXNAME + MAXNAME]; nbytes = read ( filedes, &msg, sizeof(msg) ); if (nbytes < 0) { /* Read error. */ perror ("read_from_client"); exit (EXIT_FAILURE); } else if (nbytes == 0) /* End-of-file. */ return -1; else { if( msg.type == 1 ) // change nickname of client from socket fd == filedes { rvalue = change_name(filedes, msg.mesg, phead, logfp); if( rvalue == 1 ) //truncated write(filedes, notify_toolong, sizeof(notify_toolong) ); else if( rvalue == -1) write(filedes, notify_noname, sizeof(notify_noname) ); else if( rvalue == 0 ) write(filedes, notify_succeed, sizeof(notify_succeed) ); else return -1; return 0; } else if(msg.type == 2) // send message to all clients except socket fd == filedes { if( search_client( *phead, &node, filedes) == -1 ) { fprintf(logfp, "\nERROR: cannot find fd %d in client list, therefore failed to broadcast\n", filedes); return -1; } sprintf(broadcast,"%d(%s):\n\t%s\n", node->id, node->nameset? node->nickname:" ", msg.mesg ); fprintf(logfp,"\nMSG from %d(%s), fd=%d:\n\t%s\n", node->id, node->nameset ? node->nickname : " ", node->sockfd, msg.mesg ); node = *phead; while( node != NULL ) { if( node->sockfd != filedes ) write( node->sockfd, broadcast, MAXMSG+2*MAXNAME ); node = node->next; } } else if(msg.type == 3 ) //client want to leave { return 1; } return 0; } }