Skip to content

Commit

Permalink
Incorporation of the patches posted to the original SourceForge proje…
Browse files Browse the repository at this point in the history
…ct site
  • Loading branch information
mesheets committed Mar 20, 2020
1 parent fbb2cb3 commit c6aff03
Show file tree
Hide file tree
Showing 16 changed files with 472 additions and 155 deletions.
39 changes: 23 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ INCLUDES = $(addprefix -I, $(INCLUDE_DIRS))
CFLAGS += $(INCLUDES) -Wall

# Default to NO USB tower support. USB support can be enabled
# via the platform specific settings, below.
# via the platform-specific settings, below.
USBOBJ = RCX_USBTowerPipe_none

# Set this to define the serial port for serial IR towers.
# If unset, "/dev/ttyS0" will be the default port.
#DEFAULT_SERIAL_NAME = "/dev/ttyS0"
TCPOBJ = RCX_TcpPipe_none

#
# Platform specific settings
Expand All @@ -87,10 +84,12 @@ ifneq (,$(strip $(findstring $(OSTYPE), Darwin)))
else
ifneq (,$(strip $(findstring $(OSTYPE), Linux)))
# Linux
# uncomment this next line if you have the USB tower library installed
#USBOBJ = RCX_USBTowerPipe_linux
DEFAULT_SERIAL_NAME = "/dev/ttyS0"
CFLAGS += -I/usr/local/include/LegoUSB -Wno-deprecated
USBOBJ = RCX_USBTowerPipe_linux
TCPOBJ = rcxlib/RCX_TcpPipe_linux
DEFAULT_SERIAL_NAME ?= "/dev/ttyS0"
# Timeout value is 200 in kernel driver module legousbtower.c
LEGO_TOWER_SET_READ_TIMEOUT?= 200
CFLAGS += -DLEGO_TOWER_SET_READ_TIMEOUT='$(LEGO_TOWER_SET_READ_TIMEOUT)' -Wno-deprecated
else
ifneq (,$(findstring $(OSTYPE), SunOS))
# Solaris
Expand All @@ -99,12 +98,12 @@ else
ifneq (,$(strip $(findstring $(OSTYPE), FreeBSD)))
# FreeBSD
USBOBJ = RCX_USBTowerPipe_fbsd
DEFAULT_SERIAL_NAME = "/dev/cuad0"
DEFAULT_SERIAL_NAME?= "/dev/cuad0"
CFLAGS += -Wno-deprecated
else
ifneq (,$(strip $(findstring $(OSTYPE), OpenBSD)))
# OpenBSD i386
DEFAULT_SERIAL_NAME = "/dev/cua00"
DEFAULT_SERIAL_NAME ?= "/dev/cua00"
CFLAGS += -O2 -std=gnu++98 -pipe
else
# default Unix build without USB support
Expand All @@ -115,13 +114,21 @@ endif
endif
endif

CXX:=$(TOOLPREFIX)$(CXX)

#
# If the serial port is explicitly set, use it.
#
ifneq ($(strip $(DEFAULT_SERIAL_NAME)),)
CFLAGS += -DDEFAULT_SERIAL_NAME='$(DEFAULT_SERIAL_NAME)'
endif

DEFAULT_USB_NAME ?= "/dev/usb/legousbtower0"
CFLAGS += -DDEFAULT_USB_NAME='$(DEFAULT_USB_NAME)'

DEFAULT_DEVICE_NAME ?= "usb"
CFLAGS += -DDEFAULT_DEVICE_NAME='$(DEFAULT_DEVICE_NAME)'

#
# Debug builds for most Clang/GCC environments.
# This implies -DDEBUG_TIMEOUT
Expand All @@ -136,7 +143,7 @@ OBJ = $(NQCOBJ) $(COBJ) $(RCXOBJ) $(POBJ)
RCXOBJS = RCX_Cmd RCX_Disasm RCX_Image RCX_Link RCX_Log \
RCX_Target RCX_Pipe RCX_PipeTransport RCX_Transport \
RCX_SpyboticsLinker RCX_SerialPipe \
$(USBOBJ)
$(USBOBJ) $(TCPOBJ)
RCXOBJ = $(addprefix rcxlib/, $(addsuffix .o, $(RCXOBJS)))

