Example #1
0
static byte get(byte* data, int rows, int cols) {
   byte err = 0;
   byte query[4] = { GET_LINE, 0, 0, 0 };

   do
   {
	   query[1] = FIRST;
	   //10 ms delay instead of 55 specified to avoid a second long wait.
	   err = sync_send(query, NULL, data, cols, 1000, 1100);
	   if(err != 0)
		   break;

	   query[1] = ANY;
	   for (int row = 1; row < rows - 1; row++) {
		  query[2] = row;
		  err = sync_send(query, NULL, data + row*cols, cols, 10, 128);
		   if(err != 0)
			   break;
	   }
	   if(err != 0)
		   break;

	   query[1] = LAST;
	   query[2] = rows - 1;
	   err = sync_send(query, NULL, data + (rows - 1)*cols, cols, 10, 128);
	   if(err != 0)
		   break;
   }
   while(0);

   return err;
}
int do_sync_push(const char *lpath, const char *rpath, int show_progress)
{
    struct stat st;
    unsigned mode;
    int fd;

    fd = adb_connect("sync:");
    if(fd < 0) {
        fprintf(stderr,"error: %s\n", adb_error());
        return 1;
    }

    if(stat(lpath, &st)) {
        fprintf(stderr,"cannot stat '%s': %s\n", lpath, strerror(errno));
        sync_quit(fd);
        return 1;
    }

    if(S_ISDIR(st.st_mode)) {
        BEGIN();
        if(copy_local_dir_remote(fd, lpath, rpath, 0, 0)) {
            return 1;
        } else {
            END();
            sync_quit(fd);
        }
    } else {
        if(sync_readmode(fd, rpath, &mode)) {
            return 1;
        }
        if((mode != 0) && S_ISDIR(mode)) {
                /* if we're copying a local file to a remote directory,
                ** we *really* want to copy to remotedir + "/" + localfilename
                */
            const char *name = adb_dirstop(lpath);
            if(name == 0) {
                name = lpath;
            } else {
                name++;
            }
            int  tmplen = strlen(name) + strlen(rpath) + 2;
            char *tmp = reinterpret_cast<char*>(
                malloc(strlen(name) + strlen(rpath) + 2));
            if(tmp == 0) return 1;
            snprintf(tmp, tmplen, "%s/%s", rpath, name);
            rpath = tmp;
        }
        BEGIN();
        if(sync_send(fd, lpath, rpath, st.st_mtime, st.st_mode, show_progress)) {
            return 1;
        } else {
            END();
            sync_quit(fd);
            return 0;
        }
    }

    return 0;
}
Example #3
0
inline static
void change_sender2reciver(void) {
    sync_send();          //0
    serial_delay_half1(); //1
    serial_low();         //2
    serial_input_with_pullup(); //2
    serial_delay_half1(); //3
}
Example #4
0
byte Next_calibrate() {
   byte query[4] = { FINGER_IS_PRESENT, RESET, 0x00, 0x00 };
   byte result;

   sync_send(query, NULL, &result, 1, 10, 128);

   return result;
}
Example #5
0
byte Next_stop(byte scanCount)
{
   byte err;
   byte query[4] = { STOP, scanCount, 0, 0x00 };

   err = sync_send(query, NULL, NULL, 0, 10, 128);
   return err;
}
Example #6
0
byte Next_diagnostic(byte out[9]) {
   byte err;
   byte query[4] = { DIAGNOSTIC, 0x01, 0, 0x08 };
   byte data[8] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };

   err = sync_send(query, data, out, 9, 10, 128);
   return err;
}
Example #7
0
static
void serial_send_packet(uint8_t *buffer, uint8_t size) {
  for (uint8_t i = 0; i < size; ++i) {
    uint8_t data;
    data = buffer[i];
    sync_send();
    serial_write_chunk(data,8);
  }
}
Example #8
0
byte Next_serial(byte* data) {
   byte err;
   byte query[4] = { GET_SERIAL, 0, 0, 0 };

   err = sync_send(query, NULL, data, 12, 10, 128);


   return err;
}
Example #9
0
byte Next_isFinger(byte * p_result) {
   byte query[4] = { FINGER_IS_PRESENT, GET, 0x00, 0x00 };
   byte ret = 0;

   ret = sync_send(query, NULL, p_result, 1, 100, 128);
   //result > HIGH_THRESHOLD

   return ret;
}
Example #10
0
uint32_t Next_version() {
   uint32_t ver = 0;
   byte query[4] = { GET_VERSION, 0, 0, 0 };
   uint8_t data[3] = {0};

   sync_send(query, NULL, data, 3, 10, 128);

   ver = data[0] << 16 | data[1] << 8 | data[2];

   return ver;
}
Example #11
0
static int _do_sync_push(const char *lpath, const char *rpath, int show_progress) {
    struct stat st;
    unsigned mode;
    int fd;

    if((fd = _adb_connect("sync:")) < 0) {
        return 1;
    }

    if(stat(lpath, &st)) {
        sync_quit(fd);
        return 2;
    }

    if(S_ISDIR(st.st_mode)) {
        if(copy_local_dir_remote(fd, lpath, rpath, 0, 0)) {
            return 3;
        } else {
            sync_quit(fd);
        }
    } else {
        if(sync_readmode(fd, rpath, &mode)) {
            return 4;
        }
        if((mode != 0) && S_ISDIR(mode)) {
            /* if we're copying a local file to a remote directory,
            ** we *really* want to copy to remotedir + "/" + localfilename
            */
            const char *name = strrchr(lpath, '/');
            if(name == 0) {
                name = lpath;
            } else {
                name++;
            }
            int  tmplen = strlen(name) + strlen(rpath) + 2;
            char *tmp = malloc(strlen(name) + strlen(rpath) + 2);
            if(tmp == 0) return 1;
            snprintf(tmp, tmplen, "%s/%s", rpath, name);
            rpath = tmp;
        }
        if(sync_send(fd, lpath, rpath, st.st_mtime, st.st_mode, show_progress)) {
            return 5;
        } else {
            sync_quit(fd);
            return 0;
        }
    }

    return 0;
}
Example #12
0
typed_message_future<
    typename detail::deduce_output_type<
        util::type_list<Signatures...>,
        util::type_list<
            typename detail::implicit_conversions<
                typename util::rm_const_and_ref<
                    Ts
                >::type
            >::type...
        >
    >::type
