Commit 84941a64 authored by Lindenberg, Arthur-Vincent's avatar Lindenberg, Arthur-Vincent
Browse files

Progammed a GPIO Pin Wrapper method in the oscilloscope.c file

parent 69061608
......@@ -20,6 +20,105 @@ osc_configuration_start_t cs;
struct timespec preAcqSleep;
struct timespec postAcqSleep;
/*
Redpitiaya GPIO-Pin-table corresponding to enums in rp.h
*/
const char *etable[] = {
"RP_LED0",
"RP_LED1",
"RP_LED2",
"RP_LED3",
"RP_LED4",
"RP_LED5",
"RP_LED6",
"RP_LED7",
"RP_DIO0_P",
"RP_DIO1_P",
"RP_DIO2_P",
"RP_DIO3_P",
"RP_DIO4_P",
"RP_DIO5_P",
"RP_DIO6_P",
"RP_DIO7_P",
"RP_DIO0_N",
"RP_DIO1_N",
"RP_DIO2_N",
"RP_DIO3_N",
"RP_DIO4_N",
"RP_DIO5_N",
"RP_DIO6_N",
"RP_DIO7_N",
NULL };
/*
parse char string to enum of the type rp_dpin_t
*/
rp_dpin_t find_enum(char *sval)
{
rp_dpin_t result=RP_LED0; // value corresponding to etable[0]
int i=0;
for (i=0; etable[i]!=NULL; ++i, ++result)
if (0==strcmp(sval, etable[i])) return result;
return -1;
}
/*
int8_t parse_gpio(const struct mosquitto_message *msg)
- parse given mqtt message for gpio purposes
returns 1 if the message belongs to gpio
returns -1 if the message does not belong to gpio
*/
int8_t parse_gpio (const struct mosquitto_message *msg) {
char* curr_root_topic = append_topic_str(mqtt_root_topic_base, "CONFIGURE/GPIO");
if(strcmp(append_topic_str(curr_root_topic, "OUTPUT"), msg->topic) == 0) {
rp_dpin_t dPin = find_enum((char*)msg->payload);
rp_DpinSetDirection(dPin, RP_OUT);
}
else if(strcmp(append_topic_str(curr_root_topic, "INPUT"), msg->topic) == 0) {
rp_dpin_t dPin = find_enum((char*)msg->payload);
rp_DpinSetDirection(dPin, RP_IN);
}
else if(strcmp(append_topic_str(curr_root_topic, "HIGH"), msg->topic) == 0) {
rp_dpin_t dPin = find_enum((char*)msg->payload);
rp_DpinSetState(dPin, RP_HIGH);
}
else if(strcmp(append_topic_str(curr_root_topic, "LOW"), msg->topic) == 0) {
rp_dpin_t dPin = find_enum((char*)msg->payload);
rp_DpinSetState(dPin, RP_LOW);
}
else if(strcmp(append_topic_str(curr_root_topic, "LEDHIGH"), msg->topic) == 0) {
rp_dpin_t dPin = find_enum((char*)msg->payload);
rp_DpinSetState(dPin, RP_HIGH);
}
else if(strcmp(append_topic_str(curr_root_topic, "LEDLOW"), msg->topic) == 0) {
rp_dpin_t dPin = find_enum((char*)msg->payload);
rp_DpinSetState(dPin, RP_LOW);
}
else {
//rp_DpinSetState(RP_LED0, RP_HIGH);
return -1;
}
return 1; //leave function --> one of the if cases was reached
}
/*
int8_t parse_osc(const struct mosquitto_message *msg)
- parse given mqtt message for oscilloscope purposes
......@@ -211,14 +310,24 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m
if(parse_osc(mosq, msg) > 0) {
return;
}
if(parse_gpio(msg) > 0) {
//mosquitto_publish(mosq, NULL, append_topic_str(mqtt_root_topic_base, "TEST"), strlen("GPIO_STRING"), "GPIO_STRING", 0, true);
return;
}
}
int main(int argc, char **argv){
if(init_mqtt(on_message) < 0) {
printf("Can't initialize mqtt");
return -1;
}
mosquitto_publish(my_mosq, NULL, append_topic_str(mqtt_root_topic_base, "STATE"), strlen("START"), "START", 0, true);
/* Print error, if rp_Init() function failed */
......@@ -237,8 +346,18 @@ int main(int argc, char **argv){
rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
/*
rp_DpinSetState(RP_LED1, RP_HIGH);
rp_DpinSetDirection(RP_DIO2_P, RP_OUT);
rp_DpinSetDirection(RP_DIO2_N, RP_OUT);
rp_DpinSetState(RP_DIO2_P, RP_HIGH);
rp_DpinSetState(RP_DIO2_N, RP_HIGH);
*/
// Main Loop
while(shutdown < 1) {
if(stop_osc > 0) {
osc_running = 0;
sleep(1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment