Esempio n. 1
0
		void init_(bool comrvs) {

			reg_select_(0);
			chip_enable_();

			// toggle RST low to reset; CS low so it'll listen to us
			// if (cs > 0)
    		//     digitalWrite(cs, LOW);

			// digitalWrite(rst, LOW);
			// _delay_ms(500);
			// digitalWrite(rst, HIGH);

			write_(CMD::DISPLAY_OFF);

			// LCD bias select
			write_(CMD::SET_BIAS_7);
			// ADC select
			write_(CMD::SET_ADC_NORMAL);
			// SHL select
			if(comrvs) {
				write_(CMD::SET_COM_REVERSE);
			} else {
				write_(CMD::SET_COM_NORMAL);
			}

			// Initial display line
			write_(CMD::SET_DISP_START_LINE);

			// turn on voltage converter (VC=1, VR=0, VF=0)
			write_(CMD::SET_POWER_CONTROL, 0x4);
			// wait for 50% rising
			utils::delay::milli_second(50);

			// turn on voltage regulator (VC=1, VR=1, VF=0)
			write_(CMD::SET_POWER_CONTROL, 0x6);

			// wait >=50ms
			utils::delay::milli_second(50);

			// turn on voltage follower (VC=1, VR=1, VF=1)
			write_(CMD::SET_POWER_CONTROL, 0x7);

			// wait 10ms
			utils::delay::milli_second(10);

			// set lcd operating voltage (regulator resistor, ref voltage resistor)
			write_(CMD::SET_RESISTOR_RATIO, 0x6);
		}
Esempio n. 2
0
 void readData(){
   write_();
   while(true){
     thread t1(&ArduinoComm2::readDataTask,this);
     t1.join();
   }
 }
Esempio n. 3
0
File: cat.c Progetto: alexkats/Code
int main ()
{
    char buf[size];
    ssize_t rhave = 0;
    ssize_t whave = 0;

    while (1)
    {
        rhave = read_(STDIN_FILENO, buf, size);

        if (rhave == -1)
        {
            fprintf(stderr, "%s\n", strerror(errno));
            return 1;
        }

        whave = write_(STDOUT_FILENO, buf, rhave);

        if (whave == -1)
        {
            fprintf(stderr, "%s\n", strerror(errno));
            return 1;
        }

        if (rhave > whave)
        {
            fprintf(stderr, "Cannot output everything in file\n");
            return 1;
        }

        if (rhave < size)
            return 0;
    }
}
void doWork(int position, int position1){
	char buf[4096];
	char buf1[4096];
	char temp[20];
	struct sigaction sa;
	sigset_t sigsetMask;

	buf[0] = '\0';
 
	sigfillset(&sigsetMask);
	sigdelset(&sigsetMask, SIGUSR1);
	sigprocmask( SIG_BLOCK, &sigsetMask, NULL);
	
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = &ChildSignalHandler;
	CHECK(sigaction(SIGUSR1, &sa, NULL) ==  0);

	while(quit){
		
		lockSem(position);
		read_((char*)&buf1); //precita obsah pamate
		sprintf((char*)&temp, "%u\n", getpid()); ///vytvori string z PID
		// fprintf(stderr, "PID:%s", temp);
		strcat((char*)&buf, (char*)&buf1); //spoji dokopy
		// fprintf(stderr, "@SHARED:%s", buf);
		strcat((char*)&buf, (char*)&temp);
		// fprintf(stderr, "2SHARED:%s", buf);
		write_((char*)&buf, strlen(buf));
		sleep(1);
		unlockSem(position1);
		buf[0] = '\0'; //premazanie
	}
	fprintf(stderr, "Killed %u\n", getpid());
}
static void save_hdr(Tfsekop_transact *sekop_transact)
{
	lseek_(sekop_transact, sekop_transact->offs, SEEK_SET);
	IF_ERROR_RETURN();
	sekop_transact->hdr.crc = hdr_crc(&sekop_transact->hdr);
	write_(sekop_transact, &sekop_transact->hdr, sizeof(Tfsekop_transact_hdr));
}
Esempio n. 6
0
	void write(uword_t inByteCount, void *inData)
		{
		if (inByteCount == 0)
			return;

		mPosition += inByteCount;

		while (inByteCount)
			{
			if (mBufferBytesUsed + inByteCount < mBufferSize)
				{
				memcpy(mBufPtr + mBufferBytesUsed, inData, inByteCount);
				mBufferBytesUsed += inByteCount;
				inByteCount = 0;
				}
			else
				{
				long bytesToFinishBuffer = mBufferSize - mBufferBytesUsed;

				memcpy(mBufPtr + mBufferBytesUsed, inData, bytesToFinishBuffer);

				write_(mBufferSize, mBufPtr);

				mBufferBytesUsed = 0;

				inByteCount -= bytesToFinishBuffer;

				inData = (char*)inData + bytesToFinishBuffer;
				}
			}
		}
