static msg_t check_vector_missings(SEXP x, SEXP any_missing, SEXP all_missing) { if (!asFlag(any_missing, "any.missing") && any_missing_atomic(x)) return make_msg("Contains missing values"); if (!asFlag(all_missing, "all.missing") && all_missing_atomic(x)) return make_msg("Contains only missing values"); return MSGT; }
static msg_t check_names(SEXP nn, SEXP type, const char * what) { typedef enum { T_NAMED, T_UNIQUE, T_STRICT } name_t; const char * expected = asString(type, "names"); if (strcmp(expected, "unnamed") == 0) { if (isNull(nn)) return MSGT; return make_msg("%s must be unnamed, but has names", what); } name_t checks; if (strcmp(expected, "named") == 0) { checks = T_NAMED; } else if (strcmp(expected, "unique") == 0) { checks = T_UNIQUE; } else if (strcmp(expected, "strict") == 0) { checks = T_STRICT; } else { error("Unknown type '%s' to specify check for names. Supported are 'unnamed', 'named', 'unique' and 'strict'.", expected); } if (isNull(nn) || any_missing_string(nn) || !all_nchar(nn, 1)) return make_msg("%s must be named", what); if (checks >= T_UNIQUE) { if (any_duplicated(nn, FALSE) != 0) return make_msg("%s must be uniquely named", what); if (checks >= T_STRICT && !check_strict_names(nn)) return make_msg("%s must be named according to R's variable naming rules", what); } return MSGT; }
static msg_t check_matrix_dims(SEXP x, SEXP min_rows, SEXP min_cols, SEXP rows, SEXP cols) { if (!isNull(min_rows) || !isNull(rows)) { R_len_t xrows = get_nrows(x); if (!isNull(min_rows)) { R_len_t cmp = asCount(min_rows, "min.rows"); if (xrows < cmp) return make_msg("Must have at least %i rows, but has %i rows", cmp, xrows); } if (!isNull(rows)) { R_len_t cmp = asCount(rows, "rows"); if (xrows != cmp) return make_msg("Must have exactly %i rows, but has %i rows", cmp, xrows); } } if (!isNull(min_cols) || !isNull(cols)) { R_len_t xcols = get_ncols(x); if (!isNull(min_cols)) { R_len_t cmp = asCount(min_cols, "min.cols"); if (xcols < cmp) return make_msg("Must have at least %i cols, but has %i cols", cmp, xcols); } if (!isNull(cols)) { R_len_t cmp = asCount(cols, "cols"); if (xcols != cmp) return make_msg("Must have exactly %i cols, but has %i cols", cmp, xcols); } } return MSGT; }
void PingTalk::evtContTrans() { if(mode == MODE_UPLOAD){ uint8_t buf[raw_data_len]; ssize_t cc = read(fd_trans, buf, raw_data_len); char pkt[sizeof(MsgHeader)+max_data_len]; MsgHeader* msg = (MsgHeader*)pkt; size_t msgsiz; if(cc>0){ msgsiz = make_msg(msg, TYPE_FILE_DATA, mode_encrypted, buf, cc); postMsg(msg, msgsiz+sizeof(MsgHeader)); #ifdef LOGGING printf("pingtalk: continue uploading.\n"); #endif }else{ msgsiz = make_msg(msg, TYPE_FILE_FIN, mode_encrypted, buf, 0); postMsg(msg, msgsiz+sizeof(MsgHeader)); printf("pingtalk: uploading completed.\n"); close(fd_trans); fd_trans = 0; mode = MODE_TALK; } //usleep(10000); // prevent from packet loss } }
static msg_t check_storage(SEXP x, SEXP mode) { if (!isNull(mode)) { const char * const storage = asString(mode, "mode"); if (strcmp(storage, "logical") == 0) { if (!isLogical(x)) return make_msg("Must store logicals"); } else if (strcmp(storage, "integer") == 0) { if (!isInteger(x)) return make_msg("Must store integers"); } else if (strcmp(storage, "double") == 0) { if (!isReal(x)) return make_msg("Must store doubles"); } else if (strcmp(storage, "numeric") == 0) { if (!isStrictlyNumeric(x)) return make_msg("Must store numerics"); } else if (strcmp(storage, "complex") == 0) { if (!isComplex(x)) return make_msg("Must store complexs"); } else if (strcmp(storage, "character") == 0) { if (!isString(x)) return make_msg("Must store characters"); } else if (strcmp(storage, "list") == 0) { if (!isRList(x)) return make_msg("Must store a list"); } else if (strcmp(storage, "atomic") == 0) { if (!isVectorAtomic(x)) return make_msg("Must be atomic"); } else { error("Invalid argument 'mode'. Must be one of 'logical', 'integer', 'double', 'numeric', 'complex', 'character', 'list' or 'atomic'"); } } return MSGT; }
void *thread_start(void *arg) { TR_MQ *mq=((struct thread_data *)arg)->mq; int n_msgs=((struct thread_data *)arg)->n_msgs; useconds_t msg_dly=((struct thread_data *)arg)->msg_dly; const char *label=((struct thread_data *)arg)->label; while (n_msgs>=0) { usleep(msg_dly); tr_mq_add(mq, make_msg(label, n_msgs)); n_msgs--; } tr_mq_add(mq, make_msg(label, -9999)); return NULL; }
yaml_cast_exception::yaml_cast_exception( const class node& node, const std::string& msg) : yaml_exception(make_msg(msg.c_str(), node)), start_mark_(node.start_mark()), end_mark_(node.end_mark()) { }
u_int32 identify_hd ( ){ u_int16 hd_info_buf[256]; struct HD_MSG hd; hd.lba=0; hd.buf=hd_info_buf; hd.type=HD_IDENTIFY; make_msg(&msg_send,fs_pid,HD_DRIVER,HD_MSG_TYPE,BLOCK_NEED); msg_send.u.msg_hd=hd; u_int32 key=send(&msg_send,fs_pid); if(key==FALSE) return 0; else { memcpy8((u_int8*)(hd_info_buf+10),(u_int8*)hd_info.hd_no,20);//硬盘序列号 hd_info.hd_no[20]='\0'; hd_info.hd_type[40]='\0'; memcpy8((u_int8*)(hd_info_buf+27),(u_int8*)hd_info.hd_type,40);//型号 hd_info.sectorNum=*((u_int32*)(hd_info_buf+60)); hd_info.capabilities=*(hd_info_buf+49); hd_info.support_cmd=*(hd_info_buf+83); bmp_sect=((hd_info.sectorNum%4096)==0)?(hd_info.sectorNum/4096):(hd_info.sectorNum/4096+1); return TRUE; } }
Publisher::Publisher(std::string hostname, int port, std::string protocol, message_type_t msg_type):_context(1), _publisher(_context, ZMQ_PUB){ BOOST_LOG_TRIVIAL(info) << "Starting Publusher on port " << port; _publisher.bind(connect_name(protocol, hostname, port).c_str()); std::string msg = make_msg(msg_type); startThread(protocol, hostname, port+1, msg); }
static msg_t check_min_chars(SEXP x, SEXP min_chars) { if (!isNull(min_chars)) { R_xlen_t n = asCount(min_chars, "min.chars"); if (n > 0 && !all_nchar(x, n)) return make_msg("All elements must have at least %g characters", (double)n); } return MSGT; }
static msg_t check_vector_len(SEXP x, SEXP len, SEXP min_len, SEXP max_len) { if (!isNull(len)) { R_xlen_t n = asCount(len, "len"); if (xlength(x) != n) return make_msg("Must have length %g, but has length %g", (double)n, (double)xlength(x)); } if (!isNull(min_len)) { R_xlen_t n = asCount(min_len, "min.len"); if (xlength(x) < n) return make_msg("Must have length >= %g, but has length %g", (double)n, (double)xlength(x)); } if (!isNull(max_len)) { R_xlen_t n = asCount(max_len, "max.len"); if (xlength(x) > n) return make_msg("Must have length <= %g, but has length %g", (double)n, (double)xlength(x)); } return MSGT; }
/* * log_event * * This is how you send things to the logger so it can log them. * The id parameter must point to an array of at least SDC_MSG_ID_BYTES chars. * The data_length parameter must accurately represent the length of the array * pointed to by the data parameter, and this length must be no longer than * SDC_MSG_MAX_PAYLOAD_BYTES. The returned boolean indicates whether the event * was succesfully posted (true) or failed because the buffer of events to be * logged was full (false). */ bool log_event(const char* id, const uint8_t* data, uint16_t data_length) { msg_t status; GENERIC_message* msg = make_msg(id, data, data_length); if (msg == NULL) return false; status = chMBPost(&event_mail, (msg_t) msg, TIME_IMMEDIATE); return status == RDY_OK; }
static msg_t check_bounds(SEXP x, SEXP lower, SEXP upper) { double tmp; tmp = asNumber(lower, "lower"); if (R_FINITE(tmp)) { if (isReal(x)) { const double *xp = REAL(x); const double * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (!ISNAN(*xp) && *xp < tmp) return make_msg("All elements must be >= %g", tmp); } } else if (isInteger(x)) { const int *xp = INTEGER(x); const int * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (*xp != NA_INTEGER && *xp < tmp) return make_msg("All elements must be >= %g", tmp); } } } tmp = asNumber(upper, "upper"); if (R_FINITE(tmp)) { if (isReal(x)) { const double *xp = REAL(x); const double * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (!ISNAN(*xp) && *xp > tmp) return make_msg("All elements must be <= %g", tmp); } } else if (isInteger(x)) { const int *xp = INTEGER(x); const int * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (*xp != NA_INTEGER && *xp > tmp) return make_msg("All elements must be <= %g", tmp); } } } return MSGT; }
void PingTalk::evtStdin() { int cc; char buf[raw_data_len]; if(mode == MODE_TALK){ cc = read(0, buf, raw_data_len); buf[cc-1] = 0; if(strncmp(buf, "send ", 5)==0){ fd_trans = open(buf+5, O_RDONLY); if(fd_trans<0){ perror("pingtalk: open"); fd_trans = 0; return; } printf("rename? "); fflush(stdout); cc = read(0, buf, sizeof(buf)); buf[cc-1] = 0; char pkt[sizeof(MsgHeader)+max_data_len]; MsgHeader* msg = (MsgHeader*)pkt; size_t msgsiz = make_msg(msg, TYPE_FILE_START, mode_encrypted, buf, cc); postMsg(msg, msgsiz+sizeof(MsgHeader)); mode = MODE_UPLOAD; printf("pingtalk: start uploading.\n"); } else if(strcmp(buf, "base64")==0){ mode_encrypted = !mode_encrypted; printf("pingtalk: encryption is %s\n", (mode_encrypted?"ON":"OFF")); } else{ char pkt[sizeof(MsgHeader)+max_data_len]; MsgHeader* msg = (MsgHeader*)pkt; size_t msgsiz = make_msg(msg, TYPE_TEXT, mode_encrypted, buf, cc); postMsg(msg, msgsiz+sizeof(MsgHeader)); } } }
u_int32 write_sector (u_int32 lba,void*buf ){ struct HD_MSG hd; hd.lba=lba; hd.buf=buf; hd.type=HD_WRITE; make_msg(&msg_send,fs_pid,HD_DRIVER,HD_MSG_TYPE,BLOCK_NEED); msg_send.u.msg_hd=hd; u_int32 key=send(&msg_send,fs_pid); if(key==TRUE) return TRUE; else return FALSE; }
PUBLIC void IRQ14_ATDisk1 (void){ sendEOI_Slave (); sendEOI_Master (); u_int8 status=io_in8(REG_STATUS); /*此处应该加入对状态的错误与否来发送消息*/ struct MESSAGE msg; struct INT_MSG intMsg; intMsg.intNo=14; intMsg.status=status; make_msg(&msg,0,HD_DRIVER,INT_MSG_TYPE,BLOCK_NOT_NEED); msg.u.msg_int=intMsg; send_msg(&msg,0); }
PUBLIC void IRQ12_PS2Mouse1 (void){ u_int8 byte=io_in8(0x60); sendEOI_Slave (); sendEOI_Master (); if(mousePhase==0) { mousePhase=1; return; } if(mousePhase==1)/*循环缓冲区*/ { mouse_inPut_buf[mouse_write_pos++]=byte; mousePhase=2; if(mouse_write_pos==MAX_MOUSE_BUF) mouse_write_pos=0; return; } if(mousePhase==2) { mouse_inPut_buf[mouse_write_pos++]=byte; mousePhase=3; if(mouse_write_pos==MAX_MOUSE_BUF) mouse_write_pos=0; return; } if(mousePhase==3) { mouse_inPut_buf[mouse_write_pos++]=byte; mousePhase=1; if(mouse_write_pos==MAX_MOUSE_BUF) mouse_write_pos=0; /*收满3字节,向WINDOW服务发送鼠标移动消息*/ struct MESSAGE msg; struct INT_MSG intMsg; intMsg.intNo=12; intMsg.status=mouse_read_pos; make_msg(&msg,0,3,INT_MSG_TYPE,BLOCK_NOT_NEED); msg.u.msg_int=intMsg; send_msg(&msg,0); mouse_read_pos+=3; mouse_read_pos=mouse_read_pos%MAX_MOUSE_BUF; return; } //test //int i; //for(i=0;i<mouse_write_pos;i++) // drawNum(mouse_inPut_buf[i],16*((32*i)/1024),(i*32)%1024,0x3c,0x00); }
int register_client (unsigned int sock) { int result; char buf[MAX_MSGLEN]; make_msg (buf, CLIENT_REGISTER, "Client registering"); result = send (sock, buf, MAX_MSGLEN, 0); if (result == -1) { perror ("Client registering send"); return 0; } result = recv (sock, buf, MAX_MSGLEN, 0); if (result < 0) { perror ("Client registering recv"); return 0; } else if (result == 0) { printf ("The server closed the connection on us unexpectedly."); return 0; } else { char comment[MAX_MSGLEN]; int msg; parse_msg (buf, &msg, comment); if (msg == REGISTER_OK) { return 1; } else if (msg == TOO_MANY_CLIENTS) { printf ("Server reports too many clients, exiting.\n"); return 0; } } return 0; /* we should never reach this */ }
void make_cmd(t_env *e, int cs, char *line) { char *arg; arg = less_cmd(line); if (ft_verify_word(line, "/nick") == 0) check_name(e, cs, arg); else if (ft_verify_word(line, "/join") == 0) make_join(e, cs, arg); else if (ft_strcmp(line, "/leave") == 0) make_leave(e, cs, arg); else if (ft_strcmp(line, "/who") == 0) make_who(e, cs, arg); else if (ft_verify_word(line, "/msg") == 0) make_msg(e, cs, arg); else send(cs, "Wrong command.\0", 15, 0); }
static int do_sending(void) { unsigned i; if (!make_msg()) return stdin_eof ? STATE_EXITING : STATE_CONNECTED; /* Try to send the message packet multiple times. */ for (i = 1; !exitasap && i <= retransmits; ++i) { debugf(DEBUG_PACKET, "{Sending seq #}llu{ to #}llu", seq_send, seq_last); send_packet("MSG1", ack_timeout * i); while (!exitasap) { if (poll_both() == 0) { debug1(DEBUG_STATE, "Timed out waiting for ACK"); break; } if (stdin_ready) read_lines(); if (sock_ready && receive_ack()) return saw_seq_gap ? STATE_DISCONNECTED : STATE_SENDING; } } return STATE_DISCONNECTED; }
int match_message(char * msg,long size,int sock){ char type[5]; if(size<9||size>156){ write(out,"Message de taille incorrecte\n",strlen("Message de taille incorrecte\n")); } snprintf(type,5,"%s",msg); if(strcmp("MESS",type)==0){ if(size<15){ write(out,"Message de taille incorrecte(2)\n",strlen("Message de taille incorrecte(2)\n")); return 0; } char id[9],mess[141]; snprintf(id,9,"%s",(msg+5)); snprintf(mess, size-15,"%s",(msg+14)); add_msg(make_msg(id, "DIFF", mess)); char tmp[9]="ACKM\r\n"; tmp[8]='\0'; send(sock,tmp,9,0); }else if(strcmp("LAST",type)==0){ if(size!=10){ write(out,"Message de taille incorrecte(3)\n",strlen("Message de taille incorrecte(3)\n")); return 0; } int nb; if((nb=atoi((msg+5)))<0)return 2; post_old_msg(sock,nb); }else{ printf("Type non reconnu\n"); return 0; } return 1; }
static int scan_maildir(void) { long pos; long i; msg_bytes = 0; if (!str_truncate(&msg_filenames, 0)) return 0; msg_count = 0; if (!scan_dir("cur", &msg_filenames, &cur_count, max_cur_count)) return 0; if (!scan_dir("new", &msg_filenames, &new_count, max_new_count)) return 0; if (msg_count == 0) return 1; if (!str_sort(&msg_filenames, 0, -1, fn_compare)) return 0; del_count = 0; del_bytes = 0; if (msgs != 0) free(msgs); if ((msgs = malloc(msg_count * sizeof msgs[0])) == 0) return 0; for (i = pos = 0; i < msg_count; pos += strlen(msg_filenames.s+pos)+1, ++i) make_msg(&msgs[i], msg_filenames.s + pos); return 1; }
yaml_parse_exception::yaml_parse_exception( const char*& msg, const yaml_mark_t& mark) : yaml_exception(make_msg(msg, mark)), problem_mark_(mark) { }
main( int argc, char *argv[]) { int ret; char bipname[256]; int account_no = 16002; char hostname[256]; char *argbuf; if (argc != 2) { usage(); } argbuf = argv[1]; for (argbuf = argv[1]; *argbuf != NULL; argbuf++) { printf("argbuf is %c\n", *argbuf); if (!isdigit(*argbuf)) { usage(); } } account_no = atoi(argv[1]); printf("Processing account %d\n", account_no ); ret = ipc_comm_init(Bip_instname); if (ret < 0) { printf("Unable to init inst error %s\n", ipc_error(ret)); return 0; } #ifdef DATABASE /* * If we have a database, then we will lookup the list of output queues * using ipc_msg_queue_find. This routine takes an array of 10 names * and will fill 1 or more entries. If no entries can be filled, an error * is returned. */ { Ipc_msg_queue_array bip_output_queues; Arb_connection *dbp; int j; int array_size; /* NULL out the message queue name buffer */ array_size = sizeof(bip_output_queues)/sizeof(bip_output_queues[0]); for (j = 0; j < array_size; j++) { bip_output_queues[j][0] = '\0'; } /* Access the output data queue */ if (ipc_msg_queue_find(dbp, HOTINVOICING_BIP_CAT, bip_output_queues) != Success) { goto cleanup; } /* We only expect one queue, so just take that one */ strcpy(bipname, bip_output_queues[0]); } #else /* DATABASE */ sprintf(bipname, "@mila52d1:%s:bip01", &Bip_instname[1]); #endif /* DATABASE */ printf("About to access BIP queue %s\n", bipname); ret = ipc_msg_queue_access(&Bip_data_queue, bipname, 0); if (ret < 0) { printf("Unable to access queue %s error %s\n", bipname, ipc_error(ret)); goto cleanup; } printf("About to register message types\n"); /* Register bip input message */ ret = ipc_msg_type_register_simple(IPC_MSG_TYPE_BIP_GUI_INPUT, "BIP_GUI_INPUT_MSG"); if (ret < 0) { printf("Unable to register messagetype error %s\n", ipc_error(ret)); goto cleanup; } /* Register GUI report message */ ret = ipc_msg_type_register_simple(IPC_MSG_TYPE_HOTINV_GUI_REPORT, "HOTINV_GUI_REPORT_MSG"); if (ret < 0) { printf("Unable to register messagetype error %s\n", ipc_error(ret)); goto cleanup; } ret = gethostname(hostname, sizeof(hostname)); if (ret != 0) { return Failure; } /* * NOTE: Make sure to use the short name in rely queue creation. * i.e. use "gui01" to create or access when we know the queue * is local. When it is remote, we will use the full path name. * Using the full path to create the local queue will break * the naming convention. * * Also note that in creating the full path, we skip the @ before * the instance name, so we create the correct string: * "@bishop:HotInvoice:gui01" instead of the wrong string * "@bishop:@HotInvoice:gui01". */ sprintf(Gui_reply_queue_full_name, "@%s:%s:%s", hostname, &Bip_instname[1], Gui_reply_queue_name); /* Create the reply queue, if there is one already, then access it */ ret = ipc_msg_queue_create(&ReplyId, Gui_reply_queue_name, 0); if (ret < 0) { printf("Unable to create reply Q error %s try access\n", ipc_error(ret)); ret = ipc_msg_queue_access(&ReplyId, Gui_reply_queue_name, 0); if (ret < 0) { printf("Unable to access reply Q %s error %s\n", Gui_reply_queue_name, ipc_error(ret)); goto cleanup; } } /* Now make a message */ { BIP_GUI_INPUT_MSG omsg; HOTINV_GUI_REPORT_MSG imsg; printf("Posting a request for account %d\n", account_no); (void) make_msg(account_no, &omsg); if (send_msg(&omsg) < 0) { goto cleanup; } if (recv_msg(&imsg) < 0) { goto cleanup; } printf("Got reply for account %d received status %d\n", account_no, imsg.gui_status); } cleanup: ipc_comm_shutdown(); return 0; }
static msg_t check_vector_unique(SEXP x, SEXP unique) { if (asFlag(unique, "unique") && any_duplicated(x, FALSE) > 0) return make_msg("Contains duplicated values"); return MSGT; }
static msg_t check_vector_finite(SEXP x, SEXP finite) { if (asFlag(finite, "finite") && any_infinite(x)) return make_msg("Must be finite"); return MSGT; }
int main(int argc, char *argv[]) { int i; struct icmp6_filter filt; u_int hlim = 1; fd_set fdset; struct itimerval itimer; u_int type; int ch; type = MLD6_LISTENER_QUERY; while ((ch = getopt(argc, argv, "dr")) != -1) { switch (ch) { case 'd': type = MLD6_LISTENER_DONE; break; case 'r': type = MLD6_LISTENER_REPORT; break; default: usage(); /*NOTREACHED*/ } } argv += optind; argc -= optind; if (argc != 1 && argc != 2) usage(); ifindex = (u_short)if_nametoindex(argv[0]); if (ifindex == 0) usage(); if (argc == 2 && inet_pton(AF_INET6, argv[1], &maddr) != 1) usage(); if ((s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) err(1, "socket"); if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hlim, sizeof(hlim)) == -1) err(1, "setsockopt(IPV6_MULTICAST_HOPS)"); mreq.ipv6mr_multiaddr = any; mreq.ipv6mr_interface = ifindex; if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1) err(1, "setsockopt(IPV6_JOIN_GROUP)"); ICMP6_FILTER_SETBLOCKALL(&filt); ICMP6_FILTER_SETPASS(ICMP6_MEMBERSHIP_QUERY, &filt); ICMP6_FILTER_SETPASS(ICMP6_MEMBERSHIP_REPORT, &filt); ICMP6_FILTER_SETPASS(ICMP6_MEMBERSHIP_REDUCTION, &filt); if (setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, sizeof(filt)) < 0) err(1, "setsockopt(ICMP6_FILTER)"); make_msg(ifindex, &maddr, type); if (sendmsg(s, &m, 0) < 0) err(1, "sendmsg"); itimer.it_value.tv_sec = QUERY_RESPONSE_INTERVAL / 1000; itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_usec = 0; itimer.it_value.tv_usec = 0; signal(SIGALRM, quit); setitimer(ITIMER_REAL, &itimer, NULL); FD_ZERO(&fdset); for (;;) { FD_SET(s, &fdset); if ((i = select(s + 1, &fdset, NULL, NULL, NULL)) < 0) perror("select"); if (i == 0) continue; else dump(s); } }
cJSON *ft_orders_next_get(t_car_info *carInfo, t_order *orders) { cJSON *msg = NULL; t_order *ptr = NULL; int i; double newSpeed = 0; /* 0 to 1 values */ if (orders == NULL) return NULL; /* find order */ for (i = 0; i < MAX_ORDERS; ++i) { /* if current order is ok for : pos and status */ if (carInfo->pos + SEND_ORDER_OFFSET >= orders[i].pos && orders[i].status == ORDER_STATUS_ENABLED) { ptr = &orders[i]; ptr->status = ORDER_STATUS_SENDED; break; } } /* if order is found, handle it, else check speed */ /* speed or switch lane - default == speed */ if (ptr != NULL) { if (ptr->type == ORDER_TYPE_SWITCH) { if (ptr->switchDir == ORDER_SWITCH_RIGHT) msg = make_msg("switchLane", cJSON_CreateString("Right")), printf("\t\tswitch right"); else msg = make_msg("switchLane", cJSON_CreateString("Left")), printf("\t\tswitch left"); } else { carInfo->speedWanted = ptr->speed; /* big diff, extrem values -> 0 to 1 values */ if (ft_abs(carInfo->speedActual - carInfo->speedWanted) > SPEED_DIFF_EXTREM_VALUES) { if (carInfo->speedActual > carInfo->speedWanted) newSpeed = 0; else newSpeed = 1; } else newSpeed = carInfo->speedWanted/10; /* if the speed order has yet been sended */ if (carInfo->lastSpeedOrder == newSpeed) ; else { msg = throttle_msg(newSpeed); carInfo->lastSpeedOrder = newSpeed; printf("\t\t%.2f -> %.2f", newSpeed, carInfo->speedWanted/10); } } } /* check if order has been received */ if (msg == NULL) { if ((carInfo->speedOld <= carInfo->speedActual && carInfo->speedActual <= carInfo->lastSpeedOrder) || (carInfo->speedOld >= carInfo->speedActual && carInfo->speedActual >= carInfo->lastSpeedOrder)) ;/* order applyed */ else msg = throttle_msg(carInfo->lastSpeedOrder); } return msg; }
int main (int argc, char *argv[]) { unsigned int comm_server; /* WRITEME: check arguments */ /* establish the communications with the master */ comm_server = init_client (SOCKET_FILE); if (register_client(comm_server)) { int result; struct ping_req req; struct ping_ack ack; char pinginfo[MAX_MSGLEN]; char buf[MAX_MSGLEN]; int done = 0; /* here is where the processing goes */ /* example of requesting a ping */ strlcpy (req.host, "polar.bowdoin.edu", MAX_HOST); req.id = 0; /* assigned by server */ req.seq_no = 1; req.size = 64; make_ping_req (pinginfo, &req); make_msg (buf, SEND_PING, pinginfo); result = send (comm_server, buf, MAX_MSGLEN, 0); if (result == -1) { perror ("Sending ping request"); exit (1); } /* put a delay in here so that the server gets the ping reply before it gets/acknowledges the client-done */ sleep(3); /* example of sending client-done */ make_msg (buf, CLIENT_SIGNOFF, "Goodnight, Mrs Calabash"); result = send (comm_server, buf, MAX_MSGLEN, 0); if (result == -1) { perror ("Sending signoff request"); exit (1); } /* example of handling return messages */ /* NB: if we send one ping-request, we expect a ping-ack and a ping-reply. If we send a client signoff request, we expect a signoff-ok reply. In the example, we send a ping-request and a signoff-request; we expect a ping-ack, a ping-reply, and a signoff-ok. */ while (!done) { result = recv (comm_server, buf, MAX_MSGLEN, 0); if (result < 0) { perror ("Reading from server"); exit (1); } else if (result == 0) { printf ("The server closed the connection."); exit (1); } else { char info[MAX_MSGLEN]; int msg; printf ("Received from server: %s\n", buf); parse_msg (buf, &msg, info); switch (msg) { case PING_SENT: /* do nothing; the server is acknowledging the request */ break; case PING_RECD: parse_ping_ack (info, &ack); printf ("Ping packet %u from %s, size %u, returned " "in %u sec, %u usec\n", ack.seq_no, ack.host, ack.size, ack.d_sec, ack.d_usec); break; case SIGNOFF_OK: done = 1; break; } } } } close(comm_server); return 0; }
/* PROC_CMD -- Process a single command. */ static int proc_cmd (int samp, char *method, char *arg1, char *arg2, char *arg3, char *arg4) { register int i = 0, stat = 0; char *appName = NULL; char rstr[SZ_RESSTR], *sres = rstr; Map resp; if (debug) fprintf (stderr, "Proc_Cmd Method '%s' Args: '%s' '%s' '%s'\n", method,arg1,arg2,arg3); if (strcasecmp (method, "quit") == 0) { /* QUIT */ printf ("Quitting....\n\n"); if (sampShutdown (samp) != 0) fprintf (stderr, "Shutdown fails\n"); sampClose (samp); return (0); } else if (strcasecmp (method, "start") == 0) { /* START */ printf ("Starting SAMP interface .....\n"); sampStartup (samp); } else if (strcasecmp (method, "stop") == 0) { /* STOP */ printf ("Stopping SAMP interface .....\n"); sampShutdown (samp); } else if (strcasecmp (method, "help") == 0) { /* HELP */ help_summary (); } else if (strcasecmp (method, "listClient") == 0) { /* LISTCLIENT */ samp_listClients (samp); } else if (strcasecmp (method, "trace") == 0) { /* TRACE */ trace++; if (trace % 2) setenv ("XMLRPC_TRACE_XML", "1", 1); else unsetenv ("XMLRPC_TRACE_XML"); } else if (strcasecmp (method, "target") == 0) { /* TARGET */ appName = arg1; } else if (strcasecmp (method, "envSet") == 0) { /* ENVSET */ if (nscan < 4) { cmdUsage ("envSet appName keyw value"); } else { stat = samp_envSet (samp, arg1, arg2, arg3); print_result (samp, stat); } } else if (strcasecmp (method, "envGet") == 0) { /* ENVGET */ if (nscan < 3) { cmdUsage ("envGet appName keyw"); } else { char *v = samp_envGet (samp, arg1, arg2); if (v) printf ("OK '%s' = '%s'\n", arg2, v); else printf ("ERR '%s' not found\n", arg2); } ; } else if (strcasecmp (method, "paramSet") == 0) { /* PARAMSET */ if (nscan < 4) { cmdUsage ("envSet appName keyw value"); } else { stat = samp_paramSet (samp, arg1, arg2, arg3); print_result (samp, stat); } } else if (strcasecmp (method, "paramGet") == 0) { /* PARAMGET */ ; } else if (strcasecmp (method, "notify") == 0) { /* NOTIFY */ if (nscan < 3) { cmdUsage ("notify appName mtype"); } else { int msg = make_msg (arg2); samp_notify (samp, arg1, msg); print_result (samp, SAMP_OK); } } else if (strcasecmp (method, "notifyAll") == 0) { /* NOTIFYALL */ if (nscan < 2) { cmdUsage ("notifyAll mtype"); } else { int msg = make_msg (arg1); stat = samp_notifyAll (samp, msg); print_result (samp, stat); } } else if (strcasecmp (method, "call") == 0) { /* CALL */ if (nscan < 3) { cmdUsage ("call appName mtype"); } else { int msg = make_msg (arg2); char *id = samp_call (samp, arg1, "testTag", msg); fprintf (stderr, "msgId = '%s'\n", id); print_result (samp, stat); } } else if (strcasecmp (method, "callAll") == 0) { /* CALLALL */ if (nscan < 2) { cmdUsage ("callAll mtype"); } else { int msg = make_msg (arg1); stat = samp_callAll (samp, "allTag", msg); print_result (samp, stat); } } else if (strcasecmp (method, "callAndWait") == 0) { /* CALLANDWAIT*/ if (nscan < 3) { cmdUsage ("callAndWait appName mtype"); } else { int msg = make_msg (arg2); stat = samp_callAndWait (samp, arg1, "waitTag", msg); print_result (samp, stat); } } else if (strcasecmp (method, "Register") == 0) { /* REGISTER */ if (nscan < 3) { cmdUsage ("Register appName appDesc"); } else { if (samp_Register (samp) != OK) fprintf (stderr, "Registration fails\n"); else { registered = 1; fprintf (stderr, "Registration OK\n"); } } } else if (strcasecmp (method, "Unregister") == 0) { /* UNREGISTER */ if (samp == 0) { fprintf (stderr, "Samp Hub not connected\n"); } else { if (samp_UnRegister (samp) != OK) fprintf (stderr, "UnRegistration fails\n"); else { registered = 0; fprintf (stderr, "UnRegistration OK\n"); } } } else if (strcasecmp (method, "DeclareMetadata") == 0) { /* METADATA */ if (samp == 0) { fprintf (stderr, "Samp Hub not connected\n"); } else { if (samp_DeclareMetadata (samp) != OK) fprintf (stderr, "Metadata declaration fails\n"); else fprintf (stderr, "Metadata declaration OK\n"); } } else if (strcasecmp (method, "Ping") == 0) { /* PING */ if (nscan < 2) { cmdUsage ("Ping appName"); } else { if ((samp_Ping (samp, arg1)) < 0) fprintf (stderr, "%s responds w/ ERR\n", arg1); else fprintf (stderr, "%s responds OK [%d]\n", arg1, cmdNum++); } } else if (strcasecmp (method, "GetMetadata") == 0) { /* GETMETADATA */ if (nscan < 2) { cmdUsage ("GetMetadata appName"); } else { if ((resp = samp_GetMetadata (samp, arg1)) > 0) { xr_getStringFromStruct (resp, "samp.name", &sres); printf (" Name = '%s'\n", sres); xr_getStringFromStruct (resp, "author.name", &sres); printf (" Author = '%s'\n", sres); xr_getStringFromStruct (resp, "samp.description.text", &sres); printf (" Descr = '%s'\n", sres); xr_getStringFromStruct (resp, "samp.icon.url", &sres); printf ("IconURL = '%s'\n", sres); xr_getStringFromStruct (resp, "samp.documentation.url", &sres); printf (" DocURL = '%s'\n", sres); } } /* SUBSCRIPTIONS */ } else if (strcasecmp (method, "DeclareSubscriptions") == 0) { if ((samp_DeclareSubscriptions (samp)) < 0) fprintf (stderr, "DeclareSubscriptions responds w/ ERR\n"); else fprintf (stderr, "DeclareSubscriptions OK\n"); } else if (strcasecmp (method, "GetSubscriptions") == 0) { Map subs = (Map) 0; if ((subs = samp_GetSubscriptions (samp, arg1)) > 0) { /* Need xmlrpc_struct_read_member() to scan map names .... */ } /* CLIENTS */ } else if (strcasecmp (method, "GetRegisteredClients") == 0) { /* Print the list of registered clients. */ List clients = samp_GetRegisteredClients (samp); for (i=0; i < samp_listLen (clients); i++) printf ("%s\n", samp_getStringFromList (clients, i)); samp_freeList (clients); } else if (strcasecmp (method, "GetSubscribedClients") == 0) { if (nscan < 2) { cmdUsage ("GetSubscribedClients mtype"); } else { /* Print the list of clients subscribed to a specific mtype. */ List clients = samp_GetSubscribedClients (samp, arg1); for (i=0; i < samp_listLen (clients); i++) printf ("%s\n", samp_getStringFromList (clients, i)); samp_freeList (clients); } /* table.load.votable (url, [table-id], [name]) */ } else if (strcasecmp (method, "tableLoadVOTable") == 0) { if (nscan < 2) { cmdUsage ("tableLoadVOTable appName url [table-id] [name]"); } else { if (samp_tableLoadVOTable (samp, arg1, arg2, arg3, arg4) == SAMP_OK) printf ("OK\n"); else printf ("Error: '%s'\n", samp_getErr (samp)); } /* table.load.fits (url, [table-id], [name]) */ } else if (strcasecmp (method, "tableLoadFITS") == 0) { if (nscan < 2) { cmdUsage ("tableLoadFITS appName url [table-id] [name]"); } else { if (samp_tableLoadFITS (samp, arg1, arg2, arg3, arg4) == SAMP_OK) printf ("OK\n"); else printf ("Error: '%s'\n", samp_getErr (samp)); } /* table.highlight.row (table-id, url, (int) row) */ } else if (strcasecmp (method, "tableHighlightRow") == 0) { ; /* table.highlight.rowList (table-id, url, (List)row) */ } else if (strcasecmp (method, "tableSelectRowList") == 0) { ; /* image.load.fits (url, [table-id], [name]) */ } else if (strcasecmp (method, "imageLoadFits") == 0) { if (nscan < 2) { cmdUsage ("imageLoadFITS appName url [image-id] [name]"); } else { if (samp_imageLoadFITS (samp, arg1, arg2, arg3, arg4) == SAMP_OK) printf ("OK\n"); else printf ("Error: '%s'\n", samp_getErr (samp)); } /* coord.pointAt.sky ((float)ra, (float)dec) */ } else if (strcasecmp (method, "coordPointAtSky") == 0) { ; /* spectrum.load.ssa-generic (url, (Map)meta, [spectrum-id], [name]) */ } else if (strcasecmp (method, "specLoadSSAGeneric") == 0) { ; /* send (appName, mtype) */ } else if (strcasecmp (method, "send") == 0) { ; } else if (method[0]) fprintf (stderr, "Unknown command '%s'\n", method); return (0); }