00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <unistd.h>
00022 #include <stdlib.h>
00023 #include "hsmsd_cli.h"
00024
00025 static FILE *fp = NULL;
00026
00027
00028 void hsms_msg_handler(hsmsd_msg_t* msg)
00029 {
00030 unsigned char *begin = NULL, *end = NULL, *iter = NULL;
00031 unsigned int ctr = 0;
00032 printf("hsms_msg_handler: s%df%d\n", msg->stream, msg->function);
00033
00034 if(fp)
00035 {
00036 fprintf(fp, "s%df%d, len=%d\n", msg->stream, msg->function, msg->data_len);
00037
00038 begin = &msg->data[0];
00039 end = &msg->data[0] + msg->data_len;
00040 for(iter = begin; iter < end; ++iter)
00041 {
00042 fprintf(fp, "0x%x, ", *iter);
00043 if(ctr++ > 10)
00044 {
00045 fprintf(fp, "\n");
00046 ctr = 0;
00047 }
00048 }
00049 fprintf(fp, "\n\n\n");
00050 fflush(fp);
00051 }
00052
00053 free(msg);
00054 }
00055
00056 void hsms_cnx_state_handler(hsmsd_cnx_state_t state)
00057 {
00058 static char str_state[][32] = {"NOT CONNECTED", "NOT SELECTED", "SELECTED"};
00059
00060 printf("hsms_cnx_state_handler: %s\n", str_state[state]);
00061 }
00062
00063 void hsmsd_cnx_error_handler(int err)
00064 {
00065 printf("hsmsd_cnx_error_handler: %d\n", err);
00066 }
00067
00068
00069 int main(int argc, char **argv)
00070 {
00071 int r;
00072 hsmsd_handle_t h;
00073
00074 r = hsmsd_alloc_handle(&h, "hsms1");
00075 printf("hsmsd_alloc_handle returned %d\n", r);
00076 if(r) exit(-1);
00077
00078 r = hsmsd_subscribe_for_msgs(h, (hsmsd_msg_handler_t)hsms_msg_handler );
00079 printf("hsmsd_subscribe_for_msgs returned %d\n", r);
00080 if(r) exit(-2);
00081
00082 r = hsmsd_subscribe_for_cnx_state(h, (hsmsd_cnx_state_handler_t)hsms_cnx_state_handler);
00083 printf("hsmsd_subscribe_for_cnx_state returned %d\n", r);
00084 if(r) exit(-3);
00085
00086 r = hsmsd_subscribe_for_cnx_error(h, (hsmsd_cnx_error_handler_t)hsmsd_cnx_error_handler);
00087 printf("hsmsd_subscribe_for_cnx_error returned %d\n", r);
00088 if(r) exit(-4);
00089
00090 fp = fopen("./msgs.txt", "w+");
00091 if(!fp) exit(-5);
00092
00093 r = hsmsd_cnx_start(h);
00094 printf("hsmsd_cnx_start returned %d\n", r);
00095 if(r) exit(-6);
00096
00097 while(1) sleep(2);
00098
00099
00100 exit(0);
00101 }