Esempio n. 7
0
void del_person()
{
    printf("请输入要删除联系人的编号:");
    int n;
    scanf("%d",&n);
    if (n==1)
    {
        for (int i=0; i<=c; i++)
        {
            strcpy((persons+i)->name, (persons+(i+1))->name);
            strcpy((persons+i)->phone, (persons+(i+1))->phone);
        }
        c--;
    }
    else if (n==c)
    {
        c--;
    }
    else
    {
        for (int i=n; i<=c; i++)
        {
            strcpy((persons+(n-1))->name, (persons+n)->name);
            strcpy((persons+(n-1))->phone, (persons+n)->phone);
        }
        c--;
    }
    write_();
    printf("删除联系人成功!\n");
}
Esempio n. 8
0
	~OFileDescriptorProtocol()
		{
		if (mBufferBytesUsed)
			{
			lassert(mAlignment > 0);

			if (mBufferBytesUsed % mAlignment)
				{
				memset(mBufPtr + mBufferBytesUsed, 0, mAlignment - mBufferBytesUsed % mAlignment);

				mBufferBytesUsed += mAlignment - mBufferBytesUsed % mAlignment;
				}

			try {
				write_(mBufferBytesUsed, mBufPtr);
				}
			catch(std::logic_error& e)
				{
				LOG_CRITICAL << "Exception thrown while flushing an OFileDescriptorProtocol:\n"
					<< e.what();
				}
			catch(...)
				{
				LOG_CRITICAL << "Unknown exception thrown while flushing an OFileDescriptorProtocol\n";
				}
			}

		if (mCloseOnDestroy == CloseOnDestroy::True)
			close(mFD);
		}