POBJS = PStream PSerial_unix PHashTable PListS PDebug
Expand Down Expand Up @@ -269,10 +276,10 @@ docs:
# Installation of binary and man page
#
install: all
test -d $(BINDIR) || mkdir -p $(BINDIR)
cp -r bin/* $(BINDIR)
test -d $(MANDIR) || mkdir -p $(MANDIR)
cp nqc-man-2.1r1-0.man $(MANDIR)/nqc.$(MANEXT)
test -d $(DESTDIR)$(BINDIR) || mkdir -p $(DESTDIR)$(BINDIR)
cp -r bin/* $(DESTDIR)$(BINDIR)
test -d $(DESTDIR)$(MANDIR) || mkdir -p $(DESTDIR)$(MANDIR)
cp nqc-man-2.1r1-0.man $(DESTDIR)$(MANDIR)/nqc.$(MANEXT)

#
# Print some info about the environment
Expand Down
6 changes: 3 additions & 3 deletions PORTING
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Mainfest
platform - source for utility classes
rcx.nqh - system include file for using nqcc
rcxlib - classes implementing the rcx interface
readme.txt - the readme file
test.nqc - a trivial nqcc test program
README.md - the readme file
test.nqc - a trivial nqc test program


The Mac and win32 version are built under Metrowerks CodeWarrior.
The Mac and Win32 version are built under Metrowerks CodeWarrior.
The included Makefile was designed for Linux, but should work on other
Unix platforms with minor modification.

Expand Down
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@ NQC
> Not Quite C is a simple language with a C-like syntax that can be used to program Lego's RCX programmable brick (from the MindStorms set). If you are just getting started with programming, then graphical environments such as the MindStorms RIS software or Robolab are probably better choices. If, however, you're a C programmer and prefer typing a few lines to drag and drop icon programming, then NQC might be perfect for you.
This BrickBot/nqc repo captures changes to the 3.1r6 code as found on
[BricxCC](http://bricxcc.sourceforge.net/nqc/), including the following [patches that were posted to the original SourceForge project site following the release of nqc 3.1r6 but never incorporated](https://sourceforge.net/p/bricxcc/patches/):
[BricxCC](http://bricxcc.sourceforge.net/nqc/), including the following [patches that were posted by Matthew Sheets to the original SourceForge project site following the release of nqc 3.1r6 but never incorporated](https://sourceforge.net/p/bricxcc/patches/):
1. [Added TCP support, facilitating use of NQC with programs such as BrickEmu (an RCX emulator)](https://sourceforge.net/p/bricxcc/patches/2/)
2. [Added additional capabilities for specifying the default USB port, including at both compile time using a Make variable and via enhanced command-line argument support](https://sourceforge.net/p/bricxcc/patches/2/)
3. [Support Makefile variables DESTDIR and TOOLPREFIX](https://sourceforge.net/p/bricxcc/patches/3/)
4. [Enable specifying the default IR tower name in a configuration file](https://sourceforge.net/p/bricxcc/patches/4/)
5. [Support using a Make variable to specify the default compile-time port name, instead of having to modify source code files](https://sourceforge.net/p/bricxcc/patches/5/)

This release also builds on the jverne/nqc private fork, which was maintained to keep NQC building and running on OS X and BSD.
This release also attempts to build on the jverne/nqc private fork, which was maintained to keep NQC building and running on OS X and BSD.

For bug reports about _this_ fork of NQC, please [file a GitHub Issue](https://github.com/BrickBot/nqc/issues) for this project.

The original README from the NQC project follows.

---

NQC Readme
NQC ReadMe
----------

If you have a problem, PLEASE CHECK THE FAQ:
<http://bricxcc.sourceforge.net/nqc/doc/faq.html>
* http://bricxcc.sourceforge.net/nqc/doc/faq.html

Send bug reports to bricxcc@comcast.net. Be sure to include details about what
platform you are running nqc on and a sample file that demonstrates the bug if
possible.

For updates and additional documentation, visit the NQC Web Site:
<http://bricxcc.sourceforge.net/nqc>
For updates and additional documentation, visit the [NQC Web Site](http://bricxcc.sourceforge.net/nqc)


Note to Windows Users
Expand All @@ -46,10 +45,10 @@ use the text editor of your choice, etc. It also makes for identical
behavior under Windows, Mac, and Linux. In order to use the command line
version of NQC you'll need to do two things:

1) Use some sort of text editor (such as Notepad) to edit and save a
1. Use some sort of text editor (such as Notepad) to edit and save a
source file for NQC to compile.

2) From an MS-DOS window type the appropriate NQC command. Its usually
2. From an MS-DOS window type the appropriate NQC command. Its usually
best to either put all of your programs and nqc.exe in the same
directory, or make sure the directory containing NQC is in your command
path.
Expand All @@ -74,7 +73,7 @@ already be downloaded.

Compile and download the test file using the following command line:

nqc -d test.nqc
`nqc -d test.nqc

The test program assumes there's a motor on output A and a touch sensor
on input 1. It turns on the motor and waits for the switch to be
Expand Down Expand Up @@ -102,4 +101,3 @@ Linux:
should work. Other device drivers may or may not work depending on if
they implement the expected ioctl's to setup the baud rate, parity,
etc.

Binary file added doc/NQC_Guide.pdf
Binary file not shown.
Binary file added doc/NQC_Manual.pdf
Binary file not shown.
17 changes: 0 additions & 17 deletions firmware/README

This file was deleted.

16 changes: 16 additions & 0 deletions firmware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Some of these firmware files are property of someone else; probably LEGO, Inc. or Dick Swan.

They are provided here as a convenience only, as they can be found all over the internet.

Note that it is unknown if any of the "fast" firmwares work with any current version of NQC, as I only test with LEGO firmwares.

* firm0309 - Original version shipped with RIS 1.0 and 1.5
* firm0328 - Shipped with RIS 2.0
* firm0332 - Released as part of the LEGO Education Robotics sets
* fast0103 - Dick Swan's 10x firmware; compatible with most bricks and NQC
* fast0612 - Dick Swan's 100x firmware; mostly compatible with NQC 3.1r5
* fast0722 - Dick Swan firmware that only works with RobotC
* fast0753 - Dick Swan firmware that only works with RobotC
* fast0798 - Dick Swan firmware included with the last version of RobotC for the RCX

Unless there is a compelling reason not to do so, you should just use the latest LEGO firmware (0332) for NQC, which can be used in any RCX brick from 1.0 on.
19 changes: 19 additions & 0 deletions nqc/nqc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,29 @@ void PrintError(RCX_Result error, const char *filename)
case kRCX_GhostNotFoundError:
fprintf(STDERR," Ghost libraries are not installed properly\n");
break;

case kRCX_TcpUnsupportedError:
fprintf(STDERR, "TCP not supported\n");
break;
case kRCX_UnknownTcpHostError:
fprintf(STDERR, "Unknown TCP host\n");
break;
case kRCX_OpenSocketError:
fprintf(STDERR, "Could not open TCP socket\n");
break;
case kRCX_BindPortError:
fprintf(STDERR, "Failure binding TCP port\n");
break;
case kRCX_TcpConnectError:
fprintf(STDERR, "Could not create TCP connection\n");
break;

default:
fprintf(STDERR, "Error #%d\n", -error);
break;
}

fflush(STDERR);
}

void PrintVersion()
Expand Down
57 changes: 55 additions & 2 deletions rcxlib/RCX_Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include <cstdio>
#include <cstdlib>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <limits.h>

#include "RCX_Link.h"
#include "RCX_Cmd.h"
#include "rcxnub.h"
Expand All @@ -32,6 +37,7 @@
using std::printf;
using std::getenv;
using std::tolower;
using std::ifstream;

#define kSerialPortEnv "RCX_PORT"

Expand All @@ -46,6 +52,9 @@ using std::tolower;

#define kNubStart 0x8000

#define kDeviceUserConfFile "/.rcx/device.conf"
#define kDeviceEtcConfFile "/etc/rcx/device.conf"

extern bool gQuiet;

static int Checksum(const UByte *data, int length);
Expand Down Expand Up @@ -80,9 +89,42 @@ RCX_Result RCX_Link::Open(RCX_TargetType target, const char *portName, ULong opt
// see if an environment variable is set, otherwise use default serial device
if (!portName) portName = getenv(kSerialPortEnv);

#ifndef WIN32
string portName_buf;

// Check for a user configuration file specifying the port name
if (!portName)
{
ifstream userCfgFile;
char *homePath = getenv("HOME");
char userConfPath[PATH_MAX];
strcpy(userConfPath, homePath);
strcat(userConfPath, kDeviceUserConfFile);

userCfgFile.open(userConfPath);
if (userCfgFile) userCfgFile >> portName_buf;
userCfgFile.close();
if (portName_buf.length() > 0) portName = portName_buf.c_str();
}

// Check for a system configuration file specifying the port name
if (!portName)
{
ifstream etcCfgFile;
etcCfgFile.open(kDeviceEtcConfFile);
if (etcCfgFile) etcCfgFile >> portName_buf;
etcCfgFile.close();
if (portName_buf.length() > 0) portName = portName_buf.c_str();
}
#endif

// if a default device has not yet been found, use the compiled default
if (!portName) portName = DEFAULT_DEVICE_NAME;

const char *devName;

if (portName && ((devName=CheckPrefix(portName, "usb")) != 0)) {
if (portName && ((devName=CheckPrefix(portName, "usb")) != 0))
{
// USB Tower
gUSB = true;
#ifdef GHOST
Expand All @@ -92,7 +134,18 @@ RCX_Result RCX_Link::Open(RCX_TargetType target, const char *portName, ULong opt
if (!pipe) return kRCX_USBUnsupportedError;
fTransport = new RCX_PipeTransport(pipe);
#endif
} else {
}
else if (portName && ((devName=CheckPrefix(portName, "tcp")) != 0))
{
// TCP
gUSB = false;

RCX_Pipe *pipe = RCX_NewTcpPipe();
if (!pipe) return kRCX_TcpUnsupportedError;
fTransport = new RCX_PipeTransport(pipe);
}
else
{
// Serial Tower
gUSB = false;
if (portName) {
Expand Down
6 changes: 6 additions & 0 deletions rcxlib/RCX_Pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ class RCX_Pipe
*/
RCX_Pipe* RCX_NewUSBTowerPipe();

/*
* This is an operating system dependent factory method for creating
* a pipe for TCP.
*/
RCX_Pipe* RCX_NewTcpPipe();

#endif
9 changes: 8 additions & 1 deletion rcxlib/RCX_Result.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ typedef int RCX_Result;
#define kRCX_USBUnsupportedError -10 ///< USB is not yet supported (depends on the OS)
#define kRCX_GhostNotFoundError -11 ///< USB requires Ghost, which is not installed

#define kRCX_LastError -11 ///< Last error code so classes can hook their own codes in
// new error codes for TCP support
#define kRCX_TcpUnsupportedError -12 ///< TCP is not yet supported
#define kRCX_UnknownTcpHostError -13 ///< unknown TCP host
#define kRCX_OpenSocketError -14 ///< failure opening a TCP socket
#define kRCX_BindPortError -15 ///< unable to bind port
#define kRCX_TcpConnectError -16 ///< cannot connect

#define kRCX_LastError -16 ///< Last error code so classes can hook their own codes in

/// Convenience define to check if a code is an error condition.
#define RCX_ERROR(result) ((result) < 0)
Expand Down
Loading

0 comments on commit c6aff03

Please sign in to comment.