static void sys_cfg_set_dns() { CLEAR_SCREEN; input_dst* dns_input; dns_input = input_init(FREE_MOD); input_props_set(dns_input, input_one_property); input_property_set(dns_input, INPUT_HIND, "DNS IP"); input_dis(MAIN_DISP, dns_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入DNS地址", 1); lcd_160_upd(); input_key_manege(MAIN_DISP, dns_input , lcd_160_upd); char dns[32] = {0}; input_str_get(dns_input, dns); input_destory(dns_input); if (check_ip_valid(dns)) { disp_msg("地址格式错误", 10); return; } char cmd[128]; sprintf(cmd, "echo \"nameserver %s\" > /etc/resolv.conf", dns); system(cmd); disp_msg("修改DNS成功", 5); }
static void sys_cfg_set_agent() { CLEAR_SCREEN; const uint32 input_length = 190; input_dst* agent_input, *agent_port_input; agent_input = input_init(FREE_MOD); agent_port_input = input_init(FREE_MOD); input_props_set(agent_input, input_one_property); input_property_set(agent_input, INPUT_HIND, "前置IP"); input_property_set(agent_input, INPUT_MAX_LEN, 15); input_property_set(agent_input, INPUT_RET_STA, 176, INPUT_Y_COOR); input_property_set(agent_input, INPUT_RET_SIZ, INPUT_HEIGHT, input_length); input_props_set(agent_port_input, input_two_property); input_property_set(agent_port_input, INPUT_HIND, "前置端口"); input_property_set(agent_port_input, INPUT_MAX_LEN, 5); input_dis(MAIN_DISP, agent_input); input_dis(MAIN_DISP, agent_port_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入前置地址", 1); lcd_160_upd(); input_key_manege(MAIN_DISP, agent_input , lcd_160_upd); input_key_manege(MAIN_DISP, agent_port_input , lcd_160_upd); char agent_ip[24] = {0}; input_str_get(agent_input, agent_ip); uint32 agent_port = input_val_get(agent_port_input) / 100; input_destory(agent_input); input_destory(agent_port_input); if (check_ip_valid(agent_ip) || agent_port < 80 || agent_port > 65535) { LOG((LOG_DEBUG, "前置机IP: %s:%d", agent_ip, agent_port)); disp_msg("地址格式错误", 10); return; } if (update_config("svc.remotename", agent_ip) || update_config_int("svc.remoteport", agent_port)) { disp_msg("更新前置信息失败", 10); return; } SAFE_STR_CPY(p16pos.remote[REMOTE_WIRE].u.host.host_name, agent_ip); p16pos.remote[REMOTE_WIRE].u.host.host_port = agent_port; setup_svc_url(); disp_msg("修改前置信息成功", 5); }
static void sys_cfg_set_time() { CLEAR_SCREEN; input_dst* date_input, *time_input; date_input = input_init(FREE_MOD); time_input = input_init(FREE_MOD); input_props_set(date_input, input_one_property); input_property_set(date_input, INPUT_HIND, "日期"); input_property_set(date_input, INPUT_MAX_LEN, 8); input_props_set(time_input, input_two_property); input_property_set(time_input, INPUT_HIND, "时间"); input_property_set(time_input, INPUT_MAX_LEN, 6); input_dis(MAIN_DISP, date_input); input_dis(MAIN_DISP, time_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "格式YYYYMMDD HHMMSS", 1); lcd_160_upd(); input_key_manege(MAIN_DISP, date_input , lcd_160_upd); input_key_manege(MAIN_DISP, time_input , lcd_160_upd); char date_buf[24] = {0}; char time_buf[24] = {0}; input_str_get(date_input, date_buf); input_str_get(time_input, time_buf); input_destory(date_input); input_destory(time_input); char input_buf[24] = {0}; char output_buf[32] = {0}; strcpy(input_buf, date_buf); strcat(input_buf, time_buf); if (strlen(input_buf) != 14 || convert_datetime(input_buf, "%Y%m%d%H%M%S", "%Y-%m-%d%H:%M:%S", output_buf, sizeof(output_buf) - 1) != 0) { disp_msg("时间格式错误", 8); } else { char cmd[128]; strcpy(cmd, "date -D %Y-%m-%d%H:%M:%S -s "); strcat(cmd, output_buf); system(cmd); system("hwclock -w"); disp_msg("修改时间成功", 5); } }
static void sys_cfg_set_admin() { CLEAR_SCREEN; input_dst* pswd1, *pswd2; pswd1 = input_init(PASSWORD_MOD); pswd2 = input_init(PASSWORD_MOD); input_props_set(pswd1, input_one_property); input_property_set(pswd1, INPUT_HIND, "密码"); input_property_set(pswd1, INPUT_MAX_LEN, 8); input_props_set(pswd2, input_two_property); input_property_set(pswd2, INPUT_HIND, "确认"); input_property_set(pswd2, INPUT_MAX_LEN, 8); input_dis(MAIN_DISP, pswd1); input_dis(MAIN_DISP, pswd2); lcd_160_upd(); int ret; ret = input_key_manege(MAIN_DISP, pswd1 , lcd_160_upd); if (ret < 0) goto L_END; ret = input_key_manege(MAIN_DISP, pswd2 , lcd_160_upd); if (ret < 0) goto L_END; char pswd1_str[9] = {0}; char pswd2_str[9] = {0}; input_str_get(pswd1, pswd1_str); input_str_get(pswd2, pswd2_str); if (strcmp(pswd1_str, pswd2_str) != 0) { disp_msg("输入密码不符", 10); } else if (strlen(pswd1_str) < 6 || strlen(pswd1_str) > 8) { disp_msg("密码长度不符", 10); } else if (update_config("sys.password", pswd1_str)) { disp_msg("修改参数失败", 10); } else { disp_msg("修改密码成功", 5); } L_END: input_destory(pswd1); input_destory(pswd2); }
static void oper_login() { if (p16pos.login_flag == 1) { disp_msg("已签到,请先签出", 10); return; } if (!check_oper_login()) { disp_msg("签到成功", 5); } }
static void oper_printer_by_devseqno() { CLEAR_SCREEN; input_dst* devseqno_input; devseqno_input = input_init(FREE_MOD); input_props_set(devseqno_input, input_one_property); input_property_set(devseqno_input, INPUT_HIND, "流水号"); input_property_set(devseqno_input, INPUT_MAX_LEN, 10); input_dis(MAIN_DISP, devseqno_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入终端流水号", 1); lcd_160_upd(); input_key_manege(MAIN_DISP, devseqno_input , lcd_160_upd); char seqno_buf[24] = {0}; input_str_get(devseqno_input, seqno_buf); input_destory(devseqno_input); int devseqno = atoi(seqno_buf); int ret; p16_transdtl_t transdtl; memset(&transdtl, 0, sizeof transdtl); ret = trans_get_oper_devseqno(&transdtl, p16pos.operid, devseqno); if (ret == 0) { disp_msg("无流水", 10); return; } else if (ret < 0) { disp_msg("查询流水失败,请联系管理员", 10); } else { if (transdtl.transflag == TRANS_SYS_FAILED || transdtl.transflag == TRANS_INIT) { disp_msg("无效流水不能打印", 3); return; } ret = pos_printer(&transdtl, 1, 1); if (ret == 0) { disp_msg("打印成功", 5); } } }
static void sys_cfg_clear_transdtl() { int ret = confirm_dialog("确认清空流水?"); if (ret != 0) return; ret = trans_clear_dtl(); if (!ret) { disp_msg("清空流水成功", 10); } else { disp_msg("清空流水失败\n 请联系管理员", 10); } }
static void sys_cfg_reset() { if (check_admin_pswd()) { return; } disp_msg("准备恢复出厂设置", 0); if (syspara_reset()) { disp_msg("恢复出厂设置成功", 3); } else { disp_msg("恢复出厂设置失败", 3); } }
static void sys_cfg_heartbeat() { CLEAR_SCREEN; input_dst* heartbeat_input; heartbeat_input = input_init(FREE_MOD); input_props_set(heartbeat_input, input_one_property); input_property_set(heartbeat_input, INPUT_HIND, "心跳参数"); input_property_set(heartbeat_input, INPUT_MAX_LEN, 1); input_dis(MAIN_DISP, heartbeat_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "单位分,0~10", 1); lcd_160_upd(); int ret = input_key_manege(MAIN_DISP, heartbeat_input , lcd_160_upd); if (ret < 0) { input_destory(heartbeat_input); return; } char input_buf[24] = {0}; input_str_get(heartbeat_input, input_buf); input_destory(heartbeat_input); int heartbeat = atoi(input_buf); if (heartbeat < 0 || heartbeat > 10) { disp_msg("输入参数值不正确", 10); return; } if (update_config_int("sys.heartbeatminutes", heartbeat)) { disp_msg("更新工作模式失败", 10); return; } p16pos.heartbeat_minutes = heartbeat; disp_msg("修改成功,请手动重启", 5); }
static void sys_cf_set_printerpages() { CLEAR_SCREEN; input_dst* pages_input; pages_input = input_init(FREE_MOD); input_props_set(pages_input, input_one_property); input_property_set(pages_input, INPUT_HIND, "小票联数"); input_property_set(pages_input, INPUT_MAX_LEN, 1); input_dis(MAIN_DISP, pages_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入0-3一位数字", 1); lcd_160_upd(); int ret = input_key_manege(MAIN_DISP, pages_input , lcd_160_upd); if (ret < 0) { input_destory(pages_input); return; } char pages_buf[24] = {0}; input_str_get(pages_input, pages_buf); input_destory(pages_input); int pages = atoi(pages_buf); if (pages < 0 || pages > 3) { disp_msg("小票联数范围0~3", 10); return; } if (update_config_int("sys.printerpages", pages)) { disp_msg("更新小票联数失败", 10); return; } p16pos.printer_pages = (uint8)pages; disp_msg("修改小票联数成功", 5); }
static void sys_cfg_workmode() { CLEAR_SCREEN; input_dst* workmode_input; workmode_input = input_init(FREE_MOD); input_props_set(workmode_input, input_one_property); input_property_set(workmode_input, INPUT_HIND, "工作模式"); input_property_set(workmode_input, INPUT_MAX_LEN, 1); input_dis(MAIN_DISP, workmode_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "0-充值 1-补助", 1); lcd_160_upd(); int ret = input_key_manege(MAIN_DISP, workmode_input , lcd_160_upd); if (ret < 0) { input_destory(workmode_input); return; } char input_buf[24] = {0}; input_str_get(workmode_input, input_buf); input_destory(workmode_input); int mode = atoi(input_buf); if (mode != 0 && mode != 1) { disp_msg("输入参数值不正确", 10); return; } if (update_config_int("sys.workmode", mode)) { disp_msg("更新工作模式失败", 10); return; } p16pos.work_mode = mode; disp_msg("修改成功,请手动重启", 5); }
static void oper_logout() { if (p16pos.login_flag == 1) { int ret; ret = confirm_dialog("确定签出操作员?"); if (ret < 0) return; p16pos.login_flag = 0; p16pos.operid = 0; p16pos.authcode = 0; p16pos.batchno = 0; disp_msg("操作员签出成功", 6); } else { disp_msg("不需要签出", 5); } }
//{{{ int main(int argc,char** argv) int main(int argc,char** argv) { //get_config(); format_msg(0);//初次运行时获取天气 get_batt();// 初次运行时获取电量 get_cpu();//cpu get_mem();//mem get_net();//net get_temp();//temperature get_mailchk();//2014-4-2添加,邮件检查的显示。 disp_msg(); exit(0); }//}}}
static int8 check_admin_pswd() { CLEAR_SCREEN; int ret; char admin_pswd[64] = {0}; ret = SAFE_GET_CONFIG("sys.password", admin_pswd); if (ret) { disp_msg("不能获取管理密码", 5); return -1; } input_dst* pswd_input; pswd_input = input_init(PASSWORD_MOD); input_props_set(pswd_input, input_one_property); input_property_set(pswd_input, INPUT_HIND, "密码"); input_property_set(pswd_input, INPUT_MAX_LEN, 8); input_dis(MAIN_DISP, pswd_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "请输入管理员密码", 1); lcd_160_upd(); ret = input_key_manege(MAIN_DISP, pswd_input , lcd_160_upd); if (ret >= 0) { char pswd[9] = {0}; input_str_get(pswd_input, pswd); if (strcmp(pswd, admin_pswd) == 0) ret = 0; else { disp_msg("密码错误", 10); ret = -1; } } input_destory(pswd_input); return ret; }
static void sys_cfg_set_devphyid() { CLEAR_SCREEN; input_dst* devphyid_input; devphyid_input = input_init(FREE_MOD); input_props_set(devphyid_input, input_one_property); input_property_set(devphyid_input, INPUT_HIND, "终端编号"); input_property_set(devphyid_input, INPUT_MAX_LEN, 8); input_dis(MAIN_DISP, devphyid_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入8位终端编号", 1); lcd_160_upd(); input_key_manege(MAIN_DISP, devphyid_input , lcd_160_upd); char devphyid_buf[24] = {0}; input_str_get(devphyid_input, devphyid_buf); input_destory(devphyid_input); if (strlen(devphyid_buf) != 8) { disp_msg("终端号格式错误", 10); return; } if (update_config("dev.devphyid", devphyid_buf)) { disp_msg("更新终端号失败", 10); return; } strcpy(p16pos.devphyid, devphyid_buf); LOG((LOG_DEBUG, "终端号%s", p16pos.devphyid)); disp_msg("修改终端号成功", 5); }
static void oper_printer_last() { int ret; p16_transdtl_t transdtl; memset(&transdtl, 0, sizeof transdtl); ret = trans_get_last_succ(&transdtl, p16pos.operid); if (ret == 0) { disp_msg("无流水", 10); return; } else if (ret < 0) { disp_msg("查询流水失败,请联系管理员", 10); } else { ret = pos_printer(&transdtl, 1, 1); if (ret == 0) { disp_msg("打印成功", 5); } } }
static void oper_pos_printer() { if (p16pos.login_flag != 1) { disp_msg("请操作员先登录", 10); return; } menu_item_t menu[] = { {"1.最后一笔", &oper_printer_last}, {"2.按流水号", &oper_printer_by_devseqno}, {NULL, NULL}, }; easy_menu_loop(menu, "小票打印"); }
static int check_send_transdtl() { const int TRANSDTL_SLEEP_TM = 10; const int HEART_SLEEP_TM = 30; char recv_buf[1024] = {0}; int recv_len = 0; int ret =0; LOG((LOG_DEBUG,"进入check_send_transdtl")); while (p16pos.app_running) { memset(recv_buf,0,1024); recv_len = 0; ret = send_rt_transdtl_data(recv_buf,&recv_len); if(ret == 0)//发送实时流水成功的情况 { if(recv_len>0) { p16_recv_rt_transdtl_package recv_package; memset(&recv_package,0,sizeof(recv_package)); parse_recv_data(recv_buf,3,&recv_package); if(recv_package.data.ret_code == 0) { LOG((LOG_DEBUG,"上传实时流水成功")); } else { LOG((LOG_DEBUG,"上传实时流水失败,pos机不再上传流水")); } } LOG((LOG_DEBUG,"=========================sleep %d========================",TRANSDTL_SLEEP_TM)); sleep(TRANSDTL_SLEEP_TM); } else//没有交易流水需要发送 { //发送心跳 send_heart_data(recv_buf,&recv_len); if(recv_len>0) { //分析接收的数据 p16_recv_heart_package recv_heart; parse_recv_data(recv_buf,0,&recv_heart); LOG((LOG_DEBUG,"心跳收到的系统版本号:")); p16dump_hex(LOG_DEBUG,recv_heart.data.cfgverno,4); LOG((LOG_DEBUG,"心跳收到的服务器时间:")); p16dump_hex(LOG_DEBUG,recv_heart.data.server_datetime,6); LOG((LOG_DEBUG,"心跳收到的服务器黑名单版本号:")); p16dump_hex(LOG_DEBUG,recv_heart.data.current_blacklist_version,6); LOG((LOG_DEBUG,"当前系统的黑名单版本号:")); p16dump_hex(LOG_DEBUG,p16pos.pos_blacklist_version, 6); if(memcmp(recv_heart.data.current_blacklist_version,p16pos.pos_blacklist_version, 6)>0) { LOG((LOG_DEBUG,"心跳收到的黑名单版本号大于当前系统的黑名单版本号,执行下载黑名单函数!!")); //下载黑名单 memset(recv_buf,0,1024); recv_len = 0; send_download_blacklist_data(recv_buf,&recv_len); if(recv_len>0) { p16_recv_blacklist_package recv_package; parse_recv_data(recv_buf, 2, &recv_package); if(recv_package.data.list_cnt>0) { //有黑名单 LOG((LOG_DEBUG,"有黑名单%d条",recv_package.data.list_cnt)); ret = save_blackcard_record(recv_package.data.list_cnt, recv_package.data.blacklist_list); if(ret) { //致命错误,联系管理员 disp_msg("操作数据库失败,请联系管理员",10); return -1; } //更新系统黑名单版本号 char pos_blacklist_version[13] = {0}; encode_hex(recv_package.data.sys_list_version, 6, pos_blacklist_version); //更新系统版本号 ret = update_config("dev.pos_blacklist_version",pos_blacklist_version); if(ret) { //致命错误 return -2; } memcpy(p16pos.pos_blacklist_version, recv_package.data.sys_list_version, 6); LOG((LOG_DEBUG,"更新版本号为:%s",pos_blacklist_version)); LOG((LOG_DEBUG,"=======================================================")); } } } } LOG((LOG_DEBUG,"=========================sleep %d========================",HEART_SLEEP_TM)); sleep(HEART_SLEEP_TM); } } return 0; }
static void do_statistic_oper_by_day(const char* today) { if (p16pos.login_flag != 1) { disp_msg("请操作员先登录", 10); return; } oper_trans_t trans; memset(&trans, 0, sizeof trans); int ret = oper_get_trans(today, p16pos.operid, &trans); if (ret) { disp_msg("查询失败\n请联系管理员", 10); return; } char tip[64]; CLEAR_SCREEN; uint8 y_coor = DISP_Y_COOR; sprintf(tip, "操作员 %s", p16pos.opername); printf_str(MAIN_DISP, DISP_X_COOR, y_coor, tip, 1); y_coor += 26; sprintf(tip, "统计日期 %s", today); printf_str(MAIN_DISP, DISP_X_COOR, y_coor, tip, 1); y_coor += 26; line(MAIN_DISP, DISP_X_COOR, y_coor, DISP_X_COOR + 200, y_coor, 1); line(MAIN_DISP, DISP_X_COOR, y_coor + 1, DISP_X_COOR + 200, y_coor + 1, 1); y_coor += 6; int index = 0; uint8 key; dis_mod_set(MAIN_DISP, DEFAULT_HZ_FONT, DEFAULT_ASC_FONT); while (1) { // box(MAIN_DISP, 0, y_coor, 160, 160, 0); CLEAR(MAIN_DISP, DISP_X_COOR, y_coor, DISP_X_COOR + DISP_X_PIXEL, DISP_Y_PIXEL); if (index == 0) { sprintf(tip, "成功 %d笔", trans.success_cnt); printf_str(MAIN_DISP, DISP_X_COOR, y_coor, tip, 1); sprintf(tip, " %0.2f元", trans.success_amt / 100.0); printf_str(MAIN_DISP, DISP_X_COOR, y_coor + INPUT_HEIGHT, tip, 1); } else if (index == 1) { sprintf(tip, "失败 %d笔", trans.total_cnt - trans.success_cnt); printf_str(MAIN_DISP, DISP_X_COOR, y_coor, tip, 1); sprintf(tip, " %0.2f元", (trans.total_amt - trans.success_amt) / 100.0); printf_str(MAIN_DISP, DISP_X_COOR, y_coor + INPUT_HEIGHT, tip, 1); } else { sprintf(tip, "总数 %d笔", trans.total_cnt); printf_str(MAIN_DISP, DISP_X_COOR, y_coor, tip, 1); sprintf(tip, " %0.2f元", (trans.total_amt) / 100.0); printf_str(MAIN_DISP, DISP_X_COOR, y_coor + INPUT_HEIGHT, tip, 1); } lcd_160_upd(); ret = get_key(&key, BLOCK_MOD, -1); if (ret < 0) continue; if (ESC_KEY == key) { return; } else if (KEY_UP == key) { --index; if (index < 0) index = 0; } else if (KEY_DN == key) { ++index; if (index > 2) index = 2; } } }
static void sys_cfg_rom_update() { CLEAR_SCREEN; disp_msg("未实现功能", 5); }
static void sys_cfg_set_local_network() { CLEAR_SCREEN; const uint32 input_length = 190; input_dst* ip_input, *net_input, *gw_input; ip_input = input_init(FREE_MOD); net_input = input_init(FREE_MOD); gw_input = input_init(FREE_MOD); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "输入IP信息", 1); input_props_set(ip_input, input_one_property); input_property_set(ip_input, INPUT_HIND, "IP"); input_property_set(ip_input, INPUT_MAX_LEN, 15); input_property_set(ip_input, INPUT_RET_STA, 150, INPUT_Y_COOR); input_property_set(ip_input, INPUT_RET_SIZ, INPUT_HEIGHT, input_length); input_props_set(net_input, input_two_property); input_property_set(net_input, INPUT_HIND, "掩码"); input_property_set(net_input, INPUT_MAX_LEN, 15); input_property_set(net_input, INPUT_RET_STA, 150, INPUT_TWO_Y_COOR); input_property_set(net_input, INPUT_RET_SIZ, INPUT_HEIGHT, input_length); input_props_set(gw_input, input_three_property); input_property_set(gw_input, INPUT_HIND, "网关"); input_property_set(gw_input, INPUT_MAX_LEN, 15); input_property_set(gw_input, INPUT_RET_STA, 150, INPUT_THREE_Y_COOR); input_property_set(gw_input, INPUT_RET_SIZ, INPUT_HEIGHT, input_length); input_dis(MAIN_DISP, ip_input); input_dis(MAIN_DISP, net_input); input_dis(MAIN_DISP, gw_input); lcd_160_upd(); input_key_manege(MAIN_DISP, ip_input, lcd_160_upd); input_key_manege(MAIN_DISP, net_input, lcd_160_upd); input_key_manege(MAIN_DISP, gw_input, lcd_160_upd); char ip[24] = {0}; char netmask[24] = {0}; char gw[24] = {0}; input_str_get(ip_input, ip); input_str_get(net_input, netmask); input_str_get(gw_input, gw); input_destory(ip_input); input_destory(net_input); input_destory(gw_input); if (check_ip_valid(ip) || check_ip_valid(netmask) || check_ip_valid(gw)) { disp_msg("输入格式错误", 10); return; } if (set_local_ip(ip, netmask, gw)) { disp_msg("修改IP失败", 10); } else { update_config("dev.ip", ip); update_config("dev.netmask", netmask); update_config("dev.gateway", gw); disp_msg("设置IP成功", 5); } }