Esempio n. 9
0
void EventBase::Response(int aSockid) {
    if (write_) {
        if (RET_ERROR == write_(aSockid)) {
            ErrSocket(aSockid);
        }        
    }
}
Esempio n. 10
0
void file_sekop_write_transact_block(Tfsekop_transact *sekop_transact, const void *packet, int packet_size, int packet_num, time_t fin_time)
{
	sekop_transact->res = FSEKOP_TRANSACT_OK;
	if(sekop_transact->opened != 1) {
		sekop_transact->res = FSEKOP_TRANSACT_ENOPEN;
		return;
	}
	if(sekop_transact->hdr.pnum >= packet_num) {
		sekop_transact->res = FSEKOP_TRANSACT_EEXIST;
		return;
	}
	int written_size = sekop_transact->hdr.size;
	if((written_size + packet_size) > sekop_transact->size) {
		sekop_transact->res = FSEKOP_TRANSACT_ENOSPC;
		return;
	}
	lseek_(sekop_transact, buff_offset(sekop_transact) + written_size, SEEK_SET);
	IF_ERROR_RETURN();
	write_(sekop_transact, packet, packet_size);
	IF_ERROR_RETURN();
	sekop_transact->hdr.size = written_size + packet_size;
	sekop_transact->hdr.pnum = packet_num;
	sekop_transact->hdr.time = fin_time;
	save_hdr(sekop_transact);
}
size_t RingBufferStream::write(const char *buffer, size_t size)
{
	for(uint32_t i=0; i<size; i++)
	{
		write_(buffer[i]);
	}
	if(observer) observer->data_arrival(size);
	return size;
}
Esempio n. 12
0
void use_device(struct reader *reader, struct writer *writer, struct device *d)
    /*@
    requires
        reader(reader) &*& writer(writer) &*& lockset(currentThread, nil) &*&
        [?f1]d->ops |-> ?ops &*& [f1]file_ops(ops, ?device, ?file_) &*&
        [?f2]device();
    @*/
    /*@
    ensures
        reader(reader) &*& writer(writer) &*& lockset(currentThread, nil) &*&
        [f1]d->ops |-> ops &*& [f1]file_ops(ops, device, file_) &*&
        [f2]device();
    @*/
{
    //@ open file_ops(ops, _, _);
    device_open *open_ = d->ops->open_;
    device_close *close_ = d->ops->close_;
    void *file = open_();
    bool exitMenu = false;
    while (!exitMenu)
        /*@
        invariant
            reader(reader) &*& writer(writer) &*& file_(f2, file) &*& lockset(currentThread, nil) &*&
            [f1]d->ops |-> ops &*&
            [f1]ops->read |-> ?read &*& [f1]ops->write |-> ?write &*&
            [_]is_device_read(read, file_) &*&
            [_]is_device_write(write, file_);
        @*/
    {
        int choice = 0;
        writer_write_string(writer,
            "Device Menu:\r\n"
            "1. Read Value\r\n"
            "2. Write Value\r\n"
            "0. Exit\r\n");
        choice = reader_read_nonnegative_integer(reader);
        if (choice == 1) {
            device_read *read_ = d->ops->read;
            int value = read_(file);
            writer_write_string(writer, "Value read: ");
            writer_write_integer_as_decimal(writer, value);
            writer_write_string(writer, "\r\n");
        } else if (choice == 2) {
            int value = 0;
            device_write *write_ = d->ops->write;
            writer_write_string(writer, "Enter value:\r\n");
            value = reader_read_nonnegative_integer(reader);
            write_(file, value);
            writer_write_string(writer, "The value has been written\r\n");
        } else {
            exitMenu = true;
        }
    }
    close_(file);
    //@ close [f1]file_ops(ops, device, file_);
}
Esempio n. 13
0
void add_person()
{
    printf("请输入第%d姓名:",c+1);
    scanf("%s",(persons+c)->name);
    printf("请输入第%d电话:",c+1);
    scanf("%s",(persons+c)->phone);
    c++;
    write_();
    printf("添加联系人成功!\n");
}
Esempio n. 14
0
void BufferEvent::setRespBuffer(int aSockid, Slice aMsg) {
    if (outputs_.find(aSockid) == outputs_.end()) {
        outputs_.insert(std::make_pair(aSockid,
            std::move(std::unique_ptr<Buffer>(new Buffer()))));
    }
    if (write_) {
        int nouse = 0;
        // this is encode function.
        write_(nouse, *(outputs_[aSockid].get()), aMsg);
    }
    else {
        outputs_[aSockid]->append(aMsg.data(), aMsg.size());
    }
}
Esempio n. 15
0
File: qlog.c Progetto: Zengwn/qlibc
/**
 * qlog->writef(): Log messages
 *
 * @param log       a pointer of qlog_t
 * @param format    messages format
 *
 * @return true if successful, otherewise returns false
 */
