Frequency 902-928 Mhz, 30 digital channels, 19200 bps wireless communication. Wireless communication is 300 feet outdoor, 150 feet indoor.
Source code for a Java server on PC with serial link to one Master Cybiko and as many slaves as you care to poll via the RF link. Perfect for gateway, remote monitoring and control, etc...
Java Server:
/* * filename: Wireless.java * by Sonny Cruz * */ import javax.comm.*; import java.io.*; public class Wireless extends Thread{ static final int AVAILABLE_CYBIKO = 3; static InputStream in = null; static OutputStream out = null; static SerialPort sp = null; static int packetCount = 0; static int count; static int counter = 0; static byte[] receivedBuffer = new byte[8]; static byte[] sendBuffer = new byte[8]; boolean flop = true; private static Wireless instance = new Wireless(); public static Wireless getInstance() { return instance; } private Wireless() { try { CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier("COM2"); sp = (SerialPort)portID.open("Wireless", 1000); sp.setSerialPortParams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); sp.setFlowControlMode(SerialPort. FLOWCONTROL_NONE); sp.enableReceiveTimeout(500); out = sp.getOutputStream(); in = sp.getInputStream(); //initialize sendBuffer sendBuffer[0] = 0x30; sendBuffer[1] = 0x31; sendBuffer[2] = 0x32; sendBuffer[3] = 0x33; sendBuffer[4] = 0x34; sendBuffer[5] = 0x35; sendBuffer[6] = 0x36; sendBuffer[7] = 0x38; } catch (IOException ioe) {} catch (NoSuchPortException nspe) {} catch (UnsupportedCommOperationException ucoe) {} catch (PortInUseException piue) {} } public byte[] getBuffer() { return receivedBuffer; } public int getPacketCount() { return packetCount; } public void setFifthByte(byte b) { sendBuffer[4] = b; } public void resetFifthByte() { sendBuffer[4] = 0x35; } public void run() { while (true) { if (counter++ >= AVAILABLE_CYBIKO) // increment cybiko address counter = 0; switch(counter) { // assign cybiko address case 0 : sendBuffer[1] = 0x31; break; case 1 : sendBuffer[1] = 0x32; break; case 2 : sendBuffer[1] = 0x33; break; } try { out.write(0x1b); // synch out.write(sendBuffer, 0, sendBuffer.length); try { Thread.sleep(50); } catch (InterruptedException e) {} count = in.read(receivedBuffer, 0, receivedBuffer.length); if (count == 8) packetCount++; try { Thread.sleep(250); } catch (InterruptedException e) {} } catch (IOException e) {} } } }
Master Cybiko:
// // filename: serial.c // // tutorial file to use wireless cybiko as a general purpose terminal // // by Sonny Cruz 2/27/2003 // // loop // wait for synch byte (0x1b) from serial port // read 8 bytes from serial // translate 2nd byte to cybiko id // send 8 bytes to the wireless network // received 8 bytes from the wireless network // translate 2nd byte to char // send 8 bytes to serial // // use delete key to quit the program // serial settings 57600 baud, 8 data, 1 stop, no parity // shows status on the cybiko screen // beeps if serial ports timeout // // to add more cybiko's // add define for id, use console and type id in the command to get id // adjust functions convertCharToID and convertIDToChar accordingly // 2nd char of the buffer is the id before conversion // #include <cybiko.h> #define MY_APP (MSG_USER + 1) // my own message id #define ID1 0x00035FE1 // blue cybiko #define ID2 0x000339DC // pink cybiko #define ID3 0x0002C3C8 // green cybiko #define SYNCH 0x1b // synch character #define LIMIT 8 // limit of char to read / write #define TIMEOUT 100 // time out in millisecond for read #define MAX_RETRY 20 // maximun retry to wait for synch #define LINE_INCREMENT 10 // increment y axis for screen position static timeout = 0; // count of time out static int X = 0; // used for positioning the text on screen static int Y = 0; // used for positioning the text on screen char buffer[LIMIT]; // buffer to use for read / write char str[40]; // used for status message struct module_t m; // holder for graphics and thread message queue com_t port; // cybiko's serial port struct Message* mess; // cybiko's message queue /*********************************** * function: serialWrite * ***********************************/ void serialWrite() { int i; for (i = 0; i < LIMIT; i++) com_write(port, buffer[i], 0); } /*********************************** * function serialRead * ***********************************/ bool serialRead() { int timeout; int i; int data; data = 0x00; timeout = 0; while ((data != SYNCH) && (timeout < MAX_RETRY)) { // wait for synch data data = com_read(port, TIMEOUT); timeout++; } if (data == SYNCH) { for (i = 0; i < LIMIT; i++) buffer[i] = (char) com_read(port, TIMEOUT); return TRUE; } return FALSE; } /*********************************** * function: getKey * ***********************************/ int getKey() { return Message_get_key_param(mess)->scancode; } /*********************************** * function: convertIDToChar * ***********************************/ char convertIDToChar(long l) { char c; switch (l) { case ID1 : c = 0x31; break; case ID2 : c = 0x32; break; case ID3 : c = 0x33; break; default : c = 0x00; break; } return c; } /************************************ * function: convertCharToID * ************************************/ long convertCharToID(char c) { long l; switch (c) { case 0x31 : l = ID1; break; case 0x32 : l = ID2; break; case 0x33 : l = ID3; break; default : l = 0x00; break; } return l; } /************************************ * function: clearScreen * ************************************/ void clearScreen() { DisplayGraphics_set_color(m.m_gfx, CLR_WHITE); DisplayGraphics_fill_rect(m.m_gfx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); DisplayGraphics_show(m.m_gfx); } /*********************************** * function: putString * ***********************************/ void putString(char* s) { if (Y > SCREEN_HEIGHT) { Y = 0; clearScreen(); } DisplayGraphics_set_color(m.m_gfx, CLR_BLACK); DisplayGraphics_draw_text(m.m_gfx, s, X, Y); DisplayGraphics_show(m.m_gfx); Y += LINE_INCREMENT; } /************************************** * main * **************************************/ long main(int argc, char* argv[], bool start) { long tempID; bool exitApp = FALSE; init_module(&m); port = com_open(COMM_DEV_DEFAULT, 500); DisplayGraphics_set_font(m.m_gfx, mini_normal_font); clearScreen(); putString("Starting program..."); while (!exitApp) { putString("reading serial"); if (!serialRead()) { putString("Timeout reading serial"); beep(BEEP_ERROR); } else { sprintf(str, "Sending wireless to %c", buffer[1]); putString(str); send_remote_msg(convertCharToID(buffer[1]), "serial", MY_APP, 0L, 0L, buffer, LIMIT); } mess = cWinApp_get_message(m.m_process, TIMEOUT, 1, MY_APP); if (mess) { switch(mess->msgid) { case MSG_SHUTUP : case MSG_QUIT : exitApp = TRUE; break; case MY_APP : Buffer_load(Message_get_buffer(mess), buffer, 0, LIMIT); sprintf(str, "Receiving wireless from %c", buffer[1]); putString(str); buffer[1] = convertIDToChar(Message_get_sender_id(mess)); putString("sending serial"); serialWrite(); break; case MSG_KEYDOWN : if (getKey() == KEY_DEL) exitApp = TRUE; break; default : cWinApp_defproc(m.m_process, mess); } Message_delete(mess); } } com_close(port); return 0L; }
Slave Cybiko:
// filename serial.c // slave file used to respond to poll from master // update percentage number in the bottom of the screen // draw random lines to screen everytime it receives a packet from the master // clear screen every 100th packet receive // by Sonny Cruz 2/24/03 // // program flow // loop #include <cybiko.h> #include <cywin.h> #define MY_APP (MSG_USER + 1) #define CYBIKO_MASTER 0x0004A1E8 // global variables char buffer[8]; char str[30]; struct module_t mainModule; char dummy = 0; int counter = 0; struct cProgressBar cPB; void drawLine() { int startX, startY, endX, endY; color_t color; // get start position startX = (int) random(SCREEN_WIDTH); startY = (int) random(SCREEN_HEIGHT); // get end position endX = (int) random(SCREEN_WIDTH); endY = (int) random(SCREEN_HEIGHT); // get color color = (color_t) random(4); switch (color) { case 0 : color = CLR_WHITE; break; case 1 : color = CLR_LTGRAY; break; case 2 : color = CLR_DKGRAY; break; case 3 : color = CLR_BLACK; break; } // draw the line DisplayGraphics_set_color(mainModule.m_gfx, color); DisplayGraphics_draw_line(mainModule.m_gfx, startX, startY, endX, endY); DisplayGraphics_show(mainModule.m_gfx); } // start of main long main(int argc, char* argv[], bool start) { struct Message* ptrMessage; dummy = 0; init_module(&mainModule); // construct a progress bar cProgressBar_ctor(&cPB, 30, 0, 100, cool_normal_font, CLR_WHITE, CLR_BLACK, 20); // add progress bar to screen cWinApp_AddObj(mainModule.m_process, &cPB, (SCREEN_WIDTH/2)-15, SCREEN_HEIGHT-20); // set up font DisplayGraphics_set_font(mainModule.m_gfx, mini_normal_font); cWinApp_clear_screen(); while (TRUE) { ptrMessage = cWinApp_get_message(mainModule.m_process, 0, 1, MY_APP); if (ptrMessage) { switch(ptrMessage->msgid) { case MY_APP : Buffer_load(Message_get_buffer(ptrMessage), buffer, 0, 8); dummy++; buffer[3] = dummy; if (counter++ > 100){ counter = 0; cWinApp_clear_screen(); } cProgressBar_SetCurrentPos(&cPB, counter); drawLine(); send_remote_msg(CYBIKO_MASTER, "serial", MY_APP, 0L, 0L, buffer, 8); break; default : cWinApp_defproc(mainModule.m_process, ptrMessage); } // delete message after processing Message_delete(ptrMessage); } } cProgressBar_dtor(&cPB, LEAVE_MEMORY); return 0L; }
See also:
file: /Techref/cybiko/rf.htm, 12KB, , updated: 2007/4/29 08:08, local time: 2024/11/21 10:29,
owner: JMN-EFP-786,
18.218.108.24:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/techref/cybiko/rf.htm"> RF</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.