techninja / cncserver

A RESTful API server for driving serial based CNC devices
133 stars 39 forks source link

JS module based machine definitions #64

Open docprofsky opened 9 years ago

docprofsky commented 9 years ago

This is an issue to discuss using JS modules for handling machine definitions and adding more extensibility to CNC Server.

I see the scope of CNC Server as being

techninja commented 9 years ago

Words. We're going to need some slightly different vocabulary to describe what all these parts mean and in what context.

Modules:

These are basically complete projects, packaged in a certain way following the CommonJS standard for node. The neat thing is that they're clean and can provide almost anything to their parents that require('them'). The Grunt task runner project has done a great job utilizing this to make their own "plugin" model.

Plugin:

A plugin in this instance is really just a node module, but with some extra requirements. Possibly some additional package.json fields, but most likely it's all about some expected structure or API around its instantiation and use. Cncserver might require a module plugin like this:

require('cncserver-watercolorbot')(cncserver); // Note we don't have to assign output to a variable

Basically passing in the "global" cncserver object over to an instantiation function (as is done all over the place, including with grunt), and then "the plugin API" will be operated entirely through that object.

Machine definitions could be passed in to cncserver.defineMachine([object]), and the object would easily be enough to define everything currently setup in the ini files. Callbacks for events and additional control surfaces for tool changes (to add wiggle, etc.) could easily be added as well and passed along.

Anyways... any additional functionality would likely have to be a module plugin of some kind, I suspect if we add enough API, the addition of plugins that technically can provide communication methods, API endpoints, machines, tools, and anything else imaginable, is certainly possible.

Of course all of this is a bit moot if we still have customers left in the lurch trying to get basic systems working, and all we seem to be doing is trying to over-engineer things. This is not my current priority, but it seems to be a great idea and may become a future priority. Without active contributors beyond myself (or funds to make up for my lost time), it would take years for something like this to really happen.