static bool writef(qlog_t *log, const char *format, ...) {
    if (log == NULL || log->fp == NULL)
        return false;

    char *str;
    DYNAMIC_VSPRINTF(str, format);
    if (str == NULL)
        return false;

    bool ret = write_(log, str);

    free(str);
    return ret;
}
Esempio n. 16
0
int main(int argc, char *argv[])
{
    if (argc < 3) {
        write_(STDOUT_FILENO, "Usage:\n    filesender port file\n", 32);
        return 0;
    }

    struct sigaction sa;
    bzero(&sa, sizeof(sa));
    sa.sa_handler = SIG_IGN;
    sa.sa_flags = SA_RESTART;
    CATCH_IO(sigaction(SIGCHLD, &sa, NULL));
    
    CATCH_IO(access(argv[2], R_OK | F_OK));

    int sock;
    CATCH_IO(sock = make_server_socket(argv[1]));
    CATCH_IO(listen(sock, 1));

    struct sockaddr_in client;
    socklen_t len = sizeof(client);
    while(1) {
        int remote, pid;
        CATCH_IO(remote = accept(sock, (struct sockaddr*) &client, &len));
        CATCH_IO(pid = fork());

        if (pid == 0) {
            int file;

            CATCH_IO(file = open(argv[2], O_RDONLY));
            int s = cat(file, remote);
            int exit_status = 0;

            if (s == -1) {
                perror("Error while sending file");
                exit_status = 1;
            }

            close(remote);
            close(file);
            _exit(exit_status);
        }

        CATCH_IO(close(remote));
    }

    CATCH_IO(close(sock));
    return 0;
}
Esempio n. 17
0
void repair_person()
{
    printf("请输入要修改联系人的编号:");
    int n;
    scanf("%d",&n);
    printf("请输入要修改联系人的姓名:");
    char ch[13];
    scanf("%s",ch);
    strcpy((persons+(n-1))->name,ch);
    printf("请输入要修改联系人的电话:");
    scanf("%s",ch);
    strcpy((persons+(n-1))->phone,ch);
    write_();
    printf("修改联系人成功!\n");
}
Esempio n. 18
0
void find_person()
{
    printf("请输入要查找联系人的姓名:");
    char ch[13];
    scanf("%s",ch);
    int a=0;
    for (int i=0; i<c; i++)
    {
        if (strcmp((persons+i)->name, ch)==0)
        {
            printf("%s\t",(persons+i)->name);
            printf("%s\n",(persons+i)->phone);
            a=1;
        }
    
    }
    if(a==0)
    {
        printf("没有此人!");
    }
    write_();
    printf("查找联系人成功!\n");
}
 void SOLAIRE_EXPORT_CALL writeI64(const int64_t aValue) throw() override {
     write_(&aValue, sizeof(int64_t));
 }
size_t RingBufferStream::write( const uint8_t uc_data )
{
	int ret = write_(uc_data);
	if(observer) observer->data_arrival(1);
	return ret;
}
Esempio n. 21
0
 void write(T const& value) {
   BOOST_STATIC_ASSERT(boost::is_fundamental<T>::value);
   unsafe_cast<T> cast(value);
   endian<T_is_big_endian>::swap(cast.begin(), cast.end());
   write_(cast.data(), cast.size());
 }
Esempio n. 22
0
/*
 * Form a shell temporary file (in unit 0) from the words
 * of the shell input up to a line the same as "term".
 * Unit 0 should have been closed before this call.
 */
