-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
321 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include <define.h> | ||
#include <Flowmeter.h> | ||
#include <Wire.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
#ifndef GSAAIO_DEFINES_H | ||
#define GSAAIO_DEFINES_H | ||
|
||
#include <SoftwareSerial.h> | ||
#include <Arduino.h> | ||
|
||
|
||
// extern SoftwareSerial mySerial(5, 6); | ||
// #define SLAVE_SERIAL mySerial | ||
|
||
// #define DEBUG_SERIAL Serial | ||
// #define DBGprint(...) Serial.print(__VA_ARGS__) | ||
// #define DBGprintln(...) Serial.println(__VA_ARGS__) | ||
// | ||
|
||
|
||
#define ADC_NUM 4 | ||
|
||
#define SAMPLE_NUM 800 | ||
#define SAMPLE_DUR 1600 | ||
#define SAMPLE_VALVE_ON 10 | ||
#define SAMPLE_VALVE_OFF 12 | ||
#define SAMPLE_NUM 800 //800 | ||
#define SAMPLE_DUR 1600 //1600 | ||
#define SAMPLE_VALVE_ON 10 //10 | ||
#define SAMPLE_VALVE_OFF 12 //12 | ||
#define SAMPLE_PERIOD 20 | ||
|
||
#define VALVE_SWITCH 12 | ||
#define OLD_PUMP 13 | ||
#define OLD_PUMP 13 | ||
|
||
#endif //GSAAIO_DEFINES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Created by Zhenyi Ye on 2020-01-23. | ||
// | ||
|
||
#include <protoc.h> | ||
#include <AIOapp.h> | ||
|
||
extern AIOapp aiOapp; | ||
extern msgBuff txBuff; | ||
extern msgBuff rxBuff; | ||
|
||
// app configuration | ||
AppConfig appConfig; | ||
|
||
// Functional Command | ||
void parseAirflow(){ | ||
aiOapp.airFlow(appConfig.airspeed); | ||
} | ||
|
||
void parseFragflow(){ | ||
aiOapp.fragFlow(appConfig.fragspeed); | ||
} | ||
|
||
// Debug Command | ||
void parsePumpPwm(){ | ||
uint8_t speed = rxBuff.buff[1]; | ||
aiOapp.airFlow(speed); | ||
} | ||
|
||
void parseValveSet(){ | ||
uint8_t valve_index = rxBuff.buff[1]; | ||
uint8_t valve_state = rxBuff.buff[2]; | ||
if (valve_state == 1) | ||
valve_state = HIGH; | ||
else | ||
valve_state = LOW; | ||
switch (valve_index){ | ||
case 1: | ||
break; | ||
case 2: | ||
break; | ||
case 3: | ||
digitalWrite(VALVE_SWITCH, valve_state); | ||
break; | ||
default: | ||
break; | ||
|
||
} | ||
} | ||
|
||
// Parse Command Function | ||
void parseCommand(){ | ||
|
||
uint8_t command_type = rxBuff.buff[0]; | ||
|
||
switch (command_type){ | ||
|
||
// functional command | ||
case AIRFLOW: | ||
parseAirflow(); | ||
break; | ||
case FRAGFLOW: | ||
parseFragflow(); | ||
break; | ||
case CHAMCLOSE: | ||
break; | ||
|
||
// debug command | ||
case PUMP_PWM: | ||
parsePumpPwm(); | ||
break; | ||
case VALVE_SET: | ||
parseValveSet(); | ||
break; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef GSAAIO_PROTOC_H | ||
#define GSAAIO_PROTOC_H | ||
|
||
#endif //GSAAIO_PROTOC_H | ||
|
||
#include <Arduino.h> | ||
#include "serial.h" | ||
|
||
// DEBUG COMMAND | ||
const uint8_t VALVE_SET = 0xF0; | ||
const uint8_t PUMP_PWM = 0xF1; | ||
|
||
// FUNCTIONAL COMMAND | ||
const uint8_t AIRFLOW = 0x00; | ||
const uint8_t FRAGFLOW = 0x01; | ||
const uint8_t CHAMCLOSE = 0x02; | ||
|
||
|
||
|
||
// Function Header | ||
void parseAirflow(); | ||
void parseFragflow(); | ||
|
||
|
||
void parseValveSet(); | ||
void parsePumpPwm(); | ||
|
||
// Parse Command Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#include <serial.h> | ||
// #include <stdint.h> | ||
// #include <Arduino.h> | ||
|
||
msgBuff rxBuff; | ||
msgBuff txBuff; | ||
bool ser_escape = false; | ||
bool ser_reading = false; | ||
uint8_t rxByte; | ||
|
||
void (*msgHandler)(); | ||
|
||
void setNewMsgCallback(void (*cb)(void)) { | ||
msgHandler = cb; | ||
} | ||
|
||
void parseSerial() | ||
{ | ||
while(mySerial.available()) { | ||
rxByte = mySerial.read(); | ||
// DBGprintln(rxByte, HEX); | ||
if (!ser_escape) { | ||
if (rxByte == '^') { | ||
rxBuff.len = 0; | ||
ser_reading = true; | ||
return; | ||
} | ||
if (rxByte == '?' && ser_reading) { | ||
ser_escape = true; | ||
return; | ||
} | ||
if (rxByte == '\n') { | ||
ser_reading = false; | ||
// DBGprint("Len: "); | ||
// DBGprintln(rxBuff.len); | ||
parseCmd(); | ||
} | ||
} | ||
if (ser_reading && rxBuff.len < S_BUFF_SIZE) { | ||
if (ser_escape) { | ||
ser_escape = false; | ||
} | ||
rxBuff.buff[rxBuff.len++] = rxByte; | ||
return; | ||
} | ||
if (rxBuff.len >= S_BUFF_SIZE) { | ||
rxBuff.len = 0; | ||
ser_reading = false; | ||
ser_escape = false; | ||
} | ||
} | ||
} | ||
|
||
void parseCmd() | ||
{ | ||
|
||
byte our_csum = calcRX_CSum(&rxBuff); | ||
byte snt_csum = rxBuff.buff[rxBuff.len - 1]; | ||
|
||
if (our_csum != snt_csum) { | ||
//complete csum error return | ||
//SLAVE_SERIAL.write("^E\n"); | ||
} | ||
else{ | ||
//SLAVE_SERIAL.println("{\"RESP\":1}"); | ||
|
||
msgHandler(); | ||
} | ||
} | ||
|
||
uint8_t calcRX_CSum(msgBuff *mb) | ||
{ | ||
return calc_CSum(mb->buff, mb->len - 1); | ||
} | ||
|
||
uint8_t calcTX_CSum(msgBuff *mb) | ||
{ | ||
return calc_CSum(mb->buff, mb->len); | ||
} | ||
|
||
uint8_t calc_CSum(uint8_t *buff, uint16_t len) | ||
{ | ||
uint8_t csum = 0; | ||
for (uint16_t i = 0; i < len; i++) | ||
{ | ||
csum ^= *(buff + i); | ||
} | ||
return csum; | ||
} | ||
|
||
|
||
bool msgBuffAddByte(msgBuff *mb, uint8_t b) | ||
{ | ||
if (mb->len < S_BUFF_SIZE) { | ||
mb->buff[mb->len++] = b; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool msgBuffAdd(msgBuff *mb, void * data, uint16_t size) | ||
{ | ||
if (mb->len + size >= S_BUFF_SIZE) | ||
{ | ||
return false; | ||
} | ||
uint8_t *b = (mb->buff + mb->len); | ||
uint8_t *d = (uint8_t *)data; | ||
|
||
for (uint16_t i = 0; i < size; i++) { | ||
*(b + i) = *(d + i); | ||
} | ||
mb->len += size; | ||
return true; | ||
} | ||
|
||
void sendMsgBuff(msgBuff *mb) | ||
{ | ||
uint8_t csum = calcTX_CSum(mb); | ||
msgBuffAddByte(mb,csum); | ||
mySerial.write('^'); | ||
for (uint16_t i = 0; i < mb->len; i++) { | ||
switch (mb->buff[i]) | ||
{ | ||
case '?': | ||
case '^': | ||
case '\n': | ||
mySerial.write('?'); | ||
default: | ||
mySerial.write(mb->buff[i]); | ||
} | ||
} | ||
mySerial.write('\n'); | ||
} | ||
|
||
|
Oops, something went wrong.