static int write_entry_to_dir(struct file_buffer *dir, char *name, int inode, int type) { struct lmfs_inode_entry *lp = (struct lmfs_inode_entry *)dir->inode_entry; char *buffer = dir->data_buffer + dir->data_pos; u32 *block_buffer = (u32 *)dir->block_buffer; u32 *inode_addr; struct lmfs_dir_entry *dent; if (dir->data_pos == 0) { /* flush data to the data block */ if (dir->data) flush_data(buffer, dir->data); dir->data = pop_block(); if (!dir->data) return -ENOSPC; memset(buffer, 0, 4096); if (dir->lvl1_pos == 0) { debug("allocate new lvl1 block\n"); if (dir->lvl1) flush_data((char *)block_buffer, dir->lvl1); dir->lvl1 = pop_block(); if (!dir->lvl1) return -ENOSPC; memset(block_buffer, 0, 4096); if (dir->lvl0_pos == 32) { return -ENOSPC; } else dir->lvl0_buf[dir->lvl0_pos] = dir->lvl1; } lp->block_nr++; block_buffer[dir->lvl1_pos] = dir->data; } dent = (struct lmfs_dir_entry *)buffer; strcpy(dent, name); dent->type = type; dent->inode_index = inode; dir->data_pos += 256; if (dir->data_pos == 4096) { dir->data_pos = 0; debug("write file entry, data pos is 4096\n"); dir->lvl1 ++; if (dir->lvl1 == 1024) { debug("write file entry, lvl1 pos is 1024\n"); dir->lvl1 = 0; } } lp->file_nr++; update_bitmap(dir); return 0; }
static int write_inode(struct file_buffer *fb) { struct lmfs_inode_entry *lp = (struct lmfs_inode_entry *)fb->inode_entry; char *data_buffer = fb->data_buffer; u32 *block_buffer = (u32 *)fb->block_buffer; int i; debug("write inode %d\n", fb->inode); lp->pos_in_lvl1 = fb->lvl1_pos; lp->pos_in_lvl0 = fb->lvl0_pos; /* fix me some conner case will block * data write to the file * should consider the fb->data_pos and the * fb->lvl1_pos. TBD later */ if (fb->data) flush_data(data_buffer, fb->data); debug("lvl1 %d buf[0] %d\n", fb->lvl1, block_buffer[0]); if (fb->lvl1) flush_data((char *)block_buffer, fb->lvl1); i = inode_to_sector(fb->inode); /* first copy the inode meta data, then copy the block info */ //memcpy(data_buffer, lp, sizeof(struct lmfs_inode_entry) - 64 * sizeof(u32)); //memcpy(data_buffer + 256, lp->lvl1_block, 256); write_sector((char *)lp, i); return 0; }
void Buddha::worker(uint64_t from, uint64_t to) { uint64_t filled = 0; std::vector<uint64_t> local_data(thread_vector_size_); std::size_t progress_local = 0; floating_type radius_sqr = radius_ * radius_; floating_type subpixel_width = 2 * radius_ / x_size_; floating_type subpixel_height = 2 * radius_ / y_size_; for (uint64_t sub_x = 0; sub_x < subpixel_resolution_; ++sub_x) { for (uint64_t sub_y = 0; sub_y < subpixel_resolution_; ++sub_y) { for (uint64_t i = from; i < to; ++i) { ++progress_local; if (filled + max_iterations_ >= thread_vector_size_) flush_data(local_data, filled); complex_type c = lin2complex(i); c.real(c.real() + sub_x * subpixel_width); c.imag(c.imag() + sub_y * subpixel_height); complex_type z = c; uint64_t pos = 0; if (mandelbrot_hint(c)) continue; while (z.real() * z.real() + z.imag() * z.imag() < radius_sqr && pos < max_iterations_) { // TODO: Possible optimization when computing abs(z)^2. uint64_t zpos = complex2lin(z); if (zpos < data_.size()) { local_data[filled + pos] = zpos; } z *= z; z += c; ++pos; } if (pos >= min_iterations_ && pos < max_iterations_) { filled += pos; } } if (progress_local > 10000) { progress_ += progress_local; progress_local = 0; } } } flush_data(local_data, filled); }
static void mv_mmap_info(Addr a, SizeT len, MV_MMapType type, int thread, const HChar *filename) { if (!clo_pipe) return; // Flush outstanding events to ensure consistent ordering. Avoid // calling this with 0 entries. if (theEntries) flush_data(); MV_Header header; header.myType = MV_MMAP; header.myMMap.myStart = a; header.myMMap.myEnd = a + len; header.myMMap.myType = type; header.myMMap.myThread = thread; if (!filename) filename = "\0"; header.myMMap.mySize = VG_(strlen)(filename)+1; // Include terminating '\0' VG_(write)(clo_pipe, &header, sizeof(MV_Header)); VG_(write)(clo_pipe, filename, header.myMMap.mySize); }
static void parse_input (FILE *fp) { char line[2000]; size_t length; unsigned int lineno = 0; while (fgets (line, sizeof (line), fp)) { lineno++; length = strlen (line); if (length && line[length - 1] == '\n') line[--length] = 0; else err ("line number %u too long or last line not terminated", lineno); if (length && line[length - 1] == '\r') line[--length] = 0; if (sniffusb) parse_line_sniffusb (line, lineno); else parse_line (line, lineno); } flush_data (); if (ferror (fp)) err ("error reading input at line %u: %s", lineno, strerror (errno)); }
void push_data(Types... args) { data_buffer.push_back(boost::tuple<Types...>(args...)); if(data_buffer.size() == buffer_size) { flush_data(false); } }
/** * Function to buffer data, and flush buffer according to buffering rules. * * @param[in] fctx - the filter data * @param[in] reader - the data reader * @param[in] nbytes - number of bytes to buffer * @return success or error status */ static ib_status_t buffer_data_chunk(ib_filter_ctx *fctx, TSIOBufferReader reader, int64_t nbytes) { ib_status_t rc = IB_OK; int64_t copied; if (fctx->buffering == IOBUF_DISCARD) { /* discard anything we have buffered */ if (fctx->buffered > 0) { TSIOBufferReaderConsume(fctx->reader, fctx->buffered); fctx->buffered = 0; } /* caller will mark input consumed, so do-nothing == discard */ return rc; } if ((fctx->buffering == IOBUF_BUFFER_FLUSHALL) && (fctx->buffered + nbytes > fctx->buf_limit)) { /* flush all old data before buffering new data */ rc = flush_data(fctx, -1, 0); } /* If buffering enabled, copy the chunk to our buffer */ /* It's only a refcount here */ copied = TSIOBufferCopy(fctx->buffer, reader, nbytes, 0); fctx->buffered += copied; if (fctx->buffering == IOBUF_NOBUF) { /* consume it all right now */ rc = flush_data(fctx, -1, 0); } else if ((fctx->buffering == IOBUF_BUFFER_FLUSHPART) && (fctx->buffered > fctx->buf_limit)) { /* flush just enough data to bring us within the limit */ rc = flush_data(fctx, fctx->buffered - fctx->buf_limit, 0); } /* Check buffer size vs policy in operation */ /* If we're over the limit, flush by passing to edit */ return rc; }
static inline void put_data(Addr addr, uint32 type, uint32 size) { if (theEntries >= theMaxEntries) flush_data(); // This same encoding is created with VEX IR in flushEventsIR(). type |= theThread; type |= size << MV_SizeShift; theBlock->myAddr[theEntries].myAddr = addr; theBlock->myAddr[theEntries].myType = type; theEntries++; }
int addbit_to_pid(pid_t pid, int bit) { t_clients *client; int len; if ((client = find_client(pid)) != NULL) { len = (client->bit_len / (sizeof(char) * 8)); if (len >= BLOCK_SIZE) { client->data[len] = '\0'; flush_data(client); } client->data[len] = ((client->data[len] << 1) | bit); ++client->bit_len; if ((client->bit_len % (sizeof(char) * 8)) == 0 && client->data[len] == '\0') flush_data(client); return (1); } return (0); }
/** * \brief Flushes the data for *all* exporters and ODIDs * * @param conf Plugin configuration data structure */ void flush_all_data(struct fastbit_config *conf) { std::map<std::string, std::map<uint32_t, od_info>*> *od_infos = conf->od_infos; std::map<std::string, std::map<uint32_t, od_info>*>::iterator exporter_it; std::map<uint32_t, od_info>::iterator odid_it; /* Iterate over all exporters and ODIDs and flush data */ for (exporter_it = od_infos->begin(); exporter_it != od_infos->end(); ++exporter_it) { for (odid_it = exporter_it->second->begin(); odid_it != exporter_it->second->end(); ++odid_it) { flush_data(conf, exporter_it->first, odid_it->first, &(odid_it->second.template_info)); } } }
static void collect_data (char *hexdata, const char *address, unsigned int lineno) { size_t length; int is_bi; char *s; unsigned int value; is_bi = (*address && address[1] == 'i'); if (databuffer.is_bi != is_bi || strcmp (databuffer.address, address)) flush_data (); databuffer.is_bi = is_bi; if (strlen (address) >= sizeof databuffer.address) die ("address field too long"); strcpy (databuffer.address, address); length = databuffer.count; for (s=hexdata; *s; s++ ) { if (ascii_isspace (*s)) continue; if (!hexdigitp (*s)) { err ("invalid hex digit in line %u - line skipped", lineno); break; } value = xtoi_1 (*s) * 16; s++; if (!hexdigitp (*s)) { err ("invalid hex digit in line %u - line skipped", lineno); break; } value += xtoi_1 (*s); if (length >= sizeof (databuffer.data)) { err ("too much data at line %u - can handle only up to % bytes", lineno, sizeof (databuffer.data)); break; } databuffer.data[length++] = value; } databuffer.count = length; }
int storage_close(void **config) { struct fastbit_config *conf = (struct fastbit_config *) (*config); std::map<std::string, std::map<uint32_t, od_info>*> *od_infos = conf->od_infos; std::map<std::string, std::map<uint32_t, od_info>*>::iterator exporter_it; std::map<uint32_t, od_info>::iterator odid_it; std::map<uint16_t, template_table*> *templates; std::map<uint16_t, template_table*>::iterator table; /* Iterate over all exporters and ODIDs, flush data and release templates */ for (exporter_it = od_infos->begin(); exporter_it != od_infos->end(); ++exporter_it) { for (odid_it = exporter_it->second->begin(); odid_it != exporter_it->second->end(); ++odid_it) { templates = &(odid_it->second.template_info); flush_data(conf, exporter_it->first, odid_it->first, templates); /* Free templates */ for (table = templates->begin(); table != templates->end(); table++) { delete (*table).second; } } delete (*exporter_it).second; } /* Tell index thread to terminate */ terminate = true; pthread_cond_signal(&conf->mutex_cond); MSG_INFO(msg_module, "Waiting for the index thread to finish"); if (pthread_join(conf->index_thread, NULL) != 0) { MSG_ERROR(msg_module, "pthread_join"); } MSG_INFO(msg_module, "Index thread finished"); /* Free config structure */ delete od_infos; delete conf->index_en_id; delete conf->dirs; delete conf; return 0; }
/*********************************************** FUNCTION NAME: diamond_send_back COMMENT: 1.send date back to pc ************************************************/ static void diamond_send_back(void *p_buff, u32 size) { u32 crc = CRC_INIT; u8 cmd[10] = {0}; u8 ack = 0; u8 send_counter = 0; while(1) { flush_data(); mtos_task_delay_ms(20); //send indicator cmd[0] = DM_INDICATOR1; //data packet start indicator1: '#' cmd[1] = DM_INDICATOR2; //data packet start indicator2: '*' send_data(cmd, 2); //send data send_data(p_buff, size); //send crc crc = crc_fast_calculate(CRC_MODE, CRC_INIT, p_buff, size); send_data((u8 *)&crc, 4); //send crc //get response if(SUCCESS == read_data(&ack, 1, 3000)) { if(ack == DM_RES_ACK) { break; } } send_counter++; if(send_counter > 5) { cmd_response(DM_RES_ERR, dm_status, DM_ERR_TIMEOUT); break; } } }
int store_packet(void *config, const struct ipfix_message *ipfix_msg, const struct ipfix_template_mgr *template_mgr) { (void) template_mgr; std::map<uint16_t, template_table*>::iterator table; struct fastbit_config *conf = (struct fastbit_config *) config; std::map<uint16_t, template_table*> *templates = NULL; std::map<uint16_t, template_table*> *old_templates = NULL; /* Templates to be removed */ std::map<std::string, std::map<uint32_t, od_info>*> *od_infos = conf->od_infos; std::map<std::string, std::map<uint32_t, od_info>*>::iterator exporter_it; std::map<uint32_t, od_info>::iterator odid_it; static int rcnt = 0; uint16_t template_id; uint32_t odid = ntohl(ipfix_msg->pkt_header->observation_domain_id); struct input_info_network *input = (struct input_info_network *) ipfix_msg->input_info; int rc_flows = 0; uint64_t rc_flows_sum = 0; char exporter_ip_addr_tmp[INET6_ADDRSTRLEN]; if (input->l3_proto == 6) { /* IPv6 */ ipv6_addr_non_canonical(exporter_ip_addr_tmp, &(input->src_addr.ipv6)); } else { /* IPv4 */ inet_ntop(AF_INET, &(input->src_addr.ipv4.s_addr), exporter_ip_addr_tmp, INET_ADDRSTRLEN); } /* Convert to C++ string for use in `od_infos` data structure */ std::string exporter_ip_addr (exporter_ip_addr_tmp); /* Find exporter in od_infos data structure */ if ((exporter_it = od_infos->find(exporter_ip_addr)) == od_infos->end()) { MSG_INFO(msg_module, "Received data for new exporter: %s", exporter_ip_addr.c_str()); /* Add new exporter to data structure */ std::map<uint32_t, od_info> *new_exporter = new std::map<uint32_t, od_info>; od_infos->insert(std::make_pair(exporter_ip_addr, new_exporter)); exporter_it = od_infos->find(exporter_ip_addr); } /* Find ODID in template_info data structure (under exporter) */ if ((odid_it = exporter_it->second->find(odid)) == exporter_it->second->end()) { MSG_INFO(msg_module, "Received new ODID for exporter %s: %u", exporter_ip_addr.c_str(), odid); /* Add new ODID to data structure (under exporter) */ od_info new_odid; new_odid.exporter_ip_addr = exporter_ip_addr; new_odid.path = generate_path(conf, exporter_ip_addr, odid); exporter_it->second->insert(std::make_pair(odid, new_odid)); odid_it = exporter_it->second->find(odid); } templates = &(odid_it->second.template_info); /* Process all datasets in message */ int i; for (i = 0 ; i < MSG_MAX_DATA_COUPLES && ipfix_msg->data_couple[i].data_set; i++) { if (ipfix_msg->data_couple[i].data_template == NULL) { /* Skip data couples without templates */ continue; } template_id = ipfix_msg->data_couple[i].data_template->template_id; /* If template (ID) is unknown, add it to the template map */ if ((table = templates->find(template_id)) == templates->end()) { MSG_DEBUG(msg_module, "Received new template: %hu", template_id); template_table *table_tmp = new template_table(template_id, conf->buff_size); if (table_tmp->parse_template(ipfix_msg->data_couple[i].data_template, conf) != 0) { /* Template cannot be parsed, skip data set */ delete table_tmp; continue; } templates->insert(std::pair<uint16_t, template_table*>(template_id, table_tmp)); table = templates->find(template_id); } else { /* Check template time. On reception of a new template it is crucial to rewrite the old one. */ if (ipfix_msg->data_couple[i].data_template->first_transmission > table->second->get_first_transmission()) { MSG_DEBUG(msg_module, "Received new template with already used template ID: %hu", template_id); /* Init map for old template if necessary */ if (old_templates == NULL) { old_templates = new std::map<uint16_t,template_table*>; } /* Store old template */ old_templates->insert(std::pair<uint16_t, template_table*>(table->first, table->second)); /* Flush data */ flush_data(conf, exporter_ip_addr, odid, old_templates); /* Remove rewritten template */ delete table->second; delete old_templates; old_templates = NULL; /* Remove old template from current list */ templates->erase(table); /* Add the new template */ template_table *table_tmp = new template_table(template_id, conf->buff_size); if (table_tmp->parse_template(ipfix_msg->data_couple[i].data_template, conf) != 0) { /* Template cannot be parsed; skip data set */ delete table_tmp; continue; } templates->insert(std::pair<uint16_t, template_table*>(template_id, table_tmp)); table = templates->find(template_id); /* New template was created; create new directory if necessary */ } } /* Check whether data has to be flushed before storing data record */ bool flush_records = conf->records_window > 0 && rcnt > conf->records_window; bool flush_time = false; time_t now; if (conf->time_window > 0) { time(&now); flush_time = difftime(now, conf->last_flush) > conf->time_window; } if (flush_records || flush_time) { /* Flush data for all exporters and ODIDs */ flush_all_data(conf); /* Time management differs between flush policies (records vs. time) */ if (flush_records) { time(&(conf->last_flush)); } else if (flush_time) { while (difftime(now, conf->last_flush) > conf->time_window) { conf->last_flush = conf->last_flush + conf->time_window; } } /* Update window name and path */ update_window_name(conf); odid_it->second.path = generate_path(conf, exporter_ip_addr, (*odid_it).first); rcnt = 0; conf->new_dir = true; } /* Store this data record */ rc_flows = (*table).second->store(ipfix_msg->data_couple[i].data_set, odid_it->second.path, conf->new_dir); if (rc_flows >= 0) { rc_flows_sum += rc_flows; rcnt += rc_flows; } else { /* No need for showing error message here, since it is already done * by store() in case of an error */ // MSG_ERROR(msg_module, "An error occurred during FastBit table store; no records were stored"); } } /* We've told all tables that the directory has changed */ conf->new_dir = false; if (rc_flows_sum) { odid_it->second.flow_watch.add_flows(rc_flows_sum); } odid_it->second.flow_watch.update_seq_no(ntohl(ipfix_msg->pkt_header->sequence_number)); return 0; }
static void parse_line_sniffusb (char *line, unsigned int lineno) { char *p; if (debug) printf ("line[%u] ='%s'\n", lineno, line); p = strtok (line, " \t"); if (!p) return; p = strtok (NULL, " \t"); if (!p) return; p = strtok (NULL, " \t"); if (!p) return; if (hexdigitp (p[0]) && hexdigitp (p[1]) && hexdigitp (p[2]) && hexdigitp (p[3]) && p[4] == ':' && !p[5]) { size_t length; unsigned int value; length = databuffer.count; while ((p=strtok (NULL, " \t"))) { if (!hexdigitp (p[0]) || !hexdigitp (p[1])) { err ("invalid hex digit in line %u (%s)", lineno,p); break; } value = xtoi_1 (p[0]) * 16 + xtoi_1 (p[1]); if (length >= sizeof (databuffer.data)) { err ("too much data at line %u - can handle only up to % bytes", lineno, sizeof (databuffer.data)); break; } databuffer.data[length++] = value; } databuffer.count = length; } else if (!strcmp (p, "TransferFlags")) { flush_data (); *databuffer.address = 0; while ((p=strtok (NULL, " \t(,)"))) { if (!strcmp (p, "USBD_TRANSFER_DIRECTION_IN")) { databuffer.is_bi = 1; break; } else if (!strcmp (p, "USBD_TRANSFER_DIRECTION_OUT")) { databuffer.is_bi = 0; break; } } } }
static int write_file(int file, struct file_buffer *bfile) { struct lmfs_inode_entry *lp = (struct lmfs_inode_entry *)bfile->inode_entry; char *data_buffer = bfile->data_buffer + bfile->data_pos; u32 *block_buffer = (u32 *)bfile->block_buffer; int i; int read_size = 0; do { if (bfile->data_pos == 0) { /* flush data to the data block */ if (bfile->data) flush_data(data_buffer, bfile->data); bfile->data = pop_block(); if (!bfile->data) return -ENOSPC; memset(data_buffer, 0, 4096); if (bfile->lvl1_pos == 0) { if (bfile->lvl1) flush_data((char *)block_buffer, bfile->lvl1); bfile->lvl1 = pop_block(); debug("allocate new lvl1 block in write file\n"); if (!bfile->lvl1) return -ENOSPC; memset(block_buffer, 0, 4096); if (bfile->lvl0_pos == 32) { return -ENOSPC; } else bfile->lvl0_buf[bfile->lvl0_pos] = bfile->lvl1; } lp->block_nr ++; block_buffer[bfile->lvl1_pos] = bfile->data; } read_size = read(file, data_buffer, 4096); debug("read size is %d\n", read_size); if (read_size > 0) { bfile->data_pos += read_size; if (bfile->data_pos == 4096) { bfile->data_pos = 0; bfile->lvl1_pos++; if (bfile->lvl1_pos == 1024) { bfile->lvl1_pos = 0; bfile->lvl0_pos++; } } lp->size += read_size; debug("lp->size is %d\n", lp->size); if (read_size < 4096) break; } else break; } while (read_size == 4096); write_inode(bfile); return 0; }
~SQLiteInsertor() { flush_data(true); }
//format:id + len + block_id + zipflag + size + crc (for all data) // zipflag = 'Z': zipped data(only available for upg all, block_id = 0xFF), // zipfleg = other char, normal data static void cmd_handle_transfer() { u32 i = 0, id, index = 0, crc = CRC_INIT, zip = 0, tcrc = 0, seq = 0, seqtmp = 0; u32 total = 0, got = 0, len = 0; u8 *buff = (u8 *)(upg_cfg.flash_map_start); u8 *p = NULL; u8 start[10] = {0, }; if(TRUE == upg_cfg.upg_all_flag) //update all flash data { if(P2P_CMD_UPG_ALL != cmd_buff[2]) { cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_UPGALL_ID_ERR); return; } total = get_dword(&cmd_buff[4]); if(total > upg_cfg.upg_all_size) { cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_UPGALL_LEN_ERR); return; } zip = ('Z' == cmd_buff[3]) ? 1 : 0; //check if zipped data if(zip) //if zipped data, store to bk place first. { upg_cfg.data_bk_start = upg_cfg.flash_map_start + upg_cfg.upg_all_size + 100 * 1024; buff = (u8 *)upg_cfg.data_bk_start; } } else //update blocks { id = cmd_buff[2]; if('Z' == cmd_buff[3]) //not support zipped block data { cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_ZIPPED_FOR_BLOCK); return; } total = get_dword(&cmd_buff[4]); //OS_PRINTK("total =%x\n",total); //check if size right with prev stored info if(BOOTLOADER_BLOCK_ID == id) { index = 0xFF; //do not check total crc below for bootloader } else { for(i = 0; i < slave_info.block_num; i++) { if(slave_info.blocks[i].id == id) { if(slave_info.blocks[i].size != total) //check if the size is the same as informed bofore { cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_BLOCK_LEN_ERR); return; } else //record the block index for total crc check later { if(flash_mapping_type == 2) { //find the block start addr buff += (slave_info.blocks[i].base_addr + slave_info.dmh_start_addr); } else { buff += slave_info.blocks[i].base_addr; //find the block start addr } index = i; break; } } } } if(i >= slave_info.block_num) { cmd_response(CMD_ERROR, P2P_CMD_TRANSFER, CMD_TRANS_ID_NOT_EXIST); return; } } cmd_response(CMD_OK, 0, 0); // respond command p = buff; got = 0; //actual got bytes flush_data(); seq = 0; //record data packet sequence while(got < total) { len = (total - got > P2P_PACKET_SIZE) ? P2P_PACKET_SIZE : total - got; //get packet start indicator start[0] = 0; //start indecator 1 start[1] = 0; //start indecator 2 start[2] = 0; //sequence high byte start[3] = 0; //sequence low byte if((SUCCESS != read_data(start, 4, 1000)) || (P2P_START_INDICATOR != start[0]) || (P2P_START_INDICATOR2 != start[1])) { continue; } //seq in slave should always >= seqs in master, //becasue master never trans a new packet before acked! seqtmp = (start[2] << 8 | start[3]); if(seqtmp != seq) { if(seqtmp == (seq - 1)) //the ack is lost { read_data(p, len + 4, 1000); cmd_response(CMD_ACK, (seq >> 8) & 0xFF, seq & 0xff); //ack the sequence continue; } else //not the start indicator, but the data { read_data(p, len + 4, 1000); continue; } }
static GstBuffer * gst_rtp_qdm2_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstRtpQDM2Depay *rtpqdm2depay; GstBuffer *outbuf; guint16 seq; rtpqdm2depay = GST_RTP_QDM2_DEPAY (depayload); { gint payload_len; guint8 *payload; guint avail; guint pos = 0; payload_len = gst_rtp_buffer_get_payload_len (buf); if (payload_len < 3) goto bad_packet; payload = gst_rtp_buffer_get_payload (buf); seq = gst_rtp_buffer_get_seq (buf); if (G_UNLIKELY (seq != rtpqdm2depay->nextseq)) { GST_DEBUG ("GAP in sequence number, Resetting data !"); /* Flush previous data */ flush_data (rtpqdm2depay); /* And store new timestamp */ rtpqdm2depay->ptimestamp = rtpqdm2depay->timestamp; rtpqdm2depay->timestamp = GST_BUFFER_TIMESTAMP (buf); /* And that previous data will be pushed at the bottom */ } rtpqdm2depay->nextseq = seq + 1; GST_DEBUG ("Payload size %d 0x%x sequence:%d", payload_len, payload_len, seq); GST_MEMDUMP ("Incoming payload", payload, payload_len); while (pos < payload_len) { switch (payload[pos]) { case 0x80:{ GST_DEBUG ("Unrecognized 0x80 marker, skipping 12 bytes"); pos += 12; } break; case 0xff: /* HEADERS */ GST_DEBUG ("Headers"); /* Store the incoming timestamp */ rtpqdm2depay->ptimestamp = rtpqdm2depay->timestamp; rtpqdm2depay->timestamp = GST_BUFFER_TIMESTAMP (buf); /* flush the internal data if needed */ flush_data (rtpqdm2depay); if (G_UNLIKELY (!rtpqdm2depay->configured)) { guint8 *ourdata; GstBuffer *codecdata; GstCaps *caps; /* First bytes are unknown */ GST_MEMDUMP ("Header", payload + pos, 32); ourdata = payload + pos + 10; pos += 10; rtpqdm2depay->channs = GST_READ_UINT32_BE (payload + pos + 4); rtpqdm2depay->samplerate = GST_READ_UINT32_BE (payload + pos + 8); rtpqdm2depay->bitrate = GST_READ_UINT32_BE (payload + pos + 12); rtpqdm2depay->blocksize = GST_READ_UINT32_BE (payload + pos + 16); rtpqdm2depay->framesize = GST_READ_UINT32_BE (payload + pos + 20); rtpqdm2depay->packetsize = GST_READ_UINT32_BE (payload + pos + 24); /* 16 bit empty block (0x02 0x00) */ pos += 30; GST_DEBUG ("channs:%d, samplerate:%d, bitrate:%d, blocksize:%d, framesize:%d, packetsize:%d", rtpqdm2depay->channs, rtpqdm2depay->samplerate, rtpqdm2depay->bitrate, rtpqdm2depay->blocksize, rtpqdm2depay->framesize, rtpqdm2depay->packetsize); /* Caps */ codecdata = gst_buffer_new_and_alloc (48); memcpy (GST_BUFFER_DATA (codecdata), headheader, 20); memcpy (GST_BUFFER_DATA (codecdata) + 20, ourdata, 28); caps = gst_caps_new_simple ("audio/x-qdm2", "samplesize", G_TYPE_INT, 16, "rate", G_TYPE_INT, rtpqdm2depay->samplerate, "channels", G_TYPE_INT, rtpqdm2depay->channs, "codec_data", GST_TYPE_BUFFER, codecdata, NULL); gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), caps); gst_caps_unref (caps); rtpqdm2depay->configured = TRUE; } else { GST_DEBUG ("Already configured, skipping headers"); pos += 40; } break; default:{ /* Shuffled packet contents */ guint packetid = payload[pos++]; guint packettype = payload[pos++]; guint packlen = payload[pos++]; guint hsize = 2; GST_DEBUG ("Packet id:%d, type:0x%x, len:%d", packetid, packettype, packlen); /* Packets bigger than 0xff bytes have a type with the high bit set */ if (G_UNLIKELY (packettype & 0x80)) { packettype &= 0x7f; packlen <<= 8; packlen |= payload[pos++]; hsize = 3; GST_DEBUG ("Packet id:%d, type:0x%x, len:%d", packetid, packettype, packlen); } if (packettype > 0x7f) { GST_ERROR ("HOUSTON WE HAVE A PROBLEM !!!!"); } add_packet (rtpqdm2depay, packetid, packlen + hsize, payload + pos - hsize); pos += packlen; } } } GST_DEBUG ("final pos %d", pos); avail = gst_adapter_available (rtpqdm2depay->adapter); if (G_UNLIKELY (avail)) { GST_DEBUG ("Pushing out %d bytes of collected data", avail); outbuf = gst_adapter_take_buffer (rtpqdm2depay->adapter, avail); GST_BUFFER_TIMESTAMP (outbuf) = rtpqdm2depay->ptimestamp; GST_DEBUG ("Outgoing buffer timestamp %" GST_TIME_FORMAT, GST_TIME_ARGS (rtpqdm2depay->ptimestamp)); return outbuf; } } return NULL; /* ERRORS */ bad_packet: { GST_ELEMENT_WARNING (rtpqdm2depay, STREAM, DECODE, (NULL), ("Packet was too short")); return NULL; } }
/** * Process data from ATS. * * Process data from one of the ATS events. * * @param[in,out] contp - the continuation * @param[in,out] ibd - the filter descriptor */ static void process_data(TSCont contp, ibd_ctx *ibd) { int64_t ntodo; int64_t navail; TSIOBufferReader input_reader, output_reader; TSIOBufferBlock block; const char *buf; int64_t nbytes; ib_status_t rc; tsib_filter_ctx *fctx = ibd->data; tsib_txn_ctx *txndata = TSContDataGet(contp); TSVIO input_vio = TSVConnWriteVIOGet(contp); TSIOBuffer in_buf = TSVIOBufferGet(input_vio); /* Test whether we're going into an errordoc */ if (HTTP_CODE(txndata->status)) { /* We're going to an error document, * so we discard all this data */ ib_log_debug2_tx(txndata->tx, "Status is %d, discarding", txndata->status); ibd->data->buffering = IOBUF_DISCARD; } /* Test for EOS */ if (in_buf == NULL) { if (fctx->output_buffer != NULL) { /* flush anything we have buffered. This is final! */ rc = flush_data(fctx, -1, 1); switch(rc) { case IB_OK: break; case IB_EBADVAL: ib_log_error_tx(txndata->tx, "Bad/Inconsistent stream edit(s) ignored."); break; default: /* Can't happen unless a new status is introduced */ ib_log_error_tx(txndata->tx, "Unhandled return value %d", rc); break; } } else { /* I guess NULL input may mean something other than EOS. * This appears to be possible when * processing an HTTP error from the backend. */ ib_log_debug2_tx(txndata->tx, "Filter input was null. No filtering."); /* RNS-1268: seems we may have to go through all the motions * of creating and enabling an output_vio with no data. */ fctx->output_buffer = TSIOBufferCreate(); ib_mm_register_cleanup(txndata->tx->mm, (ib_mm_cleanup_fn_t) TSIOBufferDestroy, (void*) fctx->output_buffer); output_reader = TSIOBufferReaderAlloc(fctx->output_buffer); fctx->output_vio = TSVConnWrite(TSTransformOutputVConnGet(contp), contp, output_reader, 0); TSVIOReenable(fctx->output_vio); } return; } /* Test for first time, and initialise. */ if (!fctx->output_buffer) { // FIXME - What to choose here and why? int64_t output_vio_sz = TSVIONBytesGet(input_vio); // NOTE: Using INT64_MAX asserts on 4.2.2: InkAPI.cc:6261: failed assert `sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS` //int64_t output_vio_sz = INT64_MAX; // NOTE: Does it matter that this is only INT32_MAX as in the examples? // int64_t output_vio_sz = INT32_MAX; //int64_t output_vio_sz = fctx->have_edits // ? INT64_MAX // : TSVIONBytesGet(input_vio); fctx->output_buffer = TSIOBufferCreate(); ib_mm_register_cleanup(txndata->tx->mm, (ib_mm_cleanup_fn_t) TSIOBufferDestroy, (void*) fctx->output_buffer); // FIXME - Where is TSIOBufferReaderFree()? output_reader = TSIOBufferReaderAlloc(fctx->output_buffer); fctx->output_vio = TSVConnWrite(TSTransformOutputVConnGet(contp), contp, output_reader, output_vio_sz); fctx->buffer = TSIOBufferCreate(); ib_mm_register_cleanup(txndata->tx->mm, (ib_mm_cleanup_fn_t) TSIOBufferDestroy, (void*) fctx->buffer); // FIXME - Where is TSIOBufferReaderFree()? fctx->reader = TSIOBufferReaderAlloc(fctx->buffer); /* Get the buffering config */ if (!HTTP_CODE(txndata->status)) { buffer_init(ibd, txndata->tx); } } /* Get any unprocessed bytes. */ ntodo = TSVIONTodoGet(input_vio); /* Test for EOS */ if (ntodo == 0) { ib_log_debug2_tx(txndata->tx, "ntodo zero before consuming data"); flush_data(fctx, -1, 1); /* Call back the input VIO continuation to let it know that we * have completed the write operation. */ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_COMPLETE, input_vio); return; } /* OK, there's some input awaiting our attention */ input_reader = TSVIOReaderGet(input_vio); while (navail = TSIOBufferReaderAvail(input_reader), navail > 0) { block = TSIOBufferReaderStart(input_reader); buf = TSIOBufferBlockReadStart(block, input_reader, &nbytes); rc = (*ibd->ibd->ib_notify_body)(txndata->tx->ib, txndata->tx, buf, nbytes); if (rc != IB_OK) { ib_log_error_tx(txndata->tx, "Error %d notifying body data.", rc); } rc = buffer_data_chunk(fctx, input_reader, nbytes); switch (rc) { case IB_EAGAIN: case IB_OK: break; case IB_EBADVAL: ib_log_error_tx(txndata->tx, "Bad/Inconsistent stream edit(s) ignored."); break; default: /* Can't happen unless a new status is introduced */ ib_log_error_tx(txndata->tx, "Unhandled return value %d", rc); break; } TSIOBufferReaderConsume(input_reader, nbytes); TSVIONDoneSet(input_vio, TSVIONDoneGet(input_vio) + nbytes); } ntodo = TSVIONTodoGet(input_vio); if (ntodo == 0) { ib_log_debug2_tx(txndata->tx, "ntodo zero after consuming data"); flush_data(fctx, -1, 1); /* Call back the input VIO continuation to let it know that we * have completed the write operation. */ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_COMPLETE, input_vio); } else { /* Call back the input VIO continuation to let it know that we * are ready for more data. */ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_READY, input_vio); } }
//format:id + len + block_id + zipflag + size + crc (for all data) // zipflag = 'Z': zipped data(only available for upg all, block_id = 0xFF), // zipfleg = other char, normal data static void diamond_set_hw() { u32 data_size = get_dword(&cmd_buff[2]); u8 start[2] = {0}; u32 crc = 0; u32 cal_crc = 0; hw_cfg_t hw_cfg = {0}; if(data_size == sizeof(hw_cfg_t)) { cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_DATA_SIZE); return; } diamond_fp_enable(FALSE); //get packet start indicator start[0] = 0; //start indecator 1 start[1] = 0; //start indecator 2 flush_data(); if((SUCCESS != read_data(start, 2, 4000)) || (DM_INDICATOR1 != start[0]) || (DM_INDICATOR2 != start[1])) { cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_INDICATOR); flush_data(); diamond_fp_enable(TRUE); return; } //get data if(SUCCESS != read_data((u8 *)&hw_cfg, sizeof(hw_cfg_t), 4000)) { cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_TIMEOUT); flush_data(); diamond_fp_enable(TRUE); return; } //get crc if(SUCCESS != read_data((u8 *)&crc, 4, 4000)) { cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_TIMEOUT); flush_data(); diamond_fp_enable(TRUE); return; } //check crc cal_crc = crc_fast_calculate(CRC_MODE, CRC_INIT, (u8 *)&hw_cfg, sizeof(hw_cfg_t)); if(crc != cal_crc) { cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_CRC); flush_data(); diamond_fp_enable(TRUE); return; } diamond_fp_enable(TRUE); memcpy(&diamond_cfg.hw_cfg, &hw_cfg, sizeof(hw_cfg_t)); //try to config project. if(diamond_set()) { cmd_response(DM_RES_OK, DM_ST_SET_HW, DM_ERR_NONE); } else { cmd_response(DM_RES_ERR, DM_ST_SET_HW, DM_ERR_NONE); } return; }
/** * Process data from ATS. * * Process data from one of the ATS events. * * @param[in,out] contp - the continuation * @param[in,out] ibd - the filter descriptor */ static void process_data(TSCont contp, ibd_ctx *ibd) { int64_t ntodo; int64_t navail; TSIOBufferReader input_reader, output_reader; TSIOBufferBlock block; const char *buf; int64_t nbytes; ib_status_t rc; ib_filter_ctx *fctx = ibd->data; ib_txn_ctx *data = TSContDataGet(contp); TSVIO input_vio = TSVConnWriteVIOGet(contp); TSIOBuffer in_buf = TSVIOBufferGet(input_vio); /* Test whether we're going into an errordoc */ if (IB_HTTP_CODE(data->status)) { /* We're going to an error document, * so we discard all this data */ TSDebug("ironbee", "Status is %d, discarding", data->status); ibd->data->buffering = IOBUF_DISCARD; } /* Test for EOS */ if (in_buf == NULL) { /* flush anything we have buffered. This is final! */ flush_data(fctx, -1, 1); return; } ntodo = TSVIONTodoGet(input_vio); /* Test for first time, and initialise. */ if (!fctx->output_buffer) { fctx->output_buffer = TSIOBufferCreate(); ib_mm_register_cleanup(data->tx->mm, (ib_mm_cleanup_fn_t) TSIOBufferDestroy, (void*) fctx->output_buffer); output_reader = TSIOBufferReaderAlloc(fctx->output_buffer); fctx->output_vio = TSVConnWrite(TSTransformOutputVConnGet(contp), contp, output_reader, TSVIONBytesGet(input_vio)); fctx->buffer = TSIOBufferCreate(); ib_mm_register_cleanup(data->tx->mm, (ib_mm_cleanup_fn_t) TSIOBufferDestroy, (void*) fctx->buffer); fctx->reader = TSIOBufferReaderAlloc(fctx->buffer); /* Get the buffering config */ if (!IB_HTTP_CODE(data->status)) { buffer_init(ibd, data->tx); } /* Do we still have to delay feeding the first data to Ironbee * to keep the IB events in their proper order? * * Appears maybe not, so let's do nothing until it shows signs of breakage. */ #if BUFFER_FIRST /* First time through we can only buffer data until headers are sent. */ fctx->first_time = 1; input_reader = TSVIOReaderGet(input_vio); fctx->buffered = TSIOBufferCopy(fctx->buffer, TSVIOReaderGet(input_vio), ntodo, 0); TSIOBufferReaderConsume(input_reader, fctx->buffered); /* Do we need to request more input or just continue? */ TSVIONDoneSet(input_vio, fctx->buffu`ered + fctx->bytes_done); TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_READY, input_vio); return; #endif } /* second time through we have to feed already-buffered data through * ironbee while retaining it in buffer. Regardless of what else happens. */ #if BUFFER_FIRST if (fctx->first_time) { fctx->first_time = 0; for (block = TSIOBufferStart(fctx->buffer); block != NULL; block = TSIOBufferBlockNext(block)) { //nbytes = TSIOBufferBlockDataSizeGet(block); /* FIXME - do this without a reader ? */ buf = TSIOBufferBlockReadStart(block, fctx->reader, &nbytes); //rc = examine_data_chunk(ibd->ibd, data->tx, buf, nbytes); rc = (*ibd->ibd->ib_notify_body)(data->tx->ib, data->tx, buf, nbytes); if (rc != IB_OK) { // FIXME ??? } } } #endif /* Test for EOS */ if (ntodo == 0) { TSDebug("[ironbee]", "ntodo zero before consuming data"); /* Call back the input VIO continuation to let it know that we * have completed the write operation. */ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_COMPLETE, input_vio); return; } /* OK, there's some input awaiting our attention */ input_reader = TSVIOReaderGet(input_vio); while (navail = TSIOBufferReaderAvail(input_reader), navail > 0) { block = TSIOBufferReaderStart(input_reader); buf = TSIOBufferBlockReadStart(block, input_reader, &nbytes); rc = (*ibd->ibd->ib_notify_body)(data->tx->ib, data->tx, buf, nbytes); if (rc != IB_OK) { // FIXME ??? } rc = buffer_data_chunk(fctx, input_reader, nbytes); if (rc != IB_OK) { // FIXME ??? } TSIOBufferReaderConsume(input_reader, nbytes); TSVIONDoneSet(input_vio, TSVIONDoneGet(input_vio) + nbytes); } ntodo = TSVIONTodoGet(input_vio); if (ntodo == 0) { TSDebug("[ironbee]", "ntodo zero after consuming data"); /* Call back the input VIO continuation to let it know that we * have completed the write operation. */ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_COMPLETE, input_vio); } else { /* Call back the input VIO continuation to let it know that we * are ready for more data. */ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_READY, input_vio); } }
/************************************************************************************************* Main **************************************************************************************************/ void main(void) { HAL_BOARD_INIT(); UART_init(); U0CSR &= ~0x04; ENABLE_RX(); /*setup sensors*/ sensors_init(); sensor_int_init(); /* Setup LED's */ P1DIR |= BV(0); P0DIR |= BV(4); P1_0 = 0; start_gyro(); //start the gyro init_acc(); //start the accelerometer start_mag(); start_baro(); //zero_mag(); EA = 1; SLEEPCMD |= 0x02; //pm 2 uint8 flag; uint8 IDbyte; uint8 baro_stage = 1; while(1){ if (RXin) { //If it is a cal data request if ( active_sensors & BV(4) ) { flag = 0x03; flush_data(&flag); baro_read_cal(); //End of line char flag = 0x00; flush_byte(&flag); } else if ( active_sensors > 0 ) { // P0_4 = 1; /**************************************************************************/ /* Read and transmit sensor data */ flag = 0x04; flush_byte(&flag); flush_byte(&active_sensors); /*---------------------------------------------------------------------*/ //Read accelerometer and gyro if ( active_sensors & BV(0) ) { IDbyte = BV(0); flush_data(&IDbyte); while( !( acc_int_status() ) ); //wait for interrupt read_acc(); //read the accelerometer while( !(gyro_int_status() & BV(0) ) ); //wait for interrupt read_gyro(); } /*---------------------------------------------------------------------*/ //Read Magnetometer //start_interrupts(MAG_INT); if ( active_sensors & BV(1) ) { IDbyte = BV(1); flush_data(&IDbyte); //PCON |= 1; while( !(mag_status() & 0x08 ) ); read_mag(); // mag_sleep(TRUE); } /*---------------------------------------------------------------------*/ //Barometer //uint16 delay_ticks; uint8 baro_res = 2; if ( active_sensors & BV(2) ) { IDbyte = BV(2); flush_data(&IDbyte); if (active_sensors & 0x40) { //delay_ticks = 0xFA00; baro_capture_press(baro_res); //while(delay_ticks--); baro_read_press(TRUE); //delay_ticks = 0xFA00; baro_capture_temp(); //while(delay_ticks--); baro_read_temp(TRUE); }else{ uint8 nullbyte = 3; switch (baro_stage) { case 1 : baro_capture_press(baro_res); baro_read_press(FALSE); baro_read_temp(FALSE); baro_stage++; break; case 2 : baro_read_press(TRUE); baro_read_temp(FALSE); baro_stage++; break; case 3 : baro_capture_temp(); baro_read_press(FALSE); baro_read_temp(FALSE); baro_stage++; break; case 4 : baro_read_press(FALSE); baro_read_temp(TRUE); baro_stage = 1; break; } } //baro_shutdown(); } /*---------------------------------------------------------------------*/ //Humidity if ( active_sensors & BV(3) ) { IDbyte = BV(3); flush_data(&IDbyte); humid_init(); humid_read_humidity(TRUE); } /*---------------------------------------------------------------------*/ //End of line char flag = 0x00; flush_byte(&flag); } if ( !(active_sensors & BV(5)) ) //if autopoll is off { P0_4 = 1; RXin = 0; //clear the RX flag }else{ P0_4 = 0; } } IEN0 |= 0x04; U0CSR &= ~0x04; } }
/** * dump - dump info **/ void dump(struct s_hardware *hardware) { if (hardware->is_pxe_valid==false) { printf("PXE stack was not detected, Dump feature is not available\n"); return; } const union syslinux_derivative_info *sdi = syslinux_derivative_info(); int err=0; ZZJSON *json = NULL; ZZJSON_CONFIG config = { ZZJSON_VERY_STRICT, NULL, (int(*)(void*)) fgetc, NULL, malloc, calloc, free, realloc, stderr, NULL, stdout, (int(*)(void *,const char*,...)) dumpprintf, (int(*)(int,void*)) fputc }; memset(&p_buf,0,sizeof(p_buf)); /* By now, we only support TFTP reporting */ upload=&upload_tftp; upload->name="tftp"; /* The following defines the behavior of the reporting */ char *arg[64]; char filename[512]={0}; compute_filename(hardware, filename, sizeof(filename)); /* The filename */ arg[0] = filename; /* The server to upload the file */ if (strlen(hardware->tftp_ip) != 0) { arg[1] = hardware->tftp_ip; arg[2] = NULL; } else { arg[1] = NULL; snprintf(hardware->tftp_ip, sizeof(hardware->tftp_ip), "%u.%u.%u.%u", ((uint8_t *)&sdi->pxe.ipinfo->serverip)[0], ((uint8_t *)&sdi->pxe.ipinfo->serverip)[1], ((uint8_t *)&sdi->pxe.ipinfo->serverip)[2], ((uint8_t *)&sdi->pxe.ipinfo->serverip)[3]); } /* We initiate the cpio to send */ cpio_init(upload,(const char **)arg); dump_cpu(hardware, &config, &json); dump_pxe(hardware, &config, &json); dump_syslinux(hardware, &config, &json); dump_vpd(hardware, &config, &json); dump_vesa(hardware, &config, &json); dump_disks(hardware, &config, &json); dump_dmi(hardware, &config, &json); dump_memory(hardware, &config, &json); dump_pci(hardware, &config, &json); dump_acpi(hardware, &config, &json); dump_kernel(hardware, &config, &json); dump_hdt(hardware, &config, &json); /* We close & flush the file to send */ cpio_close(upload); if ((err=flush_data(upload)) != TFTP_OK) { /* As we manage a tftp connection, let's display the associated error message */ more_printf("Dump failed !\n"); more_printf("TFTP ERROR on : %s:/%s \n",hardware->tftp_ip, filename); more_printf("TFTP ERROR msg : %s \n",tftp_string_error_message[-err]); } else { more_printf("Dump file sent at %s:/%s\n",hardware->tftp_ip, filename); } }
static void mv_fini(Int exitcode) { flush_data(); VG_(printf)("Total events: %lld\n", theTotalEvents); }