bool CanonDriver::setAutoExposure(AutoExposureMode aem) { if (!sendAndWait(0x82,0x0000)) return false; if (aem != AXPundef) { unsigned char data[2]; data[0] = ((unsigned int)aem) >> 8; data[1] = ((unsigned int)aem) & 0xFF; if (!sendAndWait(0x87,0x0000,data,2)) return false; }
bool CanonDriver::moveTo(double pan, double tilt, double zoom) { unsigned char data[6]; signed short span,stilt,szoom; //printf("P %f T %f Z %f\n",pan,tilt,zoom); if (pan < -170) pan = -170; if (pan > +170) pan = +170; if (tilt < -90) tilt = -90; if (tilt > 10) tilt = 10; if (zoom < 1.97) zoom = 1.97; if (zoom > 41.26) zoom = 41.26; //printf("P %f T %f Z %f\n",pan,tilt,zoom); span = (signed short)round(pan*100.0); stilt = (signed short)round(tilt*100.0); szoom = (signed short)round(zoom*100.0); unsigned short upan,utilt,uzoom; upan = (unsigned short)span; utilt = (unsigned short)stilt; uzoom = (unsigned short)szoom; //printf("P %02X T %02X Z %02X\n",upan,utilt,uzoom); data[0] = upan >> 8; data[1] = (upan & 0xFF); data[2] = utilt >> 8; data[3] = (utilt & 0xFF); data[4] = uzoom >> 8; data[5] = (uzoom & 0xFF); bool res = sendAndWait(0x33,0x00e0,data,6); if (!res && (verbose > 0)) printf("Move To Failed\n"); return res; }
int SyslinkMemory::read(int i, uint16_t addr, char *buf, int length) { syslink_ow_read_t *data = (syslink_ow_read_t *) &msgbuf.data; msgbuf.type = SYSLINK_OW_READ; int nread = 0; while (nread < length) { msgbuf.length = 3; data->idx = i; data->addr = addr; sendAndWait(); // Number of bytes actually read int n = MIN(length - nread, msgbuf.length - 3); if (n == 0) { break; } memcpy(buf, data->data, n); nread += n; buf += n; addr += n; } return nread; }
bool CanonDriver::setMinSpeed() { unsigned char data[8] = { 0x02, 0x21, 0x01, 0x98, 0x00, 0x00, 0xE0, 0x00 }; return sendAndWait(0x3B,0x0000,data,8); }
bool CanonDriver::setMaxSpeed() { unsigned char data[8] = { 0x08, 0x84, 0x06, 0x63, 0x00, 0x07, 0xE0, 0x00 }; return sendAndWait(0x3B,0x0000,data,8); }
bool CanonDriver::setFocusMode(FocusMode fm, ManualFocusMode mfm) { unsigned char data = fm; if (!sendAndWait(0x40,0x0000,&data,1)) return false; if ((fm == FMManual) && (mfm != FMUndef)) { // This sequence used in the win app data = 0; if (!sendAndWait(0x43,0x0000,&data,1)) return false; data = mfm; if (!sendAndWait(0x43,0x0000,&data,1)) return false; data = 0; if (!sendAndWait(0x43,0x0000,&data,1)) return false; } return true; }
void SyslinkMemory::getinfo(int i) { syslink_ow_getinfo_t *data = (syslink_ow_getinfo_t *) &msgbuf.data; msgbuf.type = SYSLINK_OW_GETINFO; msgbuf.length = 1; data->idx = i; sendAndWait(); }
bool smtpClientClass::login(const QString &user, const QString &password) { if(sendAndWait("AUTH PLAIN " + QByteArray().append((char) 0).append(user).append((char) 0).append(password).toBase64(), 235) == false) { return false; } return true; }
bool smtpClientClass::sendMail(email& thisMail) { QString messageToSend; QCryptographicHash md5(QCryptographicHash::Md5); QString resultHash; md5.addData(QByteArray().append(qrand())); resultHash = md5.result().toHex(); if(sendAndWait("MAIL FROM: <" + thisMail.from + ">") == false) { return false; } if(sendAndWait("RCPT TO: <" + thisMail.to + ">") == false) { return false; } if(sendAndWait("DATA", 354) == false) { return false; } messageToSend = "From: market stalker"; messageToSend += " <" + thisMail.from + ">\r\n"; messageToSend += "To: you <" + thisMail.to + ">\r\n"; messageToSend += "Subject: " + thisMail.subject + "\r\n"; messageToSend += "Mime-Version: 1.0\r\n"; messageToSend += "Content-Type: text/plain; charset=UTF-8\r\n"; messageToSend += "Content-Transfer-Encoding: 8bit\r\n\r\n"; messageToSend += thisMail.message.replace("\n", "\r\n").replace("\r\n.\r\n", "\r\n..\r\n"); if(sendMessage(messageToSend) == false) { return false; } if(sendAndWait(".") == false) { return false; } return true; }
bool CanonDriver::setPanSpeed(unsigned short speed) { unsigned char data[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00 }; data[0] = speed >> 8; data[1] = speed & 0xFF; return sendAndWait(0x3B,0x0000,data,8); }
uint8_t SyslinkMemory::scan() { syslink_ow_scan_t *data = (syslink_ow_scan_t *) &msgbuf.data; msgbuf.type = SYSLINK_OW_SCAN; msgbuf.length = 0; sendAndWait(); return data->nmems; }
bool CanonDriver::setTiltSpeed(unsigned short speed) { unsigned char data[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00 }; data[2] = speed >> 8; data[3] = speed & 0xFF; return sendAndWait(0x3B,0x0000,data,8); }
bool CanonDriver::setZoomSpeed(unsigned short speed) { unsigned char data[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00 }; data[4] = speed >> 8; data[5] = speed & 0xFF; return sendAndWait(0x3B,0x0000,data,8); }
static void sendReq(uint8_t header, uint16_t index, uint8_t subindex, const uint8_t* data, int length) { txMsg.data[1] = index; txMsg.data[2] = index >> 8; txMsg.data[3] = subindex; for (int i = 0; i < 4; ++i) txMsg.data[4+i] = i < length ? *data++ : 0; sendAndWait(header, 8); if (txMsg.data[7] & 0x08) blinkLed(3); }
bool CanonDriver::disconnect() { //printf("Sending 0x21\n"); if (connected) { if (!sendAndWait(0x21,0x0000)) { if (verbose) fprintf(stderr,"Failed to send 0x21\n"); } } //printf("Sent 0x21\n"); cm.close(); //printf("Close comm manager\n"); connected = false; stopVideoReception(); //printf("Close video manager\n"); return true; }
bool smtpClientClass::connectToHost() { socket->connectToHostEncrypted(host, port); if(socket->waitForConnected(connectionTimeout) == false) { return false; } if(waitForResponse() == false) { return false; } if(responseCode != 220) { return false; } if(sendAndWait("EHLO you") == false) { return false; } return true; }
bool CanonDriver::startMoving(Direction dir) { unsigned char data = dir; return sendAndWait(0x3C,0x0000,&data,1); }
bool CanonDriver::startDeZooming() { unsigned char data = 0x02; return sendAndWait(0x3D,0x0000,&data,1); }
void sdoWriteDataSegment(uint8_t header, const uint8_t* data, int length) { for (int i = 0; i < 7; ++i) txMsg.data[1+i] = i < length ? *data++ : 0; sendAndWait(header, 8); }
// main start int main(void) { asm volatile ("clr __zero_reg__"); // reset MCU status register MCUSR = 0; // enable watchdog to avoid deadlock watchdogConfig(WATCHDOG_8S); // initialize SPI SPIinit(); // initialize RF module RFinit(); // Read node config from EEPROM, i.e. nodeId, parent nodeId, distance eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(struct NodeConfig)); // Read firmware config from EEPROM, i.e. type, version, CRC, blocks eeprom_read_block((void*)&fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig)); // find nearest node during reboot: invalidate parent node settings, since we have to re-discover them for every single reboot configuredParentID = nc.parentNodeId; // nc.parentNodeId = 0xFF; nc.distance = 0xFF; // prepare for I_FIND_PARENTS outMsg.sender = nc.nodeId; outMsg.last = nc.nodeId; outMsg.sensor = 0xFF; outMsg.destination = BROADCAST_ADDRESS; // set header mSetVersion(outMsg, PROTOCOL_VERSION); mSetLength(outMsg, 0); mSetCommand(outMsg, C_INTERNAL); mSetAck(outMsg,false); mSetPayloadType(outMsg, P_STRING); // set reading & writing pipe address setAddress(nc.nodeId); // network up? get neighbors, else startup if (!sendAndWait(I_FIND_PARENT, I_FIND_PARENT_RESPONSE)) { startup(); } // all messages to gateway outMsg.destination = GATEWAY_ADDRESS; // if no node id assigned, request new id if (nc.nodeId == AUTO) { // listen to broadcast openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(BROADCAST_ADDRESS)); if (sendAndWait(I_ID_REQUEST, I_ID_RESPONSE)) { // save id to eeprom eeprom_update_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, atoi(inMsg.data)); } // we could go on and set everything right here, but rebooting will take care of that - and saves some bytes :) reboot(); } // wuff watchdogReset(); // prepare for FW config request RequestFirmwareConfig *reqFWConfig = (RequestFirmwareConfig *)outMsg.data; mSetLength(outMsg, sizeof(RequestFirmwareConfig)); mSetCommand(outMsg, C_STREAM); mSetPayloadType(outMsg,P_CUSTOM); // copy node settings to reqFWConfig memcpy(reqFWConfig,&fc,sizeof(NodeFirmwareConfig)); // add bootloader information reqFWConfig->BLVersion = MYSBOOTLOADER_VERSION; // send node config and request FW config from controller if (!sendAndWait(ST_FIRMWARE_CONFIG_REQUEST, ST_FIRMWARE_CONFIG_RESPONSE)) { startup(); } NodeFirmwareConfig *firmwareConfigResponse = (NodeFirmwareConfig *)inMsg.data; // bootloader commands if (firmwareConfigResponse->blocks == 0) { // verify flag if (firmwareConfigResponse->crc == 0xDA7A){ // cmd 0x01 clear eeprom if(firmwareConfigResponse->bl_command == 0x01) { for(uint16_t i = 0; i < EEPROM_SIZE; i++) eeprom_update_byte((uint8_t *)i,0xFF); } else // cmd 0x02 set id if(firmwareConfigResponse->bl_command == 0x02) { eeprom_update_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, (uint8_t)firmwareConfigResponse->bl_data); } } // final step reboot(); } // compare with current node configuration, if equal startup if (!memcmp(&fc,firmwareConfigResponse,sizeof(NodeFirmwareConfig))) { startup(); } // *********** from here on we will fetch new FW // invalidate current CRC fc.crc = 0xFFFF; // write fetched type and version in case OTA fails (BL will reboot and re-request FW with stored settings) eeprom_update_block(&fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS,sizeof(NodeFirmwareConfig)); // copy new FW config memcpy(&fc,firmwareConfigResponse,sizeof(NodeFirmwareConfig)); RequestFWBlock *firmwareRequest = (RequestFWBlock *)outMsg.data; mSetLength(outMsg, sizeof(RequestFWBlock)); firmwareRequest->type = fc.type; firmwareRequest->version = fc.version; // request FW from controller, load FW counting backwards uint16_t block = fc.blocks; do { firmwareRequest->block = block - 1; // request FW block if (!sendAndWait(ST_FIRMWARE_REQUEST, ST_FIRMWARE_RESPONSE)) { reboot(); } ReplyFWBlock *firmwareResponse = (ReplyFWBlock *)inMsg.data; // did we receive requested block? if (!memcmp(firmwareRequest,firmwareResponse,sizeof(RequestFWBlock))) { // calculate page offset uint8_t offset = ((block - 1) * FIRMWARE_BLOCK_SIZE) % SPM_PAGESIZE; // write to buffer memcpy(progBuf + offset, firmwareResponse->data, FIRMWARE_BLOCK_SIZE); // program if page full if (offset == 0) { programPage(((block - 1) * FIRMWARE_BLOCK_SIZE), progBuf); } block--; } } while (block); // wuff watchdogReset(); // all blocks transmitted, calc CRC and write to eeprom if valid if (IsFirmwareValid()) { // if FW is valid, write settings to eeprom eeprom_update_block(&fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig)); } // final step reboot(); }