Skip to content

Commit fb8d222

Browse files
committed
Issue#4: Se coloco el enumerado, y se implemento la lectura de los datos en hpmInput
1 parent ede49b0 commit fb8d222

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

src/hpm.c

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ static char rxIdx; //Indice del buffer de recepcion
1010
static bool autosend;
1111
static uint16_t pm25;
1212
static uint16_t pm10;
13+
static comandoEnviar_t ultimoComandoEnviado;
14+
15+
typedef enum{
16+
ReadMeasure,
17+
StartMeasure,
18+
StopMeasure,
19+
EnableAutosend,
20+
DisableAutosend
21+
22+
}comandoEnviar_t;
23+
1324

1425
static void enviaOrden (char *const orden, char largo);
1526

@@ -31,26 +42,32 @@ void hpmChangeAutosend (bool enable) {
3142
}
3243

3344
void hpmSendReadMeasure(void) {
45+
ultimoComandoEnviado=ReadMeasure;
3446
const char orden[] = {0x68,0x01,0x04,0x93};
3547
enviaOrden(orden,4);
3648
}
3749

3850
void hpmSendStartMeasure(void) {
51+
ultimoComandoEnviado=StartMeasure;
3952
const char orden[] = {0x68,0x01,0x01,0x96};
4053
enviaOrden(orden,4);
54+
4155
}
4256

4357
void hpmSendStopMeasure(void) {
58+
ultimoComandoEnviado=StopMeasure;
4459
const char orden[] = {0x68,0x01,0x02,0x95};
4560
enviaOrden(orden,4);
4661
}
4762

4863
void hpmSendEnableAutoSend(void) {
64+
ultimoComandoEnviado=EnableAutosend;
4965
const char orden[] = {0x68,0x01,0x40,0x57};
5066
enviaOrden(orden,4);
5167
}
5268

5369
void hpmSendDisableAutoSend(void) {
70+
ultimoComandoEnviado=DisableAutosend;
5471
const char orden[] = {0x68,0x01,0x20,0x77};
5572
enviaOrden(orden,4);
5673
}
@@ -68,11 +85,11 @@ uint16_t getLastPM25 (void)
6885
/*
6986
//Quizas no sea necesario este bloque de codigo, teniendo en cuenta la descripcion
7087
//de la funcion HPMinput() - TODO: Eliminar este comentario, de ser necesario
71-
if (modo == true){
88+
if (autosend == true){
7289
pm25=(carga[6]<<8)+carga[7];
7390
}
7491
else{
75-
ReadMeasure();
92+
hpmSendReadMeasure();
7693
pm25=(carga[3]<<8)+carga[4];
7794
}
7895
// */
@@ -84,17 +101,17 @@ uint16_t getLastPM10(void)
84101
/*
85102
//Quizas no sea necesario este bloque de codigo, teniendo en cuenta la descripcion
86103
//de la funcion HPMinput() - TODO: Eliminar este comentario, de ser necesario
87-
if (modo == true){
104+
if (autosend == true){
88105
pm10=(carga[8]<<8)+carga[9];
89106
}
90107
else{
91-
ReadMeasure();
108+
hpmSendReadMeasure();
92109
pm10=(carga[5]<<8)+carga[6];
93110
}
94111
// */
95112
return pm10;
96113
}
97-
114+
/*
98115
void HPMinput(char octeto) {
99116
if (rxIdx < RXBUFLEN) {
100117
rxBuffer[rxIdx++] = octeto;
@@ -106,15 +123,52 @@ void HPMinput(char octeto) {
106123
* al comienzo del codigo. Y es en este bloque de codigo que ese "updated"
107124
* se ha de actualizar. Idealmente, se habria de poner a true, cuando
108125
* ya se tengan los octetos suficientes segun el modo y/u orden enviada.
109-
*/
126+
110127
if (autosend) {
111-
//TODO: Procesamiento segun Tabla 5 del Datasheet
128+
/*TODO: Procesamiento segun Tabla 5 del Datasheet
129+
130+
112131
} else {
113-
//TODO: Procesamiento segun Tabla 4 del Datasheet
132+
/*TODO: Procesamiento segun Tabla 4 del Datasheet
133+
134+
114135
}
115136
}
116137
}
138+
*/
117139

140+
void HPMinput(char octeto) {
141+
if (rxIdx < RXBUFLEN) {
142+
rxBuffer[rxIdx++] = octeto;
143+
if (autosend) {
144+
if (rxIdx == RXBUFLEN){
145+
rxBuffer[rxIdx++]=octeto;
146+
pm10=(rxBuffer[8]<<8)+rxBuffer[9];
147+
pm25=(rxBuffer[6]<<8)+rxBuffer[7];
148+
rxIdx=0;
149+
150+
}else{
151+
switch(ultimoComandoEnviado){
152+
case ReadMeasure:
153+
if (rxIdx == RXBUFLEN){
154+
rxBuffer[rxIdx++]=octeto;
155+
pm10=(rxBuffer[5]<<8)+rxBuffer[6];
156+
pm25=(rxBuffer[3]<<8)+rxBuffer[4];
157+
rxIdx=0;
158+
break;
159+
160+
}
161+
162+
}
163+
164+
}
165+
/*TODO: Procesamiento segun Tabla 5 del Datasheet*/
166+
167+
168+
}
169+
}
170+
}
171+
118172
void enviaOrden (char *const orden, char largo) {
119173
handlerEnvio(orden,largo);
120174
rxIdx = 0;

0 commit comments

Comments
 (0)