Hello
i’m writing application that GET/SET string value in a main string named “_pacchetto”.
//example:
before: pacchetto "$#______________________________________$"
SET_Tipo_Mittente(“03”);
after: pacchetto "$#03#______________________________________$"
before: pacchetto "$#______________________________________$"
SET_Mittente(“ABCDE”);
after: pacchetto "$#ABCDE#___________________________________$"
Could you suggest better way to do it?
Better means less memory usage
//==================================================================================
//FILE .h
//==================================================================================
class Pacchetto_DT
{
public:
//Costruttore
Pacchetto_DT(void);
//Mittente
void SET_Tipo_Mittente(String tipo_mittente);
String GET_Tipo_Mittente(void);
void SET_Mittente(String mittente);
String GET_Mittente(void);
private:
String _pacchetto;
byte _indice_di_scavalcamento;
};
//==================================================================================
//FINE FILE .h
//==================================================================================
//==================================================================================
//FILE .cpp
//==================================================================================
//Costruttore.......................................................................
Pacchetto_DT::Pacchetto_DT(void)
{
_pacchetto"$#_______________________________________$"
}
//...............................................................................
//SET Tipo Mittente..................................................................
void Pacchetto_DT::SET_Tipo_Mittente(String tipo_mittente)
{
_indice_di_scavalcamento = INDICE_Tipo_Mittente + LUNGHEZZA_Tipo_Mittente ;
_pacchetto = _pacchetto.substring(0,INDICE_Tipo_Mittente ) + tipo_mittente + _pacchetto.substring(_indice_di_scavalcamento, 255 - _indice_di_scavalcamento);
}//.................................................................................
//GET Tipo Mittente.................................................................
String Pacchetto_DT::GET_Tipo_Mittente(void)
{
return _pacchetto.substring(2, 2);
}//.................................................................................
//SET Mittente......................................................................
void Pacchetto_DT::SET_Mittente(String mittente)
{
_indice_di_scavalcamento = INDICE_Mittente + LUNGHEZZA_Mittente + 1;
_pacchetto = _pacchetto.substring(0, INDICE_Mittente) + mittente + Delimitatore_Campo + _pacchetto.substring(_indice_di_scavalcamento, 255 - _indice_di_scavalcamento);
}//.................................................................................
//GET Mittente.....................................................................
String Pacchetto_DT::GET_Mittente(void)
{
return _pacchetto.substring(4, 5);
}//.................................................................................
//==================================================================================
//FINE FILE-cpp
//==================================================================================
//==================================================================================
//PROGRAMMA PRINCIPALE
//==================================================================================
#include "Arduino.h"
Pacchetto_DT DT;
String temp;
void setup()
{
/*
// initialize the serial communication:
serial.init(0, 9600);
serial.setPacketHandler(handlePacket);
// Initialize the send buffer that we will use to send data
send_buffer.init(255);
if( !serial.isBusySending() ){
//Pulisco il Buffer
send_buffer.clear()
*/
Serial.begin(9600);
Serial.println("----------------");
Serial.println("Test Classe DT 7");
Serial.println("----------------");
//SET Mittente
Serial.println("SET Tipo Mittente[2]= 03");
DT.SET_Tipo_Mittente("03");
Serial.println("SET Mittente[4]= ABCDE");
DT.SET_Mittente("ABCDE");
//SET Destinatario
Serial.println("SET Tipo Destinatario[10] = 00");
DT.SET_Tipo_Destinatario("00");
Serial.println("SET Destinatario[12] = FGHIL");
DT.SET_Destinatario("FGHIL");
}
void loop()
{
/* add main program code here */
}