Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
sstaub committed Oct 1, 2022
1 parent 44977f4 commit dcb60e7
Show file tree
Hide file tree
Showing 11 changed files with 1,558 additions and 0 deletions.
Empty file modified LICENSE
100755 → 100644
Empty file.
451 changes: 451 additions & 0 deletions README.md

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions examples/sACN_Receive/sACN_Receive.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "Ethernet.h"
#include "sACN.h"

uint8_t mac[] = {0x90, 0xA2, 0xDA, 0x10, 0x14, 0x48}; // MAC Adress of your device
IPAddress ip(10, 101, 1, 201); // IP address of your device
IPAddress dns(10, 101, 1, 100); // DNS address of your device
IPAddress gateway(10, 101, 1, 100); // Gateway address of your device
IPAddress subnet(255, 255, 0, 0); // Subnet mask of your device

EthernetUDP sacn;
Receiver recv(sacn, 1); // universe 1

void dmxReceived() {
Serial.println("New DMX data received ");
Serial.print("DMX Slot 1: ");
Serial.print(recv.dmx(1));
Serial.print(" DMX Slot 2: ");
Serial.println(recv.dmx(2));
}

void newSource() {
Serial.print("new soure name: ");
Serial.println(recv.name());
}

void framerate() {
Serial.print("Framerate fps: ");
Serial.println(recv.framerate());
}

void timeOut() {
Serial.println("Timeout!");
}

void setup() {
Serial.begin(9600);
delay(2000);
Ethernet.begin(mac, ip, dns, gateway, subnet);
recv.callbackDMX(dmxReceived);
recv.callbackSource(newSource);
recv.callbackFramerate(framerate);
recv.callbackTimeout(timeOut);
recv.begin();
Serial.println("sACN start");
}

void loop() {
recv.receive();
}
27 changes: 27 additions & 0 deletions examples/sACN_Send/sACN_Send.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "Ethernet.h"
#include "sACN.h"

uint8_t mac[] = {0x90, 0xA2, 0xDA, 0x10, 0x14, 0x48}; // MAC Adress of your device
IPAddress ip(10, 101, 1, 201); // IP address of your device
IPAddress dns(10, 101, 1, 100); // DNS address of your device
IPAddress gateway(10, 101, 1, 100); // Gateway address of your device
IPAddress subnet(255, 255, 0, 0); // Subnet mask of your device

EthernetUDP sacn;

// CID fd32aedc-7b94-11e7-bb31-be2e44b06b34
uint8_t id[16] {0xFD, 0x32, 0xAE, 0xDC, 0x7B, 0x94, 0x11, 0xE7, 0xBB, 0x31, 0xBE, 0x2E, 0x44, 0xB0, 0x6B, 0x34};
Source sender(sacn, 1, 100, id, "Arduino", true);

void setup() {
Serial.begin(9600);
delay(2000);
Ethernet.begin(mac, ip, dns, gateway, subnet);
sender.begin();
Serial.println("sACN start");
sender.dmx(1, 255); // send value 255 to DMX slot 1
}

void loop() {
sender.idle();
}
37 changes: 37 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#######################################
# Syntax Coloring Map for sACN
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

Receiver KEYWORD1
Source KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
stop KEYWORD2
receive KEYWORD2
send KEYWORD2
sendDD KEYWORD2
idle KEYWORD2
idleDD KEYWORD2
callBackDMX KEYWORD2
callBackSource KEYWORD2
callBackTimeout KEYWORD2
callBackFramerate KEYWORD2
dmx KEYWORD2
dd KEYWORD2
CID KEYWORD2
name KEYWORD2
framerate KEYWORD2
sources KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

15 changes: 15 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "sACN",
"keywords": "sACN, DMX",
"description": "Arduino library for sending and receiving sACN DMX streams following ANSI E1.31",
"authors": {
"name": "Stefan Staub"
},
"repository":
{
"type": "git",
"url": "https://github.com/sstaub/sACN"
},
"version": "1.0.0",
"frameworks": "arduino"
}
10 changes: 10 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=sACN
version=1.0.0
author=Stefan Staub
maintainer=Stefan Staub <[email protected]>
sentence=LCD Library for sACN ANSI E1.31
paragraph=LCD Library for sending and receiving sACN DMX streams following ANSI E1.31
category=Communication
url=https://github.com/sstaub/sACN
architectures=*
includes=sACN.h
157 changes: 157 additions & 0 deletions src/IDTools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/* Arduino library for pseudo randomized UUID and MAC address
*
* (c) 2022 stefan staub
* Released under the MIT License
*
* 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.
*/

