Skip to content
Snippets Groups Projects
Commit 2065fe0d authored by Luca Erbetta's avatar Luca Erbetta :rocket:
Browse files

Moved homeone scripts & added event header generator

parent 1ba43ea7
No related merge requests found
......@@ -23,3 +23,5 @@ build
*.sublime-project
.vscode/*
store.json
\ No newline at end of file
/* Copyright (c) 2018 Skyward Experimental Rocketry
* Authors: Luca Erbetta
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
******************************************************************************
* THIS FILE IS AUTOGENERATED. DO NOT EDIT. *
******************************************************************************
*/
// Generated from: {sheet_link}
// Autogen date: {date}
#ifndef SRC_SHARED_BOARDS_HOMEONE_EVENTS_H
#define SRC_SHARED_BOARDS_HOMEONE_EVENTS_H
#include <string>
#include <map>
#include "events/Event.h"
#include "HomeoneEventClasses.h"
using std::string;
using std::map;
namespace HomeoneBoard
{{
/**
* Definition of all events in the Homeone Board software
* Refer to section 5.1.1 of the Software Design Document.
*/
enum Events : uint8_t
{{
{enum_data}
}};
/**
* @brief Returns the name of the provided event
*
* @param event
* @return string
*/
string getEventString(uint8_t event)
{{
static const map<uint8_t, string> event_string_map {{
{map_data}
}};
auto it = event_string_map.find(event);
return it == event_string_map.end() ? "EV_EMPTY" : it->second;
}}
}}
#endif /* SRC_SHARED_BOARDS_HOMEONE_EVENTS_H */
/* Copyright (c) 2018 Skyward Experimental Rocketry
* Authors: Luca Erbetta
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
******************************************************************************
* THIS FILE IS AUTOGENERATED. DO NOT EDIT. *
******************************************************************************
*/
// Generated from: {sheet_link}
// Autogen date: {date}
#ifndef SRC_SHARED_BOARDS_HOMEONE_TOPICS_H
#define SRC_SHARED_BOARDS_HOMEONE_TOPICS_H
#include <stdint.h>
#include <map>
#include <string>
using std::map;
using std::string;
namespace HomeoneBoard
{{
/**
* Definition of various event topics to use in the EventBroker
*/
enum Topics : uint8_t
{{
{enum_data}
}};
/**
* @brief Returns the name of the provided event
*
* @param event
* @return string
*/
string getTopicString(uint8_t topic)
{{
static const map<uint8_t, string> event_string_map{{
{map_data}
}};
auto it = event_string_map.find(event);
return it == event_string_map.end() ? "TOPIC_UNKNOWN" : it->second;
}}
}} // namespace HomeoneBoard
#endif /* SRC_SHARED_BOARDS_HOMEONE_TOPICS_H_ */
{"installed":{"client_id":"1025168905991-tv31etsgm3lecodc5c798shqciekad40.apps.googleusercontent.com","project_id":"homeone-event-ge-1540834105298","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://www.googleapis.com/oauth2/v3/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"Yhaf67HuHR4DyXZKNXWu2lre","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
\ No newline at end of file
#!/usr/bin/python3
# Copyright (c) 2018 Skyward Experimental Rocketry
# Authors: Luca Erbetta
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import re
import datetime
import sys
SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly'
service = None
SPREADSHEET_ID = '12TecOmDd7Uot-MvXkCbhDJRU48-XO6s5ChKDlr4AOvI'
EVENTS_RANGE_NAME = 'EventList!A2:A'
TOPICS_RANGE_NAME = 'Topics!B3:B'
def auth():
try:
store = file.Storage('store.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
global service
service = build('sheets', 'v4', http=creds.authorize(Http()))
return True
except:
print("Authentication error:", sys.exc_info()[0])
return False
def load_events():
result = service.spreadsheets().values().get(spreadsheetId=SPREADSHEET_ID,
range=EVENTS_RANGE_NAME).execute()
lines = result.get('values', [])
# Event names start with EV_ and contains only uppercase letters or underscores
re_event = re.compile(r'(?P<ev>^EV_([A-Z_]+)+)')
# Only return lines with valid events, remove additional data
events = []
for l in lines:
m = re_event.match(l[0])
if m is not None:
events.append(m.group('ev'))
else:
print("Skipped line containing invalid event: {}".format(l))
return events
def load_topics():
result = service.spreadsheets().values().get(spreadsheetId=SPREADSHEET_ID,
range=TOPICS_RANGE_NAME).execute()
lines = result.get('values', [])
re_topics = re.compile(r'(?P<topic>^TOPIC_([A-Z_]+)+)')
# Only return lines with valid topics, remove additional data
topics = []
for l in lines:
m = re_topics.match(l[0])
if m is not None:
topics.append(m.group('topic'))
else:
print("Skipped line containing invalid topics: {}".format(l))
return topics
def has_duplicates(lst):
if len(lst) != len(set(lst)):
return True
return False
print("Homeone on-board software event header generator v0.2")
print("Google sheets API auth in progress...")
if auth():
print("Auth successfull.")
else:
exit()
print("Reading from: https://docs.google.com/spreadsheets/d/12TecOmDd7Uot-MvXkCbhDJRU48-XO6s5ChKDlr4AOvI")
events = load_events()
topics = load_topics()
# Check duplicates
if has_duplicates(events):
print("Duplicate events found! Terminating.")
exit()
if has_duplicates(topics):
print("Duplicate topics found! Terminating.")
exit()
print("{} events loaded.".format(len(events)))
print("{} topics loaded.".format(len(topics)))
enum_str = ""
map_str = ""
date = datetime.datetime.now()
link = "https://docs.google.com/spreadsheets/d/{id}".format(id=SPREADSHEET_ID)
# Events.h generation
print("Generating Events.h...")
for e in events:
endl = ",\n" if e != events[-1] else ""
enum_str += " " + e + \
(" = EV_FIRST_SIGNAL" if e == events[0] else "") + endl
map_str += " {{ {event}, {string} }}{endl}".format(
event=e, string='"' + e + '"', endl=endl)
with open('Events.h.template', 'r') as template_file:
template = template_file.read()
template = template.format(sheet_link=link, date=date,
enum_data=enum_str, map_data=map_str)
with open('Events.h', 'w') as header_file:
header_file.write(template)
print("Events.h successfully generated.")
# Topics.h generation
print("Generating Topics.h...")
enum_str = ""
map_str = ""
for t in topics:
endl = ",\n" if t != topics[-1] else ""
enum_str += " " + t + endl
map_str += " {{ {topics}, {string} }}{endl}".format(
topics=t, string='"' + t + '"', endl=endl)
with open('Topics.h.template', 'r') as template_file:
template = template_file.read()
template = template.format(sheet_link=link, date=date,
enum_data=enum_str, map_data=map_str)
with open('Topics.h', 'w') as header_file:
header_file.write(template)
print("Topics.h successfully generated.")
print("Done.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment