Coder Social home page Coder Social logo

thiagoesteves / xfp_elixir Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 162 KB

Transceiver XFP written in Elixir using Erlang Ports

Elixir 67.71% Makefile 2.96% C 28.62% Dockerfile 0.71%
elixir elixir-library elixir-programming-language elixir-language erlang erlang-library erlang-developement erlang-port erlang-port-driver erlang-ports

xfp_elixir's Introduction

github workflow Build Status Coverage Status Erlant/OTP Release

The XFP application

Authors: Thiago Esteves ([email protected]).

Note

The XFP application is dependent on GPROC library (Erlang) and the low level functions implemented at c_src/xfp_driver.c are just for test purposes (stubbed) and must be replace for the real accessors.

Introduction

The XFP is a transceiver for high-speed computer network and telecommunication links that use optical fiber. It is largely used in telecommunications equipment and the code here is an example of how Erlang language can be used to handle eletronic devices with a wrapper to the basic fucntions (i2c, uart, spi, etc).

The driver is using the polling format to read the presence pin every 1 second which means that it will take up to 1 second to detect any changes. Once the device is inserted, all the static information is read and saved in its state.

Deploy using Docker

The current local deploy using docker:

  • Create the docker container docker-compose up
  • Destroy the docker container docker-compose down
  • Access the container docker exec -it XfpElixir /bin/bash

Compiling and Running

To compile and run for your machine just call the following command in the CLI:

$ iex -S mix

Use case: Creating XFP devices

The user can create as many device as needed (the stub supports only 20, but with the real hardware there is no limitation):

iex(1)> Xfp.Sup.create_xfp 0
{:ok, #PID<0.258.0>}
iex(2)> Xfp.get_temperature 0
{:ok, 64.0234375}
iex(3)> Xfp.get_state 0
%{
  aux_monitoring: 255,
  cdr_sup: 0,
  data_code: 'DATACODE',
  diagnostic: 255,
  enhanced: 85,
  identifier: 6,
  inst: 0,
  name: :"Xfp:0",
  part_number: 'VENDOR PARTNUMBE',
  present: true,
  revision: '01',
  vendor_name: 'VENDOR NAME  XFP',
  vendor_oui: 2097152,
  vendor_serial: 'VENDOR SERIALNUM',
  wavelength: 1131.5
}
iex(4)> Xfp.get_laser_state
{:ok, 1}
iex(5)> Xfp.Sup.remove_xfp 0 
:ok

Stub: Emulating Insertion/Removal of the XFP

In order to test the capture of the insertion or the removal of the device you can write in the presence pin to simulate this condition as the example below:

iex(1)> Xfp.Sup.create_xfp
{:ok, #PID<0.208.0>}
iex(2)> Xfp.get_state
%{
  aux_monitoring: 255,
  cdr_sup: 0,
  data_code: 'DATACODE',
  diagnostic: 255,
  enhanced: 85,
  identifier: 6,
  inst: 0,
  name: :"Xfp:0",
  part_number: 'VENDOR PARTNUMBE',
  present: true,
  revision: '01',
  vendor_name: 'VENDOR NAME  XFP',
  vendor_oui: 2097152,
  vendor_serial: 'VENDOR SERIALNUM',
  wavelength: 1131.5
}
iex(3)> Xfp.Driver.write_pin(0,2,1)
{:ok, 0}
iex(4)> Xfp.get_state              
%{inst: 0, name: :"Xfp:0", present: false}

Supervisor tree

The supervisor tree of all XFP's created can be easily viewed with the observer, try the sequence of commands below and have a look at the Applications->xfp.

iex(1)> Xfp.Sup.create_xfp 0
{:ok, #PID<0.208.0>}
iex(2)> Xfp.Sup.create_xfp 1
{:ok, #PID<0.210.0>}
iex(3)> Xfp.Sup.create_xfp 2
{:ok, #PID<0.212.0>}
iex(4)> Xfp.Sup.create_xfp 3
{:ok, #PID<0.214.0>}
iex(5)> Xfp.Sup.create_xfp 4
{:ok, #PID<0.216.0>}
iex(6)> Xfp.Sup.create_xfp 5
{:ok, #PID<0.218.0>}
iex(7)> :observer.start()
:ok

This image shows how the supervision tree is composed once the XFP is instantiated: Supervision Tree

Installation

If available in Hex, the package can be installed by adding xfp_app to your list of dependencies in mix.exs:

def deps do
  [
    {:xfp_app, "~> 0.1.0"}
  ]
end

Erlang Code References

http://erlang.org/doc/tutorial/c_port.html  
http://erlang.org/doc/reference_manual/ports.html

Elixir Code References

https://elixir-lang.org/
https://tonyc.github.io/posts/managing-external-commands-in-elixir-with-ports/  
https://cultivatehq.com/posts/communicating-with-c-from-elixir-using-ports/

XFP References

https://www.gigalight.com/downloads/standards/INF-8077i.pdf  
https://en.wikipedia.org/wiki/XFP_transceiver

xfp_elixir's People

Contributors

thiagoesteves avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.