English 中文(简体)
• 如何在uint8-t数据上发出信号?
原标题:How to send an int over uint8_t data?

I m 利用电台Head Packet电台的广播图书馆,收音机。 举例来说(nrf24_reliable_datagram_client &服务器),他们允许两条节点相互沟通,发送插头。 现在,我想发出一个声音,而不是加以扼杀,并用这些数据做一些事情。 比如说:

逐项界定。

uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

这项职能收到数据:

manager.recvfromAckTimeout(buf, &len, 500, &from)

印刷制成变。

Serial.print((char*)buf);

迄今情况良好。 现在我想做的是:

int value = (char*)buf;

或:

char value[10] = { (char*)buf };

但当时我得到:

invalid conversion from  char*  to  int  (or to  char ...)

除此之外,在我发送数据的另一方面,我有:

uint8_t data[] = { analogRead(A0) };

当我用第一个问题中的代码在接收方印刷这一数据时,我就有了超常的特性。 因此,我认为,让我们努力:

Serial.print((char*)buf, DEC); // or BYTE

但当时我得到:

call of overloaded  print(char*, int)  is ambiguous

What am I doing wrong? Thanks in advance!

问题回答

You can t just assign an array to an integer and hope that it merges the elements together for you - for example, how does it know how to merge them?

为了将1 uint16_t改为1 uint8_t/12阵列,你希望做这样的事情:

uint16_t analog = analogRead(A0); //read in as int.
uint8_t data[2] = {analog, (analog >> 8)}; // extract as {lower byte, upper byte)
Serial.write(data,2); //write the two bytes to the serial port, lower byte first.

你可以以其他方式这样做,例如利用一个u16的联盟,它有两根u8。 你们也可以这样做,把点推到暗中,然而,如果某一端使用大端,而另一端则使用不大的终点站,那么,除非你照你获得的阵列中的数据。

收受人最终会:

uint8_t data[2];
...
... //whatever you do to receive the bytes that were sent over serial.
...
//Now assuming that data[] contains the received bytes where:
//data[0] was the first in (lower byte) and data[1] was the second in (upper byte)
uint16_t merged = (data[1] << 8) | data[0]; //merge them back together

希望这样做。

此外,超负荷的原型说,不存在任何功能,而这种功能需要特定类型的投入变量。 不过,从印刷班头看,你会发现这种原型:

write(const uint8_t *buffer, size_t size);

你们想要的是——从一阵列中印出一定数量的u8。





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签