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 <string.h>
00024 #include <semaphore.h>
00025 #include "hsmsd_cli.h"
00026
00027
00028 #define MAX_DELTA 30
00029
00030 struct
00031 {
00032 unsigned short stream;
00033 unsigned short function;
00034 unsigned char wbit;
00035 unsigned int sysbytes;
00036 unsigned int data_len;
00037 unsigned char data[2];
00038 } s1f13_msg =
00039 {
00040 .stream = 1,
00041 .function = 13,
00042 .wbit = 1,
00043 .sysbytes = 0,
00044 .data_len = 2,
00045 .data = {0x1, 0x0}
00046 };
00047
00048 struct
00049 {
00050 unsigned short stream;
00051 unsigned short function;
00052 unsigned char wbit;
00053 unsigned int sysbytes;
00054 unsigned int data_len;
00055 unsigned char data[343];
00056 } s3f17_msg =
00057 {
00058 .stream = 3,
00059 .function = 17,
00060 .wbit = 1,
00061 .sysbytes = 1 << 24,
00062 .data_len = 343,
00063 .data = { 0x1, 0x5, 0xa9, 0x2, 0x0, 0x1, 0x41, 0x4, 0x42, 0x69, 0x6e, 0x64,
00064 0x41, 0x10, 0x43, 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30,
00065 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0xa5, 0x1, 0x1, 0x1, 0x5, 0x1,
00066 0x2, 0x41, 0x8, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0xa5,
00067 0x1, 0x19, 0x1, 0x2, 0x41, 0xe, 0x53, 0x75, 0x62, 0x73, 0x74, 0x72,
00068 0x61, 0x74, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0xa5, 0x1, 0x0, 0x1,
00069 0x2, 0x41, 0x5, 0x55, 0x73, 0x61, 0x67, 0x65, 0x41, 0x7, 0x50, 0x52,
00070 0x4f, 0x44, 0x55, 0x43, 0x54, 0x1, 0x2, 0x41, 0x7, 0x53, 0x6c, 0x6f,
00071 0x74, 0x4d, 0x61, 0x70, 0x1, 0x19, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1,
00072 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1,
00073 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1,
00074 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1,
00075 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1,
00076 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1,
00077 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0xa5, 0x1, 0x1, 0x1, 0x2, 0x41,
00078 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x4d, 0x61, 0x70, 0x1,
00079 0x19, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00080 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00081 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00082 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00083 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00084 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00085 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00086 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00087 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00088 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00089 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00090 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0, 0x1, 0x2, 0x41, 0x0, 0x41,
00091 0x0, 0x1, 0x2, 0x41, 0x0, 0x41, 0x0}
00092 };
00093
00094 struct
00095 {
00096 unsigned short stream;
00097 unsigned short function;
00098 unsigned char wbit;
00099 unsigned int sysbytes;
00100 unsigned int data_len;
00101 unsigned char data[343];
00102 } s16f15_msg =
00103 {
00104 .stream = 16,
00105 .function = 15,
00106 .wbit = 1,
00107 .sysbytes = 2 << 24,
00108 .data_len = 260,
00109 .data = { 0x1, 0x2, 0xa9, 0x2, 0x0, 0x0, 0x1, 0x3, 0x1, 0x6, 0x41, 0xe,
00110 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x4a, 0x6f, 0x62, 0x5f,
00111 0x47, 0x31, 0x21, 0x1, 0xd, 0x1, 0x1, 0x1, 0x2, 0x41, 0x10, 0x43,
00112 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30,
00113 0x30, 0x30, 0x32, 0x1, 0x1, 0xa5, 0x1, 0x1, 0x1, 0x3, 0xa5, 0x1,
00114 0x1, 0x41, 0x16, 0x48, 0x6f, 0x73, 0x74, 0x5c, 0x52, 0x65, 0x61, 0x64,
00115 0x20, 0x61, 0x6e, 0x64, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65,
00116 0x72, 0x1, 0x0, 0x25, 0x1, 0xff, 0x1, 0x0, 0x1, 0x6, 0x41, 0xe,
00117 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x4a, 0x6f, 0x62, 0x5f,
00118 0x47, 0x32, 0x21, 0x1, 0xd, 0x1, 0x1, 0x1, 0x2, 0x41, 0x10, 0x43,
00119 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30,
00120 0x30, 0x30, 0x33, 0x1, 0x1, 0xa5, 0x1, 0x1, 0x1, 0x3, 0xa5, 0x1,
00121 0x1, 0x41, 0x16, 0x48, 0x6f, 0x73, 0x74, 0x5c, 0x52, 0x65, 0x61, 0x64,
00122 0x20, 0x61, 0x6e, 0x64, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65,
00123 0x72, 0x1, 0x0, 0x25, 0x1, 0xff, 0x1, 0x0, 0x1, 0x6, 0x41, 0xe,
00124 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x4a, 0x6f, 0x62, 0x5f,
00125 0x47, 0x33, 0x21, 0x1, 0xd, 0x1, 0x1, 0x1, 0x2, 0x41, 0x10, 0x43,
00126 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30,
00127 0x30, 0x30, 0x34, 0x1, 0x1, 0xa5, 0x1, 0x1, 0x1, 0x3, 0xa5, 0x1,
00128 0x1, 0x41, 0x16, 0x48, 0x6f, 0x73, 0x74, 0x5c, 0x52, 0x65, 0x61, 0x64,
00129 0x20, 0x61, 0x6e, 0x64, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65,
00130 0x72, 0x1, 0x0, 0x25, 0x1, 0xff, 0x1, 0x0 }
00131 };
00132
00133 struct
00134 {
00135 unsigned short stream;
00136 unsigned short function;
00137 unsigned char wbit;
00138 unsigned int sysbytes;
00139 unsigned int data_len;
00140 unsigned char data[504];
00141 } s14f9_msg =
00142 {
00143 .stream = 14,
00144 .function = 9,
00145 .wbit = 1,
00146 .sysbytes = 3 << 24,
00147 .data_len = 504,
00148 .data = { 0x1, 0x3, 0x41, 0x9, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e,
00149 0x74, 0x41, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x4a, 0x6f,
00150 0x62, 0x1, 0x9, 0x1, 0x2, 0x41, 0x5, 0x4f, 0x62, 0x6a, 0x49, 0x44,
00151 0x41, 0x7, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x5f, 0x47, 0x1, 0x2, 0x41,
00152 0x12, 0x44, 0x61, 0x74, 0x61, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74,
00153 0x69, 0x6f, 0x6e, 0x50, 0x6c, 0x61, 0x6e, 0x41, 0x0, 0x1, 0x2, 0x41,
00154 0x10, 0x43, 0x61, 0x72, 0x72, 0x69, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75,
00155 0x74, 0x53, 0x70, 0x65, 0x63, 0x1, 0x4, 0x41, 0x10, 0x43, 0x41, 0x52,
00156 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
00157 0x31, 0x41, 0x10, 0x43, 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30,
00158 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x41, 0x10, 0x43, 0x41, 0x52,
00159 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
00160 0x33, 0x41, 0x10, 0x43, 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30,
00161 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x1, 0x2, 0x41, 0xb, 0x4d,
00162 0x74, 0x72, 0x6c, 0x4f, 0x75, 0x74, 0x53, 0x70, 0x65, 0x63, 0x1, 0x3,
00163 0x1, 0x2, 0x1, 0x2, 0x41, 0x10, 0x43, 0x41, 0x52, 0x52, 0x49, 0x45,
00164 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x1, 0x1,
00165 0xa5, 0x1, 0x1, 0x1, 0x2, 0x41, 0x10, 0x43, 0x41, 0x52, 0x52, 0x49,
00166 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x1,
00167 0x1, 0xa5, 0x1, 0x1, 0x1, 0x2, 0x1, 0x2, 0x41, 0x10, 0x43, 0x41,
00168 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
00169 0x30, 0x33, 0x1, 0x1, 0xa5, 0x1, 0x1, 0x1, 0x2, 0x41, 0x10, 0x43,
00170 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30, 0x30, 0x30, 0x30,
00171 0x30, 0x30, 0x31, 0x1, 0x1, 0xa5, 0x1, 0x2, 0x1, 0x2, 0x1, 0x2,
00172 0x41, 0x10, 0x43, 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30, 0x30,
00173 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x1, 0x1, 0xa5, 0x1, 0x1, 0x1,
00174 0x2, 0x41, 0x10, 0x43, 0x41, 0x52, 0x52, 0x49, 0x45, 0x52, 0x5f, 0x30,
00175 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x1, 0x1, 0xa5, 0x1, 0x3,
00176 0x1, 0x2, 0x41, 0xf, 0x4d, 0x74, 0x72, 0x6c, 0x4f, 0x75, 0x74, 0x42,
00177 0x79, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x1, 0x0, 0x1, 0x2, 0x41,
00178 0xa, 0x50, 0x61, 0x75, 0x73, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1,
00179 0x0, 0x1, 0x2, 0x41, 0x12, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73,
00180 0x69, 0x6e, 0x67, 0x43, 0x74, 0x72, 0x6c, 0x53, 0x70, 0x65, 0x63, 0x1,
00181 0x3, 0x1, 0x3, 0x41, 0xe, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65,
00182 0x72, 0x4a, 0x6f, 0x62, 0x5f, 0x47, 0x31, 0x1, 0x0, 0x1, 0x0, 0x1,
00183 0x3, 0x41, 0xe, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x4a,
00184 0x6f, 0x62, 0x5f, 0x47, 0x32, 0x1, 0x0, 0x1, 0x0, 0x1, 0x3, 0x41,
00185 0xe, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x4a, 0x6f, 0x62,
00186 0x5f, 0x47, 0x33, 0x1, 0x0, 0x1, 0x0, 0x1, 0x2, 0x41, 0x10, 0x50,
00187 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x4d,
00188 0x67, 0x6d, 0x74, 0xa5, 0x1, 0x3, 0x1, 0x2, 0x41, 0xb, 0x53, 0x74,
00189 0x61, 0x72, 0x74, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x25, 0x1, 0x0}
00190 };
00191
00192 static FILE *fp = NULL;
00193 static char msg_flags[15][30];
00194
00195 static struct
00196 {
00197 sem_t sent_sem;
00198 sem_t recv_sem;
00199 sem_t err_sem;
00200 unsigned long us_timeout;
00201 unsigned int transaction_id;
00202 hsmsd_msg_t* pmsg;
00203 }msg_dict[4] =
00204 {
00205 {.us_timeout = 1, .transaction_id = 1 << 24, .pmsg = (hsmsd_msg_t*)&s1f13_msg},
00206 {.us_timeout = 1, .transaction_id = 2 << 24, .pmsg = (hsmsd_msg_t*)&s3f17_msg},
00207 {.us_timeout = 1, .transaction_id = 3 << 24, .pmsg = (hsmsd_msg_t*)&s16f15_msg},
00208 {.us_timeout = 1, .transaction_id = 4 << 24, .pmsg = (hsmsd_msg_t*)&s14f9_msg}
00209 };
00210
00211
00212 static void prepare_dict(void);
00213 static void start_threads(void*);
00214 static void hsms_msg_handler(hsmsd_msg_t* msg);
00215 static void hsms_cnx_state_handler(hsmsd_cnx_state_t state);
00216 static void hsmsd_cnx_error_handler(int err);
00217
00218 static void* thread_func0(void*);
00219 static void* thread_func1(void*);
00220 static void* thread_func2(void*);
00221 static void* thread_func3(void*);
00222
00223 static sem_t cnx_ready_sem;
00224
00225 int main(int argc, char **argv)
00226 {
00227 int print_offset;
00228 int r, sent[4], recv[4], err[4];
00229 hsmsd_handle_t h;
00230
00231
00232 memset(msg_flags, 0, sizeof(msg_flags));
00233
00234 r = hsmsd_alloc_handle(&h, "hsms1");
00235 fprintf(stdout, "hsmsd_alloc_handle returned %d\n", r);
00236 if(r) exit(-1);
00237
00238 r = hsmsd_subscribe_for_msgs(h, (hsmsd_msg_handler_t)hsms_msg_handler );
00239 fprintf(stdout, "hsmsd_subscribe_for_msgs returned %d\n", r);
00240 if(r) exit(-2);
00241
00242 r = hsmsd_subscribe_for_cnx_state(h, (hsmsd_cnx_state_handler_t)hsms_cnx_state_handler);
00243 fprintf(stdout, "hsmsd_subscribe_for_cnx_state returned %d\n", r);
00244 if(r) exit(-3);
00245
00246 r = hsmsd_subscribe_for_cnx_error(h, (hsmsd_cnx_error_handler_t)hsmsd_cnx_error_handler);
00247 fprintf(stdout, "hsmsd_subscribe_for_cnx_error returned %d\n", r);
00248 if(r) exit(-4);
00249
00250 sem_init(&cnx_ready_sem, 0, 0);
00251
00252 r = hsmsd_cnx_start(h);
00253 fprintf(stdout, "hsmsd_cnx_start returned %d\n", r);
00254 if(r) exit(-5);
00255
00256 sem_wait(&cnx_ready_sem);
00257
00258 prepare_dict();
00259 fprintf(stdout, "dict prepared\n");
00260
00261 start_threads((void*)&h);
00262 fprintf(stdout, "threads started\n");
00263
00264 while(1)
00265 {
00266 sleep(2);
00267
00268 sem_getvalue(&msg_dict[0].sent_sem, &sent[0]);
00269 sem_getvalue(&msg_dict[1].sent_sem, &sent[1]);
00270 sem_getvalue(&msg_dict[2].sent_sem, &sent[2]);
00271 sem_getvalue(&msg_dict[3].sent_sem, &sent[3]);
00272
00273 sem_getvalue(&msg_dict[0].recv_sem, &recv[0]);
00274 sem_getvalue(&msg_dict[1].recv_sem, &recv[1]);
00275 sem_getvalue(&msg_dict[2].recv_sem, &recv[2]);
00276 sem_getvalue(&msg_dict[3].recv_sem, &recv[3]);
00277
00278 sem_getvalue(&msg_dict[0].err_sem, &err[0]);
00279 sem_getvalue(&msg_dict[1].err_sem, &err[1]);
00280 sem_getvalue(&msg_dict[2].err_sem, &err[2]);
00281 sem_getvalue(&msg_dict[3].err_sem, &err[3]);
00282
00283 print_offset = 0;
00284 print_offset += fprintf(stdout,
00285 "sent:\t%d\t|\t%d\t|\t%d\t|\t%d\n",
00286 sent[0], sent[1], sent[2], sent[3]);
00287 print_offset += fprintf(stdout,
00288 "recv:\t%d\t|\t%d\t|\t%d\t|\t%d\n",
00289 recv[0], recv[1], recv[2], recv[3]);
00290 print_offset += fprintf(stdout,
00291 "err:\t%d\t|\t%d\t|\t%d\t|\t%d\n",
00292 err[0], err[1], err[2], err[3]);
00293
00294 fflush(stdout);
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 }
00306
00307
00308 exit(0);
00309 }
00310
00311
00312
00313 void prepare_dict(void)
00314 {
00315 sem_init(&msg_dict[0].sent_sem, 0, 0);
00316 sem_init(&msg_dict[1].sent_sem, 0, 0);
00317 sem_init(&msg_dict[2].sent_sem, 0, 0);
00318 sem_init(&msg_dict[3].sent_sem, 0, 0);
00319
00320 sem_init(&msg_dict[0].recv_sem, 0, 0);
00321 sem_init(&msg_dict[1].recv_sem, 0, 0);
00322 sem_init(&msg_dict[2].recv_sem, 0, 0);
00323 sem_init(&msg_dict[3].recv_sem, 0, 0);
00324
00325 sem_init(&(msg_dict[0].err_sem), 0, 0);
00326 sem_init(&(msg_dict[1].err_sem), 0, 0);
00327 sem_init(&(msg_dict[2].err_sem), 0, 0);
00328 sem_init(&(msg_dict[3].err_sem), 0, 0);
00329 }
00330
00331 void start_threads(void *pdata)
00332 {
00333 pthread_t id0, id1, id2, id3;
00334 pthread_create(&id0, NULL, thread_func0, pdata);
00335 pthread_create(&id1, NULL, thread_func1, pdata);
00336 pthread_create(&id2, NULL, thread_func2, pdata);
00337 pthread_create(&id3, NULL, thread_func3, pdata);
00338 }
00339
00340 void hsmsd_cnx_error_handler(int err)
00341 {
00342 fprintf(stdout, "hsmsd_cnx_error_handler: %d\n", err);
00343 }
00344
00345
00346 void hsms_msg_handler(hsmsd_msg_t* msg)
00347 {
00348 unsigned char *begin = NULL, *end = NULL, *iter = NULL;
00349 unsigned int ctr = 0;
00350
00351
00352
00353 if(fp && 0 == msg_flags[msg->stream][msg->function])
00354 {
00355 msg_flags[msg->stream][msg->function] = 1;
00356
00357 fprintf(fp, "s%df%d, len=%d\n", msg->stream, msg->function, msg->data_len);
00358
00359 begin = &msg->data[0];
00360 end = &msg->data[0] + msg->data_len;
00361 for(iter = begin; iter < end; ++iter)
00362 {
00363 fprintf(fp, "0x%x, ", *iter);
00364 if(ctr++ > 10)
00365 {
00366 fprintf(fp, "\n");
00367 ctr = 0;
00368 }
00369 }
00370 fprintf(fp, "\n\n\n");
00371 fflush(fp);
00372 }
00373
00374 int pool_num = msg->sysbytes >> 24;
00375 if(4 > pool_num)
00376 {
00377 sem_post(&msg_dict[pool_num].recv_sem);
00378 }
00379 else
00380 {
00381 fprintf(stdout, ">>>!!!!!unknown id: %d!!!!!<<<\n",pool_num);
00382 }
00383 free(msg);
00384 }
00385
00386 void hsms_cnx_state_handler(hsmsd_cnx_state_t state)
00387 {
00388 static char str_state[][32] = {"NOT CONNECTED", "NOT SELECTED", "SELECTED"};
00389
00390 if(CNX_SELECTED == state)
00391 {
00392 sem_post(&cnx_ready_sem);
00393 }
00394 fprintf(stdout, "hsms_cnx_state_handler: %s\n", str_state[state]);
00395 }
00396
00397 static void* thread_funcx(int num, void* data)
00398 {
00399 fprintf(stdout, "thread function %d\n", num);
00400 hsmsd_handle_t h = *((hsmsd_handle_t*)data);
00401 while(1)
00402 {
00403 usleep(msg_dict[num].us_timeout);
00404 msg_dict[num].pmsg->sysbytes += 1;
00405 if(0 == hsmsd_cnx_send_msg(h, msg_dict[num].pmsg))
00406 {
00407 sem_post(&msg_dict[num].sent_sem);
00408 }
00409 else
00410 {
00411 fprintf(stdout, "thread function %d: exit...\n", num);
00412 sem_post(&msg_dict[num].err_sem);
00413 pthread_exit(NULL);
00414 }
00415 }
00416 fprintf(stdout, "thread function %d: exit...\n", num);
00417 return NULL;
00418 }
00419
00420 void* thread_func0(void* data)
00421 {
00422 return thread_funcx(0, data);
00423 }
00424
00425 void* thread_func1(void* data)
00426 {
00427 return thread_funcx(1, data);
00428 }
00429
00430 void* thread_func2(void* data)
00431 {
00432 return thread_funcx(2, data);
00433 }
00434
00435 void* thread_func3(void* data)
00436 {
00437 return thread_funcx(3, data);
00438 }