可能的记忆问题

时间:2019-05-28 08:46:44

标签: c++

我使用waveshare的SIM7020E NB-IoT HAT并将其示例代码用于Raspberry pi。

根据我对示例代码和注释的理解,他们使用自己的实现串行端口通信,类似于Arduino中使用的通信。

我发现内存有很多错误,以至于我不确定我是否正确理解了代码。

SIM7020X-NB-IoT-HAT-Demo-Code / Raspberry / examples / arduPi.cpp中的几个示例代码

/* Prints data to the serial port as human-readable ASCII text followed
 * by a carriage retrun character '\r' and a newline character '\n' */
void SerialPi::println(float f, int precission){
  const char *str1="%.";
  char * str2;
  char * str3;
  char * message;
  sprintf(str2,"%df",precission);
  asprintf(&str3,"%s%s",str1,str2);
  sprintf(message,str3,f);

  const char *newline="\r\n";
  char * msg = NULL;
  asprintf(&msg,"%s%s",message,newline);
  unistd::write(sd,msg,strlen(msg));
}

/* Prints data to the serial port as human-readable ASCII text followed
* by a carriage retrun character '\r' and a newline character '\n' */
void SerialPi::println(const char *message){
  const char *newline="\r\n";
  char * msg = NULL;
  asprintf(&msg,"%s%s",message,newline);
  unistd::write(sd,msg,strlen(msg));
}

可以从他们的网站https://www.waveshare.com/wiki/File:SIM7020X-NB-IoT-HAT-Demo-Code.7z下载整个代码库

0 个答案:

没有答案