📄 test1_main.c
字号:
/* * (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net) * * This file is part of FREESECS. * * FREESECS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * FREESECS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with FREESECS, see COPYING. * If not, see <http://www.gnu.org/licenses/>. */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include "hsmsd_cli.h"static FILE *fp = NULL;void hsms_msg_handler(hsmsd_msg_t* msg){ unsigned char *begin = NULL, *end = NULL, *iter = NULL; unsigned int ctr = 0; printf("hsms_msg_handler: s%df%d\n", msg->stream, msg->function); if(fp) { fprintf(fp, "s%df%d, len=%d\n", msg->stream, msg->function, msg->data_len); begin = &msg->data[0]; end = &msg->data[0] + msg->data_len; for(iter = begin; iter < end; ++iter) { fprintf(fp, "0x%x, ", *iter); if(ctr++ > 10) { fprintf(fp, "\n"); ctr = 0; } } fprintf(fp, "\n\n\n"); fflush(fp); } free(msg);}void hsms_cnx_state_handler(hsmsd_cnx_state_t state){ static char str_state[][32] = {"NOT CONNECTED", "NOT SELECTED", "SELECTED"}; printf("hsms_cnx_state_handler: %s\n", str_state[state]);}void hsmsd_cnx_error_handler(int err){ printf("hsmsd_cnx_error_handler: %d\n", err);}int main(int argc, char **argv){ int r; hsmsd_handle_t h; r = hsmsd_alloc_handle(&h, "hsms1"); printf("hsmsd_alloc_handle returned %d\n", r); if(r) exit(-1); r = hsmsd_subscribe_for_msgs(h, (hsmsd_msg_handler_t)hsms_msg_handler ); printf("hsmsd_subscribe_for_msgs returned %d\n", r); if(r) exit(-2); r = hsmsd_subscribe_for_cnx_state(h, (hsmsd_cnx_state_handler_t)hsms_cnx_state_handler); printf("hsmsd_subscribe_for_cnx_state returned %d\n", r); if(r) exit(-3); r = hsmsd_subscribe_for_cnx_error(h, (hsmsd_cnx_error_handler_t)hsmsd_cnx_error_handler); printf("hsmsd_subscribe_for_cnx_error returned %d\n", r); if(r) exit(-4); fp = fopen("./msgs.txt", "w+"); if(!fp) exit(-5); r = hsmsd_cnx_start(h); printf("hsmsd_cnx_start returned %d\n", r); if(r) exit(-6); while(1) sleep(2); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -