Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various cleanups #12

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions examples/main/hackerpet_plus.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Project hackerpet_plus
* Description:
* Author:
* Date:
* VERSION:
*/


#include "Particle.h"
#include "softap_http.h"
#include "hotspot-http-server.h"

# include "../lib/MDNS/src/Buffer.h"
# include "../lib/MDNS/src/Buffer.cpp"
# include "../lib/MDNS/src/Record.h"
# include "../lib/MDNS/src/Record.cpp"
# include "../lib/MDNS/src/Label.h"
# include "../lib/MDNS/src/Label.cpp"
# include "../lib/MDNS/src/MDNS.h"
# include "../lib/MDNS/src/MDNS.cpp"

// new

#include "config-manager.h"
#include "game-manager.h"


// Use primary serial over USB interface for logging output (9600)
// Choose logging level here (ERROR, WARN, INFO) or TRACE
// *** important *** if you want to enable TRACE level debugging, this will display A LOT of logs.
// If you need to debug at that level, it is recommended to "slow down" the hub by executing the contents of the main loop() only i.e. once a second.

SerialLogHandler logHandler(LOG_LEVEL_INFO, { // Logging level for all messages
{ "app.hackerpet", LOG_LEVEL_ERROR }, // Logging level for library messages
{ "app", LOG_LEVEL_INFO } // Logging level for application messages
});


// classes
HubInterface hub;
GameManager gameMan(&hub); // which game to play given gameId from config
ConfigManager configMan(&hub, &gameMan); // handles config of hub and game via webpage and eeprom

// enables simultaneous execution of application and system thread
SYSTEM_THREAD(ENABLED);

// hotspot
STARTUP(softap_set_application_page_handler(myPages, nullptr));

// setup() runs once, when the device is first turned on.
void setup() {

configMan.Initialize(); // also initializes game manager

// this is used by hackerpet for reports
hub.Initialize("game_ID_here_TODO");
// in games it was: hub.Initialize(__FILE__);
}

unsigned long lastmemcheck = 0;
unsigned long FREE_MEMORY;

// loop() runs over and over again, as quickly as it can execute.
void loop() {

Log.trace("[[calling]]: configMan.Run();");
// serve webpage, read/write eeprom as config changes
configMan.Run();

Log.trace("[[calling]]: hub.Run(20);");
// run the hub
// if testing on a particle photon by itself with no hub, comment this line to avoid seg fault
hub.Run(20);

// run the loop for the current active game
Log.trace("[[calling]]: gameMan.Run();");
gameMan.Run();

// every 10 seconds, print the free memory as a serial heartbeat

if ((millis() - lastmemcheck) > 10000) {
Log.trace(Time.timeStr());
Log.trace("[[calling]]: free memory");

FREE_MEMORY = System.freeMemory();

lastmemcheck = millis();

Serial.printlnf("\tMILLIS: %lu\tSYSTEM MEMORY=%lu", lastmemcheck, FREE_MEMORY);
}
}
63 changes: 0 additions & 63 deletions examples/main/particle-test-local.ino

This file was deleted.

21 changes: 21 additions & 0 deletions lib/MDNS/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Mark Hornsby 2020

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.
4 changes: 4 additions & 0 deletions lib/MDNS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spark-core-mdns
===============

Multicast DNS and DNS-SD for the Spark Core
9 changes: 9 additions & 0 deletions lib/MDNS/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=MDNS
version=2.0.0
license=MIT
author=Mark Hornsby <me@markhornsby.uk>
sentence=Support for multicast name and DNS service registration
# paragraph=a longer description of this library, always prepended with sentence when shown
# url=the url for the project
repository=https://github.com/mrhornsby/spark-core-mdns.git
# architectures=a list of supported boards if this library is hardware dependent, like particle-photon,particle-electron
73 changes: 73 additions & 0 deletions lib/MDNS/src/Buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "Buffer.h"

mdns::Buffer::Buffer(uint16_t size) {
this->data = (uint8_t *) malloc(size);
this->size = data != NULL? size : 0;
}

uint16_t mdns::Buffer::available() {
return offset < limit? limit - offset : offset - limit;
}

void mdns::Buffer::mark() {
if (markOffset == INVALID_MARK_OFFSET) {
markOffset = offset;
}
}

void mdns::Buffer::reset() {
if (markOffset != INVALID_MARK_OFFSET) {
offset = markOffset;
markOffset = INVALID_MARK_OFFSET;
}
}

void mdns::Buffer::setOffset(uint16_t offset) {
this->offset = offset;
}

uint16_t mdns::Buffer::getOffset() {
return offset;
}

void mdns::Buffer::read(UDP * udp) {
offset = 0;
limit = udp->read(data, size);
}

uint8_t mdns::Buffer::readUInt8() {
return data[offset++];
}

uint16_t mdns::Buffer::readUInt16() {
return readUInt8() << 8 | readUInt8();
}

void mdns::Buffer::writeUInt8(uint8_t value) {
if (offset < size) {
data[offset++] = value;
}
}

void mdns::Buffer::writeUInt16(uint16_t value) {
writeUInt8(value >> 8);
writeUInt8(value);
}

void mdns::Buffer::writeUInt32(uint32_t value) {
writeUInt8(value >> 24);
writeUInt8(value >> 16);
writeUInt8(value >> 8);
writeUInt8(value);
}

void mdns::Buffer::write(UDP * udp) {
udp->write(data, offset);

offset = 0;
}

void mdns::Buffer::clear() {
offset = 0;
limit = 0;
}
46 changes: 46 additions & 0 deletions lib/MDNS/src/Buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "application.h"

#ifndef _INCL_BUFFER
#define _INCL_BUFFER

#define INVALID_MARK_OFFSET 0xffff

namespace mdns {

class Buffer {
public:
Buffer(uint16_t size);

uint16_t available();

void mark();
void reset();
void setOffset(uint16_t offset);
uint16_t getOffset();

void read(UDP * udp);

uint8_t readUInt8();
uint16_t readUInt16();

void write(UDP * udp);

void writeUInt8(uint8_t value);
void writeUInt16(uint16_t value);
void writeUInt32(uint32_t value);

void clear();

private:

uint8_t * data;
uint16_t size;

uint16_t limit = 0;
uint16_t offset = 0;
uint16_t markOffset = INVALID_MARK_OFFSET;
};

}

#endif
Loading