void
heredoc(tchar *term)
{
	int c;
	tchar *Dv[2];
	tchar obuf[BUFSIZ], lbuf[BUFSIZ], mbuf[BUFSIZ];
	int ocnt, lcnt, mcnt;
	tchar *lbp, *obp, *mbp;
	tchar **vp;
	bool quoted;
	tchar shtemp[] = {'/', 't', 'm', 'p', '/', 's', 'h', 'X', 'X', 'X',
'X', 'X', 'X', 0};
	int fd1;

#ifdef TRACE
	tprintf("TRACE- heredoc()\n");
#endif
	if ((fd1 = mkstemp_(shtemp)) < 0)
		Perror(shtemp);
	(void) unlink_(shtemp);			/* 0 0 inode! */
	unsetfd(fd1);
	Dv[0] = term; Dv[1] = NOSTR; gflag = 0;
	trim(Dv); rscan(Dv, Dtestq); quoted = gflag;
	ocnt = BUFSIZ; obp = obuf;
	for (;;) {
		/*
		 * Read up a line
		 */
		lbp = lbuf; lcnt = BUFSIZ - 4;
		for (;;) {
			c = readc(1);		/* 1 -> Want EOF returns */
			if (c < 0) {
				setname(term);
				bferr("<< terminator not found");
			}
			if (c == '\n')
				break;
			if (c &= TRIM) {
				*lbp++ = c;
				if (--lcnt < 0) {
					setname(S_LESLES /* "<<" */);
					error("Line overflow");
				}
			}
		}
		*lbp = 0;

		/*
		 * Compare to terminator -- before expansion
		 */
		if (eq(lbuf, term)) {
			(void) write_(0, obuf, BUFSIZ - ocnt);
			(void) lseek(0, (off_t)0, 0);
			return;
		}

		/*
		 * If term was quoted or -n just pass it on
		 */
		if (quoted || noexec) {
			*lbp++ = '\n'; *lbp = 0;
			for (lbp = lbuf; c = *lbp++; ) {
				*obp++ = c;
				if (--ocnt == 0) {
					(void) write_(0, obuf, BUFSIZ);
					obp = obuf; ocnt = BUFSIZ;
				}
			}
			continue;
		}

		/*
		 * Term wasn't quoted so variable and then command
		 * expand the input line
		 */
		Dcp = lbuf; Dvp = Dv + 1; mbp = mbuf; mcnt = BUFSIZ - 4;
		for (;;) {
			c = DgetC(DODOL);
			if (c == DEOF)
				break;
			if ((c &= TRIM) == 0)
				continue;
			/* \ quotes \ $ ` here */
			if (c == '\\') {
				c = DgetC(0);
/*				if (!any(c, "$\\`")) */
				if ((c != '$') && (c != '\\') && (c != '`'))
					unDgetC(c | QUOTE), c = '\\';
				else
					c |= QUOTE;
			}
			*mbp++ = c;
			if (--mcnt == 0) {
				setname(S_LESLES /* "<<" */);
				bferr("Line overflow");
			}
		}
		*mbp++ = 0;

		/*
		 * If any ` in line do command substitution
		 */
		mbp = mbuf;
		if (any('`', mbp)) {
			/*
			 * 1 arg to dobackp causes substitution to be literal.
			 * Words are broken only at newlines so that all blanks
			 * and tabs are preserved.  Blank lines (null words)
			 * are not discarded.
			 */
			vp = dobackp(mbuf, 1);
		} else
			/* Setup trivial vector similar to return of dobackp */
			Dv[0] = mbp, Dv[1] = NOSTR, vp = Dv;

		/*
		 * Resurrect the words from the command substitution
		 * each separated by a newline.  Note that the last
		 * newline of a command substitution will have been
		 * discarded, but we put a newline after the last word
		 * because this represents the newline after the last
		 * input line!
		 */
		for (; *vp; vp++) {
			for (mbp = *vp; *mbp; mbp++) {
				*obp++ = *mbp & TRIM;
				if (--ocnt == 0) {
					(void) write_(0, obuf, BUFSIZ);
					obp = obuf; ocnt = BUFSIZ;
				}
			}
			*obp++ = '\n';
			if (--ocnt == 0) {
				(void) write_(0, obuf, BUFSIZ);
				obp = obuf; ocnt = BUFSIZ;
			}
		}
		if (pargv)
			blkfree(pargv), pargv = 0;
	}
}
 void SOLAIRE_EXPORT_CALL writeC(const char aValue) throw() override {
     write_(&aValue, sizeof(char));
 }
 void SOLAIRE_EXPORT_CALL writeD(const double aValue) throw() override {
     write_(&aValue, sizeof(double));
 }
 void SOLAIRE_EXPORT_CALL writeF(const float aValue) throw() override {
     write_(&aValue, sizeof(float));
 }
Esempio n. 26
0
bool writeString(int socket, const std::string& str){
    if (socket == -1)
        return false;
    return write_(socket,str.c_str(), str.length()) >= 0;
}
 void SOLAIRE_EXPORT_CALL write(const void* const aPtr, const uint32_t aBytes) throw() override {
     write_(aPtr, aBytes);
 }
Esempio n. 28
0
 void write_string(std::string const& value) {
   write_(value.data(), value.size());
 }
Esempio n. 29
0
bool writeBytes(int socket, char *buf, int len){
    if (socket == -1)
        return false;
    return write_(socket, buf, len);
}
 void SOLAIRE_EXPORT_CALL writeU32(const uint32_t aValue) throw() override {
     write_(&aValue, sizeof(uint32_t));
 }