/** * Builds and returns the next packet info, or NULL * if no more data is available. * max on data_len is 254, size of header is 8 */ packet_info *get_next_packet_info(int sequence) { char *data = malloc(DATA_SIZE); int data_len = get_next_data(data, DATA_SIZE); if (data_len == 0) { free(data); return NULL; } header *myheader = make_header(sequence, data_len, 0, 0); void *packet = malloc(sizeof(header) + data_len); memcpy(packet, myheader, sizeof(header)); memcpy(((char *) packet) +sizeof(header), data, data_len); free(data); free(myheader); packet_info *info = (packet_info *) malloc(sizeof(packet_info)); info->packet = packet; info->retrieved = time(0); info->data_len = data_len; info->sequence = sequence; return info; }
/** * Builds and returns the next packet, or NULL * if no more data is available. */ void *get_next_packet(int sequence, int *len) { //store sent packets in buffer if (wind_cache[sequence % WIND_SIZE]) { void* cached_pkt = wind_cache[sequence % WIND_SIZE]; int cached_header_seq = read_hseq(cached_pkt); if (cached_header_seq == sequence ) { //packets are only sent from the buffer if packet loss or a timeout occured debug_time = SEND_TIMEOUT; mylog( "[From Cache] %i\n", cached_header_seq); *len = sizeof(header) + read_hlength(cached_pkt); return cached_pkt; } } //increase timeout debug_time += SHORT_TIMEOUT; char *data = malloc(DATA_SIZE); int data_length = get_next_data(data, DATA_SIZE); if (data_length == 0) { free(data); return NULL; } //create header for packet header *myheader = make_header(sequence, data_length, 0, 0); //create the packet void *pkt = malloc(sizeof(header) + data_length + sizeof(checksum_t)); memcpy(pkt, myheader, sizeof(header)); memcpy(((char *) pkt) + sizeof(header), data, data_length); //calculate the checksum for the packet and attach checksum_t chksm = chksum(data, data_length); memcpy(((char *) pkt) + sizeof(header) + data_length, &chksm, sizeof(checksum_t)); free(data); free(myheader); //len = packet size in bytes *len = sizeof(header) + data_length + sizeof(checksum_t); mylog("Checksum %d\n", get_chksum(pkt, data_length + sizeof(header))); if (wind_cache[sequence % WIND_SIZE]) { free(wind_cache[sequence % WIND_SIZE]); } wind_cache[sequence % WIND_SIZE] = (void*)malloc(sizeof(header) + data_length + sizeof(checksum_t)); memcpy(wind_cache[sequence % WIND_SIZE], pkt, sizeof(header) + data_length + sizeof(checksum_t)); return pkt; }
void scan_dir_ext( const std::string &dirname,bool recursive, scanDirOp &op ) { _finddata_t data = {0}; std::string path = dirname; path += "\\*"; intptr_t hdl = ::_findfirst( path.c_str(),&data ); if( hdl < 0 ) { op.error("the path is not valid."); return; } std::list<find_info_s> hdls; hdls.push_back( find_info_s() ); hdls.back().hdl = hdl; hdls.back().cur_dir = dirname; op.enter_dir( dirname ); while( !hdls.empty() ) { find_info_s &fi = hdls.back(); if( _A_SUBDIR == data.attrib ) { if( std::string(".") == data.name || std::string("..") == data.name ) { if( !get_next_data( hdls,data,op ) ) { // return; } } else if( recursive ) { std::string tp = fi.cur_dir; tp += "\\"; tp += data.name; path = tp; path += "\\*"; hdl = ::_findfirst( path.c_str(),&data ); if( hdl < 0 ) { if( !get_next_data( hdls,data,op ) ) { // return; } } else { hdls.push_back( find_info_s() ); hdls.back().hdl = hdl; hdls.back().cur_dir = tp; op.enter_dir( tp ); } } else { std::string p = fi.cur_dir; p += "\\"; p += data.name; if( !op.scan_file(p,data.size,data.attrib) ) { return; } if( !get_next_data( hdls,data,op ) ) { // return; } } } else { std::string p = fi.cur_dir; p += "\\"; p += data.name; if( !op.scan_file(p,data.size,data.attrib) ) { return; } if( !get_next_data( hdls,data,op ) ) { // return; } } } }
void ds1Wire::decode() { assert(_data); _max_width = 0; uint8_t cur_state = Unknown; const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots = _data->get_snapshots(); if (snapshots.empty()) return; const shared_ptr<pv::data::LogicSnapshot> &snapshot = snapshots.front(); uint64_t flag_index1; uint64_t flag_index2; uint64_t flag_index3; uint64_t flag_index4; //uint64_t start_index; //uint64_t stop_index; //bool edge1; //bool edge2; uint64_t left = 0; uint64_t right = snapshot->get_sample_count() - 1; const uint64_t samplerate = _data->get_samplerate(); double pulse_width1; double pulse_width2; double pulse_width3; double pulse_width4; uint8_t data; bool valid = false; if (!_state_index.empty()) _state_index.clear(); while(left < right && pulse_width1 != 0) // Regular Speed { // search reset flag pulse_width1 = get_next_pulse_width(0, samplerate, left, right, snapshot); flag_index1 = left; if (pulse_width1 >= 0.48 && pulse_width1 <= 0.96) { // tRSTL pulse_width2 = get_next_pulse_width(1, samplerate, left, right, snapshot); flag_index2 = left; if (pulse_width2 >= 0.015 && pulse_width2 <= 0.06) { // tPDH pulse_width3 = get_next_pulse_width(0, samplerate, left, right, snapshot); flag_index3 = left; if (pulse_width3 >= 0.06 && pulse_width3 <= 0.24) { // tPDL pulse_width4 = get_next_pulse_width(1, samplerate, left, right, snapshot); flag_index4 = left; if (pulse_width2 + pulse_width3 + pulse_width4 >= 0.48) { cur_state = Reset; _state_index.push_back(std::make_pair(std::make_pair(flag_index1, flag_index2 - flag_index1), std::make_pair(cur_state, 0))); cur_state = Presence; _state_index.push_back(std::make_pair(std::make_pair(flag_index3, flag_index4 - flag_index3), std::make_pair(cur_state, 0))); } else { continue; } } else { continue; } } else { continue; } } else { continue; } uint64_t start; uint64_t end; int i; if (cur_state == Presence) { data = get_next_data(false, valid, start, end, samplerate, left, right, snapshot); if (valid) { cur_state = Command; _state_index.push_back(std::make_pair(std::make_pair(start, end - start), std::make_pair(cur_state, data))); }else { continue; } } if (cur_state == Command) { data = get_next_data(false, valid, start, end, samplerate, left, right, snapshot); if (valid) { cur_state = Family; _state_index.push_back(std::make_pair(std::make_pair(start, end - start), std::make_pair(cur_state, data))); } else { continue; } } if (cur_state == Family) { for (i = 0; i < 6; i++) { data = get_next_data(false, valid, start, end, samplerate, left, right, snapshot); if (valid) { cur_state = Serial; _state_index.push_back(std::make_pair(std::make_pair(start, end - start), std::make_pair(cur_state, data))); } else { break; } } if (i != 6) continue; } if (cur_state == Serial) { data = get_next_data(false, valid, start, end, samplerate, left, right, snapshot); if (valid) { cur_state = Crc; _state_index.push_back(std::make_pair(std::make_pair(start, end - start), std::make_pair(cur_state, data))); } else { continue; } } if (cur_state == Crc) { while (1) { data = get_next_data(false, valid, start, end, samplerate, left, right, snapshot); if (valid) { cur_state = Data; _state_index.push_back(std::make_pair(std::make_pair(start, end - start), std::make_pair(cur_state, data))); } else { break; } } } } // if (cur_state == Unknown) { // while(1) { // Overdrive Speed // } // } }