void fmtr(char *f) { int i, w, cw; Rune r; static int nstart; USED(f); if(nstart) xprint("%*c", 3*nstart, ' '); for(i=nstart; i<ndata; ) if(data[i] < Runeself) onefmtc(data[i++]); else{ w = chartorune(&r, (char *)data+i); if(w == 1 || i + w>nread) onefmtc(data[i++]); else{ cw = w; if(i + w>ndata) cw = ndata - i; xprint(rfmt[0][0], r); xprint("%*c", 3*cw-3, ' '); i += w; } } if(i > ndata) nstart = i - ndata; else nstart = 0; }
void *ResetWatchdogTask(void *argc) { struct timeval tv; struct tm ctime; int sectime, check1sec = FALSE; ThreadAlive[PTASK4] = TRUE; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_cleanup_push(ThreadCleanUp, (void *)NULL); gettimeofday(&tv, NULL); localtime_r((time_t *)&(tv.tv_sec), &ctime); sectime = ctime.tm_sec; for (;;) { if (ThreadAlive[PTASK4] != TRUE) { break; } gettimeofday(&tv, NULL); localtime_r((time_t *)&(tv.tv_sec), &ctime); /* check for every sec */ if (sectime != ctime.tm_sec) { if (check1sec != TRUE && CHECK_WATCHDOG_MSEC != 0) { xprint(FMS_HST | FMS_INFO5, "%s :: Rest Bypass WatchDog Start\n", __func__); /* re-set bypass watchdog */ ResetBypassWatchdog(); sectime = ctime.tm_sec; check1sec = TRUE; xprint(FMS_HST | FMS_INFO5, "%s :: Rest Bypass WatchDog End\n", __func__); } } else { check1sec = FALSE; } nanoSleep(100); } ThreadAlive[PTASK4] = FALSE; ThreadFlags[PTASK4] = FALSE; pthread_cleanup_pop(1); return(NULL); }
int matcher(char *action, Pattern *p, char *message, Resub *m) { char *cp; String *s; for(cp = message; matchpat(p, cp, m); cp = m->ep) { switch(p->action) { case SaveLine: if(vflag) xprint(2, action, m); saveline(linefile, sender, m); break; case HoldHeader: case Hold: if(nflag) continue; if(vflag) xprint(2, action, m); *qdir = holdqueue; if(hflag && qname) { cp = strchr(sender, '!'); if(cp) { *cp = 0; *qname = strdup(sender); *cp = '!'; } else *qname = strdup(sender); } return 1; case Dump: if(vflag) xprint(2, action, m); *(m->ep) = 0; if(!tflag) { s = s_new(); s_append(s, sender); s = unescapespecial(s); syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->sp, s_to_c(s_restart(recips))); s_free(s); } tflag = 1; if(sflag) cout = opendump(sender); return 1; default: break; } } return 0; }
void *CheckTcpStatusTask(void *argc) { int check1min; struct timeval tv; struct tm ctime; ThreadAlive[PTASK3] = TRUE; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_cleanup_push(ThreadCleanUp, (void *)NULL); check1min = FALSE; /* tmphandler */ for (;;) { if (ThreadAlive[PTASK3] != TRUE) { break; } gettimeofday(&tv, NULL); localtime_r((time_t *)&(tv.tv_sec), &ctime); /* every minute */ if (ctime.tm_sec == 15) { if (check1min != TRUE) { xprint(FMS_HST | FMS_INFO1, "%s : Check TCP Status START\n", __func__); /* TCP status */ CheckTcpStatus(); check1min = TRUE; xprint(FMS_HST | FMS_INFO1, "%s : Check TCP Status End\n", __func__); } } else { check1min = FALSE; } nanoSleep(100); } ThreadAlive[PTASK3] = FALSE; ThreadFlags[PTASK3] = FALSE; pthread_cleanup_pop(1); return(NULL); }
static int uvc_gadget_stream(struct uvc_gadget_device *dev, int enable) { int ret; if (enable) { xprint(xLOGDBG, "Starting video stream\n"); ret = v4l2_stream_on(dev->fd, dev->type); } else { xprint(xLOGDBG, "Stopping video stream\n"); ret = v4l2_stream_off(dev->fd, dev->type); } return ret; }
/** @function ******************************************************************************** <PRE> 函数名: voiceToMFCC() 功能: 得到语音的MFCC参数组 用法: 参数: [IN] pRawVoice: 原始语音数据 [IN] iSampleNum: 语音样本数 [OUT] MFCC: 指向存放MFCC参数组的指针,大小为MFCC[帧数][20] [IN] train_frame_num: 训练帧帧数 返回: TRUE: 成功提取 FALSE: 提取失败 调用: PreEmphasis(), JudgeTrainFrame(), FrameMultiHamming(), FrameToMFCC() 主调函数: 备注: 提供给外层的接口 </PRE> *******************************************************************************/ BOOL voiceToMFCC(BYTE * pRawVoice, int iSampleNum, double ** MFCC, int train_frame_num) { double * pDiffVoice = NULL; double * pDiff = NULL; VOICEFRAME * pVoiceFrame = NULL; // 指向可用的训练帧 //pDiffVoice = (double *)malloc(iSampleNum * sizeof(double)); pDiffVoice = (double *)calloc(iSampleNum, sizeof(double)); if (!pDiffVoice) { xprint("pDiffVoice"); return FALSE; } PreEmphasis(pRawVoice, iSampleNum, pDiffVoice); // 预增强 pDiff = JudgeTrainFrame2(pDiffVoice, iSampleNum, train_frame_num); if (!pDiff) // 判断静寂语音 { //xprint("Error: It`s silent voice!"); free(pDiffVoice); return FALSE; } pVoiceFrame = (VOICEFRAME *)malloc(train_frame_num * sizeof(VOICEFRAME)); FrameMultiHamming(pDiff, pVoiceFrame, train_frame_num); // 得到频域帧 free(pDiff); FrameToMFCC(pVoiceFrame, MFCC, train_frame_num); // 从帧得到MFCC参数组 free(pVoiceFrame); free(pDiffVoice); return TRUE; }
void fmt0(char *f) { int i; for(i=0; i<ndata; i++) xprint(f, data[i]); }
void fmt1(char *f) { int i; for(i=0; i<ndata; i+=sizeof(ushort)) xprint(f, (data[i]<<8)|data[i+1]); }
void home_task(void) { task_open(); current_menu_item = 1; current_tid = 0; while(1) { if( current_tid == 0) { clearBuff(); setxy(2,4); xprint("%s\n0x%04X",mainMenu[current_menu_item].name,mainMenu[current_menu_item].task ); lcd_xmit(); } event_wait( buttonEvent ); char button_state = button_get_pressed(); if(current_tid == 0) { if(( button_state & BUTTON_DOWN )&&( current_menu_item > 0 )) { current_menu_item--; // antmation? } else if(( button_state & BUTTON_UP )&&( current_menu_item < N_MENU -1 )) { current_menu_item++; } else if(( button_state & BUTTON_SELECT )) // no task running { // call up a new task task_create( mainMenu[current_menu_item].task, 10, 0, 0, 0 ); // should be a lower priority than this task // store tid current_tid = 1;//task_id_get( mainMenu[current_menu_item].task ); } } else { if(( button_state & BUTTON_MENU )) { task_kill( mainMenu[current_menu_item].task ); current_tid = 0; } } task_wait(10); //P2OUT ^= BIT3; } task_close(); }
void fmt2(char *f) { int i; for(i=0; i<ndata; i+=sizeof(ulong)) xprint(f, (data[i]<<24)|(data[i+1]<<16)|(data[i+2]<<8)|data[i+3]); }
static void show_4d(const char *name, const char *part, struct QOP_MDWF_State *state, int v[]) { xprint("%p.%s.%s %5d %5d %5d %5d", state, name, part, v[0], v[1], v[2], v[3]); }
/* Signal handler */ static void vmct_signal_handler(int signum) { xprint(FMS_VMC | FMS_LOOKS, "Received Signal(%d)\n", signum); vmct_shutdown(); RunState = 0; }
static int SendVmProcStateRsp(int alist_idx, unsigned int systemid) { int i, TcpMsgLength; unsigned int system_addr; common_tcpmsg_t sndmsg; system_addr = alist[alist_idx].sysinfo.systemaddr; for (i = 0; i < MAX_SYSTEM_NUM; i++) { if (hostConf.vmc_system[i].systemaddr == system_addr) { hostConf.vmc_system[i].is_check = IS_CHECK_ON; hostConf.vmc_system[i].link_status = 0; break; } } if (i == MAX_SYSTEM_NUM) { xprint(FMS_HST | FMS_ERROR, "%s(%d) : System is Unknown.(= %s)\n", __func__, __LINE__, addr2ntoa(system_addr)); return -1; } sndmsg.TpktHdr = 0x00; sndmsg.SystemID = systemid; sndmsg.MsgType = VM_PROC_STATE_RSP; sndmsg.MsgSize = 0; TcpMsgLength = DEFAULT_TCP_COMHDR_LENGTH + sndmsg.MsgSize; TCP_MSG_HTON((common_tcpmsg_t *)&sndmsg); i = alist_idx; pthread_mutex_lock(&TcpMutex); if (alist[i].AcceptFD < 0) { xprint(FMS_HST | FMS_ERROR, "%s(%d) : recv fd lost.\n", __func__, __LINE__); } else { if (TcpSend(i, alist[i].AcceptFD, (unsigned char *)&sndmsg, TcpMsgLength) == TcpMsgLength) { xprint(FMS_HST | FMS_INFO3, "|-------->| VM_PROC_STATE_RSP msg send(len:%d) OK. systemid(%d : %s)\n", TcpMsgLength, systemid, alist[i].sysinfo.systemname); } else { xprint(FMS_HST | FMS_ERROR, "|---XXX-->| VM_PROC_STATE_RSP msg send Fail. systemid(%d : %s)\n", systemid, alist[i].sysinfo.systemname); } } pthread_mutex_unlock(&TcpMutex); return i; }
static void dump_state(struct QOP_MDWF_State *state) { int i; xprint("MDWF state at %p", state); xprint("allocate = %d", state->allocated); xprint("v2lx = %p", state->v2lx); xprint("volume = %d", state->volume); for (i = 0; i < state->volume; i++) { int x[4]; q(l2v)(x, &state->local, state->lx2v[i]); xprint(" u[%5d]: { %5d, %5d, %5d, %5d}", i, x[0], x[1], x[2], x[3]); } dump_eo("even", state, &state->even, &state->odd); dump_eo("odd", state, &state->odd, &state->even); }
static void TcpdSock_Event(int alist_idx, unsigned char *buf) { #if 0 int retval; common_tcpmsg_t *mpmsg = (common_tcpmsg_t *)buf; #if 0 xdump(FMS_HST | FMS_LOOKS, (unsigned char *)mpmsg, 20, "1111 TcpRecv "); xdump(FMS_HST | FMS_LOOKS, (unsigned char *)buf, NBO_NTOHS(mpmsg->MsgSize) + DEFAULT_TCP_COMHDR_LENGTH, "GUI RECV-1"); #endif TCP_MSG_NTOH(mpmsg); if (((mpmsg->MsgType > GUI_COMMAND_BASE) && (mpmsg->MsgType < GUI_REPORT_BASE)) || (mpmsg->MsgType == SYSTEM_INFO_REQ) || (mpmsg->MsgType == CCS_REGISTER_REQ) || (mpmsg->MsgType == DSG_REGISTER_REQ) || (mpmsg->MsgType == SDM_REGISTER_REQ) || (mpmsg->MsgType == CTS_REGISTER_REQ) || (mpmsg->MsgType == DBS_REGISTER_REQ) || (mpmsg->MsgType == SFM_REGISTER_REQ)) { retval = tcp_PutFifo(FIFO_TYPE_REGCTRL, mpmsg, alist_idx, (unsigned char *)(buf + DEFAULT_TCP_COMHDR_LENGTH)); } else { retval = tcp_PutFifo(FIFO_TYPE_ACTION, mpmsg, alist_idx, (unsigned char *)(buf + DEFAULT_TCP_COMHDR_LENGTH)); } if (retval < 0) { xprint(FMS_HST | FMS_ERROR, "%s(%d) : tcp_PutFifo failed.\n", __func__, __LINE__); } #else int retval; common_tcpmsg_t *mpmsg = (common_tcpmsg_t *)buf; TCP_MSG_NTOH(mpmsg); retval = tcp_PutFifo(mpmsg, alist_idx, (unsigned char *)(buf + DEFAULT_TCP_COMHDR_LENGTH)); if (retval < 0) { xprint(FMS_HST | FMS_ERROR, "%s(%d) : tcp_PutFifo failed.\n", __func__, __LINE__); } #endif return; }
static void uvc_gadget_events_process_control(struct uvc_gadget *gadget, uint8_t req, uint8_t cs, struct uvc_request_data *resp) { xprint(xLOGDBG, "control request (req %02x cs %02x)\n", req, cs); (void)gadget; (void)req; (void)cs; (void)resp; }
static void uvc_gadget_events_process_standard(struct uvc_gadget *gadget, struct usb_ctrlrequest *ctrl, struct uvc_request_data *resp) { xprint(xLOGDBG, "standard request\n"); (void)gadget; (void)ctrl; (void)resp; }
int matcher(char *action, Pattern *p, char *message, Resub *m) { if(matchpat(p, message, m)){ if(p->action != Lineoff) xprint(1, action, m); return 1; } return 0; }
static void dump_eo(const char *name, struct QOP_MDWF_State *state, struct eo_lattice *eo, struct eo_lattice *oe) { int i, d; xprint("%p.%s face %6d", state, name, eo->face_size); xprint("%p.%s body %6d", state, name, eo->body_size); xprint("%p.%s full %6d", state, name, eo->full_size); xprint("%p.%s neighbor %p", state, name, eo->neighbor); show_4d(name, "local.lo", state, eo->local->lo); show_4d(name, "local.hi", state, eo->local->hi); show_4d(name, "local.dx", state, eo->local->dx); show_4d(name, "down_snd", state, eo->send_down_size); show_4d(name, "down_rcv", state, eo->receive_down_size); show_4d(name, "up_snd", state, eo->send_up_size); show_4d(name, "up_rcv", state, eo->receive_up_size); for (i = 0; i < eo->full_size; i++) { int m, u_u; int x[4]; int f_u[4], f_d[4], u_d[4]; q(get_neighbor)(&m, f_u, &u_u, f_d, u_d, eo->neighbor, i); q(l2v)(x, eo->local, eo->lx2v[i]); xprint("%s.nb %5d {%5d, %5d, %5d, %5d}: %02x" " f. %5d %5d %5d %5d :: %5d," " b. %5d %5d %5d %5d :: %5d %5d %5d %5d", name, i, x[0], x[1], x[2], x[3], m, f_u[0], f_u[1], f_u[2], f_u[3], u_u, f_d[0], f_d[1], f_d[2], f_d[3], u_d[0], u_d[1], u_d[2], u_d[3]); } for (d = 0; d < 4; d++) { dump_down_send(name, d, state, oe, eo->send_down_size[d], eo->down_pack[d]); dump_up_send(name, d, state, oe, eo->send_up_size[d], eo->up_pack[d]); } }
int main(int argc, char *argv[]) { int i=0; char *endp; stor[i++] = 0; if (argc < 2) { puts("\aUsage: PI <number_of_digits>"); return(1); } n = strtol(argv[1], &endp, 10); if (NULL == (mf = Fcalloc((Size_T)(n + 3L), (Size_T)sizeof(long)))) memerr(1); if (NULL == (ms = Fcalloc((Size_T)(n + 3L), (Size_T)sizeof(long)))) memerr(2); printf("\nApproximation of PI to %ld digits\n", (long)n); cnt = 0; kf = 25; ks = 57121L; mf[1] = 1L; for (i = 2; i <= (int)n; i += 2) { mf[i] = -16L; mf[i+1] = 16L; } for (i = 1; i <= (int)n; i += 2) { ms[i] = -4L; ms[i+1] = 4L; } printf("\n 3."); while (cnt < n) { for (i = 0; ++i <= (int)n - (int)cnt; ) { mf[i] *= 10L; ms[i] *= 10L; } for (i =(int)(n - cnt + 1); --i >= 2; ) { temp = 2 * i - 1; shift(&mf[i - 1], &mf[i], temp - 2, temp * kf); shift(&ms[i - 1], &ms[i], temp - 2, temp * ks); } nd = 0; shift((long FAR *)&nd, &mf[1], 1L, 5L); shift((long FAR *)&nd, &ms[1], 1L, 239L); xprint(nd); } printf("\n\nCalculations Completed!\n"); Ffree(ms); Ffree(mf); return(0); }
static inline int v4l2_set_format(int fd, struct v4l2_format *fmt) { int ret; ret = xioctl(fd, VIDIOC_S_FMT, fmt); if (ret < 0) xprint(xLOGERR, "Unable to set format: %s\n", strerror(errno)); return ret; }
static inline int v4l2_request_buffer(int fd, struct v4l2_requestbuffers *rbuf) { int ret; unsigned int nbufs; nbufs = rbuf->count; ret = xioctl(fd, VIDIOC_REQBUFS, rbuf); if (ret < 0) xprint(xLOGERR, "Unable to send response: %s\n", strerror(errno)); if (rbuf->count != nbufs) { xprint(xLOGERR, "rbuf->count: %d nbufs: %d\n", rbuf->count, nbufs); ret = -1; } return ret; }
static inline int v4l2_stream_off(int fd, int type) { int ret; ret = xioctl(fd, VIDIOC_STREAMOFF, &type); if (ret < 0) xprint(xLOGERR, "Unable to stop video stream: %s\n", strerror(errno)); return ret; }
static inline int v4l2_query_buffer(int fd, struct v4l2_buffer *buf) { int ret; ret = xioctl(fd, VIDIOC_QUERYBUF, buf); if (ret < 0) xprint(xLOGERR, "Unable to query buffer: %s\n", strerror(errno)); return ret; }
static inline int v4l2_query_capture(int fd, struct v4l2_capability *cap) { int ret; ret = xioctl(fd, VIDIOC_QUERYCAP, cap); if (ret < 0) xprint(xLOGERR, "Unable to query capture: %s\n", strerror(errno)); return ret; }
static inline int v4l2_dequeue_event(int fd, struct v4l2_event *event) { int ret; ret = xioctl(fd, VIDIOC_DQEVENT, event); if (ret < 0) xprint(xLOGERR, "Unable to dequeue event: %s\n", strerror(errno)); return ret; }
static inline int uvc_send_response(int fd, struct uvc_request_data *resp) { int ret; ret = xioctl(fd, UVCIOC_SEND_RESPONSE, resp); if (ret < 0) xprint(xLOGERR, "Unable to send response: %s\n", strerror(errno)); return ret; }
static inline int v4l2_subscribe_event(int fd, struct v4l2_event_subscription *sub) { int ret; ret = xioctl(fd, VIDIOC_SUBSCRIBE_EVENT, sub); if (ret < 0) xprint(xLOGERR, "Unable to subscribe event: %s\n", strerror(errno)); return ret; }
/* * ioctrl wrapper */ static inline int v4l2_dequeue_buf(int fd, struct v4l2_buffer *buf) { int ret; ret = xioctl(fd, VIDIOC_DQBUF, buf); if (ret < 0) xprint(xLOGERR, "Unable to dequeue buffer: %s\n", strerror(errno)); return ret; }
static void vmct_shutdown(void) { int i; static unsigned char once = 0; if (once) { return; } else { once = 1; } /* socket fd close (HOST TCP - Client) */ pthread_mutex_lock(&TcpHostMutex); if (tlinkHOST.mode == LINK_MODE_CLIENT) { if (tlinkHOST.ListenFD > 0) { close(tlinkHOST.ListenFD); FD_CLR(tlinkHOST.ListenFD, &allsetHOST); tlinkHOST.ListenFD = -1; } } else if (tlinkHOST.mode == LINK_MODE_SERVER) { for (i = 0; i < MAX_LISTENQ; i++) { if (alist[i].AcceptFD > 0) { close(alist[i].AcceptFD); FD_CLR(alist[i].AcceptFD, &allsetHOST); alist[i].AcceptFD = -1; } } if (tlinkHOST.ListenFD > 0) { close(tlinkHOST.ListenFD); FD_CLR(tlinkHOST.ListenFD, &allsetHOST); tlinkHOST.ListenFD = -1; } } pthread_mutex_unlock(&TcpHostMutex); for (i = 0; i < MAX_PTASK; i++) { if (ThreadFlags[i] != TRUE) { continue; } ThreadAlive[i] = FALSE; xprint(FMS_VMC | FMS_LOOKS, "%s :: ThreadFlags(%d)\n", __func__, i); pthread_cancel(ThreadArray[i]); nanoSleep(10); } pthread_mutex_destroy(&TcpHostMutex); close_xprint(); terminateLog(); exit(0); }