本文整理汇总了C++中write_data函数的典型用法代码示例。如果您正苦于以下问题:C++ write_data函数的具体用法?C++ write_data怎么用?C++ write_data使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_buffer_truehd
/* Adapted from libavformat/spdifenc.c:
* It seems Dolby TrueHD frames have to be encapsulated in MAT frames before
* they can be encapsulated in IEC 61937.
* Here we encapsulate 24 TrueHD frames in a single MAT frame, padding them
* to achieve constant rate.
* The actual format of a MAT frame is unknown, but the below seems to work.
* However, it seems it is not actually necessary for the 24 TrueHD frames to
* be in an exact alignment with the MAT frame
*/
static int write_buffer_truehd( filter_t *p_filter, block_t *p_in_buf )
{
#define TRUEHD_FRAME_OFFSET 2560
filter_sys_t *p_sys = p_filter->p_sys;
if( !p_sys->p_out_buf
&& write_init( p_filter, p_in_buf, 61440, 61440 / 16 ) )
return SPDIF_ERROR;
int i_padding = 0;
if( p_sys->truehd.i_frame_count == 0 )
{
static const char p_mat_start_code[20] = {
0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00,
0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83, 0x49, 0x80, 0x77, 0xE0
};
write_data( p_filter, p_mat_start_code, 20, true );
/* We need to include the S/PDIF header in the first MAT frame */
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - 20
- SPDIF_HEADER_SIZE;
}
else if( p_sys->truehd.i_frame_count == 11 )
{
/* The middle mat code need to be at the ((2560 * 12) - 4) offset */
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - 4;
}
else if( p_sys->truehd.i_frame_count == 12 )
{
static const char p_mat_middle_code[12] = {
0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA,
0x82, 0x83, 0x49, 0x80, 0x77, 0xE0
};
write_data( p_filter, p_mat_middle_code, 12, true );
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - ( 12 - 4 );
}
else if( p_sys->truehd.i_frame_count == 23 )
{
static const char p_mat_end_code[16] = {
0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11
};
/* The end mat code need to be at the ((2560 * 24) - 24) offset */
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - 24;
if( i_padding < 0 || p_in_buf->i_buffer + i_padding >
p_sys->p_out_buf->i_buffer - p_sys->i_out_offset )
return SPDIF_ERROR;
write_buffer( p_filter, p_in_buf );
write_padding( p_filter, i_padding );
write_data( p_filter, p_mat_end_code, 16, true );
write_finalize( p_filter, IEC61937_TRUEHD, 1 /* in bytes */ );
p_sys->truehd.i_frame_count = 0;
return SPDIF_SUCCESS;
}
else
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer;
if( i_padding < 0 || p_in_buf->i_buffer + i_padding >
p_sys->p_out_buf->i_buffer - p_sys->i_out_offset )
return SPDIF_ERROR;
write_buffer( p_filter, p_in_buf );
write_padding( p_filter, i_padding );
p_sys->truehd.i_frame_count++;
return SPDIF_MORE_DATA;
}
示例2: smb2_sendfile_send_data
/* struct smbd_smb2_read_state destructor. Send the SMB2_READ data. */
static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
{
struct lock_struct lock;
uint32_t in_length = state->in_length;
uint64_t in_offset = state->in_offset;
files_struct *fsp = state->fsp;
const DATA_BLOB *hdr = state->smb2req->queue_entry.sendfile_header;
NTSTATUS *pstatus = state->smb2req->queue_entry.sendfile_status;
struct smbXsrv_connection *xconn = state->smb2req->xconn;
ssize_t nread;
ssize_t ret;
int saved_errno;
nread = SMB_VFS_SENDFILE(xconn->transport.sock,
fsp,
hdr,
in_offset,
in_length);
DEBUG(10,("smb2_sendfile_send_data: SMB_VFS_SENDFILE returned %d on file %s\n",
(int)nread,
fsp_str_dbg(fsp) ));
if (nread == -1) {
saved_errno = errno;
/*
* Returning ENOSYS means no data at all was sent.
Do this as a normal read. */
if (errno == ENOSYS) {
goto normal_read;
}
if (errno == EINTR) {
/*
* Special hack for broken Linux with no working sendfile. If we
* return EINTR we sent the header but not the rest of the data.
* Fake this up by doing read/write calls.
*/
set_use_sendfile(SNUM(fsp->conn), false);
nread = fake_sendfile(xconn, fsp, in_offset, in_length);
if (nread == -1) {
saved_errno = errno;
DEBUG(0,("smb2_sendfile_send_data: fake_sendfile "
"failed for file %s (%s) for client %s. "
"Terminating\n",
fsp_str_dbg(fsp), strerror(saved_errno),
smbXsrv_connection_dbg(xconn)));
*pstatus = map_nt_error_from_unix_common(saved_errno);
return 0;
}
goto out;
}
DEBUG(0,("smb2_sendfile_send_data: sendfile failed for file "
"%s (%s) for client %s. Terminating\n",
fsp_str_dbg(fsp), strerror(saved_errno),
smbXsrv_connection_dbg(xconn)));
*pstatus = map_nt_error_from_unix_common(saved_errno);
return 0;
} else if (nread == 0) {
/*
* Some sendfile implementations return 0 to indicate
* that there was a short read, but nothing was
* actually written to the socket. In this case,
* fallback to the normal read path so the header gets
* the correct byte count.
*/
DEBUG(3, ("send_file_readX: sendfile sent zero bytes "
"falling back to the normal read: %s\n",
fsp_str_dbg(fsp)));
goto normal_read;
}
/*
* We got a short read
*/
goto out;
normal_read:
/* Send out the header. */
ret = write_data(xconn->transport.sock,
(const char *)hdr->data, hdr->length);
if (ret != hdr->length) {
saved_errno = errno;
DEBUG(0,("smb2_sendfile_send_data: write_data failed for file "
"%s (%s) for client %s. Terminating\n",
fsp_str_dbg(fsp), strerror(saved_errno),
smbXsrv_connection_dbg(xconn)));
*pstatus = map_nt_error_from_unix_common(saved_errno);
return 0;
}
nread = fake_sendfile(xconn, fsp, in_offset, in_length);
if (nread == -1) {
saved_errno = errno;
DEBUG(0,("smb2_sendfile_send_data: fake_sendfile "
"failed for file %s (%s) for client %s. "
"Terminating\n",
fsp_str_dbg(fsp), strerror(saved_errno),
smbXsrv_connection_dbg(xconn)));
//.........这里部分代码省略.........
示例3: write_lpex
MYBOOL __WINAPI write_lpex(lprec *lp, void *userhandle, write_modeldata_func write_modeldata)
{
int i, j, b,
nrows = lp->rows,
ncols = lp->columns,
nchars, maxlen = LP_MAXLINELEN;
MYBOOL ok;
REAL a;
char *ptr;
if(lp->matA->is_roworder) {
report(lp, IMPORTANT, "LP_writefile: Cannot write to LP file while in row entry mode.\n");
return(FALSE);
}
if(!mat_validate(lp->matA)) {
report(lp, IMPORTANT, "LP_writefile: Could not validate the data matrix.\n");
return(FALSE);
}
/* Write name of model */
ptr = get_lp_name(lp);
if(ptr != NULL)
if(*ptr)
write_lpcomment(userhandle, write_modeldata, ptr, FALSE);
else
ptr = NULL;
/* Write the objective function */
write_lpcomment(userhandle, write_modeldata, "Objective function", (MYBOOL) (ptr != NULL));
if(is_maxim(lp))
write_data(userhandle, write_modeldata, "max: ");
else
write_data(userhandle, write_modeldata, "min: ");
write_lprow(lp, 0, userhandle, write_modeldata, maxlen);
a = get_rh(lp, 0);
if(a != 0)
write_data(userhandle, write_modeldata, " %+.12g", a);
write_data(userhandle, write_modeldata, ";\n");
/* Write constraints */
if(nrows > 0)
write_lpcomment(userhandle, write_modeldata, "Constraints", TRUE);
for(j = 1; j <= nrows; j++) {
if(((lp->names_used) && (lp->row_name[j] != NULL)) || (write_lprow(lp, j, userhandle, NULL, maxlen) == 1))
ptr = get_row_name(lp, j);
else
ptr = NULL;
if((ptr != NULL) && (*ptr))
write_data(userhandle, write_modeldata, "%s: ", ptr);
#ifndef SingleBoundedRowInLP
/* Write the ranged part of the constraint, if specified */
if ((lp->orig_upbo[j]) && (lp->orig_upbo[j] < lp->infinite)) {
if(my_chsign(is_chsign(lp, j), lp->orig_rhs[j]) == -lp->infinite)
write_data(userhandle, write_modeldata, "-Inf %s ", (is_chsign(lp, j)) ? ">=" : "<=");
else if(my_chsign(is_chsign(lp, j), lp->orig_rhs[j]) == lp->infinite)
write_data(userhandle, write_modeldata, "+Inf %s ", (is_chsign(lp, j)) ? ">=" : "<=");
else
write_data(userhandle, write_modeldata, "%+.12g %s ",
(lp->orig_upbo[j]-lp->orig_rhs[j]) * (is_chsign(lp, j) ? 1.0 : -1.0) / (lp->scaling_used ? lp->scalars[j] : 1.0),
(is_chsign(lp, j)) ? ">=" : "<=");
}
#endif
if((!write_lprow(lp, j, userhandle, write_modeldata, maxlen)) && (ncols >= 1))
write_data(userhandle, write_modeldata, "0 %s", get_col_name(lp, 1));
if(lp->orig_upbo[j] == 0)
write_data(userhandle, write_modeldata, " =");
else if(is_chsign(lp, j))
write_data(userhandle, write_modeldata, " >=");
else
write_data(userhandle, write_modeldata, " <=");
if(fabs(get_rh(lp, j) + lp->infinite) < 1)
write_data(userhandle, write_modeldata, " -Inf;\n");
else if(fabs(get_rh(lp, j) - lp->infinite) < 1)
write_data(userhandle, write_modeldata, " +Inf;\n");
else
write_data(userhandle, write_modeldata, " %.12g;\n", get_rh(lp, j));
#ifdef SingleBoundedRowInLP
/* Write the ranged part of the constraint, if specified */
if ((lp->orig_upbo[j]) && (lp->orig_upbo[j] < lp->infinite)) {
if(((lp->names_used) && (lp->row_name[j] != NULL)) || (write_lprow(lp, j, userhandle, NULL, maxlen) == 1))
ptr = get_row_name(lp, j);
else
ptr = NULL;
if((ptr != NULL) && (*ptr))
write_data(userhandle, write_modeldata, "%s: ", ptr);
if((!write_lprow(lp, j, userhandle, write_modeldata, maxlen)) && (get_Ncolumns(lp) >= 1))
write_data(userhandle, write_modeldata, "0 %s", get_col_name(lp, 1));
write_data(userhandle, write_modeldata, " %s %g;\n",
(is_chsign(lp, j)) ? "<=" : ">=",
(lp->orig_upbo[j]-lp->orig_rhs[j]) * (is_chsign(lp, j) ? 1.0 : -1.0) / (lp->scaling_used ? lp->scalars[j] : 1.0));
}
#endif
}
/* Write bounds on variables */
//.........这里部分代码省略.........
示例4: command_list
static void command_list(void)
{
write_command(ILI9341_PWCTRB);
write_data(0x00);
write_data(0XC1);
write_data(0X30);
write_command(ILI9341_TIMCTRA);
write_data(0x85);
write_data(0x00);
write_data(0x78);
write_command(ILI9341_PWCTRSEQ);
write_data(0x39);
write_data(0x2C);
write_data(0x00);
write_data(0x34);
write_data(0x02);
write_command(ILI9341_PUMP);
write_data(0x20);
write_command(ILI9341_TIMCTRB);
write_data(0x00);
write_data(0x00);
write_command(ILI9341_PWCTR1);
write_data(0x23);
write_command(ILI9341_PWCTR2);
write_data(0x10);
write_command(ILI9341_VMCTR1);
write_data(0x3e);
write_data(0x28);
write_command(ILI9341_VMCTR2);
write_data(0x86);
write_command(ILI9341_MADCTL);
write_data(0x48);
write_command(ILI9341_PIXFMT);
write_data(0x55);
write_command(ILI9341_FRMCTR1);
write_data(0x00);
write_data(0x18);
write_command(ILI9341_DFUNCTR);
write_data(0x08);
write_data(0x82);
write_data(0x27);
write_command(ILI9341_ENGMCTR);
write_data(0x00);
write_command(ILI9341_GAMMASET);
write_data(0x01);
write_command(ILI9341_GMCTRP1);
write_data(0x0F);
write_data(0x31);
write_data(0x2B);
write_data(0x0C);
write_data(0x0E);
write_data(0x08);
write_data(0x4E);
write_data(0xF1);
write_data(0x37);
write_data(0x07);
write_data(0x10);
write_data(0x03);
write_data(0x0E);
write_data(0x09);
write_data(0x00);
write_command(ILI9341_GMCTRN1);
write_data(0x00);
write_data(0x0E);
write_data(0x14);
write_data(0x03);
write_data(0x11);
write_data(0x07);
write_data(0x31);
write_data(0xC1);
write_data(0x48);
write_data(0x08);
write_data(0x0F);
write_data(0x0C);
write_data(0x31);
write_data(0x36);
write_data(0x0F);
write_command(ILI9341_SLPOUT);
nrf_delay_ms(120);
write_command(ILI9341_DISPON);
}
示例5: do_work
void
do_work(unsigned int start)
{
unsigned int stack_array[STACK_ARRAY_ELEMS];
unsigned int i = 0;
unsigned int array1_start = start;
unsigned int array2_start = start + (ELEMS / (ELEMS_PER_PAGE)) + 10;
printf("Checking uninitialized array1\n");
/* check the uninitialized array1 before initialization */
for (i=0; i<ELEMS; i++) {
if (array1[i] != 0) {
printf("FAILED in file %s at line %d: array1[%d] = %u != %d\n", __FILE__, __LINE__, i, array1[i], 0);
exit(1);
}
}
printf("Checking uninitialized array2\n");
/* check the uninitialized array2 before initialization */
for (i=0; i<ELEMS; i++) {
if (array2[i] != 0) {
printf("FAILED in file %s at line %d: array2[%d] = %u != %d\n", __FILE__, __LINE__, i, array2[i], 0);
exit(1);
}
}
for (i=0; i<STACK_ARRAY_ELEMS; i++) {
stack_array[i] = i * 1000;
}
for (i=0; i<2; i++) {
call_all();
write_data(array1, array1_start);
call_all();
printf("Checking initialized array1\n");
read_data(array1, array1_start, "array1");
}
/* check the uninitialized array2 again before initialization */
printf("Checking initialized array2 again\n");
for (i=0; i<ELEMS; i++) {
if (array2[i] != 0) {
printf("FAILED in file %s at line %d: array2[%d] = %u != %d\n", __FILE__, __LINE__, i, array2[i], 0);
exit(1);
}
}
printf("Checking initialized stack_array\n");
for (i=0; i<STACK_ARRAY_ELEMS; i++) {
if (stack_array[i] != i * 1000) {
printf("FAILED in file %s at line %d: stack_array[%d] = %u != %d\n", __FILE__, __LINE__, i, stack_array[i], i);
exit(1);
}
}
printf("Checking initialized init\n");
/* check the initialized array */
for (i=0; i<INIT_ARRAY_ELEMS; i++) {
if (init[i] != i) {
printf("FAILED in file %s at line %d: init[%d] = %u != %d\n", __FILE__, __LINE__, i, init[i], i);
exit(1);
}
}
for (i=0; i<2; i++) {
call_all();
write_data(array2, array2_start);
call_all();
printf("Checking initialized array2\n");
read_data(array2, array2_start, "array2");
}
printf("Checking initialized stack_array\n");
for (i=0; i<STACK_ARRAY_ELEMS; i++) {
if (stack_array[i] != i * 1000) {
printf("FAILED in file %s at line %d: stack_array[%d] = %u != %d\n", __FILE__, __LINE__, i, stack_array[i], i);
exit(1);
}
}
/* check the initialized array */
printf("Checking initialized init\n");
for (i=0; i<INIT_ARRAY_ELEMS; i++) {
if (init[i] != i) {
printf("FAILED in file %s at line %d: init[%d] = %u != %d\n", __FILE__, __LINE__, i, init[i], i);
exit(1);
}
}
printf("Checking initialized array1 for the last time\n");
read_data(array1, array1_start, "array1");
printf("Checking initialized array2 for the last time\n");
read_data(array2, array2_start, "array2");
printf("SUCCEEDED\n");
}
示例6: kcs_event
//.........这里部分代码省略.........
kcs->state = KCS_WAIT_WRITE_END;
} else {
write_next_byte(kcs);
}
break;
case KCS_WAIT_WRITE_END:
if (state != KCS_WRITE_STATE) {
start_error_recovery(kcs,
"Not in write state for write end");
break;
}
clear_obf(kcs, status);
write_next_byte(kcs);
kcs->state = KCS_WAIT_READ;
break;
case KCS_WAIT_READ:
if ((state != KCS_READ_STATE) && (state != KCS_IDLE_STATE)) {
start_error_recovery(
kcs,
"Not in read or idle in read state");
break;
}
if (state == KCS_READ_STATE) {
if (! check_obf(kcs, status, time))
return KCS_CALL_WITH_DELAY;
read_next_byte(kcs);
} else {
/* We don't implement this exactly like the state
machine in the spec. Some broken hardware
does not write the final dummy byte to the
read register. Thus obf will never go high
here. We just go straight to idle, and we
handle clearing out obf in idle state if it
happens to come in. */
clear_obf(kcs, status);
kcs->orig_write_count = 0;
kcs->state = KCS_IDLE;
return KCS_TRANSACTION_COMPLETE;
}
break;
case KCS_ERROR0:
clear_obf(kcs, status);
write_cmd(kcs, KCS_GET_STATUS_ABORT);
kcs->state = KCS_ERROR1;
break;
case KCS_ERROR1:
clear_obf(kcs, status);
write_data(kcs, 0);
kcs->state = KCS_ERROR2;
break;
case KCS_ERROR2:
if (state != KCS_READ_STATE) {
start_error_recovery(kcs,
"Not in read state for error2");
break;
}
if (! check_obf(kcs, status, time))
return KCS_CALL_WITH_DELAY;
clear_obf(kcs, status);
write_data(kcs, KCS_READ_BYTE);
kcs->state = KCS_ERROR3;
break;
case KCS_ERROR3:
if (state != KCS_IDLE_STATE) {
start_error_recovery(kcs,
"Not in idle state for error3");
break;
}
if (! check_obf(kcs, status, time))
return KCS_CALL_WITH_DELAY;
clear_obf(kcs, status);
if (kcs->orig_write_count) {
restart_kcs_transaction(kcs);
} else {
kcs->state = KCS_IDLE;
return KCS_TRANSACTION_COMPLETE;
}
break;
case KCS_HOSED:
break;
}
if (kcs->state == KCS_HOSED) {
init_kcs_data(kcs, kcs->port, kcs->addr);
return KCS_SM_HOSED;
}
return KCS_CALL_WITHOUT_DELAY;
}
示例7: write_key_init
/*
* move the file pointer to the point where the next key can be written and return
* that offset
*/
int
write_key_init(int fd, UINT32 pub_data_size, UINT32 blob_size, UINT32 vendor_data_size)
{
UINT32 num_keys;
BYTE version;
int rc, offset;
/* seek to the PS version */
rc = lseek(fd, TSSPS_VERSION_OFFSET, SEEK_SET);
if (rc == ((off_t) - 1)) {
LogError("lseek: %s", strerror(errno));
return -1;
}
/* go to NUM_KEYS */
rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET);
if (rc == ((off_t) - 1)) {
LogError("lseek: %s", strerror(errno));
return -1;
}
/* read the number of keys */
rc = read(fd, &num_keys, sizeof(UINT32));
num_keys = LE_32(num_keys);
if (rc == -1) {
LogError("read of %zd bytes: %s", sizeof(UINT32), strerror(errno));
return -1;
} else if (rc == 0) {
/* This is the first key being written */
num_keys = 1;
version = 1;
/* seek to the PS version */
rc = lseek(fd, TSSPS_VERSION_OFFSET, SEEK_SET);
if (rc == ((off_t) - 1)) {
LogError("lseek: %s", strerror(errno));
return -1;
}
/* write out the version info byte */
if ((rc = write_data(fd, &version, sizeof(BYTE)))) {
LogError("%s", __FUNCTION__);
return rc;
}
rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET);
if (rc == ((off_t) - 1)) {
LogError("lseek: %s", strerror(errno));
return -1;
}
num_keys = LE_32(num_keys);
if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
LogError("%s", __FUNCTION__);
return rc;
}
/* return the offset */
return (TSSPS_NUM_KEYS_OFFSET + sizeof(UINT32));
}
/* if there is a hole in the file we can write to, find it */
offset = find_write_offset(pub_data_size, blob_size, vendor_data_size);
if (offset != -1) {
/* we found a hole, seek to it and don't increment the # of keys on disk */
rc = lseek(fd, offset, SEEK_SET);
} else {
/* we didn't find a hole, increment the number of keys on disk and seek
* to the end of the file
*/
num_keys++;
/* go to the beginning */
rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET);
if (rc == ((off_t) - 1)) {
LogError("lseek: %s", strerror(errno));
return -1;
}
num_keys = LE_32(num_keys);
if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
LogError("%s", __FUNCTION__);
return rc;
}
rc = lseek(fd, 0, SEEK_END);
}
if (rc == ((off_t) - 1)) {
LogError("lseek: %s", strerror(errno));
return -1;
}
/* lseek returns the number of bytes of offset from the beginning of the file */
return rc;
}
示例8: lcd_initial
void lcd_initial()
{
int i;
// hard reset
for (i=0; i<120; i++)
SPI_LCD_REST_LOW();
for (i=0; i<120; i++)
SPI_LCD_REST_HIGH();
//-------------------Software Reset-------------------------------//
write_command(0x11);//Sleep exit
//ST7735R Frame Rate
write_command(0xB1);
write_data(0x01); write_data(0x2C); write_data(0x2D);
write_command(0xB2);
write_data(0x01); write_data(0x2C); write_data(0x2D);
write_command(0xB3);
write_data(0x01); write_data(0x2C); write_data(0x2D);
write_data(0x01); write_data(0x2C); write_data(0x2D);
write_command(0xB4); //Column inversion
write_data(0x07);
//ST7735R Power Sequence
write_command(0xC0);
write_data(0xA2); write_data(0x02); write_data(0x84);
write_command(0xC1); write_data(0xC5);
write_command(0xC2);
write_data(0x0A); write_data(0x00);
write_command(0xC3);
write_data(0x8A); write_data(0x2A);
write_command(0xC4);
write_data(0x8A); write_data(0xEE);
write_command(0xC5); //VCOM
write_data(0x0E);
write_command(0x36); //MX, MY, RGB mode
#if ROTATION == 90
write_data(0xa0 | SBIT_RGB);
#elif ROTATION == 180
write_data(0xc0 | SBIT_RGB);
#elif ROTATION == 270
write_data(0x60 | SBIT_RGB);
#else
write_data(0x00 | SBIT_RGB);
#endif
#if ROTATION == 90 || ROTATION == 270
write_command(0x2a);
write_data(0x00);write_data(0x00);
write_data(0x00);write_data(0x9f);
write_command(0x2b);
write_data(0x00);write_data(0x00);
write_data(0x00);write_data(0x7f);
#else
write_command(0x2a);
write_data(0x00);write_data(0x00);
write_data(0x00);write_data(0x7f);
write_command(0x2b);
write_data(0x00);write_data(0x00);
write_data(0x00);write_data(0x9f);
#endif
//ST7735R Gamma Sequence
write_command(0xe0);
write_data(0x0f); write_data(0x1a);
write_data(0x0f); write_data(0x18);
write_data(0x2f); write_data(0x28);
write_data(0x20); write_data(0x22);
write_data(0x1f); write_data(0x1b);
write_data(0x23); write_data(0x37);
write_data(0x00); write_data(0x07);
write_data(0x02); write_data(0x10);
write_command(0xe1);
write_data(0x0f); write_data(0x1b);
write_data(0x0f); write_data(0x17);
write_data(0x33); write_data(0x2c);
write_data(0x29); write_data(0x2e);
write_data(0x30); write_data(0x30);
write_data(0x39); write_data(0x3f);
write_data(0x00); write_data(0x07);
write_data(0x03); write_data(0x10);
write_command(0xF0); //Enable test command
write_data(0x01);
write_command(0xF6); //Disable ram power save mode
write_data(0x00);
write_command(0x3A); //65k mode
write_data(0x05);
//.........这里部分代码省略.........
示例9: write_item
void write_item(uint8_t *buf)
{
write_data(buf+1, buf[0]);
}
示例10: RequestMonitoredPages
void RequestMonitoredPages(void)
{
DIR *dir;
struct dirent* ent;
/* Open the monitor subdirectory. */
if(chdir("monitor"))
{PrintMessage(Warning,"Cannot change to directory 'monitor'; [%!s] no files monitored.");return;}
dir=opendir(".");
if(!dir)
{PrintMessage(Warning,"Cannot open directory 'monitor'; [%!s] no files monitored.");ChangeBackToSpoolDir();return;}
ent=readdir(dir);
if(!ent)
{PrintMessage(Warning,"Cannot read directory 'monitor'; [%!s] no files monitored.");closedir(dir);ChangeBackToSpoolDir();return;}
/* Scan through all of the files. */
do
{
struct stat buf;
if(ent->d_name[0]=='.' && (ent->d_name[1]==0 || (ent->d_name[1]=='.' && ent->d_name[2]==0)))
continue; /* skip . & .. */
if(stat(ent->d_name,&buf))
{PrintMessage(Inform,"Cannot stat file 'monitor/%s'; [%!s] race condition?",ent->d_name);return;}
else if(S_ISREG(buf.st_mode) && *ent->d_name=='O')
{
URL *Url=FileNameToURL(ent->d_name);
int last,next;
ChangeBackToSpoolDir();
if(!Url)
continue;
MonitorTimes(Url,&last,&next);
PrintMessage(Debug,"Monitoring '%s' last=%dh next=%dh => %s",Url->name,last,next,next?"No":"Yes");
chdir("monitor");
if(next==0)
{
int ifd=open(ent->d_name,O_RDONLY|O_BINARY);
if(ifd==-1)
PrintMessage(Warning,"Cannot open monitored file 'monitor/%s' to read; [%!s].",ent->d_name);
else
{
int ofd;
init_io(ifd);
ChangeBackToSpoolDir();
ofd=OpenNewOutgoingSpoolFile();
if(ofd==-1)
PrintMessage(Warning,"Cannot open outgoing spool file for monitored URL '%s'; [%!s].",Url->name);
else
{
char *contents=(char*)malloc(buf.st_size+1);
init_io(ofd);
read_data(ifd,contents,buf.st_size);
if(write_data(ofd,contents,buf.st_size)==-1)
PrintMessage(Warning,"Cannot write to outgoing file; disk full?");
finish_io(ofd);
CloseNewOutgoingSpoolFile(ofd,Url);
free(contents);
}
chdir("monitor");
finish_io(ifd);
close(ifd);
if(utime(URLToFileName(Url,'M',0),NULL))
PrintMessage(Warning,"Cannot change timestamp of monitored file 'monitor/%s'; [%!s].",URLToFileName(Url,'M',0));
}
}
FreeURL(Url);
}
}
while((ent=readdir(dir)));
ChangeBackToSpoolDir();
closedir(dir);
}
示例11: main
int main(int argc, char *argv[]){
DWORD status = 0;
DWORD errorstatus = 0;
string error_str;
scu_mil myscu;
/* int test = 0;
BYTE blub = 0x38;
cin>>hex>>test;
printf("test 0x%x \n", (unsigned char)test);
cout<<"HEX :"<<hex<<test<<endl;
cout<<"DEC :"<<dec<<test<<endl;
cout<<"BYTE HEX :"<<hex<<char(test)<<endl;
cout<<"BYTE DEC :"<<dec<<BYTE(test)<<endl;
//blub = test;
cout<<"HEX blub: "<<hex<<blub<<endl;*/
if(argc == 1){
cout<<"No target device defined !"<<endl;
cout<<"example : scumil tcp/scuxl0089.acc"<<endl;
cout<<"end"<<endl;
return 0;
}
int choice = 0;
bool run = true;
// generator starten
srand((unsigned)time(NULL));
// status = myscu.scu_milbusopen("tcp/scuxl0089.acc", errorstatus);
status = myscu.scu_milbusopen(argv[1], errorstatus);
error_str = myscu.scu_milerror(status);
cout <<"open scu : "<<error_str<<endl;
if (status != status_ok){
return 0;
}
// -------------------------
do{
choice = print_menue();
switch (choice)
{
case 1:
scan_milbus_loop(myscu);
break;
case 2:
write_data(myscu);
break;
case 3:
write_cmd(myscu);
break;
case 4:
read_data(myscu);
break;
case 5:
write_ifk(myscu);
break;
case 6:
read_ifk(myscu);
break;
case 7:
cout<<endl<<"IFKs online:"<<endl;
cout<<"----------------"<<endl;
echo_test(myscu,choose_ifk(myscu));
break;
default : run = false;
break;
}
}while (run);
// -------------------------
status = myscu.scu_milbusclose(errorstatus);
error_str = myscu.scu_milerror(status);
cout <<"close scu : "<<error_str<<endl;
return 0;
}
示例12: main
//.........这里部分代码省略.........
vect_free(subdispdt);
}
/* Allocate our data array and start getting data */
if (myid == 0) {
printf("De-dispersing using %d subbands.\n", cmd->nsub);
if (cmd->downsamp > 1)
printf("Downsampling by a factor of %d (new dt = %.10g)\n",
cmd->downsamp, dsdt);
printf("\n");
}
/* Print the nodes and the DMs they are handling */
print_dms(hostname, myid, numprocs, local_numdms, dms);
outdata = gen_fmatrix(local_numdms, worklen / cmd->downsamp);
numread = get_data(outdata, blocksperread, &s,
&obsmask, idispdt, offsets, &padding);
while (numread == worklen) {
numread /= cmd->downsamp;
if (myid == 0)
print_percent_complete(totwrote, totnumtowrite);
/* Write the latest chunk of data, but don't */
/* write more than cmd->numout points. */
numtowrite = numread;
if (cmd->numoutP && (totwrote + numtowrite) > cmd->numout)
numtowrite = cmd->numout - totwrote;
if (myid > 0) {
write_data(outfiles, local_numdms, outdata, 0, numtowrite);
/* Update the statistics */
if (!padding) {
for (ii = 0; ii < numtowrite; ii++)
update_stats(statnum + ii, outdata[0][ii], &min, &max, &avg, &var);
statnum += numtowrite;
}
}
totwrote += numtowrite;
/* Stop if we have written out all the data we need to */
if (cmd->numoutP && (totwrote == cmd->numout))
break;
numread = get_data(outdata, blocksperread, &s,
&obsmask, idispdt, offsets, &padding);
}
datawrote = totwrote;
} else { /* Main loop if we are barycentering... */
/* What ephemeris will we use? (Default is DE200) */
if (cmd->de405P)
strcpy(ephem, "DE405");
else
strcpy(ephem, "DE200");
/* Define the RA and DEC of the observation */
ra_dec_to_string(rastring, idata.ra_h, idata.ra_m, idata.ra_s);
ra_dec_to_string(decstring, idata.dec_d, idata.dec_m, idata.dec_s);
示例13: mifare_desfire_write_record_ex
ssize_t
mifare_desfire_write_record_ex (MifareTag tag, uint8_t file_no, off_t offset, size_t length, void *data, int cs)
{
return write_data (tag, 0x3B, file_no, offset, length, data, cs);
}
示例14: fd_read_body
//.........这里部分代码省略.........
if (fd_read_line (fd) == NULL)
ret = -1;
break;
}
}
rdsize = MIN (remaining_chunk_size, dlbufsize);
}
else
rdsize = exact ? MIN (toread - sum_read, dlbufsize) : dlbufsize;
if (progress_interactive)
{
/* For interactive progress gauges, always specify a ~1s
timeout, so that the gauge can be updated regularly even
when the data arrives very slowly or stalls. */
tmout = 0.95;
if (opt.read_timeout)
{
double waittm;
waittm = ptimer_read (timer) - last_successful_read_tm;
if (waittm + tmout > opt.read_timeout)
{
/* Don't let total idle time exceed read timeout. */
tmout = opt.read_timeout - waittm;
if (tmout < 0)
{
/* We've already exceeded the timeout. */
ret = -1, errno = ETIMEDOUT;
break;
}
}
}
}
ret = fd_read (fd, dlbuf, rdsize, tmout);
if (progress_interactive && ret < 0 && errno == ETIMEDOUT)
ret = 0; /* interactive timeout, handled above */
else if (ret <= 0)
break; /* EOF or read error */
if (progress || opt.limit_rate || elapsed)
{
ptimer_measure (timer);
if (ret > 0)
last_successful_read_tm = ptimer_read (timer);
}
if (ret > 0)
{
sum_read += ret;
if (!write_data (out, dlbuf, ret, &skip, &sum_written))
{
ret = -2;
goto out;
}
if (chunked)
{
remaining_chunk_size -= ret;
if (remaining_chunk_size == 0)
if (fd_read_line (fd) == NULL)
{
ret = -1;
break;
}
}
}
if (opt.limit_rate)
limit_bandwidth (ret, timer);
if (progress)
progress_update (progress, ret, ptimer_read (timer));
#ifdef WINDOWS
if (toread > 0 && !opt.quiet)
ws_percenttitle (100.0 *
(startpos + sum_read) / (startpos + toread));
#endif
}
if (ret < -1)
ret = -1;
out:
if (progress)
progress_finish (progress, ptimer_read (timer));
if (elapsed)
*elapsed = ptimer_read (timer);
if (timer)
ptimer_destroy (timer);
if (qtyread)
*qtyread += sum_read;
if (qtywritten)
*qtywritten += sum_written;
free (dlbuf);
return ret;
}
示例15: relay_traffic
//.........这里部分代码省略.........
rc = set_timeouts( ssockfd, dsockfd,
ctx->rcv_tmout, 0,
ctx->snd_tmout, 0 );
if( 0 != rc ) break;
}
if( dsockfd > 0 ) {
rc = sync_dsockbuf_len( ssockfd, dsockfd );
if( 0 != rc ) break;
rc = send_http_response( dsockfd, 200, "OK" );
if( 0 != rc ) break;
/* timeshift: to detect PAUSE make destination
* socket non-blocking, otherwise make it blocking
* (since it might have been set unblocking earlier)
*/
rc = set_nblock( dsockfd, (ALLOW_PAUSES ? 1 : 0) );
if( 0 != rc ) break;
}
data = malloc(data_len);
if( NULL == data ) {
mperror( g_flog, errno, "%s: malloc", __func__ );
break;
}
if( g_uopt.cl_tpstat )
tpstat_init( &tps, SET_PID );
} while(0);
TRACE( (void)tmfprintf( g_flog, "Relaying traffic from socket[%d] "
"to socket[%d], buffer size=[%d], Rmsgs=[%d], pauses=[%d]\n",
ssockfd, dsockfd, data_len, g_uopt.rbuf_msgs, ALLOW_PAUSES) );
/* RELAY LOOP
*/
ropt.max_frgs = g_uopt.rbuf_msgs;
ropt.buf_tmout = g_uopt.dhold_tmout;
pause_time = 0;
while( (0 == rc) && !(quit = must_quit()) ) {
if( g_uopt.mcast_refresh > 0 ) {
check_mcast_refresh( ssockfd, &rfr_tm, mifaddr );
}
nrcv = read_data( &ds, ssockfd, data, data_len, &ropt );
if( -1 == nrcv ) break;
TRACE( check_fragments( "received new", data_len,
lrcv, nrcv, t_delta, g_flog ) );
lrcv = nrcv;
if( dsockfd && (nrcv > 0) ) {
nsent = write_data( &ds, data, nrcv, dsockfd );
if( -1 == nsent ) break;
if ( nsent < 0 ) {
if ( !ALLOW_PAUSES ) break;
if ( 0 != pause_detect( nsent, MAX_PAUSE_MSEC, &pause_time ) )
break;
}
TRACE( check_fragments("sent", nrcv,
lsent, nsent, t_delta, g_flog) );
lsent = nsent;
}
if( (dfilefd > 0) && (nrcv > 0) ) {
nwr = write_data( &ds, data, nrcv, dfilefd );
if( -1 == nwr )
break;
TRACE( check_fragments( "wrote to file",
nrcv, lsent, nwr, t_delta, g_flog ) );
lsent = nwr;
}
if( ds.flags & F_SCATTERED ) reset_pkt_registry( &ds );
if( uf_TRUE == g_uopt.cl_tpstat )
tpstat_update( ctx, &tps, nsent );
} /* end of RELAY LOOP */
/* CLEANUP
*/
TRACE( (void)tmfprintf( g_flog, "Exited relay loop: received=[%ld], "
"sent=[%ld], quit=[%ld]\n", (long)nrcv, (long)nsent, (long)quit ) );
free_dstream_ctx( &ds );
if( NULL != data ) free( data );
if( 0 != (quit = must_quit()) ) {
TRACE( (void)tmfprintf( g_flog, "Child process=[%d] must quit\n",
getpid()) );
}
return rc;
}