/* CID Tools following RFC4122
* To initialise the pseudo random generators add an usefull input like AnalogIn(x)
* At least you should use hardware chips with included serial and mac address like
* AT24MAC402/AT24MAC602 from microchip
*/

#ifndef ID_TOOLS_H
#define ID_TOOLS_H

#include "Arduino.h"

/**
* @brief genertate a random CID / UUID
*
* @param uuid
* @param srnd start number for random function
*/
void generateCID(uint8_t uuid[], unsigned int srnd) {
srand(srnd);
for (uint8_t i = 0; i < 16; i++) {
uuid[i] = rand() %256;
}
uuid[6] = 0x40 | (0x0F & uuid[6]); // version 4 / random based
uuid[8] = 0x80 | (0x3F & uuid[8]); // variant RFC4122
}

/**
* @brief genertate a random CID / UUID
*
* @param srnd start number for random function
* @return uint8_t* uuid
*/
uint8_t* generateCID(unsigned int srnd) {
static uint8_t uuid[16];
srand(srnd);
for (uint8_t i = 0; i < 16; i++) {
uuid[i] = rand() %256;
}
// add uuid variant and version
uuid[6] = 0x40 | (0x0F & uuid[6]); // version 4 / random based
uuid[8] = 0x80 | (0x3F & uuid[8]); // variant RFC4122
return uuid;
}

/**
* @brief verify if CID / UUID is RFC4122 conform
*
* @param uuid
* @return true if variant and version ok
* @return false
*/
bool verifyCID(uint8_t uuid[]) {
if (uuid[6] >> 4 == 0x04 && uuid[8] >> 6 == 0x02) {
return true;
}
else {
return false;
}
}

/**
* @brief converts the CID / UUID to a string
*
* @param cid
* @param cidString
*/
void CIDtoString(uint8_t cid[], char cidString[]) {
sprintf(cidString, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
cid[0], cid[1], cid[2], cid[3], cid[4], cid[5], cid[6], cid[7],
cid[8], cid[9], cid[10], cid[11], cid[12], cid[13], cid[14], cid[15]);
}

/**
* @brief converts the CID / UUID to a string
*
* @param cid
* @return char* cid tring
*/
char* CIDtoString(uint8_t cid[]) {
static char cidString[70];
sprintf(cidString, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
cid[0], cid[1], cid[2], cid[3], cid[4], cid[5], cid[6], cid[7],
cid[8], cid[9], cid[10], cid[11], cid[12], cid[13], cid[14], cid[15]);
return cidString;
}

/**
* @brief generate a random mac address for local use
*
* @param mac
* @param srnd start number for random function
*/
void generateMAC(uint8_t mac[], unsigned int srnd) {
srand(srnd);
for (uint8_t i = 0; i < 6; i++) {
mac[i] = rand() %256;
}
mac[0] &= ~(1 << 0); // unicast = 0, multicast / broadcast = 1
mac[0] |= 1 << 1; // local = 1, universal = 0
}

/**
* @brief generate a random mac address for local use
*
* @param srnd start number for random function
* @return uint8_t* MAC address
*/
uint8_t* generateMAC(unsigned int srnd) {
static uint8_t mac[6];
srand(srnd);
for (uint8_t i = 0; i < 6; i++) {
mac[i] = rand() %256;
}
mac[0] &= ~(1 << 0); // unicast = 0, multicast / broadcast = 1
mac[0] |= 1 << 1; // local = 1, universal = 0
return mac;
}

/**
* @brief converts the MAC to a string
*
* @param mac
* @param macString
*/
void MACtoString(uint8_t mac[], char macString[]) {
sprintf(macString, "%02X:%02X:%02X:%02X:%02X:%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}

/**
* @brief converts the MAC to a string
*
* @param mac
* @return char* MAC string
*/
char* MACtoString(uint8_t mac[]) {
static char macString[31];
sprintf(macString, "%02X:%02X:%02X:%02X:%02X:%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return macString;
}

#endif
Loading

0 comments on commit dcb60e7

Please sign in to comment.