static THD_FUNCTION(m3pyro_continuity_thd, arg) { (void)arg; while(true) { adcsample_t sampbuf[5]; adcStart(&ADCD1, NULL); msg_t result = adcConvert(&ADCD1, &adc_grp, sampbuf, 1); adcStop(&ADCD1); if(result != MSG_OK) { m3status_set_error(M3PYRO_COMPONENT_CONTINUITY, M3PYRO_ERROR_ADC); chThdSleepMilliseconds(500); continue; } uint8_t continuities[4]; continuities[0] = adc_to_resistance(sampbuf[0]); continuities[1] = adc_to_resistance(sampbuf[1]); continuities[2] = adc_to_resistance(sampbuf[2]); continuities[3] = adc_to_resistance(sampbuf[3]); can_send(CAN_MSG_ID_M3PYRO_CONTINUITY, false, continuities, sizeof(continuities)); uint8_t supply; supply = adc_to_voltage(sampbuf[4]); can_send(CAN_MSG_ID_M3PYRO_SUPPLY_STATUS, false, &supply, 1); m3status_set_ok(M3PYRO_COMPONENT_CONTINUITY); chThdSleepMilliseconds(500); } }
void main() { BYTE cpt_RB4; BYTE cpt_RB5; Command cmd; BYTE param; int run = 1; init(); cpt_RB4 = 0; cpt_RB5 = 0; avancement = 0; while(run) { if (1 == can_receive(&cmd, ¶m)) { switch (cmd) { case Avancer: avancer(param); break; case Reculer: reculer(param); break; case Degree: degree(); break; case Reset: run = 0; break; default: break; } } if(bouton_RB4_pressed()) { cpt_RB4++; can_send(BoutonRB4, cpt_RB4); } if(bouton_RB5_pressed()) { cpt_RB5++; can_send(BoutonRB5, cpt_RB5); } } }
/* msg_channel_flags() * * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC * say NOTICE must not auto reply * - pointer to source_p * - pointer to channel * - flags * - pointer to text to send * output - NONE * side effects - message given channel either chanop or voice */ static void msg_channel(int p_or_n, struct Client *source_p, struct Channel *chptr, unsigned int flags, const char *text) { unsigned int type = 0; const char *prefix = ""; if (flags & CHFL_VOICE) { type = CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE; prefix = "+"; } else if (flags & CHFL_HALFOP) { type = CHFL_CHANOP | CHFL_HALFOP; prefix = "%"; } else if (flags & CHFL_CHANOP) { type = CHFL_CHANOP; prefix = "@"; } /* Chanops and voiced can flood their own channel with impunity */ int ret = can_send(chptr, source_p, NULL, text, p_or_n == NOTICE); if (ret < 0) { if (ret == CAN_SEND_OPV || !flood_attack_channel(p_or_n, source_p, chptr)) sendto_channel_butone(source_p, source_p, chptr, type, "%s %s%s :%s", command[p_or_n], prefix, chptr->name, text); } else if (p_or_n != NOTICE) sendto_one_numeric(source_p, &me, ret, chptr->name, text); }
void command_reculer(void) { char buf[64]; int n, pic; printf("De combien de pas ? "); rs232_read_line(buf); n = atoi(buf); printf("Numero du pic ? (1 ou 2) "); rs232_read_line(buf); pic = atoi(buf); if(pic == 1) { if (avancement - n >= 0 && avancement - n < 256) { avancement -= n; } else { printf("Vous devez donner un nombre de pas permettant de rester entre 0 et 255. L'avancement actuel est déjà de %ld pas." NL, avancement); } led_afficher_int(avancement); } else if(pic == 2) { can_send(Reculer, n); } else { printf("Le numéro du pic choisi n'est pas valable" NL); } }
/* * m_quit * parv[0] = sender prefix * parv[1] = comment */ int m_quit(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) #ifdef TIDY_QUIT { buf[0] = '\0'; if ((parc > 1) && parv[1]) { if (strlen(parv[1]) > (MAX_QUIT_LENGTH - 2)) parv[1][MAX_QUIT_LENGTH - 2] = '\0'; /* Don't add quotes to a null message */ if (MyConnect(sptr) && *parv[1]) { strncpy_irc(buf, "\"", 2); strncat(buf, strip_colour(parv[1]), MAX_QUIT_LENGTH - 2); strncat(buf, "\"", 1); } else strncpy_irc(buf, parv[1], BUFSIZE); } sptr->flags |= FLAGS_NORMALEX; #ifdef ANTI_SPAM_EXIT_MESSAGE /* Your quit message is suppressed if: * * You haven't been connected to the server for long enough */ if( !IsServer(sptr) && MyConnect(sptr) && (sptr->firsttime + ANTI_SPAM_EXIT_MESSAGE_TIME) > CurrentTime) strcpy(buf, "Client Quit"); else if (MyConnect(sptr) && IsPerson(sptr)) { /* Or you are in a channel to which you cannot send */ struct SLink *chptr; for (chptr = sptr->user->channel; chptr; chptr = chptr->next) { if (can_send(sptr, chptr->value.chptr) != 0) { strcpy(buf, "Client Quit"); break; } } } #endif if (IsPerson(sptr)) { sendto_local_ops_flag(UMODE_CCONN, "Client exiting: %s (%s@%s) [%s] [%s] [%s]", sptr->name, sptr->username, sptr->host, #ifdef WINTRHAWK buf, #else (sptr->flags & FLAGS_NORMALEX) ? "Client Quit" : comment, #endif /* WINTRHAWK */ sptr->sockhost, sptr->servptr ? sptr->servptr->name : "<null>"); } return IsServer(sptr) ? 0 : exit_client(cptr, sptr, sptr, buf); }
int main(void) { int reg_spi; reg_spi = open("/root/spi_if",O_RDWR | O_FSYNC); // Open SPI Interface printf("reg_spi = %d\n", reg_spi); if (reg_spi > 0){ printf("spi_if open succeeded\n"); } else { printf ("Open failed.\n"); switch (errno) { case EACCES: printf ("Permission denied.\n"); break; case EMFILE: printf ("No file handle available.\n"); break; case ENOENT: printf ("File or path not found.\n"); break; default: printf ("Unknown error.\n"); break; } printf("Numero de error %d\n",errno); } CanMessage can; can.id=1; can.dlc=2; can.data[0]=0x10; can.data[1]=0xAA; mcp_init(reg_spi); can_send(reg_spi, &can); close(reg_spi); return 0; }
/* msg_channel() * * inputs - flag privmsg or notice * - pointer to command "PRIVMSG" or "NOTICE" * - pointer to source_p * - pointer to channel * output - NONE * side effects - message given channel */ static void msg_channel(int p_or_n, const char *command, struct Client *source_p, struct Channel *chptr, const char *text) { int result = 0; /* Chanops and voiced can flood their own channel with impunity */ if ((result = can_send(chptr, source_p, NULL, text)) < 0) { if (result == CAN_SEND_OPV || !flood_attack_channel(p_or_n, source_p, chptr)) sendto_channel_butone(source_p, source_p, chptr, 0, "%s %s :%s", command, chptr->name, text); } else { if (p_or_n != NOTICE) { if (result == ERR_NOCTRLSONCHAN) sendto_one_numeric(source_p, &me, ERR_NOCTRLSONCHAN, chptr->name, text); else if (result == ERR_NEEDREGGEDNICK) sendto_one_numeric(source_p, &me, ERR_NEEDREGGEDNICK, chptr->name); else sendto_one_numeric(source_p, &me, ERR_CANNOTSENDTOCHAN, chptr->name); } } }
/** Attempt to send data queued for a client. * @param[in] to Client to send data to. */ void send_queued(struct Client *to) { assert(0 != to); assert(0 != cli_local(to)); if (IsBlocked(to) || !can_send(to)) return; /* Don't bother */ while (MsgQLength(&(cli_sendQ(to))) > 0) { unsigned int len; if ((len = deliver_it(to, &(cli_sendQ(to))))) { msgq_delete(&(cli_sendQ(to)), len); cli_lastsq(to) = MsgQLength(&(cli_sendQ(to))) / 1024; if (IsBlocked(to)) { update_write(to); return; } } else { if (IsDead(to)) { char tmp[512]; sprintf(tmp,"Write error: %s", ((cli_sslerror(to)) ? (cli_sslerror(to)) : ((strerror(cli_error(to))) ? (strerror(cli_error(to))) : "Unknown error")) ); dead_link(to, tmp); } return; } } /* Ok, sendq is now empty... */ client_drop_sendq(cli_connect(to)); update_write(to); }
/* This is the function that we call periodically during the one second startup time to see if we have a bootloader request on the CAN Bus. */ uint8_t bload_check(void) { struct CanFrame frame; uint8_t result, channel, send_node; result = can_poll_int(); if(result & (1<<CAN_RX0IF)) { /* If the filters and masks are okay this should be a firware update command addressed to us. */ can_read(0, &frame); print_frame(frame); /* Debugging Stuff */ if(frame.data[0] == node_id && frame.data[1] == FIX_FIRMWARE && frame.data[2] == BL_VERIFY_LSB && frame.data[3] == BL_VERIFY_MSB) { /* Save the data from the frame that we need later. */ channel = frame.data[4]; send_node = frame.id & 0x0FF; /* Build success frame */ frame.id = FIX_NODE_SPECIFIC + node_id; frame.length = 3; frame.data[0] = send_node; frame.data[1] = FIX_FIRMWARE; frame.data[2] = 0x00; can_send(0, 3, frame); /* Jump to load firmware */ load_firmware(channel); /* We should never come back from here */ } } return 0; }
void command_degree(void) { char buf[64]; int pic; unsigned int rheo_val; printf("Numero du pic ? (1 ou 2) "); rs232_read_line(buf); pic = atoi(buf); if(pic == 1) { rheo_get_value(&rheo_val); printf("La valeur du potentiomètre du PIC 1 est %d."NL, rheo_val); } else if(pic == 2) { can_send(Degree, 0); } else { printf("Le numéro du PIC choisi n'est pas valable." NL); } }
/* part_one_client() * * inputs - pointer to server * - pointer to source client to remove * - char pointer of name of channel to remove from * output - none * side effects - remove ONE client given the channel name */ static void part_one_client(struct Client *client_p, struct Client *source_p, const char *name, char *reason) { struct Channel *chptr = NULL; struct Membership *ms = NULL; if ((chptr = hash_find_channel(name)) == NULL) { sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), me.name, source_p->name, name); return; } if ((ms = find_channel_link(source_p, chptr)) == NULL) { sendto_one(source_p, form_str(ERR_NOTONCHANNEL), me.name, source_p->name, name); return; } if (MyConnect(source_p) && !IsOper(source_p)) check_spambot_warning(source_p, NULL); /* * Remove user from the old channel (if any) * only allow /part reasons in -m chans */ if(msg_has_colors(reason) && (chptr->mode.mode & MODE_NOCOLOR)) reason = strip_color(reason); if (reason[0] && (!MyConnect(source_p) || ((can_send(chptr, source_p, ms) && (source_p->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < CurrentTime)))) { sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s :%s", ID(source_p), chptr->chname, reason); sendto_server(client_p, chptr, NOCAPS, CAP_TS6, ":%s PART %s :%s", source_p->name, chptr->chname, reason); sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s PART %s :%s", source_p->name, source_p->username, source_p->host, chptr->chname, reason); } else { sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s", ID(source_p), chptr->chname); sendto_server(client_p, chptr, NOCAPS, CAP_TS6, ":%s PART %s", source_p->name, chptr->chname); sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s PART %s", source_p->name, source_p->username, source_p->host, chptr->chname); } remove_user_from_channel(ms); }
static int raw_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t size) { struct sock *sk = sock->sk; struct raw_sock *ro = raw_sk(sk); struct sk_buff *skb; struct net_device *dev; int ifindex; int err; if (msg->msg_name) { struct sockaddr_can *addr = (struct sockaddr_can *)msg->msg_name; if (addr->can_family != AF_CAN) return -EINVAL; ifindex = addr->can_ifindex; } else ifindex = ro->ifindex; if (size != sizeof(struct can_frame)) return -EINVAL; dev = dev_get_by_index(&init_net, ifindex); if (!dev) return -ENXIO; skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT, &err); if (!skb) goto put_dev; err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size); if (err < 0) goto free_skb; err = sock_tx_timestamp(msg, sk, skb_tx(skb)); if (err < 0) goto free_skb; skb->dev = dev; skb->sk = sk; err = can_send(skb, ro->loopback); dev_put(dev); if (err) goto send_failed; return size; free_skb: kfree_skb(skb); put_dev: dev_put(dev); send_failed: return err; }
static int m_cycle(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { char *p, *name; char *s = LOCAL_COPY(parv[1]); struct Channel *chptr; struct membership *msptr; name = rb_strtok_r(s, ",", &p); /* Finish the flood grace period... */ if(MyClient(source_p) && !IsFloodDone(source_p)) flood_endgrace(source_p); while(name) { if((chptr = find_channel(name)) == NULL) { sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); return 0; } msptr = find_channel_membership(chptr, source_p); if(msptr == NULL) { sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); return 0; } if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) check_spambot_warning(source_p, NULL); if((is_any_op(msptr) || !MyConnect(source_p) || ((can_send(chptr, source_p, msptr) > 0 && (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) { sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s :Cycling", use_id(source_p), chptr->chname); sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :Cycling", source_p->name, source_p->username, source_p->host, chptr->chname); } else { sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s", use_id(source_p), chptr->chname); sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", source_p->name, source_p->username, source_p->host, chptr->chname); } remove_user_from_channel(msptr); chptr = NULL; msptr = NULL; name = rb_strtok_r(NULL, ",", &p); } user_join(client_p, source_p, parv[1], parc > 2 ? parv[2] : NULL); return 0; }
/* * part_one_client * * inputs - pointer to server * - pointer to source client to remove * - char pointer of name of channel to remove from * output - none * side effects - remove ONE client given the channel name */ static void part_one_client(struct Client *client_p, struct Client *source_p, char *name, char *reason) { struct Channel *chptr; struct membership *msptr; if((chptr = find_channel(name)) == NULL) { sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); return; } msptr = find_channel_membership(chptr, source_p); if(msptr == NULL) { sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); return; } if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) check_spambot_warning(source_p, NULL); /* * Remove user from the old channel (if any) * only allow /part reasons in -m chans */ if(reason[0] && (is_chanop(msptr) || !MyConnect(source_p) || ((can_send(chptr, source_p, msptr) > 0 && (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < CurrentTime)))) { sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s :%s", use_id(source_p), chptr->chname, reason); sendto_server(client_p, chptr, NOCAPS, CAP_TS6, ":%s PART %s :%s", source_p->name, chptr->chname, reason); sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", source_p->name, source_p->username, source_p->host, chptr->chname, reason); } else { sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s", use_id(source_p), chptr->chname); sendto_server(client_p, chptr, NOCAPS, CAP_TS6, ":%s PART %s", source_p->name, chptr->chname); sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", source_p->name, source_p->username, source_p->host, chptr->chname); } remove_user_from_channel(msptr); }
int main(void) { char c; uint8_t i; for (i = 0; i < 8; i++) msg.b[i] = i + 3; can_init(); DDRB = _BV(LED_PIN); uart_init(9600); while (1) { c = uart_getchar(); if (buffer_append(&buffer, c)) { buffer_split(&buffer); if (strncmp(buffer.b + 3, "GLL", 3) == 0) { msg.l[0] = dmmtoint(buffer.f[0], buffer.f[1]); msg.l[1] = dmmtoint(buffer.f[2], buffer.f[3]); can_send(0x201, msg.b, 8); } else if (strncmp(buffer.b + 3, "RMC", 3) == 0) { msg.l[0] = dmmtoint(buffer.f[2], buffer.f[3]); msg.l[1] = dmmtoint(buffer.f[4], buffer.f[5]); can_send(0x201, msg.b, 8); } else if (strncmp(buffer.b + 3, "HDT", 3) == 0) { msg.s[0] = atof(buffer.f[0]) * 100; can_send(0x202, msg.b, 2); } else if (strncmp(buffer.b + 3, "ROT", 3) == 0) { msg.s[0] = atof(buffer.f[0]) * 100; can_send(0x203, msg.b, 2); } else if (strncmp(buffer.b + 3, "VTG", 3) == 0) { msg.us[0] = atof(buffer.f[0]) * 100; msg.us[1] = atof(buffer.f[4]) * 100; if (*buffer.f[5] == 'M') msg.us[2] = 1000; else msg.us[2] = 1852; can_send(0x204, msg.b, 6); } else if (strncmp(buffer.b + 3, "DBT", 3) == 0) { msg.s[0] = atof(buffer.f[2]) * 100; can_send(0x205, msg.b, 2); } else if (strncmp(buffer.b + 3, "VBW", 3) == 0) { msg.s[0] = atof(buffer.f[0]) * 100; msg.s[1] = atof(buffer.f[1]) * 100; can_send(0x206, msg.b, 4); } else if (strncmp(buffer.b + 3, "MWV", 3) == 0) { msg.us[0] = atof(buffer.f[0]) * 100; msg.us[1] = atof(buffer.f[2]) * 100; if (*buffer.f[3] == 'M') msg.us[2] = 1000; else msg.us[2] = 1852; can_send(0x208, msg.b, 6); } } } }
static int raw_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t size) { struct sock *sk = sock->sk; struct raw_opt *ro = raw_sk(sk); struct sk_buff *skb; struct net_device *dev; int ifindex; int err; DBG("socket %p, sk %p\n", sock, sk); if (msg->msg_name) { struct sockaddr_can *addr = (struct sockaddr_can *)msg->msg_name; if (addr->can_family != AF_CAN) return -EINVAL; ifindex = addr->can_ifindex; } else ifindex = ro->ifindex; dev = dev_get_by_index(ifindex); if (!dev) { DBG("device %d not found\n", ifindex); return -ENXIO; } skb = alloc_skb(size, GFP_KERNEL); if (!skb) { dev_put(dev); return -ENOMEM; } err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size); if (err < 0) { kfree_skb(skb); dev_put(dev); return err; } skb->dev = dev; skb->sk = sk; DBG("sending skbuff to interface %d\n", ifindex); DBG_SKB(skb); err = can_send(skb, ro->loopback); dev_put(dev); if (err) return err; return size; }
void CFsAdapter::lookupForFsuipcChanges() { for(std::list<CAbstractOffsetFamily*>::iterator it = m_lstFamilies.begin(); it != m_lstFamilies.end(); it++) { if((*it)->dataHasChanged()) { (*it)->update(); can_event_msg_t msg = (*it)->transformToCanMessage(); can_send(msg); } } }
int altitude_send_changes(i2c_can_trans_t* trans, long* nextAlt) { can_event_msg_t msg; if(altitude_changes_lookup(trans, nextAlt) == 0) { memset(&msg, 0, sizeof(msg)); msg.id = trans->canId; *((long *)msg.data)=*nextAlt<<16; msg.length = 4; return can_send(msg); } return 0; }
/** Try to send a buffer to a client, queueing it if needed. * @param[in,out] to Client to send message to. * @param[in] buf Message to send. * @param[in] prio If non-zero, send as high priority. */ void send_buffer(struct Client* to, struct MsgBuf* buf, int prio) { assert(0 != to); assert(0 != buf); if (cli_from(to)) to = cli_from(to); if (!can_send(to)) /* * This socket has already been marked as dead */ return; if (MsgQLength(&(cli_sendQ(to))) > get_sendq(to)) { if (IsServer(to)) sendto_opmask(0, SNO_OLDSNO, "Max SendQ limit exceeded for %C: %zu > %zu", to, MsgQLength(&(cli_sendQ(to))), get_sendq(to)); dead_link(to, "Max sendQ exceeded"); return; } Debug((DEBUG_SEND, "Sending [%p] to %s", buf, cli_name(to))); #if defined(USE_SSL) if (cli_socket(to).s_ssl) prio = 0; #endif msgq_add(&(cli_sendQ(to)), buf, prio); client_add_sendq(cli_connect(to), &send_queues); update_write(to); /* * Update statistics. The following is slightly incorrect * because it counts messages even if queued, but bytes * only really sent. Queued bytes get updated in SendQueued. */ ++(cli_sendM(to)); ++(cli_sendM(&me)); /* * This little bit is to stop the sendQ from growing too large when * there is no need for it to. Thus we call send_queued() every time * 2k has been added to the queue since the last non-fatal write. * Also stops us from deliberately building a large sendQ and then * trying to flood that link with data (possible during the net * relinking done by servers with a large load). */ if (MsgQLength(&(cli_sendQ(to))) / 1024 > cli_lastsq(to)) send_queued(to); }
/* msg_channel_flags() * * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC * say NOTICE must not auto reply * - pointer to command, "PRIVMSG" or "NOTICE" * - pointer to source_p * - pointer to channel * - flags * - pointer to text to send * output - NONE * side effects - message given channel either chanop or voice */ static void msg_channel(int p_or_n, const char *command, struct Client *source_p, struct Channel *chptr, unsigned int flags, const char *text) { int result = 0; unsigned int type = 0; const char *prefix = ""; if (flags & CHFL_VOICE) { type = CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE; prefix = "+"; } else if (flags & CHFL_HALFOP) { type = CHFL_CHANOP | CHFL_HALFOP; prefix = "%"; } else if (flags & CHFL_CHANOP) { type = CHFL_CHANOP; prefix = "@"; } /* Chanops and voiced can flood their own channel with impunity */ if ((result = can_send(chptr, source_p, NULL, text)) < 0) { if (result == CAN_SEND_OPV || !flood_attack_channel(p_or_n, source_p, chptr)) sendto_channel_butone(source_p, source_p, chptr, type, "%s %s%s :%s", command, prefix, chptr->name, text); } else { if (p_or_n != NOTICE) { if (result == ERR_NOCTRLSONCHAN) sendto_one_numeric(source_p, &me, ERR_NOCTRLSONCHAN, chptr->name, text); else if (result == ERR_NOCTCP) sendto_one_numeric(source_p, &me, ERR_NOCTCP, chptr->name, text); else if (result == ERR_NEEDREGGEDNICK) sendto_one_numeric(source_p, &me, ERR_NEEDREGGEDNICK, chptr->name); else sendto_one_numeric(source_p, &me, ERR_CANNOTSENDTOCHAN, chptr->name); } } }
/* msg_channel() * * inputs - flag privmsg or notice * - pointer to command "PRIVMSG" or "NOTICE" * - pointer to client_p * - pointer to source_p * - pointer to channel * output - NONE * side effects - message given channel */ static void msg_channel(int p_or_n, const char *command, struct Client *client_p, struct Client *source_p, struct Channel *chptr, char *text) { int result; if(MyClient(source_p)) { /* idle time shouldnt be reset by notices --fl */ if(p_or_n != NOTICE) source_p->localClient->last = CurrentTime; } #ifndef STATIC_MODULES execute_callback(channel_message, source_p, chptr, text); #endif /* chanops and voiced can flood their own channel with impunity */ if((result = can_send(chptr, source_p, NULL, text, p_or_n)) > 0) { if(result == CAN_SEND_OPV || !flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) { sendto_channel_butone(client_p, source_p, chptr, command, ":%s", text); } } else { if(p_or_n != NOTICE) { if(result == CAN_SEND_NOREGNICK) sendto_one(source_p, form_str(ERR_NEEDREGGEDNICK), ID_or_name(&me, client_p), ID_or_name(source_p, client_p), chptr->chname, "speak in"); else if(result == CAN_SEND_NOCTRLS) sendto_one(source_p, form_str(ERR_NOCTRLSONCHAN), ID_or_name(&me, client_p), ID_or_name(source_p, client_p), chptr->chname, text); else if(result == CAN_SEND_NOCTCP) sendto_one(source_p, form_str(ERR_NOCTCP), ID_or_name(&me, client_p), ID_or_name(source_p, client_p), chptr->chname, "channel", text); else sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN), ID_or_name(&me, client_p), ID_or_name(source_p, client_p), chptr->chname); } } }
void ClientNetSocket::push_send(SendBuffer& buf) { if (!can_send()) { THROW("%s: unexpected send attempt for connection_id=%d (status = %d)", __FUNCTION__, _id, _status); } if (_fin_pending || _close_pending) { THROW("%s: unexpected send attempt for connection_id=% - shutdown send pending", __FUNCTION__, _id); } _send_messages.push_back(buf.ref()); send(); }
/* * part_one_client * * inputs - pointer to server * - pointer to source client to remove * - char pointer of name of channel to remove from * output - none * side effects - remove ONE client given the channel name */ static void part_one_client(struct Client *client_p, struct Client *source_p, char *name, char *reason) { struct Channel *chptr; struct membership *msptr; char reason2[BUFSIZE]; if((chptr = find_channel(name)) == NULL) { sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); return; } msptr = find_channel_membership(chptr, source_p); if(msptr == NULL) { sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); return; } if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) check_spambot_warning(source_p, NULL); /* * Remove user from the old channel (if any) * only allow /part reasons in -m chans */ if(reason[0] && (is_any_op(msptr) || !MyConnect(source_p) || ((can_send(chptr, source_p, msptr) > 0 && ConfigFileEntry.use_part_messages && (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) { if(chptr->mode.mode & MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr))) { rb_strlcpy(reason2, reason, BUFSIZE); strip_colour(reason2); reason = reason2; } sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s :%s", use_id(source_p), chptr->chname, reason); sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :\"%s\"", source_p->name, source_p->username, source_p->host, chptr->chname, reason); } else { sendto_server(client_p, chptr, CAP_TS6, NOCAPS, ":%s PART %s", use_id(source_p), chptr->chname); sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", source_p->name, source_p->username, source_p->host, chptr->chname); } remove_user_from_channel(msptr); }
int XSocket::send_n(const void* buf, int len, int timeout_ms) { if (m_sock == INVALID_SOCKET) return -1; if ((buf == NULL) || len <= 0) return 0; int sendsize = 0; do { if (!can_send(timeout_ms)) return sendsize; int ret = this->send((const char *)buf + sendsize, len - sendsize); if (ret < 0) return -1; sendsize += ret; } while(sendsize < len); assert(sendsize == len); return sendsize; }
void ClientNetSocket::on_event() { if (can_send()) { send(); } if (!during_send()) { if (_close_pending) { close_and_tell(); } else if (_fin_pending) { apply_guest_fin(); } } if (can_receive()) { receive(); } }
bool Traffic_source::send(void) { #ifdef DEBUG assert(can_send()); #endif pLink link = (pLink) get_sink(); pFlit a_flit = get_flit(); link->receive(a_flit); if ( a_flit->is_header() ) { // Mark the time at which the packet leaves the source queue pPacket current_packet = a_flit->get_packet(); current_packet->set_sent_time(net_clock.get_clock()); } // Congestion monitor if ( (src_monitoring) && (net_clock.get_clock() > param.warmup_period) ) { if (a_flit->is_tail()) { unsigned int prev = src_congestion_monitor.back(); src_congestion_monitor.push_back(net_clock.get_clock()); src_congestion_monitor.push_back(prev-packet_size); } // if (a_flit.. pPacket p = a_flit->get_packet(); int flit_type = 1; //assume header if (a_flit->is_tail()) flit_type = 3; //tail else if (!a_flit->is_header()) flit_type = 2; //body buffer_monitor.push_back(p->get_id()); buffer_monitor.push_back(a_flit->get_sequence_id()); buffer_monitor.push_back(flit_type); buffer_monitor.push_back(net_clock.get_clock()); buffer_monitor.push_back(0); buffer_monitor.push_back(p->get_src_position().x); buffer_monitor.push_back(p->get_src_position().y); buffer_monitor.push_back(p->get_dst_position().x); buffer_monitor.push_back(p->get_dst_position().y); buffer_monitor.push_back(buffer.get_num_of_flits()); } // Congestion monitor return true; }
/** * @brief Cherche un message à envoyer parmis les binds * * can_tx_periodique est appelée périodiquement et est chargée de trouver parmis les * binds actifs celui qui a dépassé sa période et d'envoyer le message * correspondant. * * @param signo Signal appelant la fonction (SIGALRM ici) */ static void can_tx_periodique(int signo) { struct timeval now; struct bind_tx * ptr_bind; struct can_frame cf; if(signo != SIGALRM) return; gettimeofday(&now, NULL); #ifdef DEBUG printf("TIC_TX %ld %ld\n", now.tv_sec, now.tv_usec); printf("Recherche Bind_TX actif : ID, ptr_mem, longueur, periode\n"); #endif /* Recherche Bind d'envoi actif */ for(ptr_bind = binds_tx; ptr_bind < ptr_bind_tx_max; ptr_bind++) { #ifdef DEBUG printf("Bind_Tx : %#x, %p, %d, %ld\n", ptr_bind->id, ptr_bind->pmem, ptr_bind->len, ptr_bind->period); #endif if( (unsigned)(1000*(now.tv_sec - ptr_bind->last_send.tv_sec) + (now.tv_usec - ptr_bind->last_send.tv_usec)/1000) >= (ptr_bind->period - DELTA_TIME)) { /* Trouvé*/ #ifdef DEBUG printf("MATCH_TX! %#x %ld %ld\n", ptr_bind->id, now.tv_sec, now.tv_usec); #endif /* Envoi message */ cf.can_id = ptr_bind->id; cf.can_dlc = ptr_bind->len; memcpy(cf.data, ptr_bind->pmem, ptr_bind->len); can_send(cf); memcpy(&(ptr_bind->last_send), &now, sizeof(struct timeval)); } } }
int fpga_send_changes(i2c_can_trans_t trans[], unsigned short length) { short i; int ret; can_event_msg_t msg; ret = 0; for(i = 0; i < length; ++i) { if(fpga_changes_lookup(trans+i) == 0) { memset(&msg, 0, sizeof(msg)); msg.id = trans[i].canId; memcpy(msg.data, trans[i].oldData, trans[i].dataLength); msg.length = trans[i].dataLength; ret = (can_send(msg) == -1) ? -1 : ret; } else { // printf("No changes on I2C nodes\n"); } } return ret; }
static bool publish_ids(const canmsg_t *service_msg, void *parg) { // we only accept a publish ids if the addressed node id is 0 or the node if if(service_msg->canas.node_id == 0 || service_msg->canas.node_id == node_id) { canmsg_t msg; ids_reply[0] = hardware_revision; ids_reply[1] = software_revision; can_send(create_can_msg_uint8_4(&msg, service_msg->id + 1, 0, ids_reply[0], ids_reply[1], ids_reply[2], ids_reply[3])); return true; } return false; }
/** * Send gresb realization */ int SendGresb::send(int interfaceNum, ECI_CTRL_MESSAGE *msg, bool isNeedShowMsg ) { int n; // int len; /** * FIXME: For clear warning ( interfaceNum, isNeedShowMsg) not used */ interfaceNum = 0; interfaceNum++; isNeedShowMsg = 0; isNeedShowMsg++; // if (len > 0) { if ( (n = can_send(sock, 1, 0, msg->u.sCanMessage.u.V0.dwMsgId, msg->u.sCanMessage.u.V0.uMsgInfo.Bits.dlc, msg->u.sCanMessage.u.V0.abData)) < 0) { qDebug()<<"Error writing socket: "; return -1; } else if (n == 0) { qDebug()<<"Remote side closed connection"; } // } return 0; }