int write_pan_packet(uint8_t *buf, int len) { int rv; pthread_mutex_lock(&pan_lock); rv = write_serial_packet(ser_src, buf, len); pthread_mutex_unlock(&pan_lock); return rv; }
int serial_send(int node, int op, const uint8_t *data, int len) { uint8_t buf[1 + SPACKET_SIZE + MFSMSG_SIZE]; memset(buf, 0, sizeof buf); tmsg_t *spacket_header, *msg; buf[0] = 0; spacket_header = new_tmsg(buf + 1, SPACKET_SIZE); spacket_header_dest_set(spacket_header, 0xffff); spacket_header_length_set(spacket_header, MFSMSG_SIZE); spacket_header_type_set(spacket_header, MFSMSG_AM_TYPE); msg = new_tmsg(buf + 1 + SPACKET_SIZE, MFSMSG_SIZE); mfsmsg_node_set(msg, node); mfsmsg_op_set(msg, op); if (len > MFS_DATA_SIZE) len = MFS_DATA_SIZE; set_data(msg, data, len); DEBUG_PACKET(buf); return (src_type == SRC_DEVICE) ? write_serial_packet(src_dev, buf, sizeof buf) : write_sf_packet(src_fd, buf, sizeof buf); }
void forward_packet(const void *packet, int len) { int ok = write_serial_packet(src, packet, len); packets_written++; if (ok < 0) exit(2); if (ok > 0) fprintf(stderr, "Note: write failed\n"); }
void send_packet(serial_source src, char **bytes, int count) { int i; unsigned char *packet; packet = malloc(count); if (!packet) exit(2); for (i = 0; i < count; i++) packet[i] = strtol(bytes[i], NULL, 0); fprintf(stderr, "Sending "); for (i = 0; i < count; i++) fprintf(stderr, " %02x", packet[i]); fprintf(stderr, "\n"); if (write_serial_packet(src, packet, count) == 0) printf("ack\n"); else printf("noack\n"); }