Giter Site home page Giter Site logo

jverne / nqc Goto Github PK

View Code? Open in Web Editor NEW
40.0 6.0 6.0 1.48 MB

NQC (Not Quite C) is a programming language for several LEGO MINDSTORMS products including the RCX, CyberMaster, and Scout.

Home Page: http://www.clevermonkey.org/nqc

License: Other

C++ 66.18% C 22.76% TeX 6.11% Makefile 0.65% Batchfile 0.01% Lex 0.82% Yacc 1.17% Roff 0.81% Rich Text Format 0.82% Gnuplot 0.65% R 0.03%
nqc rcx bricxcc lego-mindstorms

nqc's Introduction

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 may be perfect for you.

This is my own repo to capture my changes to the 3.1r6 code as found on BricxCC. I've been maintaining this private fork for a few years in order to keep it building and running on OS X and BSD.

For bug reports about this fork of NQC, please file a GitHub Issue for this project.

The original README from the NQC project follows.


NQC Readme

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

Send bug reports to [email protected]. 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

Note to Windows Users

NQC is a command line based tool - normally you run it by typing an appropriate command into an MS-DOS window. There is no GUI for it and if you double-click the nqc.exe file an MS-DOS console will be created for you, NQC will run within it, then since NQC finishes almost immediately, the entire window will disappear.

Some people prefer command line based tools because they allow you to 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 source file for NQC to compile.

  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.

If any of the above seem either too confusing or too tedious, then you may want to try the BricxCC which provides a familiar Windows style GUI on top of the standard NQC compiler. You can download BricxCC here:

http://bricxcc.sourceforge.net/

Getting started

Download the appropriate compiler (nqc or nqc.exe) and put it where your shell can find it as a command.

The IR tower should be connected to your modem port (macintosh) or COM1 (Win32/Linux). The IR tower should be set for "near" mode (small triangle). The RCX should also be set for this mode, and firmware must already be downloaded.

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

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 pressed, then it turns off the motor and plays a sound.

If you are using a USB tower or a different serial port you will need to specify the port either by adding a -Sx option (where x is the name of the port) to the command line or by setting the RCX_PORT environment variable.

Here are some examples:

USB tower (where supported) nqc -Susb -d test.nqc

Win32 COM2 port: set RCX_PORT=COM2

Win32 USB port: set RCX_PORT=usb

Linux: The syntax for setting environment variables is shell specific. By default nqcc uses "/dev/ttyS0" as the device name for the serial port. If you are using the second serial port, then "/dev/ttyS1" 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.

nqc's People

Contributors

jverne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nqc's Issues

Get rcxspy building and working

Either abandon rcxspy or get it working. It exercises some of the disassembly stuff in RCXlib which is nice, but it looks like it has languished a bit. RCX_Image also does some weird stuff with a char array. Either convert this to use safe string functions or use a C++ string object.

Switch usages of strlcpy and strlcat to more cross-compatible methods

When compiling this under Windows Subsystem for Linux (WSL) using Ubuntu, I was able to get this to compile using the following steps:

  1. Install the build tool chain and the dependencies:

sudo apt install build-essential bison flex

  1. Patch nqc/DirList.cpp to replace strlcpy() and strlcat() with strncpy() and strcat() respectively. Usage of sizeof() worked to at least compile bin/nqc. Here's the git diff showing the patched lines. (Note: I'm not sure this is the right way, but it should be close... I think???)
diff --git a/nqc/DirList.cpp b/nqc/DirList.cpp
index 766b2b4..6bccc93 100644
--- a/nqc/DirList.cpp
+++ b/nqc/DirList.cpp
@@ -53,7 +53,7 @@ bool DirList::Find(const char *filename, char *pathname)
     struct stat stat_buf;

     size_t len = sizeof(pathname);
-    if (strlcpy(pathname, filename, len) >= len) {
+    if (sizeof(strncpy(pathname, filename, len)) >= len) {
         return false;
     }

@@ -61,8 +61,8 @@ bool DirList::Find(const char *filename, char *pathname)
         return true;

     for(Entry *e = fEntries.GetHead(); e; e=e->GetNext()) {
-        if (strlcpy(pathname, e->GetPath(), len) < len) {
-            if (strlcat(pathname, filename, len) < len) {
+        if (sizeof(strncpy(pathname, e->GetPath(), len)) < len) {
+            if (sizeof(strncat(pathname, filename, len)) < len) {
                 if (stat(pathname, &stat_buf) == 0) {
                     return true;
                 }
  1. Run make from the root of the repository
  2. Run bin/nqc

If this sounds acceptable, I'll open a PR for the change.

Figure out why firmware uploading appears to fail

No matter what mode I put the tower in, -firmfast fails. It starts to upload, issues a series of tones and a beep-beep, and then uploads again until it reports a failure:

3402% ./bin/nqc -firmfast firmware/firm0332.lgo
Downloading firmware:...............................................................................................................................................................................................
No reply from RCX
3402 (253)%

Subsequent commands indicate there is no firmware.

Only fails sometimes, so there seems to be a timing bug somewhere. Maybe where I took out the wait/pause stuff in the OS X specific USB send code?

Need API commenting via Doxygen

While I learn the code-base, add Doxygen API comments. Once I have enough, add some targets to the Makefile to generate the API docs.

Windows 10 Support

Do I dare try to get this working in Windows 10? The USB support alone might be a quagmire.

It probably needs to be native Windows support, and not through WSL or MinGW.

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.