>
sync_send(const typed_actor_ptr<Signatures...>& whom, Ts&&... what) {
    return sync_send(whom.type_erased(), std::forward<Ts>(what)...);
}
int do_sync_push(const char* lpath, const char* rpath, bool show_progress) {
    std::string error;
    int fd = adb_connect("sync:", &error);
    if (fd < 0) {
        fprintf(stderr,"error: %s\n", error.c_str());
        return 1;
    }

    struct stat st;
    if (stat(lpath, &st)) {
        fprintf(stderr,"cannot stat '%s': %s\n", lpath, strerror(errno));
        sync_quit(fd);
        return 1;
    }

    if (S_ISDIR(st.st_mode)) {
        BEGIN();
        if (copy_local_dir_remote(fd, lpath, rpath, 0, 0)) {
            return 1;
        }
    } else {
        unsigned mode;
        if (sync_readmode(fd, rpath, &mode)) {
            return 1;
        }
        std::string path_holder;
        if ((mode != 0) && S_ISDIR(mode)) {
            // If we're copying a local file to a remote directory,
            // we really want to copy to remote_dir + "/" + local_filename.
            path_holder = android::base::StringPrintf("%s/%s", rpath, adb_basename(lpath).c_str());
            rpath = path_holder.c_str();
        }
        BEGIN();
        if (sync_send(fd, lpath, rpath, st.st_mtime, st.st_mode, show_progress)) {
            return 1;
        }
    }

    END();
    sync_quit(fd);
    return 0;
}
Example #14
0
int  soft_serial_transaction(void) {
  SSTD_t *trans = Transaction_table;
#else
int  soft_serial_transaction(int sstd_index) {
  SSTD_t *trans = &Transaction_table[sstd_index];
#endif
  cli();

  // signal to the target that we want to start a transaction
  serial_output();
  serial_low();
  _delay_us(SLAVE_INT_WIDTH_US);

#ifndef SERIAL_USE_MULTI_TRANSACTION
  // wait for the target response
  serial_input_with_pullup();
  _delay_us(SLAVE_INT_RESPONSE_TIME);

  // check if the target is present
  if (serial_read_pin()) {
    // target failed to pull the line low, assume not present
    serial_output();
    serial_high();
    *trans->status = TRANSACTION_NO_RESPONSE;
    sei();
    return TRANSACTION_NO_RESPONSE;
  }

#else
  // send transaction table index
  sync_send();
  _delay_sub_us(TID_SEND_ADJUST);
  serial_write_chunk(sstd_index, 4);
  serial_delay_half1();

  // wait for the target response (step1 low->high)
  serial_input_with_pullup();
  while( !serial_read_pin() ) {
      _delay_sub_us(2);
  }

  // check if the target is present (step2 high->low)
  for( int i = 0; serial_read_pin(); i++ ) {
      if (i > SLAVE_INT_ACK_WIDTH + 1) {
	  // slave failed to pull the line low, assume not present
	  serial_output();
	  serial_high();
	  *trans->status = TRANSACTION_NO_RESPONSE;
	  sei();
	  return TRANSACTION_NO_RESPONSE;
      }
      _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
  }
#endif

  // initiator recive phase
  // if the target is present syncronize with it
  if( trans->target2initiator_buffer_size > 0 ) {
      if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer,
				trans->target2initiator_buffer_size) ) {
	  serial_output();
	  serial_high();
	  *trans->status = TRANSACTION_DATA_ERROR;
	  sei();
	  return TRANSACTION_DATA_ERROR;
      }
   }

  // initiator switch to output
  change_reciver2sender();

  // initiator send phase
  if( trans->initiator2target_buffer_size > 0 ) {
      serial_send_packet((uint8_t *)trans->initiator2target_buffer,
			 trans->initiator2target_buffer_size);
  }

  // always, release the line when not in use
  sync_send();

  *trans->status = TRANSACTION_END;
  sei();
  return TRANSACTION_END;
}
Example #15
0
static int copy_local_dir_remote(int fd, const char *lpath, const char *rpath, int checktimestamps, int listonly)
{
    copyinfo *filelist = 0;
    copyinfo *ci, *next;
    int pushed = 0;
    int skipped = 0;

    if((lpath[0] == 0) || (rpath[0] == 0)) return -1;
    if(lpath[strlen(lpath) - 1] != '/') {
        int  tmplen = strlen(lpath)+2;
        char *tmp = malloc(tmplen);
        if(tmp == 0) return -1;
        snprintf(tmp, tmplen, "%s/",lpath);
        lpath = tmp;
    }
    if(rpath[strlen(rpath) - 1] != '/') {
        int tmplen = strlen(rpath)+2;
        char *tmp = malloc(tmplen);
        if(tmp == 0) return -1;
        snprintf(tmp, tmplen, "%s/",rpath);
        rpath = tmp;
    }

    if(local_build_list(&filelist, lpath, rpath)) {
        return -1;
    }

    if(checktimestamps){
        for(ci = filelist; ci != 0; ci = ci->next) {
            if(sync_start_readtime(fd, ci->dst)) {
                return 1;
            }
        }
        for(ci = filelist; ci != 0; ci = ci->next) {
            unsigned int timestamp, mode, size;
            if(sync_finish_readtime(fd, &timestamp, &mode, &size))
                return 1;
            if(size == ci->size) {
                /* for links, we cannot update the atime/mtime */
                if((S_ISREG(ci->mode & mode) && timestamp == ci->time) ||
                    (S_ISLNK(ci->mode & mode) && timestamp >= ci->time))
                    ci->flag = 1;
            }
        }
    }
    for(ci = filelist; ci != 0; ci = next) {
        next = ci->next;
        if(ci->flag == 0) {
            fprintf(stderr,"%spush: %s -> %s\n", listonly ? "would " : "", ci->src, ci->dst);
            if(!listonly &&
               sync_send(fd, ci->src, ci->dst, ci->time, ci->mode,
                         0 /* no show progress */)) {
                return 1;
            }
            pushed++;
        } else {
            skipped++;
        }
        free(ci);
    }

    fprintf(stderr,"%d file%s pushed. %d file%s skipped.\n",
            pushed, (pushed == 1) ? "" : "s",
            skipped, (skipped == 1) ? "" : "s");

    return 0;
}
Example #16
0
 response_handle_type sync_send(const actor& dest, Ts&&... xs) {
   return sync_send(message_priority::normal, dest, std::forward<Ts>(xs)...);
 }
ssize_t
MulticastSendStrategy::send_bytes_i(const iovec iov[], int n)
{
  return (this->link_->config()->async_send() ? async_send(iov, n) : sync_send(iov, n));
}